@haystackeditor/cli 0.25.0 → 0.26.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 (113) hide show
  1. package/README.md +39 -455
  2. package/dist/capture/adapters/django.js +7 -0
  3. package/dist/capture/adapters/index.js +10 -0
  4. package/dist/capture/adapters/next-build.js +113 -0
  5. package/dist/capture/adapters/next.js +272 -105
  6. package/dist/capture/adapters/nuxt.js +7 -0
  7. package/dist/capture/adapters/rails.js +7 -0
  8. package/dist/capture/adapters/react-router.js +7 -0
  9. package/dist/capture/adapters/sveltekit.js +7 -0
  10. package/dist/capture/adapters/vite.js +14 -0
  11. package/dist/capture/app-config.js +27 -2
  12. package/dist/capture/csp.js +7 -6
  13. package/dist/capture/url-rewrites.js +232 -0
  14. package/dist/capture-step.js +3 -0
  15. package/dist/commands/capture-brief.js +41 -32
  16. package/dist/commands/capture-manifest.js +25 -17
  17. package/dist/commands/feedback.js +66 -0
  18. package/dist/commands/init-capture.js +44 -27
  19. package/dist/commands/init-telemetry.js +77 -14
  20. package/dist/commands/init.js +19 -4
  21. package/dist/commands/lockfile-pin.js +307 -0
  22. package/dist/commands/verify-onboarding.js +16 -0
  23. package/dist/commands/verify.js +70 -15
  24. package/dist/index.js +29 -923
  25. package/dist/schema.js +4 -10
  26. package/dist/utils/haystack-api.js +0 -36
  27. package/package.json +1 -5
  28. package/schemas/feedback.v1.json +13 -0
  29. package/schemas/init.v1.json +1 -1
  30. package/schemas/pre-verify.v2.json +240 -0
  31. package/schemas/verify-raw.v1.json +1132 -0
  32. package/schemas/verify.v2.json +655 -0
  33. package/dist/assets/hooks/agent-context/detect.ts +0 -316
  34. package/dist/assets/hooks/agent-context/format.ts +0 -100
  35. package/dist/assets/hooks/agent-context/index.ts +0 -41
  36. package/dist/assets/hooks/agent-context/parsers/claude.ts +0 -262
  37. package/dist/assets/hooks/agent-context/parsers/codex.ts +0 -416
  38. package/dist/assets/hooks/agent-context/parsers/gemini.ts +0 -155
  39. package/dist/assets/hooks/agent-context/parsers/opencode.ts +0 -174
  40. package/dist/assets/hooks/agent-context/tsconfig.json +0 -14
  41. package/dist/assets/hooks/agent-context/types.ts +0 -58
  42. package/dist/assets/hooks/llm-rules-template.md +0 -59
  43. package/dist/assets/hooks/package-lock.json +0 -598
  44. package/dist/assets/hooks/package.json +0 -12
  45. package/dist/assets/hooks/scripts/commit-msg.sh +0 -5
  46. package/dist/assets/hooks/scripts/post-commit.sh +0 -5
  47. package/dist/assets/hooks/scripts/pre-commit.sh +0 -175
  48. package/dist/assets/hooks/scripts/pre-push.sh +0 -25
  49. package/dist/assets/hooks/scripts/prepare-commit-msg.sh +0 -5
  50. package/dist/assets/hooks/truncation-checker/ast-analyzer.ts +0 -528
  51. package/dist/assets/hooks/truncation-checker/index.ts +0 -595
  52. package/dist/assets/hooks/truncation-checker/tsconfig.json +0 -13
  53. package/dist/assets/skills/map-cloud-verifier-universe/SKILL.md +0 -2051
  54. package/dist/assets/skills/map-cloud-verifier-universe/agents/openai.yaml +0 -4
  55. package/dist/assets/skills/map-cloud-verifier-universe/references/output-contract.md +0 -3411
  56. package/dist/assets/skills/map-your-system.md +0 -143
  57. package/dist/assets/skills/submit.md +0 -200
  58. package/dist/commands/ask.js +0 -20
  59. package/dist/commands/cloud-verifier-behaviors.js +0 -218
  60. package/dist/commands/cloud-verifier-data-store-census.js +0 -539
  61. package/dist/commands/cloud-verifier-data-store-drift.js +0 -158
  62. package/dist/commands/cloud-verifier-identity-census.js +0 -4060
  63. package/dist/commands/cloud-verifier-materialization.js +0 -704
  64. package/dist/commands/cloud-verifier-pascal-selector-census.js +0 -1382
  65. package/dist/commands/cloud-verifier-python-manifest-selector-census.js +0 -2015
  66. package/dist/commands/cloud-verifier-specialized-operational-census.js +0 -11432
  67. package/dist/commands/cloud-verifier-universe.js +0 -10178
  68. package/dist/commands/config.js +0 -549
  69. package/dist/commands/design-verify.js +0 -311
  70. package/dist/commands/dismiss.js +0 -159
  71. package/dist/commands/hooks.js +0 -226
  72. package/dist/commands/inbox.js +0 -137
  73. package/dist/commands/mcp.js +0 -201
  74. package/dist/commands/policy.js +0 -371
  75. package/dist/commands/pr-status.js +0 -207
  76. package/dist/commands/pr.js +0 -105
  77. package/dist/commands/prepare-universe-review.js +0 -1092
  78. package/dist/commands/production-source-deny-policy.js +0 -100
  79. package/dist/commands/request-review.js +0 -74
  80. package/dist/commands/review.js +0 -191
  81. package/dist/commands/rules.js +0 -98
  82. package/dist/commands/scaffold-provisional-universe.js +0 -806
  83. package/dist/commands/setup.js +0 -1170
  84. package/dist/commands/skills.js +0 -447
  85. package/dist/commands/submit.js +0 -745
  86. package/dist/commands/system-map.js +0 -228
  87. package/dist/commands/triage.js +0 -598
  88. package/dist/commands/webhooks.js +0 -241
  89. package/dist/states.js +0 -46
  90. package/dist/tools/detect.js +0 -832
  91. package/dist/triage/astra.js +0 -202
  92. package/dist/triage/prompts.js +0 -188
  93. package/dist/triage/runner.js +0 -200
  94. package/dist/triage/types.js +0 -7
  95. package/dist/utils/action-output.js +0 -26
  96. package/dist/utils/analysis-api.js +0 -416
  97. package/dist/utils/design-verifier-api.js +0 -294
  98. package/dist/utils/design-verifier-history.js +0 -79
  99. package/dist/utils/design-verifier-result.js +0 -424
  100. package/dist/utils/github-api.js +0 -324
  101. package/dist/utils/pending-state.js +0 -86
  102. package/dist/utils/pr-ref.js +0 -56
  103. package/dist/utils/prompter.js +0 -328
  104. package/schemas/action.v1.json +0 -22
  105. package/schemas/ask.v1.json +0 -40
  106. package/schemas/inbox.v1.json +0 -27
  107. package/schemas/pr-status.v1.json +0 -61
  108. package/schemas/pr.v1.json +0 -97
  109. package/schemas/pr.v3.json +0 -45
  110. package/schemas/setup.v1.json +0 -75
  111. package/schemas/submit.v1.json +0 -90
  112. package/schemas/triage.v1.json +0 -103
  113. package/schemas/triage.v2.json +0 -64
