@happyvertical/smrt-core 0.51.32 → 0.51.34

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.
Files changed (172) hide show
  1. package/agents/build-knowledge.md +13 -0
  2. package/dist/__tests__/fixtures/collection-coverage-fixtures.d.ts +8 -0
  3. package/dist/__tests__/fixtures/inheritance-resolver-fixtures.d.ts +9 -0
  4. package/dist/__tests__/fixtures/inheritance-test-classes.d.ts +5 -0
  5. package/dist/__tests__/fixtures/object-ai-memory-fixtures.d.ts +10 -0
  6. package/dist/__typechecks__/collection-read-plan.d.ts +2 -2
  7. package/dist/adapters/ai-usage.d.ts +5 -2
  8. package/dist/adapters/cost-rates.d.ts +1 -1
  9. package/dist/adapters/metrics.d.ts +7 -1
  10. package/dist/adapters/pubsub.d.ts +7 -1
  11. package/dist/cascade.d.ts +69 -3
  12. package/dist/change-feed-authz.d.ts +85 -2
  13. package/dist/change-feed.d.ts +133 -2
  14. package/dist/change-signals.d.ts +66 -1
  15. package/dist/child-accessors.d.ts +39 -1
  16. package/dist/class.d.ts +8 -8
  17. package/dist/collection-cache.d.ts +47 -1
  18. package/dist/collection-read-plan.d.ts +3 -3
  19. package/dist/collection.d.ts +4 -3
  20. package/dist/config.d.ts +15 -6
  21. package/dist/consumer-plugin/index.d.ts +7 -3
  22. package/dist/consumer-plugin/index.d.ts.map +1 -1
  23. package/dist/consumer-plugin/index.js +2 -0
  24. package/dist/consumer-plugin/index.js.map +1 -1
  25. package/dist/data-query.d.ts +12 -1
  26. package/dist/database.d.ts +10 -2
  27. package/dist/decisions.d.ts +9 -2
  28. package/dist/decorators/index.d.ts +11 -5
  29. package/dist/dispatch/bus.d.ts +27 -2
  30. package/dist/dispatch/collections/DispatchSubscriptions.d.ts +7 -2
  31. package/dist/dispatch/collections/Dispatches.d.ts +8 -3
  32. package/dist/dispatch/models/Dispatch.d.ts +7 -1
  33. package/dist/dispatch/types.d.ts +7 -2
  34. package/dist/embedded-write-queue.d.ts +1 -1
  35. package/dist/embeddings/provider.d.ts +8 -1
  36. package/dist/embeddings/storage.d.ts +8 -2
  37. package/dist/filesystem-loader.d.ts +16 -1
  38. package/dist/generators/changes-route.d.ts +34 -1
  39. package/dist/generators/custom-action.d.ts +10 -2
  40. package/dist/generators/events-route.d.ts +41 -4
  41. package/dist/generators/mcp-runtime-template.d.ts +13 -2
  42. package/dist/generators/mcp.d.ts +6 -1
  43. package/dist/generators/rest.d.ts +10 -5
  44. package/dist/generators/tool-schema.d.ts +1 -1
  45. package/dist/hierarchical.d.ts +37 -1
  46. package/dist/interceptors.d.ts +45 -1
  47. package/dist/junction.d.ts +24 -0
  48. package/dist/knowledge-config.d.ts +1 -1
  49. package/dist/knowledge-discovery.d.ts +2 -25
  50. package/dist/knowledge-discovery.d.ts.map +1 -1
  51. package/dist/knowledge-discovery.js +1 -53
  52. package/dist/knowledge-graph.d.ts +2 -94
  53. package/dist/knowledge-graph.d.ts.map +1 -1
  54. package/dist/knowledge-graph.js +1 -267
  55. package/dist/knowledge.d.ts +4 -23
  56. package/dist/knowledge.d.ts.map +1 -1
  57. package/dist/knowledge.js +3 -52
  58. package/dist/knowledge.js.map +1 -1
  59. package/dist/learning/memory.d.ts +21 -1
  60. package/dist/manifest/generator.d.ts +5 -1
  61. package/dist/manifest/index.d.ts +5 -1
  62. package/dist/manifest/manager.d.ts +1 -1
  63. package/dist/manifest/manifest-loader.d.ts +24 -2
  64. package/dist/manifest/sources/composite.d.ts +17 -1
  65. package/dist/manifest/sources/embedded.d.ts +10 -1
  66. package/dist/manifest/sources/explicit-paths.d.ts +13 -1
  67. package/dist/manifest/sources/fallback.d.ts +15 -1
  68. package/dist/manifest/sources/local-test.d.ts +10 -1
  69. package/dist/manifest/sources/static.d.ts +12 -1
  70. package/dist/manifest/sources/test.d.ts +9 -1
  71. package/dist/manifest/sources/types.d.ts +7 -1
  72. package/dist/manifest/static-manifest.d.ts +6 -1
  73. package/dist/manifest/static-manifest.js +1 -1
  74. package/dist/manifest/static-manifest.js.map +1 -1
  75. package/dist/manifest/store.d.ts +22 -3
  76. package/dist/manifest/store.js +1 -1
  77. package/dist/manifest.json +1 -1
  78. package/dist/migrations/backfill-tracker.d.ts +15 -1
  79. package/dist/migrations/differ.d.ts +8 -2
  80. package/dist/migrations/framework-base-tables.d.ts +57 -2
  81. package/dist/migrations/generator.d.ts +8 -2
  82. package/dist/migrations/integer-width.d.ts +10 -2
  83. package/dist/migrations/minor-units.d.ts +40 -1
  84. package/dist/migrations/null-equal-indexes.d.ts +3 -2
  85. package/dist/migrations/orchestrate.d.ts +15 -3
  86. package/dist/migrations/sqlite-rebuild.d.ts +67 -2
  87. package/dist/migrations/tracker.d.ts +9 -3
  88. package/dist/migrations/types.d.ts +7 -2
  89. package/dist/object.d.ts +7 -6
  90. package/dist/polymorphic-association.d.ts +44 -1
  91. package/dist/postgres-permissions.d.ts +1 -1
  92. package/dist/prebuild/index.d.ts +5 -1
  93. package/dist/query-bounds.d.ts +26 -0
  94. package/dist/registry/cache-config.d.ts +10 -1
  95. package/dist/registry/class-registration.d.ts +10 -2
  96. package/dist/registry/collection-resolution.d.ts +1 -1
  97. package/dist/registry/embedding-manager.d.ts +9 -1
  98. package/dist/registry/inheritance-resolver.d.ts +8 -3
  99. package/dist/registry/manifest-field-merge.d.ts +2 -2
  100. package/dist/registry/name-resolver.d.ts +22 -2
  101. package/dist/registry/relationship-graph.d.ts +9 -1
  102. package/dist/registry/schema-builder.d.ts +8 -3
  103. package/dist/registry/shared-state.d.ts +12 -2
  104. package/dist/registry/types.d.ts +15 -7
  105. package/dist/registry/validator.d.ts +10 -2
  106. package/dist/registry.d.ts +40 -11
  107. package/dist/relationship-loader.d.ts +1 -1
  108. package/dist/run-once.d.ts +110 -1
  109. package/dist/runtime/client.d.ts +4 -1
  110. package/dist/runtime/server.d.ts +5 -2
  111. package/dist/scanner/import-scanner.d.ts +1 -1
  112. package/dist/scanner/manifest-generator.d.ts +4 -1
  113. package/dist/scanner/types.d.ts +4 -1
  114. package/dist/schema/code-generator.d.ts +6 -2
  115. package/dist/schema/column-data-probes.d.ts +27 -2
  116. package/dist/schema/ddl/base-strategy.d.ts +8 -2
  117. package/dist/schema/ddl/duckdb-strategy.d.ts +14 -2
  118. package/dist/schema/ddl/index.d.ts +2 -2
  119. package/dist/schema/ddl/json-duckdb-strategy.d.ts +10 -2
  120. package/dist/schema/ddl/materialize-manifest.d.ts +1 -1
  121. package/dist/schema/ddl/null-equal-index.d.ts +1 -1
  122. package/dist/schema/ddl/postgres-strategy.d.ts +12 -2
  123. package/dist/schema/ddl/sqlite-strategy.d.ts +12 -2
  124. package/dist/schema/ddl/types.d.ts +10 -1
  125. package/dist/schema/foreign-key-ddl.d.ts +2 -2
  126. package/dist/schema/foreign-key-orphan-report.d.ts +25 -3
  127. package/dist/schema/foreign-key-planner.d.ts +2 -2
  128. package/dist/schema/foreign-key-policy.d.ts +1 -1
  129. package/dist/schema/generator.d.ts +7 -3
  130. package/dist/schema/index-utils.d.ts +11 -2
  131. package/dist/schema/live-parity.d.ts +27 -3
  132. package/dist/schema/manifest-schema.d.ts +21 -2
  133. package/dist/schema/schema-aggregator.d.ts +35 -2
  134. package/dist/schema/schema-manager.d.ts +13 -4
  135. package/dist/schema/system-table-shapes.d.ts +20 -1
  136. package/dist/schema/table-verifier.d.ts +1 -1
  137. package/dist/schema/text-cast-probe.d.ts +24 -1
  138. package/dist/schema/utils.d.ts +13 -4
  139. package/dist/schema/uuid-convergence.d.ts +32 -1
  140. package/dist/signals/bus.d.ts +8 -2
  141. package/dist/signals/sanitizer.d.ts +7 -1
  142. package/dist/smrt-knowledge.json +8 -9
  143. package/dist/system/bootstrap.d.ts +2 -1
  144. package/dist/system/compatibility.d.ts +1 -1
  145. package/dist/system/diagnostics.d.ts +17 -2
  146. package/dist/system/retention.d.ts +46 -1
  147. package/dist/system/schema.d.ts +7 -1
  148. package/dist/system-fields.d.ts +9 -1
  149. package/dist/test-utils.d.ts +7 -1
  150. package/dist/testing/database.d.ts +18 -1
  151. package/dist/testing/notifications-stub.d.ts +15 -1
  152. package/dist/tools/tool-executor.d.ts +6 -1
  153. package/dist/tools/tool-generator.d.ts +8 -2
  154. package/dist/utils/json.d.ts +9 -1
  155. package/dist/utils/qualified-names.d.ts +10 -1
  156. package/dist/utils/scanner-module.d.ts +2 -2
  157. package/dist/utils.d.ts +1 -1
  158. package/dist/vite-plugin/api-client-entries.d.ts +9 -1
  159. package/dist/vite-plugin/changes-route.d.ts +33 -2
  160. package/dist/vite-plugin/dev-plane-route.d.ts +12 -1
  161. package/dist/vite-plugin/events-route.d.ts +37 -2
  162. package/dist/vite-plugin/generated-client.d.ts +9 -1
  163. package/dist/vite-plugin/index.d.ts +9 -5
  164. package/dist/vite-plugin/resources-route.d.ts +82 -1
  165. package/dist/vite-plugin/sveltekit-generator.d.ts +8 -4
  166. package/dist/vite-plugin/sveltekit-route-coordinator.d.ts +3 -3
  167. package/dist/vite-plugin/sync-apply-route.d.ts +19 -2
  168. package/dist/vite-plugin/web-collections.d.ts +25 -2
  169. package/dist/vite-plugin/worker-registration.d.ts +21 -1
  170. package/package.json +7 -8
  171. package/dist/knowledge-discovery.js.map +0 -1
  172. package/dist/knowledge-graph.js.map +0 -1
