@rcrsr/rill 0.16.0 → 0.18.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 (97) hide show
  1. package/README.md +37 -21
  2. package/dist/ast-nodes.d.ts +14 -4
  3. package/dist/ast-unions.d.ts +1 -1
  4. package/dist/constants.d.ts +1 -1
  5. package/dist/constants.js +1 -0
  6. package/dist/error-registry.js +228 -0
  7. package/dist/ext/crypto/index.d.ts +3 -3
  8. package/dist/ext/crypto/index.js +62 -59
  9. package/dist/ext/exec/index.d.ts +3 -3
  10. package/dist/ext/exec/index.js +15 -9
  11. package/dist/ext/fetch/index.d.ts +3 -3
  12. package/dist/ext/fetch/index.js +17 -12
  13. package/dist/ext/fetch/request.js +1 -1
  14. package/dist/ext/fs/index.d.ts +3 -3
  15. package/dist/ext/fs/index.js +256 -266
  16. package/dist/ext/fs/sandbox.d.ts +18 -0
  17. package/dist/ext/fs/sandbox.js +33 -0
  18. package/dist/ext/kv/index.d.ts +3 -3
  19. package/dist/ext/kv/index.js +198 -196
  20. package/dist/ext/kv/store.d.ts +1 -1
  21. package/dist/ext/kv/store.js +2 -1
  22. package/dist/ext-parse-bridge.d.ts +10 -0
  23. package/dist/ext-parse-bridge.js +10 -0
  24. package/dist/generated/introspection-data.d.ts +1 -1
  25. package/dist/generated/introspection-data.js +385 -296
  26. package/dist/generated/version-data.d.ts +1 -1
  27. package/dist/generated/version-data.js +2 -2
  28. package/dist/highlight-map.js +1 -0
  29. package/dist/index.d.ts +1 -4
  30. package/dist/index.js +1 -5
  31. package/dist/lexer/operators.js +1 -0
  32. package/dist/parser/helpers.js +1 -0
  33. package/dist/parser/parser-expr.js +44 -5
  34. package/dist/parser/parser-literals.js +111 -4
  35. package/dist/parser/parser-shape.js +2 -2
  36. package/dist/parser/parser-types.js +12 -0
  37. package/dist/parser/parser-use.js +26 -3
  38. package/dist/parser/parser.d.ts +2 -0
  39. package/dist/parser/parser.js +2 -0
  40. package/dist/runtime/core/callable.d.ts +24 -13
  41. package/dist/runtime/core/callable.js +71 -38
  42. package/dist/runtime/core/context.d.ts +2 -13
  43. package/dist/runtime/core/context.js +80 -79
  44. package/dist/runtime/core/eval/base.d.ts +2 -2
  45. package/dist/runtime/core/eval/base.js +2 -0
  46. package/dist/runtime/core/eval/evaluator.d.ts +1 -1
  47. package/dist/runtime/core/eval/index.d.ts +3 -3
  48. package/dist/runtime/core/eval/index.js +11 -0
  49. package/dist/runtime/core/eval/mixins/closures.js +381 -41
  50. package/dist/runtime/core/eval/mixins/collections.js +81 -6
  51. package/dist/runtime/core/eval/mixins/control-flow.js +1 -1
  52. package/dist/runtime/core/eval/mixins/conversion.js +61 -115
  53. package/dist/runtime/core/eval/mixins/core.js +17 -4
  54. package/dist/runtime/core/eval/mixins/expressions.js +36 -27
  55. package/dist/runtime/core/eval/mixins/extraction.js +2 -3
  56. package/dist/runtime/core/eval/mixins/list-dispatch.js +1 -1
  57. package/dist/runtime/core/eval/mixins/literals.js +17 -6
  58. package/dist/runtime/core/eval/mixins/types.js +73 -54
  59. package/dist/runtime/core/eval/mixins/variables.js +12 -8
  60. package/dist/runtime/core/execute.d.ts +1 -1
  61. package/dist/runtime/core/field-descriptor.d.ts +3 -3
  62. package/dist/runtime/core/field-descriptor.js +2 -1
  63. package/dist/runtime/core/introspection.d.ts +2 -2
  64. package/dist/runtime/core/introspection.js +7 -6
  65. package/dist/runtime/core/resolvers.d.ts +1 -1
  66. package/dist/runtime/core/signals.d.ts +6 -1
  67. package/dist/runtime/core/signals.js +9 -0
  68. package/dist/runtime/core/types/constructors.d.ts +54 -0
  69. package/dist/runtime/core/types/constructors.js +201 -0
  70. package/dist/runtime/core/types/guards.d.ts +42 -0
  71. package/dist/runtime/core/types/guards.js +88 -0
  72. package/dist/runtime/core/types/index.d.ts +18 -0
  73. package/dist/runtime/core/types/index.js +19 -0
  74. package/dist/runtime/core/types/markers.d.ts +12 -0
  75. package/dist/runtime/core/types/markers.js +7 -0
  76. package/dist/runtime/core/types/operations.d.ts +98 -0
  77. package/dist/runtime/core/types/operations.js +804 -0
  78. package/dist/runtime/core/types/registrations.d.ts +126 -0
  79. package/dist/runtime/core/types/registrations.js +751 -0
  80. package/dist/runtime/core/{types.d.ts → types/runtime.d.ts} +22 -10
  81. package/dist/runtime/core/types/structures.d.ts +146 -0
  82. package/dist/runtime/core/types/structures.js +12 -0
  83. package/dist/runtime/core/values.d.ts +29 -209
  84. package/dist/runtime/core/values.js +56 -968
  85. package/dist/runtime/ext/builtins.js +88 -68
  86. package/dist/runtime/ext/extensions.d.ts +31 -125
  87. package/dist/runtime/ext/extensions.js +2 -94
  88. package/dist/runtime/ext/test-context.d.ts +28 -0
  89. package/dist/runtime/ext/test-context.js +155 -0
  90. package/dist/runtime/index.d.ts +12 -12
  91. package/dist/runtime/index.js +13 -5
  92. package/dist/signature-parser.d.ts +2 -2
  93. package/dist/signature-parser.js +14 -14
  94. package/dist/token-types.d.ts +1 -0
  95. package/dist/token-types.js +1 -0
  96. package/package.json +1 -1
  97. /package/dist/runtime/core/{types.js → types/runtime.js} +0 -0
