@native-sdk/cli 0.7.1 → 0.8.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 (94) hide show
  1. package/build/app.zig +273 -65
  2. package/build/ts_run.mjs +6 -8
  3. package/build.zig +341 -361
  4. package/native-sdk.d.ts +6 -3
  5. package/package.json +13 -11
  6. package/packages/core/compile-surface/core.ts +559 -0
  7. package/packages/core/package-lock.json +375 -12
  8. package/packages/core/package.json +9 -6
  9. package/packages/core/scripts/compiler_typecheck.mjs +58 -0
  10. package/packages/core/scripts/gen_case_tables.mjs +130 -0
  11. package/packages/core/scripts/gen_declarations.mjs +97 -0
  12. package/packages/core/scripts/run_external_core_compiler.mjs +108 -0
  13. package/packages/core/scripts/stage_external_core.mjs +148 -0
  14. package/packages/core/sdk/core.d.ts +363 -0
  15. package/packages/core/sdk/events.d.ts +65 -0
  16. package/packages/core/sdk/text.d.ts +51 -0
  17. package/packages/core/src/checker.ts +3 -3
  18. package/packages/core/src/cli.ts +40 -38
  19. package/packages/core/src/contract.ts +749 -0
  20. package/packages/core/src/devhost.ts +4 -3
  21. package/packages/core/src/diagnostics.ts +5 -7
  22. package/packages/core/src/{transpile.ts → frontend.ts} +38 -50
  23. package/packages/core/src/infer.ts +1 -1
  24. package/packages/core/src/typed_ast.ts +16 -15
  25. package/packages/core/src/wyhash.ts +79 -0
  26. package/skill-data/native-ui/SKILL.md +4 -2
  27. package/skill-data/ts-core/SKILL.md +29 -29
  28. package/src/platform/macos/appkit_host.m +51 -3
  29. package/src/platform/types.zig +4 -0
  30. package/src/platform/windows/gpu_surface_renderer.cpp +2280 -0
  31. package/src/platform/windows/gpu_surface_renderer.h +86 -0
  32. package/src/platform/windows/root.zig +298 -20
  33. package/src/platform/windows/webview2_host.cpp +343 -33
  34. package/src/primitives/canvas/code.zig +50 -0
  35. package/src/primitives/canvas/code_tests.zig +174 -1
  36. package/src/primitives/canvas/frame.zig +45 -1
  37. package/src/primitives/canvas/gpu.zig +6 -0
  38. package/src/primitives/canvas/render_tests.zig +93 -0
  39. package/src/primitives/canvas/root.zig +2 -0
  40. package/src/primitives/canvas/serialization.zig +150 -21
  41. package/src/primitives/canvas/themes/geist.zig +51 -5
  42. package/src/primitives/canvas/tokens.zig +33 -4
  43. package/src/primitives/canvas/ui.zig +52 -7
  44. package/src/primitives/canvas/ui_markup.zig +38 -1
  45. package/src/primitives/canvas/ui_markup_compiled.zig +28 -0
  46. package/src/primitives/canvas/ui_markup_contract.zig +9 -0
  47. package/src/primitives/canvas/ui_markup_view.zig +28 -0
  48. package/src/primitives/canvas/ui_markup_view_tests.zig +10 -2
  49. package/src/primitives/canvas/ui_schema.zig +5 -0
  50. package/src/primitives/canvas/ui_schema_tests.zig +4 -3
  51. package/src/primitives/canvas/ui_tests.zig +14 -0
  52. package/src/primitives/canvas/widget_builtin_tests.zig +513 -13
  53. package/src/primitives/canvas/widget_invalidation.zig +11 -1
  54. package/src/primitives/canvas/widget_layout.zig +260 -21
  55. package/src/primitives/canvas/widget_metrics.zig +45 -9
  56. package/src/primitives/canvas/widget_render.zig +220 -70
  57. package/src/primitives/canvas/widget_render_controls.zig +79 -21
  58. package/src/primitives/canvas/widget_render_style.zig +52 -8
  59. package/src/primitives/canvas/widget_text_input.zig +2 -0
  60. package/src/primitives/canvas/widgets.zig +53 -2
  61. package/src/runtime/canvas_frame.zig +60 -7
  62. package/src/runtime/canvas_frame_invalidation_tests.zig +80 -0
  63. package/src/runtime/canvas_frame_packet_tests.zig +83 -9
  64. package/src/runtime/canvas_frame_patch_tests.zig +16 -0
  65. package/src/runtime/canvas_images.zig +8 -2
  66. package/src/runtime/canvas_widget_clipboard_tests.zig +1 -1
  67. package/src/runtime/canvas_widget_runtime.zig +11 -8
  68. package/src/runtime/effects.zig +6 -0
  69. package/src/runtime/effects_tests.zig +30 -0
  70. package/src/runtime/gpu_surface_events.zig +38 -7
  71. package/src/runtime/media_surface_tests.zig +1 -1
  72. package/src/runtime/runtime_event_tests.zig +74 -0
  73. package/src/runtime/ts_core_host.zig +38 -38
  74. package/src/runtime/ts_ui_app.zig +12 -12
  75. package/src/runtime/ui_app.zig +10 -8
  76. package/src/runtime/ui_app_tests.zig +67 -0
  77. package/src/runtime/view.zig +6 -0
  78. package/src/runtime/view_canvas.zig +15 -0
  79. package/src/runtime/view_widget_text.zig +6 -4
  80. package/src/runtime/window_view_runtime.zig +1 -0
  81. package/src/tooling/manifest.zig +32 -0
  82. package/src/tooling/raw_manifest.zig +4 -0
  83. package/src/tooling/templates.zig +34 -26
  84. package/src/tooling/ts_core.zig +55 -34
  85. package/src/tooling/verbs.zig +1 -1
  86. package/tools/corewire/core_abi.zig +169 -0
  87. package/tools/corewire/emit.zig +2418 -0
  88. package/tools/corewire/emit_facade.zig +3984 -0
  89. package/tools/corewire/emit_profile.zig +501 -0
  90. package/tools/corewire/main.zig +561 -0
  91. package/tools/corewire/shim_rt.zig +632 -0
  92. package/tools/corewire/sidecar.zig +2507 -0
  93. package/packages/core/rt/rt.zig +0 -1986
  94. package/packages/core/src/emitter.ts +0 -11898
