feat: add /bug report command (#312)

Add `/bug` command for chat session
This commit is contained in:
Fouad Matin
2025-04-18 14:09:35 -07:00
committed by GitHub
parent 4acd7d8617
commit 8e2e77fafb
5 changed files with 152 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ export default function TerminalChatInput({
onCompact,
interruptAgent,
active,
items = [],
}: {
isNew: boolean;
loading: boolean;
@@ -65,6 +66,8 @@ export default function TerminalChatInput({
onCompact: () => void;
interruptAgent: () => void;
active: boolean;
// New: current conversation items so we can include them in bug reports
items?: Array<ResponseItem>;
}): React.ReactElement {
const app = useApp();
const [selectedSuggestion, setSelectedSuggestion] = useState<number>(0);
@@ -239,6 +242,68 @@ export default function TerminalChatInput({
},
);
return;
} else if (inputValue === "/bug") {
// Generate a GitHub bug report URL prefilled with session details
setInput("");
try {
// Dynamically import dependencies to avoid unnecessary bundle size
const [{ default: open }, os] = await Promise.all([
import("open"),
import("node:os"),
]);
// Lazy import CLI_VERSION to avoid circular deps
const { CLI_VERSION } = await import("../../utils/session.js");
const { buildBugReportUrl } = await import(
"../../utils/bug-report.js"
);
const url = buildBugReportUrl({
items: items ?? [],
cliVersion: CLI_VERSION,
model: loadConfig().model ?? "unknown",
platform: `${os.platform()} ${os.arch()} ${os.release()}`,
});
// Open the URL in the user's default browser
await open(url, { wait: false });
// Inform the user in the chat history
setItems((prev) => [
...prev,
{
id: `bugreport-${Date.now()}`,
type: "message",
role: "system",
content: [
{
type: "input_text",
text: "📋 Opened browser to file a bug report. Please include any context that might help us fix the issue!",
},
],
},
]);
} catch (error) {
// If anything went wrong, notify the user
setItems((prev) => [
...prev,
{
id: `bugreport-error-${Date.now()}`,
type: "message",
role: "system",
content: [
{
type: "input_text",
text: `⚠️ Failed to create bug report URL: ${error}`,
},
],
},
]);
}
return;
} else if (inputValue.startsWith("/")) {
// Handle invalid/unrecognized commands.
@@ -330,6 +395,7 @@ export default function TerminalChatInput({
openHelpOverlay,
history, // Add history to the dependency array
onCompact,
items,
],
);

View File

@@ -516,6 +516,7 @@ export default function TerminalChat({
agent.run(inputs, lastResponseId || "");
return {};
}}
items={items}
/>
)}
{overlayMode === "history" && (

View File

@@ -52,6 +52,9 @@ export default function HelpOverlay({
<Text>
<Text color="cyan">/clearhistory</Text> clear command history
</Text>
<Text>
<Text color="cyan">/bug</Text> file a bug report with session log
</Text>
<Text>
<Text color="cyan">/compact</Text> condense context into a summary
</Text>