@nudojs/core 1.2.2 → 1.4.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.
@@ -0,0 +1,769 @@
1
+ import * as _babel_types from '@babel/types';
2
+ import { Node, ImportDeclaration, File } from '@babel/types';
3
+
4
+ /** 项(Term):抽象值的身份。字面量是项的特例。 */
5
+ type LiteralValue = string | number | boolean | bigint | null | undefined;
6
+ type Term = {
7
+ op: "lit";
8
+ value: LiteralValue;
9
+ } | {
10
+ op: "var";
11
+ id: string;
12
+ } | {
13
+ op: "app";
14
+ fn: string;
15
+ args: Term[];
16
+ };
17
+ declare const lit: (value: LiteralValue) => Term;
18
+ declare const v: (id: string) => Term;
19
+ declare const app: (fn: string, args: Term[]) => Term;
20
+ declare function termEquals(a: Term, b: Term): boolean;
21
+ declare function termToString(t: Term): string;
22
+ /** 常量折叠 + 简单代数化简 */
23
+ declare function simplifyTerm(t: Term): Term;
24
+
25
+ /** 约束(Pred):附着在项上的事实,可传播。 */
26
+
27
+ type PrimName = "number" | "string" | "boolean" | "bigint" | "symbol";
28
+ /** JS `typeof` 完整结果域(8 标签)。Pred 的 typeof 节点用此域。 */
29
+ type TypeofName = "undefined" | "object" | "boolean" | "number" | "bigint" | "string" | "symbol" | "function";
30
+ /** typeof 标签全集(否定展开用;顺序稳定) */
31
+ declare const TYPEOF_NAMES: readonly TypeofName[];
32
+ /** abs prim 标签 → typeof 标签(恒等嵌入)。abs prim 仍是 PrimName 子集。 */
33
+ declare function primToTypeof(p: PrimName): TypeofName;
34
+ type Pred = {
35
+ op: "true";
36
+ } | {
37
+ op: "false";
38
+ } | {
39
+ op: "eq";
40
+ a: Term;
41
+ b: Term;
42
+ } | {
43
+ op: "ne";
44
+ a: Term;
45
+ b: Term;
46
+ } | {
47
+ op: "lt";
48
+ a: Term;
49
+ b: Term;
50
+ } | {
51
+ op: "le";
52
+ a: Term;
53
+ b: Term;
54
+ } | {
55
+ op: "gt";
56
+ a: Term;
57
+ b: Term;
58
+ } | {
59
+ op: "ge";
60
+ a: Term;
61
+ b: Term;
62
+ } | {
63
+ op: "and";
64
+ args: Pred[];
65
+ } | {
66
+ op: "or";
67
+ args: Pred[];
68
+ } | {
69
+ op: "not";
70
+ arg: Pred;
71
+ } | {
72
+ op: "typeof";
73
+ t: Term;
74
+ type: TypeofName;
75
+ }
76
+ /**
77
+ * 显式有限证据:t 是有限数(非 NaN/±Inf)。
78
+ * 在场时允许线性环化简(x-x=0、k*(x+y) 分配等);
79
+ * 默认关闭——无此谓词(或由 typeof=number + 双侧有限界自动导出)时
80
+ * 仍 fail-closed,与 BUG-001 / DEC-007A 口径一致。
81
+ */
82
+ | {
83
+ op: "assumeFinite";
84
+ t: Term;
85
+ };
86
+ declare const pTrue: Pred;
87
+ declare const pFalse: Pred;
88
+ declare const eq: (a: Term, b: Term) => Pred;
89
+ declare const ne: (a: Term, b: Term) => Pred;
90
+ declare const lt: (a: Term, b: Term) => Pred;
91
+ declare const le: (a: Term, b: Term) => Pred;
92
+ declare const gt: (a: Term, b: Term) => Pred;
93
+ declare const ge: (a: Term, b: Term) => Pred;
94
+ declare const ptypeof: (t: Term, type: TypeofName) => Pred;
95
+ /** 显式有限证据:t 为有限数(非 NaN/±Inf),开启线性环化简 */
96
+ declare const assumeFinite: (t: Term) => Pred;
97
+ declare function and(...preds: Pred[]): Pred;
98
+ declare function or(...preds: Pred[]): Pred;
99
+ declare function not(p: Pred): Pred;
100
+ /**
101
+ * 逻辑否定(De Morgan):¬(A∧B)=¬A∨¬B;¬(A∨B)=¬A∧¬B;双重否定消去。
102
+ * typeof 否定展开为其余 TypeofName 标签的析取——8 标签域是 JS typeof 的
103
+ * 完整结果域,展开健全且相对完备。
104
+ *
105
+ * 关系比较(lt/le/gt/ge)的否定 **不是** 全序对偶:JS 里 NaN 参与时
106
+ * 全部关系为 false,故 ¬(x<5) 真而 x≥5 假。精确否定是 not(lt);
107
+ * 正向全序事实(Φ ⊢ x≥5 ⇒ x<5 为假)仍由 totalOrderDual 处理。
108
+ * eq↔ne 是精确否定,不受 NaN 影响。
109
+ */
110
+ declare function negatePred(p: Pred): Pred;
111
+ declare function predEquals(a: Pred, b: Pred): boolean;
112
+ declare function predToString(p: Pred): string;
113
+ /** 把 pred 里的 Term 用 subst 替换(用于 bound 变量重命名等) */
114
+ declare function substPred(p: Pred, subst: (t: Term) => Term): Pred;
115
+ /** 收集 pred 中出现的自由变量 */
116
+ declare function predVars(p: Pred): Set<string>;
117
+ /** 约束环境 Φ:Pred 的合取 */
118
+ type Phi = Pred;
119
+ declare const emptyPhi: Phi;
120
+ declare const phiAnd: typeof and;
121
+ /**
122
+ * 外部蕴含 oracle(可选 SMT 等)。内建判定证不出时调用。
123
+ * 返回 true=可证;false/undefined=仍不可证(保持 fail-closed)。
124
+ * 默认无 oracle——纯内建区间/线性判定,不引入 solver 依赖。
125
+ */
126
+ type ImplicationOracle = (phi: Phi, pred: Pred) => boolean | undefined;
127
+ declare function setImplicationOracle(fn: ImplicationOracle | undefined): void;
128
+ declare function getImplicationOracle(): ImplicationOracle | undefined;
129
+ /** 简单蕴含:在区间/线性/字面量/typeof 可判定范围内判断 Φ ⊢ pred */
130
+ declare function implies(phi: Phi, pred: Pred): boolean;
131
+ /** 便捷:数字下界 */
132
+ declare function gtNum(term: Term, n: number): Pred;
133
+ declare function geNum(term: Term, n: number): Pred;
134
+ declare function ltNum(term: Term, n: number): Pred;
135
+ declare function leNum(term: Term, n: number): Pred;
136
+
137
+ /** 抽象值 Abs = 形状 × 项 × 约束 × 置信度 */
138
+
139
+ type Confidence = "exact" | "path" | "widened" | "mock" | "partial" | "opaque";
140
+ type Shape = {
141
+ k: "never";
142
+ }
143
+ /**
144
+ * any:JS 里可以是任意值(无约束参数)。
145
+ * 运算按真实 JS 语义取并集,不是「分析失败」。
146
+ */
147
+ | {
148
+ k: "any";
149
+ }
150
+ /** unknown:分析拿不到信息(求值失败/泄漏),不是「任意值」 */
151
+ | {
152
+ k: "unknown";
153
+ } | {
154
+ k: "prim";
155
+ type: PrimName;
156
+ } | {
157
+ k: "obj";
158
+ slots: Record<string, {
159
+ value: Abs;
160
+ optional?: boolean;
161
+ readonly?: boolean;
162
+ }>;
163
+ index?: {
164
+ key: Abs;
165
+ value: Abs;
166
+ };
167
+ open?: boolean;
168
+ } | {
169
+ k: "arr";
170
+ element: Abs;
171
+ } | {
172
+ k: "tuple";
173
+ elements: Abs[];
174
+ rest?: Abs;
175
+ /** 已删除下标(delete a[i] / 字面量空洞):读值为 undefined,`in` 判定 false */
176
+ holes?: number[];
177
+ } | {
178
+ k: "fn";
179
+ params: string[];
180
+ name?: string;
181
+ paramTypes?: Abs[];
182
+ returnType?: Abs;
183
+ /**
184
+ * Dual-facet globals (Number/Array/…): callable AND carries static members.
185
+ * `$get` reads these before falling back to Function.prototype names.
186
+ */
187
+ slots?: Record<string, {
188
+ value: Abs;
189
+ optional?: boolean;
190
+ readonly?: boolean;
191
+ }>;
192
+ } | {
193
+ k: "brand";
194
+ name: string;
195
+ shape: Abs;
196
+ } | {
197
+ k: "eff";
198
+ eff: "promise" | "generator";
199
+ inner: Abs;
200
+ } | {
201
+ k: "sum";
202
+ members: Abs[];
203
+ };
204
+ type Abs = {
205
+ shape: Shape;
206
+ term?: Term;
207
+ pred?: Pred;
208
+ conf: Confidence;
209
+ /**
210
+ * C2.4:分支 join 可解释标注(如 `join(number | string)`)。
211
+ * 仅展示用:不进 leq / 指纹 / check 等价;formatAbs 读取。
212
+ */
213
+ pathNote?: string;
214
+ };
215
+ declare const never: Abs;
216
+ /** 分析无信息 */
217
+ declare const unknown: Abs;
218
+ /**
219
+ * 无约束 JS 值(未标注入口参数 / 显式 any())。
220
+ * ≠ unknown:unknown 表示引擎推导失败,any 表示开发者未写契约。
221
+ */
222
+ declare const anyAbs: Abs;
223
+ /** 带 term 的 any(generalize type-var) */
224
+ declare function anyVar(id: string, conf?: Confidence): Abs;
225
+ declare function num(): Abs;
226
+ declare function str(): Abs;
227
+ declare function bool(): Abs;
228
+ declare function numLit(value: number): Abs;
229
+ declare function strLit(value: string): Abs;
230
+ declare function boolLit(value: boolean): Abs;
231
+ declare function bigintLit(value: bigint): Abs;
232
+ /** 带项的符号数,例如参数 x */
233
+ declare function numVar(id: string, pred?: Pred, conf?: Confidence): Abs;
234
+ declare function obj(slots: Record<string, {
235
+ value: Abs;
236
+ optional?: boolean;
237
+ }>): Abs;
238
+ declare function confJoin(a: Confidence, b: Confidence): Confidence;
239
+ declare function absToString(a: Abs): string;
240
+ declare function shapeToString(s: Shape): string;
241
+ /** 从 term 反推 prim shape */
242
+ declare function shapeOfTerm(t: Term): Shape;
243
+ /** 构造带项的结果 Abs;pred 相对 term */
244
+ declare function abs(shape: Shape, term: Term | undefined, pred: Pred | undefined, conf: Confidence): Abs;
245
+ declare function isNumPrim(a: Abs): boolean;
246
+ declare function isStrPrim(a: Abs): boolean;
247
+ declare function isBigPrim(a: Abs): boolean;
248
+ /** 置信度:字面量全确定 */
249
+ declare function isExactLit(a: Abs): boolean;
250
+ /**
251
+ * tagged result:把「无字面量」与「字面量 undefined」分开。
252
+ * 判定是否是字面量必须看 `ok`,禁止用 `value !== undefined` / `(litValue(...).ok ? litValue(...).value : undefined) !== undefined`。
253
+ */
254
+ type LitValueResult = {
255
+ ok: true;
256
+ value: LiteralValue;
257
+ } | {
258
+ ok: false;
259
+ };
260
+ declare function litValue(a: Abs): LitValueResult;
261
+
262
+ /**
263
+ * may-throw 效果收集(design-cli-semantics §3.3)。
264
+ * any/nullish 成员访问等危险操作记录 throws 域,不立刻 hard-fail 求值。
265
+ * Collector/tryFrames 经 AsyncLocalStorage 会话隔离,避免 LSP 并发串档。
266
+ */
267
+
268
+ type MayThrowEffect = {
269
+ /** throws 类型名,如 TypeError */
270
+ kind: string;
271
+ /** 人类可读成因 */
272
+ cause: string;
273
+ /** 接收者展示:any / null / undefined / number… */
274
+ recv?: string;
275
+ /** 成员名 */
276
+ name?: string;
277
+ line?: number;
278
+ column?: number;
279
+ };
280
+ /** 隔离一次分析的 may-throw 收集(check / analyzer 入口包一层) */
281
+ declare function runWithMayThrowSession<T>(body: () => T): T;
282
+ declare function setMayThrowCollector(c: ((e: MayThrowEffect) => void) | null): void;
283
+ declare function getMayThrowCollector(): ((e: MayThrowEffect) => void) | null;
284
+ declare function pushMayThrowFrame(): void;
285
+ /**
286
+ * 弹出 try 帧。discard=true(catch 消化)时返回空;否则返回帧内效果供上浮。
287
+ */
288
+ declare function popMayThrowFrame(discard: boolean): MayThrowEffect[];
289
+ /**
290
+ * 孤儿 soft 效果上浮:若仍有外层 try 帧则并入外层(nested try + outer catch);
291
+ * 否则交给 collector。不得在栈非空时直接 flush,否则 outer catch 被旁路。
292
+ */
293
+ declare function orphanMayThrowEffects(effects: MayThrowEffect[]): void;
294
+ /** evaluator:try 开始时压 soft 帧 */
295
+ declare function $tryMarkSoft(): void;
296
+ /** evaluator catch 消化 try 内 soft may-throw */
297
+ declare function $tryDigestSoft(): void;
298
+ /** evaluator 无 handler / 出口 / rethrow:上浮未消化 soft may-throw(外层 try 可再消化) */
299
+ declare function $tryReleaseSoft(): MayThrowEffect[];
300
+ declare function flushMayThrowEffects(effects: MayThrowEffect[]): void;
301
+ declare function recordMayThrow(e: MayThrowEffect): void;
302
+ /** throws 类型名 → Abs(brand Error 形态,formatShape 打出名字) */
303
+ declare function errorTypeAbs(name: string): Abs;
304
+ /** 效果集 → throws Abs(never = 无 may-throw) */
305
+ declare function mayThrowEffectsToAbs(effects: MayThrowEffect[]): Abs;
306
+ /**
307
+ * throws Abs → 展示名(TypeError / TypeError | RangeError)。
308
+ * 非 brand/sum 时按 Abs 形状给出可运行时名,不再一律 "Error"。
309
+ */
310
+ declare function formatThrowsAbs(t: Abs | undefined): string | undefined;
311
+ /** JS Error 家族:`@nudo:throws Error` 覆盖全部子类(与 instanceof 语义一致) */
312
+ declare const ERROR_FAMILY: Set<string>;
313
+ /** throws Abs → kind 名列表(sum 拆臂;绝不把 `"A | B"` 当单个 kind) */
314
+ declare function throwAbsToKinds(t: Abs | undefined): string[];
315
+ /** declared/ignore 条目是否盖住 kind(`Error` 盖 Error 家族;`*` 由调用方先判) */
316
+ declare function throwsKindCovered(kind: string, names: readonly string[]): boolean;
317
+ /** effects 是否被 ignore 列表吞掉(kind 或 Error 族) */
318
+ declare function isThrowsIgnored(kind: string, ignore: readonly string[] | undefined): boolean;
319
+ /**
320
+ * L2 throws 过滤(口径固定):
321
+ * 1. **declare 优先**(@nudo:throws / case !! throws / sidecar fn.throws)——有意 fail-fast;
322
+ * 2. ignoreThrows 其次——迁移期全类放行,**不是**声明的替代品。
323
+ */
324
+ declare function filterGateThrows(effects: MayThrowEffect[], declared: readonly string[] | "*" | undefined, ignore: readonly string[] | undefined): MayThrowEffect[];
325
+ /** effects 过滤后的剩余(L2 --ignore-throws) */
326
+ declare function filterIgnoredThrows(effects: MayThrowEffect[], ignore: readonly string[] | undefined): MayThrowEffect[];
327
+ /**
328
+ * 申报式抛错过滤(@nudo:throws / case !! throws / sidecar fn.throws)。
329
+ * `*` = 全部申报,L2 清空;数组 = kind 或 Error 族覆盖。
330
+ * 申报 ≠ ignoreThrows:前者是「这是有意 fail-fast」,后者是「迁移期先别管」。
331
+ */
332
+ declare function filterDeclaredThrows(effects: MayThrowEffect[], declared: readonly string[] | "*" | undefined): MayThrowEffect[];
333
+
334
+ /**
335
+ * 调用 Abs 一等函数(absFunction impl)或 mock apply。
336
+ * 供 求值引擎 import 绑定包装:`(...args) => $call(absFn, args)`。
337
+ *
338
+ * 统一顺序:apply → body → relation → isRelFn(委托 applyAbsFn)。
339
+ * 行为对齐说明(与旧 $call 的差异,均属刻意):
340
+ * 1. 带 body 的函数也进 call-budget(递归会 truncated 而非爆栈)
341
+ * 2. body 抛错与 apply 同径 rethrow(不吞成 never 返回,调用边界决定吸收)
342
+ * 3. 无 impl 时 isRelFn 可走 E 路径(旧版恒 unknown)
343
+ */
344
+
345
+ /** 清空 pure memo(宿主入口 / 会话缓存失效) */
346
+ declare function clearPureMemo(): void;
347
+ /**
348
+ * apply 返回的 throws 面 → 调用方控制流通道(H1 单点路由)。
349
+ * always-throw(abs=never)→ NudoThrow,由调用边界收成 throws;
350
+ * may-throw → pushThrowExit 记入调用方 throwExits(try/catch 可吸收)。
351
+ */
352
+ declare function routeApplyThrows(r: Abs, throws: Abs | undefined): Abs;
353
+ declare function $call(fn: Abs, args: Abs[], thisVal?: Abs): Abs;
354
+
355
+ /**
356
+ * 求值引擎调用点记录:transpile 把 `f(args)` 改成 $callNamed,
357
+ * 分析时可收集 call@ 所需的 AbsCallRecord。
358
+ * 成员缺失诊断见 member-diag.ts(共用,避免循环依赖)。
359
+ */
360
+
361
+ type EvalCallRecord = {
362
+ fnName: string;
363
+ args: Abs[];
364
+ result: Abs;
365
+ callLoc?: {
366
+ line: number;
367
+ column: number;
368
+ };
369
+ threw?: boolean;
370
+ };
371
+ /** 清空 pureCallMemo(宿主入口 / 会话缓存失效) */
372
+ declare function clearPureCallMemo(): void;
373
+ /** B 赋值记录(与 ast-records.ts AbsAssignRecord 同形;structuralAssignIssues 消费) */
374
+ type EvalAbsAssignRecord = {
375
+ name: string;
376
+ prev: Abs | undefined;
377
+ next: Abs;
378
+ line?: number;
379
+ column?: number;
380
+ conditional?: boolean;
381
+ };
382
+ /** 返回先前 collector,便于嵌套调用 save/restore(禁止 finally 置 null 砸外层) */
383
+ declare function setEvalAssignCollector(collector: ((r: EvalAbsAssignRecord) => void) | null): ((r: EvalAbsAssignRecord) => void) | null;
384
+ /** 结构赋值记录(transpile 插桩调用;无收集器时 no-op) */
385
+ declare function $assignRecord(name: string, prev: Abs | undefined, next: Abs, line: number, column: number, conditional: boolean): void;
386
+ declare function setEvalBindingSink(sink: Map<string, unknown> | null): void;
387
+ /** 顶层绑定记录(transpile 插桩调用) */
388
+ declare function $recordBinding(name: string, value: unknown): void;
389
+ /** 返回先前 collector,便于嵌套调用 save/restore(禁止 finally 置 null 砸外层) */
390
+ /** 成员/方法调用点打点($invoke 等;无收集器时 no-op)。不进 $callNamed 预算。 */
391
+ declare function noteEvalCallRecord(r: EvalCallRecord): void;
392
+ declare function setEvalCallCollector(collector: ((r: EvalCallRecord) => void) | null): ((r: EvalCallRecord) => void) | null;
393
+ declare function getEvalCallCollector(): ((r: EvalCallRecord) => void) | null;
394
+ /**
395
+ * 按名调用并记录。
396
+ * loc: [line, column](1-based line,0-based column,与 Babel 一致)
397
+ * argLocs: 与 args 对齐的实参字面量源位置(provenance;无 loc 用 null)
398
+ */
399
+ declare const MAX_EVAL_CALL_DEPTH = 64;
400
+ /** 总调用上限:与 call-budget.MAX_TOTAL_CALLS 同阀(递归×循环×分支展开的
401
+ * 规模阀)。200k 在病态展开(lodash _baseFlatten)下 ~30s,20k 收口到
402
+ * ~3s——截断 → opaque(更保守,zero-FP 安全)。 */
403
+ declare const MAX_EVAL_TOTAL_CALLS = 20000;
404
+ /** 宿主入口前强制清零(测试 / 显式 API)。执行入口请用 enterEvalCallBudgetSession。 */
405
+ declare function resetEvalCallBudget(): void;
406
+ /** @nudo:budget:在 run 期间抬高 B 路径 depth/calls 上限;finally 恢复 */
407
+ declare function withEvalBudgetOverride(budget: {
408
+ depth?: number;
409
+ calls?: number;
410
+ }, run: () => void): void;
411
+ /**
412
+ * 进入执行会话。最外层才重置预算;嵌套(导出桥 $call → apply →
413
+ * callTranspiledExportFull)必须继承外层深度/cycle 键/totalCalls,否则
414
+ * 外层帧被抹掉,$callNamed 的 evalExitCall 再把 depth 打成负数。
415
+ */
416
+ declare function enterEvalCallBudgetSession(): void;
417
+ /** 退出执行会话。禁止把 sessionDepth 留在负数。 */
418
+ declare function exitEvalCallBudgetSession(): void;
419
+ /** 预算快照(测试/诊断:断言嵌套期间 depth/keys 不被清空、depth 不为负) */
420
+ declare function getEvalCallBudgetState(): {
421
+ depth: number;
422
+ totalCalls: number;
423
+ activeKeys: number;
424
+ sessionDepth: number;
425
+ };
426
+ declare function $callNamed(name: string, fn: unknown, args: Abs[], loc?: [number, number], argLocs?: Array<[number, number] | null | undefined>): Abs;
427
+
428
+ /**
429
+ * 共享纯类型结点(AstEnv / HofCollectCtx / HofSite / RelSource)。
430
+ *
431
+ * 这些类型曾形成 ast-env ↔ hof ↔ abs-fn 的类型环(ast-env 引 HofCollectCtx,
432
+ * hof/abs-fn 引 AstEnv)。抽到本叶模块(只依赖 abs/term/babel,不回指
433
+ * ast-env/hof/abs-fn)后,三个消费方都从这里取类型,环即断。
434
+ *
435
+ * 稳定导入路径不变:ast-env.ts 重导出 AstEnv,hof.ts 重导出 HOF 三类型。
436
+ */
437
+
438
+ /**
439
+ * 关系来源标记:P4 豁免与 diagnostics 依赖它,禁止隐式猜。
440
+ * - promote:使用驱动提升(generalize symbolic / instantiate 局部)
441
+ * - refine:@nudo:contract 契约
442
+ * - relationFn:harvest/mock/测试直接写入 fnRels 时的预留来源(P4 error 路径)
443
+ */
444
+ type RelSource = "promote" | "refine" | "relationFn";
445
+ type HofSite = {
446
+ /** 形参名(函数形参) */
447
+ param: string;
448
+ /** 输入侧 term:实参的 term(element 的 var/lit/app);map 1 个、reduce 2 个 */
449
+ argTerms: Term[];
450
+ /** 输出侧:归纳出的返回 Abs */
451
+ result: Abs;
452
+ /** 源位置,便于 diagnostics */
453
+ loc?: {
454
+ line: number;
455
+ column: number;
456
+ };
457
+ };
458
+ /**
459
+ * run 局部 collector(与 Phi 并列,不进 Φ 合并)。
460
+ * symbolic 一次跑:安装并沉淀到 PolyFn;instantiate 重跑:装 throwaway
461
+ * 副本——形状提升仍生效,结果不写回共享状态(见 generalize.ts run())。
462
+ */
463
+ type HofCollectCtx = {
464
+ /** 本次归纳的形参名集合(身份判定用) */
465
+ paramNames: ReadonlySet<string>;
466
+ /** 本次 typeParams 的 α id 集合(term 复用白名单) */
467
+ alphaIds: Set<string>;
468
+ /** fresh α 计数 */
469
+ freshSeq: {
470
+ n: number;
471
+ };
472
+ sites: HofSite[];
473
+ fnRels: Map<string, {
474
+ abs: Abs;
475
+ source: RelSource;
476
+ }>;
477
+ entryShapes: Map<string, {
478
+ abs: Abs;
479
+ source: RelSource;
480
+ }>;
481
+ };
482
+ type AstEnv = {
483
+ vars: Map<string, Abs>;
484
+ /** 用户函数:name → { params, body } */
485
+ fns: Map<string, {
486
+ params: string[];
487
+ body: Node;
488
+ async?: boolean;
489
+ kind?: string;
490
+ }>;
491
+ /** class 表(旁路,withVar 必须保留) */
492
+ classes?: Map<string, unknown>;
493
+ /** 当前正在求值的方法所属类名(super.x() 从它的父类派发) */
494
+ currentOwner?: string;
495
+ /** P2:generalize symbolic 跑的 HOF collector(run 局部,不进 Φ) */
496
+ hofCollect?: HofCollectCtx;
497
+ };
498
+
499
+ /**
500
+ * Abs 上的一等函数:shape 是 fn,实现在旁路(不污染 Shape)。
501
+ * 与 term-registry 同一纪律:不给共享单例挂 impl。
502
+ */
503
+
504
+ /** Abs 原生 env/builtin 实现(evaluator 优先) */
505
+ type AbsSigImpl = (args: Abs[], thisVal?: Abs) => Abs | undefined;
506
+ /**
507
+ * 已知不抛的 apply 返回面(裸 Abs,无 throws 通道)。
508
+ * 等价 `Abs`,仅作意图标注:impl 作者写死「本 apply 不抛」时用它收窄签名,
509
+ * 调用侧仍应经 `absOnly` / `isAbsApplyResult` 取 abs(`AbsFnImpl.apply` 静态面是宽的)。
510
+ */
511
+ type AbsApplyNoThrow = Abs;
512
+ /**
513
+ * 已知不抛的 apply 实现签名(`AbsSigImpl` 的 apply 对偶)。
514
+ * 返回裸 `Abs` = 不抛;需要 throws 面时改用 `AbsFnImpl["apply"]`(`AbsApplyReturn`)。
515
+ */
516
+ type AbsApplyNoThrowFn = (args: Abs[], thisVal?: Abs) => AbsApplyNoThrow;
517
+ /**
518
+ * apply 契约返回的 throws 通道(H1 / DESIGN-003)。
519
+ * `throws` 必填:不抛传 `never`。$call 统一路由——
520
+ * always-throw(abs=never)→ NudoThrow 由调用边界收成 throws;
521
+ * may-throw → pushThrowExit 记入调用方 throwExits(try/catch 可吸收)。
522
+ * 包装 `callTranspiledExportFull` 必须走 `callTranspiledExportApply`,
523
+ * 不得手拆 `.result`(会静默丢 throws 面)。
524
+ *
525
+ * 构造只经 `makeAbsApplyResult`(打上 brand);`isAbsApplyResult` 只认 brand,
526
+ * 避免裸对象靠 `!shape` 误判成 apply 结果、吞掉 throws 面。
527
+ */
528
+ type AbsApplyResult = {
529
+ abs: Abs;
530
+ throws: Abs;
531
+ /** Discriminator stamped by makeAbsApplyResult. */
532
+ readonly applyResult: true;
533
+ };
534
+ /** apply 可返回裸 Abs(无 throws)或带 throws 通道的 AbsApplyResult */
535
+ type AbsApplyReturn = Abs | AbsApplyResult;
536
+ /** 唯一构造入口:打上 applyResult brand。 */
537
+ declare function makeAbsApplyResult(abs: Abs, throws: Abs): AbsApplyResult;
538
+ /** AbsApplyResult 判别:只认 brand(不靠 !shape 结构猜)。 */
539
+ declare function isAbsApplyResult(v: AbsApplyReturn): v is AbsApplyResult;
540
+ /**
541
+ * apply 返回值取 abs 面(已知不抛 / 测试面只想看结果时用)。
542
+ * 丢弃 throws 通道——若 impl 可能抛,必须走 `$call` 统一路由,不得用本函数吞 throws。
543
+ */
544
+ declare function absOnly(r: AbsApplyReturn): AbsApplyNoThrow;
545
+ type AbsFnImpl = {
546
+ params: string[];
547
+ /** 可选:无 body 时走 relation(纯关系 fn) */
548
+ body?: Node;
549
+ async?: boolean;
550
+ /** 声明时捕获的环境(闭包) */
551
+ env?: AstEnv;
552
+ kind?: string;
553
+ /**
554
+ * 调用时直接派发(mock withArgs 等),优先于 body。
555
+ * 返回裸 Abs = 不抛;返回 AbsApplyResult 时 throws 面经 $call 统一路由,
556
+ * 不得在 apply 内自行 re-throw / pushThrowExit(会与 $call 路由叠算)。
557
+ */
558
+ apply?: (args: Abs[], thisVal?: Abs) => AbsApplyReturn;
559
+ /**
560
+ * 对象方法(ObjectMethod / 方法型 FunctionExpression):$invoke 时把
561
+ * receiver 作为 apply 的**首参**注入。shape.params 仍是用户可见形参
562
+ * (不含 receiver),自由调用不注入 → this 为 unbound(JS 语义)。
563
+ */
564
+ bindThis?: boolean;
565
+ /**
566
+ * Optional content key for cache fingerprints. formatAbs cannot see
567
+ * WeakMap-side mock semantics (returns/withArgs/callsFake), so hosts that
568
+ * build mocks should stamp a stable fingerprint here.
569
+ * relation-only 必填(未传时 relationFn 自动生成)。
570
+ */
571
+ fingerprint?: string;
572
+ /** 无 body 时,按 paramTypes 做 α 替换得到返回 */
573
+ relation?: {
574
+ paramTypes: Abs[];
575
+ returnType: Abs;
576
+ /**
577
+ * 条件类型 infer:绑定 fromVar 后从 via 投出 inferVar
578
+ * (`T extends (infer E)[]` → via: "arr";`T extends Promise<infer U>` → "promise")。
579
+ */
580
+ inferFrom?: {
581
+ fromVar: string;
582
+ via: "arr" | "promise";
583
+ inferVar: string;
584
+ };
585
+ /** extends 不成立时的假分支(如 never) */
586
+ condFallback?: Abs;
587
+ };
588
+ /** `@nudo:pure`:调用结果按实参记忆化(无副作用契约) */
589
+ pureName?: string;
590
+ };
591
+ declare function attachFnImpl(a: Abs, impl: AbsFnImpl): void;
592
+ declare function getFnImpl(a: Abs): AbsFnImpl | undefined;
593
+ /** 标记纯函数(@nudo:pure):调用结果可按实参记忆化 */
594
+ declare function markPureFn(target: object, name: string): void;
595
+ /** 读纯函数标记(Abs impl 或对象属性 `_memoize`) */
596
+ declare function pureFnNameOf(fn: unknown): string | undefined;
597
+ /** 造一个带实现的 Abs 函数值 */
598
+ declare function absFunction(params: string[], impl: Omit<AbsFnImpl, "params">, opts?: {
599
+ name?: string;
600
+ paramTypes?: Abs[];
601
+ returnType?: Abs;
602
+ slots?: Record<string, {
603
+ value: Abs;
604
+ optional?: boolean;
605
+ readonly?: boolean;
606
+ }>;
607
+ conf?: Confidence;
608
+ }): Abs;
609
+ /** relationFn 稳定 fingerprint(同签名共享,见 §3.3 已知限制) */
610
+ declare function relationFingerprint(paramTypes: Abs[], returnType: Abs): string;
611
+ /**
612
+ * 无 body、纯关系的 fn Abs。params 仅记 arity。
613
+ *
614
+ * **双写纪律:** 同一份关系数据必须同时写到——
615
+ * 1. `shape.paramTypes` / `shape.returnType` —— format / leq / 展示读这里
616
+ * 2. `impl.relation` —— D 路径应用读这里
617
+ * 两槽共享同一数组/对象引用(防内容分叉);构造后请勿原地 mutate。
618
+ *
619
+ * 默认 conf="path"(与提升产物一致)。禁止静默对齐 absFunction 的 "exact"。
620
+ * fingerprint 必填(call-budget);未传时由 paramTypes+returnType 稳定序列化生成。
621
+ * 同签名 relationFn 共享 fingerprint → 共享 budget 键(见 design §3.3 已知限制)。
622
+ */
623
+ declare function relationFn(paramTypes: Abs[], returnType: Abs, opts?: {
624
+ params?: string[];
625
+ conf?: Confidence;
626
+ fingerprint?: string;
627
+ inferFrom?: {
628
+ fromVar: string;
629
+ via: "arr" | "promise";
630
+ inferVar: string;
631
+ };
632
+ condFallback?: Abs;
633
+ }): Abs;
634
+ /** 仅写 shape 槽(E 路径 / §5.2 提升产物);禁止 attachFnImpl */
635
+ declare function shapeOnlyFn(paramTypes: Abs[], returnType: Abs, opts?: {
636
+ params?: string[];
637
+ conf?: Confidence;
638
+ }): Abs;
639
+
640
+ /**
641
+ * Abs 模块面(无 fs):import 绑定 + export 收集。
642
+ * 解析路径/读文件在 host;core 只吃「specifier → 导出表」。
643
+ */
644
+
645
+ type AbsModuleExports = {
646
+ named: Record<string, Abs>;
647
+ default?: Abs;
648
+ /**
649
+ * 导出表来自成功求值(evalExportsToModuleExports)。
650
+ * fail-closed 空表 / harvest stub / env 手写表不设——missing-export 只对
651
+ * 成功求值的表报(zero-FP,避免与 module-missing 叠报)。
652
+ */
653
+ evaluated?: boolean;
654
+ };
655
+ /**
656
+ * 命名空间 Abs(`import * as ns` / `export * as ns` / CJS require 绑定):
657
+ * open + path——导出收集可能不全(CJS 收集失败等),缺失成员是分析
658
+ * 视图不完整,不得按「运行时缺失」判定(不可调用判定会假抛 TypeError)。
659
+ * 单一构造点:bindImports / run.ts namespaceAbsOf / abs-modules-graph 同口径。
660
+ */
661
+ declare function namespaceAbsOf(mod: AbsModuleExports): Abs;
662
+ /** 把 import 说明符绑定进 env(宿主已求值依赖) */
663
+ declare function bindImports(node: ImportDeclaration, env: AstEnv, modules: Record<string, AbsModuleExports>): void;
664
+ /**
665
+ * 从已求值 env + AST 收集 ESM 导出。
666
+ * 支持:export function/const、export { a, b as c }、export default(具名)、
667
+ * 以及带 source 的 re-export(`export { a } from "mod"` / `export * from "mod"` /
668
+ * `export * as ns from "mod"`——需 host 传入已求值 modules)。
669
+ */
670
+ declare function collectAbsExports(file: File, env: AstEnv, modules?: Record<string, AbsModuleExports>): AbsModuleExports;
671
+
672
+ type RunTranspiledOptions = {
673
+ /** 说明符 → 依赖导出(host 模块图或 runTranspiled 产物) */
674
+ modules?: Record<string, AbsModuleExports | Record<string, unknown>>;
675
+ maxLoopIters?: number;
676
+ /** analyze = 跳过效应性顶层语句 */
677
+ mode?: "exec" | "analyze";
678
+ /** @nudo:replace 注入值:varName → Abs */
679
+ replacements?: Record<string, Abs>;
680
+ /** @nudo:replace 匹配表:传给 transpile */
681
+ replacementTargets?: Array<{
682
+ target: string;
683
+ varName: string;
684
+ stmtStart?: number;
685
+ stmtEnd?: number;
686
+ }>;
687
+ /** @nudo:as 注入值:varName → Abs */
688
+ asOverrides?: Record<string, Abs>;
689
+ /** @nudo:as 语句范围表 */
690
+ asOverrideTargets?: Array<{
691
+ varName: string;
692
+ stmtStart: number;
693
+ stmtEnd: number;
694
+ }>;
695
+ /** @nudo:env 全局 Abs(JSON/Math/console…)→ 作用域绑定 */
696
+ envGlobals?: Record<string, Abs>;
697
+ /** @nudo:mock 注入值:name → Abs(mockDirectivesToAbsSeeds 产物) */
698
+ mocks?: Record<string, Abs>;
699
+ /** 宽松全局(调用点发现 exec 采集:未声明全局调用保守 unknown 不中断) */
700
+ lenientGlobals?: boolean;
701
+ };
702
+ /**
703
+ * inject/modules **内容**指纹(memo 键)。对象身份对「每次新建同内容」
704
+ * 的 CLI 注入不稳——同一语义的 inject 跨 checkSource 调用会 miss 缓存。
705
+ */
706
+ declare function runTranspiledOptionsMemoKey(opts: RunTranspiledOptions | undefined): string;
707
+ declare const RUNTIME_IMPORT_RE: RegExp;
708
+ declare function bindingsOf(run: Record<string, unknown>): Map<string, unknown> | undefined;
709
+ /**
710
+ * 执行一段 求值引擎程序,返回顶层 `export function` / `export const`。
711
+ */
712
+ declare function runTranspiled(source: string, opts?: RunTranspiledOptions): Record<string, unknown>;
713
+ /** evaluator 回落事件(观测单一埋点;reason: unsupported:* = 能力边界,internal = 引擎自身缺陷) */
714
+ type EvalFallback = {
715
+ reason: string;
716
+ message: string;
717
+ loc?: {
718
+ line: number;
719
+ column: number;
720
+ };
721
+ };
722
+ declare function setEvalFallbackCollector(collector: ((f: EvalFallback) => void) | null): void;
723
+ /** 表达式级求值(scan 的 case 字面量实参等静态求值面):编译单表达式经
724
+ * eval 运行时执行。bindings:表达式自由标识符 → Abs(调用方按绑定表注入)。
725
+ * 编译失败抛错(调用方按需 catch)。 */
726
+ declare function evalExprAbs(expr: _babel_types.Expression, bindings?: Record<string, Abs>): Abs;
727
+ /** 回落计数(D6-A:internal 可暴露为 health 指标,不静默吞) */
728
+ type EvalFallbackStats = {
729
+ internal: number;
730
+ unsupported: number;
731
+ moduleThrow: number;
732
+ total: number;
733
+ };
734
+ /** 始终累计(与 collector 无关)——health / 测试读同一口径 */
735
+ declare function getEvalFallbackStats(): EvalFallbackStats;
736
+ /** 宿主入口 / health 按文件分析前重置 */
737
+ declare function resetEvalFallbackStats(): void;
738
+ /** 记录一次 B 回落(body-fn / tryRunTranspiled / call 边界兜底共用) */
739
+ declare function noteEvalFallback(e: unknown): void;
740
+ /**
741
+ * B 单一入口:runTranspiled + 类型化回落观测。
742
+ * unsupported:*(能力边界)/ internal(B 缺陷)都记录到收集器;
743
+ * 返回 undefined 表示调用方应走解释路径。
744
+ */
745
+ declare function tryRunTranspiled(source: string, opts?: RunTranspiledOptions): Record<string, unknown> | undefined;
746
+ type TranspiledCallResult = {
747
+ result: Abs;
748
+ /** 非 never 表示函数可能 throw 该类型 */
749
+ throws: Abs;
750
+ };
751
+ /** 调用 runTranspiled 导出(捕获 $throw)。opts.phi:入口 Φ 种子
752
+ * (instantiate/symbolic 的约束入口——eval 侧路径条件收窄)。
753
+ * 嵌套进入(导出桥 apply)继承外层预算;仅最外层宿主入口重置。 */
754
+ declare function callTranspiledExportFull(exports: Record<string, unknown>, name: string, args: Abs[], opts?: {
755
+ phi?: Phi;
756
+ }): TranspiledCallResult;
757
+ /** 调用 runTranspiled 导出(仅结果) */
758
+ declare function callTranspiledExport(exports: Record<string, unknown>, name: string, args: Abs[]): Abs;
759
+ /**
760
+ * 包装 runTranspiled 导出为 Abs apply 钩子——throws 面经返回值通道强制保留
761
+ * (H1 / DESIGN-003)。这是包装 `callTranspiledExportFull` 的**唯一入口**:
762
+ * 返回 AbsApplyResult(`{abs, throws}`),$call 统一路由 throws。
763
+ * 手拆 `.result` 会静默丢 throws 面(BUG-006 根因)。
764
+ *
765
+ * `exports` 可传惰性 getter(互递归模块桥:导出表在桥创建后才赋值)。
766
+ */
767
+ declare function callTranspiledExportApply(exports: Record<string, unknown> | (() => Record<string, unknown>), name: string): (args: Abs[], thisVal?: Abs) => AbsApplyResult;
768
+
769
+ export { $tryDigestSoft as $, type Abs as A, runWithMayThrowSession as B, type Confidence as C, setMayThrowCollector as D, ERROR_FAMILY as E, throwAbsToKinds as F, throwsKindCovered as G, withEvalBudgetOverride as H, type HofCollectCtx as I, type HofSite as J, type AbsModuleExports as K, type LiteralValue as L, type MayThrowEffect as M, type RunTranspiledOptions as N, $assignRecord as O, type PrimName as P, $call as Q, type RelSource as R, type Shape as S, type Term as T, $callNamed as U, $recordBinding as V, type AbsApplyNoThrow as W, type AbsApplyNoThrowFn as X, type AbsApplyResult as Y, type AbsApplyReturn as Z, type AbsFnImpl as _, type Pred as a, num as a$, type AbsSigImpl as a0, type EvalAbsAssignRecord as a1, type EvalCallRecord as a2, type EvalFallback as a3, type ImplicationOracle as a4, type LitValueResult as a5, MAX_EVAL_CALL_DEPTH as a6, MAX_EVAL_TOTAL_CALLS as a7, RUNTIME_IMPORT_RE as a8, TYPEOF_NAMES as a9, geNum as aA, getEvalCallCollector as aB, getFnImpl as aC, getImplicationOracle as aD, gt as aE, gtNum as aF, implies as aG, isAbsApplyResult as aH, isBigPrim as aI, isExactLit as aJ, isNumPrim as aK, isStrPrim as aL, le as aM, leNum as aN, lit as aO, litValue as aP, lt as aQ, ltNum as aR, makeAbsApplyResult as aS, markPureFn as aT, namespaceAbsOf as aU, ne as aV, negatePred as aW, never as aX, not as aY, noteEvalCallRecord as aZ, noteEvalFallback as a_, type TranspiledCallResult as aa, type TypeofName as ab, abs as ac, absFunction as ad, absOnly as ae, absToString as af, and as ag, anyAbs as ah, anyVar as ai, app as aj, assumeFinite as ak, attachFnImpl as al, bigintLit as am, bindImports as an, bindingsOf as ao, bool as ap, boolLit as aq, callTranspiledExport as ar, callTranspiledExportApply as as, callTranspiledExportFull as at, collectAbsExports as au, confJoin as av, emptyPhi as aw, eq as ax, evalExprAbs as ay, ge as az, type Phi as b, numLit as b0, numVar as b1, obj as b2, or as b3, pFalse as b4, pTrue as b5, phiAnd as b6, predEquals as b7, predToString as b8, predVars as b9, primToTypeof as ba, ptypeof as bb, pureFnNameOf as bc, relationFingerprint as bd, relationFn as be, resetEvalCallBudget as bf, runTranspiled as bg, runTranspiledOptionsMemoKey as bh, setEvalAssignCollector as bi, setEvalBindingSink as bj, setEvalCallCollector as bk, setEvalFallbackCollector as bl, setImplicationOracle as bm, shapeOfTerm as bn, shapeOnlyFn as bo, shapeToString as bp, simplifyTerm as bq, str as br, strLit as bs, substPred as bt, termEquals as bu, termToString as bv, tryRunTranspiled as bw, unknown as bx, v as by, routeApplyThrows as bz, type AstEnv as c, $tryMarkSoft as d, $tryReleaseSoft as e, type EvalFallbackStats as f, clearPureCallMemo as g, clearPureMemo as h, enterEvalCallBudgetSession as i, errorTypeAbs as j, exitEvalCallBudgetSession as k, filterDeclaredThrows as l, filterGateThrows as m, filterIgnoredThrows as n, flushMayThrowEffects as o, formatThrowsAbs as p, getEvalCallBudgetState as q, getEvalFallbackStats as r, getMayThrowCollector as s, isThrowsIgnored as t, mayThrowEffectsToAbs as u, orphanMayThrowEffects as v, popMayThrowFrame as w, pushMayThrowFrame as x, recordMayThrow as y, resetEvalFallbackStats as z };