@@ -1,595 +0,0 @@
1
- /**
2
- * Truncation Pattern Checker
3
- *
4
- * Scans staged git diff for patterns that violate the "No Truncation Without Permission" rule.
5
- * See LLM_RULES.md for the full policy.
6
- */
7
-
8
- import { execSync } from 'child_process';
9
- import { join } from 'path';
10
- import { analyzeFiles, formatASTViolations, type ASTViolation } from './ast-analyzer.js';
11
-
12
- // ============================================================================
13
- // CONFIGURATION
14
- // ============================================================================
15
-
16
- /** Paths that should be checked for truncation violations */
17
- const CHECKED_PATH_PATTERNS = [
18
- /^agent\//,
19
- /^analysis\//,
20
- /\/prompts?\//i,
21
- /tool/i,
22
- /llm/i,
23
- /agent/i,
24
- /pipeline/i,
25
- /context/i,
26
- ];
27
-
28
- /** Paths that should be excluded from checks */
29
- const EXCLUDED_PATH_PATTERNS = [
30
- /node_modules/,
31
- /\.test\./,
32
- /\.spec\./,
33
- /__tests__/,
34
- /\/test\//,
35
- /\/tests\//,
36
- /^hooks\//, // Don't check our own hook code
37
- /\.md$/,
38
- /\.json$/,
39
- /\.yaml$/,
40
- /\.yml$/,
41
- /\.svg$/,
42
- /\.png$/,
43
- /\.jpg$/,
44
- /\.gif$/,
45
- /\.ico$/,
46
- /\.lock$/,
47
- /package-lock/,
48
- /pnpm-lock/,
49
- ];
50
-
51
- // ============================================================================
52
- // PATTERN DEFINITIONS
53
- // ============================================================================
54
-
55
- interface TruncationPattern {
56
- id: string;
57
- name: string;
58
- description: string;
59
- patterns: RegExp[];
60
- severity: 'error' | 'warning';
61
- }
62
-
63
- const TRUNCATION_PATTERNS: TruncationPattern[] = [
64
- // -------------------------------------------------------------------------
65
- // Category 1: Direct slice/substring with numeric limits
66
- // -------------------------------------------------------------------------
67
- {
68
- id: 'slice-numeric',
69
- name: 'Slice with numeric limit',
70
- description: 'Direct .slice(0, N) or .substring(0, N) with hardcoded limit',
71
- patterns: [
72
- /\.slice\s*\(\s*0\s*,\s*\d+\s*\)/,
73
- /\.substring\s*\(\s*0\s*,\s*\d+\s*\)/,
74
- /\.substr\s*\(\s*0\s*,\s*\d+\s*\)/,
75
- ],
76
- severity: 'error',
77
- },
78
- {
79
- id: 'slice-variable',
80
- name: 'Slice with limit variable',
81
- description: '.slice(0, limit) or .slice(0, max...) with variable limit',
82
- patterns: [
83
- /\.slice\s*\(\s*0\s*,\s*(?:max|limit|MAX|LIMIT|cutoff|truncate)/i,
84
- /\.substring\s*\(\s*0\s*,\s*(?:max|limit|MAX|LIMIT|cutoff|truncate)/i,
85
- /\.slice\s*\(\s*0\s*,\s*[A-Z_]+(?:LENGTH|LIMIT|SIZE|COUNT|ITEMS|LINES|CHARS|TOKENS)\s*\)/,
86
- ],
87
- severity: 'error',
88
- },
89
-
90
- // -------------------------------------------------------------------------
91
- // Category 2: Ellipsis additions indicating truncation
92
- // -------------------------------------------------------------------------
93
- {
94
- id: 'ellipsis-concat',
95
- name: 'Ellipsis concatenation',
96
- description: 'Adding "..." or ellipsis character to indicate truncation',
97
- patterns: [
98
- /\+\s*['"`]\.\.\.['"`]/,
99
- /\+\s*['"`]…['"`]/, // Unicode ellipsis
100
- /\+\s*['"`]\[\.\.\.?\]]['"`]/,
101
- /\+\s*['"`]\s*\.\.\.\s*\(truncated\)['"`]/i,
102
- /\+\s*['"`]\[truncated\]['"`]/i,
103
- /\+\s*['"`]\(truncated\)['"`]/i,
104
- /\+\s*['"`]\[omitted\]['"`]/i,
105
- /\+\s*['"`]\(omitted\)['"`]/i,
106
- /['"`]\.\.\.['"`]\s*\+/, // Prefix ellipsis
107
- ],
108
- severity: 'error',
109
- },
110
- {
111
- id: 'ellipsis-template',
112
- name: 'Ellipsis in template literal',
113
- description: 'Template literal with ellipsis pattern',
114
- patterns: [
115
- /`[^`]*\.\.\.[^`]*\$\{/,
116
- /`[^`]*\$\{[^}]+\}[^`]*\.\.\.`/,
117
- /`\.\.\./,
118
- ],
119
- severity: 'warning', // Lower severity - could be legitimate UI
120
- },
121
-
122
- // -------------------------------------------------------------------------
123
- // Category 3: "N more" patterns
124
- // -------------------------------------------------------------------------
125
- {
126
- id: 'n-more-pattern',
127
- name: '"N more" truncation indicator',
128
- description: 'Patterns like "and X more", "+ N others"',
129
- patterns: [
130
- /\$\{[^}]+\}\s*more/i,
131
- /`[^`]*and\s+\$\{[^}]+\}\s+more[^`]*`/i,
132
- /`[^`]*\+\s*\$\{[^}]+\}\s*(?:more|others|items|remaining)[^`]*`/i,
133
- /['"`]\s*\.\.\.\s*and\s+['"`]\s*\+/i,
134
- /\[\s*\+\s*\$\{[^}]+\}\s*\]/,
135
- /`[^`]*\$\{[^}]+\}\s+additional[^`]*`/i,
136
- /`[^`]*\$\{[^}]+\}\s+remaining[^`]*`/i,
137
- ],
138
- severity: 'error',
139
- },
140
-
141
- // -------------------------------------------------------------------------
142
- // Category 4: "First N" / "Showing N" patterns
143
- // -------------------------------------------------------------------------
144
- {
145
- id: 'showing-first-n',
146
- name: '"Showing first N" pattern',
147
- description: 'Patterns indicating partial display',
148
- patterns: [
149
- /['"`](?:showing|displaying)\s+(?:first|only)\s+\d+/i,
150
- /['"`]first\s+\d+\s+(?:results?|items?|lines?|entries)/i,
151
- /['"`]limited\s+to\s+\d+/i,
152
- /['"`]only\s+showing\s+\d+/i,
153
- /['"`]top\s+\d+\s+(?:results?|items?)/i,
154
- /['"`]truncated\s+to\s+\d+/i,
155
- ],
156
- severity: 'error',
157
- },
158
-
159
- // -------------------------------------------------------------------------
160
- // Category 5: Truncation functions
161
- // -------------------------------------------------------------------------
162
- {
163
- id: 'truncate-function',
164
- name: 'Truncation function call',
165
- description: 'Calling truncate(), shortenText(), etc.',
166
- patterns: [
167
- /(?<!function\s)(?<!\.)\btruncate\s*\(/i,
168
- /(?<!function\s)truncateText\s*\(/i,
169
- /(?<!function\s)truncateString\s*\(/i,
170
- /(?<!function\s)shortenText\s*\(/i,
171
- /(?<!function\s)limitLength\s*\(/i,
172
- /(?<!function\s)ellipsize\s*\(/i,
173
- /(?<!function\s)abbreviate\s*\(/i,
174
- /_\.truncate\s*\(/,
175
- /_\.take\s*\(/,
176
- /lodash.*\.truncate\s*\(/,
177
- ],
178
- severity: 'error',
179
- },
180
-
181
- // -------------------------------------------------------------------------
182
- // Category 6: Conditional length checks with truncation
183
- // -------------------------------------------------------------------------
184
- {
185
- id: 'conditional-truncation',
186
- name: 'Conditional length check',
187
- description: 'if (x.length > N) patterns suggesting truncation',
188
- patterns: [
189
- /if\s*\([^)]*\.length\s*>\s*\d+[^)]*\)\s*\{[^}]*\.slice/,
190
- /if\s*\([^)]*\.length\s*>\s*(?:max|limit|MAX|LIMIT)/i,
191
- /\.length\s*>\s*\d+\s*\?\s*[^:]+\.slice\s*\(/,
192
- /\.length\s*>\s*(?:max|limit|MAX|LIMIT)[^?]*\?[^:]*\.slice/i,
193
- ],
194
- severity: 'error',
195
- },
196
-
197
- // -------------------------------------------------------------------------
198
- // Category 7: Content omission markers
199
- // -------------------------------------------------------------------------
200
- {
201
- id: 'omission-marker',
202
- name: 'Content omission marker',
203
- description: 'Strings indicating content was omitted',
204
- patterns: [
205
- /['"`]\[content\s+omitted\]['"`]/i,
206
- /['"`]\[\.\.\.\s*snip\s*\.\.\.\]['"`]/i,
207
- /['"`]<!--\s*truncated\s*-->['"`]/i,
208
- /['"`]\[showing\s+\d+\s+of\s+\d+\]['"`]/i,
209
- /['"`]\[\d+\s+items?\s+hidden\]['"`]/i,
210
- /['"`]\[rest\s+omitted\]['"`]/i,
211
- /['"`]output\s+truncated['"`]/i,
212
- /['"`]results?\s+truncated['"`]/i,
213
- ],
214
- severity: 'error',
215
- },
216
-
217
- // -------------------------------------------------------------------------
218
- // Category 8: Array truncation
219
- // -------------------------------------------------------------------------
220
- {
221
- id: 'array-truncation',
222
- name: 'Array truncation',
223
- description: 'Truncating arrays via length assignment or splice',
224
- patterns: [
225
- /\.length\s*=\s*\d+/, // array.length = N (truncates)
226
- /\.length\s*=\s*(?:max|limit|MAX|LIMIT)/i,
227
- /\.splice\s*\(\s*\d+\s*\)/, // splice(N) removes from index N
228
- /\.splice\s*\(\s*(?:max|limit|MAX|LIMIT)/i,
229
- ],
230
- severity: 'warning',
231
- },
232
-
233
- // -------------------------------------------------------------------------
234
- // Category 9: Take/head operations (lodash style)
235
- // -------------------------------------------------------------------------
236
- {
237
- id: 'take-head',
238
- name: 'Take/head operations',
239
- description: 'Lodash-style take() or head() limiting',
240
- patterns: [
241
- /\.take\s*\(\s*\d+\s*\)/,
242
- /\.head\s*\(\s*\d+\s*\)/,
243
- /\.first\s*\(\s*\d+\s*\)/,
244
- /\.limit\s*\(\s*\d+\s*\)/,
245
- ],
246
- severity: 'warning',
247
- },
248
-
249
- // -------------------------------------------------------------------------
250
- // Category 10: Max/limit constants being defined (context: likely used for truncation)
251
- // -------------------------------------------------------------------------
252
- {
253
- id: 'limit-constant',
254
- name: 'Limit constant definition',
255
- description: 'Defining MAX_* or *_LIMIT constants',
256
- patterns: [
257
- /(?:const|let|var)\s+MAX_(?:LENGTH|ITEMS|LINES|TOKENS|CHARS|RESULTS|OUTPUT|CONTENT)\s*=/i,
258
- /(?:const|let|var)\s+(?:LENGTH|ITEMS|LINES|TOKENS|CHARS|RESULTS|OUTPUT|CONTENT)_(?:LIMIT|MAX)\s*=/i,
259
- /(?:const|let|var)\s+(?:max|limit)(?:Length|Items|Lines|Tokens|Chars|Results|Output|Content)\s*=/,
260
- /(?:const|let|var)\s+TRUNCATE_(?:AT|AFTER|LENGTH)\s*=/i,
261
- /(?:const|let|var)\s+head_limit\s*=/i,
262
- ],
263
- severity: 'warning',
264
- },
265
-
266
- // -------------------------------------------------------------------------
267
- // Category 11: Output/result slicing (common in agent code)
268
- // -------------------------------------------------------------------------
269
- {
270
- id: 'output-slicing',
271
- name: 'Output/result slicing',
272
- description: 'Slicing output, result, content, or text variables',
273
- patterns: [
274
- /(?:output|result|content|text|response|data|items|lines|entries)\s*(?:=|\.)\s*[^;]*\.slice\s*\(\s*0\s*,/i,
275
- /(?:output|result|content|text|response|data)\s*=\s*[^;]*\.substring\s*\(\s*0\s*,/i,
276
- ],
277
- severity: 'error',
278
- },
279
- ];
280
-
281
- // ============================================================================
282
- // VIOLATION DETECTION
283
- // ============================================================================
284
-
285
- export interface Violation {
286
- file: string;
287
- line: number;
288
- column: number;
289
- content: string;
290
- pattern: TruncationPattern;
291
- matchedText: string;
292
- }
293
-
294
- interface DiffHunk {
295
- file: string;
296
- lines: Array<{
297
- lineNumber: number;
298
- content: string;
299
- type: 'add' | 'remove' | 'context';
300
- }>;
301
- }
302
-
303
- function parseDiff(diffOutput: string): DiffHunk[] {
304
- const hunks: DiffHunk[] = [];
305
- let currentFile = '';
306
- let currentHunk: DiffHunk | null = null;
307
- let lineNumber = 0;
308
-
309
- for (const line of diffOutput.split('\n')) {
310
- // New file
311
- if (line.startsWith('+++ b/')) {
312
- currentFile = line.slice(6);
313
- currentHunk = { file: currentFile, lines: [] };
314
- hunks.push(currentHunk);
315
- continue;
316
- }
317
-
318
- // Hunk header: @@ -old,count +new,count @@
319
- const hunkMatch = line.match(/^@@\s+-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);
320
- if (hunkMatch) {
321
- lineNumber = parseInt(hunkMatch[1], 10) - 1; // Will be incremented on first line
322
- continue;
323
- }
324
-
325
- // Only process if we're in a file
326
- if (!currentHunk) continue;
327
-
328
- if (line.startsWith('+') && !line.startsWith('+++')) {
329
- lineNumber++;
330
- currentHunk.lines.push({
331
- lineNumber,
332
- content: line.slice(1), // Remove the '+' prefix
333
- type: 'add',
334
- });
335
- } else if (line.startsWith('-') && !line.startsWith('---')) {
336
- // Removed lines don't increment lineNumber
337
- // We don't check removed lines
338
- } else if (line.startsWith(' ')) {
339
- lineNumber++;
340
- // Context line, don't check
341
- }
342
- }
343
-
344
- return hunks;
345
- }
346
-
347
- function shouldCheckFile(filePath: string): boolean {
348
- // Check exclusions first
349
- for (const pattern of EXCLUDED_PATH_PATTERNS) {
350
- if (pattern.test(filePath)) {
351
- return false;
352
- }
353
- }
354
-
355
- // Check if it matches any included path
356
- for (const pattern of CHECKED_PATH_PATTERNS) {
357
- if (pattern.test(filePath)) {
358
- return true;
359
- }
360
- }
361
-
362
- return false;
363
- }
364
-
365
- function findViolations(hunks: DiffHunk[]): Violation[] {
366
- const violations: Violation[] = [];
367
-
368
- for (const hunk of hunks) {
369
- if (!shouldCheckFile(hunk.file)) {
370
- continue;
371
- }
372
-
373
- for (const line of hunk.lines) {
374
- if (line.type !== 'add') continue;
375
-
376
- // Skip comments (basic heuristic)
377
- const trimmed = line.content.trim();
378
- if (trimmed.startsWith('//') || trimmed.startsWith('*') || trimmed.startsWith('/*')) {
379
- // But still check if it's a suspicious comment
380
- if (!/intentional|pagination|user.?control|by.?design|expected/i.test(line.content)) {
381
- // Check for omission markers in comments too
382
- for (const pattern of TRUNCATION_PATTERNS.filter(p => p.id === 'omission-marker')) {
383
- for (const regex of pattern.patterns) {
384
- const match = regex.exec(line.content);
385
- if (match) {
386
- violations.push({
387
- file: hunk.file,
388
- line: line.lineNumber,
389
- column: match.index + 1,
390
- content: line.content,
391
- pattern,
392
- matchedText: match[0],
393
- });
394
- }
395
- }
396
- }
397
- }
398
- continue;
399
- }
400
-
401
- // Check each pattern
402
- for (const pattern of TRUNCATION_PATTERNS) {
403
- for (const regex of pattern.patterns) {
404
- const match = regex.exec(line.content);
405
- if (match) {
406
- violations.push({
407
- file: hunk.file,
408
- line: line.lineNumber,
409
- column: match.index + 1,
410
- content: line.content,
411
- pattern,
412
- matchedText: match[0],
413
- });
414
- break; // One match per pattern per line is enough
415
- }
416
- }
417
- }
418
- }
419
- }
420
-
421
- return violations;
422
- }
423
-
424
- // ============================================================================
425
- // OUTPUT FORMATTING
426
- // ============================================================================
427
-
428
- function formatViolations(violations: Violation[]): string {
429
- if (violations.length === 0) {
430
- return '';
431
- }
432
-
433
- const lines: string[] = [];
434
- lines.push('');
435
- lines.push('========================================');
436
- lines.push(' TRUNCATION VIOLATIONS DETECTED');
437
- lines.push('========================================');
438
- lines.push('');
439
- lines.push('The following changes appear to violate the "No Truncation Without Permission" rule.');
440
- lines.push('See LLM_RULES.md for the full policy.');
441
- lines.push('');
442
-
443
- // Group by file
444
- const byFile = new Map<string, Violation[]>();
445
- for (const v of violations) {
446
- const existing = byFile.get(v.file) || [];
447
- existing.push(v);
448
- byFile.set(v.file, existing);
449
- }
450
-
451
- for (const [file, fileViolations] of byFile) {
452
- lines.push(`📄 ${file}`);
453
- for (const v of fileViolations) {
454
- const severity = v.pattern.severity === 'error' ? '❌' : '⚠️';
455
- lines.push(` ${severity} Line ${v.line}: ${v.pattern.name}`);
456
- lines.push(` Pattern: ${v.pattern.description}`);
457
- lines.push(` Matched: ${v.matchedText}`);
458
- lines.push(` Code: ${v.content.trim().slice(0, 100)}${v.content.length > 100 ? '...' : ''}`);
459
- lines.push('');
460
- }
461
- }
462
-
463
- lines.push('----------------------------------------');
464
- lines.push('');
465
- lines.push('If this truncation is intentional and user-approved:');
466
- lines.push(' 1. Add a comment explaining why truncation is needed');
467
- lines.push(' 2. Include "intentional" or "user-approved" in the comment');
468
- lines.push(' 3. Document what content is being truncated and how much');
469
- lines.push('');
470
- lines.push('If this is pagination or user-controlled:');
471
- lines.push(' 1. Ensure the user can access the full content');
472
- lines.push(' 2. Add a comment with "pagination" or "user-control"');
473
- lines.push('');
474
- lines.push('========================================');
475
-
476
- return lines.join('\n');
477
- }
478
-
479
- // ============================================================================
480
- // MAIN
481
- // ============================================================================
482
-
483
- export interface CheckResult {
484
- violations: Violation[];
485
- astViolations: ASTViolation[];
486
- hasErrors: boolean;
487
- hasWarnings: boolean;
488
- output: string;
489
- }
490
-
491
- function getStagedFiles(): string[] {
492
- try {
493
- const output = execSync('git diff --cached --name-only', {
494
- encoding: 'utf-8',
495
- });
496
- return output
497
- .trim()
498
- .split('\n')
499
- .filter((f) => f && shouldCheckFile(f));
500
- } catch {
501
- return [];
502
- }
503
- }
504
-
505
- function getRepoRoot(): string {
506
- try {
507
- return execSync('git rev-parse --show-toplevel', {
508
- encoding: 'utf-8',
509
- }).trim();
510
- } catch {
511
- return process.cwd();
512
- }
513
- }
514
-
515
- export function checkStagedChanges(): CheckResult {
516
- const startTime = Date.now();
517
-
518
- let diffOutput: string;
519
- try {
520
- diffOutput = execSync('git diff --cached --unified=0', {
521
- encoding: 'utf-8',
522
- maxBuffer: 10 * 1024 * 1024, // 10MB
523
- });
524
- } catch {
525
- return {
526
- violations: [],
527
- astViolations: [],
528
- hasErrors: false,
529
- hasWarnings: false,
530
- output: '',
531
- };
532
- }
533
-
534
- if (!diffOutput.trim()) {
535
- return {
536
- violations: [],
537
- astViolations: [],
538
- hasErrors: false,
539
- hasWarnings: false,
540
- output: '',
541
- };
542
- }
543
-
544
- // Regex-based detection (fast, catches obvious patterns)
545
- const hunks = parseDiff(diffOutput);
546
- const violations = findViolations(hunks);
547
-
548
- // AST-based detection (semantic analysis)
549
- const repoRoot = getRepoRoot();
550
- const stagedFiles = getStagedFiles().map((f) => join(repoRoot, f));
551
- const astViolations = analyzeFiles(stagedFiles);
552
-
553
- const regexTime = Date.now() - startTime;
554
-
555
- const hasErrors =
556
- violations.some((v) => v.pattern.severity === 'error') ||
557
- astViolations.some((v) => v.severity === 'error');
558
- const hasWarnings =
559
- violations.some((v) => v.pattern.severity === 'warning') ||
560
- astViolations.some((v) => v.severity === 'warning');
561
-
562
- // Combine output
563
- let output = formatViolations(violations);
564
- const astOutput = formatASTViolations(astViolations);
565
- if (astOutput) {
566
- output += '\n' + astOutput;
567
- }
568
-
569
- // Add timing info in verbose mode
570
- if (process.env.TRUNCATION_CHECK_VERBOSE) {
571
- output += `\n[Timing: regex=${regexTime}ms, total=${Date.now() - startTime}ms, files=${stagedFiles.length}]`;
572
- }
573
-
574
- return {
575
- violations,
576
- astViolations,
577
- hasErrors,
578
- hasWarnings,
579
- output,
580
- };
581
- }
582
-
583
- // CLI entry point
584
- if (process.argv[1]?.endsWith('index.ts') || process.argv[1]?.endsWith('index.js')) {
585
- const result = checkStagedChanges();
586
- if (result.output) {
587
- console.error(result.output);
588
- }
589
- // Exit with error if any errors found (regex or AST)
590
- if (result.hasErrors) {
591
- process.exit(1);
592
- }
593
- }
594
-
595
- export { type ASTViolation } from './ast-analyzer.js';
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "Node16",
5
- "moduleResolution": "Node16",
6
- "strict": true,
7
- "esModuleInterop": true,
8
- "resolveJsonModule": true,
9
- "noEmit": true,
10
- "skipLibCheck": true
11
- },
12
- "include": ["./**/*.ts"]
13
- }