explainthisrepo 0.4.0 → 0.4.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/cli.js +47 -27
- package/dist/prompt.d.ts +3 -2
- package/dist/prompt.js +46 -38
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import path from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
import { fetchRepo, fetchReadme } from "./github.js";
|
|
9
|
-
import { buildPrompt, buildSimplePrompt } from "./prompt.js";
|
|
9
|
+
import { buildPrompt, buildQuickPrompt, buildSimplePrompt } from "./prompt.js";
|
|
10
10
|
import { generateExplanation } from "./generate.js";
|
|
11
11
|
import { writeOutput } from "./writer.js";
|
|
12
12
|
import { readRepoSignalFiles } from "./repo_reader.js";
|
|
@@ -192,41 +192,39 @@ Examples:
|
|
|
192
192
|
console.warn(`Warning: Could not fetch README: ${e?.message || e}`);
|
|
193
193
|
readme = null;
|
|
194
194
|
}
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
if (options.quick) {
|
|
196
|
+
const prompt = buildQuickPrompt(repoData.full_name, repoData.description, readme);
|
|
197
|
+
console.log("Generating explanation...");
|
|
198
|
+
let output;
|
|
197
199
|
try {
|
|
198
|
-
|
|
200
|
+
output = await generateExplanation(prompt);
|
|
199
201
|
}
|
|
200
202
|
catch (e) {
|
|
201
|
-
console.
|
|
202
|
-
|
|
203
|
+
console.error("Failed to generate explanation.");
|
|
204
|
+
console.error(`error: ${e?.message || e}`);
|
|
205
|
+
console.error("\nfix:");
|
|
206
|
+
console.error("- Ensure GEMINI_API_KEY is set");
|
|
207
|
+
console.error("- Or run: explainthisrepo --doctor");
|
|
208
|
+
process.exit(1);
|
|
203
209
|
}
|
|
204
|
-
}
|
|
205
|
-
const prompt = buildPrompt(repoData.full_name, repoData.description, readme, options.detailed || false, options.quick || false, readResult?.treeText ?? null, readResult?.filesText ?? null);
|
|
206
|
-
console.log("Generating explanation...");
|
|
207
|
-
let output;
|
|
208
|
-
try {
|
|
209
|
-
output = await generateExplanation(prompt);
|
|
210
|
-
}
|
|
211
|
-
catch (e) {
|
|
212
|
-
console.error("Failed to generate explanation.");
|
|
213
|
-
console.error(`error: ${e?.message || e}`);
|
|
214
|
-
console.error("\nfix:");
|
|
215
|
-
console.error("- Ensure GEMINI_API_KEY is set");
|
|
216
|
-
console.error("- Or run: explainthisrepo --doctor");
|
|
217
|
-
process.exit(1);
|
|
218
|
-
}
|
|
219
|
-
if (options.quick) {
|
|
220
210
|
console.log("Quick summary 🎉");
|
|
221
211
|
console.log(output.trim());
|
|
222
212
|
return;
|
|
223
213
|
}
|
|
224
214
|
if (options.simple) {
|
|
225
|
-
|
|
226
|
-
const simplePrompt = buildSimplePrompt(output);
|
|
227
|
-
let simpleOutput;
|
|
215
|
+
let readResult = null;
|
|
228
216
|
try {
|
|
229
|
-
|
|
217
|
+
readResult = await readRepoSignalFiles(owner, repo);
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
console.warn(`Warning: Could not read repo files: ${e?.message || e}`);
|
|
221
|
+
readResult = null;
|
|
222
|
+
}
|
|
223
|
+
const prompt = buildSimplePrompt(repoData.full_name, repoData.description, readme, readResult?.treeText ?? null);
|
|
224
|
+
console.log("Generating explanation...");
|
|
225
|
+
let output;
|
|
226
|
+
try {
|
|
227
|
+
output = await generateExplanation(prompt);
|
|
230
228
|
}
|
|
231
229
|
catch (e) {
|
|
232
230
|
console.error("Failed to generate explanation.");
|
|
@@ -237,9 +235,31 @@ Examples:
|
|
|
237
235
|
process.exit(1);
|
|
238
236
|
}
|
|
239
237
|
console.log("Simple summary 🎉");
|
|
240
|
-
console.log(
|
|
238
|
+
console.log(output.trim());
|
|
241
239
|
return;
|
|
242
240
|
}
|
|
241
|
+
let readResult = null;
|
|
242
|
+
try {
|
|
243
|
+
readResult = await readRepoSignalFiles(owner, repo);
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
246
|
+
console.warn(`Warning: Could not read repo files: ${e?.message || e}`);
|
|
247
|
+
readResult = null;
|
|
248
|
+
}
|
|
249
|
+
const prompt = buildPrompt(repoData.full_name, repoData.description, readme, options.detailed || false, readResult?.treeText ?? null, readResult?.filesText ?? null);
|
|
250
|
+
console.log("Generating explanation...");
|
|
251
|
+
let output;
|
|
252
|
+
try {
|
|
253
|
+
output = await generateExplanation(prompt);
|
|
254
|
+
}
|
|
255
|
+
catch (e) {
|
|
256
|
+
console.error("Failed to generate explanation.");
|
|
257
|
+
console.error(`error: ${e?.message || e}`);
|
|
258
|
+
console.error("\nfix:");
|
|
259
|
+
console.error("- Ensure GEMINI_API_KEY is set");
|
|
260
|
+
console.error("- Or run: explainthisrepo --doctor");
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
243
263
|
console.log("Writing EXPLAIN.md...");
|
|
244
264
|
writeOutput(output);
|
|
245
265
|
const wordCount = output.split(/\s+/).filter(Boolean).length;
|
package/dist/prompt.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export declare function buildPrompt(repoName: string, description: string | null, readme: string | null, detailed?: boolean,
|
|
2
|
-
export declare function
|
|
1
|
+
export declare function buildPrompt(repoName: string, description: string | null, readme: string | null, detailed?: boolean, treeText?: string | null, filesText?: string | null): string;
|
|
2
|
+
export declare function buildQuickPrompt(repoName: string, description: string | null, readme: string | null): string;
|
|
3
|
+
export declare function buildSimplePrompt(repoName: string, description: string | null, readme: string | null, treeText?: string | null): string;
|
package/dist/prompt.js
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
export function buildPrompt(repoName, description, readme, detailed = false,
|
|
2
|
-
if (quick) {
|
|
3
|
-
const readmeSnippet = (readme || "").slice(0, 2000);
|
|
4
|
-
return `
|
|
5
|
-
You are a senior software engineer.
|
|
6
|
-
|
|
7
|
-
Write a ONE-SENTENCE plain-English definition of what this GitHub repository is.
|
|
8
|
-
|
|
9
|
-
Repository:
|
|
10
|
-
- Name: ${repoName}
|
|
11
|
-
- Description: ${description || "No description provided"}
|
|
12
|
-
|
|
13
|
-
README snippet:
|
|
14
|
-
${readmeSnippet || "No README provided"}
|
|
15
|
-
|
|
16
|
-
Rules:
|
|
17
|
-
- Output MUST be exactly 1 sentence.
|
|
18
|
-
- Plain English.
|
|
19
|
-
- No markdown.
|
|
20
|
-
- No quotes.
|
|
21
|
-
- No bullet points.
|
|
22
|
-
- No extra text.
|
|
23
|
-
- Do not add features not stated in the description/README.
|
|
24
|
-
`.trim();
|
|
25
|
-
}
|
|
1
|
+
export function buildPrompt(repoName, description, readme, detailed = false, treeText = null, filesText = null) {
|
|
26
2
|
let prompt = `You are a senior software engineer.
|
|
27
3
|
|
|
28
4
|
Your task is to explain a GitHub repository clearly and concisely for a human reader.
|
|
@@ -34,10 +10,10 @@ Repository:
|
|
|
34
10
|
README content:
|
|
35
11
|
${readme || "No README provided"}
|
|
36
12
|
|
|
37
|
-
|
|
38
|
-
${treeText || "No tree provided"}
|
|
13
|
+
Repo structure:
|
|
14
|
+
${treeText || "No file tree provided"}
|
|
39
15
|
|
|
40
|
-
Key files
|
|
16
|
+
Key code files:
|
|
41
17
|
${filesText || "No code files provided"}
|
|
42
18
|
|
|
43
19
|
Instructions:
|
|
@@ -70,14 +46,46 @@ Output format:
|
|
|
70
46
|
`;
|
|
71
47
|
return prompt.trim();
|
|
72
48
|
}
|
|
73
|
-
export function
|
|
74
|
-
|
|
75
|
-
You are a senior software engineer.
|
|
49
|
+
export function buildQuickPrompt(repoName, description, readme) {
|
|
50
|
+
const readmeSnippet = (readme || "No README provided").slice(0, 2000);
|
|
51
|
+
const prompt = `You are a senior software engineer.
|
|
52
|
+
|
|
53
|
+
Write a ONE-SENTENCE plain-English definition of what this GitHub repository is.
|
|
54
|
+
|
|
55
|
+
Repository:
|
|
56
|
+
- Name: ${repoName}
|
|
57
|
+
- Description: ${description || "No description provided"}
|
|
58
|
+
|
|
59
|
+
README snippet:
|
|
60
|
+
${readmeSnippet}
|
|
61
|
+
|
|
62
|
+
Rules:
|
|
63
|
+
- Output MUST be exactly 1 sentence.
|
|
64
|
+
- Plain English.
|
|
65
|
+
- No markdown.
|
|
66
|
+
- No quotes.
|
|
67
|
+
- No bullet points.
|
|
68
|
+
- No extra text.
|
|
69
|
+
- Do not add features not stated in the description/README.
|
|
70
|
+
`;
|
|
71
|
+
return prompt.trim();
|
|
72
|
+
}
|
|
73
|
+
export function buildSimplePrompt(repoName, description, readme, treeText = null) {
|
|
74
|
+
const readmeContent = (readme || "No README provided").slice(0, 4000);
|
|
75
|
+
const treeContent = (treeText || "No file tree provided").slice(0, 1500);
|
|
76
|
+
const prompt = `You are a senior software engineer.
|
|
77
|
+
|
|
78
|
+
Summarize this GitHub repository in a concise bullet-point format.
|
|
79
|
+
|
|
80
|
+
Repository:
|
|
81
|
+
- Name: ${repoName}
|
|
82
|
+
- Description: ${description || "No description provided"}
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
README content:
|
|
85
|
+
${readmeContent}
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
${
|
|
87
|
+
Repo structure:
|
|
88
|
+
${treeContent}
|
|
81
89
|
|
|
82
90
|
Output style rules:
|
|
83
91
|
- Plain English.
|
|
@@ -89,13 +97,13 @@ Key points from the repo:
|
|
|
89
97
|
- Each bullet MUST start with: ⬤
|
|
90
98
|
- Each bullet title should be 1–3 words only (example: "Purpose", "Stack", "Entrypoints", "How it works", "Usage", "Structure").
|
|
91
99
|
- Each bullet body should be 1–2 lines max.
|
|
92
|
-
-
|
|
93
|
-
-
|
|
100
|
+
- Base bullets strictly on the provided README and structure.
|
|
101
|
+
- Do NOT invent features, architecture, or details not present in the input.
|
|
94
102
|
- Optional: end with one extra line starting with:
|
|
95
103
|
Also interesting:
|
|
96
|
-
- Do NOT add features not present in the input.
|
|
97
104
|
- No quotes.
|
|
98
105
|
|
|
99
106
|
Make it feel like a human developer explaining to another developer in simple terms.
|
|
100
|
-
|
|
107
|
+
`;
|
|
108
|
+
return prompt.trim();
|
|
101
109
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "explainthisrepo",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "A CLI developer tool to explain any GitHub repository in plain English",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Caleb Wodi <calebwodi33@gmail.com>",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"prepublishOnly": "npm run build"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
43
|
+
"node": ">=20"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@google/generative-ai": "^0.24.1",
|