@lokascript/framework 2.3.0 → 2.4.0

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 (54) hide show
  1. package/dist/api/index.js +29 -516
  2. package/dist/api/index.js.map +1 -1
  3. package/dist/core/index.js +20 -128
  4. package/dist/core/index.js.map +1 -1
  5. package/dist/core/pattern-matching/index.js +19 -12
  6. package/dist/core/pattern-matching/index.js.map +1 -1
  7. package/dist/core/tokenization/index.js.map +1 -1
  8. package/dist/core/types.d.ts +7 -354
  9. package/dist/core/types.d.ts.map +1 -1
  10. package/dist/core/types.js +21 -129
  11. package/dist/core/types.js.map +1 -1
  12. package/dist/generation/diagnostics.d.ts +5 -115
  13. package/dist/generation/diagnostics.d.ts.map +1 -1
  14. package/dist/generation/index.js +20 -77
  15. package/dist/generation/index.js.map +1 -1
  16. package/dist/index.cjs +189 -1458
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.js +108 -1347
  19. package/dist/index.js.map +1 -1
  20. package/dist/interfaces/value-extractor.d.ts +20 -0
  21. package/dist/interfaces/value-extractor.d.ts.map +1 -1
  22. package/dist/ir/explicit-parser.d.ts +2 -83
  23. package/dist/ir/explicit-parser.d.ts.map +1 -1
  24. package/dist/ir/explicit-renderer.d.ts +2 -31
  25. package/dist/ir/explicit-renderer.d.ts.map +1 -1
  26. package/dist/ir/index.js +89 -1260
  27. package/dist/ir/index.js.map +1 -1
  28. package/dist/ir/protocol-json.d.ts +2 -70
  29. package/dist/ir/protocol-json.d.ts.map +1 -1
  30. package/dist/ir/references.d.ts +2 -16
  31. package/dist/ir/references.d.ts.map +1 -1
  32. package/dist/ir/types.d.ts +2 -148
  33. package/dist/ir/types.d.ts.map +1 -1
  34. package/dist/parsing/index.js +19 -12
  35. package/dist/parsing/index.js.map +1 -1
  36. package/dist/schema/command-schema.d.ts +3 -92
  37. package/dist/schema/command-schema.d.ts.map +1 -1
  38. package/dist/schema/index.js +3 -20
  39. package/dist/schema/index.js.map +1 -1
  40. package/dist/testing/index.js +1133 -755
  41. package/dist/testing/index.js.map +1 -1
  42. package/package.json +6 -2
  43. package/src/core/types.ts +71 -600
  44. package/src/generation/diagnostics.ts +12 -233
  45. package/src/interfaces/value-extractor.ts +32 -0
  46. package/src/ir/explicit-parser.ts +12 -792
  47. package/src/ir/explicit-renderer.ts +2 -195
  48. package/src/ir/from-interchange.test.ts +91 -4
  49. package/src/ir/from-interchange.ts +59 -0
  50. package/src/ir/protocol-json.test.ts +16 -7
  51. package/src/ir/protocol-json.ts +9 -748
  52. package/src/ir/references.ts +2 -30
  53. package/src/ir/types.ts +18 -190
  54. package/src/schema/command-schema.ts +3 -134
@@ -1,33 +1,5 @@
1
1
  /**
2
- * Reference Validation
3
- *
4
- * Configurable validation for reference values (me, you, it, result, etc.).
5
- * Domain DSLs can provide custom reference sets.
2
+ * Reference Validation — re-exported from @lokascript/intent
6
3
  */
7
4
 