package/README.md CHANGED
@@ -13,24 +13,34 @@ npm install @rcrsr/rill
13
13
  ## Quick Start
14
14
 
15
15
  ```typescript
16
- import { parse, execute, createRuntimeContext } from '@rcrsr/rill';
16
+ import { parse, execute, createRuntimeContext, toCallable } from '@rcrsr/rill';
17
+ import type { ExtensionFactoryResult } from '@rcrsr/rill';
18
+
19
+ function createMyExtension(): ExtensionFactoryResult {
20
+ return {
21
+ value: {
22
+ prompt: toCallable({
23
+ params: [{ name: 'message', type: { kind: 'string' } }],
24
+ fn: async (args) => await callYourLLM(args.message),
25
+ annotations: { description: 'Call your LLM' },
26
+ returnType: { kind: 'string' },
27
+ }),
28
+ },
29
+ };
30
+ }
31
+
32
+ const ext = createMyExtension();
33
+ const ctx = createRuntimeContext({
34
+ variables: { app: ext.value },
35
+ });
17
36
 
18
37
  const script = `
19
- prompt("Analyze this code for issues")
38
+ app.prompt("Analyze this code for issues")
20
39
  -> .contains("ERROR") ? error($) ! "Analysis complete"
21
40
  `;
22
41
 
23
- const ctx = createRuntimeContext({
24
- functions: {
25
- prompt: {
26
- params: [{ name: 'message', type: 'string' }],
27
- fn: async (args) => await callYourLLM(args[0]),
28
- },
29
- },
30
- });
31
-
32
42
  const result = await execute(parse(script), ctx);
33
- console.log(result.value);
43
+ console.log(result.result);
34
44
  ```
35
45
 
36
46
  ## API
@@ -47,25 +57,31 @@ Source Text → parse() → AST → execute() → Result
47
57
  | `execute(ast, ctx)` | Execute an AST with a runtime context |
48
58
  | `createRuntimeContext(opts)` | Create a configured runtime context |
49
59
  | `callable(fn, isProperty?)` | Wrap a function as a rill-callable value |
50
- | `prefixFunctions(prefix, fns)` | Namespace host functions (e.g., `app::`) |
60
+ | `toCallable(def)` | Convert a `RillFunction` to an `ApplicationCallable` |
61
+ | `createTestContext(extensions)` | Wire extensions for testing without config infrastructure |
51
62
 
52
63
  ### Runtime Options
53
64
 
