hyntx 1.5.0 → 2.0.1
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 +499 -6
- package/dist/api/index.d.ts +665 -0
- package/dist/api/index.js +2851 -0
- package/dist/cli.d.ts +225 -0
- package/dist/cli.js +5770 -0
- package/dist/index-B6r9mP1J.d.ts +394 -0
- package/dist/index.d.ts +3 -251
- package/dist/index.js +2349 -3932
- package/package.json +23 -4
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
import { P as PatternSeverity, a as AnalysisProvider, b as ProjectContext, R as RulesConfig, A as AnalysisResult, L as LogReadResult, E as ExtractedPrompt, D as DayGroup, H as HistoryMetadata, c as HistoryEntry, d as ListHistoryOptions, C as ComparisonResult, e as ProviderType, f as EnvConfig, g as CacheOptions } from '../index-B6r9mP1J.js';
|
|
2
|
+
export { h as AnalysisPattern, i as AnalysisStats, p as AnthropicConfig, Q as BATCH_STRATEGIES, l as BatchStrategy, m as BatchStrategyType, B as BeforeAfter, T as CACHE_DEFAULTS, s as CacheMetadata, t as CachedBatchResult, n as ClaudeMessage, w as CliOptions, q as ComparisonChanges, M as ENV_DEFAULTS, K as EXIT_CODES, x as ExitCode, F as FilePosition, G as GoogleConfig, J as JsonErrorResponse, o as LogEntry, u as LogWatcher, O as OllamaConfig, y as OutputFormat, N as PROVIDER_LIMITS, r as PatternChange, j as PromptAnalysis, v as PromptEvent, k as ProviderLimits, S as SchemaVersion, I as ShellConfigResult, z as ShellType, W as WatcherOptions } from '../index-B6r9mP1J.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema variants and issue taxonomy for AI analysis providers.
|
|
7
|
+
*
|
|
8
|
+
* This module provides:
|
|
9
|
+
* - Issue taxonomy with predefined metadata
|
|
10
|
+
* - System prompts for different schema types
|
|
11
|
+
* - Type definitions for schema variants
|
|
12
|
+
* - Rules configuration utilities
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Metadata for a predefined issue type.
|
|
17
|
+
* Used by the aggregator to convert minimal issue IDs to full patterns.
|
|
18
|
+
*/
|
|
19
|
+
type IssueMetadata = {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly severity: PatternSeverity;
|
|
22
|
+
readonly suggestion: string;
|
|
23
|
+
readonly exampleBefore?: string;
|
|
24
|
+
readonly exampleAfter?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Taxonomy mapping issue IDs to their metadata.
|
|
28
|
+
*/
|
|
29
|
+
type IssueTaxonomy = Record<string, IssueMetadata>;
|
|
30
|
+
/**
|
|
31
|
+
* Schema type identifier.
|
|
32
|
+
* - minimal: Lightweight schema for small models (issue IDs + score)
|
|
33
|
+
* - simple: Medium schema with issue objects
|
|
34
|
+
* - full: Complete schema with patterns and stats
|
|
35
|
+
*/
|
|
36
|
+
type SchemaType = 'minimal' | 'simple' | 'full';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Aggregator for converting minimal analysis results to full AnalysisResult.
|
|
40
|
+
*
|
|
41
|
+
* This module provides utilities to:
|
|
42
|
+
* - Convert minimal responses (issue IDs + score) to full AnalysisResult
|
|
43
|
+
* - Aggregate multiple minimal results into a single result
|
|
44
|
+
* - Look up issue metadata from the taxonomy with graceful fallback
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Minimal result from small models.
|
|
49
|
+
* Contains only issue IDs and a quality score.
|
|
50
|
+
*/
|
|
51
|
+
type MinimalResult = {
|
|
52
|
+
readonly issues: readonly string[];
|
|
53
|
+
readonly score: number;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Prompt Analyzer for Hyntx
|
|
58
|
+
*
|
|
59
|
+
* This module provides core analysis functionality for batching prompts,
|
|
60
|
+
* merging results, and orchestrating the analysis workflow.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Options for analyzing prompts.
|
|
65
|
+
*/
|
|
66
|
+
type AnalyzePromptsOptions = {
|
|
67
|
+
readonly provider: AnalysisProvider;
|
|
68
|
+
readonly prompts: readonly string[];
|
|
69
|
+
readonly date: string;
|
|
70
|
+
readonly context?: ProjectContext;
|
|
71
|
+
readonly rules?: RulesConfig;
|
|
72
|
+
readonly onProgress?: (current: number, total: number) => void;
|
|
73
|
+
readonly noCache?: boolean;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Analyzes prompts using the provided AI provider.
|
|
77
|
+
*
|
|
78
|
+
* Orchestrates the full analysis workflow:
|
|
79
|
+
* 1. Sanitizes prompts to remove secrets
|
|
80
|
+
* 2. Batches prompts based on provider limits
|
|
81
|
+
* 3. Checks cache for existing results (unless noCache is true)
|
|
82
|
+
* 4. Processes batches sequentially with progress updates
|
|
83
|
+
* 5. Stores results in cache for future use
|
|
84
|
+
* 6. Merges batch results into final output
|
|
85
|
+
* 7. Applies rules configuration to filter/modify patterns
|
|
86
|
+
*
|
|
87
|
+
* @param options - Analysis options
|
|
88
|
+
* @returns Analysis result
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const result = await analyzePrompts({
|
|
93
|
+
* provider: ollamaProvider,
|
|
94
|
+
* prompts: ['prompt1', 'prompt2', 'prompt3'],
|
|
95
|
+
* date: '2025-01-15',
|
|
96
|
+
* context: { role: 'developer', techStack: ['TypeScript'] },
|
|
97
|
+
* onProgress: (current, total) => console.log(`${current}/${total}`),
|
|
98
|
+
* noCache: false
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function analyzePrompts(options: AnalyzePromptsOptions): Promise<AnalysisResult>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Secret Sanitizer for Hyntx
|
|
106
|
+
*
|
|
107
|
+
* This module provides functionality to automatically redact secrets and sensitive
|
|
108
|
+
* information from prompts before sending them to AI providers.
|
|
109
|
+
*/
|
|
110
|
+
/**
|
|
111
|
+
* Result of sanitizing a single text.
|
|
112
|
+
*/
|
|
113
|
+
type SanitizeResult = {
|
|
114
|
+
readonly text: string;
|
|
115
|
+
readonly redacted: number;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Result of sanitizing multiple prompts.
|
|
119
|
+
*/
|
|
120
|
+
type SanitizePromptsResult = {
|
|
121
|
+
readonly prompts: readonly string[];
|
|
122
|
+
readonly totalRedacted: number;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Sanitizes a single text by redacting all detected secrets.
|
|
126
|
+
*
|
|
127
|
+
* @param text - Text to sanitize
|
|
128
|
+
* @returns Sanitized text and count of redactions
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const result = sanitize('My API key is sk-1234567890abcdef...');
|
|
133
|
+
* // { text: 'My API key is [REDACTED_OPENAI_KEY]', redacted: 1 }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare function sanitize(text: string): SanitizeResult;
|
|
137
|
+
/**
|
|
138
|
+
* Sanitizes an array of prompts and returns sanitized prompts with total redaction count.
|
|
139
|
+
*
|
|
140
|
+
* @param prompts - Array of prompts to sanitize
|
|
141
|
+
* @returns Sanitized prompts and total number of redactions across all prompts
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const prompts = [
|
|
146
|
+
* 'My key is sk-123...',
|
|
147
|
+
* 'Email me at user@example.com'
|
|
148
|
+
* ];
|
|
149
|
+
* const result = sanitizePrompts(prompts);
|
|
150
|
+
* // {
|
|
151
|
+
* // prompts: ['My key is [REDACTED_OPENAI_KEY]', 'Email me at [REDACTED_EMAIL]'],
|
|
152
|
+
* // totalRedacted: 2
|
|
153
|
+
* // }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function sanitizePrompts(prompts: readonly string[]): SanitizePromptsResult;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Basic JSONL Log Reader for Claude Code logs.
|
|
160
|
+
*
|
|
161
|
+
* This module provides functionality to read and parse Claude Code JSONL log files.
|
|
162
|
+
* It extracts user prompts with metadata for analysis.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Options for filtering logs.
|
|
167
|
+
*/
|
|
168
|
+
type ReadLogsOptions = {
|
|
169
|
+
readonly date?: string;
|
|
170
|
+
readonly from?: string;
|
|
171
|
+
readonly to?: string;
|
|
172
|
+
readonly project?: string;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Checks if the Claude projects directory exists.
|
|
176
|
+
*
|
|
177
|
+
* @returns true if ~/.claude/projects/ exists
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* if (!claudeProjectsExist()) {
|
|
182
|
+
* console.error('Claude Code logs not found');
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function claudeProjectsExist(): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Extracts the project name from a JSONL file path.
|
|
189
|
+
* The project hash is the directory name containing the JSONL file.
|
|
190
|
+
*
|
|
191
|
+
* @param filePath - Full path to the JSONL file
|
|
192
|
+
* @returns The project hash/name
|
|
193
|
+
*/
|
|
194
|
+
declare function extractProjectName(filePath: string): string;
|
|
195
|
+
/**
|
|
196
|
+
* Parses date strings into Date objects.
|
|
197
|
+
* Supports 'today', 'yesterday', and ISO date format (YYYY-MM-DD).
|
|
198
|
+
*
|
|
199
|
+
* @param dateStr - Date string to parse
|
|
200
|
+
* @returns Parsed Date object
|
|
201
|
+
* @throws Error if date string is invalid
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* parseDate('today') // Returns current date at start of day
|
|
206
|
+
* parseDate('yesterday') // Returns yesterday at start of day
|
|
207
|
+
* parseDate('2025-01-23') // Returns specific date
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function parseDate(dateStr: string): Date;
|
|
211
|
+
/**
|
|
212
|
+
* Groups prompts by day.
|
|
213
|
+
*
|
|
214
|
+
* @param prompts - Array of prompts to group
|
|
215
|
+
* @returns Array of DayGroup objects, sorted by date
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const groups = groupByDay(prompts);
|
|
220
|
+
* // [
|
|
221
|
+
* // { date: '2025-01-23', prompts: [...], projects: ['project-a'] },
|
|
222
|
+
* // { date: '2025-01-24', prompts: [...], projects: ['project-b'] }
|
|
223
|
+
* // ]
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare function groupByDay(prompts: readonly ExtractedPrompt[]): readonly DayGroup[];
|
|
227
|
+
/**
|
|
228
|
+
* Reads all Claude Code logs and extracts user prompts.
|
|
229
|
+
*
|
|
230
|
+
* This function finds all JSONL files in the Claude projects directory,
|
|
231
|
+
* parses them, and extracts user messages sorted chronologically.
|
|
232
|
+
* Supports filtering by date range, single date, and project name.
|
|
233
|
+
*
|
|
234
|
+
* @param options - Optional filtering options
|
|
235
|
+
* @returns LogReadResult containing prompts and warnings
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // Read all logs
|
|
240
|
+
* const result = await readLogs();
|
|
241
|
+
*
|
|
242
|
+
* // Filter by date
|
|
243
|
+
* const today = await readLogs({ date: 'today' });
|
|
244
|
+
*
|
|
245
|
+
* // Filter by date range
|
|
246
|
+
* const range = await readLogs({ from: '2025-01-20', to: '2025-01-25' });
|
|
247
|
+
*
|
|
248
|
+
* // Filter by project
|
|
249
|
+
* const project = await readLogs({ project: 'my-app' });
|
|
250
|
+
*
|
|
251
|
+
* // Combine filters
|
|
252
|
+
* const combined = await readLogs({
|
|
253
|
+
* from: '2025-01-20',
|
|
254
|
+
* to: '2025-01-25',
|
|
255
|
+
* project: 'my-app'
|
|
256
|
+
* });
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare function readLogs(options?: ReadLogsOptions): Promise<LogReadResult>;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* History management for Hyntx.
|
|
263
|
+
*
|
|
264
|
+
* This module provides functions to save, load, and compare analysis results.
|
|
265
|
+
* History files are stored in ~/.hyntx/history/ with filenames as YYYY-MM-DD.json.
|
|
266
|
+
*/
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Gets the history directory path.
|
|
270
|
+
*
|
|
271
|
+
* @returns History directory path
|
|
272
|
+
*/
|
|
273
|
+
declare function getHistoryDir(): string;
|
|
274
|
+
/**
|
|
275
|
+
* Ensures the history directory exists with proper permissions.
|
|
276
|
+
* Creates the directory if it doesn't exist.
|
|
277
|
+
*
|
|
278
|
+
* @throws Error if directory creation fails
|
|
279
|
+
*/
|
|
280
|
+
declare function ensureHistoryDir(): Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Saves an analysis result to history with atomic write.
|
|
283
|
+
* Sanitizes pattern examples before saving to protect privacy.
|
|
284
|
+
* Does not throw on failure - logs warning instead.
|
|
285
|
+
*
|
|
286
|
+
* @param result - Analysis result to save
|
|
287
|
+
* @param metadata - Analysis execution metadata
|
|
288
|
+
*/
|
|
289
|
+
declare function saveAnalysisResult(result: AnalysisResult, metadata: HistoryMetadata): Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* Loads an analysis result from history for a specific date.
|
|
292
|
+
*
|
|
293
|
+
* @param date - Date string (YYYY-MM-DD)
|
|
294
|
+
* @returns History entry or null if not found
|
|
295
|
+
*/
|
|
296
|
+
declare function loadAnalysisResult(date: string): Promise<HistoryEntry | null>;
|
|
297
|
+
/**
|
|
298
|
+
* Lists all available history dates.
|
|
299
|
+
* Returns dates in descending order (newest first).
|
|
300
|
+
*
|
|
301
|
+
* @param options - Optional filtering options
|
|
302
|
+
* @returns Array of date strings (YYYY-MM-DD)
|
|
303
|
+
*/
|
|
304
|
+
declare function listAvailableDates(options?: ListHistoryOptions): Promise<readonly string[]>;
|
|
305
|
+
/**
|
|
306
|
+
* Compares two analysis results and identifies changes.
|
|
307
|
+
*
|
|
308
|
+
* @param before - Earlier analysis result
|
|
309
|
+
* @param after - Later analysis result
|
|
310
|
+
* @returns Comparison result with detected changes
|
|
311
|
+
*/
|
|
312
|
+
declare function compareResults(before: AnalysisResult, after: AnalysisResult): ComparisonResult;
|
|
313
|
+
/**
|
|
314
|
+
* Calculates the date one week ago from a given date.
|
|
315
|
+
*
|
|
316
|
+
* @param fromDate - Date string (YYYY-MM-DD) or Date object
|
|
317
|
+
* @returns Date string one week ago (YYYY-MM-DD)
|
|
318
|
+
*/
|
|
319
|
+
declare function getDateOneWeekAgo(fromDate: string | Date): string;
|
|
320
|
+
/**
|
|
321
|
+
* Calculates the date one month ago from a given date.
|
|
322
|
+
*
|
|
323
|
+
* @param fromDate - Date string (YYYY-MM-DD) or Date object
|
|
324
|
+
* @returns Date string one month ago (YYYY-MM-DD)
|
|
325
|
+
*/
|
|
326
|
+
declare function getDateOneMonthAgo(fromDate: string | Date): string;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Provider factory with multi-provider support and fallback.
|
|
330
|
+
*
|
|
331
|
+
* This module provides factory functions for creating and selecting AI providers
|
|
332
|
+
* with automatic fallback support when the primary provider is unavailable.
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Callback type for fallback notifications.
|
|
337
|
+
* Called when getAvailableProvider falls back to a different provider.
|
|
338
|
+
*
|
|
339
|
+
* @param from - The provider that was unavailable
|
|
340
|
+
* @param to - The provider that will be used instead
|
|
341
|
+
*/
|
|
342
|
+
type FallbackCallback = (from: string, to: string) => void;
|
|
343
|
+
/**
|
|
344
|
+
* Creates a provider instance for the given type.
|
|
345
|
+
*
|
|
346
|
+
* @param type - The provider type to create
|
|
347
|
+
* @param config - Environment configuration with provider settings
|
|
348
|
+
* @returns The created provider instance
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* const config = getEnvConfig();
|
|
352
|
+
* const provider = createProvider('ollama', config);
|
|
353
|
+
*/
|
|
354
|
+
declare function createProvider(type: ProviderType, config: EnvConfig): AnalysisProvider;
|
|
355
|
+
/**
|
|
356
|
+
* Gets the first available provider from the configured services list.
|
|
357
|
+
* Tests each provider in order and returns the first one that is available.
|
|
358
|
+
* Optionally calls a callback when falling back to a different provider.
|
|
359
|
+
*
|
|
360
|
+
* @param config - Environment configuration with services list and provider settings
|
|
361
|
+
* @param onFallback - Optional callback called when falling back to a different provider
|
|
362
|
+
* @returns Promise resolving to the first available provider
|
|
363
|
+
* @throws Error if no providers are configured or none are available
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* const config = getEnvConfig();
|
|
367
|
+
* const provider = await getAvailableProvider(config, (from, to) => {
|
|
368
|
+
* console.log(`Falling back from ${from} to ${to}`);
|
|
369
|
+
* });
|
|
370
|
+
*/
|
|
371
|
+
declare function getAvailableProvider(config: EnvConfig, onFallback?: FallbackCallback): Promise<AnalysisProvider>;
|
|
372
|
+
/**
|
|
373
|
+
* Gets all configured providers as instances.
|
|
374
|
+
* Returns providers for all types listed in the services configuration.
|
|
375
|
+
*
|
|
376
|
+
* @param config - Environment configuration with services list and provider settings
|
|
377
|
+
* @returns Array of provider instances
|
|
378
|
+
* @throws Error if no providers are configured
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* const config = getEnvConfig();
|
|
382
|
+
* const providers = getAllProviders(config);
|
|
383
|
+
* // [OllamaProvider, AnthropicProvider, ...]
|
|
384
|
+
*/
|
|
385
|
+
declare function getAllProviders(config: EnvConfig): readonly AnalysisProvider[];
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Environment variable management for Hyntx.
|
|
389
|
+
*
|
|
390
|
+
* This module provides functions for reading and parsing environment
|
|
391
|
+
* configuration, detecting first-time usage, and managing provider settings.
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Checks if this is the first run of Hyntx.
|
|
396
|
+
* First run is detected when HYNTX_SERVICES is not set.
|
|
397
|
+
*
|
|
398
|
+
* @returns true if this is the first run
|
|
399
|
+
*/
|
|
400
|
+
declare function isFirstRun(): boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Parses the HYNTX_SERVICES environment variable into an array of valid providers.
|
|
403
|
+
* Invalid provider names are filtered out.
|
|
404
|
+
*
|
|
405
|
+
* @param services - Comma-separated list of provider names (e.g., "ollama,anthropic")
|
|
406
|
+
* @returns Array of valid ProviderType values
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* parseServices('ollama,anthropic') // ['ollama', 'anthropic']
|
|
410
|
+
* parseServices('ollama,invalid,google') // ['ollama', 'google']
|
|
411
|
+
* parseServices('') // []
|
|
412
|
+
* parseServices(undefined) // []
|
|
413
|
+
*/
|
|
414
|
+
declare function parseServices(services: string | undefined): readonly ProviderType[];
|
|
415
|
+
/**
|
|
416
|
+
* Gets the complete configuration from environment variables.
|
|
417
|
+
* Missing values are filled with defaults from ENV_DEFAULTS.
|
|
418
|
+
*
|
|
419
|
+
* @returns Complete EnvConfig object with all settings
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* // With environment variables set:
|
|
423
|
+
* // HYNTX_SERVICES=ollama,anthropic
|
|
424
|
+
* // HYNTX_ANTHROPIC_KEY=sk-ant-xxx
|
|
425
|
+
*
|
|
426
|
+
* const config = getEnvConfig();
|
|
427
|
+
* // {
|
|
428
|
+
* // services: ['ollama', 'anthropic'],
|
|
429
|
+
* // reminder: '7d',
|
|
430
|
+
* // ollama: { model: 'llama3.2', host: 'http://localhost:11434' },
|
|
431
|
+
* // anthropic: { model: 'claude-3-5-haiku-latest', apiKey: 'sk-ant-xxx' },
|
|
432
|
+
* // google: { model: 'gemini-2.0-flash-exp', apiKey: '' }
|
|
433
|
+
* // }
|
|
434
|
+
*/
|
|
435
|
+
declare function getEnvConfig(): EnvConfig;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Project-specific configuration system.
|
|
439
|
+
*
|
|
440
|
+
* This module provides utilities for loading and merging project-specific
|
|
441
|
+
* configurations from `.hyntxrc.json` files. Project configs are merged with
|
|
442
|
+
* environment configs, with env vars taking precedence.
|
|
443
|
+
*
|
|
444
|
+
* Features:
|
|
445
|
+
* - Directory tree traversal to find config files
|
|
446
|
+
* - JSON validation with Zod schema
|
|
447
|
+
* - Config caching for performance
|
|
448
|
+
* - Graceful error handling (non-fatal)
|
|
449
|
+
*/
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Zod schema for the .hyntxrc.json file.
|
|
453
|
+
*/
|
|
454
|
+
declare const PROJECT_CONFIG_SCHEMA: z.ZodObject<{
|
|
455
|
+
context: z.ZodOptional<z.ZodObject<{
|
|
456
|
+
role: z.ZodOptional<z.ZodString>;
|
|
457
|
+
techStack: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
458
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
459
|
+
guidelines: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
460
|
+
projectType: z.ZodOptional<z.ZodString>;
|
|
461
|
+
}, z.core.$strip>>;
|
|
462
|
+
rules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
463
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
464
|
+
severity: z.ZodOptional<z.ZodEnum<{
|
|
465
|
+
medium: "medium";
|
|
466
|
+
low: "low";
|
|
467
|
+
high: "high";
|
|
468
|
+
}>>;
|
|
469
|
+
}, z.core.$strip>>>;
|
|
470
|
+
}, z.core.$strip>;
|
|
471
|
+
/**
|
|
472
|
+
* Type for the validated project config.
|
|
473
|
+
*/
|
|
474
|
+
type ProjectConfig = z.infer<typeof PROJECT_CONFIG_SCHEMA>;
|
|
475
|
+
/**
|
|
476
|
+
* Loads and validates a project configuration file.
|
|
477
|
+
*
|
|
478
|
+
* Reads the JSON file, parses it, and validates against the Zod schema.
|
|
479
|
+
* Errors are non-fatal and logged as warnings.
|
|
480
|
+
*
|
|
481
|
+
* @param configPath - Path to the .hyntxrc.json file
|
|
482
|
+
* @returns Validated config object, or null if loading/validation fails
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* const config = loadProjectConfig('/path/to/.hyntxrc.json');
|
|
487
|
+
* if (config?.context) {
|
|
488
|
+
* console.log('Project role:', config.context.role);
|
|
489
|
+
* }
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
declare function loadProjectConfig(configPath: string): ProjectConfig | null;
|
|
493
|
+
/**
|
|
494
|
+
* Merges a project config with an environment config.
|
|
495
|
+
*
|
|
496
|
+
* Merging rules:
|
|
497
|
+
* - Environment variables take precedence over project config
|
|
498
|
+
* - If envConfig.context is set (from env vars), it overrides project context
|
|
499
|
+
* - Otherwise, project context is used if available
|
|
500
|
+
* - Rules from project config are always included if present
|
|
501
|
+
*
|
|
502
|
+
* @param envConfig - Configuration from environment variables
|
|
503
|
+
* @param projectConfig - Configuration from .hyntxrc.json
|
|
504
|
+
* @returns Merged configuration with context and rules fields
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const merged = mergeConfigs(envConfig, projectConfig);
|
|
509
|
+
* if (merged.context) {
|
|
510
|
+
* // Use project context in analysis
|
|
511
|
+
* }
|
|
512
|
+
* if (merged.rules) {
|
|
513
|
+
* // Apply custom rules configuration
|
|
514
|
+
* }
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
declare function mergeConfigs(envConfig: EnvConfig, projectConfig: ProjectConfig | null): EnvConfig & {
|
|
518
|
+
context?: ProjectContext;
|
|
519
|
+
rules?: RulesConfig;
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Loads project configuration for the specified working directory.
|
|
523
|
+
*
|
|
524
|
+
* This is the main entry point for loading project configs. It:
|
|
525
|
+
* 1. Checks the cache first
|
|
526
|
+
* 2. Searches for .hyntxrc.json up the directory tree
|
|
527
|
+
* 3. Loads and validates the config file
|
|
528
|
+
* 4. Caches the result
|
|
529
|
+
*
|
|
530
|
+
* @param cwd - Current working directory
|
|
531
|
+
* @returns Loaded config or null if not found/invalid
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* const config = loadProjectConfigForCwd(process.cwd());
|
|
536
|
+
* const merged = mergeConfigs(envConfig, config);
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
declare function loadProjectConfigForCwd(cwd: string): ProjectConfig | null;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Disk-based cache for analysis results.
|
|
543
|
+
*
|
|
544
|
+
* This module provides caching functionality to avoid redundant API calls
|
|
545
|
+
* for the same prompts. Cache entries are invalidated when:
|
|
546
|
+
* - TTL expires (default: 7 days)
|
|
547
|
+
* - Model changes
|
|
548
|
+
* - System prompt changes
|
|
549
|
+
*/
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Generates a cache key from prompts, model, and schema type.
|
|
553
|
+
* The cache key uniquely identifies a batch of prompts for a specific model and schema.
|
|
554
|
+
*
|
|
555
|
+
* @param prompts - Array of prompt strings
|
|
556
|
+
* @param model - Model identifier
|
|
557
|
+
* @param schemaType - Schema type used for analysis (defaults to 'full' for backward compatibility)
|
|
558
|
+
* @returns Cache key hash
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```typescript
|
|
562
|
+
* const key = generateCacheKey(['prompt1', 'prompt2'], 'llama3.2', 'minimal');
|
|
563
|
+
* // Returns: 'a3f2b1...' (SHA-256 hash)
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
declare function generateCacheKey(prompts: readonly string[], model: string, schemaType?: string): string;
|
|
567
|
+
/**
|
|
568
|
+
* Hashes the system prompt for invalidation detection.
|
|
569
|
+
* When the system prompt changes, all cache entries become invalid.
|
|
570
|
+
*
|
|
571
|
+
* @returns System prompt hash
|
|
572
|
+
*/
|
|
573
|
+
declare function hashSystemPrompt(): string;
|
|
574
|
+
/**
|
|
575
|
+
* Validates that the system prompt has not changed.
|
|
576
|
+
* If it has changed, clears the entire cache.
|
|
577
|
+
*
|
|
578
|
+
* @returns True if system prompt is valid, false if cache was invalidated
|
|
579
|
+
*/
|
|
580
|
+
declare function validateSystemPrompt(): Promise<boolean>;
|
|
581
|
+
/**
|
|
582
|
+
* Gets a cached result if it exists and is valid.
|
|
583
|
+
* Returns null if cache miss or entry is invalid (expired, wrong model, etc).
|
|
584
|
+
*
|
|
585
|
+
* @param prompts - Array of prompt strings
|
|
586
|
+
* @param model - Model identifier
|
|
587
|
+
* @param options - Cache options
|
|
588
|
+
* @returns Cached result or null
|
|
589
|
+
*/
|
|
590
|
+
declare function getCachedResult(prompts: readonly string[], model: string, options?: CacheOptions): Promise<AnalysisResult | null>;
|
|
591
|
+
/**
|
|
592
|
+
* Stores an analysis result in the cache with atomic write.
|
|
593
|
+
* Does not throw on failure - logs warning instead.
|
|
594
|
+
*
|
|
595
|
+
* @param prompts - Array of prompt strings
|
|
596
|
+
* @param model - Model identifier
|
|
597
|
+
* @param result - Analysis result to cache
|
|
598
|
+
*/
|
|
599
|
+
declare function setCachedResult(prompts: readonly string[], model: string, result: AnalysisResult): Promise<void>;
|
|
600
|
+
/**
|
|
601
|
+
* Clears all cached entries.
|
|
602
|
+
* Removes the entire cache analysis directory.
|
|
603
|
+
*/
|
|
604
|
+
declare function clearCache(): Promise<void>;
|
|
605
|
+
/**
|
|
606
|
+
* Removes expired cache entries based on TTL.
|
|
607
|
+
* Useful for periodic cleanup to prevent disk bloat.
|
|
608
|
+
*
|
|
609
|
+
* @param options - Cache options
|
|
610
|
+
* @returns Number of entries removed
|
|
611
|
+
*/
|
|
612
|
+
declare function cleanupExpiredEntries(options?: CacheOptions): Promise<number>;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Path constants for Hyntx.
|
|
616
|
+
*
|
|
617
|
+
* This module provides path constants for accessing Claude Code logs
|
|
618
|
+
* and Hyntx state files.
|
|
619
|
+
*/
|
|
620
|
+
/**
|
|
621
|
+
* Path to Claude Code projects directory.
|
|
622
|
+
* Contains JSONL log files organized by project hash.
|
|
623
|
+
*
|
|
624
|
+
* Structure: ~/.claude/projects/<project-hash>/*.jsonl
|
|
625
|
+
*
|
|
626
|
+
* Can be overridden via HYNTX_CLAUDE_PROJECTS_DIR environment variable.
|
|
627
|
+
* This is useful for testing or custom Claude Code installations.
|
|
628
|
+
*/
|
|
629
|
+
declare const CLAUDE_PROJECTS_DIR: string;
|
|
630
|
+
/**
|
|
631
|
+
* Path to Hyntx last run timestamp file.
|
|
632
|
+
* Used by the reminder system to track when analysis was last run.
|
|
633
|
+
*/
|
|
634
|
+
declare const LAST_RUN_FILE: string;
|
|
635
|
+
/**
|
|
636
|
+
* Path to Hyntx history directory.
|
|
637
|
+
* Contains analysis history files organized by date (YYYY-MM-DD.json).
|
|
638
|
+
*
|
|
639
|
+
* Structure: ~/.hyntx/history/YYYY-MM-DD.json
|
|
640
|
+
*
|
|
641
|
+
* Can be overridden via HYNTX_HISTORY_DIR environment variable.
|
|
642
|
+
*/
|
|
643
|
+
declare const HYNTX_HISTORY_DIR: string;
|
|
644
|
+
/**
|
|
645
|
+
* Path to Hyntx cache directory.
|
|
646
|
+
* Contains cached analysis results to avoid redundant API calls.
|
|
647
|
+
*
|
|
648
|
+
* Structure: ~/.hyntx-cache/analysis/<cache-key>.json
|
|
649
|
+
* ~/.hyntx-cache/analysis/.metadata.json
|
|
650
|
+
*
|
|
651
|
+
* Can be overridden via HYNTX_CACHE_DIR environment variable.
|
|
652
|
+
*/
|
|
653
|
+
declare const HYNTX_CACHE_DIR: string;
|
|
654
|
+
/**
|
|
655
|
+
* Path to cache analysis subdirectory.
|
|
656
|
+
* Contains individual cache entry files.
|
|
657
|
+
*/
|
|
658
|
+
declare const CACHE_ANALYSIS_DIR: string;
|
|
659
|
+
/**
|
|
660
|
+
* Path to cache metadata file.
|
|
661
|
+
* Stores system prompt hash for invalidation detection.
|
|
662
|
+
*/
|
|
663
|
+
declare const CACHE_META_FILE: string;
|
|
664
|
+
|
|
665
|
+
export { AnalysisProvider, AnalysisResult, CACHE_ANALYSIS_DIR, CACHE_META_FILE, CLAUDE_PROJECTS_DIR, CacheOptions, ComparisonResult, DayGroup, EnvConfig, ExtractedPrompt, type FallbackCallback, HYNTX_CACHE_DIR, HYNTX_HISTORY_DIR, HistoryEntry, HistoryMetadata, type IssueMetadata, type IssueTaxonomy, LAST_RUN_FILE, ListHistoryOptions, LogReadResult, type MinimalResult, PatternSeverity, ProjectContext, ProviderType, type ReadLogsOptions, type SanitizePromptsResult, type SanitizeResult, type SchemaType, analyzePrompts, claudeProjectsExist, cleanupExpiredEntries, clearCache, compareResults, createProvider, ensureHistoryDir, extractProjectName, generateCacheKey, getAllProviders, getAvailableProvider, getCachedResult, getDateOneMonthAgo, getDateOneWeekAgo, getEnvConfig, getHistoryDir, groupByDay, hashSystemPrompt, isFirstRun, listAvailableDates, loadAnalysisResult, loadProjectConfig, loadProjectConfigForCwd, mergeConfigs, parseDate, parseServices, readLogs, sanitize, sanitizePrompts, saveAnalysisResult, setCachedResult, validateSystemPrompt };
|