hyntx 2.0.1 → 2.2.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.
@@ -71,6 +71,13 @@ type AnalyzePromptsOptions = {
71
71
  readonly rules?: RulesConfig;
72
72
  readonly onProgress?: (current: number, total: number) => void;
73
73
  readonly noCache?: boolean;
74
+ /**
75
+ * Pre-cached results from incremental results storage.
76
+ * When provided, these will be merged with newly analyzed results
77
+ * using mergeBatchResults(). This enables incremental analysis
78
+ * where only new prompts are analyzed.
79
+ */
80
+ readonly cachedResults?: ReadonlyMap<string, AnalysisResult>;
74
81
  };
75
82
  /**
76
83
  * Analyzes prompts using the provided AI provider.
@@ -81,14 +88,19 @@ type AnalyzePromptsOptions = {
81
88
  * 3. Checks cache for existing results (unless noCache is true)
82
89
  * 4. Processes batches sequentially with progress updates
83
90
  * 5. Stores results in cache for future use
84
- * 6. Merges batch results into final output
91
+ * 6. Merges batch results with any provided cached results
85
92
  * 7. Applies rules configuration to filter/modify patterns
86
93
  *
94
+ * For incremental analysis, use the `cachedResults` option to provide
95
+ * pre-loaded results from the incremental results storage. This allows
96
+ * the analyzer to only process new prompts and merge the results.
97
+ *
87
98
  * @param options - Analysis options
88
99
  * @returns Analysis result
89
100
  *
90
101
  * @example
91
102
  * ```typescript
103
+ * // Basic usage
92
104
  * const result = await analyzePrompts({
93
105
  * provider: ollamaProvider,
94
106
  * prompts: ['prompt1', 'prompt2', 'prompt3'],
@@ -97,6 +109,15 @@ type AnalyzePromptsOptions = {
97
109
  * onProgress: (current, total) => console.log(`${current}/${total}`),
98
110
  * noCache: false
99
111
  * });
112
+ *
113
+ * // With incremental cached results
114
+ * const { cached, toAnalyze } = await getPromptsWithCache(prompts, model, schema);
115
+ * const result = await analyzePrompts({
116
+ * provider,
117
+ * prompts: toAnalyze.map(p => p.content),
118
+ * date: '2025-01-15',
119
+ * cachedResults: cached, // Pre-loaded results from incremental storage
120
+ * });
100
121
  * ```
101
122
  */
102
123
  declare function analyzePrompts(options: AnalyzePromptsOptions): Promise<AnalysisResult>;