@@ -22,7 +22,8 @@
22
22
  // sub arm|re-arm|cancel <key> subscription reconciliation by key
23
23
  // fire <key> -> <kind> @ <ms> a virtual timer fired (dispatched)
24
24
  //
25
- // Virtual-host semantics match the run-fidelity harness (node = native):
25
+ // Virtual-host semantics match the compiled core's (node = native; the
26
+ // SDK's ts-core e2e batteries pin the native side over real archives):
26
27
  // - Cmd.now dispatches its arm immediately at the current virtual time;
27
28
  // - Sub.timer reconciles by key after every commit (new key or changed
28
29
  // interval arms, missing key cancels), each fire dispatching the named
@@ -70,8 +71,8 @@ if (!entry) usage();
70
71
  // The resolver hook maps "@native-sdk/core" onto this package's own SDK
71
72
  // module (app trees carry no node_modules for bare resolution to find),
72
73
  // and the byte-text methods (s.toUpperCase(), s.split(sep), ...) install
73
- // on Uint8Array.prototype before the core loads — the same tables the
74
- // native rt helpers use, so node runs are byte-identical by construction.
74
+ // on Uint8Array.prototype before the core loads — locale-free simple
75
+ // case tables, the semantics the compiled core carries natively.
75
76
  installTextMethods();
76
77
  register(new URL("./devhost_resolver.mjs", import.meta.url));
77
78
 
@@ -394,13 +394,11 @@ export const rules = {
394
394
  fix: "Declare `Model` as an interface record (`export interface Model { ... }`) and `Msg` as a kind-tagged union (`export type Msg = { kind: \"...\" } | ...`).",
395
395
  why: "The generated wiring commits `Model` as the reference-stored record root and dispatches `Msg` by its declaration-order kind tags; any other shape under those names has no dispatch or commit path and would fail deep inside the emitted module instead of teaching here.",
396
396
  },
