-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfits-stack.js
More file actions
67 lines (57 loc) · 2.49 KB
/
Copy pathfits-stack.js
File metadata and controls
67 lines (57 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Pure helpers for "Fits MY Stack?" — library-grounded one-call AI lens.
// No DOM, no chrome APIs, unit-testable.
export const FITS_VERDICTS = ['slots-in', 'new-paradigm', 'conflict'];
/**
* Build the prompt asking whether the repo slots into the user's existing stack.
* nearestRepos: [{ repoId, eli5, capabilities }] — top matches from the library.
*/
export function buildFitsStackPrompt(repoData, nearestRepos) {
if (!repoData?.repoId || !Array.isArray(nearestRepos) || nearestRepos.length === 0) return '';
const repoBlock = [
`Repo being evaluated: ${repoData.repoId}`,
repoData.description ? `What it does: ${repoData.description}` : '',
repoData.language ? `Language: ${repoData.language}` : '',
repoData.category ? `Category: ${repoData.category}` : '',
repoData.capabilities?.length ? `Capabilities: ${repoData.capabilities.join(', ')}` : '',
].filter(Boolean).join('\n');
const libBlock = nearestRepos.map(r =>
`- ${r.repoId}${r.eli5 ? ': ' + r.eli5.slice(0, 100) : ''}${r.capabilities?.length ? ' [' + r.capabilities.slice(0, 4).join(', ') + ']' : ''}`
).join('\n');
return `You are a senior software architect helping a developer decide whether a new repo fits their existing tech stack.
${repoBlock}
Their current stack (most relevant repos):
${libBlock}
Assess whether this repo:
- slots-in: fills a gap and is complementary to the existing tools
- new-paradigm: could replace something or requires a significant mental model shift
- conflict: creates conceptual or practical friction with what they already use
Return a single JSON object:
{
"verdict": "slots-in" | "new-paradigm" | "conflict",
"summary": "2-3 sentence explanation",
"integrations": ["how it interacts with existing tool"],
"risks": ["friction or concern"],
"recommendation": "One clear action sentence"
}`;
}
/**
* Parse the AI response into a structured result.
* Falls back to a 'new-paradigm' verdict if parsing fails.
*/
export function parseFitsStack(rawText) {
if (!rawText) return null;
const m = String(rawText).match(/\{[\s\S]*\}/);
if (!m) return null;
try {
const r = JSON.parse(m[0]);
return {
verdict: FITS_VERDICTS.includes(r.verdict) ? r.verdict : 'new-paradigm',
summary: String(r.summary || '').trim(),
integrations: Array.isArray(r.integrations) ? r.integrations.map(String) : [],
risks: Array.isArray(r.risks) ? r.risks.map(String) : [],
recommendation: String(r.recommendation || '').trim(),
};
} catch {
return null;
}
}