8
- /**
9
- * Default set of valid references.
10
- * Covers the common hyperscript references; domain DSLs can extend or replace.
11
- */
12
- export const DEFAULT_REFERENCES: ReadonlySet<string> = new Set([
13
- 'me',
14
- 'you',
15
- 'it',
16
- 'result',
17
- 'event',
18
- 'target',
19
- 'body',
20
- ]);
21
-
22
- /**
23
- * Check if a value is a valid reference name.
24
- *
25
- * @param value - The string to check
26
- * @param referenceSet - Custom reference set (defaults to DEFAULT_REFERENCES)
27
- */
28
- export function isValidReference(
29
- value: string,
30
- referenceSet: ReadonlySet<string> = DEFAULT_REFERENCES
31
- ): boolean {
32
- return referenceSet.has(value);
33
- }
5
+ export { DEFAULT_REFERENCES, isValidReference } from '@lokascript/intent';
package/src/ir/types.ts CHANGED
@@ -1,191 +1,19 @@
1
1
  /**
2
- * IR (Intermediate Representation) Types
3
- *
4
- * Types for the explicit bracket syntax, LLM JSON format, and
5
- * schema-based validation. These are domain-agnostic — they work
6
- * for any DSL built on the framework.
7
- */
8
-
9
- import type { CommandSchema } from '../schema/command-schema';
10
-
11
- // =============================================================================
12
- // LLM JSON Format
13
- // =============================================================================
14
-
15
- /**
16
- * Structured input format for LLMs.
17
- * No parsing ambiguity — action and roles are explicitly typed.
18
- *
19
- * @example
20
- * ```json
21
- * {
22
- * "action": "toggle",
23
- * "roles": { "patient": { "type": "selector", "value": ".active" } },
24
- * "trigger": { "event": "click" }
25
- * }
26
- * ```
27
- */
28
- export interface SemanticJSON {
29
- /** The command/action name */
30
- action: string;
31
- /** Named semantic roles with typed values */
32
- roles: Record<string, SemanticJSONValue>;
33
- /** Optional event trigger (wraps command in event handler) */
34
- trigger?: {
35
- event: string;
36
- modifiers?: Record<string, unknown>;
37
- };
38
- }
39
-
40
- /**
41
- * A typed value in the LLM JSON format.
42
- */
43
- export interface SemanticJSONValue {
44
- type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
45
- value: string | number | boolean;
46
- }
47
-
48
- // =============================================================================
49
- // Schema Lookup
50
- // =============================================================================
51
-
52
- /**
53
- * Interface for optional schema-based role validation in the explicit parser.
54
- * Consumers provide this to validate roles against command definitions.
55
- *
56
- * When not provided, the parser accepts any role names.
57
- */
58
- export interface SchemaLookup {
59
- getSchema(action: string): CommandSchema | undefined;
60
- }
61
-
62
- /**
63
- * Options for parseExplicit().
64
- */
65
- export interface ParseExplicitOptions {
66
- /** Optional schema lookup for role validation */
67
- schemaLookup?: SchemaLookup;
68
- /** Custom set of valid reference names (defaults to DEFAULT_REFERENCES) */
69
- referenceSet?: ReadonlySet<string>;
70
- /**
71
- * When true, validation errors are collected as diagnostics on the
72
- * returned node instead of throwing. Fatal parse errors (missing brackets,
73
- * empty input) still throw. Default: false.
74
- */
75
- collectDiagnostics?: boolean;
76
- }
77
-
78
- // =============================================================================
79
- // Diagnostics
80
- // =============================================================================
81
-
82
- /**
83
- * A diagnostic message from IR validation.
84
- *
85
- * Uses required `code` field (compatible with both framework Diagnostic
86
- * and compilation-service Diagnostic types via structural typing).
87
- */
88
- export interface IRDiagnostic {
89
- severity: 'error' | 'warning' | 'info';
90
- code: string;
91
- message: string;
92
- suggestion?: string;
93
- }
94
-
95
- // =============================================================================
96
- // Protocol Full-Fidelity JSON Format
97
- // =============================================================================
98
- // These types match the wire format spec (protocol/spec/wire-format.md).
99
- // Wire format has 3 node kinds; TS-only kinds (conditional, loop) are losslessly
100
- // encoded as command nodes with v1.1 extension fields.
101
- // property-path is flattened to expression.
102
-
103
- export type ProtocolNodeKind = 'command' | 'event-handler' | 'compound';
104
- export type ProtocolChainType = 'then' | 'and' | 'async' | 'sequential' | 'pipe';
105
-
106
- /**
107
- * A typed semantic value in the protocol full-fidelity JSON format.
108
- * Matches protocol/spec/wire-format.md "Value Shapes" table.
109
- */
110
- export interface ProtocolValueJSON {
111
- type: 'selector' | 'literal' | 'reference' | 'expression' | 'property-path' | 'flag';
112
- value?: string | number | boolean;
113
- dataType?: 'string' | 'number' | 'boolean' | 'duration';
114
- raw?: string; // expression only
115
- name?: string; // flag only
116
- enabled?: boolean; // flag only
117
- selectorKind?: 'id' | 'class' | 'attribute' | 'element' | 'complex'; // selector only, optional
118
- }
119
-
120
- /**
121
- * Protocol JSON node — matches protocol/spec/wire-format.md.
122
- * Produced by toProtocolJSON() and consumed by fromProtocolJSON().
123
- *
124
- * `kind` defaults to `"command"` when omitted.
125
- * `trigger` is convenience sugar that wraps a command in an event handler.
126
- */
127
- export interface ProtocolNodeJSON {
128
- kind?: ProtocolNodeKind; // defaults to "command" when absent
129
- action: string;
130
- roles: Record<string, ProtocolValueJSON>;
131
- trigger?: { event: string; modifiers?: Record<string, unknown> }; // convenience sugar
132
- body?: ProtocolNodeJSON[]; // event-handler body OR try body (v1.2)
133
- statements?: ProtocolNodeJSON[]; // compound only
134
- chainType?: ProtocolChainType; // compound only
135
- // Conditional fields (v1.1)
136
- thenBranch?: ProtocolNodeJSON[];
137
- elseBranch?: ProtocolNodeJSON[];
138
- // Loop fields (v1.1)
139
- loopVariant?: 'forever' | 'times' | 'for' | 'while' | 'until';
140
- loopBody?: ProtocolNodeJSON[];
141
- loopVariable?: string;
142
- indexVariable?: string;
143
- // Type constraint diagnostics (v1.2)
144
- diagnostics?: ProtocolDiagnosticJSON[];
145
- // Metadata annotations (v1.2)
146
- annotations?: AnnotationJSON[];
147
- // Error handling: try/catch/finally (v1.2)
148
- catchBranch?: ProtocolNodeJSON[];
149
- finallyBranch?: ProtocolNodeJSON[];
150
- // Async coordination: all/race (v1.2)
151
- asyncVariant?: 'all' | 'race';
152
- asyncBody?: ProtocolNodeJSON[];
153
- // Pattern matching: match/arms (v1.2)
154
- arms?: MatchArmJSON[];
155
- defaultArm?: ProtocolNodeJSON[];
156
- }
157
-
158
- // =============================================================================
159
- // v1.2 Sub-types
160
- // =============================================================================
161
-
162
- /** A diagnostic in protocol wire format (v1.2, extended v1.2.1). */
163
- export interface ProtocolDiagnosticJSON {
164
- level: 'error' | 'warning' | 'info';
165
- role?: string;
166
- message: string;
167
- code?: string;
168
- /** v1.2.1: source parser/stage that produced this diagnostic. */
169
- source?: string;
170
- /** v1.2.1: actionable fix suggestions. */
171
- suggestions?: string[];
172
- }
173
-
174
- /** A metadata annotation in protocol wire format (v1.2). */
175
- export interface AnnotationJSON {
176
- name: string;
177
- value?: string;
178
- }
179
-
180
- /** A match arm in protocol wire format (v1.2). */
181
- export interface MatchArmJSON {
182
- pattern: ProtocolValueJSON;
183
- body: ProtocolNodeJSON[];
184
- }
185
-
186
- /** Versioned envelope for multi-node LSE documents (v1.2). */
187
- export interface LSEEnvelopeJSON {
188
- lseVersion: string;
189
- features?: string[];
190
- nodes: ProtocolNodeJSON[];
191
- }
2
+ * IR Types — re-exported from @lokascript/intent
3
+ */
4
+
5
+ export type {
6
+ SemanticJSON,
7
+ SemanticJSONValue,
8
+ SchemaLookup,
9
+ ParseExplicitOptions,
10
+ IRDiagnostic,
11
+ ProtocolNodeKind,
12
+ ProtocolChainType,
13
+ ProtocolValueJSON,
14
+ ProtocolNodeJSON,
15
+ ProtocolDiagnosticJSON,
16
+ AnnotationJSON,
17
+ MatchArmJSON,
18
+ LSEEnvelopeJSON,
19
+ } from '@lokascript/intent';
@@ -1,137 +1,6 @@
1
1
  /**
2
- * Command Schema Types
3
- *
4
- * Defines the structure of DSL commands for pattern generation.
5
- * These schemas are language-neutral and describe the semantic structure
6
- * of commands rather than their surface syntax.
2
+ * Command Schema Types — re-exported from @lokascript/intent
7
3
  */