397
- // NS9xxx: internal emit-time verification. A checker gap becomes a loud
398
- // internal error naming the construct, never silent misbehavior.
399
- NS9001: {
400
- id: "NS9001",
401
- title: "construct not covered by the v1 emitter",
402
- fix: "Rewrite with the constructs in the subset table, or report this file so the mapping gains a rule.",
403
- why: "The emitter re-derives every subset rule during emission; anything it cannot prove a mapping for must stop the build.",
397
+ NS1063: {
398
+ id: "NS1063",
399
+ title: "the contract sidecar carries every crossing shape",
400
+ fix: "Spell the crossing in a schema-carried form: value-stored records (object-literal aliases) for message payloads, named records around optional or array payloads, and integer aliases whose values reach past 255.",
401
+ why: "The contract sidecar is the machine-readable twin of the core's surface, and a shape its schema cannot state would silently drop from every consumer — so the build stops here with the spelling that carries it instead.",
404
402
  },
405
403
  } as const satisfies Record<string, RuleCopy>;
406
404
 
@@ -1,64 +1,51 @@
1
- // Orchestration: resolve the core's import graph (teaching diagnostics for
2
- // every module-boundary mistake), check every module with the provider's
3
- // own checker (same semantics as the author-facing tsc by upstream design),
4
- // run the subset checker, run integer inference, then emit ONE Zig module
5
- // for the whole graph.
1
+ // The frontend orchestration: resolve the core's import graph (teaching
2
+ // diagnostics for every module-boundary mistake), check every module with
3
+ // the provider's own checker (same semantics as the author-facing tsc by
4
+ // upstream design), run the subset checker, run integer inference, then —
5
+ // when asked — emit the contract sidecar for the whole graph. The
6
+ // external core compiler does the compiling; this pass is the subset's
7
+ // teaching surface and the contract source.
6
8
 
7
9
  import { ts, TypedAst, createSubsetProgram, lineColumn } from "./typed_ast.ts";
8
10
  import { resolveModuleGraph } from "./modules.ts";
9
11
  import { TypeTable } from "./types.ts";
10
12
  import { IntInference } from "./infer.ts";
11
13
  import { SubsetChecker } from "./checker.ts";
12
- import { Emitter, EmitError, type KernelCapacities } from "./emitter.ts";
14
+ import { emitContractSidecar, ContractError } from "./contract.ts";
13
15
  import { makeDiagnostic, formatDiagnostic, type SubsetDiagnostic } from "./diagnostics.ts";
14
16
  import path from "node:path";
15
17
  import fs from "node:fs";
16
18
 
