trellis 2.0.13 → 2.1.2

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 (96) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/embeddings/index.js +1 -1
  3. package/dist/{index-7gvjxt27.js → index-2917tjd8.js} +1 -1
  4. package/package.json +2 -10
  5. package/dist/transformers.node-bx3q9d7k.js +0 -33130
  6. package/src/cli/index.ts +0 -3356
  7. package/src/core/agents/harness.ts +0 -380
  8. package/src/core/agents/index.ts +0 -18
  9. package/src/core/agents/types.ts +0 -90
  10. package/src/core/index.ts +0 -118
  11. package/src/core/kernel/middleware.ts +0 -44
  12. package/src/core/kernel/trellis-kernel.ts +0 -593
  13. package/src/core/ontology/builtins.ts +0 -248
  14. package/src/core/ontology/index.ts +0 -34
  15. package/src/core/ontology/registry.ts +0 -209
  16. package/src/core/ontology/types.ts +0 -124
  17. package/src/core/ontology/validator.ts +0 -382
  18. package/src/core/persist/backend.ts +0 -74
  19. package/src/core/persist/sqlite-backend.ts +0 -298
  20. package/src/core/plugins/index.ts +0 -17
  21. package/src/core/plugins/registry.ts +0 -322
  22. package/src/core/plugins/types.ts +0 -126
  23. package/src/core/query/datalog.ts +0 -188
  24. package/src/core/query/engine.ts +0 -370
  25. package/src/core/query/index.ts +0 -34
  26. package/src/core/query/parser.ts +0 -481
  27. package/src/core/query/types.ts +0 -200
  28. package/src/core/store/eav-store.ts +0 -467
  29. package/src/decisions/auto-capture.ts +0 -136
  30. package/src/decisions/hooks.ts +0 -163
  31. package/src/decisions/index.ts +0 -261
  32. package/src/decisions/types.ts +0 -103
  33. package/src/embeddings/auto-embed.ts +0 -248
  34. package/src/embeddings/chunker.ts +0 -327
  35. package/src/embeddings/index.ts +0 -48
  36. package/src/embeddings/model.ts +0 -112
  37. package/src/embeddings/search.ts +0 -305
  38. package/src/embeddings/store.ts +0 -313
  39. package/src/embeddings/types.ts +0 -92
  40. package/src/engine.ts +0 -1125
  41. package/src/garden/cluster.ts +0 -330
  42. package/src/garden/garden.ts +0 -306
  43. package/src/garden/index.ts +0 -29
  44. package/src/git/git-exporter.ts +0 -286
  45. package/src/git/git-importer.ts +0 -329
  46. package/src/git/git-reader.ts +0 -189
  47. package/src/git/index.ts +0 -22
  48. package/src/identity/governance.ts +0 -211
  49. package/src/identity/identity.ts +0 -224
  50. package/src/identity/index.ts +0 -30
  51. package/src/identity/signing-middleware.ts +0 -97
  52. package/src/index.ts +0 -29
  53. package/src/links/index.ts +0 -49
  54. package/src/links/lifecycle.ts +0 -400
  55. package/src/links/parser.ts +0 -484
  56. package/src/links/ref-index.ts +0 -186
  57. package/src/links/resolver.ts +0 -314
  58. package/src/links/types.ts +0 -108
  59. package/src/mcp/index.ts +0 -22
  60. package/src/mcp/server.ts +0 -1278
  61. package/src/semantic/csharp-parser.ts +0 -493
  62. package/src/semantic/go-parser.ts +0 -585
  63. package/src/semantic/index.ts +0 -34
  64. package/src/semantic/java-parser.ts +0 -456
  65. package/src/semantic/python-parser.ts +0 -659
  66. package/src/semantic/ruby-parser.ts +0 -446
  67. package/src/semantic/rust-parser.ts +0 -784
  68. package/src/semantic/semantic-merge.ts +0 -210
  69. package/src/semantic/ts-parser.ts +0 -681
  70. package/src/semantic/types.ts +0 -175
  71. package/src/sync/http-transport.ts +0 -144
  72. package/src/sync/index.ts +0 -43
  73. package/src/sync/memory-transport.ts +0 -66
  74. package/src/sync/multi-repo.ts +0 -200
  75. package/src/sync/reconciler.ts +0 -237
  76. package/src/sync/sync-engine.ts +0 -258
  77. package/src/sync/types.ts +0 -104
  78. package/src/sync/ws-transport.ts +0 -145
  79. package/src/ui/client.html +0 -695
  80. package/src/ui/server.ts +0 -419
  81. package/src/vcs/blob-store.ts +0 -124
  82. package/src/vcs/branch.ts +0 -150
  83. package/src/vcs/checkpoint.ts +0 -64
  84. package/src/vcs/decompose.ts +0 -469
  85. package/src/vcs/diff.ts +0 -409
  86. package/src/vcs/engine-context.ts +0 -26
  87. package/src/vcs/index.ts +0 -23
  88. package/src/vcs/issue.ts +0 -800
  89. package/src/vcs/merge.ts +0 -425
  90. package/src/vcs/milestone.ts +0 -124
  91. package/src/vcs/ops.ts +0 -59
  92. package/src/vcs/types.ts +0 -213
  93. package/src/vcs/vcs-middleware.ts +0 -81
  94. package/src/watcher/fs-watcher.ts +0 -255
  95. package/src/watcher/index.ts +0 -9
  96. package/src/watcher/ingestion.ts +0 -116
