guardrail-core 1.0.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.
Files changed (189) hide show
  1. package/dist/__tests__/autopilot.test.d.ts +7 -0
  2. package/dist/__tests__/autopilot.test.d.ts.map +1 -0
  3. package/dist/__tests__/autopilot.test.js +156 -0
  4. package/dist/__tests__/tier-config.test.d.ts +9 -0
  5. package/dist/__tests__/tier-config.test.d.ts.map +1 -0
  6. package/dist/__tests__/tier-config.test.js +230 -0
  7. package/dist/__tests__/utils/hash-inline.test.d.ts +2 -0
  8. package/dist/__tests__/utils/hash-inline.test.d.ts.map +1 -0
  9. package/dist/__tests__/utils/hash-inline.test.js +62 -0
  10. package/dist/__tests__/utils/hash.test.d.ts +3 -0
  11. package/dist/__tests__/utils/hash.test.d.ts.map +1 -0
  12. package/dist/__tests__/utils/hash.test.js +95 -0
  13. package/dist/__tests__/utils/simple.test.d.ts +1 -0
  14. package/dist/__tests__/utils/simple.test.d.ts.map +1 -0
  15. package/dist/__tests__/utils/simple.test.js +10 -0
  16. package/dist/__tests__/utils/utils-simple.test.d.ts +1 -0
  17. package/dist/__tests__/utils/utils-simple.test.d.ts.map +1 -0
  18. package/dist/__tests__/utils/utils-simple.test.js +6 -0
  19. package/dist/__tests__/utils/utils.test.d.ts +15 -0
  20. package/dist/__tests__/utils/utils.test.d.ts.map +1 -0
  21. package/dist/__tests__/utils/utils.test.js +172 -0
  22. package/dist/autopilot/autopilot-runner.d.ts +33 -0
  23. package/dist/autopilot/autopilot-runner.d.ts.map +1 -0
  24. package/dist/autopilot/autopilot-runner.js +479 -0
  25. package/dist/autopilot/index.d.ts +6 -0
  26. package/dist/autopilot/index.d.ts.map +1 -0
  27. package/dist/autopilot/index.js +25 -0
  28. package/dist/autopilot/types.d.ts +102 -0
  29. package/dist/autopilot/types.d.ts.map +1 -0
  30. package/dist/autopilot/types.js +18 -0
  31. package/dist/cache/index.d.ts +7 -0
  32. package/dist/cache/index.d.ts.map +1 -0
  33. package/dist/cache/index.js +22 -0
  34. package/dist/cache/redis-cache.d.ts +145 -0
  35. package/dist/cache/redis-cache.d.ts.map +1 -0
  36. package/dist/cache/redis-cache.js +459 -0
  37. package/dist/ci/github-actions.d.ts +77 -0
  38. package/dist/ci/github-actions.d.ts.map +1 -0
  39. package/dist/ci/github-actions.js +277 -0
  40. package/dist/ci/index.d.ts +12 -0
  41. package/dist/ci/index.d.ts.map +1 -0
  42. package/dist/ci/index.js +27 -0
  43. package/dist/ci/pre-commit.d.ts +65 -0
  44. package/dist/ci/pre-commit.d.ts.map +1 -0
  45. package/dist/ci/pre-commit.js +286 -0
  46. package/dist/entitlements.d.ts +149 -0
  47. package/dist/entitlements.d.ts.map +1 -0
  48. package/dist/entitlements.js +464 -0
  49. package/dist/env.d.ts +113 -0
  50. package/dist/env.d.ts.map +1 -0
  51. package/dist/env.js +204 -0
  52. package/dist/fix-packs/__tests__/generate-fix-packs.test.d.ts +7 -0
  53. package/dist/fix-packs/__tests__/generate-fix-packs.test.d.ts.map +1 -0
  54. package/dist/fix-packs/__tests__/generate-fix-packs.test.js +250 -0
  55. package/dist/fix-packs/generate-fix-packs.d.ts +15 -0
  56. package/dist/fix-packs/generate-fix-packs.d.ts.map +1 -0
  57. package/dist/fix-packs/generate-fix-packs.js +505 -0
  58. package/dist/fix-packs/index.d.ts +8 -0
  59. package/dist/fix-packs/index.d.ts.map +1 -0
  60. package/dist/fix-packs/index.js +23 -0
  61. package/dist/fix-packs/types.d.ts +113 -0
  62. package/dist/fix-packs/types.d.ts.map +1 -0
  63. package/dist/fix-packs/types.js +71 -0
  64. package/dist/index.d.ts +13 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +28 -0
  67. package/dist/metrics/prometheus.d.ts +99 -0
  68. package/dist/metrics/prometheus.d.ts.map +1 -0
  69. package/dist/metrics/prometheus.js +306 -0
  70. package/dist/quota-ledger.d.ts +119 -0
  71. package/dist/quota-ledger.d.ts.map +1 -0
  72. package/dist/quota-ledger.js +462 -0
  73. package/dist/rbac/__tests__/permissions.test.d.ts +8 -0
  74. package/dist/rbac/__tests__/permissions.test.d.ts.map +1 -0
  75. package/dist/rbac/__tests__/permissions.test.js +350 -0
  76. package/dist/rbac/index.d.ts +9 -0
  77. package/dist/rbac/index.d.ts.map +1 -0
  78. package/dist/rbac/index.js +32 -0
  79. package/dist/rbac/permissions.d.ts +71 -0
  80. package/dist/rbac/permissions.d.ts.map +1 -0
  81. package/dist/rbac/permissions.js +247 -0
  82. package/dist/rbac/types.d.ts +69 -0
  83. package/dist/rbac/types.d.ts.map +1 -0
  84. package/dist/rbac/types.js +213 -0
  85. package/dist/tier-config.d.ts +203 -0
  86. package/dist/tier-config.d.ts.map +1 -0
  87. package/dist/tier-config.js +675 -0
  88. package/dist/types.d.ts +365 -0
  89. package/dist/types.d.ts.map +1 -0
  90. package/dist/types.js +5 -0
  91. package/dist/utils.d.ts +36 -0
  92. package/dist/utils.d.ts.map +1 -0
  93. package/dist/utils.js +127 -0
  94. package/dist/verified-autofix/__tests__/format-validator.test.d.ts +11 -0
  95. package/dist/verified-autofix/__tests__/format-validator.test.d.ts.map +1 -0
  96. package/dist/verified-autofix/__tests__/format-validator.test.js +285 -0
  97. package/dist/verified-autofix/__tests__/pipeline.test.d.ts +11 -0
  98. package/dist/verified-autofix/__tests__/pipeline.test.d.ts.map +1 -0
  99. package/dist/verified-autofix/__tests__/pipeline.test.js +389 -0
  100. package/dist/verified-autofix/__tests__/repo-fingerprint.test.d.ts +11 -0
  101. package/dist/verified-autofix/__tests__/repo-fingerprint.test.d.ts.map +1 -0
  102. package/dist/verified-autofix/__tests__/repo-fingerprint.test.js +236 -0
  103. package/dist/verified-autofix/__tests__/workspace.test.d.ts +11 -0
  104. package/dist/verified-autofix/__tests__/workspace.test.d.ts.map +1 -0
  105. package/dist/verified-autofix/__tests__/workspace.test.js +314 -0
  106. package/dist/verified-autofix/format-validator.d.ts +101 -0
  107. package/dist/verified-autofix/format-validator.d.ts.map +1 -0
  108. package/dist/verified-autofix/format-validator.js +446 -0
  109. package/dist/verified-autofix/index.d.ts +14 -0
  110. package/dist/verified-autofix/index.d.ts.map +1 -0
  111. package/dist/verified-autofix/index.js +39 -0
  112. package/dist/verified-autofix/pipeline.d.ts +68 -0
  113. package/dist/verified-autofix/pipeline.d.ts.map +1 -0
  114. package/dist/verified-autofix/pipeline.js +330 -0
  115. package/dist/verified-autofix/repo-fingerprint.d.ts +56 -0
  116. package/dist/verified-autofix/repo-fingerprint.d.ts.map +1 -0
  117. package/dist/verified-autofix/repo-fingerprint.js +396 -0
  118. package/dist/verified-autofix/workspace.d.ts +83 -0
  119. package/dist/verified-autofix/workspace.d.ts.map +1 -0
  120. package/dist/verified-autofix/workspace.js +454 -0
  121. package/dist/verified-autofix.d.ts +182 -0
  122. package/dist/verified-autofix.d.ts.map +1 -0
  123. package/dist/verified-autofix.js +1021 -0
  124. package/dist/visualization/dependency-graph.d.ts +79 -0
  125. package/dist/visualization/dependency-graph.d.ts.map +1 -0
  126. package/dist/visualization/dependency-graph.js +399 -0
  127. package/dist/visualization/index.d.ts +5 -0
  128. package/dist/visualization/index.d.ts.map +1 -0
  129. package/dist/visualization/index.js +20 -0
  130. package/package.json +29 -0
  131. package/src/__tests__/autopilot.test.ts +196 -0
  132. package/src/__tests__/tier-config.test.ts +289 -0
  133. package/src/__tests__/utils/hash-inline.test.ts +76 -0
  134. package/src/__tests__/utils/hash.test.ts +119 -0
  135. package/src/__tests__/utils/simple.test.ts +10 -0
  136. package/src/__tests__/utils/utils-simple.test.ts +5 -0
  137. package/src/__tests__/utils/utils.test.ts +203 -0
  138. package/src/autopilot/autopilot-runner.ts +503 -0
  139. package/src/autopilot/index.ts +6 -0
  140. package/src/autopilot/types.ts +119 -0
  141. package/src/cache/index.ts +7 -0
  142. package/src/cache/redis-cache.d.ts +155 -0
  143. package/src/cache/redis-cache.d.ts.map +1 -0
  144. package/src/cache/redis-cache.ts +517 -0
  145. package/src/ci/github-actions.ts +335 -0
  146. package/src/ci/index.ts +12 -0
  147. package/src/ci/pre-commit.ts +338 -0
  148. package/src/db/usage-schema.prisma +114 -0
  149. package/src/entitlements.ts +570 -0
  150. package/src/env.d.ts +68 -0
  151. package/src/env.d.ts.map +1 -0
  152. package/src/env.ts +247 -0
  153. package/src/fix-packs/__tests__/generate-fix-packs.test.ts +317 -0
  154. package/src/fix-packs/generate-fix-packs.ts +577 -0
  155. package/src/fix-packs/index.ts +8 -0
  156. package/src/fix-packs/types.ts +206 -0
  157. package/src/index.d.ts +7 -0
  158. package/src/index.d.ts.map +1 -0
  159. package/src/index.ts +12 -0
  160. package/src/metrics/prometheus.d.ts +104 -0
  161. package/src/metrics/prometheus.d.ts.map +1 -0
  162. package/src/metrics/prometheus.ts +446 -0
  163. package/src/quota-ledger.ts +548 -0
  164. package/src/rbac/__tests__/permissions.test.ts +446 -0
  165. package/src/rbac/index.ts +46 -0
  166. package/src/rbac/permissions.ts +301 -0
  167. package/src/rbac/types.ts +298 -0
  168. package/src/tier-config.json +157 -0
  169. package/src/tier-config.ts +815 -0
  170. package/src/types.d.ts +365 -0
  171. package/src/types.d.ts.map +1 -0
  172. package/src/types.ts +441 -0
  173. package/src/utils.d.ts +36 -0
  174. package/src/utils.d.ts.map +1 -0
  175. package/src/utils.ts +140 -0
  176. package/src/verified-autofix/__tests__/format-validator.test.ts +335 -0
  177. package/src/verified-autofix/__tests__/pipeline.test.ts +419 -0
  178. package/src/verified-autofix/__tests__/repo-fingerprint.test.ts +241 -0
  179. package/src/verified-autofix/__tests__/workspace.test.ts +373 -0
  180. package/src/verified-autofix/format-validator.ts +517 -0
  181. package/src/verified-autofix/index.ts +63 -0
  182. package/src/verified-autofix/pipeline.ts +403 -0
  183. package/src/verified-autofix/repo-fingerprint.ts +459 -0
  184. package/src/verified-autofix/workspace.ts +531 -0
  185. package/src/verified-autofix.ts +1187 -0
  186. package/src/visualization/dependency-graph.d.ts +85 -0
  187. package/src/visualization/dependency-graph.d.ts.map +1 -0
  188. package/src/visualization/dependency-graph.ts +495 -0
  189. package/src/visualization/index.ts +5 -0