17
- export interface TranspileOptions {
18
- /// Frame arena capacity in bytes: the transient budget of one dispatch.
19
- /// Emitted as a comptime parameter of the core's rt kernel instantiation
20
- /// (rt default when omitted).
21
- readonly frameCap?: number;
22
- /// Model heap capacity in bytes PER SPACE (the two-space committed-model
23
- /// heap): the live model graph plus not-yet-compacted garbage must fit.
24
- readonly heapCap?: number;
19
+ export interface FrontendOptions {
20
+ /// When set, also emit the contract sidecar (core.contract.json,
21
+ /// schema format 1) from the checked program — the entry spelling the
22
+ /// document states (never a filesystem-absolute leak).
23
+ readonly contractEntry?: string;
25
24
  }
26
25
 
27
- export interface TranspileResult {
26
+ export interface FrontendResult {
28
27
  readonly ok: boolean;
29
- readonly zig: string | null;
28
+ /// The contract sidecar JSON, when options.contractEntry asked for it
29
+ /// (null otherwise, and on any failed check).
30
+ readonly contract: string | null;
30
31
  readonly diagnostics: SubsetDiagnostic[];
31
32
  /// Non-fatal teaching notices (NS1028 today): surfaced as warnings,
32
- /// never failing the transpile.
33
+ /// never failing the check.
33
34
  readonly warnings: SubsetDiagnostic[];
34
35
  /// Provider (tsc-semantics) diagnostics, already formatted.
35
36
  readonly typeErrors: string[];
36
37
  /// Every file the core is built from, absolute, entry first — the
37
- /// build-graph staleness set (a change to any of them re-emits).
38
+ /// build-graph staleness set (a change to any of them re-checks).
38
39
  readonly inputs: string[];
39
40
  }
40
41
 
41
- function validateCapacities(options: TranspileOptions): KernelCapacities {
42
- for (const [name, v] of [
43
- ["frameCap", options.frameCap],
44
- ["heapCap", options.heapCap],
45
- ] as const) {
46
- if (v !== undefined && (!Number.isSafeInteger(v) || v <= 0)) {
47
- throw new Error(`${name} must be a positive integer byte count, got ${v}`);
48
- }
49
- }
50
- return { frameCap: options.frameCap, heapCap: options.heapCap };
51
- }
52
-
53
- export function transpileFile(entry: string, options: TranspileOptions = {}): TranspileResult {
54
- const capacities = validateCapacities(options);
55
-
42
+ export function checkFile(entry: string, options: FrontendOptions = {}): FrontendResult {
56
43
  // Module-boundary mistakes (NS1034-NS1037) teach BEFORE the type-checked
57
44
  // program is built: a missing file or an escaped src/ boundary would
58
45
  // otherwise surface as a raw resolution error.
59
46
  const graph = resolveModuleGraph(entry);
60
47
  if (graph.diagnostics.length > 0) {
61
- return { ok: false, zig: null, diagnostics: graph.diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
48
+ return { ok: false, contract: null, diagnostics: graph.diagnostics, warnings: [], typeErrors: [], inputs: [...graph.files] };
62
49
  }
63
50
 
64
51
  const program = createSubsetProgram(entry);
@@ -68,12 +55,12 @@ export function transpileFile(entry: string, options: TranspileOptions = {}): Tr
68
55
  for (const p of graph.files) {
69
56
  const file = byPath.get(path.resolve(p));
70
57
  if (!file) {
71
- return { ok: false, zig: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${p}`], inputs: [...graph.files] };
58
+ return { ok: false, contract: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${p}`], inputs: [...graph.files] };
72
59
  }
73
60
  files.push(file);
74
61
  }
75
62
  if (files.length === 0) {
76
- return { ok: false, zig: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${entry}`], inputs: [] };
63
+ return { ok: false, contract: null, diagnostics: [], warnings: [], typeErrors: [`cannot read ${entry}`], inputs: [] };
77
64
  }
78
65
 
79
66
  const typeErrors: string[] = [];
@@ -87,14 +74,14 @@ export function transpileFile(entry: string, options: TranspileOptions = {}): Tr
87
74
  }
88
75
  }
89
76
  if (typeErrors.length > 0) {
90
- return { ok: false, zig: null, diagnostics: [], warnings: [], typeErrors: [...new Set(typeErrors)], inputs: [...graph.files] };
77
+ return { ok: false, contract: null, diagnostics: [], warnings: [], typeErrors: [...new Set(typeErrors)], inputs: [...graph.files] };
91
78
  }
92
79
 
93
80
  const table = new TypeTable(tast, files);
94
81
  const checker = new SubsetChecker(tast, table, files);
95
82
  const checkResult = checker.check();
96
83
  if (checkResult.diagnostics.length > 0) {
97
- return { ok: false, zig: null, diagnostics: checkResult.diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
84
+ return { ok: false, contract: null, diagnostics: checkResult.diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
98
85
  }
99
86
 
100
87
  const infer = new IntInference(tast, table, files);
@@ -112,32 +99,33 @@ export function transpileFile(entry: string, options: TranspileOptions = {}): Tr
112
99
  column,
113
100
  );
114
101
  });
115
- return { ok: false, zig: null, diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
102
+ return { ok: false, contract: null, diagnostics, warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
116
103
  }
117
- const emitter = new Emitter(tast, table, infer, checkResult, files, path.basename(entry), capacities);
118
104
  try {
119
- const zig = emitter.emitModule();
120
- return { ok: true, zig, diagnostics: [], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
105
+ // The contract sidecar emits from the SAME checked analysis, so a
106
+ // contract-bearing run keeps every check-time teaching.
107
+ const contract =
108
+ options.contractEntry !== undefined
109
+ ? emitContractSidecar({ tast, table, infer, checkResult, files, entry: options.contractEntry })
110
+ : null;
111
+ return { ok: true, contract, diagnostics: [], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
121
112
  } catch (e) {
122
- if (e instanceof EmitError) {
113
+ if (e instanceof ContractError) {
123
114
  const file = e.node.getSourceFile();
124
115
  const { line, column } = lineColumn(file, e.node.getStart());
125
- // Layer-3 re-derivations of taught rules keep their own rule copy;
126
- // everything else is the internal NS9001 stop.
127
- const site = e.ruleId === "NS9001" ? `Internal: no v1 mapping for ${e.message}.` : `${e.message[0].toUpperCase()}${e.message.slice(1)}.`;
128
- const d = makeDiagnostic(e.ruleId, site, file.fileName, line, column);
129
- return { ok: false, zig: null, diagnostics: [d], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
116
+ const d = makeDiagnostic("NS1063", `${e.message[0].toUpperCase()}${e.message.slice(1)}.`, file.fileName, line, column);
117
+ return { ok: false, contract: null, diagnostics: [d], warnings: checkResult.warnings, typeErrors: [], inputs: [...graph.files] };
130
118
  }
131
119
  throw e;
132
120
  }
133
121
  }
134
122
 
135
- export function transpileSource(source: string, name = "core.ts", options: TranspileOptions = {}): TranspileResult {
123
+ export function checkSource(source: string, name = "core.ts", options: FrontendOptions = {}): FrontendResult {
136
124
  // Test seam: materialize an in-memory file through a temp path-less host.
137
125
  const tmp = path.join(process.env.TMPDIR ?? "/tmp", `native-core-${process.pid}-${Math.random().toString(36).slice(2)}.ts`);
138
126
  fs.writeFileSync(tmp, source);
139
127
  try {
140
- return transpileFile(tmp, options);
128
+ return checkFile(tmp, options);
141
129
  } finally {
142
130
  fs.unlinkSync(tmp);
143
131
  }
@@ -1323,7 +1323,7 @@ export class IntInference {
1323
1323
  // comparisons against proven/demanded integer sides. Comparison-origin
1324
1324
  // demand never claims a host-boundary slot, nor any slot a host-boundary
1325
1325
  // slot feeds: the comparison itself does not require an integer (the
1326
- // emitter widens the integer side into f64 instead), and an i64-claimed
1326
+ // integer side widens into f64 instead), and an i64-claimed
1327
1327
  // exported signature would truncate host f64 values that node compares
1328
1328
  // exactly — claiming only part of such a chain would manufacture an
1329
1329
  // NS1016 conflict out of thin air. Genuine demand chains (index,
@@ -1,11 +1,16 @@
1
1
  // The TypedAst seam — the ONLY file that imports the type-checker provider.
2
2
  //
3
- // The transpiler needs resolved types (union discrimination, literal types,
3
+ // The frontend needs resolved types (union discrimination, literal types,
4
4
  // readonly-ness, symbol resolution, contextual types) but must not couple to
5
- // a particular checker API: today the provider is the `@typescript/typescript6`
6
- // compat package (same checker semantics as the author-facing TS7 tsc by
7
- // upstream design); when the stable Go-native programmatic API ships, only
8
- // this adapter changes.
5
+ // a particular checker API: today the provider is the `@typescript/old`
6
+ // alias (the 6.x compiler line). It powers the TEACHINGS; the
7
+ // author-facing typecheck VERDICT comes from the pinned external core
8
+ // compiler itself, which `native check` runs as its final pass
9
+ // (scripts/compiler_typecheck.mjs) — check and build judge with one
10
+ // compiler. The Go-native 7.x line ships no in-process API (its
11
+ // programmatic surface is an out-of-process protocol, still marked
12
+ // unstable); when a stable in-process-equivalent API exists, only this
13
+ // adapter changes.
9
14
  //
10
15
  // Surface discipline:
11
16
  // - Syntax (node kinds, tree walking) passes through as `ts` — syntax trees
@@ -13,16 +18,12 @@
13
18
  // - Every TYPE question goes through the named queries on `TypedAst` below.
14
19
  // Checker/emitter code never touches `program.getTypeChecker()` directly.
15
20
 
16
- // The IMPORT deliberately bypasses the `@typescript/typescript6` wrapper
17
- // (which stays the declared dependency — it is the provider named above,
18
- // and its own dependency IS this alias): the wrapper's lib/typescript.js
19
- // re-exports "@typescript/old" resolved from the WRAPPER's location, so a
20
- // consumer tree already carrying a conflicting hoisted @typescript/old
21
- // would win node's nearest-wins walk there while our exactly pinned copy
22
- // sat nested and unused. Importing the alias directly resolves it from
23
- // THIS file — inside our package, where our own nested/hoisted exact pin
24
- // is always the nearest — and the CLI's resolution gate additionally
25
- // verifies the resolved version against the pin.
21
+ // The IMPORT resolves the alias from THIS file — inside our package,
22
+ // where our own nested/hoisted exact pin is always the nearest in node's
23
+ // walk — so a consumer tree carrying a conflicting hoisted
24
+ // @typescript/old can never shadow the pinned compiler; the CLI's
25
+ // resolution gate additionally verifies the resolved version against the
26
+ // pin.
26
27
  import tsImpl from "@typescript/old";
27
28
  import path from "node:path";
28
29
  import { fileURLToPath } from "node:url";
@@ -0,0 +1,79 @@
1
+ // Wyhash (the final version, as Zig's std.hash.Wyhash implements it),
2
+ // one-shot form. The contract sidecar's synthesized identity fields hash
3
+ // the reflected surface with this function so the frontend-emitted
4
+ // document and the extraction-path document agree byte for byte on
5
+ // identical surfaces (tools/corewire/extract.zig hashes the same bytes
6
+ // with std.hash.Wyhash). BigInt-based: the transpiler is a build-time
7
+ // tool and the inputs are small.
8
+
9
+ const M64 = (1n << 64n) - 1n;
10
+
11
+ const SECRET = [0xa0761d6478bd642fn, 0xe7037ed1a0b428dbn, 0x8ebc6af09c88c6e3n, 0x589965cc75374cc3n] as const;
12
+
13
+ function mix(aIn: bigint, bIn: bigint): bigint {
14
+ const x = (aIn & M64) * (bIn & M64);
15
+ return (x & M64) ^ ((x >> 64n) & M64);
16
+ }
17
+
18
+ /// Little-endian read of `n` bytes at `offset`.
19
+ function read(data: Uint8Array, offset: number, n: number): bigint {
20
+ let v = 0n;
21
+ for (let i = n - 1; i >= 0; i--) v = (v << 8n) | BigInt(data[offset + i]);
22
+ return v;
23
+ }
24
+
25
+ export function wyhash(seed: bigint, input: Uint8Array): bigint {
26
+ const len = input.length;
27
+ const state = new Array<bigint>(3);
28
+ state[0] = (seed ^ mix(seed ^ SECRET[0], SECRET[1])) & M64;
29
+ state[1] = state[0];
30
+ state[2] = state[0];
31
+ let a = 0n;
32
+ let b = 0n;
33
+
34
+ if (len <= 16) {
35
+ if (len >= 4) {
36
+ const end = len - 4;
37
+ const quarter = (len >> 3) << 2;
38
+ a = ((read(input, 0, 4) << 32n) | read(input, quarter, 4)) & M64;
39
+ b = ((read(input, end, 4) << 32n) | read(input, end - quarter, 4)) & M64;
40
+ } else if (len > 0) {
41
+ a = (BigInt(input[0]) << 16n) | (BigInt(input[len >> 1]) << 8n) | BigInt(input[len - 1]);
42
+ b = 0n;
43
+ }
44
+ } else {
45
+ let i = 0;
46
+ if (len >= 48) {
47
+ while (i + 48 < len) {
48
+ for (let j = 0; j < 3; j++) {
49
+ const x = read(input, i + 8 * (2 * j), 8);
50
+ const y = read(input, i + 8 * (2 * j + 1), 8);
51
+ state[j] = mix(x ^ SECRET[j + 1], y ^ state[j]);
52
+ }
53
+ i += 48;
54
+ }
55
+ state[0] = state[0] ^ state[1] ^ state[2];
56
+ }
57
+ // The tail: 16-byte lanes relative to the last block start, then the
58
+ // final 16 bytes of the WHOLE input.
59
+ let k = i;
60
+ while (k + 16 < len) {
61
+ state[0] = mix(read(input, k, 8) ^ SECRET[1], read(input, k + 8, 8) ^ state[0]);
62
+ k += 16;
63
+ }
64
+ a = read(input, len - 16, 8);
65
+ b = read(input, len - 8, 8);
66
+ }
67
+
68
+ a = a ^ SECRET[1];
69
+ b = b ^ state[0];
70
+ const x = (a & M64) * (b & M64);
71
+ a = x & M64;
72
+ b = (x >> 64n) & M64;
73
+ return mix(a ^ SECRET[0] ^ BigInt(len), b ^ SECRET[1]);
74
+ }
75
+
76
+ /// The sidecar's identity spelling: 16 lowercase hex digits.
77
+ export function wyhashHex(seed: bigint, input: Uint8Array): string {
78
+ return wyhash(seed, input).toString(16).padStart(16, "0");
79
+ }
@@ -182,7 +182,7 @@ Automation drives the native path honestly: snapshots list every widget's declar
182
182
  | `icon` | vector icon leaf | `name` picks the icon: a bare literal is a curated built-in stroke icon (compile-checked; 49 names: search, plus, x, x-circle, check, check-circle, chevron-up/down/left/right, arrow-up/down/right, menu, panel-left, panel-right, settings, terminal, wrench, trash, edit, copy, external-link, play, pause, skip-back/forward, shuffle, repeat, music, volume, info, alert, download, save, folder, folder-open, file-text, sun, moon, eye, clock, git-pull-request, git-merge, git-branch, circle-dot, archive, refresh-cw, send); `app:<name>` reaches an icon the app registered at boot with `canvas.icons.registerAppIcons` (declare the table as `pub const app_icons` on the app root so `native check` verifies the name against the model contract), and one `{binding}` defers the choice to model data - an unknown resolved name draws the missing-icon fallback (a slashed circle) with a Debug warning naming the value, never a silent gap; tint with `foreground`, size with `width`/`height` |
183
183
  | `media-surface` | media surface leaf | composites a texture produced OUTSIDE the widget tree (video decoder, camera, an external renderer like mpv) into the layout like any widget — clipped, z-ordered, rounded. `surface="{binding}"` (required) binds the model-owned u64 surface id a Zig-tier producer targets (`runtime.acquireMediaSurfaceProducer` pushes RGBA8 frames, latest-wins, paced by the presented-frame clock; 0 = unbound, draws nothing; usable ids are nonzero values below the reserved bit 63). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content). Texture contents are presentation chrome: goldens, reference screenshots, and session replay show the deterministic id-derived placeholder, never producer frames |
184
184
  | `image` | runtime image leaf | draws a RUNTIME-REGISTERED image by its model-owned u64 ImageId — the id `Cmd.imageLoad` (TS) or `fx.loadImage`/`fx.registerImageBytes` (Zig) registered pixels under. `image="{binding}"` (required) binds a model field/fn; ids are model data, never markup literals, and 0 draws nothing (store the id only when the load reports loaded — see the Images section). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content) |
185
- | `code` | bare highlighted source/editor | `source="{binding}"` (required) provides source text and `language="tsx"` selects a literal lexer name; the component supplies no background, border, radius, shadow, or padding, so wrap it in a panel/card when chrome is wanted. It is read-only by default; `editable on-input="edit"` opts into multiline editing while retaining highlighting. It wraps by default, `line-numbers` opts into logical line numbers, and `wrap="false"` preserves lines inside one horizontal scroll region. HTML-family highlighting distinguishes HTML/XML/SVG and JSX/TSX tags, attributes, strings, comments, and embedded expressions. Zig builder: `ui.code(CodeOptions, source)` |
185
+ | `code` | bare highlighted source/editor | `source="{binding}"` (required) provides source text and `language="tsx"` selects a literal lexer name; the component supplies no background, border, radius, shadow, or padding, so wrap it in a panel/card when chrome is wanted. It is read-only by default; `editable on-input="edit"` opts into multiline editing while retaining highlighting. It wraps by default, `line-numbers` opts into logical line numbers, `added-lines="5"` / `removed-lines="2-4"` add Geist-style diff rows without changing copied source, and `wrap="false"` preserves lines inside one horizontal scroll region. HTML-family highlighting distinguishes HTML/XML/SVG and JSX/TSX tags, attributes, strings, comments, and embedded expressions. Zig builder: `ui.code(CodeOptions, source)` |
186
186
  | `markdown` | rendered markdown subtree | leaf; `source` is one `{binding}` — see "Markdown in markup" |
187
187
  | `stepper` > `step` | composite stage track | `active="{index}"` (required) derives each step's completed/active/pending state; steps are text leaves (no attributes) joined by connectors; stepper also takes `key`, `global-key`, `label` |
188
188
  | `timeline` > `timeline-item` | composite ledger list | items only inside a timeline (for/if fine); items are leaves — `title` (required), `description`, `meta`, `indicator`, `variant`, `connector="false"` on the last item, `selected`; `on-press` makes the whole item pressable with a trailing chevron |
@@ -974,6 +974,7 @@ Bare source-bound highlighted content shared with Markdown fences:
974
974
 
975
975
  ```html
976
976
  <code source="{snippet}" language="tsx" line-numbers wrap="false" width="480" label="Component source" />
977
+ <code source="{migration}" language="javascript" line-numbers added-lines="5" removed-lines="2-4" wrap="false" width="480" label="Configuration migration" />
977
978
  ```
978
979
 
979
980
  - `source` is one required `{binding}` producing `[]const u8`; the element has no children.
@@ -982,7 +983,8 @@ Bare source-bound highlighted content shared with Markdown fences:
982
983
  - Code is selectable/read-only by default. Add `editable on-input="edit"` to use the multiline editor path; the message carries `canvas.TextInputEvent`, so apply it to the same model-owned `TextBuffer` that supplies `source`. Editing retains syntax highlighting and does not add textarea chrome.
983
984
  - Wrapping is on by default. `wrap="false"` keeps logical lines intact inside one horizontal scroll region. A definite `height` makes overflow scroll vertically; with wrapping off, that constrained region scrolls on both axes.
984
985
  - `line-numbers` is off by default. Wrapped logical lines stay paired with their number. Numbered mode is limited to 128 logical lines and a reserved share of the per-view node and text-span budgets; sources that exceed any bound preserve all code and omit the gutter.
985
- - Zig builder: `ui.code(.{ .language = .html, .editable = true, .on_input = Ui.inputMsg(.edit), .line_numbers = true, .wrap = false }, model.snippet)`. Omit `editable`/`on_input` for read-only code. The public lexer helpers are under `native_sdk.canvas.code`.
986
+ - `added-lines` and `removed-lines` take one-based comma lists/inclusive ranges up to line 128 (`"2-4, 7"`) or one text binding in that form. They apply Geist's full-width green/red washes and renderer-owned `+`/`-`; the markers never enter source, selection, editing, or clipboard bytes. A line cannot be both added and removed. Read-only sources longer than 128 lines preserve all code and omit diff decoration.
987
+ - Zig builder: `ui.code(.{ .language = .html, .editable = true, .on_input = Ui.inputMsg(.edit), .line_numbers = true, .added_lines = &.{5}, .removed_lines = &.{ 2, 3, 4 }, .wrap = false }, model.snippet)`. Omit `editable`/`on_input` for read-only code. The public lexer helpers are under `native_sdk.canvas.code`.
986
988
 
987
989
  ## Markdown in markup: `<markdown>`
988
990