@native-sdk/cli 0.11.0 → 0.11.1

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 (182) hide show
  1. package/build/app.zig +73 -37
  2. package/build.zig +239 -5
  3. package/native-sdk.d.ts +5 -1
  4. package/package.json +13 -12
  5. package/packages/core/compile-surface/core.ts +30 -0
  6. package/packages/core/package-lock.json +6 -6
  7. package/packages/core/package.json +3 -3
  8. package/packages/core/scripts/scriptc-toolchain.json +44 -44
  9. package/packages/core/scripts/stage_external_core.mjs +27 -16
  10. package/packages/core/sdk/core.d.ts +24 -1
  11. package/packages/core/sdk/core.ts +51 -1
  12. package/packages/core/sdk/events.d.ts +5 -0
  13. package/packages/core/sdk/events.ts +10 -0
  14. package/packages/core/src/bridge_descriptors.ts +3 -3
  15. package/packages/core/src/checker.ts +20 -0
  16. package/packages/core/src/cli.ts +2 -11
  17. package/packages/core/src/context_menus.ts +76 -0
  18. package/packages/core/src/diagnostics.ts +7 -0
  19. package/packages/core/src/extent_program.ts +53 -0
  20. package/packages/core/src/frontend.ts +12 -10
  21. package/packages/core/src/markup_canonical.ts +140 -0
  22. package/packages/core/src/markup_construction.ts +189 -0
  23. package/packages/core/src/markup_display.ts +43 -0
  24. package/packages/core/src/markup_document.ts +226 -0
  25. package/packages/core/src/markup_elements.ts +225 -0
  26. package/packages/core/src/markup_expressions.ts +79 -0
  27. package/packages/core/src/markup_imports.ts +146 -0
  28. package/packages/core/src/markup_parser.ts +228 -0
  29. package/packages/core/src/markup_runtime.ts +93 -0
  30. package/packages/core/src/markup_scalars.ts +143 -0
  31. package/packages/core/src/markup_shapes.ts +243 -0
  32. package/packages/core/src/markup_specialized.ts +242 -0
  33. package/packages/core/src/markup_text.ts +86 -0
  34. package/packages/core/src/markup_values.ts +336 -0
  35. package/packages/core/src/portable_sources.json +24 -0
  36. package/packages/core/src/registered_font.ts +2 -3
  37. package/packages/core/src/runtime_policy.ts +24 -0
  38. package/packages/core/src/scalar_text.ts +1 -3
  39. package/packages/core/src/scroll_mutation.ts +86 -0
  40. package/packages/core/src/scroll_tree.ts +86 -0
  41. package/packages/core/src/service_contract.ts +53 -2
  42. package/packages/core/src/sqlite_cli.ts +3 -46
  43. package/packages/core/src/sqlite_codegen.ts +84 -0
  44. package/packages/core/src/staged_rebuild.ts +60 -0
  45. package/packages/core/src/view_bridge.ts +161 -0
  46. package/packages/core/src/view_check.ts +145 -0
  47. package/packages/core/src/view_evaluator.ts +823 -0
  48. package/packages/core/src/view_frontend.ts +340 -218
  49. package/packages/core/src/view_program.ts +221 -0
  50. package/packages/core/src/view_reload.ts +166 -0
  51. package/packages/core/src/view_reload_watch.ts +98 -0
  52. package/packages/core/src/view_sources.ts +34 -0
  53. package/packages/core/src/virtual_windows.ts +88 -0
  54. package/packages/core/src/web_panes.ts +67 -0
  55. package/packages/core/src/widget_continuity.ts +37 -0
  56. package/packages/core/src/widget_reconcile.ts +63 -0
  57. package/packages/core/src/widget_retention.ts +62 -0
  58. package/skill-data/native-ui/SKILL.md +2 -2
  59. package/skill-data/ts-core/SKILL.md +5 -3
  60. package/skill-data/ts-services/references/service-surface.md +29 -5
  61. package/src/app_runner/root.zig +14 -0
  62. package/src/app_runner/ts_compiled_view.zig +88 -17
  63. package/src/app_runner/ts_core_main.zig +43 -5
  64. package/src/app_runner/ts_core_mobile.zig +1 -1
  65. package/src/automation/server.zig +56 -3
  66. package/src/embed/host.zig +2 -0
  67. package/src/embed/tests.zig +2 -0
  68. package/src/embed/ui_host.zig +2 -0
  69. package/src/platform/keyboard_input.zig +32 -0
  70. package/src/platform/linux/root.zig +2 -0
  71. package/src/platform/macos/appkit_host.h +7 -2
  72. package/src/platform/macos/appkit_host.m +31 -9
  73. package/src/platform/macos/cef_host.mm +15 -1
  74. package/src/platform/macos/global_shortcuts.zig +138 -0
  75. package/src/platform/macos/key_codes.zig +102 -0
  76. package/src/platform/macos/keyboard_input.zig +81 -0
  77. package/src/platform/macos/root.zig +25 -3
  78. package/src/platform/macos/webview_inspection_test.m +106 -0
  79. package/src/platform/null_platform.zig +104 -0
  80. package/src/platform/root.zig +14 -0
  81. package/src/platform/types.zig +102 -0
  82. package/src/platform/windows/global_shortcuts.zig +157 -0
  83. package/src/platform/windows/key_codes.zig +63 -0
  84. package/src/platform/windows/keyboard_input.zig +136 -0
  85. package/src/platform/windows/root.zig +15 -0
  86. package/src/primitives/canvas/decision_reuse.zig +133 -0
  87. package/src/primitives/canvas/font_ttf.zig +27 -3
  88. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  89. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  90. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  91. package/src/primitives/canvas/fonts/README.md +15 -0
  92. package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
  93. package/src/primitives/canvas/markdown_tests.zig +3 -3
  94. package/src/primitives/canvas/reference.zig +3 -5
  95. package/src/primitives/canvas/reference_tests.zig +58 -0
  96. package/src/primitives/canvas/registered_font_policy.zig +1 -1
  97. package/src/primitives/canvas/root.zig +7 -4
  98. package/src/primitives/canvas/text_metrics.zig +32 -39
  99. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  100. package/src/primitives/canvas/text_query_policy.zig +142 -3
  101. package/src/primitives/canvas/text_scalar_policy.zig +80 -2
  102. package/src/primitives/canvas/tokens.zig +9 -0
  103. package/src/primitives/canvas/ui.zig +1 -0
  104. package/src/primitives/canvas/ui_markup.zig +69 -14
  105. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  106. package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
  107. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  108. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  109. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  110. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  111. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  112. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  113. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  114. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  115. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  116. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  117. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  118. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  119. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  120. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  121. package/src/primitives/canvas/ui_markup_view.zig +2817 -74
  122. package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
  123. package/src/primitives/canvas/virtual_extents.zig +47 -33
  124. package/src/primitives/canvas/widget_metric_policy.zig +4 -1
  125. package/src/primitives/canvas/widget_runtime.zig +2 -1
  126. package/src/root.zig +5 -0
  127. package/src/runtime/api.zig +1 -0
  128. package/src/runtime/bridge_descriptor_policy.zig +1 -1
  129. package/src/runtime/bridge_payload.zig +2 -0
  130. package/src/runtime/canvas_widget_context_menu.zig +179 -0
  131. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  132. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  133. package/src/runtime/canvas_widget_runtime.zig +306 -92
  134. package/src/runtime/context_menu_policy.zig +112 -0
  135. package/src/runtime/core.zig +14 -0
  136. package/src/runtime/effects.zig +172 -4
  137. package/src/runtime/effects_host_tests.zig +25 -0
  138. package/src/runtime/flow.zig +1 -0
  139. package/src/runtime/flow_reference.zig +1 -0
  140. package/src/runtime/global_shortcuts.zig +75 -0
  141. package/src/runtime/keyboard_input.zig +86 -0
  142. package/src/runtime/root.zig +3 -0
  143. package/src/runtime/scroll_mutation_policy.zig +130 -0
  144. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  145. package/src/runtime/scroll_tree_policy.zig +99 -0
  146. package/src/runtime/session_record.zig +7 -0
  147. package/src/runtime/staged_rebuild_policy.zig +83 -0
  148. package/src/runtime/system_services.zig +19 -0
  149. package/src/runtime/tests.zig +1 -0
  150. package/src/runtime/ts_core_host.zig +126 -0
  151. package/src/runtime/ts_ui_app.zig +24 -0
  152. package/src/runtime/ui_app.zig +274 -31
  153. package/src/runtime/ui_app_tests.zig +48 -179
  154. package/src/runtime/ui_app_window_tests.zig +133 -0
  155. package/src/runtime/view_reload.zig +226 -0
  156. package/src/runtime/view_widget_scroll.zig +30 -21
  157. package/src/runtime/view_widget_tree.zig +43 -13
  158. package/src/runtime/virtual_window_policy.zig +128 -0
  159. package/src/runtime/web_pane_policy.zig +111 -0
  160. package/src/runtime/web_pane_test_cases.zig +204 -0
  161. package/src/runtime/widget_continuity_policy.zig +73 -0
  162. package/src/runtime/widget_reconcile_policy.zig +81 -0
  163. package/src/runtime/widget_retention_policy.zig +75 -0
  164. package/src/runtime/window_views.zig +19 -4
  165. package/src/security/root.zig +1 -0
  166. package/src/tooling/templates.zig +8 -0
  167. package/src/tooling/ts_core.zig +84 -1
  168. package/src/tooling/verbs.zig +79 -15
  169. package/tools/corewire/core.test.ts +25 -3
  170. package/tools/corewire/core_abi.zig +4 -0
  171. package/tools/corewire/core_contract.ts +1 -1
  172. package/tools/corewire/core_goldens.json +75 -75
  173. package/tools/corewire/core_projection.ts +3 -2
  174. package/tools/corewire/emit_mirror.ts +19 -9
  175. package/tools/corewire/facade_templates.ts +1 -1
  176. package/tools/corewire/intake.test.ts +4 -0
  177. package/tools/corewire/intake_goldens.json +50 -50
  178. package/tools/corewire/invocation.test.ts +4 -0
  179. package/tools/corewire/invocation_goldens.json +3 -3
  180. package/tools/corewire/mirror_templates.ts +4 -0
  181. package/tools/corewire/profile_emission.ts +2 -0
  182. package/tools/corewire/sidecar.zig +2 -0
