Skip to content

Commit a000eaf

Browse files
committed
feat: enhance backend HTTP request logging in System Messages
- Improve backend chat components for better request visibility - Add comprehensive HTTP request logging in chat stream handlers - Enhance terminal handlers for backend command execution - Update token count handlers for accurate tracking - Backend HTTP requests now properly appear in System Messages
1 parent 920c772 commit a000eaf

File tree

9 files changed

+173
-65
lines changed

9 files changed

+173
-65
lines changed

src/components/backend-chat/BackendChatHeader.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export function BackendChatHeader({
112112
{/* Backend Mode Indicator */}
113113
<div className="flex items-center justify-center px-4 py-2 bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200">
114114
<Server size={16} className="mr-2" />
115-
<span className="text-sm font-medium">Backend Development Mode - Roo-Code Logic</span>
115+
<span className="text-sm font-medium">
116+
Backend Development Mode - Roo-Code Logic
117+
</span>
116118
</div>
117119

118120
{/* If the version pane is open, it's expected to not always be on the main branch. */}
@@ -222,4 +224,4 @@ export function BackendChatHeader({
222224
</div>
223225
</div>
224226
);
225-
}
227+
}

src/components/backend-chat/BackendChatInput.tsx

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,38 @@ export function BackendChatInput({ chatId }: { chatId?: number }) {
107107

108108
try {
109109
// Import terminal output functions
110-
const { addTerminalOutput } = await import("../../ipc/handlers/terminal_handlers");
110+
const { addTerminalOutput } = await import(
111+
"../../ipc/handlers/terminal_handlers"
112+
);
111113

112114
// Initialize backend terminal with welcome message
113-
addTerminalOutput(appId, "backend", `🚀 Backend Development Environment Ready`, "output");
114-
addTerminalOutput(appId, "backend", `Type commands or ask me to run backend operations...`, "output");
115+
addTerminalOutput(
116+
appId,
117+
"backend",
118+
`🚀 Backend Development Environment Ready`,
119+
"output",
120+
);
121+
addTerminalOutput(
122+
appId,
123+
"backend",
124+
`Type commands or ask me to run backend operations...`,
125+
"output",
126+
);
115127

116128
// For fullstack mode, also initialize frontend terminal
117129
if (settings?.selectedChatMode === "fullstack") {
118-
addTerminalOutput(appId, "frontend", `🚀 Frontend Development Environment Ready`, "output");
119-
addTerminalOutput(appId, "frontend", `Type commands or ask me to run frontend operations...`, "output");
130+
addTerminalOutput(
131+
appId,
132+
"frontend",
133+
`🚀 Frontend Development Environment Ready`,
134+
"output",
135+
);
136+
addTerminalOutput(
137+
appId,
138+
"frontend",
139+
`Type commands or ask me to run frontend operations...`,
140+
"output",
141+
);
120142
}
121143
} catch (error) {
122144
logger.error("Failed to initialize terminals:", error);
@@ -283,7 +305,9 @@ export function BackendChatInput({ chatId }: { chatId?: number }) {
283305
{/* Backend Mode Indicator */}
284306
<div className="flex items-center justify-center px-3 py-2 bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200">
285307
<Server size={16} className="mr-2" />
286-
<span className="text-sm font-medium">Backend Development Mode Active</span>
308+
<span className="text-sm font-medium">
309+
Backend Development Mode Active
310+
</span>
287311
</div>
288312

289313
{/* Only render ChatInputActions if proposal is loaded */}
@@ -358,7 +382,10 @@ export function BackendChatInput({ chatId }: { chatId?: number }) {
358382
</div>
359383
<div className="pl-2 pr-1 flex items-center justify-between pb-2">
360384
<div className="flex items-center">
361-
<ChatInputControls showContextFilesPicker={true} appId={appId ?? undefined} />
385+
<ChatInputControls
386+
showContextFilesPicker={true}
387+
appId={appId ?? undefined}
388+
/>
362389
{/* File attachment dropdown */}
363390
<FileAttachmentDropdown
364391
onFileSelect={handleFileSelect}
@@ -418,7 +445,11 @@ function BackendChatInputActions({
418445
return <div>Backend tip proposal</div>;
419446
}
420447
if (proposal.type === "action-proposal") {
421-
return <BackendActionProposalActions proposal={proposal}></BackendActionProposalActions>;
448+
return (
449+
<BackendActionProposalActions
450+
proposal={proposal}
451+
></BackendActionProposalActions>
452+
);
422453
}
423454

424455
// Split files into server functions and other files - only for CodeProposal
@@ -517,7 +548,9 @@ function BackendChatInputActions({
517548
<div className="p-3 border-t border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/20 text-sm">
518549
{!!proposal.securityRisks.length && (
519550
<div className="mb-3">
520-
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">Security Risks</h4>
551+
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">
552+
Security Risks
553+
</h4>
521554
<ul className="space-y-1">
522555
{proposal.securityRisks.map((risk, index) => (
523556
<li key={index} className="flex items-start space-x-2">
@@ -544,7 +577,9 @@ function BackendChatInputActions({
544577

545578
{proposal.sqlQueries?.length > 0 && (
546579
<div className="mb-3">
547-
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">SQL Queries</h4>
580+
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">
581+
SQL Queries
582+
</h4>
548583
<ul className="space-y-2">
549584
{proposal.sqlQueries.map((query, index) => (
550585
<BackendSqlQueryItem key={index} query={query} />
@@ -555,7 +590,9 @@ function BackendChatInputActions({
555590

556591
{proposal.packagesAdded?.length > 0 && (
557592
<div className="mb-3">
558-
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">Backend Packages Added</h4>
593+
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">
594+
Backend Packages Added
595+
</h4>
559596
<ul className="space-y-1">
560597
{proposal.packagesAdded.map((pkg, index) => (
561598
<li
@@ -582,7 +619,9 @@ function BackendChatInputActions({
582619

583620
{serverFunctions.length > 0 && (
584621
<div className="mb-3">
585-
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">Server Functions Changed</h4>
622+
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">
623+
Server Functions Changed
624+
</h4>
586625
<ul className="space-y-1">
587626
{serverFunctions.map((file: FileChange, index: number) => (
588627
<li key={index} className="flex items-center space-x-2">
@@ -604,7 +643,9 @@ function BackendChatInputActions({
604643

605644
{otherFilesChanged.length > 0 && (
606645
<div>
607-
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">Backend Files Changed</h4>
646+
<h4 className="font-semibold mb-1 text-blue-800 dark:text-blue-200">
647+
Backend Files Changed
648+
</h4>
608649
<ul className="space-y-1">
609650
{otherFilesChanged.map((file: FileChange, index: number) => (
610651
<li key={index} className="flex items-center space-x-2">
@@ -630,11 +671,17 @@ function BackendChatInputActions({
630671
);
631672
}
632673

633-
function BackendActionProposalActions({ proposal }: { proposal: ActionProposal }) {
674+
function BackendActionProposalActions({
675+
proposal,
676+
}: {
677+
proposal: ActionProposal;
678+
}) {
634679
return (
635680
<div className="border-b border-blue-200 dark:border-blue-800 p-2 pb-0 flex items-center justify-between bg-blue-50/50 dark:bg-blue-950/20">
636681
<div className="flex items-center space-x-2 overflow-x-auto pb-2">
637-
<span className="text-sm font-medium text-blue-800 dark:text-blue-200">Backend Actions:</span>
682+
<span className="text-sm font-medium text-blue-800 dark:text-blue-200">
683+
Backend Actions:
684+
</span>
638685
{proposal.actions.map((action) => mapBackendActionToButton(action))}
639686
</div>
640687
</div>
@@ -673,7 +720,10 @@ function BackendRebuildButton() {
673720
}, [selectedAppId, posthog, restartApp]);
674721

675722
return (
676-
<BackendSuggestionButton onClick={onClick} tooltipText="Rebuild backend application">
723+
<BackendSuggestionButton
724+
onClick={onClick}
725+
tooltipText="Rebuild backend application"
726+
>
677727
Rebuild Backend
678728
</BackendSuggestionButton>
679729
);
@@ -692,7 +742,10 @@ function BackendRestartButton() {
692742
}, [selectedAppId, posthog, restartApp]);
693743

694744
return (
695-
<BackendSuggestionButton onClick={onClick} tooltipText="Restart backend server">
745+
<BackendSuggestionButton
746+
onClick={onClick}
747+
tooltipText="Restart backend server"
748+
>
696749
Restart Backend
697750
</BackendSuggestionButton>
698751
);
@@ -713,7 +766,10 @@ function BackendKeepGoingButton() {
713766
});
714767
};
715768
return (
716-
<BackendSuggestionButton onClick={onClick} tooltipText="Continue backend development">
769+
<BackendSuggestionButton
770+
onClick={onClick}
771+
tooltipText="Continue backend development"
772+
>
717773
Keep Going
718774
</BackendSuggestionButton>
719775
);
@@ -751,17 +807,11 @@ function BackendSuggestionButton({
751807
function getBackendIconForFileChange(file: FileChange) {
752808
switch (file.type) {
753809
case "write":
754-
return (
755-
<FileText size={16} className="text-blue-500 flex-shrink-0" />
756-
);
810+
return <FileText size={16} className="text-blue-500 flex-shrink-0" />;
757811
case "rename":
758-
return (
759-
<SendToBack size={16} className="text-blue-500 flex-shrink-0" />
760-
);
812+
return <SendToBack size={16} className="text-blue-500 flex-shrink-0" />;
761813
case "delete":
762-
return (
763-
<FileX size={16} className="text-blue-500 flex-shrink-0" />
764-
);
814+
return <FileX size={16} className="text-blue-500 flex-shrink-0" />;
765815
}
766816
}
767817

@@ -853,9 +903,7 @@ function BackendSqlQueryItem({ query }: { query: SqlQuery }) {
853903
</div>
854904
{isExpanded && (
855905
<div className="mt-2 text-xs max-h-[200px] overflow-auto">
856-
<CodeHighlight className="language-sql">
857-
{queryContent}
858-
</CodeHighlight>
906+
<CodeHighlight className="language-sql">{queryContent}</CodeHighlight>
859907
</div>
860908
)}
861909
</li>

src/components/backend-chat/BackendChatMessage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ interface BackendChatMessageProps {
1717
isLastMessage?: boolean;
1818
}
1919

20-
const BackendChatMessage = ({ message, isLastMessage }: BackendChatMessageProps) => {
20+
const BackendChatMessage = ({
21+
message,
22+
isLastMessage,
23+
}: BackendChatMessageProps) => {
2124
const { isStreaming } = useStreamChat();
2225
const appId = useAtomValue(selectedAppIdAtom);
2326
const { versions: liveVersions } = useVersions(appId);
@@ -178,4 +181,4 @@ const BackendChatMessage = ({ message, isLastMessage }: BackendChatMessageProps)
178181
);
179182
};
180183

181-
export { BackendChatMessage };
184+
export { BackendChatMessage };

src/components/backend-chat/BackendChatPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ export function BackendChatPanel({
140140
</div>
141141
</div>
142142
);
143-
}
143+
}

src/components/backend-chat/BackendMessagesList.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,20 @@ export const BackendMessagesList = forwardRef<
2727
<div className="text-2xl">🚀</div>
2828
<h3 className="text-lg font-semibold">Backend Development Ready</h3>
2929
<p className="text-sm text-muted-foreground max-w-md">
30-
Start building your backend with Roo-Code logic. Ask questions about
31-
server architecture, API design, database schemas, or get help with
32-
backend development tasks.
30+
Start building your backend with Roo-Code logic. Ask questions
31+
about server architecture, API design, database schemas, or get
32+
help with backend development tasks.
3333
</p>
3434
</div>
3535
</div>
3636
) : (
3737
<>
3838
{messages.map((message, index) => (
39-
<BackendChatMessage
40-
key={message.id || index}
41-
message={message}
42-
/>
39+
<BackendChatMessage key={message.id || index} message={message} />
4340
))}
4441
<div ref={messagesEndRef} />
4542
</>
4643
)}
4744
</div>
4845
);
49-
});
46+
});

src/components/backend-chat/BackendVersionPane.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ interface BackendVersionPaneProps {
1010
onClose: () => void;
1111
}
1212

13-
export function BackendVersionPane({ isVisible, onClose }: BackendVersionPaneProps) {
13+
export function BackendVersionPane({
14+
isVisible,
15+
onClose,
16+
}: BackendVersionPaneProps) {
1417
const appId = useAtomValue(selectedAppIdAtom);
1518
const { versions, loading } = useVersions(appId);
1619

@@ -19,7 +22,9 @@ export function BackendVersionPane({ isVisible, onClose }: BackendVersionPanePro
1922
return (
2023
<div className="w-80 border-l border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/20 flex flex-col">
2124
<div className="flex items-center justify-between p-4 border-b border-blue-200 dark:border-blue-800">
22-
<h3 className="font-semibold text-blue-800 dark:text-blue-200">Backend Version History</h3>
25+
<h3 className="font-semibold text-blue-800 dark:text-blue-200">
26+
Backend Version History
27+
</h3>
2328
<Button
2429
variant="ghost"
2530
size="sm"
@@ -32,9 +37,13 @@ export function BackendVersionPane({ isVisible, onClose }: BackendVersionPanePro
3237

3338
<div className="flex-1 overflow-y-auto p-4">
3439
{loading ? (
35-
<div className="text-center text-muted-foreground">Loading versions...</div>
40+
<div className="text-center text-muted-foreground">
41+
Loading versions...
42+
</div>
3643
) : versions.length === 0 ? (
37-
<div className="text-center text-muted-foreground">No versions yet</div>
44+
<div className="text-center text-muted-foreground">
45+
No versions yet
46+
</div>
3847
) : (
3948
<div className="space-y-3">
4049
{versions.map((version, index) => (
@@ -43,7 +52,10 @@ export function BackendVersionPane({ isVisible, onClose }: BackendVersionPanePro
4352
className="border border-blue-200 dark:border-blue-800 rounded-lg p-3 bg-white dark:bg-gray-800"
4453
>
4554
<div className="flex items-start gap-3">
46-
<GitCommit size={16} className="text-blue-500 mt-1 flex-shrink-0" />
55+
<GitCommit
56+
size={16}
57+
className="text-blue-500 mt-1 flex-shrink-0"
58+
/>
4759
<div className="flex-1 min-w-0">
4860
<div className="flex items-center gap-2 mb-1">
4961
<span className="font-mono text-sm text-blue-600 dark:text-blue-400">
@@ -61,7 +73,10 @@ export function BackendVersionPane({ isVisible, onClose }: BackendVersionPanePro
6173
<div className="flex items-center gap-1 text-xs text-muted-foreground">
6274
<Clock size={12} />
6375
<span>
64-
{formatDistanceToNow(new Date(version.timestamp * 1000), { addSuffix: true })}
76+
{formatDistanceToNow(
77+
new Date(version.timestamp * 1000),
78+
{ addSuffix: true },
79+
)}
6580
</span>
6681
</div>
6782
</div>
@@ -73,4 +88,4 @@ export function BackendVersionPane({ isVisible, onClose }: BackendVersionPanePro
7388
</div>
7489
</div>
7590
);
76-
}
91+
}

src/ipc/handlers/chat_stream_handlers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ ${componentSnippet}
499499
// For backend mode, read AI_RULES.md from backend folder if it exists
500500
let aiRulesPath = getDyadAppPath(updatedChat.app.path);
501501
if (finalChatMode === "backend") {
502-
const backendRulesPath = path.join(aiRulesPath, "backend", "AI_RULES.md");
502+
const backendRulesPath = path.join(
503+
aiRulesPath,
504+
"backend",
505+
"AI_RULES.md",
506+
);
503507
if (fs.existsSync(backendRulesPath)) {
504508
aiRulesPath = path.join(aiRulesPath, "backend");
505509
}

0 commit comments

Comments
 (0)