@@ -1,5 +1,10 @@
1
- import { DatabaseInterface } from '@happyvertical/sql';
2
- import { DispatchTenantScope } from './tenant-resolver.js';
1
+ /**
2
+ * Type definitions for the Dispatch system
3
+ *
4
+ * Provides inter-agent communication through persistent dispatch messages.
5
+ */
6
+ import type { DatabaseInterface } from '@happyvertical/sql';
7
+ import type { DispatchTenantScope } from './tenant-resolver.js';
3
8
  /**
4
9
  * Dispatch message status
5
10
  */
@@ -1,4 +1,4 @@
1
- import { DatabaseInterface } from '@happyvertical/sql';
1
+ import { type DatabaseInterface } from '@happyvertical/sql';
2
2
  interface QueueableDatabase {
3
3
  url?: string;
4
4
  }
@@ -1,4 +1,11 @@
1
- import { EmbeddingProviderType, ProjectEmbeddingConfig } from './types';
1
+ /**
2
+ * Embedding Provider
3
+ *
4
+ * Unified interface for generating embeddings using local models or AI APIs.
5
+ * Supports transformers.js packages for local inference and @happyvertical/ai
6
+ * for cloud embeddings.
7
+ */
8
+ import type { EmbeddingProviderType, ProjectEmbeddingConfig } from './types';
2
9
  export type OptionalModuleImporter = (moduleName: string) => Promise<unknown>;
