@happyvertical/smrt-core 0.51.31 → 0.51.33
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/agents/build-knowledge.md +13 -0
- package/dist/__tests__/fixtures/collection-coverage-fixtures.d.ts +8 -0
- package/dist/__tests__/fixtures/inheritance-resolver-fixtures.d.ts +9 -0
- package/dist/__tests__/fixtures/inheritance-test-classes.d.ts +5 -0
- package/dist/__tests__/fixtures/object-ai-memory-fixtures.d.ts +10 -0
- package/dist/__typechecks__/collection-read-plan.d.ts +2 -2
- package/dist/adapters/ai-usage.d.ts +5 -2
- package/dist/adapters/cost-rates.d.ts +1 -1
- package/dist/adapters/metrics.d.ts +7 -1
- package/dist/adapters/pubsub.d.ts +7 -1
- package/dist/browser.d.ts +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +2 -1
- package/dist/cascade.d.ts +69 -3
- package/dist/change-feed-authz.d.ts +85 -2
- package/dist/change-feed.d.ts +133 -2
- package/dist/change-signals.d.ts +66 -1
- package/dist/child-accessors.d.ts +39 -1
- package/dist/class.d.ts +17 -8
- package/dist/class.d.ts.map +1 -1
- package/dist/class.js +22 -0
- package/dist/class.js.map +1 -1
- package/dist/collection-cache.d.ts +47 -1
- package/dist/collection-read-plan.d.ts +3 -3
- package/dist/collection.d.ts +4 -3
- package/dist/config.d.ts +15 -6
- package/dist/consumer-plugin/index.d.ts +7 -3
- package/dist/consumer-plugin/index.d.ts.map +1 -1
- package/dist/consumer-plugin/index.js +2 -0
- package/dist/consumer-plugin/index.js.map +1 -1
- package/dist/data-query.d.ts +12 -1
- package/dist/database.d.ts +10 -2
- package/dist/decisions.d.ts +24 -2
- package/dist/decisions.d.ts.map +1 -1
- package/dist/decisions.js +71 -1
- package/dist/decisions.js.map +1 -1
- package/dist/decorators/index.d.ts +11 -5
- package/dist/dispatch/bus.d.ts +27 -2
- package/dist/dispatch/collections/DispatchSubscriptions.d.ts +7 -2
- package/dist/dispatch/collections/Dispatches.d.ts +8 -3
- package/dist/dispatch/models/Dispatch.d.ts +7 -1
- package/dist/dispatch/types.d.ts +7 -2
- package/dist/embedded-write-queue.d.ts +1 -1
- package/dist/embeddings/provider.d.ts +8 -1
- package/dist/embeddings/storage.d.ts +8 -2
- package/dist/filesystem-loader.d.ts +16 -1
- package/dist/generators/changes-route.d.ts +34 -1
- package/dist/generators/custom-action.d.ts +10 -2
- package/dist/generators/events-route.d.ts +41 -4
- package/dist/generators/mcp-runtime-template.d.ts +13 -2
- package/dist/generators/mcp.d.ts +6 -1
- package/dist/generators/rest.d.ts +10 -5
- package/dist/generators/tool-schema.d.ts +1 -1
- package/dist/hierarchical.d.ts +37 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/interceptors.d.ts +45 -1
- package/dist/junction.d.ts +24 -0
- package/dist/knowledge-config.d.ts +1 -1
- package/dist/knowledge-discovery.d.ts +2 -25
- package/dist/knowledge-discovery.d.ts.map +1 -1
- package/dist/knowledge-discovery.js +1 -53
- package/dist/knowledge-graph.d.ts +2 -94
- package/dist/knowledge-graph.d.ts.map +1 -1
- package/dist/knowledge-graph.js +1 -267
- package/dist/knowledge.d.ts +4 -23
- package/dist/knowledge.d.ts.map +1 -1
- package/dist/knowledge.js +3 -52
- package/dist/knowledge.js.map +1 -1
- package/dist/learning/memory.d.ts +21 -1
- package/dist/manifest/generator.d.ts +5 -1
- package/dist/manifest/index.d.ts +5 -1
- package/dist/manifest/manager.d.ts +1 -1
- package/dist/manifest/manifest-loader.d.ts +24 -2
- package/dist/manifest/sources/composite.d.ts +17 -1
- package/dist/manifest/sources/embedded.d.ts +10 -1
- package/dist/manifest/sources/explicit-paths.d.ts +13 -1
- package/dist/manifest/sources/fallback.d.ts +15 -1
- package/dist/manifest/sources/local-test.d.ts +10 -1
- package/dist/manifest/sources/static.d.ts +12 -1
- package/dist/manifest/sources/test.d.ts +9 -1
- package/dist/manifest/sources/types.d.ts +7 -1
- package/dist/manifest/static-manifest.d.ts +6 -1
- package/dist/manifest/static-manifest.js +1 -1
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.d.ts +22 -3
- package/dist/manifest/store.js +1 -1
- package/dist/manifest.json +1 -1
- package/dist/migrations/backfill-tracker.d.ts +15 -1
- package/dist/migrations/differ.d.ts +8 -2
- package/dist/migrations/framework-base-tables.d.ts +57 -2
- package/dist/migrations/generator.d.ts +8 -2
- package/dist/migrations/integer-width.d.ts +10 -2
- package/dist/migrations/minor-units.d.ts +40 -1
- package/dist/migrations/null-equal-indexes.d.ts +3 -2
- package/dist/migrations/orchestrate.d.ts +15 -3
- package/dist/migrations/sqlite-rebuild.d.ts +67 -2
- package/dist/migrations/tracker.d.ts +9 -3
- package/dist/migrations/types.d.ts +7 -2
- package/dist/object.d.ts +7 -6
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +6 -17
- package/dist/object.js.map +1 -1
- package/dist/polymorphic-association.d.ts +44 -1
- package/dist/postgres-permissions.d.ts +1 -1
- package/dist/prebuild/index.d.ts +5 -1
- package/dist/query-bounds.d.ts +26 -0
- package/dist/registry/cache-config.d.ts +10 -1
- package/dist/registry/class-registration.d.ts +10 -2
- package/dist/registry/collection-resolution.d.ts +1 -1
- package/dist/registry/embedding-manager.d.ts +9 -1
- package/dist/registry/inheritance-resolver.d.ts +8 -3
- package/dist/registry/manifest-field-merge.d.ts +2 -2
- package/dist/registry/name-resolver.d.ts +22 -2
- package/dist/registry/relationship-graph.d.ts +9 -1
- package/dist/registry/schema-builder.d.ts +8 -3
- package/dist/registry/shared-state.d.ts +12 -2
- package/dist/registry/types.d.ts +15 -7
- package/dist/registry/validator.d.ts +10 -2
- package/dist/registry.d.ts +40 -11
- package/dist/relationship-loader.d.ts +1 -1
- package/dist/run-once.d.ts +110 -1
- package/dist/runtime/client.d.ts +4 -1
- package/dist/runtime/server.d.ts +5 -2
- package/dist/scanner/import-scanner.d.ts +1 -1
- package/dist/scanner/manifest-generator.d.ts +4 -1
- package/dist/scanner/types.d.ts +4 -1
- package/dist/schema/code-generator.d.ts +6 -2
- package/dist/schema/column-data-probes.d.ts +27 -2
- package/dist/schema/ddl/base-strategy.d.ts +8 -2
- package/dist/schema/ddl/duckdb-strategy.d.ts +14 -2
- package/dist/schema/ddl/index.d.ts +2 -2
- package/dist/schema/ddl/json-duckdb-strategy.d.ts +10 -2
- package/dist/schema/ddl/materialize-manifest.d.ts +1 -1
- package/dist/schema/ddl/null-equal-index.d.ts +1 -1
- package/dist/schema/ddl/postgres-strategy.d.ts +12 -2
- package/dist/schema/ddl/sqlite-strategy.d.ts +12 -2
- package/dist/schema/ddl/types.d.ts +10 -1
- package/dist/schema/foreign-key-ddl.d.ts +2 -2
- package/dist/schema/foreign-key-orphan-report.d.ts +25 -3
- package/dist/schema/foreign-key-planner.d.ts +2 -2
- package/dist/schema/foreign-key-policy.d.ts +1 -1
- package/dist/schema/generator.d.ts +7 -3
- package/dist/schema/index-utils.d.ts +11 -2
- package/dist/schema/live-parity.d.ts +27 -3
- package/dist/schema/manifest-schema.d.ts +21 -2
- package/dist/schema/schema-aggregator.d.ts +35 -2
- package/dist/schema/schema-manager.d.ts +13 -4
- package/dist/schema/system-table-shapes.d.ts +20 -1
- package/dist/schema/table-verifier.d.ts +1 -1
- package/dist/schema/text-cast-probe.d.ts +24 -1
- package/dist/schema/utils.d.ts +13 -4
- package/dist/schema/uuid-convergence.d.ts +32 -1
- package/dist/signals/bus.d.ts +8 -2
- package/dist/signals/sanitizer.d.ts +7 -1
- package/dist/smrt-knowledge.json +8 -9
- package/dist/system/bootstrap.d.ts +2 -1
- package/dist/system/compatibility.d.ts +1 -1
- package/dist/system/diagnostics.d.ts +17 -2
- package/dist/system/retention.d.ts +46 -1
- package/dist/system/schema.d.ts +7 -1
- package/dist/system-fields.d.ts +9 -1
- package/dist/test-utils.d.ts +7 -1
- package/dist/testing/database.d.ts +18 -1
- package/dist/testing/notifications-stub.d.ts +15 -1
- package/dist/tools/tool-executor.d.ts +6 -1
- package/dist/tools/tool-generator.d.ts +8 -2
- package/dist/utils/json.d.ts +9 -1
- package/dist/utils/qualified-names.d.ts +10 -1
- package/dist/utils/scanner-module.d.ts +2 -2
- package/dist/utils.d.ts +1 -1
- package/dist/vite-plugin/api-client-entries.d.ts +9 -1
- package/dist/vite-plugin/changes-route.d.ts +33 -2
- package/dist/vite-plugin/dev-plane-route.d.ts +12 -1
- package/dist/vite-plugin/events-route.d.ts +37 -2
- package/dist/vite-plugin/generated-client.d.ts +9 -1
- package/dist/vite-plugin/index.d.ts +9 -5
- package/dist/vite-plugin/resources-route.d.ts +82 -1
- package/dist/vite-plugin/sveltekit-generator.d.ts +8 -4
- package/dist/vite-plugin/sveltekit-route-coordinator.d.ts +3 -3
- package/dist/vite-plugin/sync-apply-route.d.ts +19 -2
- package/dist/vite-plugin/web-collections.d.ts +25 -2
- package/dist/vite-plugin/worker-registration.d.ts +21 -1
- package/package.json +7 -8
- package/dist/knowledge-discovery.js.map +0 -1
- package/dist/knowledge-graph.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge-graph.js","names":[],"sources":["../src/knowledge-graph.ts"],"sourcesContent":["/**\n * Cross-package knowledge graph (#2863).\n *\n * Each package's own `smrt-knowledge.json` (see `knowledge.ts`) is a\n * per-package projection. Nothing merges them, so cross-package invariants\n * that the scanner manifest already carries — `@crossPackageRef` targets, STI\n * parent/child pairs, junction/hierarchical/polymorphic base usage, and\n * `_smrt_` system-table ownership — live only as prose in the root\n * `AGENTS.md`. This module builds the merged, deterministic root artifact\n * (`.smrt/smrt-knowledge-graph.json`) from whichever per-package artifacts\n * are present, and checks it for staleness the same way `knowledge.ts` checks\n * a package artifact: by comparing recorded `sourceHashes` against the\n * current file content.\n *\n * This module never invents an edge: every edge is a direct read of a field\n * already emitted into a package's `DomainKnowledgeManifest` (`related`,\n * `tableStrategy`, `extends`, `relationshipFeatures`, `tableName`).\n */\n\nimport { createHash } from 'node:crypto';\nimport { existsSync, readdirSync, readFileSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport type {\n DomainKnowledgeManifest,\n DomainKnowledgeObject,\n} from '@happyvertical/smrt-types';\n\n/**\n * Discovers every currently-buildable per-package artifact path under\n * `<rootDir>/packages/*`, preferring the published `dist/smrt-knowledge.json`\n * over the local dev `.smrt/smrt-knowledge.json` when both exist. Shared by\n * the generator (which needs the manifest content) and the freshness check\n * (which only needs to know whether the current SET of artifacts matches\n * what the graph was built from — a newly built package, or a package that\n * newly started exporting `./smrt-knowledge.json`, must mark the graph stale\n * even though every artifact the graph already knows about is unchanged).\n */\nexport function discoverKnowledgeArtifactPaths(rootDir: string): string[] {\n const packagesDir = join(rootDir, 'packages');\n if (!existsSync(packagesDir)) return [];\n const paths: string[] = [];\n for (const entry of readdirSync(packagesDir, { withFileTypes: true })) {\n if (!entry.isDirectory()) continue;\n const packageDir = join(packagesDir, entry.name);\n const candidates = [\n join(packageDir, 'dist', 'smrt-knowledge.json'),\n join(packageDir, '.smrt', 'smrt-knowledge.json'),\n ];\n const found = candidates.find((path) => existsSync(path));\n if (found) paths.push(relative(rootDir, found).split('\\\\').join('/'));\n }\n return paths.sort();\n}\n\n/** One package's `smrt-knowledge.json`, located relative to the graph root. */\nexport interface KnowledgeGraphInput {\n /** Path to the artifact, relative to the repo root, POSIX-separated. */\n artifactPath: string;\n manifest: DomainKnowledgeManifest;\n}\n\nexport interface KnowledgeGraphPackageNode {\n name: string;\n version?: string;\n artifactPath: string;\n tags: string[];\n risks: string[];\n summary?: string;\n objectCount: number;\n}\n\nexport interface KnowledgeGraphObjectNode {\n /** `<packageName>#<qualifiedName-or-name>`, this graph's stable object id. */\n id: string;\n packageName: string;\n name: string;\n qualifiedName?: string;\n collection: string;\n tableName?: string;\n tableStrategy?: 'cti' | 'sti';\n extends?: string;\n}\n\nexport type KnowledgeGraphEdgeType =\n | 'crossPackageRef'\n | 'sti'\n | 'junction'\n | 'hierarchical'\n | 'polymorphic'\n | 'systemTable';\n\nexport interface KnowledgeGraphEdge {\n type: KnowledgeGraphEdgeType;\n /** Object id (or `<packageName>#<extends>`-style unresolved target) this edge starts from. */\n from: string;\n /**\n * Object id the edge points to when resolvable against a scanned object;\n * otherwise the raw declared target (e.g. a qualified name this run did\n * not scan), so the edge is still readable rather than dropped.\n */\n to?: string;\n /** Declaring field name, for `crossPackageRef` edges. */\n field?: string;\n}\n\nexport interface SmrtKnowledgeGraph {\n schemaVersion: 1;\n generatedAt: string;\n /** `artifactPath -> sha256(content)`, sorted by key; the freshness input. */\n sourceHashes: Record<string, string>;\n packages: KnowledgeGraphPackageNode[];\n objects: KnowledgeGraphObjectNode[];\n edges: KnowledgeGraphEdge[];\n}\n\nfunction hashContent(content: string): string {\n return createHash('sha256').update(content).digest('hex');\n}\n\nfunction objectId(packageName: string, object: DomainKnowledgeObject): string {\n return `${packageName}#${object.qualifiedName ?? object.name}`;\n}\n\nexport interface BuildKnowledgeGraphOptions {\n /**\n * The graph currently on disk, when regenerating. `generatedAt` is\n * preserved from it rather than reset to the clock whenever the rebuilt\n * graph is otherwise semantically identical — the same pattern\n * `preserveKnowledgeGeneratedAt` uses for per-package artifacts\n * (`packages/core/src/vite-plugin/index.ts`) — so re-running the generator\n * with nothing merged actually changed does not churn the file (#2872\n * review).\n */\n previousGraph?: SmrtKnowledgeGraph;\n}\n\n/** Builds the merged graph. Deterministic: every array is sorted. */\nexport function buildKnowledgeGraph(\n inputs: KnowledgeGraphInput[],\n options: BuildKnowledgeGraphOptions = {},\n): SmrtKnowledgeGraph {\n const sortedInputs = [...inputs].sort((a, b) =>\n a.artifactPath.localeCompare(b.artifactPath),\n );\n\n const sourceHashes: Record<string, string> = {};\n const packages: KnowledgeGraphPackageNode[] = [];\n const objects: KnowledgeGraphObjectNode[] = [];\n const edges: KnowledgeGraphEdge[] = [];\n\n // Qualified-name -> object id, so a crossPackageRef/STI target declared in\n // one package can be resolved to the node emitted by whichever package\n // scanned it, regardless of scan order.\n const idByQualifiedName = new Map<string, string>();\n // Distinct ids per simple name, not a plain array: the same external\n // object can appear in more than one input (e.g. a package artifact and a\n // smrtConsumer aggregate that also scanned it), and counting the\n // duplicate would make resolveTarget's `.length === 1` uniqueness check\n // see a false ambiguity for an otherwise-unique name (#2872 review).\n const idBySimpleName = new Map<string, Set<string>>();\n // A `tableStrategy: 'sti'` object's `extends` is an unqualified simple name\n // (its own package's base class, never a cross-package reference — STI\n // shares one table within a package), so a same-package simple-name match\n // must win over an ambiguous or wrong-package GLOBAL simple-name match:\n // two packages both declaring `Account` must not point one package's\n // subclass at the other package's `Account` (#2863 review).\n const idBySimpleNamePerPackage = new Map<string, Map<string, string>>();\n\n for (const input of sortedInputs) {\n const manifestPackageName =\n input.manifest.packageName ?? input.artifactPath;\n for (const object of input.manifest.objects) {\n // A merged consumer manifest (`smrtConsumer`) aggregates objects\n // scanned from multiple external packages under one local artifact;\n // each object then carries its own `packageName` and that must own\n // the id, or every external object misattributes to the local\n // project and edges resolve to the wrong node (#2872 review).\n const packageName = object.packageName ?? manifestPackageName;\n const perPackage =\n idBySimpleNamePerPackage.get(packageName) ?? new Map<string, string>();\n const id = objectId(packageName, object);\n idByQualifiedName.set(object.qualifiedName ?? id, id);\n const bySimple = idBySimpleName.get(object.name) ?? new Set<string>();\n bySimple.add(id);\n idBySimpleName.set(object.name, bySimple);\n perPackage.set(object.name, id);\n idBySimpleNamePerPackage.set(packageName, perPackage);\n }\n }\n\n const resolveTarget = (\n raw: string | undefined,\n declaringPackageName?: string,\n ): string | undefined => {\n if (!raw) return undefined;\n if (idByQualifiedName.has(raw)) return idByQualifiedName.get(raw);\n if (declaringPackageName) {\n const sameId = idBySimpleNamePerPackage\n .get(declaringPackageName)\n ?.get(raw);\n if (sameId) return sameId;\n }\n const bySimple = idBySimpleName.get(raw);\n if (bySimple && bySimple.size === 1) return [...bySimple][0];\n return undefined;\n };\n\n const seenObjectIds = new Set<string>();\n for (const input of sortedInputs) {\n sourceHashes[input.artifactPath] = hashContent(\n stableStringify(input.manifest),\n );\n const packageName = input.manifest.packageName ?? input.artifactPath;\n\n packages.push({\n name: packageName,\n version: input.manifest.packageVersion,\n artifactPath: input.artifactPath,\n tags: [...input.manifest.tags].sort(),\n risks: [...input.manifest.risks].sort(),\n summary: input.manifest.summary,\n objectCount: input.manifest.objects.length,\n });\n\n for (const object of input.manifest.objects) {\n // See the id-map pass above: an aggregated consumer manifest attributes\n // each object to its own scanned package, not the local project.\n const objectPackageName = object.packageName ?? packageName;\n const id = objectId(objectPackageName, object);\n if (!seenObjectIds.has(id)) {\n seenObjectIds.add(id);\n objects.push({\n id,\n packageName: objectPackageName,\n name: object.name,\n qualifiedName: object.qualifiedName,\n collection: object.collection,\n tableName: object.tableName,\n tableStrategy: object.tableStrategy,\n extends: object.extends,\n });\n }\n\n for (const field of object.relationships) {\n if (field.type !== 'crossPackageRef') continue;\n edges.push({\n type: 'crossPackageRef',\n from: id,\n to: resolveTarget(field.related) ?? field.related,\n field: field.name,\n });\n }\n\n if (object.tableStrategy === 'sti' && object.extends) {\n edges.push({\n type: 'sti',\n from: id,\n to:\n resolveTarget(object.extends, objectPackageName) ??\n `${objectPackageName}#${object.extends}`,\n });\n }\n\n for (const feature of object.relationshipFeatures) {\n if (feature === 'SmrtJunction') {\n edges.push({ type: 'junction', from: id });\n } else if (feature === 'SmrtHierarchical') {\n edges.push({ type: 'hierarchical', from: id });\n } else if (feature === 'SmrtPolymorphicAssociation') {\n edges.push({ type: 'polymorphic', from: id });\n }\n }\n\n if (object.tableName?.startsWith('_smrt_')) {\n edges.push({ type: 'systemTable', from: id, to: object.tableName });\n }\n }\n }\n\n packages.sort((a, b) => a.name.localeCompare(b.name));\n objects.sort((a, b) => a.id.localeCompare(b.id));\n edges.sort((a, b) => {\n const key = (edge: KnowledgeGraphEdge) =>\n `${edge.type}|${edge.from}|${edge.to ?? ''}|${edge.field ?? ''}`;\n return key(a).localeCompare(key(b));\n });\n\n const graph: SmrtKnowledgeGraph = {\n schemaVersion: 1,\n generatedAt: new Date().toISOString(),\n sourceHashes: sortRecord(sourceHashes),\n packages,\n objects,\n edges,\n };\n\n const { previousGraph } = options;\n if (\n previousGraph &&\n semanticGraphJson(previousGraph) === semanticGraphJson(graph)\n ) {\n return { ...graph, generatedAt: previousGraph.generatedAt };\n }\n return graph;\n}\n\nfunction semanticGraphJson(graph: SmrtKnowledgeGraph): string {\n const { generatedAt: _generatedAt, ...rest } = graph;\n return stableStringify(rest);\n}\n\n/** Deterministic `JSON.stringify` — object keys are sorted at every level. */\nexport function stableStringify(value: unknown): string {\n return JSON.stringify(sortValue(value));\n}\n\nfunction sortValue(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(sortValue);\n if (value && typeof value === 'object') {\n // Null-prototype target: on an ordinary `{}`, assigning the key\n // `\"__proto__\"` through bracket notation invokes `Object.prototype`'s\n // `__proto__` accessor instead of creating an own property, so that key\n // silently vanishes from the result and `JSON.stringify()` never emits\n // it — two inputs that differ only by an own `\"__proto__\"` key (which\n // `JSON.parse()` does create as a real own property) then serialize\n // identically. An object with no prototype has no such accessor to\n // shadow the assignment, so every own key — including `\"__proto__\"` —\n // becomes a real own data property. `JSON.stringify()` does not care\n // about an object's prototype, only its own enumerable properties, so\n // this changes no other output.\n const sorted: Record<string, unknown> = Object.create(null);\n for (const key of Object.keys(value as Record<string, unknown>).sort()) {\n sorted[key] = sortValue((value as Record<string, unknown>)[key]);\n }\n return sorted;\n }\n return value;\n}\n\nfunction sortRecord(record: Record<string, string>): Record<string, string> {\n const sorted: Record<string, string> = {};\n for (const key of Object.keys(record).sort()) sorted[key] = record[key];\n return sorted;\n}\n\nexport interface KnowledgeGraphFreshnessIssue {\n severity: 'error' | 'warning';\n code:\n | 'missing-knowledge-graph'\n | 'stale-knowledge-graph'\n | 'knowledge-graph-source-missing';\n message: string;\n file?: string;\n}\n\n/**\n * Checks the merged graph's recorded `sourceHashes` against the current\n * content of each per-package artifact it was built from — the same pattern\n * `knowledge.ts`/`smrt-dev-mcp` use for a single package's `sourceHashes`.\n *\n * `graphPath` and each `artifactPath` in the graph are resolved relative to\n * `rootDir` (the repo root).\n */\nexport function checkKnowledgeGraphFreshness(\n rootDir: string,\n graphPath: string,\n options: { requireArtifact?: boolean } = {},\n): KnowledgeGraphFreshnessIssue[] {\n const issues: KnowledgeGraphFreshnessIssue[] = [];\n const absoluteGraphPath = `${rootDir}/${graphPath}`;\n if (!existsSync(absoluteGraphPath)) {\n if (!options.requireArtifact) return issues;\n issues.push({\n severity: 'error',\n code: 'missing-knowledge-graph',\n message: `${graphPath} does not exist; run \\`pnpm knowledge:graph\\``,\n file: graphPath,\n });\n return issues;\n }\n\n let graph: SmrtKnowledgeGraph;\n try {\n graph = JSON.parse(readFileSync(absoluteGraphPath, 'utf8'));\n } catch (error) {\n issues.push({\n severity: 'error',\n code: 'stale-knowledge-graph',\n message: `${graphPath} is not valid JSON: ${\n error instanceof Error ? error.message : String(error)\n }`,\n file: graphPath,\n });\n return issues;\n }\n\n const recordedPaths = Object.keys(graph.sourceHashes ?? {});\n for (const [artifactPath, expectedHash] of Object.entries(\n graph.sourceHashes ?? {},\n )) {\n const absoluteArtifactPath = `${rootDir}/${artifactPath}`;\n if (!existsSync(absoluteArtifactPath)) {\n issues.push({\n severity: 'error',\n code: 'knowledge-graph-source-missing',\n message: `${artifactPath} used to build ${graphPath} no longer exists`,\n file: graphPath,\n });\n continue;\n }\n let manifest: unknown;\n try {\n manifest = JSON.parse(readFileSync(absoluteArtifactPath, 'utf8'));\n } catch (error) {\n issues.push({\n severity: 'error',\n code: 'stale-knowledge-graph',\n message: `${artifactPath} is not valid JSON (${\n error instanceof Error ? error.message : String(error)\n }); run \\`pnpm knowledge:graph\\``,\n file: graphPath,\n });\n continue;\n }\n const actualHash = hashContent(stableStringify(manifest));\n if (actualHash !== expectedHash) {\n issues.push({\n severity: 'error',\n code: 'stale-knowledge-graph',\n message: `${artifactPath} changed since ${graphPath} was generated; run \\`pnpm knowledge:graph\\``,\n file: graphPath,\n });\n }\n }\n\n // A per-key hash comparison alone cannot see an ADDED artifact: a package\n // that just finished its first build, or just started exporting\n // `./smrt-knowledge.json`, contributes a path the graph never recorded, so\n // every recorded hash still matches. Compare the current discoverable SET\n // against the recorded set to catch that (#2863 review).\n const currentPaths = discoverKnowledgeArtifactPaths(rootDir);\n const recordedSet = new Set(recordedPaths);\n const newPaths = currentPaths.filter((path) => !recordedSet.has(path));\n if (newPaths.length > 0) {\n issues.push({\n severity: 'error',\n code: 'stale-knowledge-graph',\n message: `${newPaths.join(', ')} ${\n newPaths.length === 1\n ? 'is a new package artifact'\n : 'are new package artifacts'\n } not yet merged into ${graphPath}; run \\`pnpm knowledge:graph\\``,\n file: graphPath,\n });\n }\n\n return issues;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,+BAA+B,SAA2B;CACxE,MAAM,cAAc,KAAK,SAAS,UAAU;CAC5C,IAAI,CAAC,WAAW,WAAW,GAAG,OAAO,CAAC;CACtC,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,SAAS,YAAY,aAAa,EAAE,eAAe,KAAK,CAAC,GAAG;EACrE,IAAI,CAAC,MAAM,YAAY,GAAG;EAC1B,MAAM,aAAa,KAAK,aAAa,MAAM,IAAI;EAK/C,MAAM,QAAQ,CAHZ,KAAK,YAAY,QAAQ,qBAAqB,GAC9C,KAAK,YAAY,SAAS,qBAAqB,CAEnC,CAAA,CAAW,MAAM,SAAS,WAAW,IAAI,CAAC;EACxD,IAAI,OAAO,MAAM,KAAK,SAAS,SAAS,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC;CACtE;CACA,OAAO,MAAM,KAAK;AACpB;AA+DA,SAAS,YAAY,SAAyB;CAC5C,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAAO,KAAK;AAC1D;AAEA,SAAS,SAAS,aAAqB,QAAuC;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