@@ -0,0 +1,53 @@
1
+ /** Retained virtual-table capability programs. Arithmetic and sparse updates
2
+ * stay with the existing extent reducer; this owner orders their effects on
3
+ * native storage and the app's estimate callback. No pointer crosses the ABI.
4
+ */
5
+ function nscvExtentProgram(request: Uint8Array): Uint8Array {
6
+ if (request.length < 4 || request[0] !== 100 || request[1]! > 1 || request[3] !== 0)
7
+ throw new Error("invalid extent program header");
8
+ const w = new DataView(request.buffer, request.byteOffset, request.byteLength);
9
+ const actions: number[] = [], arguments_: NscFlowInteger[] = [];
10
+ const emit = (action: number, argument: NscFlowInteger = nscvFlowSmall(0)): void => {
11
+ actions.push(action); arguments_.push(argument);
12
+ };
13
+ let flags = 0, gap = 0;
14
+ if (request[1] === 0) {
15
+ if (request.length !== 72 || request[2]! > 1 || w.getUint32(4, true) !== 0 ||
16
+ w.getUint32(60, true) !== 0 || w.getUint32(64, true) !== 0 || w.getUint32(68, true) !== 0)
17
+ throw new Error("invalid extent sync program facts");
18
+ // Reuse the original exact-word shape decision, with no redundant
19
+ // interpretation of identities, counts, chunk arithmetic or gap values.
20
+ const facts = request.slice(); facts[0] = 10; facts[1] = 0; facts[2] = 0;
21
+ const decision = nscvExtentPolicy(facts), plan = new DataView(decision.buffer);
22
+ const mode = decision[0]!;
23
+ flags = decision[1]!; gap = plan.getFloat32(4, true);
24
+ if (mode === 1) emit(0); // Reset before refreshing callback storage.
25
+ emit(1); // Refresh estimate callback, context and uniform estimate.
26
+ emit(mode === 1 ? 3 : 2); // Initialize fresh identity, or read old total.
27
+ emit(4); // Install the new sanitized gap after reading the old total.
28
+ if (mode === 3) emit(5, nscvFlowInteger(plan, 24)); // Old shape, new gap.
29
+ if (mode !== 0) {
30
+ emit(6); // Install the new count/base before pruning and rebuilding.
31
+ if (mode === 2 || mode === 3 || mode === 5) emit(7);
32
+ emit(8, nscvFlowInteger(plan, 16));
33
+ }
34
+ if (mode !== 1 && (mode === 2 || mode === 3 || mode === 5 || request[2] === 1)) emit(9);
35
+ if (mode === 2) { emit(5, nscvFlowInteger(plan, 24)); emit(10); }
36
+ if (mode === 3) emit(11);
37
+ } else {
38
+ if (request.length !== 16 || request[2]! > 3 || w.getUint32(4, true) !== 0 ||
39
+ w.getUint32(8, true) !== 0 || w.getUint32(12, true) !== 0)
40
+ throw new Error("invalid extent correction program facts");
41
+ // A single measured row needs no prefix query. Begin, end and a complete
42
+ // batch resolve the anchor against the current table before corrections.
43
+ if (request[2] !== 1) emit(12);
44
+ emit(13, nscvFlowSmall(request[2]!));
45
+ }
46
+ const result = new Uint8Array(16 + actions.length * 16), out = new DataView(result.buffer);
47
+ out.setUint32(0, flags, true); out.setFloat32(4, gap, true); out.setUint32(8, actions.length, true);
48
+ for (let i = 0; i < actions.length; i++) {
49
+ out.setUint32(16 + i * 16, actions[i]!, true);
50
+ nscvFlowWrite(out, 24 + i * 16, arguments_[i]!);
51
+ }
52
+ return result;
53
+ }
@@ -66,6 +66,8 @@ export interface FrontendResult {
66
66
  readonly servicesContract: string | null;
67
67
  /// The generated typed-client module projected from the service sidecar.
68
68
  readonly servicesClient: string | null;
69
+ /// The declaration module for `servicesClient`.
70
+ readonly servicesClientDeclarations: string | null;
69
71
  readonly diagnostics: SubsetDiagnostic[];
70
72
  /// Non-fatal capability and persistence-contract teaching notices:
71
73
  /// surfaced as warnings, never failing the check.
@@ -87,7 +89,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
87
89
  options.sdkCorePath,
88
90
  );
