@nudojs/service 3.0.0 → 5.0.0-beta.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/README.md +19 -4
- package/dist/analysis-CSXrOVlg.d.ts +267 -0
- package/dist/analysis.d.ts +7 -0
- package/dist/analysis.js +57 -0
- package/dist/analyzer-types-JyJiCt8w.d.ts +158 -0
- package/dist/call-record-CkyCFkT9.d.ts +33 -0
- package/dist/case.d.ts +124 -0
- package/dist/case.js +18 -0
- package/dist/chunk-6IZR4ZYJ.js +1107 -0
- package/dist/chunk-E4N4A4JV.js +651 -0
- package/dist/chunk-HEU4WON5.js +2419 -0
- package/dist/chunk-K3ZPOTP2.js +199 -0
- package/dist/chunk-LFZRUXGK.js +89 -0
- package/dist/chunk-PVJIMQRI.js +246 -0
- package/dist/chunk-QAFMPM2E.js +3687 -0
- package/dist/chunk-QYRH7Z2Q.js +89 -0
- package/dist/chunk-U7JYTRIB.js +888 -0
- package/dist/{chunk-ADFCZP72.js → chunk-YLALZXTZ.js} +180 -165
- package/dist/chunk-YLVZMHWC.js +364 -0
- package/dist/{config-Cqj8zeZH.d.ts → config-DDB588oA.d.ts} +45 -48
- package/dist/dts.d.ts +142 -0
- package/dist/dts.js +30 -0
- package/dist/env-loader-fj0TSCcA.d.ts +20 -0
- package/dist/evaluator/evaluator-api.d.ts +3 -1
- package/dist/evaluator/evaluator-api.js +9 -3
- package/dist/harvest.d.ts +254 -0
- package/dist/harvest.js +75 -0
- package/dist/index.d.ts +293 -1197
- package/dist/index.js +328 -7639
- package/dist/interface-BGlP7aIk.d.ts +367 -0
- package/dist/interface.d.ts +3 -0
- package/dist/interface.js +43 -0
- package/dist/lsp.d.ts +103 -0
- package/dist/lsp.js +36 -0
- package/package.json +32 -8
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { C as CallRecord } from './call-record-CkyCFkT9.js';
|
|
2
|
+
import { NudoConstraint } from '@nudojs/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 相对/绝对 specifier → 模块源码。
|
|
6
|
+
* CLI / LSP / vite / check 共用同一扩展名表,避免门禁结果分叉。
|
|
7
|
+
*/
|
|
8
|
+
type LoadModule = (spec: string, fromFile: string) => string | undefined;
|
|
9
|
+
/** 默认 loadModule:支持 .js/.mjs/.ts 与 index 入口 */
|
|
10
|
+
declare function defaultLoadModule(spec: string, fromFile: string): string | undefined;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `nudo contract` 的打印数据源(design-refine-derivation §11 第 0 步):
|
|
14
|
+
* 逐顶层函数展示有效契约分层——effectiveInterface 命中(手写契约 / 侧车
|
|
15
|
+
* 生成段)时 params/returns 用 formatConstraint 组合式显示;未命中走
|
|
16
|
+
* implicit:优先 CaseResult.argAbs / FunctionAnalysis.combinedAbs(无损
|
|
17
|
+
* Abs 源),展示用 formatShape(外延口径,不强求约束式、不带 conf)。
|
|
18
|
+
*
|
|
19
|
+
* autoBind 沿 package.json#nudo.contract(findProjectConfig → interfaceConfig)
|
|
20
|
+
* 下传,可用 opts 覆盖(测试 / CLI 显式开关);读盘用 defaultLoadModule
|
|
21
|
+
* (与 check 的 refine 解析同一扩展名表)。
|
|
22
|
+
*
|
|
23
|
+
* B3 Phase B:`nudo.cache` / NUDO_CACHE_DIR 打开时,整文件 effectiveInterface
|
|
24
|
+
* 表(含 implicit 负缓存 null)落盘;二次冷启动跳过侧车 exec / 契约合并。
|
|
25
|
+
* 缓存只服务打印/表面,不加速 B-path 分析(design-persistent-cache §0)。
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
type InterfaceSurfaceEntry = {
|
|
29
|
+
fn: string;
|
|
30
|
+
/** 本文件 named export(自动绑定边界口径:localNamedExports) */
|
|
31
|
+
kind: "export" | "local";
|
|
32
|
+
source: "handwritten" | "generated" | "implicit";
|
|
33
|
+
params: Array<{
|
|
34
|
+
name: string;
|
|
35
|
+
display: string;
|
|
36
|
+
}>;
|
|
37
|
+
returns?: string;
|
|
38
|
+
};
|
|
39
|
+
type InterfaceSurfaceOpts = {
|
|
40
|
+
/** 覆盖项目配置的 autoBind(默认 findProjectConfig → interfaceConfig) */
|
|
41
|
+
autoBind?: boolean;
|
|
42
|
+
/** 模块源码装载器(测试注入);默认 defaultLoadModule 真实读盘 */
|
|
43
|
+
loadModule?: LoadModule;
|
|
44
|
+
/** 跨文件调用记录(--from 采集):implicit 展示的实参域原料 */
|
|
45
|
+
records?: CallRecord[];
|
|
46
|
+
/** 打开 buffer 覆盖磁盘源码(E5:agent/LSP 与 hover 同口径) */
|
|
47
|
+
source?: string;
|
|
48
|
+
};
|
|
49
|
+
/** 单条 interface 打印行(CLI runInterface 与 LSP agent 面共用) */
|
|
50
|
+
declare function formatInterfaceSurfaceLine(e: InterfaceSurfaceEntry): string;
|
|
51
|
+
/**
|
|
52
|
+
* 单文件 interface 表面:analyzer 推断结果给出函数清单与 implicit 展示,
|
|
53
|
+
* effectiveInterface 给出契约命中(手写 > 生成段)。诊断 side-channel
|
|
54
|
+
* 在收尾时取走丢弃——打印命令不执法,interface-load 等错误留给 check 路径。
|
|
55
|
+
*/
|
|
56
|
+
declare function interfaceSurface(filePath: string, opts?: InterfaceSurfaceOpts): Promise<InterfaceSurfaceEntry[]>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `nudo contract --emit` 的写盘器(design-refine-derivation §5.4 / §7.3 / §11):
|
|
60
|
+
* 把分析产出的调用点域投影(joinThenProject,先 Abs join 再投影)固化为侧车
|
|
61
|
+
* `*.nudo.js` / `*.nudo.ts` 的 `@generated` 段——`export const <fn> = fn({…}, …)`。
|
|
62
|
+
*
|
|
63
|
+
* - 生成段 = 三行:`@generated` 头注释 + `// source: <相对file>:<fn>` + export 行。
|
|
64
|
+
* DSL 由 formatConstraint 产出,**写入前 round-trip 自检**(生成文本经
|
|
65
|
+
* execNudoModule 求值、导出须 isNudoConstraint 且 fn 槽存在):展示兜底形态
|
|
66
|
+
* (`x?:` 可选字段、`.eq()` 伪链、`{谓词原文}`)不是合法 DSL,自检拦下 →
|
|
67
|
+
* not-projectable 跳过,不写垃圾。
|
|
68
|
+
* - 手写导出永不覆盖:目标名已是侧车手写绑定 → 跳过写入并报
|
|
69
|
+
* `nudo:interface-name-clash`(error,手写优先)。
|
|
70
|
+
* - mode=update:剥离全部生成段再重排(幂等;非目标的既有生成段原样保留,
|
|
71
|
+
* 不随 --fn 丢失);mode=add:仅追加缺失段。
|
|
72
|
+
* - 目标过滤(§7.3):--fn 白名单 > --all 全量 > 默认只刷新已有生成段
|
|
73
|
+
* (「无根只处理已存在生成段」;Phase 1 无 root 闭包下行推导)。
|
|
74
|
+
* - autoBind=false 不影响 emit(显式动作,非 ambient 加载)。
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
type EmitInterfaceSkipReason = "name-clash" | "not-projectable" | "not-an-export" | "no-change"
|
|
78
|
+
/** package.json#nudo.contract.emit 白名单拒绝 */
|
|
79
|
+
| "emit-denied"
|
|
80
|
+
/** 手工合并的多声明符 @generated 段:按段原子保留,不拆不重写 */
|
|
81
|
+
| "multi-declarator";
|
|
82
|
+
type EmitInterfaceOpts = {
|
|
83
|
+
/** 目标导出名白名单(Phase 1:只过滤目标文件自身的导出;跨文件 root 闭包 emit 是 Phase 2 下行推导能力) */
|
|
84
|
+
fnNames?: string[];
|
|
85
|
+
/** update=剥离全部生成段再重排(幂等);add=仅追加缺失段 */
|
|
86
|
+
mode: "add" | "update";
|
|
87
|
+
/** 全部顶层导出(显式 opt-in,CLI 侧文档警告勿默认) */
|
|
88
|
+
all?: boolean;
|
|
89
|
+
/** 不写盘,返回 unifiedDiff */
|
|
90
|
+
dryRun?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* 跨文件调用记录(--from 采集):域根导出(本文件无调用点、仅有
|
|
93
|
+
* 外部使用现场记录)的投影原料;缺省时仅用本文件调用点证据。
|
|
94
|
+
*/
|
|
95
|
+
records?: CallRecord[];
|
|
96
|
+
/** 缓冲源(E5:agent/LSP 与 validate 同源);缺省读盘 */
|
|
97
|
+
source?: string;
|
|
98
|
+
/** 模块装载器(buffer-aware 侧车可见);缺省 defaultLoadModule */
|
|
99
|
+
loadModule?: (spec: string, fromFile: string) => string | undefined;
|
|
100
|
+
};
|
|
101
|
+
type EmitInterfaceResult = {
|
|
102
|
+
written: string[];
|
|
103
|
+
skipped: Array<{
|
|
104
|
+
fn: string;
|
|
105
|
+
reason: EmitInterfaceSkipReason;
|
|
106
|
+
}>;
|
|
107
|
+
changed: boolean;
|
|
108
|
+
diff?: string;
|
|
109
|
+
issues: Array<{
|
|
110
|
+
code: string;
|
|
111
|
+
severity: "error" | "warning";
|
|
112
|
+
message: string;
|
|
113
|
+
}>;
|
|
114
|
+
/** 侧车绝对路径(新建或已有) */
|
|
115
|
+
sidecarPath: string;
|
|
116
|
+
/**
|
|
117
|
+
* 默认过滤(无 --fn/--all)且侧车无既有 @generated 段可刷 —— 调用方
|
|
118
|
+
* 用它把「no interface changes」解释成首次 emit 的用法提示,而非漂移。
|
|
119
|
+
*/
|
|
120
|
+
emptyDefaultTargets?: boolean;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* 单文件 emit:分析 → 逐目标投影/自检 → 组装侧车内容 →(非 dryRun)写盘。
|
|
124
|
+
* 诊断 side-channel(round-trip 自检触发的 refine/interface diags)收尾取走丢弃。
|
|
125
|
+
*/
|
|
126
|
+
declare function emitInterface(filePath: string, opts: EmitInterfaceOpts): Promise<EmitInterfaceResult>;
|
|
127
|
+
/**
|
|
128
|
+
* emit 摘要行(CLI runInterfaceEmit 与 LSP agent 面共用;路径由调用方按
|
|
129
|
+
* 展示口径传入——CLI 传 cwd 相对、agent 传绝对路径)。
|
|
130
|
+
*/
|
|
131
|
+
declare function formatEmitSummary(sourcePath: string, sidecarRel: string, result: EmitInterfaceResult): string[];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* `nudo contract --draft`:从已有 JS **逻辑** 生成 contract 草稿。
|
|
135
|
+
*
|
|
136
|
+
* 产品位(代码优先 / 迁移):先写实现,再反推可审阅的 `fn({…}, …)` 草稿;
|
|
137
|
+
* 人审后迁入 `*.nudo.js` 才成为契约。
|
|
138
|
+
*
|
|
139
|
+
* 证据分层(与 C0 一致:草稿 ≠ ambient 义务):
|
|
140
|
+
* - callsite / directive case → joinThenProject 值域(迁移最可信)
|
|
141
|
+
* - body 触达(**仅草稿展示**)→ 参数上被读到的字段名建议;不进 check
|
|
142
|
+
* - generalize symbolic → 返回位兜底
|
|
143
|
+
* - 无证据 → 参数槽省略 + 注释 TODO(不发明义务)
|
|
144
|
+
* - 已有 handwritten 契约 → **跳过**(手写优先,不覆盖)
|
|
145
|
+
*
|
|
146
|
+
* 写盘:默认只打印;`--write` 写入 `<file>.nudo.draft.js`——**不会**被
|
|
147
|
+
* sidecar 自动绑定(loadModule 只认 `*.nudo.js`)。审阅后复制进正式侧车。
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* DraftEvidence `body` = 仅来自函数体对形参的成员读取(草稿建议,非义务)。
|
|
152
|
+
* check / effectiveInterface **永不**消费该档。
|
|
153
|
+
*/
|
|
154
|
+
type DraftEvidence = "callsite" | "directive" | "symbolic" | "body" | "none";
|
|
155
|
+
type InterfaceDraftEntry = {
|
|
156
|
+
fn: string;
|
|
157
|
+
/** 全部形参(含无证据槽,便于人读) */
|
|
158
|
+
params: Array<{
|
|
159
|
+
name: string;
|
|
160
|
+
constraint?: NudoConstraint;
|
|
161
|
+
display: string;
|
|
162
|
+
/** false = 无证据,DSL 对象里省略该槽 */
|
|
163
|
+
projected: boolean;
|
|
164
|
+
/** 函数体读到的字段名(草稿建议;与 projected 无关) */
|
|
165
|
+
bodyAccesses?: string[];
|
|
166
|
+
}>;
|
|
167
|
+
returns?: {
|
|
168
|
+
constraint?: NudoConstraint;
|
|
169
|
+
display: string;
|
|
170
|
+
projected: boolean;
|
|
171
|
+
};
|
|
172
|
+
paramEvidence: DraftEvidence;
|
|
173
|
+
returnEvidence: DraftEvidence;
|
|
174
|
+
skipped?: "handwritten" | "not-an-export";
|
|
175
|
+
/** 草稿 DSL:`fn({ … }, …)`;handwritten / 非导出时 undefined */
|
|
176
|
+
dsl?: string;
|
|
177
|
+
};
|
|
178
|
+
type InterfaceDraftOpts = {
|
|
179
|
+
fnNames?: string[];
|
|
180
|
+
records?: CallRecord[];
|
|
181
|
+
loadModule?: LoadModule;
|
|
182
|
+
/**
|
|
183
|
+
* Accepted for API compatibility; **ignored**. The handwritten-contract probe
|
|
184
|
+
* always uses `effectiveInterface(..., { autoBind: true })` so draft skips
|
|
185
|
+
* disk sidecars even when ambient autoBind is off (product: draft asks
|
|
186
|
+
* "does a contract already exist?", not "is ambient binding on?").
|
|
187
|
+
*/
|
|
188
|
+
autoBind?: boolean;
|
|
189
|
+
/** 默认 true:收集 body 成员读取作草稿建议(永不进 check) */
|
|
190
|
+
bodyAccesses?: boolean;
|
|
191
|
+
/** 打开 buffer 源(E5:与 hover/interface 同口径) */
|
|
192
|
+
source?: string;
|
|
193
|
+
};
|
|
194
|
+
type InterfaceDraftResult = {
|
|
195
|
+
file: string;
|
|
196
|
+
entries: InterfaceDraftEntry[];
|
|
197
|
+
draftSource: string;
|
|
198
|
+
sidecarPath: string;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Draft-only:收集每个顶层函数形参上的成员读取键(`user.name` → name)。
|
|
202
|
+
* **不是** C0 禁止的 body→义务通道——只进草稿注释/建议,check 不读此表。
|
|
203
|
+
*/
|
|
204
|
+
declare function collectParamBodyAccesses(source: string): Map<string, Map<string, Set<string>>>;
|
|
205
|
+
/**
|
|
206
|
+
* 为单文件顶层导出生成 interface 草稿(不写盘)。
|
|
207
|
+
* handwritten 跳过;已有 @generated 仍出草稿(便于对照)。
|
|
208
|
+
*/
|
|
209
|
+
declare function draftInterface(filePath: string, opts?: InterfaceDraftOpts): Promise<InterfaceDraftResult>;
|
|
210
|
+
/** 草稿模块文本(人读 + 可复制到 *.nudo.js / *.nudo.ts) */
|
|
211
|
+
declare function formatDraftModule(filePath: string, entries: InterfaceDraftEntry[], sidecarPath?: string): string;
|
|
212
|
+
/** `lib.js|ts` → `lib.nudo.draft.js|ts`(不进 ambient sidecar 表) */
|
|
213
|
+
declare function sidecarDraftPath(filePath: string): string;
|
|
214
|
+
type WriteDraftResult = {
|
|
215
|
+
draftPath: string;
|
|
216
|
+
written: boolean;
|
|
217
|
+
changed: boolean;
|
|
218
|
+
draftable: boolean;
|
|
219
|
+
draftSource: string;
|
|
220
|
+
};
|
|
221
|
+
/** Parse-layer draftable: at least one entry has generated DSL and was not skipped */
|
|
222
|
+
declare function isDraftableEntry(entries: ReadonlyArray<Pick<InterfaceDraftEntry, "dsl" | "skipped">>): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* 写入 `*.nudo.draft.js`(覆盖草稿文件本身;不碰正式 `*.nudo.js`)。
|
|
225
|
+
* 基础路径防护:拒绝 node_modules;拒绝 draft 路径与正式侧车重合;
|
|
226
|
+
* 拒绝 draft 路径落在源文件目录之外的穿越。
|
|
227
|
+
*
|
|
228
|
+
* `opts.entries` / `opts.draftable`:解析层判定(优先)。缺省时用 Unicode
|
|
229
|
+
* 感知 export 正则兜底——`\w` 会静默丢掉 `计算` 这类标识符。
|
|
230
|
+
*/
|
|
231
|
+
declare function writeInterfaceDraft(filePath: string, draftSource: string, opts?: {
|
|
232
|
+
dryRun?: boolean;
|
|
233
|
+
projectDir?: string;
|
|
234
|
+
entries?: ReadonlyArray<Pick<InterfaceDraftEntry, "dsl" | "skipped">>;
|
|
235
|
+
draftable?: boolean;
|
|
236
|
+
}): WriteDraftResult;
|
|
237
|
+
declare function formatDraftSummary(sourceRel: string, draftRel: string, result: InterfaceDraftResult, write?: WriteDraftResult): string[];
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Derivation slot projection(Abs → 组合式 DSL 投影缝)。
|
|
241
|
+
* 自 interface-derivation.ts 机械拆出;语义未改。
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
type ConstraintSourceExpr = {
|
|
245
|
+
expr: string;
|
|
246
|
+
importFrom?: string;
|
|
247
|
+
importName?: string;
|
|
248
|
+
};
|
|
249
|
+
type DerivedParam = {
|
|
250
|
+
name: string;
|
|
251
|
+
constraint: NudoConstraint;
|
|
252
|
+
dsl: string;
|
|
253
|
+
prelude: string[];
|
|
254
|
+
imports: Array<{
|
|
255
|
+
name: string;
|
|
256
|
+
from: string;
|
|
257
|
+
}>;
|
|
258
|
+
/** 单链组合式投影时的推导图 root 节点 id(返回位相对锚定用) */
|
|
259
|
+
rootNodeId?: number;
|
|
260
|
+
/** 该参数位自 root 起消耗的 shift 步数(与 prelude 行数无关,读图) */
|
|
261
|
+
shiftCount?: number;
|
|
262
|
+
};
|
|
263
|
+
type DerivedExport = {
|
|
264
|
+
file: string;
|
|
265
|
+
fn: string;
|
|
266
|
+
paramNames: string[];
|
|
267
|
+
params: DerivedParam[];
|
|
268
|
+
returns?: {
|
|
269
|
+
constraint: NudoConstraint;
|
|
270
|
+
dsl: string;
|
|
271
|
+
prelude: string[];
|
|
272
|
+
imports: Array<{
|
|
273
|
+
name: string;
|
|
274
|
+
from: string;
|
|
275
|
+
}>;
|
|
276
|
+
};
|
|
277
|
+
/** `lib.js:add4` */
|
|
278
|
+
derivedFrom: string;
|
|
279
|
+
compositional: boolean;
|
|
280
|
+
underivable?: boolean;
|
|
281
|
+
};
|
|
282
|
+
type RootDeriveOpts = {
|
|
283
|
+
loadModule?: LoadModule;
|
|
284
|
+
autoBind?: boolean;
|
|
285
|
+
fnNames?: string[];
|
|
286
|
+
/**
|
|
287
|
+
* true:只刷新目标侧车里**已存在**的 @generated 段(CLI 无 --fn/--all 时
|
|
288
|
+
* 的默认行为——不发明新下游契约)。false/省略:闭包内全部可推导导出。
|
|
289
|
+
*/
|
|
290
|
+
refreshExistingOnly?: boolean;
|
|
291
|
+
};
|
|
292
|
+
type RootDeriveResult = {
|
|
293
|
+
roots: string[];
|
|
294
|
+
derived: DerivedExport[];
|
|
295
|
+
hasRoot: boolean;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
declare function extractFnConstraintSources(sidecarSrc: string, fnName: string): {
|
|
299
|
+
params: Record<string, ConstraintSourceExpr>;
|
|
300
|
+
returns?: ConstraintSourceExpr;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* 入口:对 filePath 做 root 驱动下行推导。
|
|
304
|
+
*/
|
|
305
|
+
declare function deriveFromRoot(filePath: string, opts?: RootDeriveOpts): RootDeriveResult;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 组装生成段(组合式 + import + prelude)。
|
|
309
|
+
* importFrom 相对 root 侧车解析,再相对 target 侧车写出。
|
|
310
|
+
*
|
|
311
|
+
* `takenNames`:侧车顶层已占用标识符(手写 / 既有生成段 / 本批先前段)。
|
|
312
|
+
* 同文件多导出时对 import local 与 prelude local 做避让改写,
|
|
313
|
+
* 保证拼出的侧车在模块作用域内无重复声明。
|
|
314
|
+
*/
|
|
315
|
+
declare function formatDerivedSection(row: DerivedExport, opts: {
|
|
316
|
+
rootSidecarDir: string;
|
|
317
|
+
targetSidecarDir: string;
|
|
318
|
+
takenNames?: Iterable<string>;
|
|
319
|
+
}): {
|
|
320
|
+
text: string;
|
|
321
|
+
usedNames: string[];
|
|
322
|
+
} | undefined;
|
|
323
|
+
|
|
324
|
+
type EmitDerivedResult = {
|
|
325
|
+
/** 被写/将写的下游侧车(绝对路径) */
|
|
326
|
+
sidecars: Array<{
|
|
327
|
+
file: string;
|
|
328
|
+
sidecarPath: string;
|
|
329
|
+
fn: string;
|
|
330
|
+
written: boolean;
|
|
331
|
+
changed: boolean;
|
|
332
|
+
skipped?: "name-clash" | "not-projectable" | "underivable" | "no-change";
|
|
333
|
+
diff?: string;
|
|
334
|
+
issues: Array<{
|
|
335
|
+
code: string;
|
|
336
|
+
severity: "error" | "warning" | "info";
|
|
337
|
+
message: string;
|
|
338
|
+
}>;
|
|
339
|
+
}>;
|
|
340
|
+
hasRoot: boolean;
|
|
341
|
+
roots: string[];
|
|
342
|
+
/** 根在别处 / 无契约根且无已存在生成段 → info */
|
|
343
|
+
entryOnly?: boolean;
|
|
344
|
+
};
|
|
345
|
+
declare function emitDerivedFromRoot(rootFile: string, opts: {
|
|
346
|
+
fnNames?: string[];
|
|
347
|
+
mode: "add" | "update";
|
|
348
|
+
dryRun?: boolean;
|
|
349
|
+
loadModule?: LoadModule;
|
|
350
|
+
autoBind?: boolean;
|
|
351
|
+
/** 只刷新目标侧车里已存在的 @generated 段(不发明新下游契约) */
|
|
352
|
+
refreshExistingOnly?: boolean;
|
|
353
|
+
}): EmitDerivedResult;
|
|
354
|
+
|
|
355
|
+
type TypeBinding = {
|
|
356
|
+
name: string;
|
|
357
|
+
type: string;
|
|
358
|
+
};
|
|
359
|
+
/** agent 面类型表达式 → `@nudo:as` 文法 */
|
|
360
|
+
declare function typeExprToDirective(expr: string): string;
|
|
361
|
+
declare function injectBindings(source: string, bindings: TypeBinding[]): {
|
|
362
|
+
source: string;
|
|
363
|
+
applied: string[];
|
|
364
|
+
unapplied: string[];
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
export { typeExprToDirective as A, writeInterfaceDraft as B, type ConstraintSourceExpr as C, type DerivedExport as D, type EmitDerivedResult as E, type InterfaceDraftEntry as I, type LoadModule as L, type RootDeriveOpts as R, type TypeBinding as T, type WriteDraftResult as W, type DerivedParam as a, type DraftEvidence as b, type EmitInterfaceOpts as c, type EmitInterfaceResult as d, type EmitInterfaceSkipReason as e, type InterfaceDraftOpts as f, type InterfaceDraftResult as g, type InterfaceSurfaceEntry as h, type InterfaceSurfaceOpts as i, type RootDeriveResult as j, collectParamBodyAccesses as k, defaultLoadModule as l, deriveFromRoot as m, draftInterface as n, emitDerivedFromRoot as o, emitInterface as p, extractFnConstraintSources as q, formatDerivedSection as r, formatDraftModule as s, formatDraftSummary as t, formatEmitSummary as u, formatInterfaceSurfaceLine as v, injectBindings as w, interfaceSurface as x, isDraftableEntry as y, sidecarDraftPath as z };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { C as ConstraintSourceExpr, D as DerivedExport, a as DerivedParam, b as DraftEvidence, E as EmitDerivedResult, c as EmitInterfaceOpts, d as EmitInterfaceResult, e as EmitInterfaceSkipReason, I as InterfaceDraftEntry, f as InterfaceDraftOpts, g as InterfaceDraftResult, h as InterfaceSurfaceEntry, i as InterfaceSurfaceOpts, R as RootDeriveOpts, j as RootDeriveResult, T as TypeBinding, W as WriteDraftResult, k as collectParamBodyAccesses, m as deriveFromRoot, n as draftInterface, o as emitDerivedFromRoot, p as emitInterface, q as extractFnConstraintSources, r as formatDerivedSection, s as formatDraftModule, t as formatDraftSummary, u as formatEmitSummary, v as formatInterfaceSurfaceLine, w as injectBindings, x as interfaceSurface, y as isDraftableEntry, z as sidecarDraftPath, A as typeExprToDirective, B as writeInterfaceDraft } from './interface-BGlP7aIk.js';
|
|
2
|
+
import './call-record-CkyCFkT9.js';
|
|
3
|
+
import '@nudojs/core';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectParamBodyAccesses,
|
|
3
|
+
deriveFromRoot,
|
|
4
|
+
draftInterface,
|
|
5
|
+
emitDerivedFromRoot,
|
|
6
|
+
emitInterface,
|
|
7
|
+
extractFnConstraintSources,
|
|
8
|
+
formatDerivedSection,
|
|
9
|
+
formatDraftModule,
|
|
10
|
+
formatDraftSummary,
|
|
11
|
+
formatEmitSummary,
|
|
12
|
+
formatInterfaceSurfaceLine,
|
|
13
|
+
injectBindings,
|
|
14
|
+
interfaceSurface,
|
|
15
|
+
isDraftableEntry,
|
|
16
|
+
sidecarDraftPath,
|
|
17
|
+
typeExprToDirective,
|
|
18
|
+
writeInterfaceDraft
|
|
19
|
+
} from "./chunk-HEU4WON5.js";
|
|
20
|
+
import "./chunk-YLVZMHWC.js";
|
|
21
|
+
import "./chunk-QAFMPM2E.js";
|
|
22
|
+
import "./chunk-U7JYTRIB.js";
|
|
23
|
+
import "./chunk-YLALZXTZ.js";
|
|
24
|
+
import "./chunk-PVJIMQRI.js";
|
|
25
|
+
export {
|
|
26
|
+
collectParamBodyAccesses,
|
|
27
|
+
deriveFromRoot,
|
|
28
|
+
draftInterface,
|
|
29
|
+
emitDerivedFromRoot,
|
|
30
|
+
emitInterface,
|
|
31
|
+
extractFnConstraintSources,
|
|
32
|
+
formatDerivedSection,
|
|
33
|
+
formatDraftModule,
|
|
34
|
+
formatDraftSummary,
|
|
35
|
+
formatEmitSummary,
|
|
36
|
+
formatInterfaceSurfaceLine,
|
|
37
|
+
injectBindings,
|
|
38
|
+
interfaceSurface,
|
|
39
|
+
isDraftableEntry,
|
|
40
|
+
sidecarDraftPath,
|
|
41
|
+
typeExprToDirective,
|
|
42
|
+
writeInterfaceDraft
|
|
43
|
+
};
|
package/dist/lsp.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { InterfaceSource, Abs, InterfaceTierOpts } from '@nudojs/core';
|
|
2
|
+
import { S as SourceLocation, c as CompletionItem } from './analyzer-types-JyJiCt8w.js';
|
|
3
|
+
export { AbsInlay, collectAbsInlays } from '@nudojs/core/internal';
|
|
4
|
+
import '@babel/types';
|
|
5
|
+
|
|
6
|
+
type CaseInfo = {
|
|
7
|
+
functionName: string;
|
|
8
|
+
caseName: string;
|
|
9
|
+
caseIndex: number;
|
|
10
|
+
};
|
|
11
|
+
declare function getCasesForFile(filePath: string, source: string): {
|
|
12
|
+
functionName: string;
|
|
13
|
+
cases: {
|
|
14
|
+
name: string;
|
|
15
|
+
index: number;
|
|
16
|
+
}[];
|
|
17
|
+
loc: SourceLocation;
|
|
18
|
+
}[];
|
|
19
|
+
/** Async entry to getTypeAtPosition with path-env preloading (see analyzeFileAsync). */
|
|
20
|
+
declare function getTypeAtPositionAsync(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Promise<Abs | null>;
|
|
21
|
+
/** Async entry to getAbsAtPosition(与 getTypeAtPositionAsync 同预加载口径) */
|
|
22
|
+
declare function getAbsAtPositionAsync(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Promise<Abs | null>;
|
|
23
|
+
/**
|
|
24
|
+
* 光标处无损 Abs。B-path 节点表优先;用例函数体走 Abs 重放。
|
|
25
|
+
*/
|
|
26
|
+
declare function getAbsAtPosition(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Abs | null;
|
|
27
|
+
/** 光标处类型(Abs)。B-path 节点表优先;用例函数体走 Abs 重放。 */
|
|
28
|
+
declare function getTypeAtPosition(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>): Abs | null;
|
|
29
|
+
type HoverInfo = {
|
|
30
|
+
/** 外延展示(formatShape / formatAbs) */
|
|
31
|
+
typeText: string;
|
|
32
|
+
/** 内涵签名(代数 generalize) */
|
|
33
|
+
intension?: string;
|
|
34
|
+
/** 无损 Abs 单行展示(shape / term / pred / conf) */
|
|
35
|
+
abs?: string;
|
|
36
|
+
/** 无损 Abs 多行展示 */
|
|
37
|
+
absMultiline?: string;
|
|
38
|
+
/** CodeLens `● interface` 同源档位(A7);仅本地 named export */
|
|
39
|
+
interfaceSource?: InterfaceSource;
|
|
40
|
+
/** 有效契约展示(handwritten/generated);implicit 为 undefined */
|
|
41
|
+
interfaceDisplay?: string;
|
|
42
|
+
};
|
|
43
|
+
/** A7:hover/inlay 与 CodeLens interface 档同源(design-refine-derivation §8) */
|
|
44
|
+
type HoverInterfaceOpts = InterfaceTierOpts;
|
|
45
|
+
/**
|
|
46
|
+
* LSP hover:优先无损 Abs(类型即计算本体)。
|
|
47
|
+
* 节点表也是 Abs(collectAbsNodeTypes),不经 bridge。
|
|
48
|
+
*
|
|
49
|
+
* 函数名/调用 callee 位置(design-hof-relations §7):
|
|
50
|
+
* intension 一律走 generalize/formatPoly(HOF fnRels 在这里);
|
|
51
|
+
* typeText 仍落 B-path Abs(调用点显示结果类型,不是函数签名)。
|
|
52
|
+
* 禁止用 B-path 的 arity-only fn Abs 冒充权威关系源。
|
|
53
|
+
*
|
|
54
|
+
* A7 default 档:函数名 hover 附带 interfaceTierOf 来源 + 契约展示,
|
|
55
|
+
* 与 CodeLens `● interface / <source>` 同源;选 case 时 body 仍走
|
|
56
|
+
* activeCases 重放,interface 档标注不变。
|
|
57
|
+
*/
|
|
58
|
+
declare function getHoverAtPosition(filePath: string, source: string, line: number, column: number, activeCases?: Map<string, number>, opts?: HoverInterfaceOpts): HoverInfo | null;
|
|
59
|
+
declare function getCompletionsAtPosition(filePath: string, source: string, line: number, column: number): CompletionItem[];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Semantic tokens 图例(tokenTypes 下标即 LSP 编码里的 tokenType 值)。
|
|
63
|
+
* 与 LSP server capabilities 里声明的 legend 必须逐字对齐——server.ts 直接
|
|
64
|
+
* 导入本常量注册,保证「提取端索引」与「客户端图例」单一来源。
|
|
65
|
+
* 顺序沿用 lsp 包原 legend(function/variable/parameter/property 在前),
|
|
66
|
+
* 末尾追加 method(对象字面量方法键)与 interface 档 modifier(A7),
|
|
67
|
+
* 只追加不重排,客户端索引稳定。
|
|
68
|
+
*/
|
|
69
|
+
declare const SEMANTIC_TOKEN_TYPES: readonly ["function", "variable", "parameter", "property", "type", "keyword", "string", "number", "comment", "decorator", "method"];
|
|
70
|
+
declare const SEMANTIC_TOKEN_MODIFIERS: readonly ["declaration", "readonly", "deprecated", "unreachable", "contract", "generated", "derived"];
|
|
71
|
+
type SemanticToken = {
|
|
72
|
+
line: number;
|
|
73
|
+
char: number;
|
|
74
|
+
length: number;
|
|
75
|
+
typeIndex: number;
|
|
76
|
+
modifierBitmask: number;
|
|
77
|
+
};
|
|
78
|
+
/** LSP 标准相对五元组编码:deltaLine/deltaStartChar/length/tokenType/tokenModifiers。 */
|
|
79
|
+
declare function encodeSemanticTokens(tokens: SemanticToken[]): number[];
|
|
80
|
+
/** A7:interface 档 → semantic token modifier(与 CodeLens 同源) */
|
|
81
|
+
declare function interfaceTierModifierBit(src: InterfaceSource): number;
|
|
82
|
+
type BuildSemanticTokensOpts = InterfaceTierOpts & {
|
|
83
|
+
loadModule?: (spec: string, fromFile: string) => string | undefined;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* 从源码提取 semantic tokens 并按 LSP 相对编码返回扁平 number[]。
|
|
87
|
+
*
|
|
88
|
+
* 上色范围(声明位优先,未解析的 token 一律不上色):
|
|
89
|
+
* - 顶层 const/let/var 声明的绑定名:推断为函数绑定 → function,否则 variable
|
|
90
|
+
* (函数体内部的声明不做 env 反查——外层同名绑定会串味,统一 variable);
|
|
91
|
+
* - 函数声明/函数表达式的名字 → function;所有函数的参数 → parameter;
|
|
92
|
+
* - 对象字面量的键:值为函数 → method,否则 property。
|
|
93
|
+
*
|
|
94
|
+
* A7:本地 named export 的函数绑定额外带 interface 档 modifier
|
|
95
|
+
* (contract / generated / derived),与 CodeLens `● interface` 同源。
|
|
96
|
+
* 非导出绑定只带 declaration,不假装进档。
|
|
97
|
+
*
|
|
98
|
+
* 推断优先 Abs 模块图绑定(TypeValue 退出主路径);失败时复用
|
|
99
|
+
* evaluateProgram。解析失败返回 []。
|
|
100
|
+
*/
|
|
101
|
+
declare function buildSemanticTokens(filePath: string, source: string, opts?: BuildSemanticTokensOpts): number[];
|
|
102
|
+
|
|
103
|
+
export { type BuildSemanticTokensOpts, type CaseInfo, type HoverInfo, SEMANTIC_TOKEN_MODIFIERS, SEMANTIC_TOKEN_TYPES, type SemanticToken, buildSemanticTokens, encodeSemanticTokens, getAbsAtPosition, getAbsAtPositionAsync, getCasesForFile, getCompletionsAtPosition, getHoverAtPosition, getTypeAtPosition, getTypeAtPositionAsync, interfaceTierModifierBit };
|
package/dist/lsp.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SEMANTIC_TOKEN_MODIFIERS,
|
|
3
|
+
SEMANTIC_TOKEN_TYPES,
|
|
4
|
+
buildSemanticTokens,
|
|
5
|
+
encodeSemanticTokens,
|
|
6
|
+
getAbsAtPosition,
|
|
7
|
+
getAbsAtPositionAsync,
|
|
8
|
+
getCasesForFile,
|
|
9
|
+
getCompletionsAtPosition,
|
|
10
|
+
getHoverAtPosition,
|
|
11
|
+
getTypeAtPosition,
|
|
12
|
+
getTypeAtPositionAsync,
|
|
13
|
+
interfaceTierModifierBit
|
|
14
|
+
} from "./chunk-E4N4A4JV.js";
|
|
15
|
+
import "./chunk-QAFMPM2E.js";
|
|
16
|
+
import "./chunk-U7JYTRIB.js";
|
|
17
|
+
import "./chunk-YLALZXTZ.js";
|
|
18
|
+
import "./chunk-PVJIMQRI.js";
|
|
19
|
+
|
|
20
|
+
// src/lsp.ts
|
|
21
|
+
import { collectAbsInlays } from "@nudojs/core/internal";
|
|
22
|
+
export {
|
|
23
|
+
SEMANTIC_TOKEN_MODIFIERS,
|
|
24
|
+
SEMANTIC_TOKEN_TYPES,
|
|
25
|
+
buildSemanticTokens,
|
|
26
|
+
collectAbsInlays,
|
|
27
|
+
encodeSemanticTokens,
|
|
28
|
+
getAbsAtPosition,
|
|
29
|
+
getAbsAtPositionAsync,
|
|
30
|
+
getCasesForFile,
|
|
31
|
+
getCompletionsAtPosition,
|
|
32
|
+
getHoverAtPosition,
|
|
33
|
+
getTypeAtPosition,
|
|
34
|
+
getTypeAtPositionAsync,
|
|
35
|
+
interfaceTierModifierBit
|
|
36
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nudojs/service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-beta.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20"
|
|
6
6
|
},
|
|
@@ -22,6 +22,30 @@
|
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
23
|
"default": "./dist/index.js"
|
|
24
24
|
},
|
|
25
|
+
"./analysis": {
|
|
26
|
+
"types": "./dist/analysis.d.ts",
|
|
27
|
+
"default": "./dist/analysis.js"
|
|
28
|
+
},
|
|
29
|
+
"./interface": {
|
|
30
|
+
"types": "./dist/interface.d.ts",
|
|
31
|
+
"default": "./dist/interface.js"
|
|
32
|
+
},
|
|
33
|
+
"./dts": {
|
|
34
|
+
"types": "./dist/dts.d.ts",
|
|
35
|
+
"default": "./dist/dts.js"
|
|
36
|
+
},
|
|
37
|
+
"./case": {
|
|
38
|
+
"types": "./dist/case.d.ts",
|
|
39
|
+
"default": "./dist/case.js"
|
|
40
|
+
},
|
|
41
|
+
"./lsp": {
|
|
42
|
+
"types": "./dist/lsp.d.ts",
|
|
43
|
+
"default": "./dist/lsp.js"
|
|
44
|
+
},
|
|
45
|
+
"./harvest": {
|
|
46
|
+
"types": "./dist/harvest.d.ts",
|
|
47
|
+
"default": "./dist/harvest.js"
|
|
48
|
+
},
|
|
25
49
|
"./evaluator": {
|
|
26
50
|
"types": "./dist/evaluator/evaluator-api.d.ts",
|
|
27
51
|
"default": "./dist/evaluator/evaluator-api.js"
|
|
@@ -43,14 +67,14 @@
|
|
|
43
67
|
"registry": "https://registry.npmjs.org"
|
|
44
68
|
},
|
|
45
69
|
"dependencies": {
|
|
46
|
-
"@babel/traverse": "^
|
|
47
|
-
"@babel/types": "^
|
|
48
|
-
"@nudojs/
|
|
49
|
-
"@nudojs/
|
|
50
|
-
"@nudojs/env": "0.4.0",
|
|
51
|
-
"@nudojs/harvester": "0.2.
|
|
70
|
+
"@babel/traverse": "^8.0.6",
|
|
71
|
+
"@babel/types": "^8.0.6",
|
|
72
|
+
"@nudojs/parser": "1.1.0-beta.0",
|
|
73
|
+
"@nudojs/core": "3.0.0-beta.0",
|
|
74
|
+
"@nudojs/env": "0.4.2-beta.0",
|
|
75
|
+
"@nudojs/harvester": "0.2.8-beta.0"
|
|
52
76
|
},
|
|
53
77
|
"scripts": {
|
|
54
|
-
"build": "tsup src/index.ts src/evaluator/evaluator-api.ts --format esm --dts"
|
|
78
|
+
"build": "tsup src/index.ts src/analysis.ts src/interface.ts src/dts.ts src/case.ts src/lsp.ts src/harvest.ts src/evaluator/evaluator-api.ts --format esm --dts"
|
|
55
79
|
}
|
|
56
80
|
}
|