3
10
  export declare const LOCAL_TRANSFORMERS_PACKAGES: readonly ["@huggingface/transformers", "@xenova/transformers"];
4
11
  export type LocalTransformersPackage = (typeof LOCAL_TRANSFORMERS_PACKAGES)[number];
@@ -1,5 +1,11 @@
1
- import { DatabaseInterface, VectorCapabilities } from '@happyvertical/sql';
2
- import { StoredEmbedding } from './types';
1
+ /**
2
+ * Embedding Storage Operations
3
+ *
4
+ * CRUD operations for the _smrt_embeddings system table.
5
+ * Supports both JSON-based and native vector storage strategies.
6
+ */
7
+ import type { DatabaseInterface, VectorCapabilities } from '@happyvertical/sql';
8
+ import type { StoredEmbedding } from './types';
3
9
  /**
4
10
  * Storage operations for embeddings in _smrt_embeddings table
5
11
  */
@@ -1,4 +1,19 @@
1
- import { FilesystemAdapter, FilesystemAdapterOptions } from '@happyvertical/files';
1
+ /**
2
+ * Filesystem adapter acquisition boundary.
3
+ *
4
+ * `@happyvertical/files` statically imports @aws-sdk/client-s3 and reaches
5
+ * googleapis from its root, so SmrtClass must not import it eagerly — that
6
+ * single edge put the whole files SDK into every downstream SSR bundle
7
+ * (#1977/#1978). Filesystem support is acquired here instead:
8
+ *
9
+ * - Runtimes with node_modules (Node, tsx, vite dev, externalized SSR) work
10
+ * unchanged: the adapter is loaded on first use via a bundler-invisible
11
+ * import.
12
+ * - Fully-bundled deployments opt in explicitly with
13
+ * `import '@happyvertical/smrt-core/filesystem'` at server startup, which
14
+ * registers the statically-imported adapter factory.
15
+ */
16
+ import type { FilesystemAdapter, FilesystemAdapterOptions } from '@happyvertical/files';
2
17
  export type FilesystemAdapterFactory = (options: FilesystemAdapterOptions) => Promise<FilesystemAdapter>;
