hyntx 2.2.0 → 2.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/dist/cli.d.ts CHANGED
@@ -175,9 +175,10 @@ declare function connectProviderWithSpinner(isJsonMode: boolean): Promise<Analys
175
175
  * @param rules - Optional rules configuration
176
176
  * @param isJsonMode - Whether JSON output mode is active
177
177
  * @param noCache - Whether to bypass cache
178
+ * @param extractedPrompts - Optional extracted prompts for cache lookup
178
179
  * @returns Analysis result
179
180
  */
180
- declare function analyzeWithProgress(provider: AnalysisProvider, prompts: readonly string[], date: string, context: ProjectContext | undefined, rules: RulesConfig | undefined, isJsonMode: boolean, noCache?: boolean): Promise<AnalysisResult>;
181
+ declare function analyzeWithProgress(provider: AnalysisProvider, prompts: readonly string[], date: string, context: ProjectContext | undefined, rules: RulesConfig | undefined, isJsonMode: boolean, noCache?: boolean, extractedPrompts?: readonly ExtractedPrompt[]): Promise<AnalysisResult>;
181
182
  /**
182
183
  * Runs watch mode for real-time prompt analysis.
183
184
  *
package/dist/cli.js CHANGED
@@ -530,7 +530,10 @@ var HYNTX_HISTORY_DIR = process.env["HYNTX_HISTORY_DIR"] ?? join(HOME, ".hyntx",
530
530
  var HYNTX_CACHE_DIR = process.env["HYNTX_CACHE_DIR"] ?? join(HOME, ".hyntx-cache");
531
531
  var CACHE_ANALYSIS_DIR = join(HYNTX_CACHE_DIR, "analysis");
532
532
  var CACHE_META_FILE = join(CACHE_ANALYSIS_DIR, ".metadata.json");
533
- process.env["HYNTX_RESULTS_DIR"] ?? join(HOME, ".hyntx", "results");
533
+ var HYNTX_RESULTS_DIR = process.env["HYNTX_RESULTS_DIR"] ?? join(HOME, ".hyntx", "results");
534
+ function getResultsDateDir(date) {
535
+ return join(HYNTX_RESULTS_DIR, date);
536
+ }
534
537
 
535
538
  // src/core/schema-validator.ts
536
539
  var SUPPORTED_VERSIONS = ["1.0"];
@@ -2551,6 +2554,118 @@ ${chalk6.dim(entry.name)}`,
2551
2554
  function formatRulesListJson(entries, compact = false) {
2552
2555
  return compact ? JSON.stringify(entries) : JSON.stringify(entries, null, 2);
2553
2556
  }
2557
+ init_logger_base();
2558
+ function getPromptResultHash(prompt, metadata) {
2559
+ const systemPromptHash = hashSystemPrompt();
2560
+ const input = [
2561
+ prompt,
2562
+ metadata.date,
2563
+ metadata.project ?? "",
2564
+ metadata.model,
2565
+ metadata.schemaType,
2566
+ systemPromptHash
2567
+ ].join("\0");
2568
+ return hashString(input);
2569
+ }
2570
+ async function getPromptResult(prompt, metadata) {
2571
+ const hash = getPromptResultHash(prompt, metadata);
2572
+ const dateDir = getResultsDateDir(metadata.date);
2573
+ const filePath = join(dateDir, `${hash}.json`);
2574
+ if (!existsSync(filePath)) {
2575
+ logger.debug(
2576
+ `Cache miss for prompt on ${metadata.date} (hash: ${hash.slice(0, 8)}...)`,
2577
+ "results"
2578
+ );
2579
+ return null;
2580
+ }
2581
+ try {
2582
+ const content = await readFile(filePath, "utf-8");
2583
+ const data = JSON.parse(content);
2584
+ if (!data.result || !data.metadata) {
2585
+ logger.debug(
2586
+ `Invalid cached result for hash ${hash.slice(0, 8)}...`,
2587
+ "results"
2588
+ );
2589
+ return null;
2590
+ }
2591
+ logger.debug(
2592
+ `Cache hit for prompt on ${metadata.date} (hash: ${hash.slice(0, 8)}...)`,
2593
+ "results"
2594
+ );
2595
+ return data.result;
2596
+ } catch (error) {
2597
+ const errorMessage = error instanceof Error ? error.message : String(error);
2598
+ logger.debug(
2599
+ `Failed to read cached result ${hash.slice(0, 8)}...: ${errorMessage}`,
2600
+ "results"
2601
+ );
2602
+ return null;
2603
+ }
2604
+ }
2605
+ async function ensureDateDir(date) {
2606
+ const dateDir = getResultsDateDir(date);
2607
+ await mkdir(dateDir, { recursive: true, mode: 448 });
2608
+ }
2609
+ async function savePromptResult(prompt, result, metadata) {
2610
+ try {
2611
+ await ensureDateDir(metadata.date);
2612
+ const hash = getPromptResultHash(prompt, metadata);
2613
+ const promptHash = hashString(prompt);
2614
+ const fullMetadata = {
2615
+ ...metadata,
2616
+ promptHash,
2617
+ analyzedAt: Date.now()
2618
+ };
2619
+ const promptResult = {
2620
+ result,
2621
+ metadata: fullMetadata
2622
+ };
2623
+ const dateDir = getResultsDateDir(metadata.date);
2624
+ const filePath = join(dateDir, `${hash}.json`);
2625
+ const content = JSON.stringify(promptResult, null, 2);
2626
+ const tmpFile = `${filePath}.tmp`;
2627
+ await writeFile(tmpFile, content, "utf-8");
2628
+ await rename(tmpFile, filePath);
2629
+ logger.debug(
2630
+ `Saved result for prompt on ${metadata.date} (hash: ${hash.slice(0, 8)}...)`,
2631
+ "results"
2632
+ );
2633
+ } catch (error) {
2634
+ const errorMessage = error instanceof Error ? error.message : String(error);
2635
+ logger.warn(
2636
+ `Failed to save prompt result for ${metadata.date}: ${errorMessage}`,
2637
+ "results"
2638
+ );
2639
+ }
2640
+ }
2641
+ async function getPromptsWithCache(prompts3, model, schemaType) {
2642
+ const cacheResults = await Promise.all(
2643
+ prompts3.map(async (prompt) => {
2644
+ const result = await getPromptResult(prompt.content, {
2645
+ date: prompt.date,
2646
+ project: prompt.project,
2647
+ model,
2648
+ schemaType
2649
+ });
2650
+ return { prompt, result };
2651
+ })
2652
+ );
2653
+ const cached = /* @__PURE__ */ new Map();
2654
+ const toAnalyze = [];
2655
+ for (const { prompt, result } of cacheResults) {
2656
+ if (result) {
2657
+ cached.set(prompt.content, result);
2658
+ } else {
2659
+ toAnalyze.push(prompt);
2660
+ }
2661
+ }
2662
+ const hitRate = prompts3.length > 0 ? (cached.size / prompts3.length * 100).toFixed(1) : "0.0";
2663
+ logger.debug(
2664
+ `Cache: ${String(cached.size)} hits, ${String(toAnalyze.length)} misses (${hitRate}% hit rate)`,
2665
+ "results"
2666
+ );
2667
+ return { cached, toAnalyze };
2668
+ }
2554
2669
 