@@ -0,0 +1,396 @@
1
+ "use strict";
2
+ /**
3
+ * Repo Fingerprint - Project Detection & Configuration
4
+ *
5
+ * Detects project characteristics:
6
+ * 1. Package manager (pnpm, yarn, npm)
7
+ * 2. Build tool (turbo, nx, none)
8
+ * 3. Framework (next, vite, cra, etc.)
9
+ * 4. Test runner (jest, vitest, mocha, etc.)
10
+ * 5. Language features (TypeScript, ESLint, etc.)
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.fingerprintRepo = fingerprintRepo;
47
+ exports.getInstallCommand = getInstallCommand;
48
+ exports.getBuildCommand = getBuildCommand;
49
+ exports.getTestCommand = getTestCommand;
50
+ exports.getTypecheckCommand = getTypecheckCommand;
51
+ const fs = __importStar(require("fs"));
52
+ const path = __importStar(require("path"));
53
+ // ============================================================================
54
+ // DETECTION FUNCTIONS
55
+ // ============================================================================
56
+ /**
57
+ * Detect package manager from lock files
58
+ */
59
+ function detectPackageManager(projectPath) {
60
+ if (fs.existsSync(path.join(projectPath, 'pnpm-lock.yaml'))) {
61
+ return 'pnpm';
62
+ }
63
+ if (fs.existsSync(path.join(projectPath, 'yarn.lock'))) {
64
+ return 'yarn';
65
+ }
66
+ if (fs.existsSync(path.join(projectPath, 'bun.lockb'))) {
67
+ return 'bun';
68
+ }
69
+ if (fs.existsSync(path.join(projectPath, 'package-lock.json'))) {
70
+ return 'npm';
71
+ }
72
+ return 'unknown';
73
+ }
74
+ /**
75
+ * Detect build tool (monorepo orchestrator)
76
+ */
77
+ function detectBuildTool(projectPath, pkg) {
78
+ // Turbo
79
+ if (fs.existsSync(path.join(projectPath, 'turbo.json')) ||
80
+ pkg.devDependencies?.['turbo'] ||
81
+ pkg.dependencies?.['turbo']) {
82
+ return 'turbo';
83
+ }
84
+ // Nx
85
+ if (fs.existsSync(path.join(projectPath, 'nx.json')) ||
86
+ pkg.devDependencies?.['nx'] ||
87
+ pkg.dependencies?.['nx']) {
88
+ return 'nx';
89
+ }
90
+ // Lerna
91
+ if (fs.existsSync(path.join(projectPath, 'lerna.json')) ||
92
+ pkg.devDependencies?.['lerna']) {
93
+ return 'lerna';
94
+ }
95
+ return 'none';
96
+ }
97
+ /**
98
+ * Detect framework from dependencies
99
+ */
100
+ function detectFramework(pkg) {
101
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
102
+ // Next.js
103
+ if (deps['next']) {
104
+ return 'next';
105
+ }
106
+ // Remix
107
+ if (deps['@remix-run/react'] || deps['remix']) {
108
+ return 'remix';
109
+ }
110
+ // Gatsby
111
+ if (deps['gatsby']) {
112
+ return 'gatsby';
113
+ }
114
+ // Nuxt
115
+ if (deps['nuxt'] || deps['nuxt3']) {
116
+ return 'nuxt';
117
+ }
118
+ // SvelteKit
119
+ if (deps['@sveltejs/kit'] || deps['svelte']) {
120
+ return 'svelte';
121
+ }
122
+ // Angular
123
+ if (deps['@angular/core']) {
124
+ return 'angular';
125
+ }
126
+ // Vite (generic)
127
+ if (deps['vite']) {
128
+ return 'vite';
129
+ }
130
+ // Create React App
131
+ if (deps['react-scripts']) {
132
+ return 'cra';
133
+ }
134
+ // Express
135
+ if (deps['express']) {
136
+ return 'express';
137
+ }
138
+ // Fastify
139
+ if (deps['fastify']) {
140
+ return 'fastify';
141
+ }
142
+ return 'none';
143
+ }
144
+ /**
145
+ * Detect test runner
146
+ */
147
+ function detectTestRunner(projectPath, pkg) {
148
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
149
+ // Vitest
150
+ if (deps['vitest']) {
151
+ return 'vitest';
152
+ }
153
+ // Jest
154
+ if (deps['jest'] || fs.existsSync(path.join(projectPath, 'jest.config.js')) ||
155
+ fs.existsSync(path.join(projectPath, 'jest.config.ts'))) {
156
+ return 'jest';
157
+ }
158
+ // Mocha
159
+ if (deps['mocha']) {
160
+ return 'mocha';
161
+ }
162
+ // AVA
163
+ if (deps['ava']) {
164
+ return 'ava';
165
+ }
166
+ // Playwright
167
+ if (deps['@playwright/test'] || deps['playwright']) {
168
+ return 'playwright';
169
+ }
170
+ // Cypress
171
+ if (deps['cypress']) {
172
+ return 'cypress';
173
+ }
174
+ return 'none';
175
+ }
176
+ /**
177
+ * Detect if project is a monorepo
178
+ */
179
+ function detectMonorepo(projectPath, pkg) {
180
+ // Check package.json workspaces
181
+ if (pkg.workspaces) {
182
+ const workspaces = Array.isArray(pkg.workspaces)
183
+ ? pkg.workspaces
184
+ : pkg.workspaces.packages || [];
185
+ return { isMonorepo: true, workspaces };
186
+ }
187
+ // Check pnpm-workspace.yaml
188
+ const pnpmWorkspacePath = path.join(projectPath, 'pnpm-workspace.yaml');
189
+ if (fs.existsSync(pnpmWorkspacePath)) {
190
+ try {
191
+ const content = fs.readFileSync(pnpmWorkspacePath, 'utf8');
192
+ const workspaces = [];
193
+ const matches = content.match(/packages:\s*\n((?:\s+-\s*['"]?[^\n]+['"]?\n?)+)/);
194
+ if (matches && matches[1]) {
195
+ const lines = matches[1].split('\n');
196
+ for (const line of lines) {
197
+ const match = line.match(/^\s*-\s*['"]?([^'"]+)['"]?/);
198
+ if (match && match[1]) {
199
+ workspaces.push(match[1]);
200
+ }
201
+ }
202
+ }
203
+ return { isMonorepo: true, workspaces };
204
+ }
205
+ catch {
206
+ return { isMonorepo: true, workspaces: [] };
207
+ }
208
+ }
209
+ // Check for common monorepo directories
210
+ const monorepoIndicators = ['packages', 'apps', 'libs', 'modules'];
211
+ for (const dir of monorepoIndicators) {
212
+ const dirPath = path.join(projectPath, dir);
213
+ if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
214
+ // Check if any subdirectory has a package.json
215
+ try {
216
+ const subdirs = fs.readdirSync(dirPath);
217
+ for (const subdir of subdirs) {
218
+ if (fs.existsSync(path.join(dirPath, subdir, 'package.json'))) {
219
+ return { isMonorepo: true, workspaces: [`${dir}/*`] };
220
+ }
221
+ }
222
+ }
223
+ catch {
224
+ // Ignore read errors
225
+ }
226
+ }
227
+ }
228
+ return { isMonorepo: false, workspaces: [] };
229
+ }
230
+ /**
231
+ * Read Node.js version from .nvmrc or similar
232
+ */
233
+ function readNodeVersion(projectPath) {
234
+ const versionFiles = ['.nvmrc', '.node-version', '.tool-versions'];
235
+ for (const file of versionFiles) {
236
+ const filePath = path.join(projectPath, file);
237
+ if (fs.existsSync(filePath)) {
238
+ try {
239
+ const content = fs.readFileSync(filePath, 'utf8').trim();
240
+ if (file === '.tool-versions') {
241
+ const match = content.match(/nodejs\s+([^\s]+)/);
242
+ return match ? match[1] : undefined;
243
+ }
244
+ return content.replace(/^v/, '');
245
+ }
246
+ catch {
247
+ // Ignore read errors
248
+ }
249
+ }
250
+ }
251
+ return undefined;
252
+ }
253
+ // ============================================================================
254
+ // MAIN FINGERPRINT FUNCTION
255
+ // ============================================================================
256
+ /**
257
+ * Analyze a project and return its fingerprint
258
+ */
259
+ function fingerprintRepo(projectPath) {
260
+ const notes = [];
261
+ let confidence = 100;
262
+ // Read package.json
263
+ const pkgPath = path.join(projectPath, 'package.json');
264
+ let pkg = {};
265
+ if (fs.existsSync(pkgPath)) {
266
+ try {
267
+ pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
268
+ }
269
+ catch (e) {
270
+ notes.push(`Failed to parse package.json: ${e.message}`);
271
+ confidence -= 20;
272
+ }
273
+ }
274
+ else {
275
+ notes.push('No package.json found');
276
+ confidence -= 30;
277
+ }
278
+ const packageManager = detectPackageManager(projectPath);
279
+ const buildTool = detectBuildTool(projectPath, pkg);
280
+ const framework = detectFramework(pkg);
281
+ const testRunner = detectTestRunner(projectPath, pkg);
282
+ const { isMonorepo, workspaces } = detectMonorepo(projectPath, pkg);
283
+ const nodeVersion = readNodeVersion(projectPath);
284
+ // TypeScript detection
285
+ const hasTypeScript = !!(fs.existsSync(path.join(projectPath, 'tsconfig.json')) ||
286
+ pkg.devDependencies?.['typescript'] ||
287
+ pkg.dependencies?.['typescript']);
288
+ // ESLint detection
289
+ const hasESLint = !!(fs.existsSync(path.join(projectPath, '.eslintrc.js')) ||
290
+ fs.existsSync(path.join(projectPath, '.eslintrc.json')) ||
291
+ fs.existsSync(path.join(projectPath, '.eslintrc.yml')) ||
292
+ fs.existsSync(path.join(projectPath, 'eslint.config.js')) ||
293
+ pkg.devDependencies?.['eslint']);
294
+ // Prettier detection
295
+ const hasPrettier = !!(fs.existsSync(path.join(projectPath, '.prettierrc')) ||
296
+ fs.existsSync(path.join(projectPath, '.prettierrc.js')) ||
297
+ fs.existsSync(path.join(projectPath, '.prettierrc.json')) ||
298
+ fs.existsSync(path.join(projectPath, 'prettier.config.js')) ||
299
+ pkg.devDependencies?.['prettier']);
300
+ // Script detection
301
+ const hasBuildScript = !!(pkg.scripts?.['build']);
302
+ const hasTestScript = !!(pkg.scripts?.['test']);
303
+ // Add detection notes
304
+ if (packageManager === 'unknown') {
305
+ notes.push('Could not detect package manager');
306
+ confidence -= 10;
307
+ }
308
+ if (framework === 'none') {
309
+ notes.push('No major framework detected');
310
+ }
311
+ if (testRunner === 'none') {
312
+ notes.push('No test runner detected');
313
+ }
314
+ const fingerprint = {
315
+ packageManager,
316
+ buildTool,
317
+ framework,
318
+ testRunner,
319
+ hasTypeScript,
320
+ hasESLint,
321
+ hasPrettier,
322
+ hasBuildScript,
323
+ hasTestScript,
324
+ isMonorepo,
325
+ workspaces,
326
+ nodeVersion,
327
+ dependencies: pkg.dependencies || {},
328
+ devDependencies: pkg.devDependencies || {},
329
+ };
330
+ return {
331
+ fingerprint,
332
+ confidence: Math.max(0, confidence),
333
+ detectionNotes: notes,
334
+ };
335
+ }
336
+ /**
337
+ * Get appropriate install command for package manager
338
+ */
339
+ function getInstallCommand(packageManager) {
340
+ switch (packageManager) {
341
+ case 'pnpm':
342
+ return 'pnpm install --frozen-lockfile';
343
+ case 'yarn':
344
+ return 'yarn install --frozen-lockfile';
345
+ case 'bun':
346
+ return 'bun install --frozen-lockfile';
347
+ case 'npm':
348
+ default:
349
+ return 'npm ci';
350
+ }
351
+ }
352
+ /**
353
+ * Get appropriate build command
354
+ */
355
+ function getBuildCommand(fingerprint) {
356
+ if (fingerprint.buildTool === 'turbo') {
357
+ return 'npx turbo run build';
358
+ }
359
+ if (fingerprint.buildTool === 'nx') {
360
+ return 'npx nx run-many --target=build';
361
+ }
362
+ if (fingerprint.hasBuildScript) {
363
+ return 'npm run build';
364
+ }
365
+ return 'echo "No build script"';
366
+ }
367
+ /**
368
+ * Get appropriate test command
369
+ */
370
+ function getTestCommand(fingerprint) {
371
+ switch (fingerprint.testRunner) {
372
+ case 'vitest':
373
+ return 'npx vitest run';
374
+ case 'jest':
375
+ return 'npx jest --passWithNoTests';
376
+ case 'mocha':
377
+ return 'npx mocha';
378
+ case 'ava':
379
+ return 'npx ava';
380
+ case 'playwright':
381
+ return 'npx playwright test';
382
+ case 'cypress':
383
+ return 'npx cypress run';
384
+ default:
385
+ return fingerprint.hasTestScript ? 'npm test' : 'echo "No test runner"';
386
+ }
387
+ }
388
+ /**
389
+ * Get typecheck command if TypeScript is present
390
+ */
391
+ function getTypecheckCommand(fingerprint) {
392
+ if (!fingerprint.hasTypeScript) {
393
+ return null;
394
+ }
395
+ return 'npx tsc --noEmit';
396
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Temp Workspace Manager - Isolated Verification Environment
3
+ *
4
+ * Creates isolated workspaces for testing patches:
5
+ * 1. Prefers git worktree when available
6
+ * 2. Falls back to directory copy
7
+ * 3. Applies diffs with git apply --check validation
8
+ * 4. Runs verification commands (typecheck, build, tests)
9
+ */
10
+ import type { ParsedHunk } from './format-validator';
11
+ import type { RepoFingerprint } from './repo-fingerprint';
12
+ export interface WorkspaceOptions {
13
+ projectPath: string;
14
+ useWorktree?: boolean;
15
+ installDeps?: boolean;
16
+ timeout?: number;
17
+ }
18
+ export interface WorkspaceInfo {
19
+ id: string;
20
+ path: string;
21
+ type: 'worktree' | 'copy';
22
+ projectPath: string;
23
+ createdAt: Date;
24
+ }
25
+ export interface ApplyResult {
26
+ success: boolean;
27
+ applied: number;
28
+ failed: number;
29
+ errors: string[];
30
+ }
31
+ export interface VerifyResult {
32
+ passed: boolean;
33
+ checks: CheckResult[];
34
+ duration: number;
35
+ failureContext: string[];
36
+ }
37
+ export interface CheckResult {
38
+ name: string;
39
+ command: string;
40
+ passed: boolean;
41
+ output: string;
42
+ duration: number;
43
+ }
44
+ export declare class TempWorkspace {
45
+ private workspaces;
46
+ /**
47
+ * Create an isolated workspace for verification
48
+ */
49
+ create(options: WorkspaceOptions): Promise<WorkspaceInfo>;
50
+ /**
51
+ * Apply a unified diff to the workspace
52
+ */
53
+ applyDiff(workspacePath: string, diff: string, hunks: ParsedHunk[]): Promise<ApplyResult>;
54
+ /**
55
+ * Run verification checks in the workspace
56
+ */
57
+ verify(workspacePath: string, fingerprint: RepoFingerprint, options?: {
58
+ skipTests?: boolean;
59
+ timeout?: number;
60
+ }): Promise<VerifyResult>;
61
+ /**
62
+ * Copy changes back to the original project
63
+ */
64
+ copyBack(workspacePath: string, projectPath: string, files: string[]): Promise<void>;
65
+ /**
66
+ * Cleanup a workspace
67
+ */
68
+ cleanup(workspaceId: string): Promise<void>;
69
+ /**
70
+ * Cleanup all workspaces
71
+ */
72
+ cleanupAll(): Promise<void>;
73
+ private tryCreateWorktree;
74
+ private copyProject;
75
+ private installDependencies;
76
+ private tryGitApply;
77
+ private applyHunk;
78
+ private getVerificationCommands;
79
+ private truncateOutput;
80
+ private extractFailureContext;
81
+ }
82
+ export declare const tempWorkspace: TempWorkspace;
83
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/verified-autofix/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAM1D,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AA4BD,qBAAa,aAAa;IACxB,OAAO,CAAC,UAAU,CAAyC;IAE3D;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAyC/D;;OAEG;IACG,SAAS,CACb,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,EAAE,GAClB,OAAO,CAAC,WAAW,CAAC;IAsCvB;;OAEG;IACG,MAAM,CACV,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,eAAe,EAC5B,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAClD,OAAO,CAAC,YAAY,CAAC;IAyDxB;;OAEG;IACG,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB1F;;OAEG;IACG,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BjD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAUnB,iBAAiB;YAqBjB,WAAW;YAoBX,mBAAmB;YAiBnB,WAAW;YAmCX,SAAS;IAiDvB,OAAO,CAAC,uBAAuB;IAwC/B,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,qBAAqB;CAgC9B;AAGD,eAAO,MAAM,aAAa,eAAsB,CAAC"}