89
91
  if (graph.diagnostics.length > 0) {
90
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: graph.diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
92
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: graph.diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
91
93
  }
92
94
 
93
95
  const loadProgramFiles = (program: ts.Program): {
@@ -111,7 +113,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
111
113
  let program = createSubsetProgram(entry, graph.files, new Map(), options.sdkCorePath);
112
114
  let loaded = loadProgramFiles(program);
113
115
  if (loaded === null || loaded.files.length === 0) {
114
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${entry}`], inputs: [...graph.files] };
116
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${entry}`], inputs: [...graph.files] };
115
117
  }
116
118
  let tast = new TypedAst(program);
117
119
  let coreFiles = loaded.coreFiles;
@@ -129,7 +131,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
129
131
  options.servicePackages ?? [],
130
132
  );
131
133
  if (serviceSurface.diagnostics.length > 0) {
132
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
134
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
133
135
  }
134
136
 
135
137
  // The typed client is virtual during checking: authors import the stable
@@ -142,7 +144,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
142
144
  program = createSubsetProgram(entry, graph.files, new Map([[generatedPath, serviceSurface.client]]), options.sdkCorePath);
143
145
  loaded = loadProgramFiles(program);
144
146
  if (loaded === null) {
145
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [], warnings: [], typeErrors: ["cannot materialize the generated service client"], inputs: [...graph.files] };
147
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [], warnings: [], typeErrors: ["cannot materialize the generated service client"], inputs: [...graph.files] };
146
148
  }
147
149
  tast = new TypedAst(program);
148
150
  coreFiles = loaded.coreFiles;
@@ -160,7 +162,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
160
162
  options.servicePackages ?? [],
161
163
  );
162
164
  if (serviceSurface.diagnostics.length > 0) {
163
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
165
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [...serviceSurface.diagnostics], warnings: [], typeErrors: [], inputs: [...graph.files] };
164
166
  }
165
167
  }
166
168
 
@@ -180,7 +182,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
180
182
  }
181
183
  }
182
184
  if (typeErrors.length > 0) {
183
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [], warnings: [], typeErrors: [...new Set(typeErrors)], inputs: [...graph.files] };
185
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [], warnings: [], typeErrors: [...new Set(typeErrors)], inputs: [...graph.files] };
184
186
  }
185
187
 
186
188
  if (infer.conflicts.length > 0) {
@@ -195,7 +197,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
195
197
  column,
196
198
  );
197
199
  });
198
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
200
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
199
201
  }
200
202
  const serviceOps = serviceSurface.contract === null
201
203
  ? null
@@ -213,7 +215,7 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
213
215
  );
214
216
  const checkResult = checker.check();
215
217
  if (checkResult.diagnostics.length > 0) {
216
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: checkResult.diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
218
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: checkResult.diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
217
219
  }
