Files
archie/ui/src/tasks/task-run.ts
T
sam f92c5b4536
ci/woodpecker/pr/quality Pipeline was successful
Quality / check (pull_request) Canceled after 7m39s
chore(runtime): delete Kit and external agent harness support (#1877)
Archie runs its own agent loop only. Removes Kit resolution and launch,
the harness runner and adapters, the setup terminal and sandbox view,
harness secrets and OAuth capture (table dropped in migration 0075), the
task-tools contract that only Kit containers reached, and the
sandbox-kit-spec dependency. Agent profiles carry image and tools only.
The egress proxy keeps the model-session path; the sandbox relay code
stays for #1867.
2026-11-12 21:29:05 +11:00

255 lines
7.2 KiB
TypeScript

/**
* The task run page's model: what the page can show, the shapes it reads from
* the daemon, and the URL contract that carries the open tab and the pinned
* attempt.
*
* One task id, one page. The id rides in the path and the view state (`tab`,
* `attempt`) rides in the query string, so every view of this page is a deep
* link that survives a reload -- /tasks/42?tab=changes&attempt=2.
*
* The attempt is the unit of every panel. Nothing here merges two attempts:
* the rail, the log, the capture and the config are all selected by attempt,
* and the two views of the same task's attempts (the selector and the rail)
* come from a single response.
*/
import type { LocationQuery, LocationQueryRaw } from "vue-router";
import type { LogEntry } from "@/lib/log";
export interface TaskRunTab {
id: string;
label: string;
}
/**
* The inspector's tabs. The stage rail is not one of them: it is the page's
* master pane, always visible, and selecting a stage commands the inspector
* to the log tab with that stage's filter set (docs/prds/task-run-master-detail.md).
*/
export const RUN_TABS: TaskRunTab[] = [
{ id: "log", label: "Log" },
{ id: "changes", label: "Changes" },
{ id: "debug", label: "Debug" },
];
const TAB_IDS = new Set(RUN_TABS.map((tab) => tab.id));
/** URL ids for tabs that were folded into another. */
const MOVED_TABS: Record<string, string> = { stages: "log", config: "debug" };
/** The task record as the task list serves it. */
export interface TaskRecord {
id: number | string;
title?: string;
body?: string;
source?: string;
status?: string;
workflow?: string;
owner?: string;
repo?: string;
repo_url?: string;
issue_number?: number;
issue_url?: string;
pr_number?: number;
pr_url?: string;
branch?: string;
retry_mode?: string;
park_reason?: string;
tokens_used?: number;
actions?: string[];
review_gate?: string;
plan?: string;
/** The structured plan (JSON) the plan text was rendered from. */
plan_document?: string;
/** What a task waiting for approval asks: "plan", "review", or "budget". */
approval?: string;
rereview_rounds?: number;
}
/** One stage of one attempt, as `GET /api/tasks/{id}/attempts` returns it. */
export interface Stage {
seq?: number;
name?: string;
status?: string;
duration_ms?: number;
error?: string;
/** The callee tasks this stage's workflow.call steps started. */
calls?: number[];
}
export interface Attempt {
attempt: number;
error?: string;
status?: string;
started_at?: string;
duration_ms?: number;
stages?: Stage[];
}
/**
* The run history. `current_attempt` is 0 on the wire for a task with no run
* at all, which is not an attempt number.
*/
export interface AttemptsState {
attempts?: Attempt[];
current_attempt?: number;
/** What the task was started with and what its current attempt wrote. */
inputs?: Record<string, unknown>;
outputs?: Record<string, unknown>;
/** The task whose workflow.call started this one. */
called_by?: number;
/** The linked runs of the same work item before and after this one. */
handed_off_from?: number;
handed_off_to?: number;
/** The page that fixes a parked task's blocker, when the viewer may act there. */
recovery?: { blocker: string; label: string; link: string };
}
/** One event off the task's stream, as much of it as this page reads. */
export interface TaskEvent {
kind?: string;
type?: string;
stage?: string;
workflow?: string;
attempt?: number;
at?: string;
detail?: string;
data?: Record<string, unknown>;
}
export interface LogFilters {
level: string;
stage: string;
}
/** The attempt log read's three outcomes: disabled, not found, or entries. */
export interface LogState {
found?: boolean;
disabled?: boolean;
attempt?: number;
entries?: LogEntry[];
/** Older entries were not examined: the file is larger than the scan window. */
truncated?: boolean;
/** Matching entries did not fit in this page; cursor continues the read. */
more_available?: boolean;
/** The byte-offset cursor to pass back as after_id for the next page. */
cursor?: number;
}
export interface CaptureFile {
path?: string;
old_path?: string;
status?: string;
binary?: boolean;
additions?: number;
deletions?: number;
}
export interface CaptureTotals {
files?: number;
additions?: number;
deletions?: number;
}
/** One recorded change capture for an attempt. */
export interface Capture {
captured_after?: string;
captured_at?: string;
stage?: string;
owner?: string;
repo?: string;
repo_url?: string;
branch?: string;
base?: string;
head_sha?: string;
pr_number?: number;
pr_url?: string;
totals?: CaptureTotals;
files?: CaptureFile[];
truncated?: boolean;
}
export interface ChangesState {
found?: boolean;
captures?: Capture[];
}
/** The stored task record and its events, verbatim: nothing here projects it. */
export type DebugState = Record<string, unknown>;
export function parseTaskId(raw: unknown): number | null {
const value = String(raw ?? "").trim();
if (!/^\d+$/.test(value)) return null;
const n = Number(value);
return Number.isSafeInteger(n) && n > 0 ? n : null;
}
export function initialTab(query: LocationQuery | undefined): string {
const requested = String(query?.tab ?? "");
if (MOVED_TABS[requested]) return MOVED_TABS[requested];
return TAB_IDS.has(requested) ? requested : RUN_TABS[0].id;
}
/**
* `?attempt=2` pins attempt 2. An absent, empty or non-numeric value follows
* whatever the server reports as current, and 0 is the wire's own spelling of
* "the current attempt" (taskLogTarget, internal/webui/api_tasks_logs.go), so
* it selects the current attempt rather than a nonexistent attempt 0.
*/
export function initialAttempt(
query: LocationQuery | undefined,
): number | null {
const raw = query?.attempt;
if (raw == null || raw === "") return null;
const n = Number(raw);
return Number.isInteger(n) && n > 0 ? n : null;
}
/** The query string a tab and an attempt are addressed by. */
export function runQuery(
tab: string,
attempt: number | null,
): LocationQueryRaw {
const query: LocationQueryRaw = { tab: tab || RUN_TABS[0].id };
if (attempt) query.attempt = String(attempt);
return query;
}
export function attemptKey(id: number, attempt: number | null): string {
return `${id}|${Number(attempt) || 0}`;
}
export const EMPTY_LOG_FILTERS: LogFilters = { level: "", stage: "" };
/**
* The identity of a log read: a task, an attempt, and the filters that produced
* the response. Keying by task alone cannot represent two attempts, and keying
* without the filters would serve attempt 2's unfiltered log in answer to a
* filtered request.
*/
export function logCacheKey(
id: number,
attempt: number | null,
filters: LogFilters = EMPTY_LOG_FILTERS,
): string {
const applied = filters || EMPTY_LOG_FILTERS;
return [
id,
Number(attempt) || 0,
applied.level || "",
applied.stage || "",
].join("|");
}
/** A plan written as structured fields; the server renders the plan text from it. */
export interface PlanDocument {
title?: string;
problem: string;
solution: string;
files?: { path: string; change: string; note?: string }[];
acceptance?: string[];
non_goals?: string[];
diff_estimate?: string;
risks?: string[];
}