-
Notifications
You must be signed in to change notification settings - Fork 106
feat: implement ExitPlanMode HITL for Tool Permission Model #1589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
quay-devel
wants to merge
4
commits into
ambient-code:main
Choose a base branch
from
quay-devel:feat/exit-plan-mode-hitl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ffef7ac
feat: implement Tool Permission Model with ExitPlanMode HITL support
quay-devel af4a825
refactor: address review feedback for ExitPlanMode HITL
quay-devel 45eb7fc
Merge branch 'main' into feat/exit-plan-mode-hitl
mergify[bot] d7352bb
fix: address CodeRabbit review findings
quay-devel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 200 additions & 0 deletions
200
components/frontend/src/components/session/exit-plan-mode.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| "use client"; | ||
|
|
||
| import React, { useState } from "react"; | ||
| import ReactMarkdown from "react-markdown"; | ||
| import remarkGfm from "remark-gfm"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { ClipboardCheck, CheckCircle2, Send } from "lucide-react"; | ||
| import { formatTimestamp } from "@/lib/format-timestamp"; | ||
| import { hasToolResult } from "@/lib/hitl-tools"; | ||
| import type { ToolUseBlock, ToolResultBlock } from "@/types/agentic-session"; | ||
|
|
||
| export type ExitPlanModeMessageProps = { | ||
| toolUseBlock: ToolUseBlock; | ||
| resultBlock?: ToolResultBlock; | ||
| timestamp?: string; | ||
| onSubmitAnswer?: (formattedAnswer: string) => Promise<void>; | ||
| isNewest?: boolean; | ||
| }; | ||
|
|
||
| type AllowedPrompt = { | ||
| tool: string; | ||
| prompt: string; | ||
| }; | ||
|
|
||
| export const ExitPlanModeMessage: React.FC<ExitPlanModeMessageProps> = ({ | ||
| toolUseBlock, | ||
| resultBlock, | ||
| timestamp, | ||
| onSubmitAnswer, | ||
| isNewest = false, | ||
| }) => { | ||
| const input = toolUseBlock.input; | ||
| const planContent = (input.planContent as string) || ""; | ||
| const allowedPrompts = (input.allowedPrompts as AllowedPrompt[]) || []; | ||
| const alreadyAnswered = hasToolResult(resultBlock); | ||
| const formattedTime = formatTimestamp(timestamp); | ||
|
|
||
| const [submitted, setSubmitted] = useState(false); | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const [showFeedback, setShowFeedback] = useState(false); | ||
| const [feedback, setFeedback] = useState(""); | ||
| const disabled = alreadyAnswered || submitted || isSubmitting || !isNewest; | ||
|
|
||
| const handleDecision = async (decision: "approve" | "reject" | "request_changes", feedbackText?: string) => { | ||
| if (!onSubmitAnswer || disabled) return; | ||
| const response: Record<string, string> = { decision }; | ||
| if (feedbackText) { | ||
| response.feedback = feedbackText; | ||
| } | ||
| try { | ||
| setIsSubmitting(true); | ||
| await onSubmitAnswer(JSON.stringify(response)); | ||
| setSubmitted(true); | ||
| } finally { | ||
| setIsSubmitting(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="mb-3"> | ||
| <div className="flex items-start gap-3"> | ||
| {/* Avatar */} | ||
| <div className="flex-shrink-0"> | ||
| <div | ||
| className={cn( | ||
| "w-8 h-8 rounded-full flex items-center justify-center", | ||
| disabled ? "bg-green-600" : "bg-blue-500" | ||
| )} | ||
| > | ||
| {disabled ? ( | ||
| <CheckCircle2 className="w-4 h-4 text-white" /> | ||
| ) : ( | ||
| <ClipboardCheck className="w-4 h-4 text-white" /> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Content */} | ||
| <div className="flex-1 min-w-0"> | ||
| {formattedTime && ( | ||
| <div className="text-[10px] text-muted-foreground/60 mb-0.5">{formattedTime}</div> | ||
| )} | ||
|
|
||
| <div | ||
| className={cn( | ||
| "rounded-lg border-l-3 pl-3 pr-3 py-2.5", | ||
| disabled | ||
| ? "border-l-green-500 bg-green-50/30 dark:bg-green-950/10" | ||
| : "border-l-blue-500 bg-blue-50/30 dark:bg-blue-950/10" | ||
| )} | ||
| > | ||
| <p className="text-sm font-medium text-foreground mb-2">Plan Review</p> | ||
|
|
||
| {/* Plan content */} | ||
| {planContent && ( | ||
| <div className="text-sm prose prose-sm dark:prose-invert max-w-none mb-3 max-h-96 overflow-y-auto rounded border border-border/40 p-2.5 bg-background/50"> | ||
| <ReactMarkdown remarkPlugins={[remarkGfm]}> | ||
| {planContent} | ||
| </ReactMarkdown> | ||
| </div> | ||
| )} | ||
|
|
||
| {/* Allowed prompts */} | ||
| {allowedPrompts.length > 0 && ( | ||
| <div className="mb-3"> | ||
| <p className="text-xs font-medium text-muted-foreground mb-1">Requested permissions:</p> | ||
| <ul className="space-y-0.5"> | ||
| {allowedPrompts.map((p) => ( | ||
| <li key={`${p.tool}:${p.prompt}`} className="text-xs text-muted-foreground flex items-center gap-1.5"> | ||
| <span className="inline-block w-1 h-1 rounded-full bg-muted-foreground/50 flex-shrink-0" /> | ||
| <span className="font-mono">{p.tool}</span>: {p.prompt} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| )} | ||
|
|
||
| {/* Request changes feedback input */} | ||
| {showFeedback && !disabled && ( | ||
| <div className="mb-2"> | ||
| <Input | ||
| autoFocus | ||
| placeholder="Describe the changes you'd like..." | ||
| value={feedback} | ||
| onChange={(e) => setFeedback(e.target.value)} | ||
| onKeyDown={(e) => { | ||
| if (e.key === "Enter" && !e.shiftKey && feedback.trim()) { | ||
| e.preventDefault(); | ||
| handleDecision("request_changes", feedback.trim()); | ||
| } | ||
| }} | ||
| disabled={disabled} | ||
| className="h-8 text-sm" | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
| {/* Action buttons */} | ||
| {!disabled && ( | ||
| <div className="flex items-center gap-1.5 mt-2 pt-1.5 border-t border-border/40"> | ||
| {!showFeedback ? ( | ||
| <> | ||
| <Button | ||
| size="sm" | ||
| className="h-7 text-xs gap-1 px-3" | ||
| onClick={() => handleDecision("approve")} | ||
| > | ||
| <CheckCircle2 className="w-3 h-3" /> | ||
| Approve | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| size="sm" | ||
| className="h-7 text-xs px-3" | ||
| onClick={() => handleDecision("reject")} | ||
| > | ||
| Reject | ||
| </Button> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| className="h-7 text-xs px-3" | ||
| onClick={() => setShowFeedback(true)} | ||
| > | ||
| Request Changes | ||
| </Button> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <Button | ||
| size="sm" | ||
| className="h-7 text-xs gap-1 px-3" | ||
| onClick={() => handleDecision("request_changes", feedback.trim())} | ||
| disabled={!feedback.trim()} | ||
| > | ||
| <Send className="w-3 h-3" /> | ||
| Send Feedback | ||
| </Button> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| className="h-7 text-xs px-3" | ||
| onClick={() => setShowFeedback(false)} | ||
| > | ||
| Cancel | ||
| </Button> | ||
| </> | ||
| )} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| ExitPlanModeMessage.displayName = "ExitPlanModeMessage"; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.