3
18
  /**
4
19
  * Registers the factory used to satisfy `fs` options on SmrtClass instances.
@@ -1,4 +1,37 @@
1
- import { DatabaseInterface } from '@happyvertical/sql';
1
+ /**
2
+ * Generated `_changes` HTTP route for the change feed (issue #1758).
3
+ *
4
+ * Handles `GET {basePath}/_changes` in the REST generator: an auth-guarded,
5
+ * tenant-scoped cursor read over the `_smrt_changes` log. This module keeps
6
+ * the feed logic out of `rest.ts` (which only registers the path) so
7
+ * sibling generator changes stay conflict-free.
8
+ *
9
+ * Contract (part of the client/mobile sync contract, PRD #1755):
10
+ * - `GET {basePath}/_changes?since=<cursor>&tables=<a,b>&limit=<n>` returns
11
+ * `{ changes, cursor, resyncRequired?, resyncCursor? }` — see
12
+ * `getChangesSince` for the exact cursor guarantee (strictly monotonic;
13
+ * reads miss no committed changes under concurrent writers).
14
+ * `resyncRequired: true` — served as HTTP 200, it is protocol state rather
15
+ * than an error — means the cursor cannot be served incrementally (pruned
16
+ * out of the retained window, or foreign/reset) and the client must
17
+ * re-fetch its data in full, then resume from `resyncCursor`.
18
+ * - **Auth is fail-closed** (#1540 posture): the route requires the
19
+ * generator's `authMiddleware`. Without one configured, every request is
20
+ * refused with 401 — the feed spans all tables, so per-model
21
+ * `api: { public }` opt-outs deliberately do NOT apply to it.
22
+ * - **Tenant scoping** follows the active tenant context through the same
23
+ * dependency-inversion hook the DispatchBus uses: with tenancy enabled, a
24
+ * request only ever sees its own tenant's changes plus global rows; with
25
+ * tenancy enabled but no active tenant, only global rows (fail-closed).
26
+ * - **Table/row authorization** (#3020): the read additionally applies the
27
+ * consumer-supplied `authorizeChangeFeed`/`isChangeFeedEntryVisible` hooks,
28
+ * if registered (`change-feed-authz.ts`), via
29
+ * `getAuthorizedTenantScopedChangesSince()`. REST has no `locals`, so the
30
+ * hooks receive `locals: undefined` and the `authMiddleware`-processed
31
+ * `Request` as `request` — a REST-hosting consumer identifies the principal
32
+ * from `request`. Unregistered, behavior is unchanged from pre-#3020.
33
+ */
34
+ import type { DatabaseInterface } from '@happyvertical/sql';
2
35
  /**
3
36
  * Structural copy of `APIConfig['authMiddleware']` (from `rest.ts`) so this
4
37
  * module never imports the generator back (keeps the dependency one-way).
@@ -1,5 +1,13 @@
1
- import { ApiHttpMethod, ToolEffect } from '../registry/types.js';
2
- import { MethodDefinition, SmartObjectManifest } from '../scanner/types.js';
1
+ /**
2
+ * Canonical custom-action metadata and transport-safe result helpers.
3
+ *
4
+ * Custom actions are intentionally distinct from generated CRUD. Their target
5
+ * is derived from method metadata: instance methods target an item and static
6
+ * methods target the collection. API route configuration may shape an HTTP
7
+ * route, but it cannot change a method's receiver.
8
+ */
9
+ import type { ApiHttpMethod, ToolEffect } from '../registry/types.js';
10
+ import type { MethodDefinition, SmartObjectManifest } from '../scanner/types.js';
3
11
  export type CustomActionScope = 'item' | 'collection';
