@vibe-lang/runtime 0.2.5

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 (250) hide show
  1. package/package.json +46 -0
  2. package/src/ast/index.ts +375 -0
  3. package/src/ast.ts +2 -0
  4. package/src/debug/advanced-features.ts +482 -0
  5. package/src/debug/bun-inspector.ts +424 -0
  6. package/src/debug/handoff-manager.ts +283 -0
  7. package/src/debug/index.ts +150 -0
  8. package/src/debug/runner.ts +365 -0
  9. package/src/debug/server.ts +565 -0
  10. package/src/debug/stack-merger.ts +267 -0
  11. package/src/debug/state.ts +581 -0
  12. package/src/debug/test/advanced-features.test.ts +300 -0
  13. package/src/debug/test/e2e.test.ts +218 -0
  14. package/src/debug/test/handoff-manager.test.ts +256 -0
  15. package/src/debug/test/runner.test.ts +256 -0
  16. package/src/debug/test/stack-merger.test.ts +163 -0
  17. package/src/debug/test/state.test.ts +400 -0
  18. package/src/debug/test/ts-debug-integration.test.ts +374 -0
  19. package/src/debug/test/ts-import-tracker.test.ts +125 -0
  20. package/src/debug/test/ts-source-map.test.ts +169 -0
  21. package/src/debug/ts-import-tracker.ts +151 -0
  22. package/src/debug/ts-source-map.ts +171 -0
  23. package/src/errors/index.ts +124 -0
  24. package/src/index.ts +358 -0
  25. package/src/lexer/index.ts +348 -0
  26. package/src/lexer.ts +2 -0
  27. package/src/parser/index.ts +792 -0
  28. package/src/parser/parse.ts +45 -0
  29. package/src/parser/test/async.test.ts +248 -0
  30. package/src/parser/test/destructuring.test.ts +167 -0
  31. package/src/parser/test/do-expression.test.ts +486 -0
  32. package/src/parser/test/errors/do-expression.test.ts +95 -0
  33. package/src/parser/test/errors/error-locations.test.ts +230 -0
  34. package/src/parser/test/errors/invalid-expressions.test.ts +144 -0
  35. package/src/parser/test/errors/missing-tokens.test.ts +126 -0
  36. package/src/parser/test/errors/model-declaration.test.ts +185 -0
  37. package/src/parser/test/errors/nested-blocks.test.ts +226 -0
  38. package/src/parser/test/errors/unclosed-delimiters.test.ts +122 -0
  39. package/src/parser/test/errors/unexpected-tokens.test.ts +120 -0
  40. package/src/parser/test/import-export.test.ts +143 -0
  41. package/src/parser/test/literals.test.ts +404 -0
  42. package/src/parser/test/model-declaration.test.ts +161 -0
  43. package/src/parser/test/nested-blocks.test.ts +402 -0
  44. package/src/parser/test/parser.test.ts +743 -0
  45. package/src/parser/test/private.test.ts +136 -0
  46. package/src/parser/test/template-literal.test.ts +127 -0
  47. package/src/parser/test/tool-declaration.test.ts +302 -0
  48. package/src/parser/test/ts-block.test.ts +252 -0
  49. package/src/parser/test/type-annotations.test.ts +254 -0
  50. package/src/parser/visitor/helpers.ts +330 -0
  51. package/src/parser/visitor.ts +794 -0
  52. package/src/parser.ts +2 -0
  53. package/src/runtime/ai/cache-chunking.test.ts +69 -0
  54. package/src/runtime/ai/cache-chunking.ts +73 -0
  55. package/src/runtime/ai/client.ts +109 -0
  56. package/src/runtime/ai/context.ts +168 -0
  57. package/src/runtime/ai/formatters.ts +316 -0
  58. package/src/runtime/ai/index.ts +38 -0
  59. package/src/runtime/ai/language-ref.ts +38 -0
  60. package/src/runtime/ai/providers/anthropic.ts +253 -0
  61. package/src/runtime/ai/providers/google.ts +201 -0
  62. package/src/runtime/ai/providers/openai.ts +156 -0
  63. package/src/runtime/ai/retry.ts +100 -0
  64. package/src/runtime/ai/return-tools.ts +301 -0
  65. package/src/runtime/ai/test/client.test.ts +83 -0
  66. package/src/runtime/ai/test/formatters.test.ts +485 -0
  67. package/src/runtime/ai/test/retry.test.ts +137 -0
  68. package/src/runtime/ai/test/return-tools.test.ts +450 -0
  69. package/src/runtime/ai/test/tool-loop.test.ts +319 -0
  70. package/src/runtime/ai/test/tool-schema.test.ts +241 -0
  71. package/src/runtime/ai/tool-loop.ts +203 -0
  72. package/src/runtime/ai/tool-schema.ts +151 -0
  73. package/src/runtime/ai/types.ts +113 -0
  74. package/src/runtime/ai-logger.ts +255 -0
  75. package/src/runtime/ai-provider.ts +347 -0
  76. package/src/runtime/async/dependencies.ts +276 -0
  77. package/src/runtime/async/executor.ts +293 -0
  78. package/src/runtime/async/index.ts +43 -0
  79. package/src/runtime/async/scheduling.ts +163 -0
  80. package/src/runtime/async/test/dependencies.test.ts +284 -0
  81. package/src/runtime/async/test/executor.test.ts +388 -0
  82. package/src/runtime/context.ts +357 -0
  83. package/src/runtime/exec/ai.ts +139 -0
  84. package/src/runtime/exec/expressions.ts +475 -0
  85. package/src/runtime/exec/frames.ts +26 -0
  86. package/src/runtime/exec/functions.ts +305 -0
  87. package/src/runtime/exec/interpolation.ts +312 -0
  88. package/src/runtime/exec/statements.ts +604 -0
  89. package/src/runtime/exec/tools.ts +129 -0
  90. package/src/runtime/exec/typescript.ts +215 -0
  91. package/src/runtime/exec/variables.ts +279 -0
  92. package/src/runtime/index.ts +975 -0
  93. package/src/runtime/modules.ts +452 -0
  94. package/src/runtime/serialize.ts +103 -0
  95. package/src/runtime/state.ts +489 -0
  96. package/src/runtime/stdlib/core.ts +45 -0
  97. package/src/runtime/stdlib/directory.test.ts +156 -0
  98. package/src/runtime/stdlib/edit.test.ts +154 -0
  99. package/src/runtime/stdlib/fastEdit.test.ts +201 -0
  100. package/src/runtime/stdlib/glob.test.ts +106 -0
  101. package/src/runtime/stdlib/grep.test.ts +144 -0
  102. package/src/runtime/stdlib/index.ts +16 -0
  103. package/src/runtime/stdlib/readFile.test.ts +123 -0
  104. package/src/runtime/stdlib/tools/index.ts +707 -0
  105. package/src/runtime/stdlib/writeFile.test.ts +157 -0
  106. package/src/runtime/step.ts +969 -0
  107. package/src/runtime/test/ai-context.test.ts +1086 -0
  108. package/src/runtime/test/ai-result-object.test.ts +419 -0
  109. package/src/runtime/test/ai-tool-flow.test.ts +859 -0
  110. package/src/runtime/test/async-execution-order.test.ts +618 -0
  111. package/src/runtime/test/async-execution.test.ts +344 -0
  112. package/src/runtime/test/async-nested.test.ts +660 -0
  113. package/src/runtime/test/async-parallel-timing.test.ts +546 -0
  114. package/src/runtime/test/basic1.test.ts +154 -0
  115. package/src/runtime/test/binary-operators.test.ts +431 -0
  116. package/src/runtime/test/break-statement.test.ts +257 -0
  117. package/src/runtime/test/context-modes.test.ts +650 -0
  118. package/src/runtime/test/context.test.ts +466 -0
  119. package/src/runtime/test/core-functions.test.ts +228 -0
  120. package/src/runtime/test/e2e.test.ts +88 -0
  121. package/src/runtime/test/error-locations/error-locations.test.ts +80 -0
  122. package/src/runtime/test/error-locations/main-error.vibe +4 -0
  123. package/src/runtime/test/error-locations/main-import-error.vibe +3 -0
  124. package/src/runtime/test/error-locations/utils/helper.vibe +5 -0
  125. package/src/runtime/test/for-in.test.ts +312 -0
  126. package/src/runtime/test/helpers.ts +69 -0
  127. package/src/runtime/test/imports.test.ts +334 -0
  128. package/src/runtime/test/json-expressions.test.ts +232 -0
  129. package/src/runtime/test/literals.test.ts +372 -0
  130. package/src/runtime/test/logical-indexing.test.ts +478 -0
  131. package/src/runtime/test/member-methods.test.ts +324 -0
  132. package/src/runtime/test/model-config.test.ts +338 -0
  133. package/src/runtime/test/null-handling.test.ts +342 -0
  134. package/src/runtime/test/private-visibility.test.ts +332 -0
  135. package/src/runtime/test/runtime-state.test.ts +514 -0
  136. package/src/runtime/test/scoping.test.ts +370 -0
  137. package/src/runtime/test/string-interpolation.test.ts +354 -0
  138. package/src/runtime/test/template-literal.test.ts +181 -0
  139. package/src/runtime/test/tool-execution.test.ts +467 -0
  140. package/src/runtime/test/tool-schema-generation.test.ts +477 -0
  141. package/src/runtime/test/tostring.test.ts +210 -0
  142. package/src/runtime/test/ts-block.test.ts +594 -0
  143. package/src/runtime/test/ts-error-location.test.ts +231 -0
  144. package/src/runtime/test/types.test.ts +732 -0
  145. package/src/runtime/test/verbose-logger.test.ts +710 -0
  146. package/src/runtime/test/vibe-expression.test.ts +54 -0
  147. package/src/runtime/test/vibe-value-errors.test.ts +541 -0
  148. package/src/runtime/test/while.test.ts +232 -0
  149. package/src/runtime/tools/builtin.ts +30 -0
  150. package/src/runtime/tools/directory-tools.ts +70 -0
  151. package/src/runtime/tools/file-tools.ts +228 -0
  152. package/src/runtime/tools/index.ts +5 -0
  153. package/src/runtime/tools/registry.ts +48 -0
  154. package/src/runtime/tools/search-tools.ts +134 -0
  155. package/src/runtime/tools/security.ts +36 -0
  156. package/src/runtime/tools/system-tools.ts +312 -0
  157. package/src/runtime/tools/test/fixtures/base-types.ts +40 -0
  158. package/src/runtime/tools/test/fixtures/test-types.ts +132 -0
  159. package/src/runtime/tools/test/registry.test.ts +713 -0
  160. package/src/runtime/tools/test/security.test.ts +86 -0
  161. package/src/runtime/tools/test/system-tools.test.ts +679 -0
  162. package/src/runtime/tools/test/ts-schema.test.ts +357 -0
  163. package/src/runtime/tools/ts-schema.ts +341 -0
  164. package/src/runtime/tools/types.ts +89 -0
  165. package/src/runtime/tools/utility-tools.ts +198 -0
  166. package/src/runtime/ts-eval.ts +126 -0
  167. package/src/runtime/types.ts +797 -0
  168. package/src/runtime/validation.ts +160 -0
  169. package/src/runtime/verbose-logger.ts +459 -0
  170. package/src/runtime.ts +2 -0
  171. package/src/semantic/analyzer-context.ts +62 -0
  172. package/src/semantic/analyzer-validators.ts +575 -0
  173. package/src/semantic/analyzer-visitors.ts +534 -0
  174. package/src/semantic/analyzer.ts +83 -0
  175. package/src/semantic/index.ts +11 -0
  176. package/src/semantic/symbol-table.ts +58 -0
  177. package/src/semantic/test/async-validation.test.ts +301 -0
  178. package/src/semantic/test/compress-validation.test.ts +179 -0
  179. package/src/semantic/test/const-reassignment.test.ts +111 -0
  180. package/src/semantic/test/control-flow.test.ts +346 -0
  181. package/src/semantic/test/destructuring.test.ts +185 -0
  182. package/src/semantic/test/duplicate-declarations.test.ts +168 -0
  183. package/src/semantic/test/export-validation.test.ts +111 -0
  184. package/src/semantic/test/fixtures/math.ts +31 -0
  185. package/src/semantic/test/imports.test.ts +148 -0
  186. package/src/semantic/test/json-type.test.ts +68 -0
  187. package/src/semantic/test/literals.test.ts +127 -0
  188. package/src/semantic/test/model-validation.test.ts +179 -0
  189. package/src/semantic/test/prompt-validation.test.ts +343 -0
  190. package/src/semantic/test/scoping.test.ts +312 -0
  191. package/src/semantic/test/tool-validation.test.ts +306 -0
  192. package/src/semantic/test/ts-type-checking.test.ts +563 -0
  193. package/src/semantic/test/type-constraints.test.ts +111 -0
  194. package/src/semantic/test/type-inference.test.ts +87 -0
  195. package/src/semantic/test/type-validation.test.ts +552 -0
  196. package/src/semantic/test/undefined-variables.test.ts +163 -0
  197. package/src/semantic/ts-block-checker.ts +204 -0
  198. package/src/semantic/ts-signatures.ts +194 -0
  199. package/src/semantic/ts-types.ts +170 -0
  200. package/src/semantic/types.ts +58 -0
  201. package/tests/fixtures/conditional-logic.vibe +14 -0
  202. package/tests/fixtures/function-call.vibe +16 -0
  203. package/tests/fixtures/imports/cycle-detection/a.vibe +6 -0
  204. package/tests/fixtures/imports/cycle-detection/b.vibe +5 -0
  205. package/tests/fixtures/imports/cycle-detection/main.vibe +3 -0
  206. package/tests/fixtures/imports/module-isolation/main-b.vibe +8 -0
  207. package/tests/fixtures/imports/module-isolation/main.vibe +9 -0
  208. package/tests/fixtures/imports/module-isolation/moduleA.vibe +6 -0
  209. package/tests/fixtures/imports/module-isolation/moduleB.vibe +6 -0
  210. package/tests/fixtures/imports/nested-import/helper.vibe +6 -0
  211. package/tests/fixtures/imports/nested-import/main.vibe +3 -0
  212. package/tests/fixtures/imports/nested-import/utils.ts +3 -0
  213. package/tests/fixtures/imports/nested-isolation/file2.vibe +15 -0
  214. package/tests/fixtures/imports/nested-isolation/file3.vibe +10 -0
  215. package/tests/fixtures/imports/nested-isolation/main.vibe +21 -0
  216. package/tests/fixtures/imports/pure-cycle/a.vibe +5 -0
  217. package/tests/fixtures/imports/pure-cycle/b.vibe +5 -0
  218. package/tests/fixtures/imports/pure-cycle/main.vibe +3 -0
  219. package/tests/fixtures/imports/ts-boolean/checks.ts +14 -0
  220. package/tests/fixtures/imports/ts-boolean/main.vibe +10 -0
  221. package/tests/fixtures/imports/ts-boolean/type-mismatch.vibe +5 -0
  222. package/tests/fixtures/imports/ts-boolean/use-constant.vibe +18 -0
  223. package/tests/fixtures/imports/ts-error-handling/helpers.ts +42 -0
  224. package/tests/fixtures/imports/ts-error-handling/main.vibe +5 -0
  225. package/tests/fixtures/imports/ts-import/main.vibe +4 -0
  226. package/tests/fixtures/imports/ts-import/math.ts +9 -0
  227. package/tests/fixtures/imports/ts-variables/call-non-function.vibe +5 -0
  228. package/tests/fixtures/imports/ts-variables/data.ts +10 -0
  229. package/tests/fixtures/imports/ts-variables/import-json.vibe +5 -0
  230. package/tests/fixtures/imports/ts-variables/import-type-mismatch.vibe +5 -0
  231. package/tests/fixtures/imports/ts-variables/import-variable.vibe +5 -0
  232. package/tests/fixtures/imports/vibe-import/greet.vibe +5 -0
  233. package/tests/fixtures/imports/vibe-import/main.vibe +3 -0
  234. package/tests/fixtures/multiple-ai-calls.vibe +10 -0
  235. package/tests/fixtures/simple-greeting.vibe +6 -0
  236. package/tests/fixtures/template-literals.vibe +11 -0
  237. package/tests/integration/basic-ai/basic-ai.integration.test.ts +166 -0
  238. package/tests/integration/basic-ai/basic-ai.vibe +12 -0
  239. package/tests/integration/bug-fix/bug-fix.integration.test.ts +201 -0
  240. package/tests/integration/bug-fix/buggy-code.ts +22 -0
  241. package/tests/integration/bug-fix/fix-bug.vibe +21 -0
  242. package/tests/integration/compress/compress.integration.test.ts +206 -0
  243. package/tests/integration/destructuring/destructuring.integration.test.ts +92 -0
  244. package/tests/integration/hello-world-translator/hello-world-translator.integration.test.ts +61 -0
  245. package/tests/integration/line-annotator/context-modes.integration.test.ts +261 -0
  246. package/tests/integration/line-annotator/line-annotator.integration.test.ts +148 -0
  247. package/tests/integration/multi-feature/cumulative-sum.integration.test.ts +75 -0
  248. package/tests/integration/multi-feature/number-analyzer.integration.test.ts +191 -0
  249. package/tests/integration/multi-feature/number-analyzer.vibe +59 -0
  250. package/tests/integration/tool-calls/tool-calls.integration.test.ts +93 -0