2555
2670
  // src/providers/index.ts
2556
2671
  init_logger_base();
@@ -5385,24 +5500,62 @@ ${errorMessage}
5385
5500
  process.exit(EXIT_CODES.PROVIDER_UNAVAILABLE);
5386
5501
  }
5387
5502
  }
5388
- async function analyzeWithProgress(provider, prompts3, date, context, rules, isJsonMode, noCache) {
5389
- const spinner = isJsonMode ? null : ora(`Analyzing ${String(prompts3.length)} prompts...`).start();
5503
+ async function analyzeWithProgress(provider, prompts3, date, context, rules, isJsonMode, noCache, extractedPrompts) {
5504
+ let cachedResults;
5505
+ let promptsToAnalyze = prompts3;
5506
+ if (extractedPrompts) {
5507
+ const cacheResult = await loadAndFilterCachedResults(
5508
+ extractedPrompts,
5509
+ provider,
5510
+ noCache
5511
+ );
5512
+ cachedResults = cacheResult.cachedResults;
5513
+ promptsToAnalyze = cacheResult.toAnalyze;
5514
+ }
5515
+ const total = prompts3.length;
5516
+ const cached = cachedResults?.size ?? 0;
5517
+ const cacheInfo = cached > 0 ? ` (${String(cached)} cached)` : "";
5518
+ const spinner = isJsonMode ? null : ora(`Analyzing ${String(total)} prompts${cacheInfo}...`).start();
5390
5519
  try {
5391
5520
  const result = await analyzePrompts({
5392
5521
  provider,
5393
- prompts: prompts3,
5522
+ prompts: promptsToAnalyze,
5394
5523
  date,
5395
5524
  context,
5396
5525
  rules,
5397
- onProgress: (current, total) => {
5398
- if (!isJsonMode && spinner && total > 1) {
5399
- spinner.text = `Analyzing ${String(prompts3.length)} prompts (batch ${String(current + 1)}/${String(total)})...`;
5526
+ onProgress: (current, batchTotal) => {
5527
+ if (!isJsonMode && spinner && batchTotal > 1) {
5528
+ spinner.text = `Analyzing ${String(total)} prompts${cacheInfo} (batch ${String(current + 1)}/${String(batchTotal)})...`;
5400
5529
  }
5401
5530
  },
5402
- noCache
5531
+ noCache,
5532
+ cachedResults
5403
5533
  });
5534
+ if (!noCache && extractedPrompts?.length === 1 && promptsToAnalyze.length === 1) {
5535
+ const prompt = extractedPrompts[0];
5536
+ if (prompt) {
5537
+ const model = extractModelFromProvider(provider.name);
5538
+ const schemaType = determineSchemaType(provider);
5539
+ try {
5540
+ await savePromptResult(prompt.content, result, {
5541
+ date: prompt.date,
5542
+ project: prompt.project,
5543
+ provider: provider.name,
5544
+ model,
5545
+ schemaType
5546
+ });
5547
+ } catch (error) {
5548
+ const errorMessage = error instanceof Error ? error.message : String(error);
5549
+ logger2.debug(
5550
+ `Failed to save prompt result: ${errorMessage}`,
5551
+ "results"
5552
+ );
5553
+ }
5554
+ }
5555
+ }
5404
5556
  if (!isJsonMode) {
5405
- spinner?.succeed(chalk6.green("Analysis complete"));
5557
+ const hitRate = total > 0 && cached > 0 ? ` - ${(cached / total * 100).toFixed(0)}% cached` : "";
5558
+ spinner?.succeed(chalk6.green(`Analysis complete${hitRate}`));
5406
5559
  }
5407
5560
  return result;
5408
5561
  } catch (error) {
@@ -5419,6 +5572,57 @@ async function analyzeWithProgress(provider, prompts3, date, context, rules, isJ
5419
5572
  process.exit(EXIT_CODES.ERROR);
5420
5573
  }
5421
5574
  }
5575
+ function determineSchemaType(provider) {
5576
+ const providerName = provider.name.toLowerCase();
5577
+ if (providerName.includes("anthropic")) {
5578
+ return "anthropic";
5579
+ }
5580
+ if (providerName.includes("ollama")) {
5581
+ return "ollama";
5582
+ }
5583
+ if (providerName.includes("google")) {
5584
+ return "google";
5585
+ }
5586
+ return "ollama";
5587
+ }
5588
+ async function loadAndFilterCachedResults(extractedPrompts, provider, noCache) {
5589
+ if (noCache) {
5590
+ logger2.debug("Cache disabled, analyzing all prompts", "results");
5591
+ return {
5592
+ cachedResults: /* @__PURE__ */ new Map(),
5593
+ toAnalyze: extractedPrompts.map((p) => p.content)
5594
+ };
5595
+ }
5596
+ try {
5597
+ const model = extractModelFromProvider(provider.name);
5598
+ const schemaType = determineSchemaType(provider);
5599
+ const { cached, toAnalyze } = await getPromptsWithCache(
5600
+ extractedPrompts,
5601
+ model,
5602
+ schemaType
5603
+ );
5604
+ const total = extractedPrompts.length;
5605
+ const hitRate = total > 0 ? (cached.size / total * 100).toFixed(1) : "0.0";
5606
+ logger2.debug(
5607
+ `Results cache: ${String(cached.size)}/${String(total)} hits (${hitRate}%)`,
5608
+ "results"
5609
+ );
5610
+ return {
5611
+ cachedResults: cached,
5612
+ toAnalyze: toAnalyze.map((p) => p.content)
5613
+ };
5614
+ } catch (error) {
5615
+ const errorMessage = error instanceof Error ? error.message : String(error);
5616
+ logger2.warn(
5617
+ `Failed to load cached results: ${errorMessage}. Analyzing all prompts.`,
5618
+ "results"
5619
+ );
5620
+ return {
5621
+ cachedResults: /* @__PURE__ */ new Map(),
5622
+ toAnalyze: extractedPrompts.map((p) => p.content)
5623
+ };
5624
+ }
5625
+ }
5422
5626
  function generatePromptKey(prompt) {
5423
5627
  return `${prompt.project}:${prompt.sessionId}:${prompt.timestamp}`;
5424
5628
  }
@@ -5463,13 +5667,55 @@ async function runWatchMode(provider, args, context, rules) {
5463
5667
  analyzedPrompts.set(promptKey, Date.now());
5464
5668
  void (async () => {
5465
5669
  try {
5466
- const result = await analyzePrompts({
5467
- provider,
5468
- prompts: [prompt.content],
5469
- date: prompt.date,
5470
- context,
5471
- rules
5472
- });
5670
+ let result;
5671
+ if (!args.noCache) {
5672
+ const model = extractModelFromProvider(provider.name);
5673
+ const schemaType = determineSchemaType(provider);
5674
+ const cachedResult = await getPromptResult(prompt.content, {
5675
+ date: prompt.date,
5676
+ project: prompt.project,
5677
+ model,
5678
+ schemaType
5679
+ });
5680
+ if (cachedResult) {
5681
+ logger2.debug(
5682
+ `Watch mode: using cached result for prompt on ${prompt.date}`,
5683
+ "results"
5684
+ );
5685
+ result = cachedResult;
5686
+ } else {
5687
+ result = await analyzePrompts({
5688
+ provider,
5689
+ prompts: [prompt.content],
5690
+ date: prompt.date,
5691
+ context,
5692
+ rules
5693
+ });
5694
+ try {
5695
+ await savePromptResult(prompt.content, result, {
5696
+ date: prompt.date,
5697
+ project: prompt.project,
5698
+ provider: provider.name,
5699
+ model,
5700
+ schemaType
5701
+ });
5702
+ } catch (error) {
5703
+ const errorMessage = error instanceof Error ? error.message : String(error);
5704
+ logger2.debug(
5705
+ `Failed to save prompt result in watch mode: ${errorMessage}`,
5706
+ "results"
5707
+ );
5708
+ }
5709
+ }
5710
+ } else {
5711
+ result = await analyzePrompts({
5712
+ provider,
5713
+ prompts: [prompt.content],
5714
+ date: prompt.date,
5715
+ context,
5716
+ rules
5717
+ });
5718
+ }
5473
5719
  const now = /* @__PURE__ */ new Date();
5474
5720
  const timeStr = now.toLocaleTimeString("en-US", {
5475
5721
  hour12: false,
@@ -5637,7 +5883,8 @@ async function cli() {
5637
5883
  config.context,
5638
5884
  config.rules,
5639
5885
  isJsonMode,
5640
- args.noCache
5886
+ args.noCache,
5887
+ group.prompts
5641
5888
  );
5642
5889
  results.push(result);
5643
5890
  }
@@ -5713,7 +5960,8 @@ async function cli() {
5713
5960
  config.context,
5714
5961
  config.rules,
5715
5962
  isJsonMode,
5716
- args.noCache
5963
+ args.noCache,
5964
+ logResult.prompts
5717
5965
  );
5718
5966
  if (args.output) {
5719
5967
  const ext = extname(args.output);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyntx",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "CLI that analyzes Claude Code prompts and generates improvement suggestions",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,7 +41,7 @@
41
41
  "vitest": "^4.0.16"
42
42
  },
43
43
  "bin": {
44
- "hyntx": "./dist/cli.js"
44
+ "hyntx": "dist/cli.js"
45
45
  },
46
46
  "exports": {
47
47
  ".": {