@nudojs/service 0.3.2 → 1.0.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.
- package/dist/chunk-2VHITMTM.js +488 -0
- package/dist/config-NqDRWWpn.d.ts +68 -0
- package/dist/evaluator/evaluator-api.d.ts +26 -0
- package/dist/evaluator/evaluator-api.js +24 -0
- package/dist/index.d.ts +294 -46
- package/dist/index.js +2823 -1641
- package/package.json +14 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Node, File } from '@babel/types';
|
|
2
|
-
import {
|
|
2
|
+
import { Abs, PolyFn, AbsModuleExports, AstEnv, Phi, BMemberDiag, BCallRecord, TranspiledCallResult, NudoConstraint } from '@nudojs/core';
|
|
3
3
|
export { AbsInlay, BMemberDiag, collectAbsInlays } from '@nudojs/core';
|
|
4
|
-
import { CallRecord } from '
|
|
5
|
-
export {
|
|
4
|
+
import { C as CallRecord } from './config-NqDRWWpn.js';
|
|
5
|
+
export { I as InterfaceConfig, N as NudoConfig, f as findProjectConfig, i as interfaceConfig, m as matchesEmitAllowlist } from './config-NqDRWWpn.js';
|
|
6
6
|
import { HarvestedEnv } from '@nudojs/harvester';
|
|
7
7
|
import { FunctionWithDirectives } from '@nudojs/parser';
|
|
8
8
|
|
|
@@ -46,18 +46,20 @@ type Diagnostic = {
|
|
|
46
46
|
};
|
|
47
47
|
type CaseResult = {
|
|
48
48
|
name: string;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
/** 无损参数 Abs */
|
|
50
|
+
argAbs: Abs[];
|
|
51
|
+
/** 无损结果 Abs */
|
|
52
|
+
abs: Abs;
|
|
53
|
+
/** 无损抛出 Abs(未抛为 never) */
|
|
54
|
+
throwsAbs: Abs;
|
|
52
55
|
throwLoc?: SourceLocation;
|
|
53
56
|
source?: "directive" | "callsite";
|
|
54
57
|
/** `@nudo:case "name" (…) => expected` — presence means the case is a test assertion */
|
|
55
|
-
expected?:
|
|
58
|
+
expected?: Abs;
|
|
56
59
|
/** number of additional call sites folded into a symbolic case */
|
|
57
60
|
aggregatedFrom?: number;
|
|
58
61
|
/**
|
|
59
62
|
* 内涵摘要(代数 generalize):无损 Abs + term/pred/conf。
|
|
60
|
-
* 仅在 entry@ / call@(Abs 路径)填充;外延 TypeValue 不变。
|
|
61
63
|
*/
|
|
62
64
|
intension?: {
|
|
63
65
|
display?: string;
|
|
@@ -69,15 +71,14 @@ type CaseResult = {
|
|
|
69
71
|
/** 无损 Abs 多行(formatAbsMultiline) */
|
|
70
72
|
absMultiline?: string;
|
|
71
73
|
};
|
|
72
|
-
/** 无损 Abs(denote/守卫用);仅 Abs 路径 case 填充 */
|
|
73
|
-
abs?: Abs;
|
|
74
74
|
};
|
|
75
75
|
type FunctionAnalysis = {
|
|
76
76
|
name: string;
|
|
77
77
|
loc: SourceLocation;
|
|
78
78
|
paramNames: string[];
|
|
79
79
|
cases: CaseResult[];
|
|
80
|
-
|
|
80
|
+
/** cases 结果 Abs 的 join;dts 返回位源 */
|
|
81
|
+
combinedAbs?: Abs;
|
|
81
82
|
entryOnly?: boolean;
|
|
82
83
|
skipped?: boolean;
|
|
83
84
|
/**
|
|
@@ -91,7 +92,8 @@ type FunctionAnalysis = {
|
|
|
91
92
|
fromModule?: string;
|
|
92
93
|
};
|
|
93
94
|
type BindingInfo = {
|
|
94
|
-
|
|
95
|
+
/** 无损 Abs */
|
|
96
|
+
abs: Abs;
|
|
95
97
|
loc?: SourceLocation;
|
|
96
98
|
};
|
|
97
99
|
type CaseHint = {
|
|
@@ -109,7 +111,8 @@ type AnalysisResult = {
|
|
|
109
111
|
* the original — lookups must use the File that produced this result, not a
|
|
110
112
|
* freshly parsed one. getTypeAtPosition rebuilds its own map and is unaffected.
|
|
111
113
|
*/
|
|
112
|
-
|
|
114
|
+
/** 无损节点 Abs */
|
|
115
|
+
nodeAbsMap: Map<Node, Abs>;
|
|
113
116
|
caseHints: CaseHint[];
|
|
114
117
|
/** functions imported from other modules, synthesized from cross-file call sites observed while analyzing this file */
|
|
115
118
|
externalFunctions?: FunctionAnalysis[];
|
|
@@ -163,6 +166,7 @@ declare function analyzeFileAsync(filePath: string, source: string, activeCases?
|
|
|
163
166
|
* 真实的实参类型与结果类型——后续 analyzeFile 将其注入合成 case,
|
|
164
167
|
* 使被使用方从 entry-only(参数全 unknown)升级为真实调用形态。
|
|
165
168
|
*
|
|
169
|
+
* Abs 路径(TypeValue evaluateProgram 已删):evalProgramAbs + AbsCallRecord。
|
|
166
170
|
* 只做求值与记录,不产出诊断;求值异常不抛出(使用现场文件可能
|
|
167
171
|
* 依赖未 mock 的全局,收集不到就收集不到,不能拖垮主分析)。
|
|
168
172
|
*/
|
|
@@ -177,6 +181,7 @@ declare function collectCallRecords(filePath: string, source: string): CallRecor
|
|
|
177
181
|
* (CLI watch / vite-plugin)在 dep 变更时应 `clearBPathCache()` 或上述逐出。
|
|
178
182
|
*/
|
|
179
183
|
declare function analyzeFile(filePath: string, source: string, activeCases?: Map<string, number>, externalCallRecords?: CallRecord[]): AnalysisResult;
|
|
184
|
+
|
|
180
185
|
type CaseInfo = {
|
|
181
186
|
functionName: string;
|
|
182
187
|
caseName: string;
|
|
@@ -191,10 +196,17 @@ declare function getCasesForFile(filePath: string, source: string): {
|
|
|
191
196
|
loc: SourceLocation;
|
|
192
197
|
}[];
|
|
193
198
|
/** Async entry to getTypeAtPosition with path-env preloading (see analyzeFileAsync). */
|
|
194
|
-
declare function getTypeAtPositionAsync(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Promise<
|
|
195
|
-
|
|
199
|
+
declare function getTypeAtPositionAsync(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Promise<Abs | null>;
|
|
200
|
+
/** Async entry to getAbsAtPosition(与 getTypeAtPositionAsync 同预加载口径) */
|
|
201
|
+
declare function getAbsAtPositionAsync(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Promise<Abs | null>;
|
|
202
|
+
/**
|
|
203
|
+
* 光标处无损 Abs。B-path 节点表优先;用例函数体走 Abs 重放。
|
|
204
|
+
*/
|
|
205
|
+
declare function getAbsAtPosition(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Abs | null;
|
|
206
|
+
/** 光标处类型(Abs)。B-path 节点表优先;用例函数体走 Abs 重放。 */
|
|
207
|
+
declare function getTypeAtPosition(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Abs | null;
|
|
196
208
|
type HoverInfo = {
|
|
197
|
-
/**
|
|
209
|
+
/** 外延展示(formatShape / formatAbs) */
|
|
198
210
|
typeText: string;
|
|
199
211
|
/** 内涵签名(代数 generalize) */
|
|
200
212
|
intension?: string;
|
|
@@ -204,12 +216,12 @@ type HoverInfo = {
|
|
|
204
216
|
absMultiline?: string;
|
|
205
217
|
};
|
|
206
218
|
/**
|
|
207
|
-
* LSP hover:优先无损 Abs
|
|
219
|
+
* LSP hover:优先无损 Abs(类型即计算本体)。
|
|
208
220
|
* 节点表也是 Abs(collectAbsNodeTypes),不经 bridge。
|
|
209
221
|
*
|
|
210
222
|
* 函数名/调用 callee 位置(design-hof-relations §7):
|
|
211
223
|
* intension 一律走 generalize/formatPoly(HOF fnRels 在这里);
|
|
212
|
-
* typeText 仍落 B-path
|
|
224
|
+
* typeText 仍落 B-path Abs(调用点显示结果类型,不是函数签名)。
|
|
213
225
|
* 禁止用 B-path 的 arity-only fn Abs 冒充权威关系源。
|
|
214
226
|
*/
|
|
215
227
|
declare function getHoverAtPosition(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): HoverInfo | null;
|
|
@@ -219,8 +231,9 @@ declare function getCompletionsAtPosition(filePath: string, source: string, line
|
|
|
219
231
|
* `nudo infer --json` 稳定契约 v1(CI / Agent)。
|
|
220
232
|
*
|
|
221
233
|
* 字段只增不改语义:
|
|
222
|
-
* -
|
|
234
|
+
* - args / result / throws / combined:formatShape 外延投影(有损,兼容)
|
|
223
235
|
* - intension.abs*:无损 Abs 展示(主线)
|
|
236
|
+
* - argsAbs / resultAbs:CaseResult 上的无损 Abs(formatAbs);有则补齐
|
|
224
237
|
*/
|
|
225
238
|
|
|
226
239
|
type InferJsonCase = {
|
|
@@ -231,6 +244,10 @@ type InferJsonCase = {
|
|
|
231
244
|
throws: string | null;
|
|
232
245
|
source: string | null;
|
|
233
246
|
aggregatedFrom?: number;
|
|
247
|
+
/** 无损参数 Abs 展示(与 args 对齐;缺失位省略) */
|
|
248
|
+
argsAbs?: string[];
|
|
249
|
+
/** 无损结果 Abs 展示 */
|
|
250
|
+
resultAbs?: string;
|
|
234
251
|
/** 无损内涵(Abs);无则省略 */
|
|
235
252
|
intension?: {
|
|
236
253
|
display?: string;
|
|
@@ -248,6 +265,8 @@ type InferJsonFunction = {
|
|
|
248
265
|
noDeclaration?: boolean;
|
|
249
266
|
cases: InferJsonCase[];
|
|
250
267
|
combined?: string;
|
|
268
|
+
/** 无损 combined Abs 展示 */
|
|
269
|
+
combinedAbs?: string;
|
|
251
270
|
};
|
|
252
271
|
type InferJson = {
|
|
253
272
|
version: 1;
|
|
@@ -283,9 +302,11 @@ declare function serializeInferJson(result: AnalysisResult, file: string): Infer
|
|
|
283
302
|
* nudo 推断目标文件判定(纯扩展名规则,路径无需存在)。
|
|
284
303
|
*
|
|
285
304
|
* 规则:.js / .mjs / .ts 可作为推断目标;其余扩展(.cjs/.tsx/.jsx/.mts/.d.ts…)
|
|
286
|
-
* 一律 false
|
|
305
|
+
* 一律 false。显式排除:
|
|
287
306
|
* - .d.ts —— 类型声明文件(harvester 的输入),不是可求值的实现源码;
|
|
288
|
-
* - .tsx / .jsx —— JSX 构造的求值超出 nudo
|
|
307
|
+
* - .tsx / .jsx —— JSX 构造的求值超出 nudo 推断器范围;
|
|
308
|
+
* - *.nudo.js / *.nudo.ts —— 侧车契约模块(interface 绑定源),不是源码
|
|
309
|
+
* 推断目标;目录级 check/infer/doctor 展开不得把它们当实现分析。
|
|
289
310
|
*
|
|
290
311
|
* 消费方:CLI 的 collectNudoFiles/watch 过滤/doctor 目录展开(.ts 放开后统一
|
|
291
312
|
* 走本函数,避免各处手写 endsWith 漂移),以及 LSP 的 isNudoFile(接线由
|
|
@@ -353,7 +374,7 @@ declare function harvestPackage(pkg: string, fromDir?: string, maxFiles?: number
|
|
|
353
374
|
};
|
|
354
375
|
/** harvest 结果 → 人类可读导出表 */
|
|
355
376
|
declare function formatHarvestSummary(h: PackageHarvest): string;
|
|
356
|
-
/**
|
|
377
|
+
/** 取某个导出的展示串(formatShape) */
|
|
357
378
|
declare function lookupHarvested(h: PackageHarvest, moduleName: string, exportName: string): string | undefined;
|
|
358
379
|
|
|
359
380
|
/**
|
|
@@ -370,7 +391,7 @@ declare function clearHarvestCache(): void;
|
|
|
370
391
|
* 自动 harvest 源码中全部裸包(有 @types 或包内 dts 时)。
|
|
371
392
|
* 返回可注入 setEnvModules 的 modules 表;无包可 harvest 时为空对象。
|
|
372
393
|
*/
|
|
373
|
-
declare function autoHarvestModules(source: string, fromDir: string): Record<string, Record<string,
|
|
394
|
+
declare function autoHarvestModules(source: string, fromDir: string): Record<string, Record<string, Abs>>;
|
|
374
395
|
|
|
375
396
|
/**
|
|
376
397
|
* Host:import 图(相对 + 裸包 harvest)→ Abs 导出表 → 注入入口。
|
|
@@ -436,12 +457,12 @@ declare function evalProgramAbsWithModules(source: string, entryFile: string, op
|
|
|
436
457
|
declare function collectAbsBindingsFromGraph(source: string, filePath: string, opts?: AbsGraphOptions): Map<string, Abs>;
|
|
437
458
|
|
|
438
459
|
/**
|
|
439
|
-
* Harvest
|
|
440
|
-
*
|
|
460
|
+
* Harvest Abs 导出 → AbsModuleExports(供 Abs 模块图注入)。
|
|
461
|
+
* harvest 产物已是 Abs;fn 槽 apply 直接返回声明返回类型(conf=mock)。
|
|
441
462
|
*/
|
|
442
463
|
|
|
443
|
-
/** 单个
|
|
444
|
-
declare function harvestedValueToAbs(
|
|
464
|
+
/** 单个 Abs 导出 → 可调用 mock(fn 槽 apply 返回声明返回类型) */
|
|
465
|
+
declare function harvestedValueToAbs(a: Abs): Abs;
|
|
445
466
|
/**
|
|
446
467
|
* 把 harvest 的 modules/globals 合成 AbsModuleExports。
|
|
447
468
|
* 键同时登记:原始模块路径、包名、basename(path / @types/path)。
|
|
@@ -451,7 +472,7 @@ declare function packageHarvestToAbsModules(pkg: string, h: PackageHarvest): Rec
|
|
|
451
472
|
/** 裸说明符 → Abs 导出表(走 harvest 缓存) */
|
|
452
473
|
declare function bareSpecToAbsModules(spec: string, fromFile: string): AbsModuleExports | undefined;
|
|
453
474
|
|
|
454
|
-
/** @nudo:env → Abs
|
|
475
|
+
/** @nudo:env → Abs 全局表(env 模块 Abs 原生) */
|
|
455
476
|
declare function collectEnvGlobals(envNames: string[]): Record<string, Abs>;
|
|
456
477
|
/** @nudo:env modules(path / node:path / fs…)→ AbsModuleExports */
|
|
457
478
|
declare function collectEnvModules(envNames: string[]): Record<string, AbsModuleExports>;
|
|
@@ -544,14 +565,6 @@ declare function clearAnalysisSessionCaches(): void;
|
|
|
544
565
|
/** 比 clearAnalysisSessionCaches 更彻底:再丢 AST LRU(测试 / 进程复用场景) */
|
|
545
566
|
declare function resetAllAnalysisCaches(): void;
|
|
546
567
|
|
|
547
|
-
/**
|
|
548
|
-
* env TypeValue → Abs:
|
|
549
|
-
* - fnSig 带 impl(Promise.resolve / URL / path.join…)→ apply 路径,保留精确字面量
|
|
550
|
-
* - fnSig 仅有声明(readFileSync…)→ relationFn,调用产出声明返回类型而非 unknown
|
|
551
|
-
*/
|
|
552
|
-
|
|
553
|
-
declare function envValueToAbs(tv: TypeValue): Abs;
|
|
554
|
-
|
|
555
568
|
/**
|
|
556
569
|
* B 路径静态诊断(AST,不执行):
|
|
557
570
|
* - unreachable:同块 return/throw 之后的语句
|
|
@@ -635,12 +648,13 @@ declare function encodeSemanticTokens(tokens: SemanticToken[]): number[];
|
|
|
635
648
|
* - 函数声明/函数表达式的名字 → function;所有函数的参数 → parameter;
|
|
636
649
|
* - 对象字面量的键:值为函数 → method,否则 property。
|
|
637
650
|
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
651
|
+
* 推断优先 Abs 模块图绑定(TypeValue 退出主路径);失败时复用
|
|
652
|
+
* evaluateProgram。解析失败返回 []。
|
|
640
653
|
*/
|
|
641
654
|
declare function buildSemanticTokens(filePath: string, source: string): number[];
|
|
642
655
|
|
|
643
|
-
|
|
656
|
+
/** Abs → TS 类型串。有损:pred / 非 lit term 落到 shape 基类型。 */
|
|
657
|
+
declare function absToTSType(a: Abs): string;
|
|
644
658
|
/**
|
|
645
659
|
* 为单个函数生成 .d.ts 声明行(JSDoc + 单一 widen 主签名)。
|
|
646
660
|
* service 的 generateDts 与 CLI `--dts`(infer/watch)共用本函数,
|
|
@@ -649,19 +663,21 @@ declare function typeValueToTSType(tv: TypeValue): string;
|
|
|
649
663
|
declare function generateFunctionDtsLines(fn: FunctionAnalysis): string[];
|
|
650
664
|
declare function generateDts(result: AnalysisResult): string;
|
|
651
665
|
|
|
652
|
-
|
|
666
|
+
/** Abs → zod schema 源码。有损:pred / 非 lit term 落到 shape 基类型。 */
|
|
667
|
+
declare function absToZodSchema(a: Abs): string;
|
|
653
668
|
|
|
654
|
-
|
|
655
|
-
/** Abs 指称守卫(设计 §2.7):比 TypeValue 投影多保留 pred */
|
|
669
|
+
/** Abs 指称守卫(设计 §2.7):保留 pred */
|
|
656
670
|
declare function generateGuardFunctionFromAbs(name: string, abs: Abs): string;
|
|
671
|
+
/** 兼容别名:Abs 路径唯一 */
|
|
672
|
+
declare function generateGuardFunction(name: string, abs: Abs): string;
|
|
657
673
|
|
|
658
|
-
/** 单个
|
|
659
|
-
declare function serializeCaseArg(
|
|
674
|
+
/** 单个 Abs → parseCaseArgExpr 可解析回去的表达式文本;不可表达返回 null */
|
|
675
|
+
declare function serializeCaseArg(a: Abs): string | null;
|
|
660
676
|
/**
|
|
661
677
|
* 组装单行 ` * @nudo:case "name" (a, b)` 指令文本(无尾换行)。
|
|
662
678
|
* 任一实参不可序列化、或名字含双引号/换行(名字正则 `"([^"]+)"` 承载不了)→ 整体 null。
|
|
663
679
|
*/
|
|
664
|
-
declare function buildCaseDirective(name: string,
|
|
680
|
+
declare function buildCaseDirective(name: string, argsAbs: Abs[]): string | null;
|
|
665
681
|
/**
|
|
666
682
|
* 从源码剥离所有本模块生成的 @nudo:case 指令(名字以 call@ 开头,整行删除)。
|
|
667
683
|
* 若所属 JSDoc 块因此只剩空 ` *` 行(无其他 @nudo:* 指令、无文字内容),
|
|
@@ -722,4 +738,236 @@ declare function mockDirectivesToAbsSeeds(functions: Array<{
|
|
|
722
738
|
directives: FunctionWithDirectives["directives"];
|
|
723
739
|
}>): AbsMockSeeds;
|
|
724
740
|
|
|
725
|
-
|
|
741
|
+
/**
|
|
742
|
+
* `nudo interface` 的打印数据源(design-refine-derivation §11 第 0 步):
|
|
743
|
+
* 逐顶层函数展示有效契约分层——effectiveInterface 命中(手写契约 / 侧车
|
|
744
|
+
* 生成段)时 params/returns 用 formatConstraint 组合式显示;未命中走
|
|
745
|
+
* implicit:优先 CaseResult.argAbs / FunctionAnalysis.combinedAbs(无损
|
|
746
|
+
* Abs 源),展示用 formatShape(外延口径,不强求约束式、不带 conf)。
|
|
747
|
+
*
|
|
748
|
+
* autoBind 沿 package.json#nudo.interface(findProjectConfig → interfaceConfig)
|
|
749
|
+
* 下传,可用 opts 覆盖(测试 / CLI 显式开关);读盘用 defaultLoadModule
|
|
750
|
+
* (与 check 的 refine 解析同一扩展名表)。
|
|
751
|
+
*/
|
|
752
|
+
|
|
753
|
+
type InterfaceSurfaceEntry = {
|
|
754
|
+
fn: string;
|
|
755
|
+
/** 本文件 named export(自动绑定边界口径:localNamedExports) */
|
|
756
|
+
kind: "export" | "local";
|
|
757
|
+
source: "handwritten" | "generated" | "implicit";
|
|
758
|
+
params: Array<{
|
|
759
|
+
name: string;
|
|
760
|
+
display: string;
|
|
761
|
+
}>;
|
|
762
|
+
returns?: string;
|
|
763
|
+
};
|
|
764
|
+
type InterfaceSurfaceOpts = {
|
|
765
|
+
/** 覆盖项目配置的 autoBind(默认 findProjectConfig → interfaceConfig) */
|
|
766
|
+
autoBind?: boolean;
|
|
767
|
+
/** 模块源码装载器(测试注入);默认 defaultLoadModule 真实读盘 */
|
|
768
|
+
loadModule?: LoadModule;
|
|
769
|
+
/** 跨文件调用记录(--callsites 采集):implicit 展示的实参域原料 */
|
|
770
|
+
records?: CallRecord[];
|
|
771
|
+
};
|
|
772
|
+
/** 单条 interface 打印行(CLI runInterface 与 LSP agent 面共用) */
|
|
773
|
+
declare function formatInterfaceSurfaceLine(e: InterfaceSurfaceEntry): string;
|
|
774
|
+
/**
|
|
775
|
+
* 单文件 interface 表面:analyzer 推断结果给出函数清单与 implicit 展示,
|
|
776
|
+
* effectiveInterface 给出契约命中(手写 > 生成段)。诊断 side-channel
|
|
777
|
+
* 在收尾时取走丢弃——打印命令不执法,interface-load 等错误留给 check 路径。
|
|
778
|
+
*/
|
|
779
|
+
declare function interfaceSurface(filePath: string, opts?: InterfaceSurfaceOpts): Promise<InterfaceSurfaceEntry[]>;
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* `nudo interface --emit` 的写盘器(design-refine-derivation §5.4 / §7.3 / §11):
|
|
783
|
+
* 把分析产出的调用点域投影(joinThenProject,先 Abs join 再投影)固化为侧车
|
|
784
|
+
* `*.nudo.js` / `*.nudo.ts` 的 `@generated` 段——`export const <fn> = fn({…}, …)`。
|
|
785
|
+
*
|
|
786
|
+
* - 生成段 = 三行:`@generated` 头注释 + `// source: <相对file>:<fn>` + export 行。
|
|
787
|
+
* DSL 由 formatConstraint 产出,**写入前 round-trip 自检**(生成文本经
|
|
788
|
+
* execNudoModule 求值、导出须 isNudoConstraint 且 fn 槽存在):展示兜底形态
|
|
789
|
+
* (`x?:` 可选字段、`.eq()` 伪链、`{谓词原文}`)不是合法 DSL,自检拦下 →
|
|
790
|
+
* not-projectable 跳过,不写垃圾。
|
|
791
|
+
* - 手写导出永不覆盖:目标名已是侧车手写绑定 → 跳过写入并报
|
|
792
|
+
* `nudo:interface-name-clash`(error,手写优先)。
|
|
793
|
+
* - mode=update:剥离全部生成段再重排(幂等;非目标的既有生成段原样保留,
|
|
794
|
+
* 不随 --fn 丢失);mode=add:仅追加缺失段。
|
|
795
|
+
* - 目标过滤(§7.3):--fn 白名单 > --all 全量 > 默认只刷新已有生成段
|
|
796
|
+
* (「无根只处理已存在生成段」;Phase 1 无 root 闭包下行推导)。
|
|
797
|
+
* - autoBind=false 不影响 emit(显式动作,非 ambient 加载)。
|
|
798
|
+
*/
|
|
799
|
+
|
|
800
|
+
type EmitInterfaceSkipReason = "name-clash" | "not-projectable" | "not-an-export" | "no-change"
|
|
801
|
+
/** package.json#nudo.interface.emit 白名单拒绝 */
|
|
802
|
+
| "emit-denied"
|
|
803
|
+
/** 手工合并的多声明符 @generated 段:按段原子保留,不拆不重写 */
|
|
804
|
+
| "multi-declarator";
|
|
805
|
+
type EmitInterfaceOpts = {
|
|
806
|
+
/** 目标导出名白名单(Phase 1:只过滤目标文件自身的导出;跨文件 root 闭包 emit 是 Phase 2 下行推导能力) */
|
|
807
|
+
fnNames?: string[];
|
|
808
|
+
/** update=剥离全部生成段再重排(幂等);add=仅追加缺失段 */
|
|
809
|
+
mode: "add" | "update";
|
|
810
|
+
/** 全部顶层导出(显式 opt-in,CLI 侧文档警告勿默认) */
|
|
811
|
+
all?: boolean;
|
|
812
|
+
/** 不写盘,返回 unifiedDiff */
|
|
813
|
+
dryRun?: boolean;
|
|
814
|
+
/**
|
|
815
|
+
* 跨文件调用记录(--callsites 采集):域根导出(本文件无调用点、仅有
|
|
816
|
+
* 外部使用现场记录)的投影原料;缺省时仅用本文件调用点证据。
|
|
817
|
+
*/
|
|
818
|
+
records?: CallRecord[];
|
|
819
|
+
};
|
|
820
|
+
type EmitInterfaceResult = {
|
|
821
|
+
written: string[];
|
|
822
|
+
skipped: Array<{
|
|
823
|
+
fn: string;
|
|
824
|
+
reason: EmitInterfaceSkipReason;
|
|
825
|
+
}>;
|
|
826
|
+
changed: boolean;
|
|
827
|
+
diff?: string;
|
|
828
|
+
issues: Array<{
|
|
829
|
+
code: string;
|
|
830
|
+
severity: "error" | "warning";
|
|
831
|
+
message: string;
|
|
832
|
+
}>;
|
|
833
|
+
/** 侧车绝对路径(新建或已有) */
|
|
834
|
+
sidecarPath: string;
|
|
835
|
+
/**
|
|
836
|
+
* 默认过滤(无 --fn/--all)且侧车无既有 @generated 段可刷 —— 调用方
|
|
837
|
+
* 用它把「no interface changes」解释成首次 emit 的用法提示,而非漂移。
|
|
838
|
+
*/
|
|
839
|
+
emptyDefaultTargets?: boolean;
|
|
840
|
+
};
|
|
841
|
+
/**
|
|
842
|
+
* 单文件 emit:分析 → 逐目标投影/自检 → 组装侧车内容 →(非 dryRun)写盘。
|
|
843
|
+
* 诊断 side-channel(round-trip 自检触发的 refine/interface diags)收尾取走丢弃。
|
|
844
|
+
*/
|
|
845
|
+
declare function emitInterface(filePath: string, opts: EmitInterfaceOpts): Promise<EmitInterfaceResult>;
|
|
846
|
+
/**
|
|
847
|
+
* emit 摘要行(CLI runInterfaceEmit 与 LSP agent 面共用;路径由调用方按
|
|
848
|
+
* 展示口径传入——CLI 传 cwd 相对、agent 传绝对路径)。
|
|
849
|
+
*/
|
|
850
|
+
declare function formatEmitSummary(sourcePath: string, sidecarRel: string, result: EmitInterfaceResult): string[];
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Root 驱动的契约下行(design-refine-derivation §4.2 / §11 Phase 2)。
|
|
854
|
+
*
|
|
855
|
+
* 对含手写契约根的文件(lib.nudo.js 绑定 add4):
|
|
856
|
+
* 1. 从侧车 AST 抽出参数约束的源表达式(`positive` ← `./std.nudo.js`);
|
|
857
|
+
* 2. constraintToEntryAbs + tagDerivationRoot;
|
|
858
|
+
* 3. analyzeFn 求值 body(模块图注入下游),收集调用记录 + 推导打点;
|
|
859
|
+
* 4. 闭包内下游导出投影为组合式 DSL,禁止事后从 Abs 反编译链。
|
|
860
|
+
*
|
|
861
|
+
* check 分轨:每条 root 链独立;join 只用于工件聚合(多调用者)。
|
|
862
|
+
*/
|
|
863
|
+
|
|
864
|
+
type ConstraintSourceExpr = {
|
|
865
|
+
expr: string;
|
|
866
|
+
importFrom?: string;
|
|
867
|
+
importName?: string;
|
|
868
|
+
};
|
|
869
|
+
type DerivedParam = {
|
|
870
|
+
name: string;
|
|
871
|
+
constraint: NudoConstraint;
|
|
872
|
+
dsl: string;
|
|
873
|
+
prelude: string[];
|
|
874
|
+
imports: Array<{
|
|
875
|
+
name: string;
|
|
876
|
+
from: string;
|
|
877
|
+
}>;
|
|
878
|
+
/** 单链组合式投影时的推导图 root 节点 id(返回位相对锚定用) */
|
|
879
|
+
rootNodeId?: number;
|
|
880
|
+
/** 该参数位自 root 起消耗的 shift 步数(与 prelude 行数无关,读图) */
|
|
881
|
+
shiftCount?: number;
|
|
882
|
+
};
|
|
883
|
+
type DerivedExport = {
|
|
884
|
+
file: string;
|
|
885
|
+
fn: string;
|
|
886
|
+
paramNames: string[];
|
|
887
|
+
params: DerivedParam[];
|
|
888
|
+
returns?: {
|
|
889
|
+
constraint: NudoConstraint;
|
|
890
|
+
dsl: string;
|
|
891
|
+
prelude: string[];
|
|
892
|
+
imports: Array<{
|
|
893
|
+
name: string;
|
|
894
|
+
from: string;
|
|
895
|
+
}>;
|
|
896
|
+
};
|
|
897
|
+
/** `lib.js:add4` */
|
|
898
|
+
derivedFrom: string;
|
|
899
|
+
compositional: boolean;
|
|
900
|
+
underivable?: boolean;
|
|
901
|
+
};
|
|
902
|
+
type RootDeriveOpts = {
|
|
903
|
+
loadModule?: LoadModule;
|
|
904
|
+
autoBind?: boolean;
|
|
905
|
+
fnNames?: string[];
|
|
906
|
+
/**
|
|
907
|
+
* true:只刷新目标侧车里**已存在**的 @generated 段(CLI 无 --fn/--all 时
|
|
908
|
+
* 的默认行为——不发明新下游契约)。false/省略:闭包内全部可推导导出。
|
|
909
|
+
*/
|
|
910
|
+
refreshExistingOnly?: boolean;
|
|
911
|
+
};
|
|
912
|
+
type RootDeriveResult = {
|
|
913
|
+
roots: string[];
|
|
914
|
+
derived: DerivedExport[];
|
|
915
|
+
hasRoot: boolean;
|
|
916
|
+
};
|
|
917
|
+
/** 从侧车源码抽出 `export const f = fn({ x: positive }, ret)` 的约束源表达式 */
|
|
918
|
+
declare function extractFnConstraintSources(sidecarSrc: string, fnName: string): {
|
|
919
|
+
params: Record<string, ConstraintSourceExpr>;
|
|
920
|
+
returns?: ConstraintSourceExpr;
|
|
921
|
+
};
|
|
922
|
+
/**
|
|
923
|
+
* 入口:对 filePath 做 root 驱动下行推导。
|
|
924
|
+
*/
|
|
925
|
+
declare function deriveFromRoot(filePath: string, opts?: RootDeriveOpts): RootDeriveResult;
|
|
926
|
+
/**
|
|
927
|
+
* 组装生成段(组合式 + import + prelude)。
|
|
928
|
+
* importFrom 相对 root 侧车解析,再相对 target 侧车写出。
|
|
929
|
+
*
|
|
930
|
+
* `takenNames`:侧车顶层已占用标识符(手写 / 既有生成段 / 本批先前段)。
|
|
931
|
+
* 同文件多导出时对 import local 与 prelude local 做避让改写,
|
|
932
|
+
* 保证拼出的侧车在模块作用域内无重复声明。
|
|
933
|
+
*/
|
|
934
|
+
declare function formatDerivedSection(row: DerivedExport, opts: {
|
|
935
|
+
rootSidecarDir: string;
|
|
936
|
+
targetSidecarDir: string;
|
|
937
|
+
takenNames?: Iterable<string>;
|
|
938
|
+
}): {
|
|
939
|
+
text: string;
|
|
940
|
+
usedNames: string[];
|
|
941
|
+
} | undefined;
|
|
942
|
+
type EmitDerivedResult = {
|
|
943
|
+
/** 被写/将写的下游侧车(绝对路径) */
|
|
944
|
+
sidecars: Array<{
|
|
945
|
+
file: string;
|
|
946
|
+
sidecarPath: string;
|
|
947
|
+
fn: string;
|
|
948
|
+
written: boolean;
|
|
949
|
+
changed: boolean;
|
|
950
|
+
skipped?: "name-clash" | "not-projectable" | "underivable" | "no-change";
|
|
951
|
+
diff?: string;
|
|
952
|
+
issues: Array<{
|
|
953
|
+
code: string;
|
|
954
|
+
severity: "error" | "warning" | "info";
|
|
955
|
+
message: string;
|
|
956
|
+
}>;
|
|
957
|
+
}>;
|
|
958
|
+
hasRoot: boolean;
|
|
959
|
+
roots: string[];
|
|
960
|
+
/** 根在别处 / 无契约根且无已存在生成段 → info */
|
|
961
|
+
entryOnly?: boolean;
|
|
962
|
+
};
|
|
963
|
+
declare function emitDerivedFromRoot(rootFile: string, opts: {
|
|
964
|
+
fnNames?: string[];
|
|
965
|
+
mode: "add" | "update";
|
|
966
|
+
dryRun?: boolean;
|
|
967
|
+
loadModule?: LoadModule;
|
|
968
|
+
autoBind?: boolean;
|
|
969
|
+
/** 只刷新目标侧车里已存在的 @generated 段(不发明新下游契约) */
|
|
970
|
+
refreshExistingOnly?: boolean;
|
|
971
|
+
}): EmitDerivedResult;
|
|
972
|
+
|
|
973
|
+
export { type AbsGraphOptions, type AbsMockSeeds, type AbsModuleCacheEntry, type AbsModuleGraphResult, type AbsModuleLoadIssue, type AnalysisResult, type BPathBuiltinUnknown, type BPathDiagnostics, type BPathRunResult, type BPathUnreachable, type BindingInfo, CallRecord, type CaseHint, type CaseInfo, type CaseResult, type CompletionItem, type ConstraintSourceExpr, type DerivedExport, type DerivedParam, type Diagnostic, type DiagnosticSeverity, type DiagnosticTag, type EmitDerivedResult, type EmitInterfaceOpts, type EmitInterfaceResult, type EmitInterfaceSkipReason, type EmitResult, type EmitSkipReason, type FunctionAnalysis, type HoverInfo, type InferJson, type InferJsonCase, type InferJsonFunction, type InterfaceSurfaceEntry, type InterfaceSurfaceOpts, type LoadModule, type ModuleExports, type ModuleGraphCache, type NodeEnvResult, type PackageHarvest, type ReferenceInfo, type RootDeriveOpts, type RootDeriveResult, SEMANTIC_TOKEN_MODIFIERS, SEMANTIC_TOKEN_TYPES, type SemanticToken, type SourceLocation, type SymbolInfo, type SymbolTable, absToTSType, absToZodSchema, analyzeExportsFromSource, analyzeFile, analyzeFileAsync, autoHarvestModules, barePackageName, bareSpecToAbsModules, buildCaseDirective, buildModuleGraph, buildSemanticTokens, clearAbsModuleCache, clearAnalysisFileCache, clearAnalysisSessionCaches, clearBPathCache, clearFnAnalysisCache, clearHarvestCache, collectAbsBindingsFromGraph, collectBPathDiagnostics, collectBPathReplacements, collectBarePackages, collectCallRecords, collectDependencySpecs, collectDtsFromEntry, collectEnvGlobals, collectEnvModules, collectStaticImports, computeDirtySet, defaultAbsLoadModule, defaultLoadModule, deriveFromRoot, emitDerivedFromRoot, emitInterface, encodeSemanticTokens, evalAbsModuleGraph, evalProgramAbsWithModules, evictAbsModuleCacheFiles, evictAnalysisCachesForFiles, evictAnalysisFileCacheForFiles, evictBPathCacheForFiles, evictFnAnalysisCacheForFiles, extractFnConstraintSources, formatDerivedSection, formatEmitSummary, formatHarvestSummary, formatInterfaceSurfaceLine, generateDts, generateFunctionDtsLines, generateGuardFunction, generateGuardFunctionFromAbs, getAbsAtPosition, getAbsAtPositionAsync, getAnalysisFileCacheSize, getCasesForFile, getCompletionsAtPosition, getHoverAtPosition, getTypeAtPosition, getTypeAtPositionAsync, harvestNodeTypes, harvestPackage, harvestPackageCached, harvestToAbsModules, harvestedValueToAbs, insertGeneratedCaseDirectives, interfaceSurface, isBPathCapable, isNudoTargetPath, lookupHarvested, mockDirectivesToAbsSeeds, packageHarvestToAbsModules, resetAllAnalysisCaches, resolvePackageRoot, serializeCaseArg, serializeInferJson, stripGeneratedCaseDirectives, summarizeNodeEnv, topoSortDirty, tryBPathCall, tryBPathCallFull, tryRunBPath, unifiedDiff };
|