@@ -0,0 +1,797 @@
1
+ import * as AST from '../ast';
2
+ import type { VibeType, VibeTypeRequired, ContextMode } from '../ast';
3
+ import type { SourceLocation } from '../errors';
4
+ import type { PendingToolCall } from './tools/types';
5
+ export type { PendingToolCall } from './tools/types';
6
+ import type { VibeModelValue } from './ai/client';
7
+
8
+ // Runtime status
9
+ export type RuntimeStatus =
10
+ | 'running'
11
+ | 'paused'
12
+ | 'awaiting_ai'
13
+ | 'awaiting_compress' // Waiting for AI to compress loop context
14
+ | 'awaiting_user'
15
+ | 'awaiting_ts'
16
+ | 'awaiting_tool'
17
+ | 'awaiting_vibe_code' // Waiting for vibe-generated code to be processed
18
+ | 'awaiting_async' // Waiting for async operations to complete
19
+ | 'completed'
20
+ | 'error';
21
+
22
+ // Source of a variable's value
23
+ export type ValueSource = 'ai' | 'user' | null;
24
+
25
+ // ============================================================================
26
+ // VibeValue - Unified value wrapper with error handling
27
+ // ============================================================================
28
+
29
+ // Error information captured when an operation fails
30
+ export interface VibeError {
31
+ message: string;
32
+ type: string; // Error class name: "TypeError", "ReferenceError", etc.
33
+ location: SourceLocation | null; // Source location in Vibe code (where the error occurred in .vibe file)
34
+ stack?: string; // Original error stack trace (for debugging TS errors)
35
+ }
36
+
37
+ // Universal value wrapper - ALL values in Vibe are VibeValue
38
+ // Replaces both Variable and AIResultObject with a unified type
39
+ export interface VibeValue {
40
+ value: unknown; // The actual primitive data
41
+ err: boolean; // true if error, false if success (for direct boolean check: if result.err { ... })
42
+ errDetails: VibeError | null; // Error details when err is true, null otherwise
43
+ toolCalls: ToolCallRecord[]; // AI tool calls (empty array for non-AI operations)
44
+ isConst: boolean; // true for const, false for let
45
+ typeAnnotation: VibeType; // 'text', 'number', 'json', 'prompt', etc. or null
46
+ source: ValueSource; // 'ai', 'user', or null (no source)
47
+ isPrivate?: boolean; // true if hidden from AI context
48
+ asyncOperationId?: string; // ID of pending async operation (when value is pending)
49
+ }
50
+
51
+ // Type guard for VibeValue
52
+ export function isVibeValue(val: unknown): val is VibeValue {
53
+ return (
54
+ typeof val === 'object' &&
55
+ val !== null &&
56
+ 'value' in val &&
57
+ 'err' in val &&
58
+ 'errDetails' in val &&
59
+ 'toolCalls' in val &&
60
+ 'isConst' in val
61
+ );
62
+ }
63
+
64
+ // Create a VibeValue (optionally with error for preserving errors through assignments)
65
+ export function createVibeValue(
66
+ value: unknown,
67
+ options: {
68
+ isConst?: boolean;
69
+ typeAnnotation?: VibeType;
70
+ source?: ValueSource;
71
+ toolCalls?: ToolCallRecord[];
72
+ err?: boolean;
73
+ errDetails?: VibeError | null;
74
+ isPrivate?: boolean;
75
+ asyncOperationId?: string;
76
+ } = {}
77
+ ): VibeValue {
78
+ const result: VibeValue = {
79
+ value,
80
+ err: options.err ?? false,
81
+ errDetails: options.errDetails ?? null,
82
+ toolCalls: options.toolCalls ?? [],
83
+ isConst: options.isConst ?? false,
84
+ typeAnnotation: options.typeAnnotation ?? null,
85
+ source: options.source ?? null,
86
+ };
87
+ if (options.isPrivate) {
88
+ result.isPrivate = true;
89
+ }
90
+ if (options.asyncOperationId) {
91
+ result.asyncOperationId = options.asyncOperationId;
92
+ }
93
+ return result;
94
+ }
95
+
96
+ // Create a VibeValue with an error
97
+ export function createVibeError(
98
+ error: Error | string,
99
+ location: SourceLocation | null = null,
100
+ options: {
101
+ isConst?: boolean;
102
+ typeAnnotation?: VibeType;
103
+ } = {}
104
+ ): VibeValue {
105
+ const isErrorObject = error instanceof Error;
106
+ const errDetails: VibeError = {
107
+ message: typeof error === 'string' ? error : error.message,
108
+ type: typeof error === 'string' ? 'Error' : error.constructor.name,
109
+ location,
110
+ // Capture stack trace from Error objects (useful for debugging TS errors)
111
+ stack: isErrorObject ? error.stack : undefined,
112
+ };
113
+ return {
114
+ value: null,
115
+ err: true,
116
+ errDetails,
117
+ toolCalls: [],
118
+ isConst: options.isConst ?? false,
119
+ typeAnnotation: options.typeAnnotation ?? null,
120
+ source: null,
121
+ };
122
+ }
123
+
124
+ // Propagate error from one VibeValue to another (for expression evaluation)
125
+ // If source has error, result inherits it; otherwise uses provided value
126
+ export function propagateError(
127
+ source: VibeValue,
128
+ value: unknown,
129
+ options: {
130
+ isConst?: boolean;
131
+ typeAnnotation?: VibeType;
132
+ source?: ValueSource;
133
+ } = {}
134
+ ): VibeValue {
135
+ if (source.err) {
136
+ return {
137
+ value: null,
138
+ err: true,
139
+ errDetails: source.errDetails,
140
+ toolCalls: [],
141
+ isConst: options.isConst ?? false,
142
+ typeAnnotation: options.typeAnnotation ?? null,
143
+ source: options.source ?? null,
144
+ };
145
+ }
146
+ return createVibeValue(value, options);
147
+ }
148
+
149
+ // Propagate error from multiple sources (for binary operations)
150
+ // Returns first error found, or creates successful value
151
+ export function propagateErrors(
152
+ sources: VibeValue[],
153
+ value: unknown,
154
+ options: {
155
+ isConst?: boolean;
156
+ typeAnnotation?: VibeType;
157
+ source?: ValueSource;
158
+ } = {}
159
+ ): VibeValue {
160
+ for (const src of sources) {
161
+ if (src.err) {
162
+ return {
163
+ value: null,
164
+ err: true,
165
+ errDetails: src.errDetails,
166
+ toolCalls: [],
167
+ isConst: options.isConst ?? false,
168
+ typeAnnotation: options.typeAnnotation ?? null,
169
+ source: options.source ?? null,
170
+ };
171
+ }
172
+ }
173
+ return createVibeValue(value, options);
174
+ }
175
+
176
+ // ============================================================================
177
+ // Legacy Variable type (being replaced by VibeValue)
178
+ // ============================================================================
179
+
180
+ // Variable entry with mutability flag and optional type
181
+ // @deprecated Use VibeValue instead
182
+ export interface Variable {
183
+ value: unknown;
184
+ isConst: boolean;
185
+ typeAnnotation: string | null;
186
+ source?: ValueSource; // Where the value came from (AI response, user input, or code)
187
+ }
188
+
189
+ // Variable in context (for AI calls)
190
+ // Note: Models are filtered out - they are config, not data for AI context
191
+ export interface ContextVariable {
192
+ kind: 'variable';
193
+ name: string;
194
+ value: unknown;
195
+ type: 'text' | 'json' | 'boolean' | 'number' | null;
196
+ isConst: boolean;
197
+ source: ValueSource; // Where the value came from (AI response, user input, or null for code)
198
+ isPrivate?: boolean; // true if hidden from AI context
199
+ // Call stack location info (helps AI understand variable scope)
200
+ frameName: string; // Name of the function/scope (e.g., "main", "processData")
201
+ frameDepth: number; // 0 = deepest/current frame, higher = older frames
202
+ }
203
+
204
+ // Tool call within a prompt (AI-initiated tool execution during the prompt)
205
+ export interface PromptToolCall {
206
+ toolName: string;
207
+ args: Record<string, unknown>;
208
+ result?: unknown;
209
+ error?: string;
210
+ }
211
+
212
+ // Tool call error details
213
+ export interface ToolCallError {
214
+ message: string;
215
+ type?: string; // Error type if available
216
+ }
217
+
218
+ // Tool call record for VibeValue (includes timing)
219
+ export interface ToolCallRecord {
220
+ toolName: string;
221
+ args: Record<string, unknown>;
222
+ result: string | null; // null if error
223
+ err: boolean; // true if error, false if success
224
+ errDetails: ToolCallError | null; // Error details when err is true
225
+ duration: number; // milliseconds
226
+ }
227
+
228
+ // Resolve VibeValue to its primitive value for coercion
229
+ // Used in string interpolation, binary ops, print, etc.
230
+ export function resolveValue(val: unknown): unknown {
231
+ if (isVibeValue(val)) {
232
+ return val.value;
233
+ }
234
+ return val;
235
+ }
236
+
237
+ // Prompt in context (when AI function is called)
238
+ export interface ContextPrompt {
239
+ kind: 'prompt';
240
+ aiType: 'do' | 'vibe' | 'ask';
241
+ prompt: string;
242
+ toolCalls?: PromptToolCall[]; // Tool calls made during this prompt (before response)
243
+ response?: unknown; // Included when AI returns
244
+ frameName: string;
245
+ frameDepth: number;
246
+ }
247
+
248
+ // Scope marker in context (entering/exiting loops/functions)
249
+ export interface ContextScopeMarker {
250
+ kind: 'scope-enter' | 'scope-exit';
251
+ scopeType: 'for' | 'while' | 'function';
252
+ label?: string;
253
+ frameName: string;
254
+ frameDepth: number;
255
+ }
256
+
257
+ // Summary in context (from compress mode)
258
+ export interface ContextSummary {
259
+ kind: 'summary';
260
+ text: string;
261
+ frameName: string;
262
+ frameDepth: number;
263
+ }
264
+
265
+ // Tool call in context (AI-initiated tool execution)
266
+ export interface ContextToolCall {
267
+ kind: 'tool-call';
268
+ toolName: string;
269
+ args: Record<string, unknown>;
270
+ result?: unknown;
271
+ error?: string;
272
+ frameName: string;
273
+ frameDepth: number;
274
+ }
275
+
276
+ // Context entry - variable, prompt, scope marker, summary, or tool call
277
+ export type ContextEntry = ContextVariable | ContextPrompt | ContextScopeMarker | ContextSummary | ContextToolCall;
278
+
279
+ // Ordered entry - tracks order of variable assignments and AI prompts in a frame
280
+ // Values are snapshotted at assignment time for accurate history
281
+ export type FrameEntry =
282
+ | {
283
+ kind: 'variable';
284
+ name: string;
285
+ value: unknown; // Snapshot at assignment time
286
+ type: string | null;
287
+ isConst: boolean;
288
+ source?: 'ai' | 'user';
289
+ isPrivate?: boolean; // true if hidden from AI context
290
+ }
291
+ | {
292
+ kind: 'prompt';
293
+ aiType: 'do' | 'vibe' | 'ask';
294
+ prompt: string;
295
+ toolCalls?: PromptToolCall[]; // Tool calls made during this prompt
296
+ response?: unknown; // Added when AI returns
297
+ }
298
+ | {
299
+ kind: 'summary'; // For compress mode
300
+ text: string;
301
+ }
302
+ | {
303
+ kind: 'scope-enter'; // Marker for entering loop/function
304
+ scopeType: 'for' | 'while' | 'function';
305
+ label?: string; // e.g., function name or "for n in items"
306
+ }
307
+ | {
308
+ kind: 'scope-exit'; // Marker for leaving loop/function
309
+ scopeType: 'for' | 'while' | 'function';
310
+ label?: string;
311
+ }
312
+ | {
313
+ kind: 'tool-call'; // AI-initiated tool call
314
+ toolName: string;
315
+ args: Record<string, unknown>;
316
+ result?: unknown;
317
+ error?: string;
318
+ };
319
+
320
+ // Stack frame (serializable - uses Record instead of Map)
321
+ export interface StackFrame {
322
+ name: string;
323
+ locals: Record<string, VibeValue>; // All variables are VibeValue
324
+ parentFrameIndex: number | null; // Lexical parent frame for scope chain
325
+ orderedEntries: FrameEntry[]; // Track order of variable assignments and AI prompts
326
+ modulePath?: string; // Module this frame belongs to (for imported functions)
327
+ }
328
+
329
+ // AI operation history entry
330
+ export interface AIOperation {
331
+ type: 'do' | 'vibe' | 'ask';
332
+ prompt: string;
333
+ response: unknown;
334
+ timestamp: number;
335
+ }
336
+
337
+ // Detailed token usage from AI providers
338
+ export interface TokenUsage {
339
+ inputTokens: number;
340
+ outputTokens: number;
341
+ // Cached tokens (prompt caching)
342
+ cachedInputTokens?: number;
343
+ // Tokens used to create cache (Anthropic)
344
+ cacheCreationTokens?: number;
345
+ // Reasoning/thinking tokens (OpenAI o1, Claude extended thinking)
346
+ thinkingTokens?: number;
347
+ }
348
+
349
+ // Message in the AI conversation (for logging)
350
+ export interface AILogMessage {
351
+ role: 'system' | 'user' | 'assistant';
352
+ content: string;
353
+ /** For assistant messages with tool calls */
354
+ toolCalls?: Array<{
355
+ id: string;
356
+ toolName: string;
357
+ args: Record<string, unknown>;
358
+ }>;
359
+ /** For user messages with tool results */
360
+ toolResults?: Array<{
361
+ toolCallId: string;
362
+ result?: unknown;
363
+ error?: string;
364
+ }>;
365
+ }
366
+
367
+ // Detailed AI interaction for debugging/logging
368
+ // Contains the COMPLETE context that was sent to the model
369
+ export interface AIInteraction {
370
+ type: 'do' | 'vibe' | 'ask';
371
+ prompt: string;
372
+ response: unknown;
373
+ timestamp: number;
374
+ model: string;
375
+ // Model details for logging
376
+ modelDetails?: {
377
+ name: string;
378
+ provider: string;
379
+ url?: string;
380
+ thinkingLevel?: string;
381
+ };
382
+ targetType: string | null;
383
+ usage?: TokenUsage;
384
+ durationMs?: number;
385
+ // The complete message sequence sent to the model (single source of truth for logging)
386
+ messages: AILogMessage[];
387
+ // Structured execution context (variables, prompts, tool calls)
388
+ executionContext: ContextEntry[];
389
+ // Tool calls made during this interaction (after the initial request)
390
+ interactionToolCalls?: PromptToolCall[];
391
+ }
392
+
393
+ // Execution log entry for tracking what happened
394
+ export interface ExecutionEntry {
395
+ timestamp: number;
396
+ instructionType: string;
397
+ details?: Record<string, unknown>;
398
+ result?: unknown;
399
+ }
400
+
401
+ // ============================================================================
402
+ // Verbose Logging Types (JSONL output)
403
+ // ============================================================================
404
+
405
+ // Base log event fields
406
+ interface LogEventBase {
407
+ seq: number; // Sequential event number (1, 2, 3, ...)
408
+ ts: string; // ISO timestamp
409
+ event: string; // Event type
410
+ }
411
+
412
+ // Run lifecycle events
413
+ export interface RunStartEvent extends LogEventBase {
414
+ event: 'run_start';
415
+ file: string;
416
+ }
417
+
418
+ export interface RunCompleteEvent extends LogEventBase {
419
+ event: 'run_complete';
420
+ durationMs: number;
421
+ status: 'completed' | 'error';
422
+ error?: string;
423
+ }
424
+
425
+ // AI call events
426
+ export interface AIStartEvent extends LogEventBase {
427
+ event: 'ai_start';
428
+ id: string; // e.g., "do-000001", "vibe-000001"
429
+ type: 'do' | 'vibe';
430
+ model: string;
431
+ prompt: string; // Truncated prompt for display
432
+ }
433
+
434
+ export interface AICompleteEvent extends LogEventBase {
435
+ event: 'ai_complete';
436
+ id: string;
437
+ durationMs: number;
438
+ tokens?: { in: number; out: number };
439
+ toolCalls: number; // Count of tool calls made
440
+ error?: string;
441
+ }
442
+
443
+ // Tool call events (within vibe loops)
444
+ export interface ToolStartEvent extends LogEventBase {
445
+ event: 'tool_start';
446
+ parentId: string; // Parent AI call ID
447
+ tool: string;
448
+ args: Record<string, unknown>;
449
+ }
450
+
451
+ export interface ToolCompleteEvent extends LogEventBase {
452
+ event: 'tool_complete';
453
+ parentId: string;
454
+ tool: string;
455
+ durationMs: number;
456
+ success: boolean;
457
+ error?: string;
458
+ }
459
+
460
+ // TypeScript execution events
461
+ export interface TSStartEvent extends LogEventBase {
462
+ event: 'ts_start';
463
+ id: string; // e.g., "ts-000001" or "tsf-000001"
464
+ tsType: 'block' | 'function'; // block = inline ts{}, function = imported ts
465
+ name?: string; // Function name (for imported ts functions)
466
+ params: string[];
467
+ location: { file: string; line: number };
468
+ }
469
+
470
+ export interface TSCompleteEvent extends LogEventBase {
471
+ event: 'ts_complete';
472
+ id: string;
473
+ tsType: 'block' | 'function';
474
+ durationMs: number;
475
+ error?: string;
476
+ }
477
+
478
+ // Union of all log events
479
+ export type LogEvent =
480
+ | RunStartEvent
481
+ | RunCompleteEvent
482
+ | AIStartEvent
483
+ | AICompleteEvent
484
+ | ToolStartEvent
485
+ | ToolCompleteEvent
486
+ | TSStartEvent
487
+ | TSCompleteEvent;
488
+
489
+ // Pending AI request info
490
+ export interface PendingAI {
491
+ type: 'do' | 'vibe'; // 'do' = single round, 'vibe' = multi-turn tool loop
492
+ prompt: string;
493
+ model: string;
494
+ context: unknown[];
495
+ // Scope parameters for vibe code generation
496
+ vibeScopeParams?: Array<{ name: string; type: string; value: unknown }>;
497
+ }
498
+
499
+ // Expected field for destructuring/typed returns
500
+ export interface ExpectedField {
501
+ name: string;
502
+ type: VibeTypeRequired;
503
+ isPrivate?: boolean; // true if hidden from AI context
504
+ }
505
+
506
+ // Pending compress request (for compress context mode)
507
+ export interface PendingCompress {
508
+ prompt: string | null; // Custom prompt or null for default
509
+ model: string; // Model variable name to use
510
+ entriesToSummarize: FrameEntry[]; // Entries to compress
511
+ entryIndex: number; // Where scope started in orderedEntries
512
+ scopeType: 'for' | 'while';
513
+ label?: string;
514
+ }
515
+
516
+ // Pending TypeScript evaluation (inline ts block)
517
+ export interface PendingTS {
518
+ params: string[];
519
+ body: string;
520
+ paramValues: unknown[];
521
+ location: SourceLocation; // Source location in .vibe file for error reporting
522
+ }
523
+
524
+ // Pending imported TS function call
525
+ export interface PendingImportedTsCall {
526
+ funcName: string;
527
+ args: unknown[];
528
+ location: SourceLocation; // Source location in .vibe file for error reporting
529
+ }
530
+
531
+ // Loaded TypeScript module
532
+ export interface TsModule {
533
+ exports: Record<string, unknown>; // Exported functions/values
534
+ }
535
+
536
+ // Loaded Vibe module
537
+ export interface VibeModule {
538
+ exports: Record<string, ExportedItem>;
539
+ program: AST.Program;
540
+ globals: Record<string, VibeValue>; // Module-level variables (isolated per module)
541
+ }
542
+
543
+ // Exported item from a Vibe module
544
+ export type ExportedItem =
545
+ | { kind: 'function'; declaration: AST.FunctionDeclaration }
546
+ | { kind: 'variable'; name: string; value: unknown; isConst: boolean; typeAnnotation: string | null }
547
+ | { kind: 'model'; declaration: AST.ModelDeclaration };
548
+
549
+ // ============================================================================
550
+ // Async Execution Types
551
+ // ============================================================================
552
+
553
+ /** Status of an async operation */
554
+ export type AsyncOperationStatus = 'pending' | 'running' | 'completed' | 'failed';
555
+
556
+ /** Type of async operation */
557
+ export type AsyncOperationType = 'do' | 'vibe' | 'ts' | 'ts-function' | 'vibe-function';
558
+
559
+ /** Scheduled async operation waiting to be started by Runtime.run() */
560
+ export interface PendingAsyncStart {
561
+ operationId: string; // ID in asyncOperations map
562
+ type: AsyncOperationType; // What kind of operation
563
+ variableName: string | null; // Variable to store result (null for fire-and-forget)
564
+
565
+ // AI operation details (when type is 'do' or 'vibe')
566
+ aiDetails?: {
567
+ prompt: string;
568
+ model: string;
569
+ context: unknown[];
570
+ operationType: 'do' | 'vibe';
571
+ };
572
+
573
+ // TS operation details (when type is 'ts')
574
+ tsDetails?: {
575
+ params: string[];
576
+ body: string;
577
+ paramValues: unknown[];
578
+ location: SourceLocation;
579
+ };
580
+
581
+ // Imported TS function details (when type is 'ts-function')
582
+ tsFuncDetails?: {
583
+ funcName: string;
584
+ args: unknown[];
585
+ location: SourceLocation;
586
+ };
587
+
588
+ // Vibe function details (when type is 'vibe-function')
589
+ vibeFuncDetails?: {
590
+ funcName: string;
591
+ args: unknown[];
592
+ modulePath?: string; // For imported Vibe functions (scope isolation)
593
+ };
594
+ }
595
+
596
+ /** Individual async operation being tracked */
597
+ export interface AsyncOperation {
598
+ id: string; // Unique identifier (e.g., "async-001")
599
+ variableName: string | null; // null for standalone async (fire-and-forget)
600
+ status: AsyncOperationStatus;
601
+ operationType: AsyncOperationType;
602
+ startTime?: number; // ms timestamp when started
603
+ endTime?: number; // ms timestamp when completed
604
+ result?: VibeValue; // Result when completed
605
+ error?: VibeError; // Error if failed
606
+ dependencies: string[]; // Variable names this depends on
607
+ contextSnapshot: ContextEntry[]; // Context captured at wave start
608
+ waveId: number; // Which wave this operation belongs to
609
+ promise?: Promise<VibeValue>; // The actual promise (not serializable)
610
+ }
611
+
612
+ /** A wave of async operations that can run in parallel */
613
+ export interface AsyncWave {
614
+ id: number;
615
+ operationIds: string[]; // IDs of operations in this wave
616
+ contextSnapshot: ContextEntry[]; // Context at wave start
617
+ startTime: number;
618
+ endTime?: number;
619
+ }
620
+
621
+ // The complete runtime state (fully serializable)
622
+ export interface RuntimeState {
623
+ status: RuntimeStatus;
624
+
625
+ // The program
626
+ program: AST.Program;
627
+ functions: Record<string, AST.FunctionDeclaration>;
628
+
629
+ // Loaded modules
630
+ tsModules: Record<string, TsModule>; // TS modules by import path
631
+ vibeModules: Record<string, VibeModule>; // Vibe modules by import path
632
+ importedNames: Record<string, { source: string; sourceType: 'ts' | 'vibe' }>; // Track where names come from
633
+
634
+ // Execution state
635
+ callStack: StackFrame[];
636
+ instructionStack: Instruction[];
637
+ valueStack: unknown[]; // For building complex values (objects, arrays, args)
638
+
639
+ // Results
640
+ lastResult: unknown;
641
+ lastResultSource: ValueSource; // Tracks source of lastResult (ai/user/undefined)
642
+ aiHistory: AIOperation[];
643
+ executionLog: ExecutionEntry[];
644
+
645
+ // AI interaction logging (opt-in for debugging)
646
+ logAiInteractions: boolean;
647
+ aiInteractions: AIInteraction[];
648
+
649
+ // Context (rebuilt before each instruction)
650
+ localContext: ContextEntry[];
651
+ globalContext: ContextEntry[];
652
+
653
+ // Pending async operation
654
+ pendingAI: PendingAI | null;
655
+ pendingCompress: PendingCompress | null;
656
+ pendingTS: PendingTS | null;
657
+ pendingImportedTsCall: PendingImportedTsCall | null;
658
+ pendingToolCall: PendingToolCall | null;
659
+
660
+ // Destructuring support
661
+ pendingDestructuring: ExpectedField[] | null; // Fields expected from AI for destructuring
662
+ expectedFields: ExpectedField[] | null; // Expected fields for current AI call (single or multi-value)
663
+
664
+ // Model tracking for compress
665
+ lastUsedModel: string | null; // Set on model declaration, updated on AI calls
666
+
667
+ // Root directory for file operation sandboxing
668
+ rootDir: string;
669
+
670
+ // Error info
671
+ error: string | null;
672
+ errorObject: Error | null;
673
+
674
+ // Async execution tracking
675
+ asyncOperations: Map<string, AsyncOperation>; // id -> operation
676
+ pendingAsyncIds: Set<string>; // Currently executing operation IDs
677
+ asyncVarToOpId: Map<string, string>; // varName -> operation ID
678
+ asyncWaves: AsyncWave[]; // Execution waves
679
+ currentWaveId: number; // Current wave being built/executed
680
+ maxParallel: number; // Max concurrent operations (from --max-parallel)
681
+ nextAsyncId: number; // Counter for generating unique IDs
682
+ awaitingAsyncIds: string[]; // Operation IDs we're currently awaiting (when status is awaiting_async)
683
+
684
+ // Async declaration context - set when inside async let/const to enable non-blocking mode
685
+ currentAsyncVarName: string | null; // Variable being assigned (null = not in async context)
686
+ currentAsyncIsConst: boolean; // Whether it's a const declaration
687
+ currentAsyncType: VibeType; // Type annotation for the variable
688
+ currentAsyncIsPrivate: boolean; // Whether it's a private declaration
689
+ currentAsyncIsDestructure: boolean; // True if async destructuring (variables created by destructure_assign)
690
+ currentAsyncIsFireAndForget: boolean; // True for fire-and-forget async (no variable assigned)
691
+
692
+ // Async function isolation tracking
693
+ isInAsyncIsolation: boolean; // True when running in isolated state (async Vibe function)
694
+
695
+ // Scheduled async operations - waiting for Runtime.run() to start them
696
+ pendingAsyncStarts: PendingAsyncStart[]; // Operations to start as Promises
697
+
698
+ // String interpolation context - true when evaluating prompt for do/vibe or prompt variable
699
+ inPromptContext: boolean;
700
+ }
701
+
702
+ // Instructions - what to execute next
703
+ // All instructions have a location for error reporting
704
+ export type Instruction =
705
+ // Execute AST nodes
706
+ | { op: 'exec_statement'; stmt: AST.Statement; location: SourceLocation }
707
+ | { op: 'exec_expression'; expr: AST.Expression; location: SourceLocation }
708
+ | { op: 'exec_statements'; stmts: AST.Statement[]; index: number; location: SourceLocation }
709
+
710
+ // Variable operations (use lastResult)
711
+ | { op: 'declare_var'; name: string; isConst: boolean; type: VibeType; isPrivate?: boolean; location: SourceLocation }
712
+ | { op: 'assign_var'; name: string; location: SourceLocation }
713
+
714
+ // Function calls (functions always forget context - no context mode support)
715
+ | { op: 'call_function'; funcName: string; argCount: number; location: SourceLocation }
716
+ | { op: 'push_frame'; name: string; location: SourceLocation }
717
+ | { op: 'pop_frame'; location: SourceLocation }
718
+ | { op: 'return_value'; location: SourceLocation }
719
+
720
+ // Block scoping
721
+ | { op: 'enter_block'; savedKeys: string[]; location: SourceLocation }
722
+ | { op: 'exit_block'; savedKeys: string[]; location: SourceLocation }
723
+ | { op: 'clear_async_context'; location: SourceLocation }
724
+
725
+ // AI operations (pause points)
726
+ | { op: 'ai_vibe'; model: string | null; context: AST.ContextSpecifier | null; operationType: 'do' | 'vibe'; location: SourceLocation }
727
+
728
+ // TypeScript evaluation (pause point)
729
+ | { op: 'ts_eval'; params: string[]; body: string; location: SourceLocation }
730
+
731
+ // Imported TS function call (pause point)
732
+ | { op: 'call_imported_ts'; funcName: string; argCount: number; location: SourceLocation }
733
+
734
+ // Control flow
735
+ | { op: 'if_branch'; consequent: AST.BlockStatement; alternate?: AST.Statement | null; location: SourceLocation }
736
+
737
+ // For-in loop
738
+ | { op: 'for_in_init'; stmt: AST.ForInStatement; location: SourceLocation }
739
+ | { op: 'for_in_iterate'; variable: string; items: unknown[]; index: number; body: AST.BlockStatement; savedKeys: string[]; contextMode?: AST.ContextMode; label: string; entryIndex: number; location: SourceLocation }
740
+
741
+ // While loop
742
+ | { op: 'while_init'; stmt: AST.WhileStatement; savedKeys: string[]; location: SourceLocation }
743
+ | { op: 'while_iterate'; stmt: AST.WhileStatement; savedKeys: string[]; contextMode?: AST.ContextMode; label?: string; entryIndex: number; location: SourceLocation }
744
+ | { op: 'while_check'; stmt: AST.WhileStatement; savedKeys: string[]; contextMode?: AST.ContextMode; label?: string; entryIndex: number; location: SourceLocation }
745
+
746
+ // Value building (for objects, arrays, function args)
747
+ | { op: 'push_value'; location: SourceLocation }
748
+ | { op: 'build_object'; keys: string[]; location: SourceLocation }
749
+ | { op: 'build_array'; count: number; location: SourceLocation }
750
+ | { op: 'build_range'; location: SourceLocation }
751
+ | { op: 'collect_args'; count: number; location: SourceLocation }
752
+
753
+ // Literals
754
+ | { op: 'literal'; value: unknown; location: SourceLocation }
755
+
756
+ // String interpolation (regular strings - expands {var} to value)
757
+ | { op: 'interpolate_string'; template: string; location: SourceLocation }
758
+
759
+ // Prompt string interpolation ({var} = reference, !{var} = expand)
760
+ | { op: 'interpolate_prompt_string'; template: string; location: SourceLocation }
761
+
762
+ // Clear prompt context flag after evaluating prompt expression
763
+ | { op: 'clear_prompt_context'; location: SourceLocation }
764
+
765
+ // Template literal interpolation (${var} syntax) - DEPRECATED, use interpolate_string
766
+ | { op: 'interpolate_template'; template: string; location: SourceLocation }
767
+
768
+ // Binary operators
769
+ | { op: 'binary_op'; operator: string; location: SourceLocation }
770
+
771
+ // Unary operators
772
+ | { op: 'unary_op'; operator: string; location: SourceLocation }
773
+
774
+ // Array access
775
+ | { op: 'index_access'; location: SourceLocation }
776
+ | { op: 'slice_access'; hasStart: boolean; hasEnd: boolean; location: SourceLocation }
777
+
778
+ // Method call on object (built-in methods)
779
+ | { op: 'method_call'; method: string; argCount: number; location: SourceLocation }
780
+
781
+ // Member/property access (handles VibeValue.toolCalls, VibeValue.err, regular properties, and bound methods)
782
+ | { op: 'member_access'; property: string; location: SourceLocation }
783
+
784
+ // Tool operations
785
+ | { op: 'exec_tool_declaration'; decl: AST.ToolDeclaration; location: SourceLocation }
786
+
787
+ // Model declaration with tools (uses lastResult as tools array)
788
+ | { op: 'declare_model'; stmt: AST.ModelDeclaration; location: SourceLocation }
789
+
790
+ // AI tool call result (for context building)
791
+ | { op: 'ai_tool_call_result'; toolName: string; args: unknown; result: unknown; error?: string; location: SourceLocation }
792
+
793
+ // Destructuring assignment (assign multiple fields from AI result)
794
+ | { op: 'destructure_assign'; fields: ExpectedField[]; isConst: boolean; location: SourceLocation }
795
+
796
+ // Break loop - exit innermost loop with cleanup
797
+ | { op: 'break_loop'; savedKeys: string[]; contextMode?: ContextMode; label?: string; entryIndex: number; scopeType: 'for' | 'while'; location: SourceLocation };