"use client";
import type { ReactNode } from "react";
import type { WorkPackage } from "@/lib/work-package-types";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { WorkPackageOutputCard } from "@/components/WorkPackageOutput";
import { MarkdownContent } from "@/components/MarkdownContent";
import {
ArrowLeft,
CheckCircle2,
ClipboardCopy,
HelpCircle,
ListTodo,
LoaderCircle,
Play,
SlidersHorizontal,
} from "lucide-react";
import {
getWorkPackageVersion,
getWorkPackageVisualState,
} from "@/lib/work-package-ui";
import { buildPackageQuestionPrompt } from "@/lib/package-chat-context";
function statusLabel(status: WorkPackage["status"]) {
if (status === "todo") return "To do";
if (status === "in_progress") return "In progress";
return "Done";
}
function priorityLabel(priority: WorkPackage["priority"]) {
if (priority === "high") return "High";
if (priority === "medium") return "Medium";
return "Low";
}
function Section(props: {
title: string;
children: ReactNode;
action?: ReactNode;
}) {
return (
{props.title}
{props.action}
{props.children}
);
}
function createExcerpt(value: string, maxLength = 220) {
const normalized = value.trim().replace(/\s+/g, " ");
if (normalized.length <= maxLength) return normalized;
return `${normalized.slice(0, maxLength - 1).trimEnd()}...`;
}
function AskAboutButton(props: {
label: string;
onClick: () => void;
}) {
return (
);
}
export function WorkPackageDetail(props: {
workPackage?: WorkPackage;
activeWorkPackageId?: string;
onPrefill: (text: string) => void;
onBack: () => void;
}) {
const { workPackage: wp, activeWorkPackageId, onPrefill, onBack } = props;
if (!wp) {
return (
Select a work package to inspect its details.
);
}
const refName = wp.shortName || wp.title;
const latestOutput = wp.outputs.at(-1);
const visualState = getWorkPackageVisualState({
workPackage: wp,
activeWorkPackageId,
});
const version = getWorkPackageVersion(wp);
const latestOutputExcerpt = latestOutput ? createExcerpt(latestOutput.content) : "";
async function copyReference() {
try {
await navigator.clipboard.writeText(`@${refName} `);
} catch {
// ignore
}
}
return (
{wp.title}
Work package detail view
{wp.title}
{wp.shortName}
{statusLabel(wp.status)}
{priorityLabel(wp.priority)}
{wp.phase}
{visualState === "running" ? (
Running
) : null}
{visualState === "done" && version ? (
{version}
) : null}
{wp.objective}
onPrefill(
buildPackageQuestionPrompt({
packageRef: refName,
label: "objective",
excerpt: wp.objective,
}),
)
}
/>
{latestOutput ? (
{latestOutput.title}
{latestOutput.executionMode === "real"
? "LLM Automation"
: "Simulated Execution"}
{latestOutput.type}
onPrefill(
buildPackageQuestionPrompt({
packageRef: refName,
label: "output excerpt",
excerpt,
}),
)
}
/>
onPrefill(
buildPackageQuestionPrompt({
packageRef: refName,
label: "latest output",
excerpt: latestOutputExcerpt,
}),
)
}
/>
{latestOutput.disclaimer}
) : (
No output yet. Run the package to generate its primary artifact.
)}
{wp.outputs.length > 1 ? (
Output history
{wp.outputs
.slice(0, -1)
.reverse()
.map((output) => (
))}
) : null}
Package context
{wp.outputFiles.map((output) => (
{output}
))}
{wp.inputFiles.length ? (
{wp.inputFiles.join(", ")}
) : null}
{wp.coreSections.length ? (
{wp.coreSections.join(", ")}
) : null}
{wp.tasks.map((task) => (
{task.title}
onPrefill(
buildPackageQuestionPrompt({
packageRef: refName,
label: "task",
excerpt: `${task.title}: ${task.description}`,
}),
)
}
/>
{task.description}
))}
);
}