import type { EngineInterface, On } from 'claude-code' import type { AchillesStage } from '../types' import { ENDED, currentStage, isDisabled, readRuns, stageLine } from './context' // The Achilles pane: `/achilles` with no task opens it beside the chat. It draws the runs in // flight, their stages (done, current, to go), the experts at work and the last few that handed // back, the judge loop and selector scope, and the last hand-back, all from $.state, so a state // write redraws it. const MARK: Record = { completed: '✓', skipped: '–', blocked: '✗', failed: '✗' } const stageMark = (s: AchillesStage, cur: AchillesStage | undefined) => (s === cur ? '▸' : ENDED.has(s.status) ? (MARK[s.status] ?? '✓') : '·') const clock = (ms: number | undefined) => (ms === undefined ? '' : ` · since ${new Date(ms).toTimeString().slice(0, 5)}`) export const PANE = 'achilles' export async function rememberHandback($: EngineInterface, run: string, task: string, text: string) { await $.state.set({ plugin: 'achilles', key: 'handback' }, { run, task, text: text.slice(0, 2000) }) } export function registerPane(on: On) { on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => { const { Box, Text } = $.ui.resolve(e) const runs = await readRuns($) const { value: last } = await $.state.get({ plugin: 'achilles', key: 'handback' }) const width = Math.max(20, (e.props.bodyColumns ?? 60) - 2) const cut = (s: string) => (s.length > width ? `${s.slice(0, width - 1)}…` : s) return ( {isDisabled() && Achilles is switched off (ACHILLES_DISABLE=1).} {runs.length === 0 && No QA run in flight. Delegate one with /achilles <task>.} {runs.map(run => ( {cut(`${run.id} ${run.task}`)} {cut(`orchestrator ${run.agentId ?? 'starting'} · state ${run.dir}/`)} {stageLine(run) && {cut(` ${stageLine(run)}`)}} {(run.stages ?? []).map((s, i) => ( {cut(` ${stageMark(s, currentStage(run.stages))} ${s.name}${ENDED.has(s.status) && s.status !== 'completed' ? ` (${s.status})` : ''}`)} ))} {run.experts.length === 0 && no expert running} {run.experts.map(x => ( {cut(` ${x.role} ${x.agentId}${x.brief ? ` · ${x.brief}` : ''}${clock(x.since)}`)} ))} {(run.finished ?? []).slice(-3).map((f, i) => ( {cut(` handed back: ${f.role}${f.slug ? ` ${f.slug}` : ''} ${f.status}`)} ))} {run.judge && run.judge.consecutive > 0 && {` judge loop open ${run.judge.consecutive}/3`}} {run.selector && {cut(` selector ${run.selector.scope}: ${run.selector.steps.map(s => `${s.name}${s.status === 'fail' ? '✗' : ''}`).join(' → ')}`)}} ))} {last && ( {cut(`Last hand-back · ${last.run}`)} {last.text.split('\n').slice(0, 12).map((line, i) => ( {cut(line)} ))} )} ) }) }