Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(plan_review): add tool context support for request plan review

Steven Enamakel3c40ea9f24c6
diff --git a/app/src/components/assistant-ui/elements/approval-card.tsx b/app/src/components/assistant-ui/elements/approval-card.tsx
new file mode 100644
index 0000000000..e3a848b4dd
--- /dev/null
+++ b/app/src/components/assistant-ui/elements/approval-card.tsx
@@ -0,0 +1,185 @@
+'use client';
+
+/**
+ * assistant-ui's approval-card element: a decision surface for a parked tool
+ * call (or any other approve/deny prompt), with the exact command/target
+ * shown above Deny / Always allow / Allow once.
+ *
+ * Vendored from the assistant-ui `elements-approval-card` registry item
+ * (https://r.assistant-ui.com/styles/base-nova/elements-approval-card.json).
+ * Changes from upstream:
+ * - `cn` import path (`@/components/assistant-ui/lib/utils`, this app's alias).
+ * - Every user-facing label (`Deny`, `Always allow`, `Allow once`, `Approved,
+ * running`, `Denied`, `Finished with exit 0`) is now a prop with an English
+ * default, so the calling adapter supplies the translated string via
+ * `useT()` instead of the label being hard-coded.
+ * - `allowOnceProps` / `alwaysAllowProps` / `denyProps` slots: OpenHuman's
+ * WDIO/Playwright specs click a decision button by its
+ * `data-analytics-id` (`agent-harness-behaviors.spec.ts`), and the upstream
+ * buttons carry no per-button identity — only the root div spreads
+ * `...props`. These optional `ComponentProps<'button'>` slots let a caller
+ * attach `data-analytics-id`/`data-testid` without duplicating the button.
+ * - `expiry` slot: an optional node rendered next to the subtitle for a TTL
+ * countdown (`ApprovalRequestCard`'s parked-request TTL has no upstream
+ * equivalent).
+ */
+import type { ComponentProps, ReactNode } from 'react';
+import { CheckIcon, Loader2Icon, TerminalIcon, XIcon } from 'lucide-react';
+
+import { cn } from '@/components/assistant-ui/lib/utils';
+
+import { field, inkButton, paper } from './surfaces';
+
+export type ApprovalState = 'request' | 'running' | 'done' | 'denied';
+
+export interface ApprovalCardLabels {
+ deny?: string;
+ alwaysAllow?: string;
+ allowOnce?: string;
+ runningLabel?: string;
+ deniedLabel?: string;
+ doneLabel?: string;
+}
+
+export function ApprovalCard({
+ state,
+ command,
+ title,
+ subtitle,
+ expiry,
+ onAllowOnce,
+ onAlwaysAllow,
+ onDeny,
+ denyLabel = 'Deny',
+ alwaysAllowLabel = 'Always allow',
+ allowOnceLabel = 'Allow once',
+ runningLabel = 'Approved, running',
+ deniedLabel = 'Denied',
+ doneLabel = 'Finished with exit 0',
+ allowOnceProps,
+ alwaysAllowProps,
+ denyProps,
+ className,
+ ...props
+}: Omit<
+ ComponentProps<'div'>,
+ | 'children'
+ | 'state'
+ | 'command'
+ | 'title'
+ | 'subtitle'
+ | 'onAllowOnce'
+ | 'onAlwaysAllow'
+ | 'onDeny'
+> & {
+ state: ApprovalState;
+ command: string;
+ title: string;
+ subtitle: string;
+ /** Optional node rendered beside the subtitle (e.g. a TTL countdown). */
+ expiry?: ReactNode;
+ onAllowOnce?: () => void;
+ onAlwaysAllow?: () => void;
+ onDeny?: () => void;
+ denyLabel?: string;
+ alwaysAllowLabel?: string;
+ allowOnceLabel?: string;
+ runningLabel?: string;
+ deniedLabel?: string;
+ doneLabel?: string;
+ allowOnceProps?: ComponentProps<'button'>;
+ alwaysAllowProps?: ComponentProps<'button'>;
+ denyProps?: ComponentProps<'button'>;
+}) {
+ return (
+ <div
+ data-slot="approval-card"
+ className={cn(paper, 'flex w-full max-w-sm flex-col gap-3.5 rounded-[20px] p-4', className)}
+ {...props}
+ >
+ <div className="flex items-center gap-3">
+ <span className="bg-foreground/[0.05] text-foreground/45 flex size-9 shrink-0 items-center justify-center rounded-xl">
+ <TerminalIcon className="size-4" />
+ </span>
+ <div className="flex flex-col">
+ <p className="text-[13.5px] font-medium">{title}</p>
+ <p className="text-foreground/45 text-xs">{subtitle}</p>
+ {expiry}
+ </div>
+ </div>
+
+ <div className={cn(field, 'text-foreground/70 rounded-xl px-3.5 py-2.5 font-mono text-xs')}>
+ {command}
+ </div>
+
+ <div className="flex h-8 items-center justify-end gap-2">
+ {state === 'request' ? (
+ <>
+ {onDeny && (
+ <button
+ type="button"
+ onClick={onDeny}
+ {...denyProps}
+ className={cn(
+ 'text-foreground/55 hover:bg-foreground/[0.06] hover:text-foreground/90 h-8 rounded-full px-3.5 text-xs font-medium transition-[background-color,color,scale] duration-150 active:scale-[0.96]',
+ denyProps?.className
+ )}
+ >
+ {denyLabel}
+ </button>
+ )}
+ {onAlwaysAllow && (
+ <button
+ type="button"
+ onClick={onAlwaysAllow}
+ {...alwaysAllowProps}
+ className={cn(
+ 'text-foreground/55 hover:bg-foreground/[0.06] hover:text-foreground/90 h-8 rounded-full px-3.5 text-xs font-medium transition-[background-color,color,scale] duration-150 active:scale-[0.96]',
+ alwaysAllowProps?.className
+ )}
+ >
+ {alwaysAllowLabel}
+ </button>
+ )}
+ {onAllowOnce && (
+ <button
+ type="button"
+ onClick={onAllowOnce}
+ {...allowOnceProps}
+ className={cn(
+ inkButton,
+ 'flex h-8 items-center rounded-full px-3.5 text-xs font-medium',
+ allowOnceProps?.className
+ )}
+ >
+ {allowOnceLabel}
+ </button>
+ )}
+ </>
+ ) : (
+ <div
+ key={state}
+ className="fade-in animate-in text-foreground/55 flex items-center gap-2 text-xs duration-300"
+ >
+ {state === 'running' ? (
+ <>
+ <Loader2Icon className="text-foreground/45 size-3.5 animate-spin" />
+ {runningLabel}
+ </>
+ ) : state === 'denied' ? (
+ <>
+ <XIcon className="text-foreground/45 size-3.5" />
+ {deniedLabel}
+ </>
+ ) : (
+ <>
+ <CheckIcon className="size-3.5 text-emerald-500" />
+ {doneLabel}
+ </>
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/crates/openhuman-core/src/agent/plan_review/tool.rs b/crates/openhuman-core/src/agent/plan_review/tool.rs
index 3ea37583db..0f3fc79268 100644
--- a/crates/openhuman-core/src/agent/plan_review/tool.rs
+++ b/crates/openhuman-core/src/agent/plan_review/tool.rs
@@ -13,7 +13,7 @@ use serde_json::json;
use crate::agent::turn_origin::{self, AgentTurnOrigin};
use crate::security::approval::APPROVAL_CHAT_CONTEXT;
-use tinytools::{PermissionLevel, Tool, ToolResult, ToolTimeout};
+use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolRunContext, ToolTimeout};
use super::gate;
use super::types::PlanReviewResolution;
@@ -80,6 +80,26 @@ impl Tool for RequestPlanReviewTool {
}
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
+ self.execute_in_context(args, None).await
+ }
+
+ async fn execute_with_context(
+ &self,
+ args: serde_json::Value,
+ _options: ToolCallOptions,
+ context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ self.execute_in_context(args, context).await
+ }
+}
+
+impl RequestPlanReviewTool {
+ async fn execute_in_context(
+ &self,
+ args: serde_json::Value,
+ context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let tool_call_id = crate::tools::host_extensions::tool_call_id(context);
let summary = args
.get("summary")
.and_then(|v| v.as_str())