explainthisrepo 0.4.2 → 0.4.3
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 +15 -7
- package/dist/prompt.js +15 -12
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -81,9 +81,11 @@ async function checkUrl(url, timeoutMs = 6000) {
|
|
|
81
81
|
}
|
|
82
82
|
catch (e) {
|
|
83
83
|
clearTimeout(t);
|
|
84
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
85
|
+
const name = e instanceof Error ? e.name : "Error";
|
|
84
86
|
return {
|
|
85
87
|
ok: false,
|
|
86
|
-
msg: `failed (${
|
|
88
|
+
msg: `failed (${name}: ${message})`,
|
|
87
89
|
};
|
|
88
90
|
}
|
|
89
91
|
}
|
|
@@ -108,7 +110,8 @@ async function safeReadRepoFiles(owner, repo) {
|
|
|
108
110
|
return await readRepoSignalFiles(owner, repo);
|
|
109
111
|
}
|
|
110
112
|
catch (e) {
|
|
111
|
-
|
|
113
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
114
|
+
console.warn(`Warning: Could not read repo files: ${message}`);
|
|
112
115
|
return null;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
@@ -117,8 +120,9 @@ async function generateWithExit(prompt) {
|
|
|
117
120
|
return await generateExplanation(prompt);
|
|
118
121
|
}
|
|
119
122
|
catch (e) {
|
|
123
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
120
124
|
console.error("Failed to generate explanation.");
|
|
121
|
-
console.error(`error: ${
|
|
125
|
+
console.error(`error: ${message}`);
|
|
122
126
|
console.error("\nfix:");
|
|
123
127
|
console.error("- Ensure GEMINI_API_KEY is set");
|
|
124
128
|
console.error("- Or run: explainthisrepo --doctor");
|
|
@@ -173,7 +177,8 @@ Examples:
|
|
|
173
177
|
({ owner, repo } = resolveRepoTarget(repository));
|
|
174
178
|
}
|
|
175
179
|
catch (e) {
|
|
176
|
-
|
|
180
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
181
|
+
console.error(`error: ${message}`);
|
|
177
182
|
process.exit(1);
|
|
178
183
|
}
|
|
179
184
|
console.log(`Fetching ${owner}/${repo}...`);
|
|
@@ -190,7 +195,8 @@ Examples:
|
|
|
190
195
|
return;
|
|
191
196
|
}
|
|
192
197
|
catch (e) {
|
|
193
|
-
|
|
198
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
199
|
+
console.error(`error: ${message}`);
|
|
194
200
|
process.exit(1);
|
|
195
201
|
}
|
|
196
202
|
}
|
|
@@ -199,8 +205,9 @@ Examples:
|
|
|
199
205
|
repoData = await fetchRepo(owner, repo);
|
|
200
206
|
}
|
|
201
207
|
catch (e) {
|
|
208
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
202
209
|
console.error("Failed to fetch repository data.");
|
|
203
|
-
console.error(`error: ${
|
|
210
|
+
console.error(`error: ${message}`);
|
|
204
211
|
console.error("\nfix:");
|
|
205
212
|
console.error("- Ensure the repository exists and is public");
|
|
206
213
|
console.error("- Or set GITHUB_TOKEN to avoid rate limits");
|
|
@@ -211,7 +218,8 @@ Examples:
|
|
|
211
218
|
readme = await fetchReadme(owner, repo);
|
|
212
219
|
}
|
|
213
220
|
catch (e) {
|
|
214
|
-
|
|
221
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
222
|
+
console.warn(`Warning: Could not fetch README: ${message}`);
|
|
215
223
|
readme = null;
|
|
216
224
|
}
|
|
217
225
|
if (options.quick) {
|
package/dist/prompt.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
+
function escapeForPromptBlock(input) {
|
|
2
|
+
return input.replace(/</g, "<").replace(/>/g, ">");
|
|
3
|
+
}
|
|
1
4
|
export function buildPrompt(repoName, description, readme, detailed = false, treeText = null, filesText = null) {
|
|
2
5
|
let prompt = `You are a senior software engineer.
|
|
3
6
|
|
|
4
7
|
Your task is to explain a GitHub repository clearly and concisely for a human reader.
|
|
5
8
|
|
|
6
9
|
<repository_metadata>
|
|
7
|
-
Name: ${repoName}
|
|
8
|
-
Description: ${description || "No description provided"}
|
|
10
|
+
Name: ${escapeForPromptBlock(repoName)}
|
|
11
|
+
Description: ${escapeForPromptBlock(description || "No description provided")}
|
|
9
12
|
</repository_metadata>
|
|
10
13
|
|
|
11
14
|
<readme>
|
|
12
|
-
${readme || "No README provided"}
|
|
15
|
+
${escapeForPromptBlock(readme || "No README provided")}
|
|
13
16
|
</readme>
|
|
14
17
|
|
|
15
18
|
<repo_structure>
|
|
16
|
-
${treeText || "No file tree provided"}
|
|
19
|
+
${escapeForPromptBlock(treeText || "No file tree provided")}
|
|
17
20
|
</repo_structure>
|
|
18
21
|
|
|
19
22
|
<code_files>
|
|
20
|
-
${filesText || "No code files provided"}
|
|
23
|
+
${escapeForPromptBlock(filesText || "No code files provided")}
|
|
21
24
|
</code_files>
|
|
22
25
|
|
|
23
26
|
Instructions:
|
|
@@ -59,12 +62,12 @@ export function buildQuickPrompt(repoName, description, readme) {
|
|
|
59
62
|
Write a ONE-SENTENCE plain-English definition of what this GitHub repository is.
|
|
60
63
|
|
|
61
64
|
<repository_metadata>
|
|
62
|
-
Name: ${repoName}
|
|
63
|
-
Description: ${description || "No description provided"}
|
|
65
|
+
Name: ${escapeForPromptBlock(repoName)}
|
|
66
|
+
Description: ${escapeForPromptBlock(description || "No description provided")}
|
|
64
67
|
</repository_metadata>
|
|
65
68
|
|
|
66
69
|
<readme>
|
|
67
|
-
${readmeSnippet}
|
|
70
|
+
${escapeForPromptBlock(readmeSnippet)}
|
|
68
71
|
</readme>
|
|
69
72
|
|
|
70
73
|
Rules:
|
|
@@ -88,16 +91,16 @@ export function buildSimplePrompt(repoName, description, readme, treeText = null
|
|
|
88
91
|
Summarize this GitHub repository in a concise bullet-point format.
|
|
89
92
|
|
|
90
93
|
<repository_metadata>
|
|
91
|
-
Name: ${repoName}
|
|
92
|
-
Description: ${description || "No description provided"}
|
|
94
|
+
Name: ${escapeForPromptBlock(repoName)}
|
|
95
|
+
Description: ${escapeForPromptBlock(description || "No description provided")}
|
|
93
96
|
</repository_metadata>
|
|
94
97
|
|
|
95
98
|
<readme>
|
|
96
|
-
${readmeContent}
|
|
99
|
+
${escapeForPromptBlock(readmeContent)}
|
|
97
100
|
</readme>
|
|
98
101
|
|
|
99
102
|
<repo_structure>
|
|
100
|
-
${treeContent}
|
|
103
|
+
${escapeForPromptBlock(treeContent)}
|
|
101
104
|
</repo_structure>
|
|
102
105
|
|
|
103
106
|
Output style rules:
|