hyntx 2.0.0 → 2.1.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/api/index.js +65 -10
- package/dist/cli.js +65 -10
- package/dist/index.js +65 -10
- package/package.json +1 -1
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 = {
|
|
@@ -1749,6 +1750,10 @@ function getDateOneMonthAgo(fromDate) {
|
|
|
1749
1750
|
}
|
|
1750
1751
|
|
|
1751
1752
|
// src/core/aggregator.ts
|
|
1753
|
+
function normalizeScore(score100) {
|
|
1754
|
+
const normalized = score100 / 10;
|
|
1755
|
+
return Math.max(0, Math.min(10, normalized));
|
|
1756
|
+
}
|
|
1752
1757
|
function lookupIssueMetadata(issueId, taxonomy) {
|
|
1753
1758
|
if (taxonomy[issueId]) {
|
|
1754
1759
|
return taxonomy[issueId];
|
|
@@ -1762,19 +1767,66 @@ function lookupIssueMetadata(issueId, taxonomy) {
|
|
|
1762
1767
|
function titleCase(str) {
|
|
1763
1768
|
return str.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1764
1769
|
}
|
|
1765
|
-
function
|
|
1770
|
+
function extractRealExamples(issueId, prompts, limit = 3) {
|
|
1771
|
+
const matches = [];
|
|
1772
|
+
for (const prompt of prompts) {
|
|
1773
|
+
if (matches.length >= limit) {
|
|
1774
|
+
break;
|
|
1775
|
+
}
|
|
1776
|
+
const trimmed = prompt.trim();
|
|
1777
|
+
const lowerPrompt = trimmed.toLowerCase();
|
|
1778
|
+
const wordCount = trimmed.split(/\s+/).length;
|
|
1779
|
+
let isMatch = false;
|
|
1780
|
+
switch (issueId) {
|
|
1781
|
+
case "vague":
|
|
1782
|
+
isMatch = trimmed.length < 50 && wordCount <= 5 && (lowerPrompt.includes("help") || lowerPrompt.includes("fix") || lowerPrompt.includes("do") || lowerPrompt.includes("make") || lowerPrompt.includes("create")) && /\w+\.(ts|js|tsx|jsx|py|go|java|rb|php)\b/.exec(lowerPrompt) === null;
|
|
1783
|
+
break;
|
|
1784
|
+
case "no-context":
|
|
1785
|
+
isMatch = (lowerPrompt.includes("this") || lowerPrompt.includes("it") || lowerPrompt.includes("the bug") || lowerPrompt.includes("that")) && /\w+\.(ts|js|tsx|jsx|py|go|java|rb|php)\b/.exec(lowerPrompt) === null && /function|component|method|class/.exec(lowerPrompt) === null;
|
|
1786
|
+
break;
|
|
1787
|
+
case "too-broad": {
|
|
1788
|
+
const andMatches = lowerPrompt.match(/\band\b/g);
|
|
1789
|
+
isMatch = trimmed.length > 100 && (andMatches?.length ?? 0) >= 2 && (lowerPrompt.includes("also") || lowerPrompt.includes("then") || lowerPrompt.includes("build") || lowerPrompt.includes("create"));
|
|
1790
|
+
break;
|
|
1791
|
+
}
|
|
1792
|
+
case "no-goal":
|
|
1793
|
+
isMatch = trimmed.length < 30 && wordCount <= 4 && /\b(how|what|why|when|where|create|build|fix|add)\b/.exec(
|
|
1794
|
+
lowerPrompt
|
|
1795
|
+
) === null && !lowerPrompt.includes("?");
|
|
1796
|
+
break;
|
|
1797
|
+
case "imperative":
|
|
1798
|
+
isMatch = trimmed.length < 20 && wordCount <= 3 && /^(add|delete|remove|update|change|modify)\b/.exec(lowerPrompt) !== null && !lowerPrompt.includes("?");
|
|
1799
|
+
break;
|
|
1800
|
+
default:
|
|
1801
|
+
isMatch = false;
|
|
1802
|
+
}
|
|
1803
|
+
if (isMatch) {
|
|
1804
|
+
matches.push(sanitizeExample(trimmed));
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return [...new Set(matches)];
|
|
1808
|
+
}
|
|
1809
|
+
function sanitizeExample(prompt) {
|
|
1810
|
+
const trimmed = prompt.trim().replace(/\s+/g, " ");
|
|
1811
|
+
if (trimmed.length <= 80) {
|
|
1812
|
+
return trimmed;
|
|
1813
|
+
}
|
|
1814
|
+
return trimmed.slice(0, 77) + "...";
|
|
1815
|
+
}
|
|
1816
|
+
function convertMinimalToAnalysisResult(minimal, date, taxonomy, prompts) {
|
|
1766
1817
|
const issueCounts = /* @__PURE__ */ new Map();
|
|
1767
1818
|
for (const issue of minimal.issues) {
|
|
1768
1819
|
issueCounts.set(issue, (issueCounts.get(issue) ?? 0) + 1);
|
|
1769
1820
|
}
|
|
1770
1821
|
const patterns = [...issueCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 5).map(([issueId, count]) => {
|
|
1771
1822
|
const metadata = lookupIssueMetadata(issueId, taxonomy);
|
|
1823
|
+
const examples = prompts ? extractRealExamples(issueId, prompts, 3) : metadata.exampleBefore ? [metadata.exampleBefore] : [];
|
|
1772
1824
|
return {
|
|
1773
1825
|
id: issueId,
|
|
1774
1826
|
name: metadata.name,
|
|
1775
1827
|
frequency: count,
|
|
1776
1828
|
severity: metadata.severity,
|
|
1777
|
-
examples:
|
|
1829
|
+
examples: [...examples],
|
|
1778
1830
|
suggestion: metadata.suggestion,
|
|
1779
1831
|
beforeAfter: {
|
|
1780
1832
|
before: metadata.exampleBefore ?? "Example not available",
|
|
@@ -1788,7 +1840,7 @@ function convertMinimalToAnalysisResult(minimal, date, taxonomy) {
|
|
|
1788
1840
|
stats: {
|
|
1789
1841
|
totalPrompts: 1,
|
|
1790
1842
|
promptsWithIssues: minimal.issues.length > 0 ? 1 : 0,
|
|
1791
|
-
overallScore: minimal.score
|
|
1843
|
+
overallScore: normalizeScore(minimal.score)
|
|
1792
1844
|
},
|
|
1793
1845
|
topSuggestion: patterns.length > 0 && patterns[0] ? patterns[0].suggestion : "Your prompts look good!"
|
|
1794
1846
|
};
|
|
@@ -1909,7 +1961,7 @@ function tryFixTruncatedJson(json) {
|
|
|
1909
1961
|
}
|
|
1910
1962
|
return fixed;
|
|
1911
1963
|
}
|
|
1912
|
-
function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
1964
|
+
function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY, prompts) {
|
|
1913
1965
|
const codeBlockRegex = /```(?:json)?\s*\n?([\s\S]*?)\n?```/;
|
|
1914
1966
|
const jsonMatch = codeBlockRegex.exec(response);
|
|
1915
1967
|
let jsonString = jsonMatch?.[1]?.trim() ?? response.trim();
|
|
@@ -1928,7 +1980,7 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
1928
1980
|
}
|
|
1929
1981
|
if (isValidMinimalResponse(parsed)) {
|
|
1930
1982
|
const minimal = extractMinimalResult(parsed);
|
|
1931
|
-
return convertMinimalToAnalysisResult(minimal, date, taxonomy);
|
|
1983
|
+
return convertMinimalToAnalysisResult(minimal, date, taxonomy, prompts);
|
|
1932
1984
|
}
|
|
1933
1985
|
if (isValidSimpleResponse(parsed)) {
|
|
1934
1986
|
const simple = extractSimpleResponse(parsed);
|
|
@@ -1940,7 +1992,7 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
1940
1992
|
totalPrompts: 0,
|
|
1941
1993
|
// Will be filled by caller
|
|
1942
1994
|
promptsWithIssues: simple.issues.length,
|
|
1943
|
-
overallScore: simple.score
|
|
1995
|
+
overallScore: normalizeScore(simple.score)
|
|
1944
1996
|
},
|
|
1945
1997
|
topSuggestion: simple.tip
|
|
1946
1998
|
};
|
|
@@ -1949,7 +2001,10 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
1949
2001
|
return {
|
|
1950
2002
|
date,
|
|
1951
2003
|
patterns: parsed.patterns,
|
|
1952
|
-
stats:
|
|
2004
|
+
stats: {
|
|
2005
|
+
...parsed.stats,
|
|
2006
|
+
overallScore: normalizeScore(parsed.stats.overallScore)
|
|
2007
|
+
},
|
|
1953
2008
|
topSuggestion: parsed.topSuggestion
|
|
1954
2009
|
};
|
|
1955
2010
|
}
|
|
@@ -2204,7 +2259,7 @@ var OllamaProvider = class {
|
|
|
2204
2259
|
if (typeof data.response !== "string") {
|
|
2205
2260
|
throw new Error("Invalid response format from Ollama API");
|
|
2206
2261
|
}
|
|
2207
|
-
return parseResponse(data.response, date);
|
|
2262
|
+
return parseResponse(data.response, date, void 0, prompts);
|
|
2208
2263
|
} catch (error) {
|
|
2209
2264
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2210
2265
|
if (lastError.message.includes("parse") || lastError.message.includes("schema")) {
|
|
@@ -2433,7 +2488,7 @@ var AnthropicProvider = class {
|
|
|
2433
2488
|
if (!textContent?.text) {
|
|
2434
2489
|
throw new Error("Invalid response format from Anthropic API");
|
|
2435
2490
|
}
|
|
2436
|
-
return parseResponse(textContent.text, date);
|
|
2491
|
+
return parseResponse(textContent.text, date, void 0, prompts);
|
|
2437
2492
|
} finally {
|
|
2438
2493
|
clearTimeout(timeoutId);
|
|
2439
2494
|
}
|
|
@@ -2580,7 +2635,7 @@ var GoogleProvider = class {
|
|
|
2580
2635
|
if (!textContent) {
|
|
2581
2636
|
throw new Error("Invalid response format from Google API");
|
|
2582
2637
|
}
|
|
2583
|
-
return parseResponse(textContent, date);
|
|
2638
|
+
return parseResponse(textContent, date, void 0, prompts);
|
|
2584
2639
|
} finally {
|
|
2585
2640
|
clearTimeout(timeoutId);
|
|
2586
2641
|
}
|
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"];
|
|
@@ -2533,6 +2534,10 @@ init_logger_base();
|
|
|
2533
2534
|
init_logger_base();
|
|
2534
2535
|
|
|
2535
2536
|
// src/core/aggregator.ts
|
|
2537
|
+
function normalizeScore(score100) {
|
|
2538
|
+
const normalized = score100 / 10;
|
|
2539
|
+
return Math.max(0, Math.min(10, normalized));
|
|
2540
|
+
}
|
|
2536
2541
|
function lookupIssueMetadata(issueId, taxonomy) {
|
|
2537
2542
|
if (taxonomy[issueId]) {
|
|
2538
2543
|
return taxonomy[issueId];
|
|
@@ -2546,19 +2551,66 @@ function lookupIssueMetadata(issueId, taxonomy) {
|
|
|
2546
2551
|
function titleCase(str) {
|
|
2547
2552
|
return str.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
2548
2553
|
}
|
|
2549
|
-
function
|
|
2554
|
+
function extractRealExamples(issueId, prompts3, limit = 3) {
|
|
2555
|
+
const matches = [];
|
|
2556
|
+
for (const prompt of prompts3) {
|
|
2557
|
+
if (matches.length >= limit) {
|
|
2558
|
+
break;
|
|
2559
|
+
}
|
|
2560
|
+
const trimmed = prompt.trim();
|
|
2561
|
+
const lowerPrompt = trimmed.toLowerCase();
|
|
2562
|
+
const wordCount = trimmed.split(/\s+/).length;
|
|
2563
|
+
let isMatch = false;
|
|
2564
|
+
switch (issueId) {
|
|
2565
|
+
case "vague":
|
|
2566
|
+
isMatch = trimmed.length < 50 && wordCount <= 5 && (lowerPrompt.includes("help") || lowerPrompt.includes("fix") || lowerPrompt.includes("do") || lowerPrompt.includes("make") || lowerPrompt.includes("create")) && /\w+\.(ts|js|tsx|jsx|py|go|java|rb|php)\b/.exec(lowerPrompt) === null;
|
|
2567
|
+
break;
|
|
2568
|
+
case "no-context":
|
|
2569
|
+
isMatch = (lowerPrompt.includes("this") || lowerPrompt.includes("it") || lowerPrompt.includes("the bug") || lowerPrompt.includes("that")) && /\w+\.(ts|js|tsx|jsx|py|go|java|rb|php)\b/.exec(lowerPrompt) === null && /function|component|method|class/.exec(lowerPrompt) === null;
|
|
2570
|
+
break;
|
|
2571
|
+
case "too-broad": {
|
|
2572
|
+
const andMatches = lowerPrompt.match(/\band\b/g);
|
|
2573
|
+
isMatch = trimmed.length > 100 && (andMatches?.length ?? 0) >= 2 && (lowerPrompt.includes("also") || lowerPrompt.includes("then") || lowerPrompt.includes("build") || lowerPrompt.includes("create"));
|
|
2574
|
+
break;
|
|
2575
|
+
}
|
|
2576
|
+
case "no-goal":
|
|
2577
|
+
isMatch = trimmed.length < 30 && wordCount <= 4 && /\b(how|what|why|when|where|create|build|fix|add)\b/.exec(
|
|
2578
|
+
lowerPrompt
|
|
2579
|
+
) === null && !lowerPrompt.includes("?");
|
|
2580
|
+
break;
|
|
2581
|
+
case "imperative":
|
|
2582
|
+
isMatch = trimmed.length < 20 && wordCount <= 3 && /^(add|delete|remove|update|change|modify)\b/.exec(lowerPrompt) !== null && !lowerPrompt.includes("?");
|
|
2583
|
+
break;
|
|
2584
|
+
default:
|
|
2585
|
+
isMatch = false;
|
|
2586
|
+
}
|
|
2587
|
+
if (isMatch) {
|
|
2588
|
+
matches.push(sanitizeExample(trimmed));
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
return [...new Set(matches)];
|
|
2592
|
+
}
|
|
2593
|
+
function sanitizeExample(prompt) {
|
|
2594
|
+
const trimmed = prompt.trim().replace(/\s+/g, " ");
|
|
2595
|
+
if (trimmed.length <= 80) {
|
|
2596
|
+
return trimmed;
|
|
2597
|
+
}
|
|
2598
|
+
return trimmed.slice(0, 77) + "...";
|
|
2599
|
+
}
|
|
2600
|
+
function convertMinimalToAnalysisResult(minimal, date, taxonomy, prompts3) {
|
|
2550
2601
|
const issueCounts = /* @__PURE__ */ new Map();
|
|
2551
2602
|
for (const issue of minimal.issues) {
|
|
2552
2603
|
issueCounts.set(issue, (issueCounts.get(issue) ?? 0) + 1);
|
|
2553
2604
|
}
|
|
2554
2605
|
const patterns = [...issueCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 5).map(([issueId, count]) => {
|
|
2555
2606
|
const metadata = lookupIssueMetadata(issueId, taxonomy);
|
|
2607
|
+
const examples = prompts3 ? extractRealExamples(issueId, prompts3, 3) : metadata.exampleBefore ? [metadata.exampleBefore] : [];
|
|
2556
2608
|
return {
|
|
2557
2609
|
id: issueId,
|
|
2558
2610
|
name: metadata.name,
|
|
2559
2611
|
frequency: count,
|
|
2560
2612
|
severity: metadata.severity,
|
|
2561
|
-
examples:
|
|
2613
|
+
examples: [...examples],
|
|
2562
2614
|
suggestion: metadata.suggestion,
|
|
2563
2615
|
beforeAfter: {
|
|
2564
2616
|
before: metadata.exampleBefore ?? "Example not available",
|
|
@@ -2572,7 +2624,7 @@ function convertMinimalToAnalysisResult(minimal, date, taxonomy) {
|
|
|
2572
2624
|
stats: {
|
|
2573
2625
|
totalPrompts: 1,
|
|
2574
2626
|
promptsWithIssues: minimal.issues.length > 0 ? 1 : 0,
|
|
2575
|
-
overallScore: minimal.score
|
|
2627
|
+
overallScore: normalizeScore(minimal.score)
|
|
2576
2628
|
},
|
|
2577
2629
|
topSuggestion: patterns.length > 0 && patterns[0] ? patterns[0].suggestion : "Your prompts look good!"
|
|
2578
2630
|
};
|
|
@@ -2693,7 +2745,7 @@ function tryFixTruncatedJson(json) {
|
|
|
2693
2745
|
}
|
|
2694
2746
|
return fixed;
|
|
2695
2747
|
}
|
|
2696
|
-
function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
2748
|
+
function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY, prompts3) {
|
|
2697
2749
|
const codeBlockRegex = /```(?:json)?\s*\n?([\s\S]*?)\n?```/;
|
|
2698
2750
|
const jsonMatch = codeBlockRegex.exec(response);
|
|
2699
2751
|
let jsonString = jsonMatch?.[1]?.trim() ?? response.trim();
|
|
@@ -2712,7 +2764,7 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
2712
2764
|
}
|
|
2713
2765
|
if (isValidMinimalResponse(parsed)) {
|
|
2714
2766
|
const minimal = extractMinimalResult(parsed);
|
|
2715
|
-
return convertMinimalToAnalysisResult(minimal, date, taxonomy);
|
|
2767
|
+
return convertMinimalToAnalysisResult(minimal, date, taxonomy, prompts3);
|
|
2716
2768
|
}
|
|
2717
2769
|
if (isValidSimpleResponse(parsed)) {
|
|
2718
2770
|
const simple = extractSimpleResponse(parsed);
|
|
@@ -2724,7 +2776,7 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
2724
2776
|
totalPrompts: 0,
|
|
2725
2777
|
// Will be filled by caller
|
|
2726
2778
|
promptsWithIssues: simple.issues.length,
|
|
2727
|
-
overallScore: simple.score
|
|
2779
|
+
overallScore: normalizeScore(simple.score)
|
|
2728
2780
|
},
|
|
2729
2781
|
topSuggestion: simple.tip
|
|
2730
2782
|
};
|
|
@@ -2733,7 +2785,10 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
2733
2785
|
return {
|
|
2734
2786
|
date,
|
|
2735
2787
|
patterns: parsed.patterns,
|
|
2736
|
-
stats:
|
|
2788
|
+
stats: {
|
|
2789
|
+
...parsed.stats,
|
|
2790
|
+
overallScore: normalizeScore(parsed.stats.overallScore)
|
|
2791
|
+
},
|
|
2737
2792
|
topSuggestion: parsed.topSuggestion
|
|
2738
2793
|
};
|
|
2739
2794
|
}
|
|
@@ -2988,7 +3043,7 @@ var OllamaProvider = class {
|
|
|
2988
3043
|
if (typeof data.response !== "string") {
|
|
2989
3044
|
throw new Error("Invalid response format from Ollama API");
|
|
2990
3045
|
}
|
|
2991
|
-
return parseResponse(data.response, date);
|
|
3046
|
+
return parseResponse(data.response, date, void 0, prompts3);
|
|
2992
3047
|
} catch (error) {
|
|
2993
3048
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2994
3049
|
if (lastError.message.includes("parse") || lastError.message.includes("schema")) {
|
|
@@ -3220,7 +3275,7 @@ var AnthropicProvider = class {
|
|
|
3220
3275
|
if (!textContent?.text) {
|
|
3221
3276
|
throw new Error("Invalid response format from Anthropic API");
|
|
3222
3277
|
}
|
|
3223
|
-
return parseResponse(textContent.text, date);
|
|
3278
|
+
return parseResponse(textContent.text, date, void 0, prompts3);
|
|
3224
3279
|
} finally {
|
|
3225
3280
|
clearTimeout(timeoutId);
|
|
3226
3281
|
}
|
|
@@ -3368,7 +3423,7 @@ var GoogleProvider = class {
|
|
|
3368
3423
|
if (!textContent) {
|
|
3369
3424
|
throw new Error("Invalid response format from Google API");
|
|
3370
3425
|
}
|
|
3371
|
-
return parseResponse(textContent, date);
|
|
3426
|
+
return parseResponse(textContent, date, void 0, prompts3);
|
|
3372
3427
|
} finally {
|
|
3373
3428
|
clearTimeout(timeoutId);
|
|
3374
3429
|
}
|
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 = {
|
|
@@ -1749,6 +1750,10 @@ function getDateOneMonthAgo(fromDate) {
|
|
|
1749
1750
|
}
|
|
1750
1751
|
|
|
1751
1752
|
// src/core/aggregator.ts
|
|
1753
|
+
function normalizeScore(score100) {
|
|
1754
|
+
const normalized = score100 / 10;
|
|
1755
|
+
return Math.max(0, Math.min(10, normalized));
|
|
1756
|
+
}
|
|
1752
1757
|
function lookupIssueMetadata(issueId, taxonomy) {
|
|
1753
1758
|
if (taxonomy[issueId]) {
|
|
1754
1759
|
return taxonomy[issueId];
|
|
@@ -1762,19 +1767,66 @@ function lookupIssueMetadata(issueId, taxonomy) {
|
|
|
1762
1767
|
function titleCase(str) {
|
|
1763
1768
|
return str.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1764
1769
|
}
|
|
1765
|
-
function
|
|
1770
|
+
function extractRealExamples(issueId, prompts, limit = 3) {
|
|
1771
|
+
const matches = [];
|
|
1772
|
+
for (const prompt of prompts) {
|
|
1773
|
+
if (matches.length >= limit) {
|
|
1774
|
+
break;
|
|
1775
|
+
}
|
|
1776
|
+
const trimmed = prompt.trim();
|
|
1777
|
+
const lowerPrompt = trimmed.toLowerCase();
|
|
1778
|
+
const wordCount = trimmed.split(/\s+/).length;
|
|
1779
|
+
let isMatch = false;
|
|
1780
|
+
switch (issueId) {
|
|
1781
|
+
case "vague":
|
|
1782
|
+
isMatch = trimmed.length < 50 && wordCount <= 5 && (lowerPrompt.includes("help") || lowerPrompt.includes("fix") || lowerPrompt.includes("do") || lowerPrompt.includes("make") || lowerPrompt.includes("create")) && /\w+\.(ts|js|tsx|jsx|py|go|java|rb|php)\b/.exec(lowerPrompt) === null;
|
|
1783
|
+
break;
|
|
1784
|
+
case "no-context":
|
|
1785
|
+
isMatch = (lowerPrompt.includes("this") || lowerPrompt.includes("it") || lowerPrompt.includes("the bug") || lowerPrompt.includes("that")) && /\w+\.(ts|js|tsx|jsx|py|go|java|rb|php)\b/.exec(lowerPrompt) === null && /function|component|method|class/.exec(lowerPrompt) === null;
|
|
1786
|
+
break;
|
|
1787
|
+
case "too-broad": {
|
|
1788
|
+
const andMatches = lowerPrompt.match(/\band\b/g);
|
|
1789
|
+
isMatch = trimmed.length > 100 && (andMatches?.length ?? 0) >= 2 && (lowerPrompt.includes("also") || lowerPrompt.includes("then") || lowerPrompt.includes("build") || lowerPrompt.includes("create"));
|
|
1790
|
+
break;
|
|
1791
|
+
}
|
|
1792
|
+
case "no-goal":
|
|
1793
|
+
isMatch = trimmed.length < 30 && wordCount <= 4 && /\b(how|what|why|when|where|create|build|fix|add)\b/.exec(
|
|
1794
|
+
lowerPrompt
|
|
1795
|
+
) === null && !lowerPrompt.includes("?");
|
|
1796
|
+
break;
|
|
1797
|
+
case "imperative":
|
|
1798
|
+
isMatch = trimmed.length < 20 && wordCount <= 3 && /^(add|delete|remove|update|change|modify)\b/.exec(lowerPrompt) !== null && !lowerPrompt.includes("?");
|
|
1799
|
+
break;
|
|
1800
|
+
default:
|
|
1801
|
+
isMatch = false;
|
|
1802
|
+
}
|
|
1803
|
+
if (isMatch) {
|
|
1804
|
+
matches.push(sanitizeExample(trimmed));
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return [...new Set(matches)];
|
|
1808
|
+
}
|
|
1809
|
+
function sanitizeExample(prompt) {
|
|
1810
|
+
const trimmed = prompt.trim().replace(/\s+/g, " ");
|
|
1811
|
+
if (trimmed.length <= 80) {
|
|
1812
|
+
return trimmed;
|
|
1813
|
+
}
|
|
1814
|
+
return trimmed.slice(0, 77) + "...";
|
|
1815
|
+
}
|
|
1816
|
+
function convertMinimalToAnalysisResult(minimal, date, taxonomy, prompts) {
|
|
1766
1817
|
const issueCounts = /* @__PURE__ */ new Map();
|
|
1767
1818
|
for (const issue of minimal.issues) {
|
|
1768
1819
|
issueCounts.set(issue, (issueCounts.get(issue) ?? 0) + 1);
|
|
1769
1820
|
}
|
|
1770
1821
|
const patterns = [...issueCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 5).map(([issueId, count]) => {
|
|
1771
1822
|
const metadata = lookupIssueMetadata(issueId, taxonomy);
|
|
1823
|
+
const examples = prompts ? extractRealExamples(issueId, prompts, 3) : metadata.exampleBefore ? [metadata.exampleBefore] : [];
|
|
1772
1824
|
return {
|
|
1773
1825
|
id: issueId,
|
|
1774
1826
|
name: metadata.name,
|
|
1775
1827
|
frequency: count,
|
|
1776
1828
|
severity: metadata.severity,
|
|
1777
|
-
examples:
|
|
1829
|
+
examples: [...examples],
|
|
1778
1830
|
suggestion: metadata.suggestion,
|
|
1779
1831
|
beforeAfter: {
|
|
1780
1832
|
before: metadata.exampleBefore ?? "Example not available",
|
|
@@ -1788,7 +1840,7 @@ function convertMinimalToAnalysisResult(minimal, date, taxonomy) {
|
|
|
1788
1840
|
stats: {
|
|
1789
1841
|
totalPrompts: 1,
|
|
1790
1842
|
promptsWithIssues: minimal.issues.length > 0 ? 1 : 0,
|
|
1791
|
-
overallScore: minimal.score
|
|
1843
|
+
overallScore: normalizeScore(minimal.score)
|
|
1792
1844
|
},
|
|
1793
1845
|
topSuggestion: patterns.length > 0 && patterns[0] ? patterns[0].suggestion : "Your prompts look good!"
|
|
1794
1846
|
};
|
|
@@ -1909,7 +1961,7 @@ function tryFixTruncatedJson(json) {
|
|
|
1909
1961
|
}
|
|
1910
1962
|
return fixed;
|
|
1911
1963
|
}
|
|
1912
|
-
function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
1964
|
+
function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY, prompts) {
|
|
1913
1965
|
const codeBlockRegex = /```(?:json)?\s*\n?([\s\S]*?)\n?```/;
|
|
1914
1966
|
const jsonMatch = codeBlockRegex.exec(response);
|
|
1915
1967
|
let jsonString = jsonMatch?.[1]?.trim() ?? response.trim();
|
|
@@ -1928,7 +1980,7 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
1928
1980
|
}
|
|
1929
1981
|
if (isValidMinimalResponse(parsed)) {
|
|
1930
1982
|
const minimal = extractMinimalResult(parsed);
|
|
1931
|
-
return convertMinimalToAnalysisResult(minimal, date, taxonomy);
|
|
1983
|
+
return convertMinimalToAnalysisResult(minimal, date, taxonomy, prompts);
|
|
1932
1984
|
}
|
|
1933
1985
|
if (isValidSimpleResponse(parsed)) {
|
|
1934
1986
|
const simple = extractSimpleResponse(parsed);
|
|
@@ -1940,7 +1992,7 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
1940
1992
|
totalPrompts: 0,
|
|
1941
1993
|
// Will be filled by caller
|
|
1942
1994
|
promptsWithIssues: simple.issues.length,
|
|
1943
|
-
overallScore: simple.score
|
|
1995
|
+
overallScore: normalizeScore(simple.score)
|
|
1944
1996
|
},
|
|
1945
1997
|
topSuggestion: simple.tip
|
|
1946
1998
|
};
|
|
@@ -1949,7 +2001,10 @@ function parseResponse(response, date, taxonomy = ISSUE_TAXONOMY) {
|
|
|
1949
2001
|
return {
|
|
1950
2002
|
date,
|
|
1951
2003
|
patterns: parsed.patterns,
|
|
1952
|
-
stats:
|
|
2004
|
+
stats: {
|
|
2005
|
+
...parsed.stats,
|
|
2006
|
+
overallScore: normalizeScore(parsed.stats.overallScore)
|
|
2007
|
+
},
|
|
1953
2008
|
topSuggestion: parsed.topSuggestion
|
|
1954
2009
|
};
|
|
1955
2010
|
}
|
|
@@ -2204,7 +2259,7 @@ var OllamaProvider = class {
|
|
|
2204
2259
|
if (typeof data.response !== "string") {
|
|
2205
2260
|
throw new Error("Invalid response format from Ollama API");
|
|
2206
2261
|
}
|
|
2207
|
-
return parseResponse(data.response, date);
|
|
2262
|
+
return parseResponse(data.response, date, void 0, prompts);
|
|
2208
2263
|
} catch (error) {
|
|
2209
2264
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2210
2265
|
if (lastError.message.includes("parse") || lastError.message.includes("schema")) {
|
|
@@ -2433,7 +2488,7 @@ var AnthropicProvider = class {
|
|
|
2433
2488
|
if (!textContent?.text) {
|
|
2434
2489
|
throw new Error("Invalid response format from Anthropic API");
|
|
2435
2490
|
}
|
|
2436
|
-
return parseResponse(textContent.text, date);
|
|
2491
|
+
return parseResponse(textContent.text, date, void 0, prompts);
|
|
2437
2492
|
} finally {
|
|
2438
2493
|
clearTimeout(timeoutId);
|
|
2439
2494
|
}
|
|
@@ -2580,7 +2635,7 @@ var GoogleProvider = class {
|
|
|
2580
2635
|
if (!textContent) {
|
|
2581
2636
|
throw new Error("Invalid response format from Google API");
|
|
2582
2637
|
}
|
|
2583
|
-
return parseResponse(textContent, date);
|
|
2638
|
+
return parseResponse(textContent, date, void 0, prompts);
|
|
2584
2639
|
} finally {
|
|
2585
2640
|
clearTimeout(timeoutId);
|
|
2586
2641
|
}
|