package/dist/api/index.js CHANGED
@@ -382,6 +382,7 @@ var HYNTX_HISTORY_DIR = process.env["HYNTX_HISTORY_DIR"] ?? join(HOME, ".hyntx",
382
382
  var HYNTX_CACHE_DIR = process.env["HYNTX_CACHE_DIR"] ?? join(HOME, ".hyntx-cache");
383
383
  var CACHE_ANALYSIS_DIR = join(HYNTX_CACHE_DIR, "analysis");
384
384
  var CACHE_META_FILE = join(CACHE_ANALYSIS_DIR, ".metadata.json");
385
+ process.env["HYNTX_RESULTS_DIR"] ?? join(HOME, ".hyntx", "results");
385
386
 
386
387
  // src/providers/schemas.ts
387
388
  var ISSUE_TAXONOMY = {
@@ -1018,15 +1019,61 @@ function applyRulesToResult(result, rules) {
1018
1019
  topSuggestion
1019
1020
  };
1020
1021
  }
1022
+ function mergeWithCachedResults(newResults, cachedResults, date, rules) {
1023
+ if (!cachedResults || cachedResults.size === 0) {
1024
+ if (newResults.length === 1) {
1025
+ const result = newResults[0];
1026
+ if (result) {
1027
+ return applyRulesToResult(result, rules);
1028
+ }
1029
+ }
1030
+ const mergedResult2 = mergeBatchResults({ results: newResults, date });
1031
+ return applyRulesToResult(mergedResult2, rules);
1032
+ }
1033
+ const cachedArray = Array.from(cachedResults.values());
1034
+ const allResults = [...cachedArray, ...newResults];
1035
+ logger.debug(
1036
+ `Merging ${String(cachedArray.length)} cached + ${String(newResults.length)} new results`,
1037
+ "analyzer"
1038
+ );
1039
+ const mergedResult = mergeBatchResults({ results: allResults, date });
1040
+ return applyRulesToResult(mergedResult, rules);
1041
+ }
1021
1042
  async function analyzePrompts(options) {
1022
- const { provider, prompts, date, context, rules, onProgress, noCache } = options;
1043
+ const {
1044
+ provider,
1045
+ prompts,
1046
+ date,
1047
+ context,
1048
+ rules,
1049
+ onProgress,
1050
+ noCache,
1051
+ cachedResults
1052
+ } = options;
1023
1053
  logger.debug(
1024
1054
  `Starting analysis of ${String(prompts.length)} prompts for ${date}`,
1025
1055
  "analyzer"
1026
1056
  );
1057
+ if (prompts.length === 0 && cachedResults && cachedResults.size > 0) {
1058
+ logger.debug(
1059
+ `Using ${String(cachedResults.size)} cached result(s), no new prompts to analyze`,
1060
+ "analyzer"
1061
+ );
1062
+ const cachedArray = Array.from(cachedResults.values());
1063
+ const mergedResult = mergeBatchResults({ results: cachedArray, date });
1064
+ return applyRulesToResult(mergedResult, rules);
1065
+ }
1027
1066
  if (prompts.length === 0) {
1028
1067
  throw new Error("Cannot analyze empty prompts array");
1029
1068
  }
1069
+ if (cachedResults && cachedResults.size > 0) {
1070
+ const totalPrompts = prompts.length + cachedResults.size;
1071
+ const cacheHitRate = (cachedResults.size / totalPrompts * 100).toFixed(1);
1072
+ logger.debug(
1073
+ `Results cache: ${String(cachedResults.size)} cached, ${String(prompts.length)} to analyze (${cacheHitRate}% hit rate)`,
1074
+ "analyzer"
1075
+ );
1076
+ }
1030
1077
  const { prompts: sanitizedPrompts, totalRedacted } = sanitizePrompts(prompts);
1031
1078
  if (totalRedacted > 0) {
1032
1079
  logger.debug(
@@ -1077,27 +1124,8 @@ async function analyzePrompts(options) {
1077
1124
  if (results2.length === 0) {
1078
1125
  throw new Error("All prompts failed analysis");
1079
1126
  }
1080
- if (results2.length === 1) {
1081
- const result = results2[0];
1082
- if (!result) {
1083
- throw new Error("Analysis returned empty result");
1084
- }
1085
- logger.debug(
1086
- `Analysis complete: ${String(result.patterns.length)} patterns found`,
1087
- "analyzer"
1088
- );
1089
- return applyRulesToResult(result, rules);
1090
- }
1091
- logger.debug(
1092
- `Merging ${String(results2.length)} fallback results`,
1093
- "analyzer"
1094
- );
1095
- const mergedResult2 = mergeBatchResults({ results: results2, date });
1096
- logger.debug(
1097
- `Analysis complete: ${String(mergedResult2.patterns.length)} patterns found`,
1098
- "analyzer"
1099
- );
1100
- return applyRulesToResult(mergedResult2, rules);
1127
+ logger.debug(`Analysis complete, merging with cached results`, "analyzer");
1128
+ return mergeWithCachedResults(results2, cachedResults, date, rules);
1101
1129
  }
1102
1130
  const results = [];
1103
1131
  const totalBatches = batches.length;
@@ -1134,13 +1162,11 @@ async function analyzePrompts(options) {
1134
1162
  if (results.length === 0) {
1135
1163
  throw new Error("All batches failed analysis");
1136
1164
  }
1137
- logger.debug(`Merging ${String(results.length)} batch results`, "analyzer");
1138
- const mergedResult = mergeBatchResults({ results, date });
1139
1165
  logger.debug(
1140
- `Analysis complete: ${String(mergedResult.patterns.length)} patterns found`,
1166
+ `Analysis complete, merging ${String(results.length)} batch results with cached results`,
1141
1167
  "analyzer"
1142
1168
  );
1143
- return applyRulesToResult(mergedResult, rules);
1169
+ return mergeWithCachedResults(results, cachedResults, date, rules);
1144
1170
  }
1145
1171
 
1146
1172
  // src/core/schema-validator.ts
package/dist/cli.js CHANGED
@@ -530,6 +530,7 @@ 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
534
 
534
535
  // src/core/schema-validator.ts
535
536
  var SUPPORTED_VERSIONS = ["1.0"];
@@ -1969,15 +1970,61 @@ function applyRulesToResult(result, rules) {
1969
1970
  topSuggestion
1970
1971
  };
1971
1972
  }
1973
+ function mergeWithCachedResults(newResults, cachedResults, date, rules) {
1974
+ if (!cachedResults || cachedResults.size === 0) {
1975
+ if (newResults.length === 1) {
1976
+ const result = newResults[0];
1977
+ if (result) {
1978
+ return applyRulesToResult(result, rules);
1979
+ }
1980
+ }
1981
+ const mergedResult2 = mergeBatchResults({ results: newResults, date });
1982
+ return applyRulesToResult(mergedResult2, rules);
1983
+ }
1984
+ const cachedArray = Array.from(cachedResults.values());
1985
+ const allResults = [...cachedArray, ...newResults];
1986
+ logger.debug(
1987
+ `Merging ${String(cachedArray.length)} cached + ${String(newResults.length)} new results`,
1988
+ "analyzer"
1989
+ );
1990
+ const mergedResult = mergeBatchResults({ results: allResults, date });
1991
+ return applyRulesToResult(mergedResult, rules);
1992
+ }
1972
1993
  async function analyzePrompts(options) {
1973
- const { provider, prompts: prompts3, date, context, rules, onProgress, noCache } = options;
1994
+ const {
1995
+ provider,
1996
+ prompts: prompts3,
1997
+ date,
1998
+ context,
1999
+ rules,
2000
+ onProgress,
2001
+ noCache,
2002
+ cachedResults
2003
+ } = options;
1974
2004
  logger.debug(
1975
2005
  `Starting analysis of ${String(prompts3.length)} prompts for ${date}`,
1976
2006
  "analyzer"
1977
2007
  );
2008
+ if (prompts3.length === 0 && cachedResults && cachedResults.size > 0) {
2009
+ logger.debug(
2010
+ `Using ${String(cachedResults.size)} cached result(s), no new prompts to analyze`,
2011
+ "analyzer"
2012
+ );
2013
+ const cachedArray = Array.from(cachedResults.values());
2014
+ const mergedResult = mergeBatchResults({ results: cachedArray, date });
2015
+ return applyRulesToResult(mergedResult, rules);
2016
+ }
1978
2017
  if (prompts3.length === 0) {
1979
2018
  throw new Error("Cannot analyze empty prompts array");
1980
2019
  }
2020
+ if (cachedResults && cachedResults.size > 0) {
2021
+ const totalPrompts = prompts3.length + cachedResults.size;
2022
+ const cacheHitRate = (cachedResults.size / totalPrompts * 100).toFixed(1);
2023
+ logger.debug(
2024
+ `Results cache: ${String(cachedResults.size)} cached, ${String(prompts3.length)} to analyze (${cacheHitRate}% hit rate)`,
2025
+ "analyzer"
2026
+ );
2027
+ }
1981
2028
  const { prompts: sanitizedPrompts, totalRedacted } = sanitizePrompts(prompts3);
1982
2029
  if (totalRedacted > 0) {
1983
2030
  logger.debug(
@@ -2028,27 +2075,8 @@ async function analyzePrompts(options) {
2028
2075
  if (results2.length === 0) {
2029
2076
  throw new Error("All prompts failed analysis");
2030
2077
  }
2031
- if (results2.length === 1) {
2032
- const result = results2[0];
2033
- if (!result) {
2034
- throw new Error("Analysis returned empty result");
2035
- }
2036
- logger.debug(
2037
- `Analysis complete: ${String(result.patterns.length)} patterns found`,
2038
- "analyzer"
2039
- );
2040
- return applyRulesToResult(result, rules);
2041
- }
2042
- logger.debug(
2043
- `Merging ${String(results2.length)} fallback results`,
2044
- "analyzer"
2045
- );
2046
- const mergedResult2 = mergeBatchResults({ results: results2, date });
2047
- logger.debug(
2048
- `Analysis complete: ${String(mergedResult2.patterns.length)} patterns found`,
2049
- "analyzer"
2050
- );
2051
- return applyRulesToResult(mergedResult2, rules);
2078
+ logger.debug(`Analysis complete, merging with cached results`, "analyzer");
2079
+ return mergeWithCachedResults(results2, cachedResults, date, rules);
2052
2080
  }
2053
2081
  const results = [];
2054
2082
  const totalBatches = batches.length;
@@ -2085,13 +2113,11 @@ async function analyzePrompts(options) {
2085
2113
  if (results.length === 0) {
2086
2114
  throw new Error("All batches failed analysis");
2087
2115
  }
2088
- logger.debug(`Merging ${String(results.length)} batch results`, "analyzer");
2089
- const mergedResult = mergeBatchResults({ results, date });
2090
2116
  logger.debug(
2091
- `Analysis complete: ${String(mergedResult.patterns.length)} patterns found`,
2117
+ `Analysis complete, merging ${String(results.length)} batch results with cached results`,
2092
2118
  "analyzer"
2093
2119
  );
2094
- return applyRulesToResult(mergedResult, rules);
2120
+ return mergeWithCachedResults(results, cachedResults, date, rules);
2095
2121
  }
2096
2122
  function severityIcon(severity) {
2097
2123
  const icons = {
package/dist/index.js CHANGED
@@ -382,6 +382,7 @@ var HYNTX_HISTORY_DIR = process.env["HYNTX_HISTORY_DIR"] ?? join(HOME, ".hyntx",
382
382
  var HYNTX_CACHE_DIR = process.env["HYNTX_CACHE_DIR"] ?? join(HOME, ".hyntx-cache");
383
383
  var CACHE_ANALYSIS_DIR = join(HYNTX_CACHE_DIR, "analysis");
384
384
  var CACHE_META_FILE = join(CACHE_ANALYSIS_DIR, ".metadata.json");
385
+ process.env["HYNTX_RESULTS_DIR"] ?? join(HOME, ".hyntx", "results");
385
386
 
386
387
  // src/providers/schemas.ts
387
388
  var ISSUE_TAXONOMY = {
@@ -1018,15 +1019,61 @@ function applyRulesToResult(result, rules) {
1018
1019
  topSuggestion
1019
1020
  };
1020
1021
  }
1022
+ function mergeWithCachedResults(newResults, cachedResults, date, rules) {
1023
+ if (!cachedResults || cachedResults.size === 0) {
1024
+ if (newResults.length === 1) {
1025
+ const result = newResults[0];
1026
+ if (result) {
1027
+ return applyRulesToResult(result, rules);
1028
+ }
1029
+ }
1030
+ const mergedResult2 = mergeBatchResults({ results: newResults, date });
1031
+ return applyRulesToResult(mergedResult2, rules);
1032
+ }
1033
+ const cachedArray = Array.from(cachedResults.values());
1034
+ const allResults = [...cachedArray, ...newResults];
1035
+ logger.debug(
1036
+ `Merging ${String(cachedArray.length)} cached + ${String(newResults.length)} new results`,
1037
+ "analyzer"
1038
+ );
1039
+ const mergedResult = mergeBatchResults({ results: allResults, date });
1040
+ return applyRulesToResult(mergedResult, rules);
1041
+ }
1021
1042
  async function analyzePrompts(options) {
1022
- const { provider, prompts, date, context, rules, onProgress, noCache } = options;
1043
+ const {
1044
+ provider,
1045
+ prompts,
1046
+ date,
1047
+ context,
1048
+ rules,
1049
+ onProgress,
1050
+ noCache,
1051
+ cachedResults
1052
+ } = options;
1023
1053
  logger.debug(
1024
1054
  `Starting analysis of ${String(prompts.length)} prompts for ${date}`,
1025
1055
  "analyzer"
1026
1056
  );
1057
+ if (prompts.length === 0 && cachedResults && cachedResults.size > 0) {
1058
+ logger.debug(
1059
+ `Using ${String(cachedResults.size)} cached result(s), no new prompts to analyze`,
1060
+ "analyzer"
1061
+ );
1062
+ const cachedArray = Array.from(cachedResults.values());
1063
+ const mergedResult = mergeBatchResults({ results: cachedArray, date });
1064
+ return applyRulesToResult(mergedResult, rules);
1065
+ }
1027
1066
  if (prompts.length === 0) {
1028
1067
  throw new Error("Cannot analyze empty prompts array");
1029
1068
  }
1069
+ if (cachedResults && cachedResults.size > 0) {
1070
+ const totalPrompts = prompts.length + cachedResults.size;
1071
+ const cacheHitRate = (cachedResults.size / totalPrompts * 100).toFixed(1);
1072
+ logger.debug(
1073
+ `Results cache: ${String(cachedResults.size)} cached, ${String(prompts.length)} to analyze (${cacheHitRate}% hit rate)`,
1074
+ "analyzer"
1075
+ );
1076
+ }
1030
1077
  const { prompts: sanitizedPrompts, totalRedacted } = sanitizePrompts(prompts);
1031
1078
  if (totalRedacted > 0) {
1032
1079
  logger.debug(
@@ -1077,27 +1124,8 @@ async function analyzePrompts(options) {
1077
1124
  if (results2.length === 0) {
1078
1125
  throw new Error("All prompts failed analysis");
1079
1126
  }
1080
- if (results2.length === 1) {
1081
- const result = results2[0];
1082
- if (!result) {
1083
- throw new Error("Analysis returned empty result");
1084
- }
1085
- logger.debug(
1086
- `Analysis complete: ${String(result.patterns.length)} patterns found`,
1087
- "analyzer"
1088
- );
1089
- return applyRulesToResult(result, rules);
1090
- }
1091
- logger.debug(
1092
- `Merging ${String(results2.length)} fallback results`,
1093
- "analyzer"
1094
- );
1095
- const mergedResult2 = mergeBatchResults({ results: results2, date });
1096
- logger.debug(
1097
- `Analysis complete: ${String(mergedResult2.patterns.length)} patterns found`,
1098
- "analyzer"
1099
- );
1100
- return applyRulesToResult(mergedResult2, rules);
1127
+ logger.debug(`Analysis complete, merging with cached results`, "analyzer");
1128
+ return mergeWithCachedResults(results2, cachedResults, date, rules);
1101
1129
  }
1102
1130
  const results = [];
1103
1131
  const totalBatches = batches.length;
@@ -1134,13 +1162,11 @@ async function analyzePrompts(options) {
1134
1162
  if (results.length === 0) {
1135
1163
  throw new Error("All batches failed analysis");
1136
1164
  }
1137
- logger.debug(`Merging ${String(results.length)} batch results`, "analyzer");
1138
- const mergedResult = mergeBatchResults({ results, date });
1139
1165
  logger.debug(
1140
- `Analysis complete: ${String(mergedResult.patterns.length)} patterns found`,
1166
+ `Analysis complete, merging ${String(results.length)} batch results with cached results`,
1141
1167
  "analyzer"
1142
1168
  );
1143
- return applyRulesToResult(mergedResult, rules);
1169
+ return mergeWithCachedResults(results, cachedResults, date, rules);
1144
1170
  }
1145
1171
 
1146
1172
  // src/core/schema-validator.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyntx",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "CLI that analyzes Claude Code prompts and generates improvement suggestions",
5
5
  "type": "module",
6
6
  "engines": {