8
4
 
9
- import type { ActionType, SemanticRole, SemanticValue, ExpectedType } from '../core/types';
10
-
11
- /**
12
- * Command schema - defines a DSL command's structure.
13
- */
14
- export interface CommandSchema {
15
- /** The action type (command name) */
16
- readonly action: ActionType;
17
-
18
- /** Human-readable description */
19
- readonly description: string;
20
-
21
- /** Roles this command accepts */
22
- readonly roles: RoleSpec[];
23
-
24
- /** The primary role (what the command acts on) */
25
- readonly primaryRole: SemanticRole;
26
-
27
- /** Category for grouping (DSL-specific) */
28
- readonly category: string;
29
-
30
- /** Whether this command typically has a body (like event handlers, blocks) */
31
- readonly hasBody?: boolean;
32
-
33
- /** Notes about special handling or usage */
34
- readonly notes?: string;
35
- }
36
-
37
- /**
38
- * Role specification - defines a semantic role in a command.
39
- */
40
- export interface RoleSpec {
41
- /** The semantic role */
42
- readonly role: SemanticRole;
43
-
44
- /** Description of what this role represents */
45
- readonly description: string;
46
-
47
- /** Whether this role is required */
48
- readonly required: boolean;
49
-
50
- /** Expected value types */
51
- readonly expectedTypes: Array<ExpectedType>;
52
-
53
- /** Default value if not provided */
54
- readonly default?: SemanticValue;
55
-
56
- /** Position hint for SVO languages (higher = earlier) */
57
- readonly svoPosition?: number;
58
-
59
- /** Position hint for SOV languages (higher = earlier) */
60
- readonly sovPosition?: number;
61
-
62
- /**
63
- * Override the default role marker for this command.
64
- * Maps language code to the marker to use (e.g., { en: 'from', ja: 'から' }).
65
- * If not specified, uses the language profile's default roleMarker.
66
- */
67
- readonly markerOverride?: Record<string, string>;
68
-
69
- /**
70
- * Override the rendering marker separately from parsing.
71
- * Used when the parsing grammar differs from rendered output.
72
- * Maps language code to the rendering marker.
73
- */
74
- readonly renderOverride?: Record<string, string>;
75
-
76
- /**
77
- * Override the marker position for this role in the generated pattern.
78
- * 'before' = marker precedes the role value (preposition: "set X").
79
- * 'after' = marker follows the role value (postposition: "X から").
80
- * If not set, falls back to the language profile's roleMarkers position,
81
- * then to the word-order default (SOV='after', else='before').
82
- */
83
- readonly markerPosition?: 'before' | 'after';
84
-
85
- /**
86
- * When true, this role captures all remaining tokens until the next
87
- * recognized marker keyword or end of input, joining their values
88
- * with spaces into a single ExpressionValue.
89
- *
90
- * Only meaningful for the last role in a sequence or a role followed
91
- * by a marked role. Default: false.
92
- */
93
- readonly greedy?: boolean;
94
-
95
- /**
96
- * Restricts which selector subtypes are valid for this role (v1.2).
97
- * Only meaningful when expectedTypes includes 'selector'.
98
- * If omitted, all selector kinds are accepted.
99
- *
100
- * Example: `selectorKinds: ['class', 'attribute']` means only `.class`
101
- * and `[attr]` selectors are valid, not `#id` or `*wildcard`.
102
- */
103
- readonly selectorKinds?: ReadonlyArray<'id' | 'class' | 'attribute' | 'element' | 'complex'>;
104
- }
105
-
106
- /**
107
- * Helper to create a command schema with sensible defaults.
108
- * Provides defaults for description, category, and primaryRole.
109
- */
110
- export function defineCommand(
111
- schema: Partial<CommandSchema> & Pick<CommandSchema, 'action' | 'roles'>
112
- ): CommandSchema {
113
- return {
114
- description: schema.description || `${schema.action} command`,
115
- category: schema.category || 'general',
116
- primaryRole: schema.primaryRole || schema.roles[0]?.role || 'patient',
117
- ...schema,
118
- action: schema.action,
119
- roles: schema.roles,
120
- } as CommandSchema;
121
- }
122
-
123
- /**
124
- * Helper to create a role spec with sensible defaults.
125
- * Provides default for description.
126
- */
127
- export function defineRole(
128
- role: Partial<RoleSpec> & Pick<RoleSpec, 'role' | 'required' | 'expectedTypes'>
129
- ): RoleSpec {
130
- return {
131
- description: role.description || `${role.role} role`,
132
- ...role,
133
- role: role.role,
134
- required: role.required,
135
- expectedTypes: role.expectedTypes,
136
- };
137
- }
5
+ export type { CommandSchema, RoleSpec } from '@lokascript/intent';
6
+ export { defineCommand, defineRole, getRoleSpec } from '@lokascript/intent';