@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,95 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Discovers every currently-buildable per-package artifact path under
|
|
4
|
-
* `<rootDir>/packages/*`, preferring the published `dist/smrt-knowledge.json`
|
|
5
|
-
* over the local dev `.smrt/smrt-knowledge.json` when both exist. Shared by
|
|
6
|
-
* the generator (which needs the manifest content) and the freshness check
|
|
7
|
-
* (which only needs to know whether the current SET of artifacts matches
|
|
8
|
-
* what the graph was built from — a newly built package, or a package that
|
|
9
|
-
* newly started exporting `./smrt-knowledge.json`, must mark the graph stale
|
|
10
|
-
* even though every artifact the graph already knows about is unchanged).
|
|
11
|
-
*/
|
|
12
|
-
export declare function discoverKnowledgeArtifactPaths(rootDir: string): string[];
|
|
13
|
-
/** One package's `smrt-knowledge.json`, located relative to the graph root. */
|
|
14
|
-
export interface KnowledgeGraphInput {
|
|
15
|
-
/** Path to the artifact, relative to the repo root, POSIX-separated. */
|
|
16
|
-
artifactPath: string;
|
|
17
|
-
manifest: DomainKnowledgeManifest;
|
|
18
|
-
}
|
|
19
|
-
export interface KnowledgeGraphPackageNode {
|
|
20
|
-
name: string;
|
|
21
|
-
version?: string;
|
|
22
|
-
artifactPath: string;
|
|
23
|
-
tags: string[];
|
|
24
|
-
risks: string[];
|
|
25
|
-
summary?: string;
|
|
26
|
-
objectCount: number;
|
|
27
|
-
}
|
|
28
|
-
export interface KnowledgeGraphObjectNode {
|
|
29
|
-
/** `<packageName>#<qualifiedName-or-name>`, this graph's stable object id. */
|
|
30
|
-
id: string;
|
|
31
|
-
packageName: string;
|
|
32
|
-
name: string;
|
|
33
|
-
qualifiedName?: string;
|
|
34
|
-
collection: string;
|
|
35
|
-
tableName?: string;
|
|
36
|
-
tableStrategy?: 'cti' | 'sti';
|
|
37
|
-
extends?: string;
|
|
38
|
-
}
|
|
39
|
-
export type KnowledgeGraphEdgeType = 'crossPackageRef' | 'sti' | 'junction' | 'hierarchical' | 'polymorphic' | 'systemTable';
|
|
40
|
-
export interface KnowledgeGraphEdge {
|
|
41
|
-
type: KnowledgeGraphEdgeType;
|
|
42
|
-
/** Object id (or `<packageName>#<extends>`-style unresolved target) this edge starts from. */
|
|
43
|
-
from: string;
|
|
44
|
-
/**
|
|
45
|
-
* Object id the edge points to when resolvable against a scanned object;
|
|
46
|
-
* otherwise the raw declared target (e.g. a qualified name this run did
|
|
47
|
-
* not scan), so the edge is still readable rather than dropped.
|
|
48
|
-
*/
|
|
49
|
-
to?: string;
|
|
50
|
-
/** Declaring field name, for `crossPackageRef` edges. */
|
|
51
|
-
field?: string;
|
|
52
|
-
}
|
|
53
|
-
export interface SmrtKnowledgeGraph {
|
|
54
|
-
schemaVersion: 1;
|
|
55
|
-
generatedAt: string;
|
|
56
|
-
/** `artifactPath -> sha256(content)`, sorted by key; the freshness input. */
|
|
57
|
-
sourceHashes: Record<string, string>;
|
|
58
|
-
packages: KnowledgeGraphPackageNode[];
|
|
59
|
-
objects: KnowledgeGraphObjectNode[];
|
|
60
|
-
edges: KnowledgeGraphEdge[];
|
|
61
|
-
}
|
|
62
|
-
export interface BuildKnowledgeGraphOptions {
|
|
63
|
-
/**
|
|
64
|
-
* The graph currently on disk, when regenerating. `generatedAt` is
|
|
65
|
-
* preserved from it rather than reset to the clock whenever the rebuilt
|
|
66
|
-
* graph is otherwise semantically identical — the same pattern
|
|
67
|
-
* `preserveKnowledgeGeneratedAt` uses for per-package artifacts
|
|
68
|
-
* (`packages/core/src/vite-plugin/index.ts`) — so re-running the generator
|
|
69
|
-
* with nothing merged actually changed does not churn the file (#2872
|
|
70
|
-
* review).
|
|
71
|
-
*/
|
|
72
|
-
previousGraph?: SmrtKnowledgeGraph;
|
|
73
|
-
}
|
|
74
|
-
/** Builds the merged graph. Deterministic: every array is sorted. */
|
|
75
|
-
export declare function buildKnowledgeGraph(inputs: KnowledgeGraphInput[], options?: BuildKnowledgeGraphOptions): SmrtKnowledgeGraph;
|
|
76
|
-
/** Deterministic `JSON.stringify` — object keys are sorted at every level. */
|
|
77
|
-
export declare function stableStringify(value: unknown): string;
|
|
78
|
-
export interface KnowledgeGraphFreshnessIssue {
|
|
79
|
-
severity: 'error' | 'warning';
|
|
80
|
-
code: 'missing-knowledge-graph' | 'stale-knowledge-graph' | 'knowledge-graph-source-missing';
|
|
81
|
-
message: string;
|
|
82
|
-
file?: string;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Checks the merged graph's recorded `sourceHashes` against the current
|
|
86
|
-
* content of each per-package artifact it was built from — the same pattern
|
|
87
|
-
* `knowledge.ts`/`smrt-dev-mcp` use for a single package's `sourceHashes`.
|
|
88
|
-
*
|
|
89
|
-
* `graphPath` and each `artifactPath` in the graph are resolved relative to
|
|
90
|
-
* `rootDir` (the repo root).
|
|
91
|
-
*/
|
|
92
|
-
export declare function checkKnowledgeGraphFreshness(rootDir: string, graphPath: string, options?: {
|
|
93
|
-
requireArtifact?: boolean;
|
|
94
|
-
}): KnowledgeGraphFreshnessIssue[];
|
|
1
|
+
/** Compatibility exports; graph algorithms are owned by the lightweight scanner. */
|
|
2
|
+
export { type BuildKnowledgeGraphOptions, buildKnowledgeGraph, checkKnowledgeGraphFreshness, discoverKnowledgeArtifactPaths, type KnowledgeGraphEdge, type KnowledgeGraphEdgeType, type KnowledgeGraphFreshnessIssue, type KnowledgeGraphInput, type KnowledgeGraphObjectNode, type KnowledgeGraphPackageNode, type SmrtKnowledgeGraph, stableStringify, } from '@happyvertical/smrt-scanner/knowledge';
|
|
95
3
|
//# sourceMappingURL=knowledge-graph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge-graph.d.ts","sourceRoot":"","sources":["../src/knowledge-graph.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"knowledge-graph.d.ts","sourceRoot":"","sources":["../src/knowledge-graph.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EACL,KAAK,0BAA0B,EAC/B,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,eAAe,GAChB,MAAM,uCAAuC,CAAC"}
|
package/dist/knowledge-graph.js
CHANGED
|
@@ -1,268 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
|
-
import { join, relative } from "node:path";
|
|
4
|
-
//#region src/knowledge-graph.ts
|
|
5
|
-
/**
|
|
6
|
-
* Cross-package knowledge graph (#2863).
|
|
7
|
-
*
|
|
8
|
-
* Each package's own `smrt-knowledge.json` (see `knowledge.ts`) is a
|
|
9
|
-
* per-package projection. Nothing merges them, so cross-package invariants
|
|
10
|
-
* that the scanner manifest already carries — `@crossPackageRef` targets, STI
|
|
11
|
-
* parent/child pairs, junction/hierarchical/polymorphic base usage, and
|
|
12
|
-
* `_smrt_` system-table ownership — live only as prose in the root
|
|
13
|
-
* `AGENTS.md`. This module builds the merged, deterministic root artifact
|
|
14
|
-
* (`.smrt/smrt-knowledge-graph.json`) from whichever per-package artifacts
|
|
15
|
-
* are present, and checks it for staleness the same way `knowledge.ts` checks
|
|
16
|
-
* a package artifact: by comparing recorded `sourceHashes` against the
|
|
17
|
-
* current file content.
|
|
18
|
-
*
|
|
19
|
-
* This module never invents an edge: every edge is a direct read of a field
|
|
20
|
-
* already emitted into a package's `DomainKnowledgeManifest` (`related`,
|
|
21
|
-
* `tableStrategy`, `extends`, `relationshipFeatures`, `tableName`).
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Discovers every currently-buildable per-package artifact path under
|
|
25
|
-
* `<rootDir>/packages/*`, preferring the published `dist/smrt-knowledge.json`
|
|
26
|
-
* over the local dev `.smrt/smrt-knowledge.json` when both exist. Shared by
|
|
27
|
-
* the generator (which needs the manifest content) and the freshness check
|
|
28
|
-
* (which only needs to know whether the current SET of artifacts matches
|
|
29
|
-
* what the graph was built from — a newly built package, or a package that
|
|
30
|
-
* newly started exporting `./smrt-knowledge.json`, must mark the graph stale
|
|
31
|
-
* even though every artifact the graph already knows about is unchanged).
|
|
32
|
-
*/
|
|
33
|
-
function discoverKnowledgeArtifactPaths(rootDir) {
|
|
34
|
-
const packagesDir = join(rootDir, "packages");
|
|
35
|
-
if (!existsSync(packagesDir)) return [];
|
|
36
|
-
const paths = [];
|
|
37
|
-
for (const entry of readdirSync(packagesDir, { withFileTypes: true })) {
|
|
38
|
-
if (!entry.isDirectory()) continue;
|
|
39
|
-
const packageDir = join(packagesDir, entry.name);
|
|
40
|
-
const found = [join(packageDir, "dist", "smrt-knowledge.json"), join(packageDir, ".smrt", "smrt-knowledge.json")].find((path) => existsSync(path));
|
|
41
|
-
if (found) paths.push(relative(rootDir, found).split("\\").join("/"));
|
|
42
|
-
}
|
|
43
|
-
return paths.sort();
|
|
44
|
-
}
|
|
45
|
-
function hashContent(content) {
|
|
46
|
-
return createHash("sha256").update(content).digest("hex");
|
|
47
|
-
}
|
|
48
|
-
function objectId(packageName, object) {
|
|
49
|
-
return `${packageName}#${object.qualifiedName ?? object.name}`;
|
|
50
|
-
}
|
|
51
|
-
/** Builds the merged graph. Deterministic: every array is sorted. */
|
|
52
|
-
function buildKnowledgeGraph(inputs, options = {}) {
|
|
53
|
-
const sortedInputs = [...inputs].sort((a, b) => a.artifactPath.localeCompare(b.artifactPath));
|
|
54
|
-
const sourceHashes = {};
|
|
55
|
-
const packages = [];
|
|
56
|
-
const objects = [];
|
|
57
|
-
const edges = [];
|
|
58
|
-
const idByQualifiedName = /* @__PURE__ */ new Map();
|
|
59
|
-
const idBySimpleName = /* @__PURE__ */ new Map();
|
|
60
|
-
const idBySimpleNamePerPackage = /* @__PURE__ */ new Map();
|
|
61
|
-
for (const input of sortedInputs) {
|
|
62
|
-
const manifestPackageName = input.manifest.packageName ?? input.artifactPath;
|
|
63
|
-
for (const object of input.manifest.objects) {
|
|
64
|
-
const packageName = object.packageName ?? manifestPackageName;
|
|
65
|
-
const perPackage = idBySimpleNamePerPackage.get(packageName) ?? /* @__PURE__ */ new Map();
|
|
66
|
-
const id = objectId(packageName, object);
|
|
67
|
-
idByQualifiedName.set(object.qualifiedName ?? id, id);
|
|
68
|
-
const bySimple = idBySimpleName.get(object.name) ?? /* @__PURE__ */ new Set();
|
|
69
|
-
bySimple.add(id);
|
|
70
|
-
idBySimpleName.set(object.name, bySimple);
|
|
71
|
-
perPackage.set(object.name, id);
|
|
72
|
-
idBySimpleNamePerPackage.set(packageName, perPackage);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const resolveTarget = (raw, declaringPackageName) => {
|
|
76
|
-
if (!raw) return void 0;
|
|
77
|
-
if (idByQualifiedName.has(raw)) return idByQualifiedName.get(raw);
|
|
78
|
-
if (declaringPackageName) {
|
|
79
|
-
const sameId = idBySimpleNamePerPackage.get(declaringPackageName)?.get(raw);
|
|
80
|
-
if (sameId) return sameId;
|
|
81
|
-
}
|
|
82
|
-
const bySimple = idBySimpleName.get(raw);
|
|
83
|
-
if (bySimple && bySimple.size === 1) return [...bySimple][0];
|
|
84
|
-
};
|
|
85
|
-
const seenObjectIds = /* @__PURE__ */ new Set();
|
|
86
|
-
for (const input of sortedInputs) {
|
|
87
|
-
sourceHashes[input.artifactPath] = hashContent(stableStringify(input.manifest));
|
|
88
|
-
const packageName = input.manifest.packageName ?? input.artifactPath;
|
|
89
|
-
packages.push({
|
|
90
|
-
name: packageName,
|
|
91
|
-
version: input.manifest.packageVersion,
|
|
92
|
-
artifactPath: input.artifactPath,
|
|
93
|
-
tags: [...input.manifest.tags].sort(),
|
|
94
|
-
risks: [...input.manifest.risks].sort(),
|
|
95
|
-
summary: input.manifest.summary,
|
|
96
|
-
objectCount: input.manifest.objects.length
|
|
97
|
-
});
|
|
98
|
-
for (const object of input.manifest.objects) {
|
|
99
|
-
const objectPackageName = object.packageName ?? packageName;
|
|
100
|
-
const id = objectId(objectPackageName, object);
|
|
101
|
-
if (!seenObjectIds.has(id)) {
|
|
102
|
-
seenObjectIds.add(id);
|
|
103
|
-
objects.push({
|
|
104
|
-
id,
|
|
105
|
-
packageName: objectPackageName,
|
|
106
|
-
name: object.name,
|
|
107
|
-
qualifiedName: object.qualifiedName,
|
|
108
|
-
collection: object.collection,
|
|
109
|
-
tableName: object.tableName,
|
|
110
|
-
tableStrategy: object.tableStrategy,
|
|
111
|
-
extends: object.extends
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
for (const field of object.relationships) {
|
|
115
|
-
if (field.type !== "crossPackageRef") continue;
|
|
116
|
-
edges.push({
|
|
117
|
-
type: "crossPackageRef",
|
|
118
|
-
from: id,
|
|
119
|
-
to: resolveTarget(field.related) ?? field.related,
|
|
120
|
-
field: field.name
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
if (object.tableStrategy === "sti" && object.extends) edges.push({
|
|
124
|
-
type: "sti",
|
|
125
|
-
from: id,
|
|
126
|
-
to: resolveTarget(object.extends, objectPackageName) ?? `${objectPackageName}#${object.extends}`
|
|
127
|
-
});
|
|
128
|
-
for (const feature of object.relationshipFeatures) if (feature === "SmrtJunction") edges.push({
|
|
129
|
-
type: "junction",
|
|
130
|
-
from: id
|
|
131
|
-
});
|
|
132
|
-
else if (feature === "SmrtHierarchical") edges.push({
|
|
133
|
-
type: "hierarchical",
|
|
134
|
-
from: id
|
|
135
|
-
});
|
|
136
|
-
else if (feature === "SmrtPolymorphicAssociation") edges.push({
|
|
137
|
-
type: "polymorphic",
|
|
138
|
-
from: id
|
|
139
|
-
});
|
|
140
|
-
if (object.tableName?.startsWith("_smrt_")) edges.push({
|
|
141
|
-
type: "systemTable",
|
|
142
|
-
from: id,
|
|
143
|
-
to: object.tableName
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
packages.sort((a, b) => a.name.localeCompare(b.name));
|
|
148
|
-
objects.sort((a, b) => a.id.localeCompare(b.id));
|
|
149
|
-
edges.sort((a, b) => {
|
|
150
|
-
const key = (edge) => `${edge.type}|${edge.from}|${edge.to ?? ""}|${edge.field ?? ""}`;
|
|
151
|
-
return key(a).localeCompare(key(b));
|
|
152
|
-
});
|
|
153
|
-
const graph = {
|
|
154
|
-
schemaVersion: 1,
|
|
155
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
156
|
-
sourceHashes: sortRecord(sourceHashes),
|
|
157
|
-
packages,
|
|
158
|
-
objects,
|
|
159
|
-
edges
|
|
160
|
-
};
|
|
161
|
-
const { previousGraph } = options;
|
|
162
|
-
if (previousGraph && semanticGraphJson(previousGraph) === semanticGraphJson(graph)) return {
|
|
163
|
-
...graph,
|
|
164
|
-
generatedAt: previousGraph.generatedAt
|
|
165
|
-
};
|
|
166
|
-
return graph;
|
|
167
|
-
}
|
|
168
|
-
function semanticGraphJson(graph) {
|
|
169
|
-
const { generatedAt: _generatedAt, ...rest } = graph;
|
|
170
|
-
return stableStringify(rest);
|
|
171
|
-
}
|
|
172
|
-
/** Deterministic `JSON.stringify` — object keys are sorted at every level. */
|
|
173
|
-
function stableStringify(value) {
|
|
174
|
-
return JSON.stringify(sortValue(value));
|
|
175
|
-
}
|
|
176
|
-
function sortValue(value) {
|
|
177
|
-
if (Array.isArray(value)) return value.map(sortValue);
|
|
178
|
-
if (value && typeof value === "object") {
|
|
179
|
-
const sorted = Object.create(null);
|
|
180
|
-
for (const key of Object.keys(value).sort()) sorted[key] = sortValue(value[key]);
|
|
181
|
-
return sorted;
|
|
182
|
-
}
|
|
183
|
-
return value;
|
|
184
|
-
}
|
|
185
|
-
function sortRecord(record) {
|
|
186
|
-
const sorted = {};
|
|
187
|
-
for (const key of Object.keys(record).sort()) sorted[key] = record[key];
|
|
188
|
-
return sorted;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Checks the merged graph's recorded `sourceHashes` against the current
|
|
192
|
-
* content of each per-package artifact it was built from — the same pattern
|
|
193
|
-
* `knowledge.ts`/`smrt-dev-mcp` use for a single package's `sourceHashes`.
|
|
194
|
-
*
|
|
195
|
-
* `graphPath` and each `artifactPath` in the graph are resolved relative to
|
|
196
|
-
* `rootDir` (the repo root).
|
|
197
|
-
*/
|
|
198
|
-
function checkKnowledgeGraphFreshness(rootDir, graphPath, options = {}) {
|
|
199
|
-
const issues = [];
|
|
200
|
-
const absoluteGraphPath = `${rootDir}/${graphPath}`;
|
|
201
|
-
if (!existsSync(absoluteGraphPath)) {
|
|
202
|
-
if (!options.requireArtifact) return issues;
|
|
203
|
-
issues.push({
|
|
204
|
-
severity: "error",
|
|
205
|
-
code: "missing-knowledge-graph",
|
|
206
|
-
message: `${graphPath} does not exist; run \`pnpm knowledge:graph\``,
|
|
207
|
-
file: graphPath
|
|
208
|
-
});
|
|
209
|
-
return issues;
|
|
210
|
-
}
|
|
211
|
-
let graph;
|
|
212
|
-
try {
|
|
213
|
-
graph = JSON.parse(readFileSync(absoluteGraphPath, "utf8"));
|
|
214
|
-
} catch (error) {
|
|
215
|
-
issues.push({
|
|
216
|
-
severity: "error",
|
|
217
|
-
code: "stale-knowledge-graph",
|
|
218
|
-
message: `${graphPath} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,
|
|
219
|
-
file: graphPath
|
|
220
|
-
});
|
|
221
|
-
return issues;
|
|
222
|
-
}
|
|
223
|
-
const recordedPaths = Object.keys(graph.sourceHashes ?? {});
|
|
224
|
-
for (const [artifactPath, expectedHash] of Object.entries(graph.sourceHashes ?? {})) {
|
|
225
|
-
const absoluteArtifactPath = `${rootDir}/${artifactPath}`;
|
|
226
|
-
if (!existsSync(absoluteArtifactPath)) {
|
|
227
|
-
issues.push({
|
|
228
|
-
severity: "error",
|
|
229
|
-
code: "knowledge-graph-source-missing",
|
|
230
|
-
message: `${artifactPath} used to build ${graphPath} no longer exists`,
|
|
231
|
-
file: graphPath
|
|
232
|
-
});
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
let manifest;
|
|
236
|
-
try {
|
|
237
|
-
manifest = JSON.parse(readFileSync(absoluteArtifactPath, "utf8"));
|
|
238
|
-
} catch (error) {
|
|
239
|
-
issues.push({
|
|
240
|
-
severity: "error",
|
|
241
|
-
code: "stale-knowledge-graph",
|
|
242
|
-
message: `${artifactPath} is not valid JSON (${error instanceof Error ? error.message : String(error)}); run \`pnpm knowledge:graph\``,
|
|
243
|
-
file: graphPath
|
|
244
|
-
});
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (hashContent(stableStringify(manifest)) !== expectedHash) issues.push({
|
|
248
|
-
severity: "error",
|
|
249
|
-
code: "stale-knowledge-graph",
|
|
250
|
-
message: `${artifactPath} changed since ${graphPath} was generated; run \`pnpm knowledge:graph\``,
|
|
251
|
-
file: graphPath
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
const currentPaths = discoverKnowledgeArtifactPaths(rootDir);
|
|
255
|
-
const recordedSet = new Set(recordedPaths);
|
|
256
|
-
const newPaths = currentPaths.filter((path) => !recordedSet.has(path));
|
|
257
|
-
if (newPaths.length > 0) issues.push({
|
|
258
|
-
severity: "error",
|
|
259
|
-
code: "stale-knowledge-graph",
|
|
260
|
-
message: `${newPaths.join(", ")} ${newPaths.length === 1 ? "is a new package artifact" : "are new package artifacts"} not yet merged into ${graphPath}; run \`pnpm knowledge:graph\``,
|
|
261
|
-
file: graphPath
|
|
262
|
-
});
|
|
263
|
-
return issues;
|
|
264
|
-
}
|
|
265
|
-
//#endregion
|
|
1
|
+
import { buildKnowledgeGraph, checkKnowledgeGraphFreshness, discoverKnowledgeArtifactPaths, stableStringify } from "@happyvertical/smrt-scanner/knowledge";
|
|
266
2
|
export { buildKnowledgeGraph, checkKnowledgeGraphFreshness, discoverKnowledgeArtifactPaths, stableStringify };
|
|
267
|
-
|
|
268
|
-
//# sourceMappingURL=knowledge-graph.js.map
|
package/dist/knowledge.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SmartObjectManifest } from './scanner/types.js';
|
|
1
|
+
import { AGENT_SURFACE_HASH_PREFIX, MODULE_DOC_HASH_PREFIX, readAgentModuleDocs, resolveAgentModuleDocPaths } from '@happyvertical/smrt-scanner/knowledge';
|
|
3
2
|
export { discoverScopedPackageDirectories, readPackageAgentDoc, type ScopedPackageDirectory, } from './knowledge-discovery.js';
|
|
4
3
|
export { buildKnowledgeGraph, checkKnowledgeGraphFreshness, discoverKnowledgeArtifactPaths, type KnowledgeGraphEdge, type KnowledgeGraphEdgeType, type KnowledgeGraphFreshnessIssue, type KnowledgeGraphInput, type KnowledgeGraphObjectNode, type KnowledgeGraphPackageNode, type SmrtKnowledgeGraph, stableStringify, } from './knowledge-graph.js';
|
|
4
|
+
export { AGENT_SURFACE_HASH_PREFIX, MODULE_DOC_HASH_PREFIX, readAgentModuleDocs, resolveAgentModuleDocPaths, };
|
|
5
|
+
import type { DomainKnowledgeAgentSurface, DomainKnowledgeConfig, DomainKnowledgeManifest } from '@happyvertical/smrt-types';
|
|
6
|
+
import type { SmartObjectManifest } from './scanner/types.js';
|
|
5
7
|
/**
|
|
6
8
|
* Minimal package.json shape consumed by the knowledge builder.
|
|
7
9
|
* `name`/`version` are typed concretely because they flow into the manifest's
|
|
@@ -31,26 +33,5 @@ export interface BuildDomainKnowledgeOptions {
|
|
|
31
33
|
*/
|
|
32
34
|
agentSurface?: DomainKnowledgeAgentSurface;
|
|
33
35
|
}
|
|
34
|
-
/** `sourceHashes` key prefix for a linked module doc, e.g. `moduleDoc:agents/crm.md`. */
|
|
35
|
-
export declare const MODULE_DOC_HASH_PREFIX = "moduleDoc:";
|
|
36
|
-
/**
|
|
37
|
-
* `sourceHashes` key prefix for a module declaring a view intent or playbook,
|
|
38
|
-
* e.g. `agentSurface:src/lib/orders.intents.ts` (#2591).
|
|
39
|
-
*/
|
|
40
|
-
export declare const AGENT_SURFACE_HASH_PREFIX = "agentSurface:";
|
|
41
|
-
/**
|
|
42
|
-
* Module doc paths linked from a package's `AGENTS.md`, relative to the package
|
|
43
|
-
* root and in document order.
|
|
44
|
-
*
|
|
45
|
-
* Instruction chains are additive (see `scripts/check-agents-chain.mjs`), so an
|
|
46
|
-
* oversized package doc is split into `packages/<pkg>/agents/<module>.md` siblings
|
|
47
|
-
* instead of nested `AGENTS.md` files. Only links resolving to an existing file
|
|
48
|
-
* INSIDE the package are accepted — a cross-package reference such as
|
|
49
|
-
* `packages/affiliates/MIGRATION.md` belongs to that package's own chain and is
|
|
50
|
-
* ignored here.
|
|
51
|
-
*/
|
|
52
|
-
export declare function resolveAgentModuleDocPaths(rootDir: string, agentDoc: string | undefined): string[];
|
|
53
|
-
/** {@link resolveAgentModuleDocPaths}, with each doc's contents read. */
|
|
54
|
-
export declare function readAgentModuleDocs(rootDir: string, agentDoc: string | undefined): DomainKnowledgeModuleDoc[];
|
|
55
36
|
export declare function buildDomainKnowledgeManifest(options: BuildDomainKnowledgeOptions): DomainKnowledgeManifest;
|
|
56
37
|
//# sourceMappingURL=knowledge.d.ts.map
|
package/dist/knowledge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge.d.ts","sourceRoot":"","sources":["../src/knowledge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,mBAAmB,EACnB,KAAK,sBAAsB,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,eAAe,GAChB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"knowledge.d.ts","sourceRoot":"","sources":["../src/knowledge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EACL,gCAAgC,EAChC,mBAAmB,EACnB,KAAK,sBAAsB,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,GAC3B,CAAC;AAKF,OAAO,KAAK,EACV,2BAA2B,EAC3B,qBAAqB,EAGrB,uBAAuB,EAMxB,MAAM,2BAA2B,CAAC;AAanC,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,oBAAoB,CAAC;AAG5B;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,2BAA2B,CAAC;CAC5C;AA0CD,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,2BAA2B,GACnC,uBAAuB,CA0FzB"}
|
package/dist/knowledge.js
CHANGED
|
@@ -4,8 +4,9 @@ import { isFrameworkBaseClass } from "./registry/framework-base-classes.js";
|
|
|
4
4
|
import { discoverScopedPackageDirectories, readPackageAgentDoc } from "./knowledge-discovery.js";
|
|
5
5
|
import { buildKnowledgeGraph, checkKnowledgeGraphFreshness, discoverKnowledgeArtifactPaths, stableStringify } from "./knowledge-graph.js";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
|
-
import { existsSync, readFileSync, readdirSync
|
|
8
|
-
import {
|
|
7
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
8
|
+
import { join, relative } from "node:path";
|
|
9
|
+
import { AGENT_SURFACE_HASH_PREFIX, MODULE_DOC_HASH_PREFIX, readAgentModuleDocs, resolveAgentModuleDocPaths } from "@happyvertical/smrt-scanner/knowledge";
|
|
9
10
|
//#region src/knowledge.ts
|
|
10
11
|
var SDK_PACKAGE_NAMES = /* @__PURE__ */ new Set([
|
|
11
12
|
"@happyvertical/ai",
|
|
@@ -44,56 +45,6 @@ var RELATIONSHIP_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
|
44
45
|
* method while never being added as CRUD, dropping the surface entirely.
|
|
45
46
|
*/
|
|
46
47
|
var STANDARD_OPERATIONS = CRUD_OPERATIONS;
|
|
47
|
-
/**
|
|
48
|
-
* Markdown inline links whose target is a `.md` file — `[label](agents/x.md)`,
|
|
49
|
-
* tolerating an `#anchor` and a `"title"`. This is how a package registers a
|
|
50
|
-
* sibling module doc (#2108): the link in `AGENTS.md` IS the registration, so
|
|
51
|
-
* there is no separate index to drift out of sync.
|
|
52
|
-
*/
|
|
53
|
-
var MARKDOWN_MD_LINK = /\[[^\]]*\]\(\s*([^)\s#]+\.md)(?:#[^)\s]*)?(?:\s+"[^"]*")?\s*\)/g;
|
|
54
|
-
/** `sourceHashes` key prefix for a linked module doc, e.g. `moduleDoc:agents/crm.md`. */
|
|
55
|
-
var MODULE_DOC_HASH_PREFIX = "moduleDoc:";
|
|
56
|
-
/**
|
|
57
|
-
* `sourceHashes` key prefix for a module declaring a view intent or playbook,
|
|
58
|
-
* e.g. `agentSurface:src/lib/orders.intents.ts` (#2591).
|
|
59
|
-
*/
|
|
60
|
-
var AGENT_SURFACE_HASH_PREFIX = "agentSurface:";
|
|
61
|
-
/**
|
|
62
|
-
* Module doc paths linked from a package's `AGENTS.md`, relative to the package
|
|
63
|
-
* root and in document order.
|
|
64
|
-
*
|
|
65
|
-
* Instruction chains are additive (see `scripts/check-agents-chain.mjs`), so an
|
|
66
|
-
* oversized package doc is split into `packages/<pkg>/agents/<module>.md` siblings
|
|
67
|
-
* instead of nested `AGENTS.md` files. Only links resolving to an existing file
|
|
68
|
-
* INSIDE the package are accepted — a cross-package reference such as
|
|
69
|
-
* `packages/affiliates/MIGRATION.md` belongs to that package's own chain and is
|
|
70
|
-
* ignored here.
|
|
71
|
-
*/
|
|
72
|
-
function resolveAgentModuleDocPaths(rootDir, agentDoc) {
|
|
73
|
-
if (!agentDoc) return [];
|
|
74
|
-
const root = resolve(rootDir);
|
|
75
|
-
const paths = [];
|
|
76
|
-
for (const match of agentDoc.matchAll(MARKDOWN_MD_LINK)) {
|
|
77
|
-
const target = match[1];
|
|
78
|
-
if (target.includes("://")) continue;
|
|
79
|
-
const absolute = resolve(root, target);
|
|
80
|
-
if (absolute !== root && !absolute.startsWith(root + sep)) continue;
|
|
81
|
-
const relativePath = relative(root, absolute).split(sep).join("/");
|
|
82
|
-
if (relativePath === "AGENTS.md" || relativePath === "CLAUDE.md") continue;
|
|
83
|
-
if (paths.includes(relativePath)) continue;
|
|
84
|
-
if (!existsSync(absolute) || !statSync(absolute).isFile()) continue;
|
|
85
|
-
paths.push(relativePath);
|
|
86
|
-
}
|
|
87
|
-
return paths;
|
|
88
|
-
}
|
|
89
|
-
/** {@link resolveAgentModuleDocPaths}, with each doc's contents read. */
|
|
90
|
-
function readAgentModuleDocs(rootDir, agentDoc) {
|
|
91
|
-
return resolveAgentModuleDocPaths(rootDir, agentDoc).map((path) => ({
|
|
92
|
-
path,
|
|
93
|
-
module: basename(path, ".md"),
|
|
94
|
-
content: readFileSync(join(rootDir, path), "utf8")
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
48
|
function buildDomainKnowledgeManifest(options) {
|
|
98
49
|
const rootDir = options.rootDir;
|
|
99
50
|
const packageJson = options.packageJson ?? readPackageJson(rootDir) ?? {};
|