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