4
12
  export type { ToolEffect } from '../registry/types.js';
5
13
  /**
@@ -1,7 +1,44 @@
1
- import { DatabaseInterface } from '@happyvertical/sql';
2
- import { ChangeSignal } from '../change-signals.js';
3
- import { DispatchTenantScope } from '../dispatch/tenant-resolver.js';
4
- import { ChangesAuthMiddleware } from './changes-route.js';
1
+ /**
2
+ * Generated `_events` SSE route — live change signals (issue #1763, SERVER
3
+ * half; parent PRD #1755).
4
+ *
5
+ * Handles `GET {basePath}/_events` in the REST generator: an auth-guarded,
6
+ * tenant-scoped Server-Sent-Events stream of coarse change signals ({table,
7
+ * operation, rowId, tenantId} + a `seq` cursor in the SSE `id:` field). It is
8
+ * the push companion to the pull-based `_changes` route (#1758): a subscriber
9
+ * reacts to a signal by re-reading through the authorized collection routes,
10
+ * so **no row payload ever crosses this channel** — authorization stays
11
+ * entirely on the read path.
12
+ *
13
+ * The stream lifecycle (subscribe, catch-up replay, heartbeat, teardown) lives
14
+ * in {@link buildChangeEventStream} so it is written and tested once; both the
15
+ * REST generator here and the generated SvelteKit route import it. `rest.ts`
16
+ * only registers the path.
17
+ *
18
+ * Contract:
19
+ * - **Fail-closed auth** (identical to `_changes`, #1540 posture): no
20
+ * `authMiddleware` configured → 401; the middleware may return a Response to
21
+ * short-circuit (e.g. 403). The feed spans every table, so per-model
22
+ * `api: { public }` opt-outs deliberately do not apply.
23
+ * - **Tenant scope is captured ONCE at connection open** — signal delivery
24
+ * happens from a different async context (the writer's afterSave, possibly
25
+ * another request or replica) with no tenant ALS active, so the filter must
26
+ * be the value resolved at subscribe time, not re-resolved per signal.
27
+ * - **Cross-origin is opt-in** (#1861): `rest.ts` now wraps `_events` in its
28
+ * CORS layer. With the fail-closed default it stays same-origin only, but
29
+ * when the generator is configured with `enableCors`, an `allowedOrigins`
30
+ * allowlist, and `allowCredentials: true`, an allow-listed cross-origin
31
+ * browser client can subscribe with a credentialed `EventSource`
32
+ * (`withCredentials: true`) — the response echoes the specific origin (never
33
+ * `*`) plus `Access-Control-Allow-Credentials: true`, so its cookies reach
34
+ * the same fail-closed auth guard. The CORS layer only lets the cookie
35
+ * through; it never authorizes — the auth middleware + captured tenant scope
36
+ * are unchanged, so the read posture holds identically across origins.
37
+ */
38
+ import type { DatabaseInterface } from '@happyvertical/sql';
39
+ import { type ChangeSignal } from '../change-signals.js';
40
+ import { type DispatchTenantScope } from '../dispatch/tenant-resolver.js';
41
+ import { type ChangesAuthMiddleware } from './changes-route.js';
5
42
  /** Options for the `_events` route handler. */