218
220
  try {
219
221
  // The contract sidecar emits from the SAME checked analysis, so a
@@ -228,13 +230,13 @@ export function checkFile(entry: string, options: FrontendOptions = {}): Fronten
228
230
  warnings.push(...checkPersistSchemaState(coreFiles[0], options.persistStatePath, options.persistVersion, fingerprint));
229
231
  }
230
232
  const contract = options.contractEntry !== undefined ? emittedContract : null;
231
- return { ok: true, contract, servicesContract: serviceSurface.contract, servicesClient: serviceSurface.client, diagnostics: [], warnings, typeErrors: [], inputs: [...graph.files] };
233
+ return { ok: true, contract, servicesContract: serviceSurface.contract, servicesClient: serviceSurface.client, servicesClientDeclarations: serviceSurface.clientDeclarations, diagnostics: [], warnings, typeErrors: [], inputs: [...graph.files] };
232
234
  } catch (e) {
233
235
  if (e instanceof ContractError) {
234
236
  const file = e.node.getSourceFile();
235
237
  const { line, column } = lineColumn(file, e.node.getStart());
236
238
  const d = makeDiagnostic("NS1063", `${e.message[0].toUpperCase()}${e.message.slice(1)}.`, file.fileName, line, column);
237
- return { ok: false, contract: null, servicesContract: null, servicesClient: null, diagnostics: [d], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
239
+ return { ok: false, contract: null, servicesContract: null, servicesClient: null, servicesClientDeclarations: null, diagnostics: [d], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
238
240
  }
239
241
  throw e;
240
242
  }
@@ -0,0 +1,140 @@
1
+ /** Runtime typed-document coordination (109). The copied tree facts produce
2
+ * an allocation-ordered action tape. Native retains source aliases, tree
3
+ * storage and the existing exact expression-parser capability. Records are
4
+ * 48 bytes: action/code/reserved[6], then five exact little-endian f64 words.
5
+ */
6
+ class NscCanonicalReader {
7
+ canonical_at: number = 4;
8
+ readonly canonical_bytes: Uint8Array;
9
+ readonly canonical_view: DataView;
10
+ constructor(bytes: Uint8Array) {
11
+ this.canonical_bytes = bytes;
12
+ this.canonical_view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
13
+ }
14
+ word(): number {
15
+ if (this.canonical_bytes.length - this.canonical_at < 8) throw new Error("short canonical word");
16
+ const value = this.canonical_view.getFloat64(this.canonical_at, true); this.canonical_at += 8;
17
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error("invalid canonical integer");
18
+ return value;
19
+ }
20
+ blob(): Uint8Array {
21
+ const length = this.word();
22
+ if (length > this.canonical_bytes.length - this.canonical_at) throw new Error("short canonical bytes");
23
+ const value = this.canonical_bytes.subarray(this.canonical_at, this.canonical_at + length);
24
+ this.canonical_at += length; return value;
25
+ }
26
+ }
27
+ function nsccEmit(tape: number[], action: number, code: number = 0,
28
+ a: number = 0, b: number = 0, c: number = 0, d: number = 0, e: number = 0): void {
29
+ tape.push(action, code, a, b, c, d, e);
30
+ }
31
+ function nsccStart(byte: number): boolean {
32
+ return byte >= 97 && byte <= 122 || byte >= 65 && byte <= 90 || byte === 95;
33
+ }
34
+ function nsccPath(bytes: Uint8Array, start: number, end: number): boolean {
35
+ if (start === end) return false;
36
+ let first = true;
37
+ for (let i = start; i < end; i++) {
38
+ const byte = bytes[i]!;
39
+ if (first) { if (!nsccStart(byte)) return false; first = false; }
40
+ else if (byte === 46) first = true;
41
+ else if (!nsccStart(byte) && !(byte >= 48 && byte <= 57)) return false;
42
+ }
43
+ return !first;
44
+ }
45
+ function nsccTrim(bytes: Uint8Array, start: number, end: number): number[] {
46
+ while (start < end && bytes[start] === 32) start++;
47
+ while (end > start && bytes[end - 1] === 32) end--;
48
+ return [start, end];
49
+ }
50
+ function nsccFind(bytes: Uint8Array, start: number, byte: number): number {
51
+ for (let i = start; i < bytes.length; i++) if (bytes[i] === byte) return i;
52
+ return -1;
53
+ }
54
+ function nsccAttribute(tape: number[], index: number, name: Uint8Array, value: Uint8Array): void {
55
+ if (name.length >= 3 && name[0] === 111 && name[1] === 110 && name[2] === 45) {
56
+ const colon = nsccFind(value, 0, 58);
57
+ if (colon < 0) {
58
+ nsccEmit(tape, 11, nsccPath(value, 0, value.length) ? 5 : 6, index, 0, value.length, value.length, value.length);
59
+ } else if (nsccPath(value, 0, colon) && value.length - colon - 1 >= 3 && value[colon + 1] === 123 &&
60
+ value[value.length - 1] === 125 && nsccPath(value, colon + 2, value.length - 1)) {
61
+ nsccEmit(tape, 11, 5, index, 0, colon, colon + 2, value.length - 1);
62
+ } else nsccEmit(tape, 11, 6, index);
63
+ return;
64
+ }
65
+ if (value.length === 0 || value[0] !== 123) { nsccEmit(tape, 11, 1, index, 0, value.length); return; }
66
+ if (value[value.length - 1] !== 125) { nsccEmit(tape, 11, 6, index); return; }
67
+ const inner = nsccTrim(value, 1, value.length - 1), start = inner[0]!, end = inner[1]!;
68
+ if (start === end) { nsccEmit(tape, 11, 6, index); return; }
69
+ for (let i = start; i + 1 < end; i++) if (value[i] === 61 && value[i + 1] === 61) {
70
+ const left = nsccTrim(value, start, i), right = nsccTrim(value, i + 2, end);
71
+ if (nsccPath(value, left[0]!, left[1]!) && nsccPath(value, right[0]!, right[1]!)) {
72
+ nsccEmit(tape, 11, 3, index, left[0]!, left[1]!, right[0]!, right[1]!); return;
73
+ }
74
+ break; // Classification considers the first equality token only.
75
+ }
76
+ nsccEmit(tape, 11, nsccPath(value, start, end) ? 2 : 4, index, start, end);
77
+ }
78
+ function nsccText(tape: number[], text: Uint8Array): void {
79
+ let rest = 0, open = nsccFind(text, 0, 123);
80
+ if (open < 0) return;
81
+ nsccEmit(tape, 12);
82
+ while (open >= 0) {
83
+ if (open > rest) nsccEmit(tape, 13, 1, rest, open);
84
+ const close = nsccFind(text, open, 125);
85
+ if (close < 0) { nsccEmit(tape, 13, 4); nsccEmit(tape, 14); return; }
86
+ const span = nsccTrim(text, open + 1, close);
87
+ nsccEmit(tape, 13, nsccPath(text, span[0]!, span[1]!) ? 2 : 3, span[0]!, span[1]!);
88
+ rest = close + 1; open = nsccFind(text, rest, 123);
89
+ }
90
+ if (rest < text.length) nsccEmit(tape, 13, 1, rest, text.length);
91
+ nsccEmit(tape, 14);
92
+ }
93
+ function nsccOpen(reader: NscCanonicalReader, tape: number[]): number {
94
+ const kind = reader.word(), attrs = reader.word();
95
+ if (kind > 8) throw new Error("invalid canonical node kind");
96
+ if (attrs > 0) nsccEmit(tape, 10, 0, attrs);
97
+ for (let i = 0; i < attrs; i++) nsccAttribute(tape, i, reader.blob(), reader.blob());
98
+ const text = reader.blob();
99
+ if (kind === 1) nsccText(tape, text);
100
+ const children = reader.word();
101
+ if (children > 0) nsccEmit(tape, 15, 0, children);
102
+ return children;
103
+ }
104
+ function nsccNode(reader: NscCanonicalReader, tape: number[]): void {
105
+ const frames = [{ canonical_children: nsccOpen(reader, tape), canonical_next: 0 }];
106
+ while (frames.length > 0) {
107
+ const frame = frames[frames.length - 1]!;
108
+ if (frame.canonical_next < frame.canonical_children) {
109
+ nsccEmit(tape, 16, 0, frame.canonical_next++);
110
+ frames.push({ canonical_children: nsccOpen(reader, tape), canonical_next: 0 });
111
+ } else { nsccEmit(tape, 17); frames.pop(); }
112
+ }
113
+ }
114
+ function nscvMarkupCanonical(request: Uint8Array): Uint8Array {
115
+ if (request.length < 4 || request[0] !== 109 || request[1] !== 1 || request[2]! > 1 || request[3]! > 2)
116
+ throw new Error("invalid canonical request");
117
+ const reader = new NscCanonicalReader(request), tape: number[] = [];
118
+ if (request[3] !== 0) {
119
+ // Standalone raw expressions (1) and name-aware attributes (2) share
120
+ // the document classifier. Native reconstructs borrowed source slices.
121
+ const name = reader.blob(), value = reader.blob();
122
+ nsccAttribute(tape, 0, request[3] === 1 ? new Uint8Array(0) : name, value);
123
+ } else {
124
+ const templates = reader.word(), root = reader.word();
125
+ if (root > 1) throw new Error("invalid canonical root flag");
126
+ if (templates > 0) nsccEmit(tape, 1, 0, templates);
127
+ for (let i = 0; i < templates; i++) { nsccEmit(tape, 2, 0, i); nsccNode(reader, tape); }
128
+ if (root === 1) { nsccEmit(tape, 3); nsccNode(reader, tape); }
129
+ nsccEmit(tape, 4);
130
+ }
131
+ if (reader.canonical_at !== request.length) throw new Error("trailing canonical input");
132
+ const count = tape.length / 7, out = new Uint8Array(request[2] === 0 ? 16 : 16 + count * 48), wire = new DataView(out.buffer);
133
+ out[0] = 109; out[1] = 1; out[2] = request[2]!; wire.setFloat64(8, count, true);
134
+ if (request[2] === 1) for (let i = 0; i < count; i++) {
135
+ const at = 16 + i * 48, source = i * 7;
136
+ out[at] = tape[source]!; out[at + 1] = tape[source + 1]!;
137
+ for (let j = 0; j < 5; j++) wire.setFloat64(at + 8 + j * 8, tape[source + 2 + j]!, true);
138
+ }
139
+ return out;
140
+ }
@@ -0,0 +1,189 @@
1
+ /** Runtime markup construction programs (110). Copied syntax and scope facts
2
+ * select ordered native storage, reflection, evaluation and builder capabilities.
3
+ * No model values, callbacks or borrowed pointers are retained by this owner.
4
+ */
5
+ class NscBuildReader {
6
+ build_at: number = 4;
7
+ readonly build_bytes: Uint8Array;
8
+ readonly build_wire: DataView;
9
+ constructor(bytes: Uint8Array) { this.build_bytes = bytes; this.build_wire = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); }
10
+ word(): number {
11
+ if (this.build_bytes.length - this.build_at < 8) throw new Error("short construction word");
12
+ const n = this.build_wire.getFloat64(this.build_at, true); this.build_at += 8;
13
+ if (!Number.isSafeInteger(n) || n < 0) throw new Error("invalid construction integer");
14
+ return n;
15
+ }
16
+ blob(): Uint8Array {
17
+ const n = this.word(); if (n > this.build_bytes.length - this.build_at) throw new Error("short construction bytes");
18
+ const out = this.build_bytes.subarray(this.build_at, this.build_at + n); this.build_at += n; return out;
19
+ }
20
+ }
21
+ interface NscBuildAttr { readonly name: Uint8Array; readonly value: Uint8Array }
22
+ interface NscBuildNode { readonly construction_node_id: number; readonly tag: number; readonly attrs: readonly NscBuildAttr[]; readonly children: readonly NscBuildNode[] }
23
+ function nscbEqual(a: Uint8Array, b: Uint8Array): boolean {
24
+ if (a.length !== b.length) return false;
25
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
26
+ return true;
27
+ }
28
+ function nscbNamed(a: Uint8Array, b: string): boolean { return nscbEqual(a, new TextEncoder().encode(b)); }
29
+ function nscbEmit(tape: number[], action: number, code: number = 0, a: number = 0, b: number = 0, c: number = 0, d: number = 0, e: number = 0): void {
30
+ tape.push(action, code, a, b, c, d, e);
31
+ }
32
+ function nscbFail(tape: number[], code: number, node: number = 0): void { nscbEmit(tape, 255, code, node); }
33
+ function nscbNode(r: NscBuildReader): NscBuildNode {
34
+ const construction_node_id = r.word(), tag = r.word(), count = r.word(), attrs: NscBuildAttr[] = [];
35
+ if (tag > 8) throw new Error("invalid construction node kind");
36
+ for (let i = 0; i < count; i++) attrs.push({ name: r.blob(), value: r.blob() });
37
+ const length = r.word(), children: NscBuildNode[] = [];
38
+ for (let i = 0; i < length; i++) children.push(nscbNode(r));
39
+ return { construction_node_id, tag, attrs, children };
40
+ }
41
+ function nscbAttr(node: NscBuildNode, name: string): number {
42
+ for (let i = 0; i < node.attrs.length; i++) if (nscbNamed(node.attrs[i]!.name, name)) return i;
43
+ return -1;
44
+ }
45
+ function nscbSlots(node: NscBuildNode, found: number[]): void {
46
+ if (node.tag === 8) { found.push(node.construction_node_id); return; }
47
+ if (node.tag === 6) return;
48
+ for (const child of node.children) nscbSlots(child, found);
49
+ }
50
+ // Tokens are byte spans into the original args attribute. Only ASCII space
51
+ // separates tokens, and only the first equals splits the name and default.
52
+ function nscbArgs(bytes: Uint8Array): number[] {
53
+ const out: number[] = []; let at = 0;
54
+ while (at < bytes.length) {
55
+ if (bytes[at] === 32) { at++; continue; }
56
+ const first = at; let equals = -1;
57
+ while (at < bytes.length && bytes[at] !== 32) { if (bytes[at] === 61 && equals < 0) equals = at; at++; }
58
+ out.push(first, equals < 0 ? at : equals, equals < 0 ? 0 : equals + 1, at);
59
+ }
60
+ return out;
61
+ }
62
+ function nscbUse(r: NscBuildReader, tape: number[]): void {
63
+ const scopeLength = r.word(), scopeFloor = r.word(), context = r.word(), depth = r.word(), selected = r.word();
64
+ if (scopeLength > 16 || scopeFloor > scopeLength) throw new Error("invalid construction scope");
65
+ const use = nscbNode(r), definition = nscbNode(r);
66
+ if (context !== 0 && selected >= context - 1 || depth >= 128) throw new Error("unadmitted template body");
67
+ if (definition.children.length !== 1 || definition.children[0]!.tag !== 0) { nscbFail(tape, 14, definition.construction_node_id); return; }
68
+ const slots: number[] = []; nscbSlots(definition.children[0]!, slots);
69
+ if (slots.length > 1) { nscbFail(tape, 15, slots[1]!); return; }
70
+ if (use.children.length !== 0 && slots.length === 0) { nscbFail(tape, 16, use.children[0]!.construction_node_id); return; }
71
+ const argsAttribute = nscbAttr(definition, "args");
72
+ const argsBytes = argsAttribute < 0 ? new Uint8Array(0) : definition.attrs[argsAttribute]!.value;
73
+ const args = nscbArgs(argsBytes);
74
+ for (const attr of use.attrs) {
75
+ if (nscbNamed(attr.name, "template") || nscbNamed(attr.name, "on-press")) continue;
76
+ if (attr.name.length >= 3 && attr.name[0] === 111 && attr.name[1] === 110 && attr.name[2] === 45) { nscbFail(tape, 17, use.construction_node_id); return; }
77
+ let declared = false;
78
+ for (let a = 0; a < args.length; a += 4) if (nscbEqual(attr.name, argsBytes.subarray(args[a]!, args[a + 1]!))) { declared = true; break; }
79
+ if (!declared) { nscbFail(tape, 18, use.construction_node_id); return; }
80
+ }
81
+ nscbEmit(tape, 20, 0, selected, argsAttribute + 1);
82
+ const press = nscbAttr(use, "on-press");
83
+ if (press >= 0) nscbEmit(tape, 21, 0, press);
84
+ let argCount = 0;
85
+ for (let a = 0; a < args.length; a += 4) {
86
+ if (scopeLength + argCount >= 16) { nscbFail(tape, 19, use.construction_node_id); return; }
87
+ const first = args[a]!, last = args[a + 1]!, defaultFirst = args[a + 2]!, end = args[a + 3]!;
88
+ const name = argsBytes.subarray(first, last); let attrIndex = -1;
89
+ for (let i = 0; i < use.attrs.length; i++) if (nscbEqual(use.attrs[i]!.name, name)) { attrIndex = i; break; }
90
+ nscbEmit(tape, 22, 0, scopeLength + argCount, first, last);
91
+ if (attrIndex >= 0) nscbEmit(tape, 23, 0, attrIndex);
92
+ else if (defaultFirst !== 0) {
93
+ for (let i = defaultFirst; i < end; i++) if (argsBytes[i] === 123) { nscbFail(tape, 20, definition.construction_node_id); return; }
94
+ if (defaultFirst < end && (argsBytes[defaultFirst] === 39 || argsBytes[defaultFirst] === 34)) { nscbFail(tape, 21, definition.construction_node_id); return; }
95
+ nscbEmit(tape, 24, 0, defaultFirst, end);
96
+ } else { nscbFail(tape, 22, use.construction_node_id); return; }
97
+ nscbEmit(tape, 25, attrIndex < 0 ? 1 : 0); argCount++;
98
+ }
99
+ if (scopeLength + argCount >= 16) { nscbFail(tape, 19, use.construction_node_id); return; }
100
+ nscbEmit(tape, 26, 0, scopeLength + argCount);
101
+ nscbEmit(tape, 27, 0, scopeLength + argCount + 1, scopeLength, selected + 1, depth + 1);
102
+ nscbEmit(tape, 28); // Provenance allocation precedes installing restoration.
103
+ nscbEmit(tape, 29); // Build body, then restore the saved storage on every exit.
104
+ }
105
+ function nscvMarkupConstruction(input: Uint8Array): Uint8Array {
106
+ if (input.length < 4 || input[0] !== 110 || input[1] !== 1 || input[2]! > 12 || input[3]! > 1) throw new Error("invalid construction header");
107
+ const mode = input[2]!, r = new NscBuildReader(input), tape: number[] = [];
108
+ if (mode === 0) {
109
+ const imports = r.word(), root = r.word();
110
+ if (root > 1) throw new Error("invalid construction root");
111
+ if (imports > 0) nscbFail(tape, 1); else if (root === 0) nscbFail(tape, 2); else nscbEmit(tape, 0);
112
+ } else if (mode === 1 || mode === 2) {
113
+ const kind = r.word(); if (kind > 8) throw new Error("invalid construction kind");
114
+ const next = mode === 2 ? r.word() : 9, test = mode === 2 ? r.word() : 0;
115
+ if (next > 9 || test > 1) throw new Error("invalid construction child facts");
116
+ if (kind === 0) nscbEmit(tape, 1);
117
+ else if (kind === 6) nscbEmit(tape, 2);
118
+ else if (kind === 5) nscbFail(tape, 3);
119
+ else if (kind === 7) nscbFail(tape, 4);
120
+ else if (kind === 1) nscbFail(tape, 6);
121
+ else if (mode === 1) nscbFail(tape, kind === 8 ? 5 : 7);
122
+ else if (kind === 8) nscbEmit(tape, 3);
123
+ else if (kind === 2) nscbEmit(tape, 4, 0, next === 4 ? 1 : 0);
124
+ else if (kind === 3) { if (test === 0) nscbFail(tape, 8); else nscbEmit(tape, 5); }
125
+ else nscbFail(tape, 9);
126
+ } else if (mode === 3) {
127
+ const kind = r.word(), next = r.word(), result = r.word();
128
+ if ((kind !== 2 && kind !== 3) || next > 1) throw new Error("invalid construction branch");
129
+ nscbEmit(tape, kind === 3 && result !== 0 ? 6 : result === 0 && next === 1 ? 6 : 0, 0, kind === 3 && result !== 0 ? 0 : 1, next);
130
+ } else if (mode === 4) {
131
+ const length = r.word(), floor = r.word(), name = r.blob();
132
+ if (length > 16 || floor > length) throw new Error("invalid lookup scope");
133
+ let found = 0;
134
+ for (let i = 0; i < length; i++) { const entry = r.blob(); if (i >= floor && nscbEqual(entry, name)) found = i + 1; }
135
+ nscbEmit(tape, 7, 0, found);
136
+ } else if (mode === 5) {
137
+ const attrs = r.word(), children = r.word(), context = r.word(), length = r.word(), floor = r.word();
138
+ if (length > 16 || floor > length) throw new Error("invalid slot scope");
139
+ let found = 0, content = 0;
140
+ for (let i = 0; i < length; i++) { const kind = r.word(), children = r.word(); if (kind > 4 || kind !== 4 && children !== 0) throw new Error("invalid scope payload"); if (i >= floor && kind === 4) { found = i + 1; content = children; } }
141
+ if (attrs > 0) nscbFail(tape, 23); else if (children > 0) nscbFail(tape, 24); else if (found === 0 && context === 0) nscbFail(tape, 5); else nscbEmit(tape, 8, 0, content === 0 ? 0 : found);
142
+ } else if (mode === 6) {
143
+ const each = r.word(), as = r.word(), length = r.word(), children = r.word(); let invalid = 0;
144
+ for (let i = 0; i < children; i++) { const tag = r.word(); if (tag > 8) throw new Error("invalid loop child"); if (invalid === 0 && (tag === 1 || tag === 5 || tag === 7)) invalid = i + 1; }
145
+ if (each > 1 || as > 1 || length > 16) throw new Error("invalid loop scope");
146
+ if (each === 0) nscbFail(tape, 25); else if (as === 0) nscbFail(tape, 26); else if (length >= 16) nscbFail(tape, 27); else if (children === 0) nscbFail(tape, 28); else if (invalid !== 0) nscbEmit(tape, 255, 28, invalid); else nscbEmit(tape, 0);
147
+ } else if (mode === 7) {
148
+ const phase = r.word(), cursor = r.word(), length = r.word(), flags = r.word();
149
+ if (phase > 3 || cursor > length) throw new Error("invalid iteration cursor");
150
+ if (phase === 3) nscbEmit(tape, flags === 0 ? 0 : 14);
151
+ else if (cursor === length) { if (phase === 0) nscbFail(tape, 30); else nscbEmit(tape, 0); } else nscbEmit(tape, phase === 2 ? flags === 0 ? 10 : 9 : 9, 0, cursor, cursor + 1, phase === 1 ? flags + 1 : 0, phase === 1 ? flags : 0);
152
+ } else if (mode === 8) {
153
+ const present = r.word(), kind = r.word(), type = r.word(), wanted = r.word();
154
+ if (present > 1 || kind > 4) throw new Error("invalid iterable scope");
155
+ nscbEmit(tape, present === 0 ? 12 : kind === 1 && type === wanted ? 11 : 0);
156
+ } else if (mode === 9) {
157
+ const typed = r.word(), present = r.word(), kind = r.word(), tail = r.word();
158
+ if (typed > 2 || present > 1 || kind > 4 || tail > 1) throw new Error("invalid argument facts");
159
+ if (typed === 0) nscbFail(tape, 29); else nscbEmit(tape, typed === 1 && present === 1 && (kind === 1 || kind === 3) && tail === 0 ? 11 : typed === 1 && present === 0 ? 12 : 13);
160
+ } else if (mode === 10) {
161
+ const length = r.word(), floor = r.word(), context = r.word(), depth = r.word(), present = r.word(), name = r.blob(), count = r.word();
162
+ if (length > 16 || floor > length || present > 1) throw new Error("invalid template lookup scope");
163
+ let selected = -1;
164
+ for (let i = 0; i < count; i++) {
165
+ const named = r.word(), value = r.blob(); if (named > 1) throw new Error("invalid template name fact");
166
+ if (selected < 0 && named === 1 && nscbEqual(value, name)) selected = i;
167
+ }
168
+ if (present === 0) nscbFail(tape, 10);
169
+ else if (selected < 0) nscbFail(tape, 11);
170
+ else if (context !== 0 && selected >= context - 1) nscbFail(tape, 12);
171
+ else if (depth >= 128) nscbFail(tape, 13);
172
+ else nscbEmit(tape, 20, 0, selected);
173
+ } else if (mode === 12) nscbUse(r, tape);
174
+ else {
175
+ const cursor = r.word(), length = r.word(); let found = length;
176
+ if (cursor > length) throw new Error("invalid argument iterable cursor");
177
+ for (let i = 0; i < length; i++) { const byte = r.word(); if (byte > 1) throw new Error("invalid iterable type"); if (i >= cursor && found === length && byte === 0) found = i; }
178
+ nscbEmit(tape, found === length ? 0 : 9, 0, found, found + 1);
179
+ }
180
+ if (r.build_at !== input.length) throw new Error("trailing construction facts");
181
+ const count = tape.length / 7, out = new Uint8Array(input[3] === 0 ? 16 : 16 + count * 48), wire = new DataView(out.buffer);
182
+ out[0] = 110; out[1] = 1; out[2] = input[3]!; wire.setFloat64(8, count, true);
183
+ if (input[3] === 1) for (let i = 0; i < count; i++) {
184
+ const at = 16 + i * 48, source = i * 7;
185
+ out[at] = tape[source]!; out[at + 1] = tape[source + 1]!;
186
+ for (let j = 0; j < 5; j++) wire.setFloat64(at + 8 + j * 8, tape[source + 2 + j]!, true);
187
+ }
188
+ return out;
189
+ }
@@ -0,0 +1,43 @@
1
+ /** Display assembly programs (104), shared by interpolation, concatenation,
2
+ * fixed and percent. No values or pointers cross this boundary: native
3
+ * capabilities supply exact i64 conversion, f32 scaling/decimal rendering
4
+ * and arena appends. Each append retains its original allocation boundary.
5
+ * Modes: scalar=0, fixed=1, percent=2. Kinds match expression programs.
6
+ * Instructions: integer=0, shortest=1, scale=2, decimal=3, source=4,
7
+ * number=5, literal=6, repeat=7. Literal bytes belong to the returned plan.
8
+ */
9
+ function nscvMarkupDisplay(request: Uint8Array): Uint8Array {
10
+ if (request.length !== 8 || request[0] !== 104 || request[1] !== 1 || request[2]! > 2 ||
11
+ request[3]! < 1 || request[3]! > 4 || request[4]! > 6 || request[5]! > 1 ||
12
+ request[6] !== 0 || request[7] !== 0 || request[2] === 0 && request[4] !== 0 ||
13
+ request[3] !== 4 && request[5] !== 0 || request[2] !== 0 && request[3] !== 2 && request[3] !== 3)
14
+ throw new Error("invalid markup display request");
15
+ const mode = request[2]!, kind = request[3]!, digits = request[4]!;
16
+ const actions: number[] = [], literals: number[] = [];
17
+ if (mode === 0 && kind === 1) actions.push(4, 0, 0, 0);
18
+ else if (mode === 0 && kind === 4) {
19
+ if (request[5] === 1) literals.push(116, 114, 117, 101);
20
+ else literals.push(102, 97, 108, 115, 101);
21
+ actions.push(6, 0, literals.length, 0);
22
+ } else {
23
+ if (mode === 2) actions.push(2, 0, 0, 0);
24
+ actions.push(mode === 2 || mode === 1 && kind === 3 ? 3 : kind === 2 ? 0 : 1,
25
+ mode === 0 ? 0 : digits, 0, 0);
26
+ actions.push(5, 0, 0, 0);
27
+ if (mode === 1 && kind === 2 && digits > 0) {
28
+ literals.push(46);
29
+ actions.push(6, 0, 1, 0, 7, 48, digits, 0);
30
+ }
31
+ // Keep even the empty suffix append in the fixed-format program.
32
+ if (mode !== 0) {
33
+ const offset = literals.length;
34
+ if (mode === 2) literals.push(37);
35
+ actions.push(6, offset, mode === 2 ? 1 : 0, 0);
36
+ }
37
+ }
38
+ const out = new Uint8Array(8 + actions.length + literals.length);
39
+ out[0] = 104; out[1] = 1; out[2] = mode; out[3] = actions.length / 4; out[4] = literals.length;
40
+ for (let i = 0; i < actions.length; i++) out[8 + i] = actions[i]!;
41
+ for (let i = 0; i < literals.length; i++) out[8 + actions.length + i] = literals[i]!;
42
+ return out;
43
+ }