@@ -1,382 +0,0 @@
1
- /**
2
- * Ontology Validation — Schema enforcement for graph mutations.
3
- *
4
- * Provides both standalone validation (check existing entities against schemas)
5
- * and a kernel middleware that rejects mutations violating ontology constraints.
6
- *
7
- * @module trellis/core/ontology
8
- */
9
-
10
- import type { EAVStore, Fact, Link, Atom } from '../store/eav-store.js';
11
- import type { KernelOp } from '../persist/backend.js';
12
- import type { KernelMiddleware, MiddlewareContext, OpMiddlewareNext } from '../kernel/middleware.js';
13
- import type { OntologyRegistry } from './registry.js';
14
- import type {
15
- AttributeDef,
16
- AttrType,
17
- EntityDef,
18
- ValidationError,
19
- ValidationResult,
20
- } from './types.js';
21
-
22
- // ---------------------------------------------------------------------------
23
- // Standalone Validation
24
- // ---------------------------------------------------------------------------
25
-
26
- /**
27
- * Validate a single entity against the ontology registry.
28
- */
29
- export function validateEntity(
30
- entityId: string,
31
- store: EAVStore,
32
- registry: OntologyRegistry,
33
- ): ValidationResult {
34
- const errors: ValidationError[] = [];
35
- const warnings: ValidationError[] = [];
36
-
37
- const facts = store.getFactsByEntity(entityId);
38
- if (facts.length === 0) {
39
- return { valid: true, errors: [], warnings: [] };
40
- }
41
-
42
- const typeFact = facts.find((f) => f.a === 'type');
43
- if (!typeFact) {
44
- warnings.push({
45
- entityId,
46
- entityType: '(unknown)',
47
- field: 'type',
48
- message: 'Entity has no "type" attribute.',
49
- severity: 'warning',
50
- });
51
- return { valid: true, errors, warnings };
52
- }
53
-
54
- const entityType = String(typeFact.v);
55
- const def = registry.getEntityDef(entityType);
56
-
57
- if (!def) {
58
- // Type not in any registered ontology — that's OK, just warn
59
- warnings.push({
60
- entityId,
61
- entityType,
62
- field: 'type',
63
- message: `Entity type "${entityType}" is not defined in any registered ontology.`,
64
- severity: 'warning',
65
- });
66
- return { valid: true, errors, warnings };
67
- }
68
-
69
- // Check abstract
70
- if (def.abstract) {
71
- errors.push({
72
- entityId,
73
- entityType,
74
- field: 'type',
75
- message: `Cannot instantiate abstract entity type "${entityType}".`,
76
- severity: 'error',
77
- });
78
- }
79
-
80
- // Check required attributes
81
- for (const attr of def.attributes) {
82
- if (attr.required && attr.name !== 'type') {
83
- const hasFact = facts.some((f) => f.a === attr.name);
84
- if (!hasFact) {
85
- errors.push({
86
- entityId,
87
- entityType,
88
- field: attr.name,
89
- message: `Required attribute "${attr.name}" is missing.`,
90
- severity: 'error',
91
- });
92
- }
93
- }
94
- }
95
-
96
- // Validate each fact against its attribute def
97
- for (const fact of facts) {
98
- if (fact.a === 'type' || fact.a === 'createdAt' || fact.a === 'updatedAt') continue;
99
-
100
- const attrDef = def.attributes.find((a) => a.name === fact.a);
101
- if (!attrDef) {
102
- // Unknown attribute — warn but don't error (open-world assumption)
103
- warnings.push({
104
- entityId,
105
- entityType,
106
- field: fact.a,
107
- message: `Attribute "${fact.a}" is not defined in the "${entityType}" ontology.`,
108
- severity: 'warning',
109
- });
110
- continue;
111
- }
112
-
113
- // Type check
114
- const typeErr = validateAttrType(fact.v, attrDef);
115
- if (typeErr) {
116
- errors.push({
117
- entityId,
118
- entityType,
119
- field: fact.a,
120
- message: typeErr,
121
- severity: 'error',
122
- });
123
- }
124
-
125
- // Enum check
126
- if (attrDef.enum && !attrDef.enum.includes(fact.v)) {
127
- errors.push({
128
- entityId,
129
- entityType,
130
- field: fact.a,
131
- message: `Value "${fact.v}" is not in allowed values: [${attrDef.enum.join(', ')}].`,
132
- severity: 'error',
133
- });
134
- }
135
-
136
- // Pattern check
137
- if (attrDef.pattern && typeof fact.v === 'string') {
138
- if (!new RegExp(attrDef.pattern).test(fact.v)) {
139
- errors.push({
140
- entityId,
141
- entityType,
142
- field: fact.a,
143
- message: `Value "${fact.v}" does not match pattern /${attrDef.pattern}/.`,
144
- severity: 'error',
145
- });
146
- }
147
- }
148
-
149
- // Range check
150
- if (attrDef.min !== undefined) {
151
- if (typeof fact.v === 'number' && fact.v < attrDef.min) {
152
- errors.push({
153
- entityId,
154
- entityType,
155
- field: fact.a,
156
- message: `Value ${fact.v} is below minimum ${attrDef.min}.`,
157
- severity: 'error',
158
- });
159
- }
160
- if (typeof fact.v === 'string' && fact.v.length < attrDef.min) {
161
- errors.push({
162
- entityId,
163
- entityType,
164
- field: fact.a,
165
- message: `String length ${fact.v.length} is below minimum ${attrDef.min}.`,
166
- severity: 'error',
167
- });
168
- }
169
- }
170
- if (attrDef.max !== undefined) {
171
- if (typeof fact.v === 'number' && fact.v > attrDef.max) {
172
- errors.push({
173
- entityId,
174
- entityType,
175
- field: fact.a,
176
- message: `Value ${fact.v} exceeds maximum ${attrDef.max}.`,
177
- severity: 'error',
178
- });
179
- }
180
- if (typeof fact.v === 'string' && fact.v.length > attrDef.max) {
181
- errors.push({
182
- entityId,
183
- entityType,
184
- field: fact.a,
185
- message: `String length ${fact.v.length} exceeds maximum ${attrDef.max}.`,
186
- severity: 'error',
187
- });
188
- }
189
- }
190
- }
191
-
192
- // Validate links
193
- const links = store.getLinksByEntity(entityId);
194
- for (const link of links) {
195
- if (link.e1 !== entityId) continue; // Only validate outgoing links
196
- const relDef = registry.getRelationDef(link.a);
197
- if (!relDef) continue;
198
-
199
- // Check source type is allowed
200
- if (!relDef.sourceTypes.includes(entityType)) {
201
- errors.push({
202
- entityId,
203
- entityType,
204
- field: link.a,
205
- message: `Entity type "${entityType}" is not allowed as source for relation "${link.a}".`,
206
- severity: 'error',
207
- });
208
- }
209
-
210
- // Check target type
211
- const targetFacts = store.getFactsByEntity(link.e2);
212
- const targetType = targetFacts.find((f) => f.a === 'type');
213
- if (targetType && !relDef.targetTypes.includes(String(targetType.v))) {
214
- errors.push({
215
- entityId,
216
- entityType,
217
- field: link.a,
218
- message: `Target type "${targetType.v}" is not allowed for relation "${link.a}" (expected: ${relDef.targetTypes.join(', ')}).`,
219
- severity: 'error',
220
- });
221
- }
222
- }
223
-
224
- return {
225
- valid: errors.length === 0,
226
- errors,
227
- warnings,
228
- };
229
- }
230
-
231
- /**
232
- * Validate all entities in the store against the ontology registry.
233
- */
234
- export function validateStore(
235
- store: EAVStore,
236
- registry: OntologyRegistry,
237
- ): ValidationResult {
238
- const allErrors: ValidationError[] = [];
239
- const allWarnings: ValidationError[] = [];
240
-
241
- const typeFacts = store.getFactsByAttribute('type');
242
- const entityIds = new Set(typeFacts.map((f) => f.e));
243
-
244
- for (const entityId of entityIds) {
245
- const result = validateEntity(entityId, store, registry);
246
- allErrors.push(...result.errors);
247
- allWarnings.push(...result.warnings);
248
- }
249
-
250
- return {
251
- valid: allErrors.length === 0,
252
- errors: allErrors,
253
- warnings: allWarnings,
254
- };
255
- }
256
-
257
- // ---------------------------------------------------------------------------
258
- // Type checking helper
259
- // ---------------------------------------------------------------------------
260
-
261
- function validateAttrType(value: Atom, def: AttributeDef): string | null {
262
- if (def.type === 'any') return null;
263
-
264
- switch (def.type) {
265
- case 'string':
266
- if (typeof value !== 'string') return `Expected string, got ${typeof value}.`;
267
- break;
268
- case 'number':
269
- if (typeof value !== 'number') return `Expected number, got ${typeof value}.`;
270
- break;
271
- case 'boolean':
272
- if (typeof value !== 'boolean') return `Expected boolean, got ${typeof value}.`;
273
- break;
274
- case 'date':
275
- if (typeof value === 'string') {
276
- if (isNaN(Date.parse(value))) return `Expected ISO date string, got "${value}".`;
277
- } else if (!(value instanceof Date)) {
278
- return `Expected date, got ${typeof value}.`;
279
- }
280
- break;
281
- case 'ref':
282
- if (typeof value !== 'string') return `Expected entity reference (string), got ${typeof value}.`;
283
- break;
284
- }
285
-
286
- return null;
287
- }
288
-
289
- // ---------------------------------------------------------------------------
290
- // Validation Middleware
291
- // ---------------------------------------------------------------------------
292
-
293
- /**
294
- * Creates a kernel middleware that validates mutations against the ontology.
295
- *
296
- * - On `addFacts`: validates that new facts conform to attribute definitions
297
- * - On `addLinks`: validates that links conform to relation definitions
298
- * - Blocks operations that would create invalid data (throws on error)
299
- *
300
- * @param registry The ontology registry to validate against
301
- * @param strict If true, unknown entity types cause errors (default: false = warnings only)
302
- */
303
- export function createValidationMiddleware(
304
- registry: OntologyRegistry,
305
- options?: { strict?: boolean },
306
- ): KernelMiddleware {
307
- const strict = options?.strict ?? false;
308
-
309
- return {
310
- name: 'ontology-validator',
311
-
312
- handleOp: (op: KernelOp, ctx: MiddlewareContext, next: OpMiddlewareNext) => {
313
- // Validate new facts
314
- if (op.facts && op.facts.length > 0) {
315
- for (const fact of op.facts) {
316
- if (fact.a === 'type') continue; // type facts are always allowed
317
- if (fact.a === 'createdAt' || fact.a === 'updatedAt') continue;
318
-
319
- // Find the entity type from the same op's facts or skip
320
- const typeFact = op.facts.find((f) => f.e === fact.e && f.a === 'type');
321
- if (!typeFact) continue; // Can't validate without knowing the type
322
-
323
- const entityType = String(typeFact.v);
324
- const def = registry.getEntityDef(entityType);
325
- if (!def) {
326
- if (strict) {
327
- throw new Error(
328
- `[ontology-validator] Unknown entity type "${entityType}" for entity "${fact.e}".`,
329
- );
330
- }
331
- continue;
332
- }
333
-
334
- const attrDef = def.attributes.find((a) => a.name === fact.a);
335
- if (!attrDef) {
336
- if (strict) {
337
- throw new Error(
338
- `[ontology-validator] Unknown attribute "${fact.a}" for type "${entityType}".`,
339
- );
340
- }
341
- continue;
342
- }
343
-
344
- // Type check
345
- const typeErr = validateAttrType(fact.v, attrDef);
346
- if (typeErr) {
347
- throw new Error(
348
- `[ontology-validator] Entity "${fact.e}" attribute "${fact.a}": ${typeErr}`,
349
- );
350
- }
351
-
352
- // Enum check
353
- if (attrDef.enum && !attrDef.enum.includes(fact.v)) {
354
- throw new Error(
355
- `[ontology-validator] Entity "${fact.e}" attribute "${fact.a}": value "${fact.v}" not in [${attrDef.enum.join(', ')}].`,
356
- );
357
- }
358
- }
359
- }
360
-
361
- // Validate new links
362
- if (op.links && op.links.length > 0) {
363
- for (const link of op.links) {
364
- const relDef = registry.getRelationDef(link.a);
365
- if (!relDef) continue; // Unknown relation — skip
366
-
367
- // Source type check (from op facts)
368
- const sourceTypeFact = op.facts?.find(
369
- (f) => f.e === link.e1 && f.a === 'type',
370
- );
371
- if (sourceTypeFact && !relDef.sourceTypes.includes(String(sourceTypeFact.v))) {
372
- throw new Error(
373
- `[ontology-validator] Relation "${link.a}": source type "${sourceTypeFact.v}" not allowed (expected: ${relDef.sourceTypes.join(', ')}).`,
374
- );
375
- }
376
- }
377
- }
378
-
379
- return next(op, ctx);
380
- },
381
- };
382
- }
@@ -1,74 +0,0 @@
1
- /**
2
- * Kernel persistence backend types.
3
- * Inlined from trellis-core for single-package publish.
4
- *
5
- * @module trellis/core
6
- */
7
-
8
- import type { Fact, Link } from '../store/eav-store.js';
9
-
10
- export type KernelOpKind =
11
- | 'addFacts'
12
- | 'addLinks'
13
- | 'deleteFacts'
14
- | 'deleteLinks';
15
-
16
- export interface KernelOp {
17
- /**
18
- * Content hash of this operation (including previousHash).
19
- * Format: trellis:op:{hash}
20
- */
21
- hash: string;
22
-
23
- /**
24
- * Kind of operation.
25
- */
26
- kind: KernelOpKind;
27
-
28
- /**
29
- * ISO timestamp of when the op was created.
30
- */
31
- timestamp: string;
32
-
33
- /**
34
- * The ID of the agent that performed the operation.
35
- */
36
- agentId: string;
37
-
38
- /**
39
- * Hash of the previous operation in the local chain.
40
- */
41
- previousHash?: string;
42
-
43
- /**
44
- * The actual data payload.
45
- */
46
- facts?: Fact[];
47
- links?: Link[];
48
-
49
- /**
50
- * Facts to delete (for update/delete operations).
51
- */
52
- deleteFacts?: Fact[];
53
-
54
- /**
55
- * Links to delete (for update/delete operations).
56
- */
57
- deleteLinks?: Link[];
58
- }
59
-
60
- export interface KernelBackend {
61
- init(): void;
62
- append(op: KernelOp): void;
63
- readAll(): KernelOp[];
64
- readUntil(hash: string): KernelOp[];
65
- readAfter(hash: string): KernelOp[];
66
- readUntilTimestamp(isoTimestamp: string): KernelOp[];
67
- getLastOp(): KernelOp | undefined;
68
-
69
- // Snapshot support
70
- saveSnapshot(lastOpHash: string, data: any): void;
71
- loadLatestSnapshot(): { lastOpHash: string; data: any } | undefined;
72
-
73
- close?(): void;
74
- }