6
43
  export interface EventsRouteOptions {
7
44
  /** The generator's configured auth middleware, if any. */
@@ -1,5 +1,16 @@
1
- import { CustomActionScope } from './custom-action.js';
2
- import { MCPConfig, MCPContext } from './mcp.js';
1
+ /**
2
+ * Runtime bootstrap template for generated MCP servers
3
+ *
4
+ * This template provides stdio transport integration for SMRT-generated MCP servers.
5
+ * It handles:
6
+ * - Server initialization with @modelcontextprotocol/server v2
7
+ * - Tool registration from MCPGenerator
8
+ * - Stdio transport connection
9
+ * - Error handling and logging
10
+ * - Graceful shutdown
11
+ */
12
+ import type { CustomActionScope } from './custom-action.js';
13
+ import type { MCPConfig, MCPContext } from './mcp.js';
3
14
  export interface RuntimeOptions {
4
15
  /** Server name (defaults to package name) */
5
16
  name?: string;
@@ -1,4 +1,9 @@
1
- import { ToolJsonSchema } from './tool-schema.js';
1
+ /**
2
+ * MCP (Model Context Protocol) server generator for smrt objects
3
+ *
4
+ * Exposes smrt objects as AI tools for Claude, GPT, and other AI models
5
+ */
6
+ import { type ToolJsonSchema } from './tool-schema.js';
2
7
  /**
3
8
  * Runtime tool-call arguments. They arrive as untyped JSON from the MCP client,
4
9
  * so individual keys are narrowed (`as`) at each action's boundary.
@@ -1,8 +1,13 @@
1
- import { default as http } from 'node:http';
2
- import { SmrtCollection } from '../collection';
3
- import { SmrtObject } from '../object';
4
- import { RegisteredClass } from '../registry/types';
5
- import { PlaybookPreflightProvider } from './preflight-route';
1
+ /**
2
+ * High-performance REST API generator for smrt objects using Node.js HTTP server
3
+ *
4
+ * Designed for minimal bundle size and maximum performance
5
+ */
6
+ import http from 'node:http';
7
+ import type { SmrtCollection } from '../collection';
8
+ import type { SmrtObject } from '../object';
9
+ import type { RegisteredClass } from '../registry/types';
10
+ import { type PlaybookPreflightProvider } from './preflight-route';
6
11
  export interface APIConfig {
7
12
  basePath?: string;
8
13
  enableCors?: boolean;
@@ -1,4 +1,4 @@
1
- import { CustomActionMetadata, ToolEffect } from './custom-action.js';
1
+ import { type CustomActionMetadata, type ToolEffect } from './custom-action.js';
2
2
  /**
3
3
  * Transport-agnostic tool-descriptor builder (#1812, tracer).
4
4
  *
@@ -1,4 +1,40 @@
1
- import { SmrtCollection } from './collection';
1
+ /**
2
+ * SmrtHierarchical — base class for self-referencing tree hierarchies.
3
+ *
4
+ * Provides batched parent/children/ancestors/descendants/hierarchy traversal
5
+ * and a cycle-safe `moveTo`. Replaces five copies of the same logic across
6
+ * Place, Event, Tag, Account, and Zone.
7
+ *
8
+ * Examples in the monorepo:
9
+ *
10
+ * | Subclass | Domain |
11
+ * |----------|------------------------------------------------|
12
+ * | Place | hierarchical geographic places |
13
+ * | Event | nestable event hierarchy (game → period → …) |
14
+ * | Tag | tag taxonomies and category trees |
15
+ * | Account | chart of accounts |
16
+ * | Zone | placement zones inside a digital property |
17
+ *
18
+ * Convention: every subclass uses `parentId: string | null` referencing
19
+ * another row in the same table (or STI base table) by UUID. Classes whose
20
+ * self-reference has different semantics — e.g. `Fact.previousFactId` (an
21
+ * evolution chain) or `Asset.sourceAssetId` (a derivation DAG) — should
22
+ * NOT extend SmrtHierarchical. Use descriptive names and class-specific
23
+ * methods instead.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * @smrt({ tableStrategy: 'sti', api: true })
28
+ * export class Place extends SmrtHierarchical {
29
+ * name = '';
30
+ * }
31
+ *
32
+ * const ancestors = await place.getAncestors();
33
+ * const descendants = await place.getDescendants(); // BFS, one query per level
34
+ * await place.moveTo(newParent); // cycle-checked
35
+ * ```
36
+ */
37
+ import type { SmrtCollection } from './collection';
2
38
  import { SmrtObject } from './object';
3
39
  /**
4
40
  * Aggregate hierarchy view: ancestors (root-first), self, and all descendants
@@ -1,4 +1,48 @@
1
- import { SmrtObject } from './object.js';
1
+ /**
2
+ * Global Interceptors System for SMRT Collections and Objects
3
+ *
4
+ * Provides a plugin architecture for intercepting collection and object operations.
5
+ * This enables external packages (like @happyvertical/smrt-tenancy) to register
6
+ * interceptors without creating circular dependencies.
7
+ *
8
+ * Pattern: Static methods on GlobalInterceptors class with globalThis state
9
+ * (matches ObjectRegistry pattern for cross-module state sharing)
10
+ *
11
+ * @example Basic interceptor registration
12
+ * ```typescript
13
+ * import { GlobalInterceptors } from '@happyvertical/smrt-core';
14
+ *
15
+ * // Register a beforeList interceptor
16
+ * GlobalInterceptors.register({
17
+ * beforeList(className, options) {
18
+ * console.log(`Listing ${className}`);
19
+ * return options; // Return modified options
20
+ * }
21
+ * });
22
+ * ```
23
+ *
24
+ * @example Tenancy interceptor (from smrt-tenancy)
25
+ * ```typescript
26
+ * GlobalInterceptors.register({
27
+ * beforeList(className, options, context) {
28
+ * const tenantId = getCurrentTenantId();
29
+ * if (tenantId && isTenantScoped(className)) {
30
+ * return {
31
+ * ...options,
32
+ * where: { ...options.where, tenantId }
33
+ * };
34
+ * }
35
+ * return options;
36
+ * },
37
+ * beforeSave(instance, context) {
38
+ * // Validate tenant on save
39
+ * }
40
+ * });
41
+ * ```
42
+ *
43
+ * @see https://github.com/happyvertical/smrt/issues/675
44
+ */
45
+ import type { SmrtObject } from './object.js';
2
46
  /**
3
47
  * Context passed to interceptors with operation metadata
4
48
  */
@@ -1,3 +1,27 @@
1
+ /**
2
+ * SmrtJunction — base class for two-sided junction (many-to-many) collections.
3
+ *
4
+ * A junction collection manages rows that link a "left" entity to a "right" entity,
5
+ * typically with discriminator fields (relationship/role) and an optional sortOrder.
6
+ * Examples in the monorepo:
7
+ *
8
+ * | Subclass | Left field | Right field | Discriminator |
9
+ * |--------------------------------|---------------|-------------|-----------------|
10
+ * | ContentAssetCollection | contentId | assetId | relationship |
11
+ * | PerformerOwnedAssetCollection | performerId | assetId | role |
12
+ * | PlaceAssetCollection | placeId | assetId | relationship |
13
+ * | EventParticipantCollection | eventId | profileId | role |
14
+ * | FactContentCollection | factId | contentId | relationship |
15
+ *
16
+ * Each subclass declares `leftField` / `rightField` (camelCase) and optionally
17
+ * overrides `sortField` (defaults to `'sortOrder'`; set `null` to disable ORDER BY).
18
+ *
19
+ * Polymorphic subclasses (where "left" or "right" is a composite key like
20
+ * `metaType + metaId`) may override `byLeft` / `byRight` / `attach` / `detach`
21
+ * with diverging signatures — see `AssetAssociationCollection` for a reference.
22
+ *
23
+ * @typeParam TItem - The junction row class (extends `SmrtObject`)
24
+ */
1
25
  import { SmrtCollection } from './collection';
2
26
  import { SmrtObject } from './object';
3
27
  /**
@@ -1,4 +1,4 @@
1
- import { DomainKnowledgeConfig } from '@happyvertical/smrt-types';
1
+ import type { DomainKnowledgeConfig } from '@happyvertical/smrt-types';
2
2
  export declare const DEFAULT_KNOWLEDGE_CONFIG: DomainKnowledgeConfig;
3
3
  /** Resolve the file and package portions of the documented knowledge precedence. */
4
4
  export declare function resolveFileKnowledgeConfig(rootDir: string, packageName: string | undefined): Promise<DomainKnowledgeConfig>;
@@ -1,26 +1,3 @@
1
- export interface ScopedPackageDirectory {
2
- /** Scope entry name; consumers may select by alias rather than manifest name. */
3
- name: string;
4
- /** Original node_modules path, retained for workspace-relative reporting. */
5
- directory: string;
6
- /** Resolved path for identity comparisons or absolute snapshot links. */
7
- realDirectory: string;
8
- }
9
- /**
10
- * Enumerate scope entries without descending into pnpm's linked dependency graph.
11
- * Selection, workspace discovery and enrichment remain caller policies.
12
- */
13
- export declare function discoverScopedPackageDirectories(scopeDirectories: string[]): ScopedPackageDirectory[];
14
- /** Read authored docs only; never load artifacts, package code or object scans. */
15
- export declare function readPackageAgentDoc(directory: string, options?: {
16
- inspectAdapter?: boolean;
17
- }): {
18
- hasAgentsMd: boolean;
19
- hasClaudeMd: boolean;
20
- hasClaudeShim: boolean;
21
- agentsContent: string;
22
- claudeContent: string;
23
- source: "AGENTS.md" | "CLAUDE.md" | null;
24
- content: string | null;
25
- };
1
+ /** Compatibility exports; filesystem knowledge is owned by the lightweight scanner. */
2
+ export { discoverScopedPackageDirectories, readPackageAgentDoc, type ScopedPackageDirectory, } from '@happyvertical/smrt-scanner/knowledge';
26
3
  //# sourceMappingURL=knowledge-discovery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"knowledge-discovery.d.ts","sourceRoot":"","sources":["../src/knowledge-discovery.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,sBAAsB;IACrC,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,CAC9C,gBAAgB,EAAE,MAAM,EAAE,GACzB,sBAAsB,EAAE,CAwB1B;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;;;;EA0B3C"}
1
+ {"version":3,"file":"knowledge-discovery.d.ts","sourceRoot":"","sources":["../src/knowledge-discovery.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,OAAO,EACL,gCAAgC,EAChC,mBAAmB,EACnB,KAAK,sBAAsB,GAC5B,MAAM,uCAAuC,CAAC"}
@@ -1,54 +1,2 @@
1
- import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
2
- import { join } from "node:path";
3
- //#region src/knowledge-discovery.ts
4
- /**
5
- * Enumerate scope entries without descending into pnpm's linked dependency graph.
6
- * Selection, workspace discovery and enrichment remain caller policies.
7
- */
8
- function discoverScopedPackageDirectories(scopeDirectories) {
9
- const packages = [];
10
- for (const scopeDirectory of new Set(scopeDirectories)) {
11
- let entries;
12
- try {
13
- entries = readdirSync(scopeDirectory, { withFileTypes: true });
14
- } catch {
15
- continue;
16
- }
17
- for (const entry of entries) {
18
- if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
19
- const directory = join(scopeDirectory, entry.name);
20
- try {
21
- packages.push({
22
- name: entry.name,
23
- directory,
24
- realDirectory: realpathSync(directory)
25
- });
26
- } catch {}
27
- }
28
- }
29
- return packages;
30
- }
31
- /** Read authored docs only; never load artifacts, package code or object scans. */
32
- function readPackageAgentDoc(directory, options = {}) {
33
- const agentsPath = join(directory, "AGENTS.md");
34
- const claudePath = join(directory, "CLAUDE.md");
35
- const hasAgentsMd = existsSync(agentsPath);
36
- const hasClaudeMd = existsSync(claudePath);
37
- const agentsContent = hasAgentsMd ? readFileSync(agentsPath, "utf8") : "";
38
- const claudeContent = hasClaudeMd && (!hasAgentsMd || options.inspectAdapter) ? readFileSync(claudePath, "utf8") : "";
39
- const hasClaudeShim = hasClaudeMd && claudeContent.trim() === "@AGENTS.md";
40
- const source = hasAgentsMd ? "AGENTS.md" : hasClaudeMd && !hasClaudeShim ? "CLAUDE.md" : null;
41
- return {
42
- hasAgentsMd,
43
- hasClaudeMd,
44
- hasClaudeShim,
45
- agentsContent,
46
- claudeContent,
47
- source,
48
- content: hasAgentsMd ? agentsContent : source ? claudeContent : null
49
- };
50
- }
51
- //#endregion
1
+ import { discoverScopedPackageDirectories, readPackageAgentDoc } from "@happyvertical/smrt-scanner/knowledge";
52
2
  export { discoverScopedPackageDirectories, readPackageAgentDoc };
53
-
54
- //# sourceMappingURL=knowledge-discovery.js.map
@@ -1,95 +1,3 @@
1
- import { DomainKnowledgeManifest } from '@happyvertical/smrt-types';
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;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAexE;AAED,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,uBAAuB,CAAC;CACnC;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,8EAA8E;IAC9E,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,sBAAsB,GAC9B,iBAAiB,GACjB,KAAK,GACL,UAAU,GACV,cAAc,GACd,aAAa,GACb,aAAa,CAAC;AAElB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,CAAC,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,EAAE,yBAAyB,EAAE,CAAC;IACtC,OAAO,EAAE,wBAAwB,EAAE,CAAC;IACpC,KAAK,EAAE,kBAAkB,EAAE,CAAC;CAC7B;AAUD,MAAM,WAAW,0BAA0B;IACzC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,mBAAmB,EAAE,EAC7B,OAAO,GAAE,0BAA+B,GACvC,kBAAkB,CAoKpB;AAOD,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD;AA+BD,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,IAAI,EACA,yBAAyB,GACzB,uBAAuB,GACvB,gCAAgC,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GAC1C,4BAA4B,EAAE,CA0FhC"}
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"}