54
65
  ```typescript
66
+ const ext = createMyExtension();
67
+
55
68
  const ctx = createRuntimeContext({
56
- // Host functions available to scripts
69
+ // Extension values injected as variables (recommended)
70
+ variables: {
71
+ app: ext.value,
72
+ config: { greeting: 'hello' },
73
+ },
74
+
75
+ // Legacy: direct function registration (still supported)
57
76
  functions: {
58
77
  prompt: {
59
- params: [{ name: 'text', type: 'string' }],
78
+ params: [{ name: 'text', type: { kind: 'string' } }],
60
79
  fn: async (args, ctx, location) => { /* ... */ },
80
+ annotations: {},
81
+ returnType: { kind: 'string' },
61
82
  },
62
83
  },
63
84
 
64
- // Variables injected into script scope
65
- variables: {
66
- config: { greeting: 'hello' },
67
- },
68
-
69
85
  // Callbacks
70
86
  callbacks: {
71
87
  onLog: (value) => console.log(value),
@@ -159,7 +175,7 @@ import { createCryptoExtension } from '@rcrsr/rill/ext/crypto';
159
175
  | `@rcrsr/rill/ext/kv` | `createKvExtension(config)` | Key-value store with JSON persistence and schema validation |
160
176
  | `@rcrsr/rill/ext/crypto` | `createCryptoExtension(config)` | Cryptographic functions (hash, hmac, uuid, random) |
161
177
 
162
- Each factory returns an `ExtensionResult` with host function definitions ready to integrate into your runtime context.
178
+ Each factory returns an `ExtensionFactoryResult` with a `value` dict of host functions and optional lifecycle hooks (`dispose`, `suspend`, `restore`) ready to integrate into your runtime context.
163
179
 
164
180
  > **Note:** These extensions require Node.js APIs and are not compatible with browser environments.
165
181
 
@@ -129,6 +129,15 @@ export interface BreakNode extends BaseNode {
129
129
  export interface ReturnNode extends BaseNode {
130
130
  readonly type: 'Return';
131
131
  }
132
+ /**
133
+ * Yield: emit value from a stream closure.
134
+ * Used as chain terminator: $x -> yield
135
+ * Or bare: yield (implicit $ -> yield)
136
+ * Only valid inside a closure with :stream(T):R return type annotation.
137
+ */
138
+ export interface YieldNode extends BaseNode {
139
+ readonly type: 'Yield';
140
+ }
132
141
  /**
133
142
  * Pass: pass through pipe value unchanged.
134
143
  * Used as chain terminator: $x -> pass
@@ -157,8 +166,8 @@ export interface ErrorNode extends BaseNode {
157
166
  readonly message: StringLiteralNode | null;
158
167
  }
159
168
  export type ExpressionNode = PipeChainNode;
160
- /** Chain terminator: capture, break, or return */
161
- export type ChainTerminator = CaptureNode | BreakNode | ReturnNode;
169
+ /** Chain terminator: capture, break, return, or yield */
170
+ export type ChainTerminator = CaptureNode | BreakNode | ReturnNode | YieldNode;
162
171
  export interface PipeChainNode extends BaseNode {
163
172
  readonly type: 'PipeChain';
164
173
  readonly head: ArithHead;
@@ -244,7 +253,7 @@ export interface DictEntryNode extends BaseNode {
244
253
  */
245
254
  export interface TypeConstructorNode extends BaseNode {
246
255
  readonly type: 'TypeConstructor';
247
- readonly constructorName: 'list' | 'dict' | 'tuple' | 'ordered';
256
+ readonly constructorName: 'list' | 'dict' | 'tuple' | 'ordered' | 'stream';
248
257
  readonly args: FieldArg[];
249
258
  }
250
259
  /**
@@ -797,8 +806,9 @@ export interface UseExprNode extends BaseNode {
797
806
  readonly closureAnnotation: ReadonlyArray<{
798
807
  readonly name: string;
799
808
  readonly typeRef: TypeRef;
809
+ readonly defaultValue?: LiteralNode;
800
810
  }> | null;
801
811
  }
802
812
  export type SimplePrimaryNode = LiteralNode | VariableNode | HostCallNode | MethodCallNode | BlockNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | PostfixExprNode | TypeAssertionNode | TypeCheckNode;
803
- export type ASTNode = ScriptNode | FrontmatterNode | ClosureNode | ClosureParamNode | StatementNode | CaptureNode | BreakNode | ReturnNode | PassNode | AssertNode | PipeChainNode | PostfixExprNode | MethodCallNode | InvokeNode | AnnotationAccessNode | HostCallNode | HostRefNode | ClosureCallNode | PipeInvokeNode | VariableNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | StringLiteralNode | InterpolationNode | NumberLiteralNode | BoolLiteralNode | ListSpreadNode | DictNode | DictEntryNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | DestructureNode | DestructPatternNode | SliceNode | TypeAssertionNode | TypeCheckNode | TypeConstructorNode | ClosureSigLiteralNode | AnnotatedStatementNode | AnnotatedExprNode | NamedArgNode | SpreadArgNode | EachExprNode | MapExprNode | FoldExprNode | FilterExprNode | RecoveryErrorNode | ErrorNode | TypeNameExprNode | ListLiteralNode | DictLiteralNode | TupleLiteralNode | OrderedLiteralNode | DestructNode | ConvertNode | UseExprNode;
813
+ export type ASTNode = ScriptNode | FrontmatterNode | ClosureNode | ClosureParamNode | StatementNode | CaptureNode | BreakNode | ReturnNode | YieldNode | PassNode | AssertNode | PipeChainNode | PostfixExprNode | MethodCallNode | InvokeNode | AnnotationAccessNode | HostCallNode | HostRefNode | ClosureCallNode | PipeInvokeNode | VariableNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | StringLiteralNode | InterpolationNode | NumberLiteralNode | BoolLiteralNode | ListSpreadNode | DictNode | DictEntryNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | DestructureNode | DestructPatternNode | SliceNode | TypeAssertionNode | TypeCheckNode | TypeConstructorNode | ClosureSigLiteralNode | AnnotatedStatementNode | AnnotatedExprNode | NamedArgNode | SpreadArgNode | EachExprNode | MapExprNode | FoldExprNode | FilterExprNode | RecoveryErrorNode | ErrorNode | TypeNameExprNode | ListLiteralNode | DictLiteralNode | TupleLiteralNode | OrderedLiteralNode | DestructNode | ConvertNode | UseExprNode;
804
814
  export {};
@@ -2,4 +2,4 @@
2
2
  * AST Type Unions
3
3
  * String union of all AST node type literals.
4
4
  */
5
- export type NodeType = 'Script' | 'Frontmatter' | 'Closure' | 'ClosureParam' | 'Statement' | 'PipeChain' | 'PostfixExpr' | 'MethodCall' | 'Invoke' | 'AnnotationAccess' | 'HostCall' | 'HostRef' | 'ClosureCall' | 'PipeInvoke' | 'Variable' | 'Capture' | 'Conditional' | 'WhileLoop' | 'DoWhileLoop' | 'Block' | 'StringLiteral' | 'Interpolation' | 'NumberLiteral' | 'BoolLiteral' | 'ListSpread' | 'Dict' | 'DictEntry' | 'Break' | 'Return' | 'Pass' | 'Assert' | 'BinaryExpr' | 'UnaryExpr' | 'GroupedExpr' | 'Destructure' | 'DestructPattern' | 'Slice' | 'TypeAssertion' | 'TypeCheck' | 'AnnotatedStatement' | 'AnnotatedExpr' | 'NamedArg' | 'SpreadArg' | 'EachExpr' | 'MapExpr' | 'FoldExpr' | 'FilterExpr' | 'RecoveryError' | 'Error' | 'TypeNameExpr' | 'TypeConstructor' | 'ClosureSigLiteral' | 'ListLiteral' | 'DictLiteral' | 'TupleLiteral' | 'OrderedLiteral' | 'Destruct' | 'Convert' | 'UseExpr';
5
+ export type NodeType = 'Script' | 'Frontmatter' | 'Closure' | 'ClosureParam' | 'Statement' | 'PipeChain' | 'PostfixExpr' | 'MethodCall' | 'Invoke' | 'AnnotationAccess' | 'HostCall' | 'HostRef' | 'ClosureCall' | 'PipeInvoke' | 'Variable' | 'Capture' | 'Conditional' | 'WhileLoop' | 'DoWhileLoop' | 'Block' | 'StringLiteral' | 'Interpolation' | 'NumberLiteral' | 'BoolLiteral' | 'ListSpread' | 'Dict' | 'DictEntry' | 'Break' | 'Return' | 'Yield' | 'Pass' | 'Assert' | 'BinaryExpr' | 'UnaryExpr' | 'GroupedExpr' | 'Destructure' | 'DestructPattern' | 'Slice' | 'TypeAssertion' | 'TypeCheck' | 'AnnotatedStatement' | 'AnnotatedExpr' | 'NamedArg' | 'SpreadArg' | 'EachExpr' | 'MapExpr' | 'FoldExpr' | 'FilterExpr' | 'RecoveryError' | 'Error' | 'TypeNameExpr' | 'TypeConstructor' | 'ClosureSigLiteral' | 'ListLiteral' | 'DictLiteral' | 'TupleLiteral' | 'OrderedLiteral' | 'Destruct' | 'Convert' | 'UseExpr';
@@ -10,4 +10,4 @@
10
10
  * - Parser: array iteration for token validation
11
11
  * - Runtime: Set-based O(1) membership lookup
12
12
  */
13
- export declare const VALID_TYPE_NAMES: readonly ["string", "number", "bool", "closure", "list", "dict", "tuple", "ordered", "vector", "any", "type", "iterator"];
13
+ export declare const VALID_TYPE_NAMES: readonly ["string", "number", "bool", "closure", "list", "dict", "tuple", "ordered", "vector", "any", "type", "iterator", "stream"];
package/dist/constants.js CHANGED
@@ -26,4 +26,5 @@ export const VALID_TYPE_NAMES = [
26
26
  'any',
27
27
  'type',
28
28
  'iterator',
29
+ 'stream',
29
30
  ];
@@ -228,6 +228,24 @@ const ERROR_DEFINITIONS = [
228
228
  },
229
229
  ],
230
230
  },
231
+ {
232
+ errorId: 'RILL-P006',
233
+ category: 'parse',
234
+ description: 'Invalid syntax in context',
235
+ messageTemplate: '{message}',
236
+ cause: 'A syntactic construct was used in a context where it is not allowed.',
237
+ resolution: 'Check that the construct is used in the correct context.',
238
+ examples: [
239
+ {
240
+ description: 'Spread in unsupported position',
241
+ code: '$x.method(...$args) # spread not supported in method calls',
242
+ },
243
+ {
244
+ description: 'yield outside stream closure',
245
+ code: '|x| yield # yield requires :stream() return type',
246
+ },
247
+ ],
248
+ },
231
249
  {
232
250
  errorId: 'RILL-P007',
233
251
  category: 'parse',
@@ -1330,6 +1348,216 @@ const ERROR_DEFINITIONS = [
1330
1348
  },
1331
1349
  ],
1332
1350
  },
1351
+ // Type conversion: string to number (RILL-R064)
1352
+ {
1353
+ errorId: 'RILL-R064',
1354
+ category: 'runtime',
1355
+ description: 'Cannot convert string to number',
1356
+ messageTemplate: 'Cannot convert string "{value}" to number',
1357
+ cause: 'The string value is not a valid numeric representation or is empty/whitespace.',
1358
+ resolution: 'Ensure the string contains a valid number before converting. Use as(number) only on numeric strings.',
1359
+ examples: [
1360
+ {
1361
+ description: 'Non-numeric string conversion',
1362
+ code: '"hello" -> as(number) # Error: not a valid number',
1363
+ },
1364
+ ],
1365
+ },
1366
+ // Type conversion: string to bool (RILL-R065)
1367
+ {
1368
+ errorId: 'RILL-R065',
1369
+ category: 'runtime',
1370
+ description: 'Cannot convert string to bool',
1371
+ messageTemplate: 'Cannot convert string "{value}" to bool',
1372
+ cause: 'Only the strings "true" and "false" can convert to bool.',
1373
+ resolution: 'Use the exact strings "true" or "false" for bool conversion.',
1374
+ examples: [
1375
+ {
1376
+ description: 'Invalid bool string',
1377
+ code: '"yes" -> as(bool) # Error: only "true"/"false" allowed',
1378
+ },
1379
+ ],
1380
+ },
1381
+ // Type conversion: number to bool (RILL-R066)
1382
+ {
1383
+ errorId: 'RILL-R066',
1384
+ category: 'runtime',
1385
+ description: 'Cannot convert number to bool',
1386
+ messageTemplate: 'Cannot convert number {value} to bool',
1387
+ cause: 'Only the numbers 0 and 1 can convert to bool. Other numeric values have no bool equivalent.',
1388
+ resolution: 'Use 0 (false) or 1 (true) for number-to-bool conversion.',
1389
+ examples: [
1390
+ {
1391
+ description: 'Non-binary number conversion',
1392
+ code: '42 -> as(bool) # Error: only 0 and 1 allowed',
1393
+ },
1394
+ ],
1395
+ },
1396
+ // JSON serialization: value not serializable (RILL-R067)
1397
+ {
1398
+ errorId: 'RILL-R067',
1399
+ category: 'runtime',
1400
+ description: 'Value is not JSON-serializable',
1401
+ messageTemplate: '{typeName} are not JSON-serializable',
1402
+ cause: 'The value type cannot be represented in JSON. Only strings, numbers, bools, lists, and dicts serialize.',
1403
+ resolution: 'Convert the value to a serializable type before JSON operations. Extract data from closures or iterators first.',
1404
+ examples: [
1405
+ {
1406
+ description: 'Closure in JSON context',
1407
+ code: '|x| $x + 1 -> as(string) # Error: closures not serializable',
1408
+ },
1409
+ ],
1410
+ },
1411
+ // Method registration: frozen type registration (RILL-R068)
1412
+ {
1413
+ errorId: 'RILL-R068',
1414
+ category: 'runtime',
1415
+ description: 'Type registration is frozen',
1416
+ messageTemplate: "Cannot populate methods on type '{typeName}': registration is frozen",
1417
+ cause: 'The type registration object was deep-frozen, preventing method assignment.',
1418
+ resolution: 'Ensure type registrations are not deep-frozen before calling populateBuiltinMethods.',
1419
+ examples: [
1420
+ {
1421
+ description: 'Frozen registration object',
1422
+ code: '# Object.freeze(registration) prevents method population',
1423
+ },
1424
+ ],
1425
+ },
1426
+ // Context validation: function missing description (RILL-R069)
1427
+ {
1428
+ errorId: 'RILL-R069',
1429
+ category: 'runtime',
1430
+ description: 'Function missing required description',
1431
+ messageTemplate: "Function '{name}' requires description (requireDescriptions enabled)",
1432
+ cause: 'The requireDescriptions option is enabled but the function has no description.',
1433
+ resolution: 'Add a description field to the function definition, or disable requireDescriptions.',
1434
+ examples: [
1435
+ {
1436
+ description: 'Missing function description',
1437
+ code: '# registerFunction("greet", { fn: ... }) with requireDescriptions: true',
1438
+ },
1439
+ ],
1440
+ },
1441
+ // Context validation: parameter missing description (RILL-R070)
1442
+ {
1443
+ errorId: 'RILL-R070',
1444
+ category: 'runtime',
1445
+ description: 'Parameter missing required description',
1446
+ messageTemplate: "Parameter '{paramName}' of function '{functionName}' requires description (requireDescriptions enabled)",
1447
+ cause: 'The requireDescriptions option is enabled but a parameter has no description annotation.',
1448
+ resolution: 'Add a description annotation to each parameter, or disable requireDescriptions.',
1449
+ examples: [
1450
+ {
1451
+ description: 'Missing parameter description',
1452
+ code: '# param { name: "x", annotations: {} } with requireDescriptions: true',
1453
+ },
1454
+ ],
1455
+ },
1456
+ // Context validation: duplicate type registration (RILL-R071)
1457
+ {
1458
+ errorId: 'RILL-R071',
1459
+ category: 'runtime',
1460
+ description: 'Duplicate type registration',
1461
+ messageTemplate: "Duplicate type registration '{typeName}'",
1462
+ cause: 'Two type registrations share the same name. Each type name must be unique.',
1463
+ resolution: 'Remove or rename the duplicate type registration.',
1464
+ examples: [
1465
+ {
1466
+ description: 'Duplicate type name',
1467
+ code: '# Two registrations both named "string"',
1468
+ },
1469
+ ],
1470
+ },
1471
+ // Context validation: missing format protocol (RILL-R072)
1472
+ {
1473
+ errorId: 'RILL-R072',
1474
+ category: 'runtime',
1475
+ description: 'Type missing format protocol',
1476
+ messageTemplate: "Type '{typeName}' missing required format protocol",
1477
+ cause: 'Every type registration must include a format function in its protocol.',
1478
+ resolution: 'Add a format function to the type registration protocol.',
1479
+ examples: [
1480
+ {
1481
+ description: 'Missing format in protocol',
1482
+ code: '# TypeRegistration { name: "custom", protocol: {} } missing format',
1483
+ },
1484
+ ],
1485
+ },
1486
+ // Context validation: duplicate method on type (RILL-R073)
1487
+ {
1488
+ errorId: 'RILL-R073',
1489
+ category: 'runtime',
1490
+ description: 'Duplicate method on type',
1491
+ messageTemplate: "Duplicate method '{methodName}' on type '{typeName}'",
1492
+ cause: 'A method with the same name is registered twice on the same type.',
1493
+ resolution: 'Remove the duplicate method registration or rename one of them.',
1494
+ examples: [
1495
+ {
1496
+ description: 'Method registered twice',
1497
+ code: '# Type "string" has two methods both named "split"',
1498
+ },
1499
+ ],
1500
+ },
1501
+ // Value validation: empty vector (RILL-R074)
1502
+ {
1503
+ errorId: 'RILL-R074',
1504
+ category: 'runtime',
1505
+ description: 'Vector requires at least one dimension',
1506
+ messageTemplate: 'Vector data must have at least one dimension',
1507
+ cause: 'An empty Float32Array was passed to createVector. Vectors must have at least one element.',
1508
+ resolution: 'Provide a non-empty Float32Array when creating vectors.',
1509
+ examples: [
1510
+ {
1511
+ description: 'Zero-dimension vector',
1512
+ code: '# createVector(new Float32Array([]), "model") fails',
1513
+ },
1514
+ ],
1515
+ },
1516
+ // Extension validation: missing event field (RILL-R075)
1517
+ {
1518
+ errorId: 'RILL-R075',
1519
+ category: 'runtime',
1520
+ description: 'Event missing event field',
1521
+ messageTemplate: 'Event must include non-empty event field',
1522
+ cause: 'The event object passed to emitExtensionEvent has no event field or the field is empty.',
1523
+ resolution: 'Include a non-empty string event field in the event object.',
1524
+ examples: [
1525
+ {
1526
+ description: 'Empty event field',
1527
+ code: '# emitExtensionEvent(ctx, { event: "" }) fails',
1528
+ },
1529
+ ],
1530
+ },
1531
+ // Module resolution: unknown module (RILL-R076)
1532
+ {
1533
+ errorId: 'RILL-R076',
1534
+ category: 'runtime',
1535
+ description: 'Unknown module resource',
1536
+ messageTemplate: "Unknown module '{resource}'",
1537
+ cause: 'The module resolver received a resource identifier it does not recognize.',
1538
+ resolution: 'Use a valid module resource. The ext module resolver only handles the "ext" resource.',
1539
+ examples: [
1540
+ {
1541
+ description: 'Invalid module resource',
1542
+ code: 'use<module:unknown> # Error: unknown module',
1543
+ },
1544
+ ],
1545
+ },
1546
+ // Callable validation: invalid default value (RILL-R077)
1547
+ {
1548
+ errorId: 'RILL-R077',
1549
+ category: 'runtime',
1550
+ description: 'Invalid parameter default value',
1551
+ messageTemplate: "Invalid defaultValue for parameter '{paramName}': expected {expectedType}, got {actualType}",
1552
+ cause: 'The default value type does not match the declared parameter type.',
1553
+ resolution: 'Ensure the defaultValue matches the parameter type in the function definition.',
1554
+ examples: [
1555
+ {
1556
+ description: 'Type mismatch in default',
1557
+ code: '# param { name: "x", type: "number", defaultValue: "hello" }',
1558
+ },
1559
+ ],
1560
+ },
1333
1561
  // Check Errors (RILL-C0xx)
1334
1562
  {
1335
1563
  errorId: 'RILL-C001',
@@ -4,7 +4,7 @@
4
4
  * Provides cryptographic functions via thin wrapper around node:crypto.
5
5
  * Functions: hash, hmac, uuid, random
6
6
  */
7
- import type { ExtensionResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
7
+ import type { ExtensionFactoryResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
8
8
  export declare const configSchema: ExtensionConfigSchema;
9
9
  /** Crypto extension configuration */
10
10
  export interface CryptoConfig {
@@ -19,7 +19,7 @@ export interface CryptoConfig {
19
19
  * Returns 4 functions: hash, hmac, uuid, random.
20
20
  *
21
21
  * @param config - Crypto configuration
22
- * @returns ExtensionResult with 4 crypto functions
22
+ * @returns ExtensionFactoryResult with 4 crypto functions
23
23
  *
24
24
  * @example
25
25
  * ```typescript
