husteno-o feat: code review system, type safety, error handling, AI provider fallback · 9/9/2026
5ccaeae
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { aiCopilot } from "@devpulse/ai";
import { githubClient } from "@devpulse/github";
import { SlashCommandBuilder } from "discord.js";
import { createAiBugfixActionButtons, createAiReviewActionButtons } from "../ui/components.js";
import {
createAiBugfixEmbed,
createAiExplainEmbed,
createAiReviewEmbed,
createAiSummaryEmbed,
createErrorEmbed,
} from "../ui/embeds.js";
import type { Command } from "./types.js";
export const aiCommand: Command = {
data: new SlashCommandBuilder()
.setName("ai")
.setDescription(
"AI Code Copilot & Reviewer: automated PR reviews, standup summaries, bugfixes & explain",
)
.addSubcommand((sub) =>
sub
.setName("review")
.setDescription(
"Perform automated code review on a pull request (security, bugs, diff fixes)",
)
.addStringOption((opt) =>
opt.setName("repo").setDescription("Repository format 'owner/repo'").setRequired(true),
)
.addIntegerOption((opt) =>
opt.setName("pr").setDescription("Pull request number").setRequired(true),
),
)
.addSubcommand((sub) =>
sub
.setName("summarize")
.setDescription("Generate executive changelog and standup summaries of shipped code")
.addStringOption((opt) =>
opt.setName("repo").setDescription("Repository format 'owner/repo'").setRequired(true),
)
.addStringOption((opt) =>
opt
.setName("timeframe")
.setDescription("Timeframe for standup summary")
.addChoices(
{ name: "Week (Past 7 Days)", value: "week" },
{ name: "Month (Past 30 Days)", value: "month" },
)
.setRequired(false),
),
)
.addSubcommand((sub) =>
sub
.setName("bugfix")
.setDescription(
"Ingest issue description & stack traces, identify culprit, and synthesize patch",
)
.addStringOption((opt) =>
opt.setName("repo").setDescription("Repository format 'owner/repo'").setRequired(true),
)
.addIntegerOption((opt) =>
opt.setName("issue").setDescription("Issue number").setRequired(true),
),
)
.addSubcommand((sub) =>
sub
.setName("explain")
.setDescription(
"Explain algorithms, system architecture, dependencies & complexity of a file",
)
.addStringOption((opt) =>
opt.setName("repo").setDescription("Repository format 'owner/repo'").setRequired(true),
)
.addStringOption((opt) =>
opt
.setName("file")
.setDescription("Path to the file inside repository (e.g. src/auth/token.ts)")
.setRequired(true),
)
.addIntegerOption((opt) =>
opt
.setName("line")
.setDescription("Optional specific line number to focus on")
.setRequired(false),
),
),
async execute(interaction) {
await interaction.deferReply();
const subcommand = interaction.options.getSubcommand();
const repoInput = interaction.options.getString("repo", true);
try {
if (subcommand === "review") {
const prNumber = interaction.options.getInteger("pr", true);
const [repo, pr, files] = await Promise.all([
githubClient.getRepo(repoInput),
githubClient.getPullRequest(repoInput, prNumber),
githubClient.getPullRequestFiles(repoInput, prNumber),
]);
const review = await aiCopilot.reviewPullRequest(repo.fullName, pr, files);
const embed = createAiReviewEmbed(repo, pr, review);
const components = createAiReviewActionButtons(
repo.owner.login,
repo.name,
pr.number,
pr.htmlUrl,
review.approvedForMerge,
);
await interaction.editReply({ embeds: [embed], components });
return;
}
if (subcommand === "summarize") {
const timeframe = (interaction.options.getString("timeframe") || "week") as
| "week"
| "month";
const repo = await githubClient.getRepo(repoInput);
const days = timeframe === "week" ? 7 : 30;
const sinceDate = new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString();
const [commits, prs] = await Promise.all([
githubClient.getCommits(repoInput, 50),
githubClient.getPullRequests(repoInput, "closed", 30),
]);
// Filter commits and PRs within timeframe
const filteredCommits = commits.filter(
(c) => new Date(c.author.date).getTime() >= new Date(sinceDate).getTime(),
);
const targetCommits = filteredCommits.length > 0 ? filteredCommits : commits.slice(0, 15);
const filteredPrs = prs.filter(
(p) =>
p.state === "closed" &&
new Date(p.updatedAt).getTime() >= new Date(sinceDate).getTime(),
);
const targetPrs = filteredPrs.length > 0 ? filteredPrs : prs.slice(0, 10);
const summary = await aiCopilot.summarizeActivity(
repo,
targetCommits,
targetPrs,
timeframe,
);
const embed = createAiSummaryEmbed(repo, summary);
await interaction.editReply({ embeds: [embed] });
return;
}
if (subcommand === "bugfix") {
const issueNumber = interaction.options.getInteger("issue", true);
const [repo, issue] = await Promise.all([
githubClient.getRepo(repoInput),
githubClient.getSingleIssue(repoInput, issueNumber),
]);
const bugfix = await aiCopilot.suggestBugfix(repo.fullName, issue);
const embed = createAiBugfixEmbed(repo, issue, bugfix);
const components = createAiBugfixActionButtons(
repo.owner.login,
repo.name,
issue.number,
issue.htmlUrl,
);
await interaction.editReply({ embeds: [embed], components });
return;
}
if (subcommand === "explain") {
const filePath = interaction.options.getString("file", true);
const line = interaction.options.getInteger("line") || undefined;
const [repo, file] = await Promise.all([
githubClient.getRepo(repoInput),
githubClient.getFileContents(repoInput, filePath),
]);
const explanation = await aiCopilot.explainCode(
repo.fullName,
file.path,
file.content,
line,
);
const embed = createAiExplainEmbed(repo, file, explanation, line);
await interaction.editReply({ embeds: [embed] });
return;
}
} catch (err: unknown) {
await interaction.editReply({
embeds: [createErrorEmbed(err instanceof Error ? err : new Error(String(err)))],
});
}
},
};