@native-sdk/cli 0.7.2 → 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.
- package/build/app.zig +265 -65
- package/build/ts_run.mjs +6 -8
- package/build.zig +292 -349
- package/package.json +13 -11
- package/packages/core/compile-surface/core.ts +559 -0
- package/packages/core/package-lock.json +375 -12
- package/packages/core/package.json +9 -6
- package/packages/core/scripts/compiler_typecheck.mjs +58 -0
- package/packages/core/scripts/gen_case_tables.mjs +130 -0
- package/packages/core/scripts/gen_declarations.mjs +97 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +108 -0
- package/packages/core/scripts/stage_external_core.mjs +148 -0
- package/packages/core/sdk/core.d.ts +363 -0
- package/packages/core/sdk/events.d.ts +65 -0
- package/packages/core/sdk/text.d.ts +51 -0
- package/packages/core/src/checker.ts +3 -3
- package/packages/core/src/cli.ts +40 -38
- package/packages/core/src/contract.ts +749 -0
- package/packages/core/src/devhost.ts +4 -3
- package/packages/core/src/diagnostics.ts +5 -7
- package/packages/core/src/{transpile.ts → frontend.ts} +38 -50
- package/packages/core/src/infer.ts +1 -1
- package/packages/core/src/typed_ast.ts +16 -15
- package/packages/core/src/wyhash.ts +79 -0
- package/skill-data/ts-core/SKILL.md +29 -29
- package/src/runtime/ts_core_host.zig +38 -38
- package/src/runtime/ts_ui_app.zig +12 -12
- package/src/tooling/manifest.zig +32 -0
- package/src/tooling/raw_manifest.zig +4 -0
- package/src/tooling/templates.zig +25 -20
- package/src/tooling/ts_core.zig +55 -34
- package/src/tooling/verbs.zig +1 -1
- package/tools/corewire/core_abi.zig +169 -0
- package/tools/corewire/emit.zig +2418 -0
- package/tools/corewire/emit_facade.zig +3984 -0
- package/tools/corewire/emit_profile.zig +501 -0
- package/tools/corewire/main.zig +561 -0
- package/tools/corewire/shim_rt.zig +632 -0
- package/tools/corewire/sidecar.zig +2507 -0
- package/packages/core/rt/rt.zig +0 -1986
- 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
|
|
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 —
|
|
74
|
-
//
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
-
//
|
|
2
|
-
// every module-boundary mistake), check every module with
|
|
3
|
-
// own checker (same semantics as the author-facing tsc by
|
|
4
|
-
// run the subset checker, run integer inference, then
|
|
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 {
|
|
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
|
|
18
|
-
///
|
|
19
|
-
///
|
|
20
|
-
/// (
|
|
21
|
-
readonly
|
|
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
|
|
26
|
+
export interface FrontendResult {
|
|
28
27
|
readonly ok: boolean;
|
|
29
|
-
|
|
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
|
|
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-
|
|
38
|
+
/// build-graph staleness set (a change to any of them re-checks).
|
|
38
39
|
readonly inputs: string[];
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
function
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
120
|
-
|
|
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
|
|
113
|
+
if (e instanceof ContractError) {
|
|
123
114
|
const file = e.node.getSourceFile();
|
|
124
115
|
const { line, column } = lineColumn(file, e.node.getStart());
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
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
|
|
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
|
-
//
|
|
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
|
|
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/
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
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
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
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
|
+
}
|