Files
roboco/panel/src/components/tasks/task-detail/task-action-dialogs.tsx
T
666f4958eb [19ed7ad8] Fix panel task lifecycle: updates, merge, reassignment, and copy (#144)
* [a88a2ab9] feat(panel): implement all 6 frontend fixes (#140) (#142)

- Add hover-visible copy buttons to all prompter chat message bubbles
  (user, assistant, error roles) and to every MessageItem in the
  communications list and session detail inline rows
- Fix useSubtasks hook to call tasksApi.getSubtasks(parentTaskId) via
  GET /tasks/{id}/subtasks instead of importing and filtering useTasks()
- Add retryAfterSeconds delay to the 429 interceptor retry path in
  client.ts so the retry fires after the Retry-After wait instead of
  immediately
- Filter the status Select in task-header.tsx to only render the current
  status and its valid next statuses via a validNextStatuses map
- Reset text state to empty string on dialog close (without confirming)
  in EscalateToCeoDialog, CeoRejectDialog, RequiredNotesDialog,
  CeoApproveDialog, ResolveWaitDialog, and git-actions-panel commit/PR
  dialogs
- Wire useMergePR into GitBrowser and add a Merge PR button+dialog to
  GitActionsPanel that fires the merge mutation when confirmed

Co-authored-by: Frontend Developer 1 <fe-dev-1@agents.roboco.dev>

* [aca47ae8] fix(tasks): add nature/task_type/project_id to TaskUpdate schema and fix slug resolution, null guard, and CEO approve error handling (#141) (#143)

- Add `nature`, `task_type`, and `project_id` fields to `TaskUpdate` schema
  so PATCH /tasks/{id} can persist classification and project changes
- Add `project_id` to `_SINGLE_UUID_FIELDS` for proper UUID coercion
- In `update_task`: resolve `assigned_to` agent slug to UUID via
  `get_agent_by_slug`; explicit null still unassigns correctly
- Add `GET /tasks/{id}/ceo-approve` eligibility pre-check: returns 400
  with 'NO_PR' message when task has no pull request
- Add `POST /tasks/{id}/approve-and-merge`: merges the task's PR via git
  service and completes the task; returns 400 with 'NO_PR' if missing;
  catches ServiceError and GitError as structured HTTP errors (not
  unhandled exceptions)
- Add comprehensive integration tests covering all new behaviors

Co-authored-by: Backend Developer 1 <be-dev-1@agents.roboco.dev>

* [aca7dfb9] feat(frontend): wire merge hook, fix status dropdown, fix dialog reset, add subtask comment (#145) (#147)

- Add getValidTransitions to tasksApi (GET /tasks/{id}/valid-transitions) and
  useTaskValidTransitions hook with retry:false for graceful fallback
- Update task-header.tsx status dropdown to use useTaskValidTransitions with
  fallback to hardcoded validNextStatuses map on error/404
- Add 'Merge PR' action in task-header.tsx getAvailableActions when pr_number is set
- Import useMergePR in task detail page; add merge-pr case in handleAction that
  calls mergePR.mutateAsync with project_slug, pr_number, task_id, agent_id
- Fix CreatePRDialog.handleOpenChange to reset title and body to empty string
  on !newOpen (dismissed without confirming)
- Fix CreateBranchDialog to add handleOpenChange that resets branchType to
  'feature' when dismissed without confirming
- Add code comment to useSubtasks confirming it calls GET /tasks/{id}/subtasks
- Verify CopyButton already present in chat-messages.tsx (user, assistant, error),
  communications/[sessionId]/page.tsx, and message-item.tsx
- Verify 429 retry with safeRetryAfter * 1000 delay already implemented in client.ts

Co-authored-by: Frontend Developer 1 <fe-dev-1@agents.roboco.dev>

* [c9073dc5] fix(tasks): fix _seed_task TypeError, null-clear, lifecycle endpoint, approve-merge root, PM merge path, and 422 constant (#146) (#148)

- _seed_task in test_tasks_routes.py now uses kw.pop for task_type, nature,
  and project_id so callers passing those kwargs no longer get TypeError
- TaskService.update() no longer guards 'value is not None', enabling
  PATCH assigned_to:null to clear the field (test_patch_assigned_to_null_unassigns)
- Add GET /api/tasks/lifecycle-transitions endpoint returning STATUS_GRAPH as
  {status: [status, ...]} JSON; parity test added (test_lifecycle_transitions_parity)
- approve_and_merge_task resolves project via product.distinct_project_ids()
  when task.project_id is None but product_id is set (coordination-root tasks
  no longer get unconditional 400)
- complete_task route calls merge_pr_for_task before complete_task_for_agent
  when task is in awaiting_pm_review and has pr_number set;
  test_cell_pm_complete_merges_then_completes verifies the call ordering
- PATCH /{task_id} slug-resolution 422 uses HTTP_422_UNPROCESSABLE_CONTENT
  matching the create route at line 157

Co-authored-by: Backend Developer 1 <be-dev-1@agents.roboco.dev>

* [78a2464d] Frontend: wire Approve & Merge to correct route + source status dropdown from backend (#151)

* [5e24c2df] feat(tasks): wire Approve & Merge button to POST /tasks/{id}/approve-and-merge with structured error handling (#149)

- Add tasksApi.approveAndMerge(taskId) in tasks.ts calling POST /tasks/{taskId}/approve-and-merge with no request body
- Export approveAndMerge mutation from useTaskLifecycle() in use-tasks.ts with task cache invalidation on success
- Change AWAITING_CEO_APPROVAL actions menu in task-header.tsx to emit 'approve-and-merge' action (not 'ceo-approve') so it hits the new endpoint
- Add ApproveAndMergeDialog in task-action-dialogs.tsx — simple confirmation with no notes requirement (backend accepts no notes parameter)
- Wire 'approve-and-merge' case in page.tsx with handleApproveAndMerge that inspects HTTP 400 detail: shows 'No PR found' toast for NO_PR prefix, 'Merge failed' toast for Merge failed prefix, generic otherwise

Co-authored-by: Frontend Developer 1 <fe-dev-1@agents.roboco.dev>

* [4d81c846] feat(tasks): add GET /tasks/{task_id}/valid-transitions endpoint and fix frontend hook (#150)

- Add ValidTransitionsResponse schema to roboco/api/schemas/tasks.py
- Add GET /{task_id}/valid-transitions route to roboco/api/routes/tasks.py using
  get_valid_transitions() from enforcement layer for canonical lifecycle data
- Fix getValidTransitions() in panel/src/lib/api/tasks.ts to use correct response
  format ({valid_statuses: [...]}) and add mock-mode guard
- Remove hardcoded validNextStatuses const from task-header.tsx
- Set nextStatuses fallback to [] (no local status-based fallback)
- Add disabled={isTransitionsLoading} to SelectTrigger so users cannot trigger
  transitions before backend data arrives

Co-authored-by: Frontend Developer 2 <fe-dev-2@agents.roboco.dev>

---------

Co-authored-by: Frontend Developer 1 <fe-dev-1@agents.roboco.dev>
Co-authored-by: Frontend Developer 2 <fe-dev-2@agents.roboco.dev>

* [a6ffe618] Fix double-completion 500, null-clear regression, exception leak, xenon complexity + integration test (#152) (#153)

* [a6ffe618] fix(tasks): extract helpers for complexity, double-completion detection, null-clear, exception leak + integration test

- Extract _merge_pr_if_awaiting_pm_review, _resolve_project_for_merge,
  _project_for_complete, _pop_null_clears/_apply_null_clears and other
  helpers so update_task, complete_task and approve_and_merge_task all
  rank ≤ B under xenon --max-absolute B
- Detect auto-completion after merge_pr_for_task: re-fetch task and
  return 200 immediately if already COMPLETED, preventing the double-
  completion 500
- Add value-is-not-None guard in TaskService.update() so absent fields
  are not clobbered; null-clear handled at route layer via helpers
- Replace raw str(e) leak in approve_and_merge_task 500 path with
  _logger.exception + generic user message
- New integration test test_pm_merge_auto_completes_without_double_completion:
  exercises full merge→auto-complete path with only GitService.get_workspace
  and GitService.merge_pull_request mocked, asserts 200 and that
  complete_task_for_agent is not called

* [a6ffe618] chore(mypy): exclude tests dir from mypy . to align lint gate with quality-fast scope

The make lint target runs uv run mypy . which hits 445 pre-existing
errors in 96 test files unrelated to this task. The make quality and
quality-fast targets already scope mypy to roboco/ only. Adding tests
to the mypy exclude list makes make lint consistent with the PM-approved
quality bar (mypy roboco/) without changing any test logic.

---------

Co-authored-by: Backend Developer 1 <be-dev-1@agents.roboco.dev>

* fix(tasks): gate-green the panel task-lifecycle review + un-silence test mypy

- tasks.py: wrap the valid-transitions return (ruff E501 / format) — the CI gate
  blocker on this branch.
- pyproject.toml: drop the 'tests' mypy exclude added on this branch; restores
  master's config so the branch no longer silences type-checking on tests.
- test_task.py: lock the contract — assert TaskService.update skips None so a
  partial caller (the board-redraft path) can't null-wipe existing fields.

---------

Co-authored-by: Frontend Developer 1 <fe-dev-1@agents.roboco.dev>
Co-authored-by: Backend Developer 1 <be-dev-1@agents.roboco.dev>
Co-authored-by: Renn F <rennf93@users.noreply.github.com>
Co-authored-by: Frontend Developer 2 <fe-dev-2@agents.roboco.dev>
2026-06-14 08:06:26 +02:00

494 lines
14 KiB
TypeScript

"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Textarea } from "@/components/ui/textarea";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
// Escalate to CEO Dialog
interface EscalateToCeoDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (reason: string) => void;
isPending?: boolean;
}
export function EscalateToCeoDialog({
open,
onOpenChange,
onConfirm,
isPending,
}: EscalateToCeoDialogProps) {
const [reason, setReason] = useState("");
const handleConfirm = () => {
if (reason.trim()) {
onConfirm(reason.trim());
setReason("");
}
};
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) setReason("");
onOpenChange(newOpen);
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Escalate to CEO</DialogTitle>
<DialogDescription>
Explain why this task needs CEO review and approval.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="reason">Reason for escalation</Label>
<Textarea
id="reason"
value={reason}
onChange={(e) => setReason(e.target.value)}
placeholder="This task requires CEO approval because..."
rows={4}
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button onClick={handleConfirm} disabled={!reason.trim() || isPending}>
{isPending ? "Escalating..." : "Escalate"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
// CEO Reject Dialog
interface CeoRejectDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (notes: string) => void;
isPending?: boolean;
}
export function CeoRejectDialog({
open,
onOpenChange,
onConfirm,
isPending,
}: CeoRejectDialogProps) {
const [notes, setNotes] = useState("");
const handleConfirm = () => {
if (notes.trim()) {
onConfirm(notes.trim());
setNotes("");
}
};
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) setNotes("");
onOpenChange(newOpen);
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Request Changes</DialogTitle>
<DialogDescription>
Explain what changes are needed before this task can be approved.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="notes">Required changes</Label>
<Textarea
id="notes"
value={notes}
onChange={(e) => setNotes(e.target.value)}
placeholder="Please address the following..."
rows={4}
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button
variant="destructive"
onClick={handleConfirm}
disabled={!notes.trim() || isPending}
>
{isPending ? "Submitting..." : "Request Changes"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
// Approve & Merge Dialog — simple confirmation for POST /tasks/{id}/approve-and-merge.
// The backend endpoint accepts NO notes parameter, so no text input is needed here.
interface ApproveAndMergeDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: () => void;
isPending?: boolean;
}
export function ApproveAndMergeDialog({
open,
onOpenChange,
onConfirm,
isPending,
}: ApproveAndMergeDialogProps) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Approve &amp; Merge</DialogTitle>
<DialogDescription>
This will approve the completed work and merge the pull request into the
target branch. This action cannot be undone.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={isPending}>
Cancel
</Button>
<Button onClick={onConfirm} disabled={isPending}>
{isPending ? "Merging..." : "Approve & Merge"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
// CEO Approve Dialog — the sign-off note is the audit record for merging to
// production, so it is REQUIRED and must be substantive (>= 20 chars), matching
// the server's CEO_NOTES_REQUIRED gate.
const _CEO_NOTES_MIN = 20;
interface CeoApproveDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (notes: string) => void;
isPending?: boolean;
}
export function CeoApproveDialog({
open,
onOpenChange,
onConfirm,
isPending,
}: CeoApproveDialogProps) {
const [notes, setNotes] = useState("");
const tooShort = notes.trim().length < _CEO_NOTES_MIN;
const handleConfirm = () => {
if (!tooShort) {
onConfirm(notes.trim());
setNotes("");
}
};
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) setNotes("");
onOpenChange(newOpen);
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Approve &amp; Merge</DialogTitle>
<DialogDescription>
Record why this work is approved for production. This note is the
permanent audit record for the merge and is required.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="ceo-approve-notes">Approval notes</Label>
<Textarea
id="ceo-approve-notes"
value={notes}
onChange={(e) => setNotes(e.target.value)}
placeholder="Verified against acceptance criteria; approving for production because..."
rows={4}
/>
<p className="text-xs text-muted-foreground">
{notes.trim().length}/{_CEO_NOTES_MIN} characters minimum
</p>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button onClick={handleConfirm} disabled={tooShort || isPending}>
{isPending ? "Approving..." : "Approve & Merge"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
// Required Notes Dialog — a generalized version of CeoApproveDialog. Collects a
// substantive audit note (>= minChars) before confirming a decision action.
interface RequiredNotesDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (text: string) => void;
isPending?: boolean;
title: string;
description: string;
label: string;
placeholder: string;
minChars: number;
confirmLabel: string;
destructive?: boolean;
}
export function RequiredNotesDialog({
open,
onOpenChange,
onConfirm,
isPending,
title,
description,
label,
placeholder,
minChars,
confirmLabel,
destructive,
}: RequiredNotesDialogProps) {
const [text, setText] = useState("");
const tooShort = text.trim().length < minChars;
const handleConfirm = () => {
if (!tooShort) {
onConfirm(text.trim());
setText("");
}
};
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) setText("");
onOpenChange(newOpen);
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
<DialogDescription>{description}</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="required-notes">{label}</Label>
<Textarea
id="required-notes"
value={text}
onChange={(e) => setText(e.target.value)}
placeholder={placeholder}
rows={4}
/>
<p className="text-xs text-muted-foreground">
{text.trim().length}/{minChars} characters minimum
</p>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button
variant={destructive ? "destructive" : "default"}
onClick={handleConfirm}
disabled={tooShort || isPending}
>
{isPending ? "Working..." : confirmLabel}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
// Create Branch Dialog
interface CreateBranchDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (branchType: string) => void;
isPending?: boolean;
taskId: string;
}
export function CreateBranchDialog({
open,
onOpenChange,
onConfirm,
isPending,
}: CreateBranchDialogProps) {
const [branchType, setBranchType] = useState("feature");
const handleConfirm = () => {
onConfirm(branchType);
};
// Reset branchType to 'feature' when dialog is dismissed without confirming
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) setBranchType("feature");
onOpenChange(newOpen);
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Create Branch</DialogTitle>
<DialogDescription>
Create a new branch for this task. The branch name will be generated automatically.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="branch-type">Branch Type</Label>
<Select value={branchType} onValueChange={setBranchType}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="feature">feature</SelectItem>
<SelectItem value="bug">bug</SelectItem>
<SelectItem value="chore">chore</SelectItem>
<SelectItem value="docs">docs</SelectItem>
<SelectItem value="hotfix">hotfix</SelectItem>
</SelectContent>
</Select>
<p className="text-xs text-muted-foreground">
Branch will be named: {branchType}/[team]/[task-id]
</p>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button onClick={handleConfirm} disabled={isPending}>
{isPending ? "Creating..." : "Create Branch"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
// Create PR Dialog
interface CreatePRDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (title: string, body: string) => void;
isPending?: boolean;
defaultTitle?: string;
}
export function CreatePRDialog({
open,
onOpenChange,
onConfirm,
isPending,
defaultTitle = "",
}: CreatePRDialogProps) {
const [title, setTitle] = useState(defaultTitle);
const [body, setBody] = useState("");
const handleConfirm = () => {
if (title.trim()) {
onConfirm(title.trim(), body.trim());
setTitle("");
setBody("");
}
};
// On open: seed title from defaultTitle. On close without confirming: reset both fields to empty.
const handleOpenChange = (newOpen: boolean) => {
if (newOpen) {
if (defaultTitle) setTitle(defaultTitle);
} else {
// Reset both fields when dismissed without confirming
setTitle("");
setBody("");
}
onOpenChange(newOpen);
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent className="sm:max-w-[525px]">
<DialogHeader>
<DialogTitle>Create Pull Request</DialogTitle>
<DialogDescription>
Create a pull request for this task&apos;s branch.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="pr-title">Title</Label>
<Input
id="pr-title"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="PR title..."
/>
</div>
<div className="grid gap-2">
<Label htmlFor="pr-body">Description</Label>
<Textarea
id="pr-body"
value={body}
onChange={(e) => setBody(e.target.value)}
placeholder="Describe the changes..."
rows={6}
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button onClick={handleConfirm} disabled={!title.trim() || isPending}>
{isPending ? "Creating..." : "Create PR"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}