@@ -29,5 +29,5 @@ export interface CryptoConfig {
29
29
  * });
30
30
  * ```
31
31
  */
32
- export declare function createCryptoExtension(config?: CryptoConfig): ExtensionResult;
32
+ export declare function createCryptoExtension(config?: CryptoConfig): ExtensionFactoryResult;
33
33
  export declare const extensionManifest: ExtensionManifest;
@@ -6,7 +6,8 @@
6
6
  */
7
7
  import crypto from 'node:crypto';
8
8
  import { RuntimeError } from '../../error-classes.js';
9
- import { rillTypeToTypeValue, } from '../../runtime/core/values.js';
9
+ import { toCallable } from '../../runtime/core/callable.js';
10
+ import { structureToTypeValue } from '../../runtime/core/values.js';
10
11
  // ============================================================
11
12
  // TYPES
12
13
  // ============================================================
@@ -23,7 +24,7 @@ export const configSchema = {
23
24
  * Returns 4 functions: hash, hmac, uuid, random.
24
25
  *
25
26
  * @param config - Crypto configuration
26
- * @returns ExtensionResult with 4 crypto functions
27
+ * @returns ExtensionFactoryResult with 4 crypto functions
27
28
  *
28
29
  * @example
29
30
  * ```typescript
@@ -100,64 +101,66 @@ export function createCryptoExtension(config = {}) {
100
101
  // EXTENSION RESULT
101
102
  // ============================================================
102
103
  return {
103
- hash: {
104
- params: [
105
- {
106
- name: 'input',
107
- type: { type: 'string' },
108
- defaultValue: undefined,
109
- annotations: { description: 'Content to hash' },
104
+ value: {
105
+ hash: toCallable({
106
+ params: [
107
+ {
108
+ name: 'input',
109
+ type: { kind: 'string' },
110
+ defaultValue: undefined,
111
+ annotations: { description: 'Content to hash' },
112
+ },
113
+ {
114
+ name: 'algorithm',
115
+ type: { kind: 'string' },
116
+ defaultValue: defaultAlgorithm,
117
+ annotations: { description: 'Hash algorithm' },
118
+ },
119
+ ],
120
+ fn: hash,
121
+ annotations: { description: 'Hash content, returns hex output' },
122
+ returnType: structureToTypeValue({ kind: 'string' }),
123
+ }),
124
+ hmac: toCallable({
125
+ params: [
126
+ {
127
+ name: 'input',
128
+ type: { kind: 'string' },
129
+ defaultValue: undefined,
130
+ annotations: { description: 'Content to authenticate' },
131
+ },
132
+ {
133
+ name: 'algorithm',
134
+ type: { kind: 'string' },
135
+ defaultValue: defaultAlgorithm,
136
+ annotations: { description: 'Hash algorithm' },
137
+ },
138
+ ],
139
+ fn: hmac,
140
+ annotations: {
141
+ description: 'Generate HMAC signature, returns hex output',
110
142
  },
111
- {
112
- name: 'algorithm',
113
- type: { type: 'string' },
114
- defaultValue: defaultAlgorithm,
115
- annotations: { description: 'Hash algorithm' },
116
- },
117
- ],
118
- fn: hash,
119
- annotations: { description: 'Hash content, returns hex output' },
120
- returnType: rillTypeToTypeValue({ type: 'string' }),
121
- },
122
- hmac: {
123
- params: [
124
- {
125
- name: 'input',
126
- type: { type: 'string' },
127
- defaultValue: undefined,
128
- annotations: { description: 'Content to authenticate' },
129
- },
130
- {
131
- name: 'algorithm',
132
- type: { type: 'string' },
133
- defaultValue: defaultAlgorithm,
134
- annotations: { description: 'Hash algorithm' },
135
- },
136
- ],
137
- fn: hmac,
138
- annotations: {
139
- description: 'Generate HMAC signature, returns hex output',
140
- },
141
- returnType: rillTypeToTypeValue({ type: 'string' }),
142
- },
143
- uuid: {
144
- params: [],
145
- fn: uuid,
146
- annotations: { description: 'Generate random UUID v4' },
147
- returnType: rillTypeToTypeValue({ type: 'string' }),
148
- },
149
- random: {
150
- params: [
151
- {
152
- name: 'bytes',
153
- type: { type: 'number' },
154
- defaultValue: undefined,
155
- annotations: { description: 'Number of bytes' },
156
- },
157
- ],
158
- fn: random,
159
- annotations: { description: 'Generate random bytes as hex string' },
160
- returnType: rillTypeToTypeValue({ type: 'string' }),
143
+ returnType: structureToTypeValue({ kind: 'string' }),
144
+ }),
145
+ uuid: toCallable({
146
+ params: [],
147
+ fn: uuid,
148
+ annotations: { description: 'Generate random UUID v4' },
149
+ returnType: structureToTypeValue({ kind: 'string' }),
150
+ }),
151
+ random: toCallable({
152
+ params: [
153
+ {
154
+ name: 'bytes',
155
+ type: { kind: 'number' },
156
+ defaultValue: undefined,
157
+ annotations: { description: 'Number of bytes' },
158
+ },
159
+ ],
160
+ fn: random,
161
+ annotations: { description: 'Generate random bytes as hex string' },
162
+ returnType: structureToTypeValue({ kind: 'string' }),
163
+ }),
161
164
  },
162
165
  };
163
166
  }
@@ -4,7 +4,7 @@
4
4
  * Provides sandboxed command execution via allowlist/blocklist security controls.
5
5
  * Each declared command becomes a function with argument validation and process isolation.
6
6
  */
7
- import type { ExtensionResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
7
+ import type { ExtensionFactoryResult, ExtensionConfigSchema, ExtensionManifest } from '../../runtime/ext/extensions.js';
8
8
  import { type CommandConfig } from './runner.js';
9
9
  export declare const configSchema: ExtensionConfigSchema;
10
10
  /** exec extension configuration */
@@ -27,7 +27,7 @@ export type { CommandConfig };
27
27
  * Returns dispose() function to abort in-flight processes.
28
28
  *
29
29
  * @param config - Command definitions and defaults
30
- * @returns ExtensionResult with command functions and dispose
30
+ * @returns ExtensionFactoryResult with command functions and dispose
31
31
  *
32
32
  * @example
33
33
  * ```typescript
@@ -42,5 +42,5 @@ export type { CommandConfig };
42
42
  * });
43
43
  * ```
44
44
  */
45
- export declare function createExecExtension(config: ExecConfig): ExtensionResult;
45
+ export declare function createExecExtension(config: ExecConfig): ExtensionFactoryResult;
46
46
  export declare const extensionManifest: ExtensionManifest;