@shipispec/tsfix 0.1.0 → 0.3.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/CHANGELOG.md +104 -0
- package/README.md +144 -86
- package/dist/cli.js +724 -0
- package/dist/index.d.ts +176 -0
- package/dist/index.js +576 -0
- package/dist/types/index.d.ts +176 -0
- package/dist/types/tsLanguageServiceFixer.d.ts +124 -0
- package/dist/types/validatorInProcess.d.ts +64 -0
- package/package.json +19 -16
- package/bin/tsfix.mjs +0 -49
- package/cli/run-stack.ts +0 -195
- package/src/index.ts +0 -202
- package/src/tsLanguageServiceFixer.ts +0 -486
- package/src/validatorInProcess.ts +0 -276
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @shipispec/tsfix — public API.
|
|
3
|
+
*
|
|
4
|
+
* A reusable TypeScript error-recovery agent. Validates LLM-generated (or any)
|
|
5
|
+
* TypeScript code via in-process tsc, auto-fixes deterministic error classes
|
|
6
|
+
* (TS2304/2305/2552/2724) via TypeScript's built-in code-fix engine, and
|
|
7
|
+
* exposes hooks for LLM-driven repair (planned, not yet shipped).
|
|
8
|
+
*
|
|
9
|
+
* ## Quick start (library)
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { runValidationLoop } from "@shipispec/tsfix";
|
|
13
|
+
*
|
|
14
|
+
* const result = await runValidationLoop({
|
|
15
|
+
* workspaceRoot: "/path/to/your/project",
|
|
16
|
+
* targetFiles: ["src/index.ts", "src/utils.ts"],
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* console.log(result.passed, result.errorsAfter, result.lspFixer.fixesApplied);
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ## Quick start (CLI)
|
|
23
|
+
*
|
|
24
|
+
* ```
|
|
25
|
+
* npx @shipispec/tsfix --workspace ./my-project
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ## Layered API
|
|
29
|
+
*
|
|
30
|
+
* - `runValidationLoop` — full deterministic loop (recommended entry point)
|
|
31
|
+
* - `runInProcessTsc` — just type-check, returns structured diagnostics
|
|
32
|
+
* - `runLSPFixerPass` — just the auto-fix pass, edits files in place
|
|
33
|
+
*
|
|
34
|
+
* ## Public types for downstream LLM-mend integrations
|
|
35
|
+
*
|
|
36
|
+
* - `Diagnostic` — single tsc error (re-exported from `runInProcessTsc`)
|
|
37
|
+
* - `MendContext` — input contract for a Layer 2–4 LLM-mend agent
|
|
38
|
+
* - `LayerEvent` — per-layer event shape for streaming telemetry
|
|
39
|
+
*
|
|
40
|
+
* The mend agents themselves (`@shipispec/tsmend`, planned) consume these
|
|
41
|
+
* types but are not shipped from this package — `tsfix` stays Layer 0–1
|
|
42
|
+
* deterministic.
|
|
43
|
+
*/
|
|
44
|
+
export { runInProcessTsc, isInProcessTscEnabled, resetInProcessTscCache } from "./validatorInProcess.js";
|
|
45
|
+
export type { InProcessTscOptions, InProcessTscResult } from "./validatorInProcess.js";
|
|
46
|
+
export { runLSPFixerPass, isLSPFixerEnabled, resetLSPFixerCache } from "./tsLanguageServiceFixer.js";
|
|
47
|
+
export type { LSPFixerOptions, LSPFixerResult, LSPFixerLogger } from "./tsLanguageServiceFixer.js";
|
|
48
|
+
import { type InProcessTscResult } from "./validatorInProcess.js";
|
|
49
|
+
/** Logger shape required by the validation/fix loop. Plain object with three methods. */
|
|
50
|
+
export interface Logger {
|
|
51
|
+
info(msg: string): void;
|
|
52
|
+
warn(msg: string): void;
|
|
53
|
+
error(msg: string): void;
|
|
54
|
+
}
|
|
55
|
+
export interface ValidationLoopOptions {
|
|
56
|
+
/** Absolute path to the workspace (must contain `tsconfig.json`). */
|
|
57
|
+
workspaceRoot: string;
|
|
58
|
+
/**
|
|
59
|
+
* Files to scope the type-check + fix to. If omitted, all .ts/.tsx files
|
|
60
|
+
* under `workspaceRoot` (excluding node_modules, .next, dist, build, .git)
|
|
61
|
+
* are discovered.
|
|
62
|
+
*/
|
|
63
|
+
targetFiles?: string[];
|
|
64
|
+
/** Skip Layer 0 LSP auto-fixer. Default false. */
|
|
65
|
+
skipLSPFixer?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Run the LSP fixer in memory but do NOT persist edits to disk. The
|
|
68
|
+
* returned `lspFixer.filesEdited` lists files that *would* have been
|
|
69
|
+
* written. Useful for previewing changes before letting tsfix mutate a
|
|
70
|
+
* workspace. Default false.
|
|
71
|
+
*/
|
|
72
|
+
dryRun?: boolean;
|
|
73
|
+
/** Default: a no-op logger. Pass your own to capture layer events. */
|
|
74
|
+
logger?: Logger;
|
|
75
|
+
}
|
|
76
|
+
export interface ValidationLoopResult {
|
|
77
|
+
passed: boolean;
|
|
78
|
+
errorsBefore: number;
|
|
79
|
+
errorsAfter: number;
|
|
80
|
+
lspFixer: {
|
|
81
|
+
ran: boolean;
|
|
82
|
+
fixesApplied: number;
|
|
83
|
+
filesEdited: string[];
|
|
84
|
+
iterations: number;
|
|
85
|
+
};
|
|
86
|
+
remainingByCode: Record<string, number>;
|
|
87
|
+
remainingByFile: Record<string, number>;
|
|
88
|
+
diagnostics: InProcessTscResult["diagnostics"];
|
|
89
|
+
elapsedMs: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Discover all `.ts` / `.tsx` files under a workspace, excluding common
|
|
93
|
+
* non-source dirs. Skips `.d.ts` declaration files.
|
|
94
|
+
*/
|
|
95
|
+
export declare function discoverTsFiles(workspaceRoot: string): string[];
|
|
96
|
+
/**
|
|
97
|
+
* Run the full deterministic validation + fix loop:
|
|
98
|
+
*
|
|
99
|
+
* 1. In-process tsc → capture baseline diagnostics
|
|
100
|
+
* 2. If errors AND not `skipLSPFixer`, run Layer 0 LSP auto-fix
|
|
101
|
+
* 3. If fixes were applied, re-run in-process tsc to capture post-fix state
|
|
102
|
+
* 4. Return aggregated result
|
|
103
|
+
*
|
|
104
|
+
* Throws on missing `tsconfig.json` or workspace path.
|
|
105
|
+
*/
|
|
106
|
+
export declare function runValidationLoop(opts: ValidationLoopOptions): ValidationLoopResult;
|
|
107
|
+
/**
|
|
108
|
+
* Single tsc diagnostic. Re-exported from `runInProcessTsc`'s result type
|
|
109
|
+
* so consumers building a `MendContext` don't have to dig the shape out of
|
|
110
|
+
* `InProcessTscResult["diagnostics"][number]`.
|
|
111
|
+
*/
|
|
112
|
+
export type Diagnostic = InProcessTscResult["diagnostics"][number];
|
|
113
|
+
/**
|
|
114
|
+
* Input contract for a Layer 2–4 LLM-mend agent.
|
|
115
|
+
*
|
|
116
|
+
* Pattern:
|
|
117
|
+
* 1. Run `runValidationLoop` (Layer 0/1).
|
|
118
|
+
* 2. If `result.errorsAfter > 0`, build a `MendContext` from the
|
|
119
|
+
* surviving diagnostics + whatever task/spec context your pipeline has.
|
|
120
|
+
* 3. Hand off to a mend agent (e.g. `@shipispec/tsmend`).
|
|
121
|
+
*
|
|
122
|
+
* Required fields: `workspaceRoot`, `diagnostics`, `erroredFiles`.
|
|
123
|
+
* Everything else is optional — leave fields out if your pipeline doesn't
|
|
124
|
+
* carry them.
|
|
125
|
+
*/
|
|
126
|
+
export interface MendContext {
|
|
127
|
+
/** Absolute path to the workspace (must contain `tsconfig.json`). */
|
|
128
|
+
workspaceRoot: string;
|
|
129
|
+
/** Diagnostics that survived Layer 0/1 and need higher-layer repair. */
|
|
130
|
+
diagnostics: Diagnostic[];
|
|
131
|
+
/** Absolute paths of files containing the surviving diagnostics. */
|
|
132
|
+
erroredFiles: string[];
|
|
133
|
+
/** Optional one-line summary of what the failing code was supposed to do. */
|
|
134
|
+
taskDescription?: string;
|
|
135
|
+
/** Optional Markdown spec the code is implementing. Helps the LLM understand intent. */
|
|
136
|
+
featureSpecText?: string;
|
|
137
|
+
/** Optional testable acceptance criteria from the spec. */
|
|
138
|
+
acceptanceCriteria?: string;
|
|
139
|
+
/** Other tasks in the same feature, with their files and current status. */
|
|
140
|
+
siblingTasks?: Array<{
|
|
141
|
+
description: string;
|
|
142
|
+
files: string[];
|
|
143
|
+
status: "pending" | "completed" | "failed";
|
|
144
|
+
}>;
|
|
145
|
+
/** Public API surface from earlier completed tasks (helps prevent re-defining symbols). */
|
|
146
|
+
priorTaskExports?: string;
|
|
147
|
+
/** Compact type signatures of installed npm dependencies (helps prevent API hallucination). */
|
|
148
|
+
installedTypes?: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Per-layer event for streaming telemetry across the validate → fix → mend
|
|
152
|
+
* chain. Designed for an `onLayerEvent` callback (added in a future minor
|
|
153
|
+
* release) rather than accumulating in a result array — a workspace with
|
|
154
|
+
* 200 errors emits ~1000 events.
|
|
155
|
+
*
|
|
156
|
+
* Layer assignments:
|
|
157
|
+
* 0 = prevention (prompt rules, exported-API injection — caller's problem)
|
|
158
|
+
* 1 = tsfix LSP fixer (this package)
|
|
159
|
+
* 2 = single-file LLM mend
|
|
160
|
+
* 3 = multi-file LLM mend (blast-radius search/replace)
|
|
161
|
+
* 4 = stub-and-continue (escape hatch)
|
|
162
|
+
*/
|
|
163
|
+
export interface LayerEvent {
|
|
164
|
+
/** Which layer ran. */
|
|
165
|
+
layer: 0 | 1 | 2 | 3 | 4;
|
|
166
|
+
/** TypeScript error code being acted on (e.g. 2304, 2339, 7006). */
|
|
167
|
+
errorCode: number;
|
|
168
|
+
/** True if the error was resolved by this layer. */
|
|
169
|
+
fixed: boolean;
|
|
170
|
+
/** Wall-clock time spent on this attempt. */
|
|
171
|
+
latencyMs: number;
|
|
172
|
+
/** USD cost (LLM tokens). Undefined for deterministic layers. */
|
|
173
|
+
costUsd?: number;
|
|
174
|
+
/** `Date.now()` at emission. */
|
|
175
|
+
ts: number;
|
|
176
|
+
}
|