Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ profile.txt
src/version.ts
OPENAI_FIX_SUMMARY.md
docs/vercel/
TESTING.md
FEATURE_SUMMARY.md
CODE_CHANGES.md
README_COMPACT_HERE.md
6 changes: 5 additions & 1 deletion src/components/AIView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ const AIViewInner: React.FC<AIViewProps> = ({

return (
<React.Fragment key={msg.id}>
<MessageRenderer message={msg} onEditUserMessage={handleEditUserMessage} />
<MessageRenderer
message={msg}
onEditUserMessage={handleEditUserMessage}
workspaceId={workspaceId}
/>
{isAtCutoff && (
<EditBarrier>
⚠️ Messages below this line will be removed when you submit the edit
Expand Down
5 changes: 3 additions & 2 deletions src/components/Messages/MessageRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ interface MessageRendererProps {
message: DisplayedMessage;
className?: string;
onEditUserMessage?: (messageId: string, content: string) => void;
workspaceId?: string;
}

// Memoized to prevent unnecessary re-renders when parent (AIView) updates
export const MessageRenderer = React.memo<MessageRendererProps>(
({ message, className, onEditUserMessage }) => {
({ message, className, onEditUserMessage, workspaceId }) => {
// Route based on message type
switch (message.type) {
case "user":
return <UserMessage message={message} className={className} onEdit={onEditUserMessage} />;
case "assistant":
return <AssistantMessage message={message} className={className} />;
case "tool":
return <ToolMessage message={message} className={className} />;
return <ToolMessage message={message} className={className} workspaceId={workspaceId} />;
case "reasoning":
return <ReasoningMessage message={message} className={className} />;
case "stream-error":
Expand Down
4 changes: 3 additions & 1 deletion src/components/Messages/ToolMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
interface ToolMessageProps {
message: DisplayedMessage & { type: "tool" };
className?: string;
workspaceId?: string;
}

// Type guard for bash tool
Expand Down Expand Up @@ -71,7 +72,7 @@ function isProposePlanTool(toolName: string, args: unknown): args is ProposePlan
return toolName === "propose_plan" && typeof args === "object" && args !== null && "plan" in args;
}

export const ToolMessage: React.FC<ToolMessageProps> = ({ message, className }) => {
export const ToolMessage: React.FC<ToolMessageProps> = ({ message, className, workspaceId }) => {
// Route to specialized components based on tool name
if (isBashTool(message.toolName, message.args)) {
return (
Expand Down Expand Up @@ -130,6 +131,7 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({ message, className })
args={message.args}
result={message.result as ProposePlanToolResult | undefined}
status={message.status}
workspaceId={workspaceId}
/>
</div>
);
Expand Down
40 changes: 40 additions & 0 deletions src/components/tools/ProposePlanToolCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { useToolExpansion, getStatusDisplay, type ToolStatus } from "./shared/toolUtils";
import { MarkdownRenderer } from "../Messages/MarkdownRenderer";
import { formatKeybind, KEYBINDS } from "@/utils/ui/keybinds";
import { createCmuxMessage } from "@/types/message";

const PlanContainer = styled.div`
padding: 12px;
Expand Down Expand Up @@ -238,16 +239,19 @@ interface ProposePlanToolCallProps {
args: ProposePlanToolArgs;
result?: ProposePlanToolResult;
status?: ToolStatus;
workspaceId?: string;
}

export const ProposePlanToolCall: React.FC<ProposePlanToolCallProps> = ({
args,
result: _result,
status = "pending",
workspaceId,
}) => {
const { expanded, toggleExpanded } = useToolExpansion(true); // Expand by default
const [showRaw, setShowRaw] = useState(false);
const [copied, setCopied] = useState(false);
const [isCompacting, setIsCompacting] = useState(false);

const statusDisplay = getStatusDisplay(status);

Expand All @@ -261,6 +265,37 @@ export const ProposePlanToolCall: React.FC<ProposePlanToolCallProps> = ({
}
};

const handleCompactHere = async () => {
if (!workspaceId || isCompacting) return;

setIsCompacting(true);
try {
// Create a compacted message with the plan content
// Format: Title as H1 + plan content
const compactedContent = `# ${args.title}\n\n${args.plan}`;

const summaryMessage = createCmuxMessage(
`compact-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`,
"assistant",
compactedContent,
{
timestamp: Date.now(),
compacted: true,
}
);

const result = await window.api.workspace.replaceChatHistory(workspaceId, summaryMessage);

if (!result.success) {
console.error("Failed to compact:", result.error);
}
} catch (err) {
console.error("Compact error:", err);
} finally {
setIsCompacting(false);
}
};

return (
<ToolContainer expanded={expanded}>
<ToolHeader onClick={toggleExpanded}>
Expand All @@ -278,6 +313,11 @@ export const ProposePlanToolCall: React.FC<ProposePlanToolCallProps> = ({
<PlanTitle>{args.title}</PlanTitle>
</PlanHeaderLeft>
<PlanHeaderRight>
{workspaceId && (
<PlanButton onClick={() => void handleCompactHere()} disabled={isCompacting}>
{isCompacting ? "Compacting..." : "📦 Compact Here"}
</PlanButton>
)}
<PlanButton onClick={() => void handleCopy()}>
{copied ? "✓ Copied" : "Copy"}
</PlanButton>
Expand Down