@alint-js/core 0.0.4

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,365 @@
1
+ //#region src/config/types.d.ts
2
+ type ModelSize = 'large' | 'medium' | 'small';
3
+ interface ProviderDefinition {
4
+ endpoint: string;
5
+ headers?: Record<string, string>;
6
+ id: string;
7
+ models: SetupModelDefinition[];
8
+ type: ProviderType;
9
+ }
10
+ type ProviderType = 'openai-compatible';
11
+ interface RunnerCacheConfig {
12
+ enabled?: boolean;
13
+ location?: string;
14
+ }
15
+ interface RunnerConfig {
16
+ cache?: boolean | RunnerCacheConfig;
17
+ fileConcurrency?: number;
18
+ ruleConcurrency?: number;
19
+ timeoutMs?: number;
20
+ }
21
+ interface SetupConfig {
22
+ providers: ProviderDefinition[];
23
+ runner?: RunnerConfig;
24
+ version: 1;
25
+ }
26
+ interface SetupModelDefinition {
27
+ aliases?: string[];
28
+ capabilities?: string[];
29
+ contextWindow?: number;
30
+ defaultParams?: Record<string, unknown>;
31
+ id: string;
32
+ name?: string;
33
+ size?: ModelSize;
34
+ }
35
+ //#endregion
36
+ //#region src/core/source/types.d.ts
37
+ interface ClassUnit extends SourceUnit {
38
+ exported: boolean;
39
+ kind: 'class';
40
+ }
41
+ interface FunctionUnit extends SourceUnit {
42
+ async: boolean;
43
+ exported: boolean;
44
+ kind: 'function';
45
+ }
46
+ interface LineRange {
47
+ endLine: number;
48
+ startLine: number;
49
+ }
50
+ interface SourceFile {
51
+ language: 'javascript' | 'typescript' | 'unknown';
52
+ lines: string[];
53
+ path: string;
54
+ text: string;
55
+ }
56
+ interface SourceLocation {
57
+ end: SourcePosition;
58
+ start: SourcePosition;
59
+ }
60
+ interface SourcePosition {
61
+ column: number;
62
+ line: number;
63
+ }
64
+ interface SourceRange {
65
+ end: number;
66
+ start: number;
67
+ }
68
+ interface SourceRuntime {
69
+ getText: (target: SourceFile | SourceUnit) => string;
70
+ readFile: (filePath: string) => Promise<SourceFile>;
71
+ sliceLines: (file: SourceFile, range: LineRange) => SourceText;
72
+ sliceRange: (file: SourceFile, range: SourceRange) => SourceText;
73
+ }
74
+ interface SourceText {
75
+ filePath: string;
76
+ loc: SourceLocation;
77
+ text: string;
78
+ }
79
+ interface SourceUnit {
80
+ file: SourceFile;
81
+ kind: 'class' | 'function';
82
+ loc: SourceLocation;
83
+ name?: string;
84
+ range: SourceRange;
85
+ text: string;
86
+ }
87
+ //#endregion
88
+ //#region src/models/types.d.ts
89
+ interface ModelRequirement {
90
+ capabilities?: string[];
91
+ minContextWindow?: number;
92
+ params?: Record<string, unknown>;
93
+ size?: ModelSize;
94
+ }
95
+ interface ResolvedModel {
96
+ aliases: string[];
97
+ capabilities: string[];
98
+ contextWindow?: number;
99
+ id: string;
100
+ name: string;
101
+ params: Record<string, unknown>;
102
+ provider: ResolvedProvider;
103
+ size?: ModelSize;
104
+ }
105
+ interface ResolvedProvider {
106
+ endpoint: string;
107
+ headers: Record<string, string>;
108
+ id: string;
109
+ type: 'openai-compatible';
110
+ }
111
+ interface ResolveModelOptions {
112
+ request?: string;
113
+ requirement?: ModelRequirement;
114
+ ruleId?: string;
115
+ }
116
+ //#endregion
117
+ //#region src/dsl/types.d.ts
118
+ interface AlintConfig {
119
+ ignore?: IgnoreConfig;
120
+ plugins?: PluginDefinition[];
121
+ rules?: Record<string, RuleConfigEntry>;
122
+ runner?: RunnerConfig;
123
+ }
124
+ type Awaitable<T> = Promise<T> | T;
125
+ interface DiagnosticDescriptor {
126
+ evidence?: unknown;
127
+ filePath?: string;
128
+ loc?: DiagnosticLocation;
129
+ message: string;
130
+ }
131
+ interface DiagnosticLocation {
132
+ end?: {
133
+ column: number;
134
+ line: number;
135
+ };
136
+ start: {
137
+ column: number;
138
+ line: number;
139
+ };
140
+ }
141
+ interface EnabledRule {
142
+ id: string;
143
+ localId: string;
144
+ rule: RuleDefinition;
145
+ scope: string;
146
+ severity: Exclude<RuleSeverity, 'off'>;
147
+ }
148
+ interface IgnoreConfig {
149
+ gitignore?: boolean;
150
+ }
151
+ interface PluginDefinition {
152
+ rules: Record<string, RuleDefinition>;
153
+ scope: string;
154
+ }
155
+ type RuleCacheConfig = boolean | {
156
+ level?: 'target';
157
+ };
158
+ type RuleConfigEntry = [RuleSeverity] | RuleSeverity;
159
+ interface RuleContext {
160
+ cwd: string;
161
+ id: string;
162
+ localId: string;
163
+ logger: {
164
+ debug: (...args: unknown[]) => void;
165
+ };
166
+ metering: {
167
+ recordUsage: (usage: RuleInferenceUsageRecord) => void;
168
+ };
169
+ model: (selector?: ModelRequirement | string) => Promise<ResolvedModel>;
170
+ report: (diagnostic: DiagnosticDescriptor) => void;
171
+ scope: string;
172
+ src: SourceRuntime;
173
+ }
174
+ interface RuleDefinition {
175
+ cache?: RuleCacheConfig;
176
+ create: (context: RuleContext) => RuleHandlers;
177
+ model?: ModelRequirement;
178
+ }
179
+ interface RuleHandlers {
180
+ onClass?: (classNode: ClassUnit) => Awaitable<void>;
181
+ onFile?: (file: SourceFile) => Awaitable<void>;
182
+ onFunction?: (functionNode: FunctionUnit) => Awaitable<void>;
183
+ }
184
+ interface RuleInferenceUsageRecord {
185
+ filePath?: string;
186
+ inputTokens?: number;
187
+ metadata?: unknown;
188
+ modelId: string;
189
+ outputTokens?: number;
190
+ providerId: string;
191
+ ruleId?: string;
192
+ totalTokens?: number;
193
+ }
194
+ interface RuleRegistry {
195
+ enabledRules: EnabledRule[];
196
+ rules: Map<string, RuleDefinition>;
197
+ }
198
+ type RuleSeverity = 'error' | 'off' | 'warn';
199
+ //#endregion
200
+ //#region src/core/types.d.ts
201
+ interface Diagnostic {
202
+ evidence?: unknown;
203
+ filePath: string;
204
+ loc?: DiagnosticLocation;
205
+ message: string;
206
+ model?: {
207
+ providerId: string;
208
+ requested?: string;
209
+ resolvedId: string;
210
+ };
211
+ ruleId: string;
212
+ severity: 'error' | 'warn';
213
+ }
214
+ interface DiagnosticProgressPayload {
215
+ diagnostic: Diagnostic;
216
+ diagnostics: Diagnostic[];
217
+ path?: ProgressPath;
218
+ }
219
+ interface FileProgressPayload {
220
+ endedAt?: number;
221
+ file: ProgressFilePath;
222
+ startedAt?: number;
223
+ }
224
+ type InferenceUsageRecord = Omit<RuleInferenceUsageRecord, 'ruleId'> & {
225
+ ruleId: string;
226
+ };
227
+ interface ProgressFilePath {
228
+ index: number;
229
+ path: string;
230
+ planned?: number;
231
+ total: number;
232
+ }
233
+ interface ProgressPath {
234
+ file: ProgressFilePath;
235
+ rule: {
236
+ id: string;
237
+ index: number;
238
+ total: number;
239
+ };
240
+ target: {
241
+ index: number;
242
+ kind: ProgressTargetKind;
243
+ name?: string;
244
+ total: number;
245
+ };
246
+ }
247
+ interface ProgressReporter {
248
+ onDiagnostic?: (payload: DiagnosticProgressPayload) => void;
249
+ onFileEnd?: (payload: FileProgressPayload) => void;
250
+ onFileStart?: (payload: FileProgressPayload) => void;
251
+ onRuleEnd?: (payload: RuleEndPayload) => void;
252
+ onRuleStart?: (payload: RuleStartPayload) => void;
253
+ onRunEnd?: (payload: RunEndPayload) => void;
254
+ onRunStart?: (payload: RunStartPayload) => void;
255
+ onTargetEnd?: (payload: TargetProgressPayload) => void;
256
+ onTargetStart?: (payload: TargetProgressPayload) => void;
257
+ onUsage?: (payload: UsageProgressPayload) => void;
258
+ }
259
+ type ProgressTargetKind = 'class' | 'file' | 'function';
260
+ interface RuleEndPayload {
261
+ cache: 'hit' | 'miss';
262
+ endedAt?: number;
263
+ path: ProgressPath;
264
+ startedAt?: number;
265
+ state: 'completed' | 'errored';
266
+ }
267
+ interface RuleStartPayload {
268
+ path: ProgressPath;
269
+ startedAt?: number;
270
+ }
271
+ interface RunEndPayload {
272
+ cached: number;
273
+ completed: number;
274
+ diagnostics: Diagnostic[];
275
+ endedAt?: number;
276
+ errored: number;
277
+ planned: number;
278
+ startedAt?: number;
279
+ usage: RunUsage;
280
+ }
281
+ interface RunnerOptions extends RunnerConfig {
282
+ clock?: () => number;
283
+ }
284
+ interface RunOptions {
285
+ config?: AlintConfig;
286
+ cwd?: string;
287
+ files?: string[];
288
+ modelOverride?: string;
289
+ progress?: ProgressReporter;
290
+ runner?: RunnerOptions;
291
+ setupConfig?: SetupConfig;
292
+ }
293
+ interface RunResult {
294
+ diagnostics: Diagnostic[];
295
+ usage: RunUsage;
296
+ }
297
+ interface RunStartPayload {
298
+ files?: ProgressFilePath[];
299
+ filesTotal: number;
300
+ planned: number;
301
+ rulesTotal: number;
302
+ startedAt?: number;
303
+ }
304
+ interface RunUsage {
305
+ inputTokens: number;
306
+ outputTokens: number;
307
+ records: InferenceUsageRecord[];
308
+ totalTokens: number;
309
+ }
310
+ interface TargetProgressPayload {
311
+ endedAt?: number;
312
+ path: ProgressPath;
313
+ startedAt?: number;
314
+ }
315
+ interface UsageProgressPayload {
316
+ path?: ProgressPath;
317
+ record: InferenceUsageRecord;
318
+ total: RunUsage;
319
+ }
320
+ //#endregion
321
+ //#region src/core/run.d.ts
322
+ interface AlintRunFailure {
323
+ filePath?: string;
324
+ message: string;
325
+ ruleId?: string;
326
+ target?: {
327
+ kind: ProgressTargetKind;
328
+ name?: string;
329
+ };
330
+ }
331
+ declare class AlintRunError extends Error {
332
+ readonly failure?: AlintRunFailure;
333
+ readonly result: RunResult;
334
+ constructor(message: string, result: RunResult, options?: {
335
+ cause?: unknown;
336
+ failure?: AlintRunFailure;
337
+ });
338
+ }
339
+ declare function runAlint(options?: RunOptions): Promise<RunResult>;
340
+ //#endregion
341
+ //#region src/core/source/js.d.ts
342
+ interface JsSourceUnits {
343
+ classes: ClassUnit[];
344
+ functions: FunctionUnit[];
345
+ }
346
+ declare function extractJsSourceUnits(file: SourceFile): JsSourceUnits;
347
+ //#endregion
348
+ //#region src/core/source/runtime.d.ts
349
+ declare function createSourceFile(path: string, text: string): SourceFile;
350
+ declare function createSourceRuntime(): SourceRuntime;
351
+ declare function sliceLines(file: SourceFile, range: LineRange): SourceText;
352
+ declare function sliceRange(file: SourceFile, range: SourceRange): SourceText;
353
+ //#endregion
354
+ //#region src/dsl/define.d.ts
355
+ declare function defineConfig(config: AlintConfig): AlintConfig;
356
+ declare function definePlugin(plugin: PluginDefinition): PluginDefinition;
357
+ declare function defineRule(rule: RuleDefinition): RuleDefinition;
358
+ //#endregion
359
+ //#region src/dsl/registry.d.ts
360
+ declare function buildRuleRegistry(config: AlintConfig): RuleRegistry;
361
+ //#endregion
362
+ //#region src/models/resolve.d.ts
363
+ declare function resolveModel(registry: SetupConfig, options?: ResolveModelOptions): ResolvedModel;
364
+ //#endregion
365
+ export { type AlintConfig, AlintRunError, type Awaitable, type ClassUnit, type Diagnostic, type DiagnosticDescriptor, type DiagnosticLocation, type DiagnosticProgressPayload, type EnabledRule, type FileProgressPayload, type FunctionUnit, type IgnoreConfig, type InferenceUsageRecord, type LineRange, type ModelRequirement, type ModelSize, type PluginDefinition, type ProgressFilePath, type ProgressPath, type ProgressReporter, type ProgressTargetKind, type ProviderDefinition, type ProviderType, type ResolveModelOptions, type ResolvedModel, type ResolvedProvider, type RuleConfigEntry, type RuleContext, type RuleDefinition, type RuleEndPayload, type RuleHandlers, type RuleInferenceUsageRecord, type RuleRegistry, type RuleSeverity, type RuleStartPayload, type RunEndPayload, type RunOptions, type RunResult, type RunStartPayload, type RunUsage, type RunnerConfig, type SetupConfig, type SetupModelDefinition, type SourceFile, type SourceLocation, type SourcePosition, type SourceRange, type SourceRuntime, type SourceText, type SourceUnit, type TargetProgressPayload, type UsageProgressPayload, buildRuleRegistry, createSourceFile, createSourceRuntime, defineConfig, definePlugin, defineRule, extractJsSourceUnits, resolveModel, runAlint, sliceLines, sliceRange };