@almadar/core 1.0.14 → 1.0.16

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.
@@ -0,0 +1,918 @@
1
+ import { bp as SExpr, T as Entity, aZ as Page, O as OrbitalSchema, b$ as Trait } from '../schema-zGCZtr5W.js';
2
+ import 'zod';
3
+ import '@almadar/patterns';
4
+
5
+ /**
6
+ * Effect operator mapping: Both systems use the same operator names
7
+ */
8
+ declare const EFFECT_OPERATORS: readonly ["set", "emit", "navigate", "render-ui", "persist", "call-service", "spawn", "despawn", "do", "notify"];
9
+ /**
10
+ * Effect operator names (S-expression first element)
11
+ * These are the operators used in S-expression effects like ['emit', ...]
12
+ */
13
+ type EffectType = (typeof EFFECT_OPERATORS)[number];
14
+ interface SourceLocation {
15
+ line: number;
16
+ column: number;
17
+ offset: number;
18
+ }
19
+ interface SourceRange {
20
+ start: SourceLocation;
21
+ end: SourceLocation;
22
+ }
23
+ interface ASTNode {
24
+ type: string;
25
+ range?: SourceRange;
26
+ }
27
+ /**
28
+ * Domain Language field types
29
+ *
30
+ * Note: These map to OrbitalSchema types via DOMAIN_TO_SCHEMA_FIELD_TYPE
31
+ */
32
+ type DomainFieldType = 'text' | 'long text' | 'number' | 'currency' | 'date' | 'timestamp' | 'datetime' | 'yes/no' | 'enum' | 'list' | 'object' | 'relation';
33
+ interface DomainField extends ASTNode {
34
+ type: 'field';
35
+ name: string;
36
+ fieldType: DomainFieldType;
37
+ required: boolean;
38
+ unique: boolean;
39
+ auto: boolean;
40
+ default?: unknown;
41
+ enumValues?: string[];
42
+ }
43
+ type RelationshipType = 'belongs_to' | 'has_many' | 'has_one';
44
+ interface DomainRelationship extends ASTNode {
45
+ type: 'relationship';
46
+ relationshipType: RelationshipType;
47
+ targetEntity: string;
48
+ alias?: string;
49
+ }
50
+ interface DomainEntity extends ASTNode {
51
+ type: 'entity';
52
+ name: string;
53
+ description: string;
54
+ fields: DomainField[];
55
+ relationships: DomainRelationship[];
56
+ states?: string[];
57
+ initialState?: string;
58
+ }
59
+ interface DomainPageSection extends ASTNode {
60
+ type: 'page_section';
61
+ description: string;
62
+ }
63
+ interface DomainPageAction extends ASTNode {
64
+ type: 'page_action';
65
+ trigger: string;
66
+ action: string;
67
+ }
68
+ interface DomainPage extends ASTNode {
69
+ type: 'page';
70
+ name: string;
71
+ description: string;
72
+ purpose: string;
73
+ url: string;
74
+ primaryEntity?: string;
75
+ traitName?: string;
76
+ sections: DomainPageSection[];
77
+ actions: DomainPageAction[];
78
+ onAccess?: string;
79
+ }
80
+ type ComparisonOperator = '==' | '!=' | '>' | '<' | '>=' | '<=';
81
+ type LogicalOperator = 'AND' | 'OR';
82
+ interface FieldReference extends ASTNode {
83
+ type: 'field_reference';
84
+ entityName: string;
85
+ fieldName: string;
86
+ }
87
+ interface FieldCheckCondition extends ASTNode {
88
+ type: 'field_check';
89
+ field: FieldReference;
90
+ check: 'provided' | 'empty' | 'equals';
91
+ value?: string | number | boolean;
92
+ }
93
+ interface ComparisonCondition extends ASTNode {
94
+ type: 'comparison';
95
+ field: FieldReference;
96
+ operator: ComparisonOperator;
97
+ value: string | number | boolean;
98
+ }
99
+ interface UserCheckCondition extends ASTNode {
100
+ type: 'user_check';
101
+ check: 'is_role' | 'owns_this';
102
+ role?: string;
103
+ ownerField?: string;
104
+ }
105
+ interface LogicalCondition extends ASTNode {
106
+ type: 'logical';
107
+ operator: LogicalOperator;
108
+ left: GuardCondition;
109
+ right: GuardCondition;
110
+ }
111
+ type GuardCondition = FieldCheckCondition | ComparisonCondition | UserCheckCondition | LogicalCondition;
112
+ interface DomainGuard extends ASTNode {
113
+ type: 'guard';
114
+ condition: GuardCondition;
115
+ raw: string;
116
+ }
117
+ interface DomainEffect extends ASTNode {
118
+ type: 'effect';
119
+ effectType: EffectType;
120
+ description: string;
121
+ config: Record<string, unknown>;
122
+ }
123
+ interface DomainTransition extends ASTNode {
124
+ type: 'transition';
125
+ fromState: string;
126
+ toState: string;
127
+ event: string;
128
+ guards: DomainGuard[];
129
+ effects: DomainEffect[];
130
+ }
131
+ interface DomainTick extends ASTNode {
132
+ type: 'tick';
133
+ name: string;
134
+ interval: string;
135
+ intervalMs?: number;
136
+ guard?: DomainGuard;
137
+ effects: DomainEffect[];
138
+ }
139
+ interface DomainBehavior extends ASTNode {
140
+ type: 'behavior';
141
+ name: string;
142
+ entityName: string;
143
+ states: string[];
144
+ initialState: string;
145
+ transitions: DomainTransition[];
146
+ ticks: DomainTick[];
147
+ rules: string[];
148
+ }
149
+ interface DomainDocument extends ASTNode {
150
+ type: 'document';
151
+ entities: DomainEntity[];
152
+ pages: DomainPage[];
153
+ behaviors: DomainBehavior[];
154
+ }
155
+ interface SectionMapping {
156
+ sectionId: string;
157
+ sectionType: 'entity' | 'page' | 'behavior' | 'tick';
158
+ schemaPath: string;
159
+ domainText: string;
160
+ aiDescription?: string;
161
+ range?: SourceRange;
162
+ lastModified?: number;
163
+ }
164
+ interface ParseError {
165
+ message: string;
166
+ range?: SourceRange;
167
+ suggestion?: string;
168
+ }
169
+ interface ParseResult<T> {
170
+ success: boolean;
171
+ data?: T;
172
+ errors: ParseError[];
173
+ warnings: ParseError[];
174
+ }
175
+
176
+ /**
177
+ * Domain Language Tokens
178
+ *
179
+ * Token definitions for the domain language lexer.
180
+ */
181
+ declare enum TokenType {
182
+ NEWLINE = "NEWLINE",
183
+ INDENT = "INDENT",
184
+ DEDENT = "DEDENT",
185
+ TEMPLATE_VAR = "TEMPLATE_VAR",
186
+ A = "A",
187
+ AN = "AN",
188
+ IS = "IS",
189
+ IT = "IT",
190
+ HAS = "HAS",
191
+ BELONGS = "BELONGS",
192
+ TO = "TO",
193
+ MANY = "MANY",
194
+ ONE = "ONE",
195
+ AS = "AS",
196
+ CAN = "CAN",
197
+ BE = "BE",
198
+ STARTS = "STARTS",
199
+ THE = "THE",
200
+ SHOWS = "SHOWS",
201
+ ENTITY = "ENTITY",// Explicit entity reference for pages
202
+ PURPOSE = "PURPOSE",
203
+ URL = "URL",
204
+ DISPLAYS = "DISPLAYS",
205
+ USERS = "USERS",
206
+ WHEN = "WHEN",
207
+ ACCESSED = "ACCESSED",
208
+ LIFECYCLE = "LIFECYCLE",
209
+ BEHAVIOR = "BEHAVIOR",
210
+ STATES = "STATES",
211
+ INITIAL = "INITIAL",
212
+ TRANSITIONS = "TRANSITIONS",
213
+ FROM = "FROM",
214
+ IF = "IF",
215
+ THEN = "THEN",
216
+ RULES = "RULES",
217
+ EVERY = "EVERY",
218
+ CHECK = "CHECK",
219
+ AND = "AND",
220
+ OR = "OR",
221
+ NOT = "NOT",
222
+ PROVIDED = "PROVIDED",
223
+ EMPTY = "EMPTY",
224
+ USER = "USER",
225
+ OWNS = "OWNS",
226
+ THIS = "THIS",
227
+ TEXT = "TEXT",
228
+ LONG_TEXT = "LONG_TEXT",
229
+ NUMBER = "NUMBER",
230
+ CURRENCY = "CURRENCY",
231
+ DATE = "DATE",
232
+ TIMESTAMP = "TIMESTAMP",
233
+ YES_NO = "YES_NO",
234
+ ENUM = "ENUM",
235
+ LIST = "LIST",
236
+ REQUIRED = "REQUIRED",
237
+ UNIQUE = "UNIQUE",
238
+ AUTO = "AUTO",
239
+ DEFAULT = "DEFAULT",
240
+ COLON = "COLON",
241
+ COMMA = "COMMA",
242
+ PIPE = "PIPE",
243
+ DOT = "DOT",
244
+ DASH = "DASH",
245
+ LBRACKET = "LBRACKET",
246
+ RBRACKET = "RBRACKET",
247
+ LPAREN = "LPAREN",
248
+ RPAREN = "RPAREN",
249
+ GREATER_THAN = "GREATER_THAN",
250
+ LESS_THAN = "LESS_THAN",
251
+ GREATER_EQUAL = "GREATER_EQUAL",
252
+ LESS_EQUAL = "LESS_EQUAL",
253
+ EQUALS = "EQUALS",
254
+ NOT_EQUALS = "NOT_EQUALS",
255
+ IDENTIFIER = "IDENTIFIER",
256
+ STRING = "STRING",
257
+ NUMBER_LITERAL = "NUMBER_LITERAL",
258
+ BOOLEAN = "BOOLEAN",
259
+ EOF = "EOF",
260
+ ERROR = "ERROR"
261
+ }
262
+ interface Token {
263
+ type: TokenType;
264
+ value: string;
265
+ line: number;
266
+ column: number;
267
+ offset: number;
268
+ }
269
+ declare const KEYWORDS: Record<string, TokenType>;
270
+ declare const MULTI_WORD_KEYWORDS: Record<string, TokenType>;
271
+
272
+ /**
273
+ * Domain Language Lexer
274
+ *
275
+ * Tokenizes domain language text into tokens for parsing.
276
+ */
277
+
278
+ declare class Lexer {
279
+ private input;
280
+ private pos;
281
+ private line;
282
+ private column;
283
+ private indentStack;
284
+ constructor(input: string);
285
+ /**
286
+ * Tokenize the entire input
287
+ */
288
+ tokenize(): Token[];
289
+ private nextToken;
290
+ private consumeTemplateVar;
291
+ private handleIndentation;
292
+ private consumeNewline;
293
+ private consumeString;
294
+ private consumeNumber;
295
+ private consumeIdentifier;
296
+ private consumeChar;
297
+ private consumeChars;
298
+ private skipWhitespace;
299
+ private skipToEndOfLine;
300
+ private makeToken;
301
+ private peek;
302
+ private peekNext;
303
+ private advance;
304
+ private isAtEnd;
305
+ private isDigit;
306
+ private isAlpha;
307
+ private isAlphaNumeric;
308
+ }
309
+ /**
310
+ * Convenience function to tokenize a string
311
+ */
312
+ declare function tokenize(input: string): Token[];
313
+
314
+ /**
315
+ * Entity Parser
316
+ *
317
+ * Parses entity definitions from domain language.
318
+ * All entity references are explicit (e.g., Order, User, Task).
319
+ */
320
+
321
+ /**
322
+ * Parse an entity definition from domain text
323
+ *
324
+ * @example
325
+ * parseEntity(`
326
+ * A Order is a customer purchase request
327
+ * It has:
328
+ * - order number: text, required, unique
329
+ * - amount: currency
330
+ * - status: Pending | Confirmed | Shipped
331
+ * It belongs to User
332
+ * It can be: Pending, Confirmed, Shipped, Delivered, Cancelled
333
+ * It starts as Pending
334
+ * `)
335
+ */
336
+ declare function parseEntity(text: string): ParseResult<DomainEntity>;
337
+ /**
338
+ * Format an entity AST back to domain text
339
+ */
340
+ declare function formatEntityToDomain(entity: DomainEntity): string;
341
+ /**
342
+ * Format entity AST to KFlow schema
343
+ */
344
+ declare function formatEntityToSchema(entity: DomainEntity): Record<string, unknown>;
345
+
346
+ /**
347
+ * Page Parser
348
+ *
349
+ * Parses page definitions from domain language.
350
+ */
351
+
352
+ /**
353
+ * Parse a page definition from domain text
354
+ *
355
+ * @example
356
+ * parsePage(`
357
+ * The Dashboard shows an overview of system activity
358
+ * Purpose: Help users monitor their tasks and orders
359
+ * URL: /dashboard
360
+ *
361
+ * It displays:
362
+ * - Summary statistics for today
363
+ * - Recent orders list
364
+ * - Pending tasks requiring attention
365
+ *
366
+ * Users can:
367
+ * - Click a task to view details
368
+ * - Filter orders by status
369
+ * `)
370
+ */
371
+ declare function parsePage(text: string): ParseResult<DomainPage>;
372
+ /**
373
+ * Format a page AST back to domain text
374
+ */
375
+ declare function formatPageToDomain(page: DomainPage): string;
376
+ /**
377
+ * Format page AST to KFlow schema
378
+ */
379
+ declare function formatPageToSchema(page: DomainPage): Record<string, unknown>;
380
+
381
+ /**
382
+ * Behavior Parser
383
+ *
384
+ * Parses behavior/trait definitions from domain language.
385
+ * Behaviors define state machines with transitions, guards, and effects.
386
+ * All entity references are explicit (e.g., Order.status, CurrentUser.role).
387
+ */
388
+
389
+ /**
390
+ * Parse a behavior definition from domain text
391
+ *
392
+ * @example
393
+ * parseBehavior(`
394
+ * Order Lifecycle
395
+ *
396
+ * States: Pending, Confirmed, Shipped, Delivered, Cancelled
397
+ *
398
+ * Transitions:
399
+ * - From Pending to Confirmed when CONFIRM
400
+ * if Order.amount > 0
401
+ * then notify customer
402
+ * - From Confirmed to Shipped when SHIP
403
+ * - From Shipped to Delivered when DELIVER
404
+ * - From any to Cancelled when CANCEL
405
+ * if Order.status is not Delivered
406
+ *
407
+ * Rules:
408
+ * - Orders over $1000 require manager approval
409
+ * - Cancelled orders cannot be reactivated
410
+ * `, "Order")
411
+ */
412
+ declare function parseBehavior(text: string, entityName: string): ParseResult<DomainBehavior>;
413
+ /**
414
+ * Format a behavior AST back to domain text
415
+ */
416
+ declare function formatBehaviorToDomain(behavior: DomainBehavior): string;
417
+ /**
418
+ * Format behavior AST to KFlow schema trait
419
+ */
420
+ declare function formatBehaviorToSchema(behavior: DomainBehavior): Record<string, unknown>;
421
+
422
+ /**
423
+ * Guard Expression Parser
424
+ *
425
+ * Parses guard expressions deterministically from domain language.
426
+ * All entity references are explicit (e.g., Order.amount, CurrentUser.role).
427
+ */
428
+
429
+ /**
430
+ * Parse a guard expression from domain text
431
+ *
432
+ * @example
433
+ * parseGuard("if amount > 1000", "Order")
434
+ * // Returns: { field: { entityName: "Order", fieldName: "amount" }, operator: ">", value: 1000 }
435
+ */
436
+ declare function parseGuard(text: string, entityName: string): ParseResult<DomainGuard>;
437
+ /**
438
+ * Format a guard condition back to KFlow schema guard string
439
+ */
440
+ declare function formatGuardToSchema(guard: DomainGuard): string;
441
+ /**
442
+ * Format a guard condition back to domain language
443
+ */
444
+ declare function formatGuardToDomain(guard: DomainGuard): string;
445
+
446
+ /**
447
+ * S-Expression Parser
448
+ *
449
+ * Parses domain language text (guards/effects) back to S-Expression arrays.
450
+ * This is the reverse of what sexpr-formatter.ts does.
451
+ *
452
+ * @example
453
+ * parseDomainGuard("health is at least 0") → [">=", "@entity.health", 0]
454
+ * parseDomainEffect("update status to 'done'") → ["set", "@entity.status", "done"]
455
+ *
456
+ * @packageDocumentation
457
+ */
458
+
459
+ /**
460
+ * Parse a domain guard expression to S-Expression.
461
+ *
462
+ * @param text - Domain language guard (e.g., "health is at least 0", "status is 'active'")
463
+ * @param entityName - The entity context for unqualified field references
464
+ * @returns S-Expression array
465
+ *
466
+ * @example
467
+ * parseDomainGuard("health is at least 0") → [">=", "@entity.health", 0]
468
+ * parseDomainGuard("status is 'active'") → ["=", "@entity.status", "active"]
469
+ * parseDomainGuard("x > 0 and y < 100") → ["and", [">", "@entity.x", 0], ["<", "@entity.y", 100]]
470
+ */
471
+ declare function parseDomainGuard(text: string, entityName?: string): SExpr;
472
+ /**
473
+ * Parse a domain effect expression to S-Expression.
474
+ *
475
+ * @param text - Domain language effect (e.g., "update status to 'done'", "emit ORDER_PLACED")
476
+ * @param entityName - The entity context for unqualified field references
477
+ * @returns S-Expression array
478
+ *
479
+ * @example
480
+ * parseDomainEffect("update status to 'done'") → ["set", "@entity.status", "done"]
481
+ * parseDomainEffect("emit ORDER_PLACED") → ["emit", "ORDER_PLACED"]
482
+ * parseDomainEffect("render entity-table to main") → ["render-ui", "main", { type: "entity-table" }]
483
+ */
484
+ declare function parseDomainEffect(text: string, entityName?: string): SExpr;
485
+ /**
486
+ * Parse multiple domain effects (comma or "then" separated).
487
+ *
488
+ * @param text - Domain language effects
489
+ * @param entityName - The entity context
490
+ * @returns Array of S-Expressions (wrapped in ["do", ...] if multiple)
491
+ */
492
+ declare function parseDomainEffects(text: string, entityName?: string): SExpr[];
493
+
494
+ /**
495
+ * Entity Formatter
496
+ *
497
+ * Converts KFlow DataEntity schema to domain language text.
498
+ */
499
+
500
+ /**
501
+ * Convert a KFlow DataEntity to domain language text
502
+ */
503
+ declare function formatSchemaEntityToDomain(entity: Record<string, unknown>): string;
504
+ /**
505
+ * Convert KFlow DataEntity to DomainEntity AST
506
+ */
507
+ declare function schemaEntityToDomainEntity(entity: Record<string, unknown>): DomainEntity;
508
+
509
+ /**
510
+ * Page Formatter
511
+ *
512
+ * Converts KFlow Page schema to domain language text.
513
+ */
514
+
515
+ /**
516
+ * Convert a KFlow Page schema to domain language text
517
+ */
518
+ declare function formatSchemaPageToDomain(page: Record<string, unknown>): string;
519
+ /**
520
+ * Convert KFlow Page schema to DomainPage AST
521
+ */
522
+ declare function schemaPageToDomainPage(page: Record<string, unknown>): DomainPage;
523
+
524
+ /**
525
+ * Behavior Formatter
526
+ *
527
+ * Converts KFlow Trait schema to domain language text.
528
+ * Supports both legacy typed effects and S-expression format.
529
+ */
530
+
531
+ /**
532
+ * Convert a KFlow Trait schema to domain language text
533
+ */
534
+ declare function formatSchemaTraitToDomain(trait: Record<string, unknown>, entityName?: string): string;
535
+ /**
536
+ * Convert KFlow Trait schema to DomainBehavior AST
537
+ */
538
+ declare function schemaTraitToDomainBehavior(trait: Record<string, unknown>, entityName?: string): DomainBehavior;
539
+
540
+ /**
541
+ * Guard Formatter
542
+ *
543
+ * Converts KFlow guard conditions to domain language and vice versa.
544
+ * All entity references are explicit (e.g., Order.amount, CurrentUser.role).
545
+ *
546
+ * Supports both legacy string-based conditions and S-expression format.
547
+ */
548
+
549
+ /**
550
+ * Convert a KFlow schema guard to domain language text.
551
+ * Handles both legacy string conditions and S-expression format.
552
+ */
553
+ declare function formatSchemaGuardToDomain(guard: Record<string, unknown> | unknown[], entityName: string): string;
554
+ /**
555
+ * Convert a DomainGuard to KFlow schema guard format
556
+ */
557
+ declare function formatDomainGuardToSchema(guard: DomainGuard): string;
558
+ /**
559
+ * Format a guard condition AST to domain-friendly text
560
+ */
561
+ declare function formatGuardConditionToDomain(condition: GuardCondition): string;
562
+
563
+ /**
564
+ * Schema to Domain Converter
565
+ *
566
+ * Converts a complete OrbitalSchema to domain language text.
567
+ * Generates three sections: Entities, Pages, and Behaviors.
568
+ *
569
+ * Updated to read from OrbitalSchema where entities, pages, and traits
570
+ * are grouped into Orbital units. Also supports legacy KFlowSchema format
571
+ * for backward compatibility.
572
+ */
573
+
574
+ interface SchemaToDomainResult {
575
+ /** The complete domain text document */
576
+ domainText: string;
577
+ /** Parsed AST representation */
578
+ document: DomainDocument;
579
+ /** Mapping of sections to schema paths */
580
+ mappings: SectionMapping[];
581
+ /** Separate section texts for individual editing */
582
+ sections: {
583
+ entities: string[];
584
+ pages: string[];
585
+ behaviors: string[];
586
+ };
587
+ }
588
+ /**
589
+ * Legacy KFlowSchema format (for backward compatibility)
590
+ */
591
+ interface LegacyKFlowSchema {
592
+ name?: string;
593
+ dataEntities?: Array<Record<string, unknown>>;
594
+ ui?: {
595
+ pages?: Array<Record<string, unknown>>;
596
+ };
597
+ traits?: Array<Record<string, unknown>>;
598
+ ticks?: Array<Record<string, unknown>>;
599
+ }
600
+ /**
601
+ * Combined input type for the converter
602
+ */
603
+ type SchemaInput = OrbitalSchema | LegacyKFlowSchema;
604
+ /**
605
+ * Convert a complete OrbitalSchema or legacy KFlowSchema to domain language
606
+ */
607
+ declare function convertSchemaToDomain(schema: SchemaInput): SchemaToDomainResult;
608
+ /**
609
+ * Convert just the entities section
610
+ */
611
+ declare function convertEntitiesToDomain(entities: Entity[]): string;
612
+ /**
613
+ * Convert just the pages section
614
+ */
615
+ declare function convertPagesToDomain(pages: Page[]): string;
616
+ /**
617
+ * Convert just the traits/behaviors section
618
+ */
619
+ declare function convertTraitsToDomain(traits: Trait[]): string;
620
+
621
+ /**
622
+ * Domain to Schema Converter
623
+ *
624
+ * Applies domain language text changes to an OrbitalSchema.
625
+ * Supports incremental updates (single section) and full replacement.
626
+ *
627
+ * Updated to use OrbitalSchema where entities, pages, and traits
628
+ * are grouped into Orbital units instead of flat arrays.
629
+ */
630
+
631
+ interface DomainToSchemaResult {
632
+ /** Whether the conversion was successful */
633
+ success: boolean;
634
+ /** The updated schema */
635
+ schema: OrbitalSchema;
636
+ /** Any parse errors encountered */
637
+ errors: ParseError[];
638
+ /** Warnings (non-fatal issues) */
639
+ warnings: ParseError[];
640
+ /** Updated section mappings */
641
+ mappings: SectionMapping[];
642
+ }
643
+ /**
644
+ * Parse a complete domain document and convert to OrbitalSchema
645
+ */
646
+ declare function convertDomainToSchema(domainText: string, baseSchema?: OrbitalSchema): DomainToSchemaResult;
647
+ /**
648
+ * Apply a single section update to an OrbitalSchema
649
+ */
650
+ declare function applySectionUpdate(schema: OrbitalSchema, sectionType: 'entity' | 'page' | 'behavior' | 'tick', sectionId: string, newDomainText: string): DomainToSchemaResult;
651
+ /**
652
+ * Delete a section from the schema
653
+ */
654
+ declare function deleteSection(schema: OrbitalSchema, sectionType: 'entity' | 'page' | 'behavior' | 'tick', sectionId: string): OrbitalSchema;
655
+
656
+ /**
657
+ * Section Mapping
658
+ *
659
+ * Tracks the relationship between domain language sections and KFlow schema paths.
660
+ * Enables bidirectional sync and conflict detection.
661
+ */
662
+
663
+ interface MappingStore {
664
+ /** All tracked mappings */
665
+ mappings: SectionMapping[];
666
+ /** Last sync timestamp */
667
+ lastSync: number;
668
+ /** Schema version hash for change detection */
669
+ schemaHash?: string;
670
+ }
671
+ /**
672
+ * Create a new mapping store
673
+ */
674
+ declare function createMappingStore(mappings?: SectionMapping[]): MappingStore;
675
+ /**
676
+ * Find a mapping by section ID
677
+ */
678
+ declare function findMapping(store: MappingStore, sectionId: string): SectionMapping | undefined;
679
+ /**
680
+ * Find a mapping by schema path
681
+ */
682
+ declare function findMappingByPath(store: MappingStore, schemaPath: string): SectionMapping | undefined;
683
+ /**
684
+ * Find all mappings of a specific type
685
+ */
686
+ declare function findMappingsByType(store: MappingStore, sectionType: 'entity' | 'page' | 'behavior' | 'tick'): SectionMapping[];
687
+ /**
688
+ * Update or add a mapping
689
+ */
690
+ declare function upsertMapping(store: MappingStore, mapping: SectionMapping): MappingStore;
691
+ /**
692
+ * Remove a mapping
693
+ */
694
+ declare function removeMapping(store: MappingStore, sectionId: string): MappingStore;
695
+ /**
696
+ * Detect changes between old and new mappings
697
+ */
698
+ declare function detectChanges(oldMappings: SectionMapping[], newMappings: SectionMapping[]): {
699
+ added: SectionMapping[];
700
+ removed: SectionMapping[];
701
+ modified: SectionMapping[];
702
+ };
703
+ /**
704
+ * Generate a unique section ID
705
+ */
706
+ declare function generateSectionId(sectionType: 'entity' | 'page' | 'behavior' | 'tick', name: string): string;
707
+ /**
708
+ * Extract section type and name from a section ID
709
+ */
710
+ declare function parseSectionId(sectionId: string): {
711
+ sectionType: 'entity' | 'page' | 'behavior' | 'tick';
712
+ name: string;
713
+ } | null;
714
+ /**
715
+ * Get the schema path for a section
716
+ */
717
+ declare function getSchemaPath(sectionType: 'entity' | 'page' | 'behavior' | 'tick', index: number): string;
718
+ /**
719
+ * Update range information for a mapping based on text position
720
+ */
721
+ declare function updateMappingRange(mapping: SectionMapping, fullText: string): SectionMapping;
722
+ /**
723
+ * Resolve conflicts between domain changes and schema changes
724
+ */
725
+ declare function resolveConflict(domainMapping: SectionMapping, schemaMapping: SectionMapping, preference: 'domain' | 'schema' | 'newest'): SectionMapping;
726
+ /**
727
+ * Compute a simple hash of a schema for change detection
728
+ */
729
+ declare function computeSchemaHash(schema: Record<string, unknown>): string;
730
+ /**
731
+ * Check if schema has changed since last sync
732
+ */
733
+ declare function hasSchemaChanged(store: MappingStore, schema: Record<string, unknown>): boolean;
734
+ /**
735
+ * Update the schema hash in the store
736
+ */
737
+ declare function updateSchemaHash(store: MappingStore, schema: Record<string, unknown>): MappingStore;
738
+
739
+ /**
740
+ * Domain Language Chunk Merging
741
+ *
742
+ * Utilities for merging multiple domain language chunks into a single document.
743
+ * Used by the lean skill to generate orbitals incrementally.
744
+ *
745
+ * @packageDocumentation
746
+ */
747
+ interface DomainChunk {
748
+ /** The domain language text for this orbital */
749
+ text: string;
750
+ /** Optional name for this orbital (for debugging) */
751
+ name?: string;
752
+ }
753
+ interface MergeResult {
754
+ /** The merged domain language text */
755
+ text: string;
756
+ /** Number of entities merged */
757
+ entityCount: number;
758
+ /** Number of pages merged */
759
+ pageCount: number;
760
+ /** Number of behaviors merged */
761
+ behaviorCount: number;
762
+ }
763
+ /**
764
+ * Merge multiple domain language chunks into a single document.
765
+ *
766
+ * Each chunk can contain:
767
+ * - `# Entities` section with entity definitions
768
+ * - `# Pages` section with page definitions
769
+ * - `# Behaviors` section with behavior/trait definitions
770
+ *
771
+ * The merge combines all sections, maintaining the standard order:
772
+ * 1. Entities
773
+ * 2. Pages
774
+ * 3. Behaviors
775
+ *
776
+ * @example
777
+ * ```typescript
778
+ * const chunks = [
779
+ * { text: '# Entities\n\nA Task is...', name: 'Task' },
780
+ * { text: '# Entities\n\nA User is...', name: 'User' },
781
+ * ];
782
+ * const result = mergeDomainChunks(chunks);
783
+ * // result.text contains both entities merged
784
+ * ```
785
+ */
786
+ declare function mergeDomainChunks(chunks: DomainChunk[]): MergeResult;
787
+ /**
788
+ * Validate that a domain chunk has the expected structure.
789
+ * Returns errors if the chunk is malformed.
790
+ */
791
+ declare function validateDomainChunk(chunk: DomainChunk): string[];
792
+ /**
793
+ * Format a merged result as a summary string
794
+ */
795
+ declare function formatMergeSummary(result: MergeResult): string;
796
+
797
+ /**
798
+ * Domain Language Registry
799
+ *
800
+ * Central registry for OrbitalSchema <-> Domain Language mappings.
801
+ * This is the single source of truth for type conversions.
802
+ *
803
+ * When adding a new OrbitalSchema feature:
804
+ * 1. Add type mapping here
805
+ * 2. Formatters/parsers automatically use these mappings
806
+ * 3. Build-time validation ensures coverage
807
+ *
808
+ * @packageDocumentation
809
+ */
810
+
811
+ /**
812
+ * Field type mapping entry with format/parse functions
813
+ */
814
+ interface FieldTypeMapping {
815
+ /** OrbitalSchema type name */
816
+ schemaType: string;
817
+ /** Domain Language keyword(s) - can be array for aliases */
818
+ domainKeywords: string[];
819
+ /** Format schema field to domain text */
820
+ format: (field: {
821
+ type: string;
822
+ values?: string[];
823
+ relation?: {
824
+ entity: string;
825
+ };
826
+ }) => string;
827
+ /** Parse domain keyword to schema type */
828
+ parse: (keyword: string) => string;
829
+ }
830
+ /**
831
+ * Effect operator mapping entry
832
+ */
833
+ interface EffectMapping {
834
+ /** S-Expression operator name */
835
+ operator: string;
836
+ /** Human-readable domain pattern templates */
837
+ domainPatterns: string[];
838
+ /** Description for documentation */
839
+ description: string;
840
+ }
841
+ /**
842
+ * Guard operator mapping entry
843
+ */
844
+ interface GuardMapping {
845
+ /** S-Expression operator */
846
+ operator: string;
847
+ /** Human-readable domain patterns */
848
+ domainPatterns: string[];
849
+ /** Description */
850
+ description: string;
851
+ }
852
+ /**
853
+ * Complete field type registry with format/parse functions
854
+ */
855
+ declare const FIELD_TYPE_REGISTRY: Record<string, FieldTypeMapping>;
856
+ /**
857
+ * Effect operator registry with human-readable patterns
858
+ */
859
+ declare const EFFECT_REGISTRY: Record<string, EffectMapping>;
860
+ /**
861
+ * Guard operator registry with human-readable patterns
862
+ */
863
+ declare const GUARD_REGISTRY: Record<string, GuardMapping>;
864
+ /**
865
+ * Get all registered field types
866
+ */
867
+ declare function getRegisteredFieldTypes(): string[];
868
+ /**
869
+ * Get all registered effect operators
870
+ */
871
+ declare function getRegisteredEffects(): string[];
872
+ /**
873
+ * Get all registered guard operators
874
+ */
875
+ declare function getRegisteredGuards(): string[];
876
+ /**
877
+ * Check if a field type is registered
878
+ */
879
+ declare function isFieldTypeRegistered(type: string): boolean;
880
+ /**
881
+ * Check if an effect operator is registered
882
+ */
883
+ declare function isEffectRegistered(operator: string): boolean;
884
+ /**
885
+ * Check if a guard operator is registered
886
+ */
887
+ declare function isGuardRegistered(operator: string): boolean;
888
+ /**
889
+ * Get field type mapping
890
+ */
891
+ declare function getFieldTypeMapping(type: string): FieldTypeMapping | undefined;
892
+ /**
893
+ * Get effect mapping
894
+ */
895
+ declare function getEffectMapping(operator: string): EffectMapping | undefined;
896
+ /**
897
+ * Get guard mapping
898
+ */
899
+ declare function getGuardMapping(operator: string): GuardMapping | undefined;
900
+ /**
901
+ * Lookup domain keyword and return schema type
902
+ */
903
+ declare function domainKeywordToSchemaType(keyword: string): string | undefined;
904
+ /**
905
+ * Lookup schema type and return primary domain keyword
906
+ */
907
+ declare function schemaTypeToDomainKeyword(type: string): string | undefined;
908
+ /**
909
+ * Get registry statistics for validation/documentation
910
+ */
911
+ declare function getRegistryStats(): {
912
+ fieldTypes: number;
913
+ effects: number;
914
+ guards: number;
915
+ uiSlots: number;
916
+ };
917
+
918
+ export { type ASTNode, type ComparisonCondition, type ComparisonOperator, type DomainBehavior, type DomainChunk, type DomainDocument, type DomainEffect, type DomainEntity, type DomainField, type DomainFieldType, type DomainGuard, type DomainPage, type DomainPageAction, type DomainPageSection, type DomainRelationship, type DomainTick, type DomainToSchemaResult, type DomainTransition, EFFECT_REGISTRY, type EffectMapping, type EffectType, FIELD_TYPE_REGISTRY, type FieldCheckCondition, type FieldReference, type FieldTypeMapping, GUARD_REGISTRY, type GuardCondition, type GuardMapping, KEYWORDS, Lexer, type LogicalCondition, type LogicalOperator, MULTI_WORD_KEYWORDS, type MappingStore, type MergeResult, type ParseError, type ParseResult, type RelationshipType, type SchemaToDomainResult, type SectionMapping, type SourceLocation, type SourceRange, type Token, TokenType, type UserCheckCondition, applySectionUpdate, computeSchemaHash, convertDomainToSchema, convertEntitiesToDomain, convertPagesToDomain, convertSchemaToDomain, convertTraitsToDomain, createMappingStore, deleteSection, detectChanges, domainKeywordToSchemaType, findMapping, findMappingByPath, findMappingsByType, formatBehaviorToDomain, formatBehaviorToSchema, formatDomainGuardToSchema, formatEntityToDomain, formatEntityToSchema, formatGuardConditionToDomain, formatGuardToDomain, formatGuardToSchema, formatMergeSummary, formatPageToDomain, formatPageToSchema, formatSchemaEntityToDomain, formatSchemaGuardToDomain, formatSchemaPageToDomain, formatSchemaTraitToDomain, generateSectionId, getEffectMapping, getFieldTypeMapping, getGuardMapping, getRegisteredEffects, getRegisteredFieldTypes, getRegisteredGuards, getRegistryStats, getSchemaPath, hasSchemaChanged, isEffectRegistered, isFieldTypeRegistered, isGuardRegistered, mergeDomainChunks, parseBehavior, parseDomainEffect, parseDomainEffects, parseDomainGuard, parseEntity, parseGuard, parsePage, parseSectionId, removeMapping, resolveConflict, schemaEntityToDomainEntity, schemaPageToDomainPage, schemaTraitToDomainBehavior, schemaTypeToDomainKeyword, tokenize, updateMappingRange, updateSchemaHash, upsertMapping, validateDomainChunk };