@nandoblanco/opencode-relay-orchestration 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +136 -0
- package/LICENSE +21 -0
- package/README.md +312 -2
- package/assets/screenshot-tui.png +0 -0
- package/assets/screenshot.png +0 -0
- package/dist/gui-experimental.cjs +1 -0
- package/package.json +83 -4
- package/src/config.ts +77 -0
- package/src/gui.css +826 -0
- package/src/gui.tsx +394 -0
- package/src/index.ts +1 -0
- package/src/model.ts +58 -0
- package/src/orchestrator.ts +329 -0
- package/src/planner.ts +201 -0
- package/src/report.ts +35 -0
- package/src/rpc.ts +65 -0
- package/src/scope.ts +116 -0
- package/src/server.ts +449 -0
- package/src/store.ts +300 -0
- package/src/tui.ts +413 -0
- package/src/verify.ts +82 -0
- package/src/view.ts +124 -0
package/src/gui.tsx
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { Plugin, Panel, Command, Style, type Context as PluginContext } from '@opencode/plugin/gui'
|
|
2
|
+
import { createEffect, createSignal, createMemo, onCleanup, untrack, For, Show } from 'solid-js'
|
|
3
|
+
import { RelayRpc, type RelayApi } from './rpc.ts'
|
|
4
|
+
import { isFinalTask, checkScope, type RecordInfo, type Status, type Op, type Owner, type RunInfo, type Check, type Evidence } from './model.ts'
|
|
5
|
+
import { recordView, visibleError, approvalMessage, pendingMessage, signOffMessage, signOffError } from './view.ts'
|
|
6
|
+
import css from './gui.css?inline'
|
|
7
|
+
import { type ConfigReport, type RoleCheck } from './config.ts'
|
|
8
|
+
import { checkView, evidenceView, canRecordManual, evidenceTitle } from './view.ts'
|
|
9
|
+
import { auditSummary } from './report.ts'
|
|
10
|
+
|
|
11
|
+
function roleState(role: RoleCheck) {
|
|
12
|
+
if (role.errors.length || role.image === 'failed' || role.image === 'error') return 'invalid'
|
|
13
|
+
if (!role.model) return 'missing'
|
|
14
|
+
return 'valid'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function evidenceState(label: string, manual?: boolean) {
|
|
18
|
+
if (manual) return 'manual'
|
|
19
|
+
if (label.startsWith('Passed')) return 'passed'
|
|
20
|
+
if (label.startsWith('Failed')) return 'failed'
|
|
21
|
+
if (label.startsWith('Deferred') || label.startsWith('Not applicable')) return 'deferred'
|
|
22
|
+
return 'unverified'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function RelayPanel(props: { ctx: PluginContext }) {
|
|
26
|
+
const [record, setRecord] = createSignal<RecordInfo>()
|
|
27
|
+
const [runs, setRuns] = createSignal<RunInfo[]>([])
|
|
28
|
+
const [evidence, setEvidence] = createSignal<Evidence[]>([])
|
|
29
|
+
const [checkName, setCheckName] = createSignal('')
|
|
30
|
+
const [checkCommand, setCheckCommand] = createSignal('')
|
|
31
|
+
const [checkAdapter, setCheckAdapter] = createSignal<Check['adapter']>('command')
|
|
32
|
+
const [checkPolicy, setCheckPolicy] = createSignal<Check['policy']>('automated-required')
|
|
33
|
+
const [checkScopeValue, setCheckScopeValue] = createSignal<'task' | 'final'>('task')
|
|
34
|
+
const [checkReason, setCheckReason] = createSignal('')
|
|
35
|
+
const [signing, setSigning] = createSignal(false)
|
|
36
|
+
const [signingRevision, setSigningRevision] = createSignal(0)
|
|
37
|
+
const [records, setRecords] = createSignal<RecordInfo[]>([])
|
|
38
|
+
const [error, setError] = createSignal('')
|
|
39
|
+
let errorBanner: HTMLDivElement | undefined
|
|
40
|
+
const [refreshError, setRefreshError] = createSignal('')
|
|
41
|
+
createEffect(() => { if (error() || refreshError()) queueMicrotask(() => { errorBanner?.scrollIntoView({ block: 'nearest' }); errorBanner?.focus({ preventScroll: true }) }) })
|
|
42
|
+
const [busy, setBusy] = createSignal(false)
|
|
43
|
+
const [approving, setApproving] = createSignal(false)
|
|
44
|
+
const [approvalRevision, setApprovalRevision] = createSignal(0)
|
|
45
|
+
const connected = () => Boolean(props.ctx.sessions.current()?.location && props.ctx.sessions.current()?.server.connected)
|
|
46
|
+
let creationDetails: HTMLDetailsElement | undefined
|
|
47
|
+
const [title, setTitle] = createSignal('')
|
|
48
|
+
const [taskTitle, setTaskTitle] = createSignal('')
|
|
49
|
+
const [taskScope, setTaskScope] = createSignal('')
|
|
50
|
+
const [interruptReason, setInterruptReason] = createSignal('')
|
|
51
|
+
const [config, setConfig] = createSignal<ConfigReport>()
|
|
52
|
+
const [configBusy, setConfigBusy] = createSignal(false)
|
|
53
|
+
const [configError, setConfigError] = createSignal('')
|
|
54
|
+
const [configNotice, setConfigNotice] = createSignal('')
|
|
55
|
+
const [audit, setAudit] = createSignal<string[]>([])
|
|
56
|
+
const [auditError, setAuditError] = createSignal('')
|
|
57
|
+
const [exportStatus, setExportStatus] = createSignal('')
|
|
58
|
+
const [exportBusy, setExportBusy] = createSignal(false)
|
|
59
|
+
let auditDetails: HTMLDetailsElement | undefined
|
|
60
|
+
async function loadAudit() {
|
|
61
|
+
const current = record(); if (!current) return
|
|
62
|
+
const key = props.ctx.sessions.current()?.key
|
|
63
|
+
setAuditError(''); setExportStatus('')
|
|
64
|
+
try {
|
|
65
|
+
const { api, options } = target()
|
|
66
|
+
const related = current.sessionID ? records().filter(item => item.sessionID === current.sessionID) : [current]
|
|
67
|
+
const summaries = await Promise.all((related.length ? related : [current]).map(async item => auditSummary(item, await api.listRuns({ recordID: item.id }, options))))
|
|
68
|
+
if (key === props.ctx.sessions.current()?.key && current.id === record()?.id) setAudit(summaries)
|
|
69
|
+
} catch { if (key === props.ctx.sessions.current()?.key) setAuditError('Could not load audit. Close and reopen Audit to retry.') }
|
|
70
|
+
}
|
|
71
|
+
async function exportReport(copy = false) {
|
|
72
|
+
const current = record(); if (!current || exportBusy()) return
|
|
73
|
+
const key = props.ctx.sessions.current()?.key
|
|
74
|
+
setExportBusy(true); setExportStatus(''); setAuditError('')
|
|
75
|
+
try {
|
|
76
|
+
const { api, options } = target()
|
|
77
|
+
const report = await api.exportReport({ recordID: current.id }, options)
|
|
78
|
+
if (key !== props.ctx.sessions.current()?.key || current.id !== record()?.id) return
|
|
79
|
+
if (copy) { await props.ctx.system.copy(report.markdown); setExportStatus('Copied') }
|
|
80
|
+
else setExportStatus(await props.ctx.system.save({ name: report.name, content: report.markdown }) ? 'Report saved' : 'Save cancelled')
|
|
81
|
+
} catch (failure) { if (key === props.ctx.sessions.current()?.key) setAuditError(visibleError(failure) === 'Could not write report file.' ? 'Could not write report file.' : copy ? 'Could not copy report.' : 'Could not export report.') }
|
|
82
|
+
finally { if (key === props.ctx.sessions.current()?.key) setExportBusy(false) }
|
|
83
|
+
}
|
|
84
|
+
const canProbe = () => config()?.enableProbe && config()?.roles.some(role => role.role === 'reviewer' && role.model && !role.errors.length)
|
|
85
|
+
// Automatic loads retry after 0.5 s, 1 s and 2 s because the server can briefly reject plugin
|
|
86
|
+
// RPC while it reloads plugins. Manual actions report failures immediately.
|
|
87
|
+
let epoch = 0
|
|
88
|
+
async function checkConfig(probe = false, retry = 0, notify = false) {
|
|
89
|
+
if (configBusy()) return
|
|
90
|
+
setConfigBusy(true); setConfigError('')
|
|
91
|
+
if (notify) setConfigNotice('')
|
|
92
|
+
const key = props.ctx.sessions.current()?.key
|
|
93
|
+
const token = epoch
|
|
94
|
+
try {
|
|
95
|
+
const { api, options, session } = target()
|
|
96
|
+
const result = probe ? await api.probeImage({ parentSessionID: session.id }, options) : await api.validateConfig({}, options)
|
|
97
|
+
if (key === props.ctx.sessions.current()?.key) {
|
|
98
|
+
setConfig(result)
|
|
99
|
+
if (notify) {
|
|
100
|
+
const issues = result.errors.length + result.roles.reduce((sum, role) => sum + role.errors.length, 0)
|
|
101
|
+
setConfigNotice(issues ? `Checked at ${new Date().toLocaleTimeString()} · ${issues} issue${issues === 1 ? '' : 's'}` : `Validated at ${new Date().toLocaleTimeString()}`)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (failure) {
|
|
106
|
+
if (key !== props.ctx.sessions.current()?.key) return
|
|
107
|
+
console.warn('Relay config check failed', failure)
|
|
108
|
+
if (retry && retry <= 2000) setTimeout(() => { if (token === epoch) void checkConfig(false, retry * 2) }, retry)
|
|
109
|
+
else setConfigError(probe ? 'Could not run the image probe. Check reviewer validation and try again only when authorized.' : 'Could not validate role configuration. Use Validate config to retry.')
|
|
110
|
+
}
|
|
111
|
+
finally { if (key === props.ctx.sessions.current()?.key) setConfigBusy(false) }
|
|
112
|
+
}
|
|
113
|
+
const view = createMemo(() => recordView(record(), runs()))
|
|
114
|
+
const serverPending = () => Boolean(record()?.pendingApproval && record()?.pendingApproval?.revision === record()?.revision)
|
|
115
|
+
const doneCount = () => view().tasks.filter(task => task.status === 'completed').length
|
|
116
|
+
let generation = 0
|
|
117
|
+
function target() {
|
|
118
|
+
const session = props.ctx.sessions.current()
|
|
119
|
+
if (!session?.location || !session.server.connected) throw new Error('Current session server is unavailable. Reconnect, then refresh.')
|
|
120
|
+
return { session, api: session.server.client.rpc(RelayRpc) as unknown as RelayApi, options: { location: session.location } }
|
|
121
|
+
}
|
|
122
|
+
async function refresh(clearError = false, retry = 0) {
|
|
123
|
+
if (clearError) setError('')
|
|
124
|
+
const token = ++generation
|
|
125
|
+
try {
|
|
126
|
+
const { session, api, options } = target()
|
|
127
|
+
const all = (await api.listRecords({}, options)).filter(item => item.location.directory === session.location!.directory)
|
|
128
|
+
const current = record()
|
|
129
|
+
const chosen = all.find(item => item.id === current?.id) ?? all.find(item => item.sessionID === session.id) ?? all[0]
|
|
130
|
+
const snapshot = chosen ? await api.getSnapshot({ recordID: chosen.id }, options) : undefined
|
|
131
|
+
const runList = snapshot ? await api.listRuns({ recordID: snapshot.id }, options) : []
|
|
132
|
+
const evidenceList = snapshot ? await api.listEvidence({ id: snapshot.id }, options) : []
|
|
133
|
+
if (token === generation) { setRecords(all); setRecord(snapshot); setRuns(runList); setEvidence(evidenceList); setRefreshError(''); if (auditDetails?.open) void loadAudit() }
|
|
134
|
+
} catch (failure) {
|
|
135
|
+
if (token !== generation) return
|
|
136
|
+
console.warn('Relay refresh failed', failure)
|
|
137
|
+
if (retry && retry <= 2000) setTimeout(() => { if (token === generation) void refresh(false, retry * 2) }, retry)
|
|
138
|
+
else setRefreshError('Could not refresh. Use Refresh to retry.')
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function run(work: (api: RelayApi, options: object, sessionID: string) => Promise<RecordInfo>, requestApproval = false) {
|
|
142
|
+
if (requestApproval ? approving() : busy()) return false
|
|
143
|
+
if (requestApproval) { setApproving(true); setApprovalRevision(record()!.revision) } else setBusy(true)
|
|
144
|
+
setError(''); setRefreshError('')
|
|
145
|
+
const sessionKey = props.ctx.sessions.current()?.key
|
|
146
|
+
try {
|
|
147
|
+
const { session, api, options } = target()
|
|
148
|
+
const result = await work(api, options, session.id)
|
|
149
|
+
if (props.ctx.sessions.current()?.key !== sessionKey) return false
|
|
150
|
+
setRecord(result)
|
|
151
|
+
await refresh()
|
|
152
|
+
return true
|
|
153
|
+
} catch (failure) {
|
|
154
|
+
if (props.ctx.sessions.current()?.key !== sessionKey) return false
|
|
155
|
+
await refresh(false)
|
|
156
|
+
setError(visibleError(failure, record(), requestApproval))
|
|
157
|
+
return false
|
|
158
|
+
} finally { if (props.ctx.sessions.current()?.key === sessionKey) { if (requestApproval) setApproving(false); else setBusy(false) } }
|
|
159
|
+
}
|
|
160
|
+
function mutate(op: Op) {
|
|
161
|
+
const current = record()
|
|
162
|
+
if (current) return run((api, options, sessionID) => op.type === 'complete' ? api.signOff({ recordID: current.id, expectedRevision: current.revision, sessionID }, options) : api.mutate({ recordID: current.id, expectedRevision: current.revision, op }, options))
|
|
163
|
+
}
|
|
164
|
+
async function signOff() {
|
|
165
|
+
const current = record()
|
|
166
|
+
if (!current || !view().canSignOff || signing()) return
|
|
167
|
+
const key = props.ctx.sessions.current()?.key
|
|
168
|
+
setSigning(true); setSigningRevision(current.revision); setError('')
|
|
169
|
+
try {
|
|
170
|
+
const { api, options, session } = target()
|
|
171
|
+
const result = await api.signOff({ recordID: current.id, expectedRevision: current.revision, sessionID: session.id }, options)
|
|
172
|
+
if (key !== props.ctx.sessions.current()?.key || current.id !== record()?.id) return
|
|
173
|
+
setRecord(result); await refresh()
|
|
174
|
+
} catch (failure) {
|
|
175
|
+
if (key !== props.ctx.sessions.current()?.key || current.id !== record()?.id) return
|
|
176
|
+
await refresh(); setError(signOffError(failure))
|
|
177
|
+
} finally { if (key === props.ctx.sessions.current()?.key) setSigning(false) }
|
|
178
|
+
}
|
|
179
|
+
createEffect(() => {
|
|
180
|
+
const session = props.ctx.sessions.current()
|
|
181
|
+
const location = session?.location
|
|
182
|
+
const connected = session?.server.connected
|
|
183
|
+
const client = session?.server.client
|
|
184
|
+
generation++; epoch++; setRecord(undefined); setRecords([]); setError(''); setRefreshError(''); setBusy(false); setApproving(false); setTitle(''); setTaskTitle(''); setInterruptReason(''); setConfig(undefined); setConfigBusy(false); setConfigError(''); setConfigNotice('')
|
|
185
|
+
setAudit([]); setAuditError(''); setExportStatus(''); setExportBusy(false)
|
|
186
|
+
setRuns([]); setEvidence([]); setCheckName(''); setCheckCommand(''); setCheckReason(''); setCheckAdapter('command'); setCheckPolicy('automated-required'); setCheckScopeValue('task'); setSigning(false)
|
|
187
|
+
if (!location || !connected || !client) { setError('Select a connected session to view relay records.'); return }
|
|
188
|
+
// Snapshot on mount, location change and reconnection. Every matching event triggers
|
|
189
|
+
// a full snapshot, which also covers revision gaps in this live-only event stream.
|
|
190
|
+
const off = client.rpc(RelayRpc).events.on('changed', event => {
|
|
191
|
+
if (event.location.directory === location.directory) void refresh()
|
|
192
|
+
})
|
|
193
|
+
void refresh(false, 500)
|
|
194
|
+
untrack(() => { void checkConfig(false, 500) })
|
|
195
|
+
onCleanup(() => { off(); generation++; epoch++ })
|
|
196
|
+
})
|
|
197
|
+
return <section class="relay-panel" data-appearance={props.ctx.appearance?.mode()} aria-busy={busy()} aria-label="Relay status">
|
|
198
|
+
<header class="relay-header">
|
|
199
|
+
<div class="relay-header-title">
|
|
200
|
+
<h2>Relay</h2>
|
|
201
|
+
<Show when={record()}><span class="relay-phase-dot" data-phase={record()!.phase} aria-hidden="true" /></Show>
|
|
202
|
+
</div>
|
|
203
|
+
<button type="button" class="relay-btn-sm" disabled={busy()} onClick={() => { void refresh(true); void checkConfig() }}>Refresh</button>
|
|
204
|
+
</header>
|
|
205
|
+
<Show when={error() || refreshError()}><div ref={errorBanner} tabindex="-1" class="relay-error" role="alert"><Show when={error()}><p>{error()}</p></Show><Show when={refreshError()}><p>{refreshError()}</p></Show></div></Show>
|
|
206
|
+
<Show when={pendingMessage(record()) || approving()}>
|
|
207
|
+
<div class="relay-banner relay-banner-warn">
|
|
208
|
+
<p role="status">{pendingMessage(record()) || `Waiting for approval of revision ${approvalRevision()}`}</p>
|
|
209
|
+
<Show when={record()?.pendingApproval}><button type="button" class="relay-btn-sm" disabled={busy()} onClick={() => { const current = record()!; void run((api, options) => api.withdrawApproval({ recordID: current.id, key: current.pendingApproval!.key }, options)) }}>Withdraw approval request</button></Show>
|
|
210
|
+
</div>
|
|
211
|
+
</Show>
|
|
212
|
+
<Show when={approvalMessage(record())}><p class="relay-banner" classList={{ 'relay-banner-ok': record()?.approvalResult?.outcome === 'approved', 'relay-banner-warn': record()?.approvalResult?.outcome !== 'approved' }} role="status">{approvalMessage(record())}</p></Show>
|
|
213
|
+
<Show when={records().length > 1}><label class="relay-picker"><span>Record</span><select value={record()?.id} onChange={event => { setRuns([]); setEvidence([]); setSigning(false); setRecord(records().find(item => item.id === event.currentTarget.value)); void refresh(true) }}><For each={records()}>{item => <option value={item.id}>{item.title}</option>}</For></select></label></Show>
|
|
214
|
+
<div class="relay-hero">
|
|
215
|
+
<Show when={record()} fallback={<><h3 class="relay-record-title">{view().title}</h3><p class="relay-meta">{connected() ? 'Create a record to track tasks. Nothing starts automatically.' : 'Reconnect the selected session to load its records.'}</p></>}>
|
|
216
|
+
<div class="relay-hero-meta">
|
|
217
|
+
<span class="relay-pill relay-phase" data-phase={record()!.phase}>{view().phase}</span>
|
|
218
|
+
<span class="relay-chip relay-mono">{view().revision}</span>
|
|
219
|
+
<Show when={view().tasks.length}><span class="relay-chip">{doneCount()}/{view().tasks.length} done</span></Show>
|
|
220
|
+
</div>
|
|
221
|
+
<h3 class="relay-record-title">{view().title}</h3>
|
|
222
|
+
<p class="relay-location">{view().location}</p>
|
|
223
|
+
<Show when={view().reason}><p class="relay-banner relay-banner-warn" role="status">{view().reason}</p></Show>
|
|
224
|
+
<Show when={signing()}><p class="relay-banner relay-banner-warn" role="status">{signOffMessage(signingRevision())}</p></Show>
|
|
225
|
+
<div class="relay-metrics">
|
|
226
|
+
<p class="relay-meta">{view().tokens}</p>
|
|
227
|
+
<Show when={view().plannerTokens}><p class="relay-meta">{view().plannerTokens}</p></Show>
|
|
228
|
+
</div>
|
|
229
|
+
<Show when={view().actions.some(action => action !== 'interrupt' && action !== 'complete') || view().canSignOff}>
|
|
230
|
+
<div class="relay-actions">
|
|
231
|
+
<For each={view().actions.filter(action => action !== 'interrupt' && action !== 'complete')}>{action => <button type="button" classList={{ 'relay-btn-primary': action === 'start' || action === 'resume', 'relay-btn-subtle': action === 'cancel' }} disabled={busy()} onClick={() => mutate({ type: action })}>{action[0].toUpperCase() + action.slice(1)}</button>}</For>
|
|
232
|
+
<Show when={view().canSignOff}><button type="button" class="relay-btn-primary" disabled={busy() || signing()} onClick={() => { void signOff() }}>Sign off</button></Show>
|
|
233
|
+
</div>
|
|
234
|
+
</Show>
|
|
235
|
+
<Show when={view().actions.includes('interrupt')}><form class="relay-interrupt-form" onSubmit={async event => { event.preventDefault(); if (!interruptReason().trim()) return; if (await mutate({ type: 'interrupt', reason: interruptReason().trim() })) setInterruptReason('') }}>
|
|
236
|
+
<label>Interrupt reason<input maxLength={500} value={interruptReason()} onInput={event => setInterruptReason(event.currentTarget.value)} required /></label><button disabled={busy() || !interruptReason().trim()}>Interrupt</button>
|
|
237
|
+
</form></Show>
|
|
238
|
+
</Show>
|
|
239
|
+
</div>
|
|
240
|
+
<Show when={record()}>
|
|
241
|
+
<section class="relay-section" aria-label="Tasks">
|
|
242
|
+
<div class="relay-section-head">
|
|
243
|
+
<h3>Tasks</h3>
|
|
244
|
+
<Show when={view().tasks.length}><span class="relay-count">{view().tasks.length}</span></Show>
|
|
245
|
+
</div>
|
|
246
|
+
<Show when={record()?.phase === 'running'}><p class="relay-hint">Task status and owner are managed by Relay while running. Interrupt to edit.</p></Show>
|
|
247
|
+
<Show when={view().tasks.length} fallback={<p class="relay-meta">No tasks yet.</p>}>
|
|
248
|
+
<ul class="relay-tasks"><For each={view().tasks}>{task => {
|
|
249
|
+
const [expanded, setExpanded] = createSignal(false)
|
|
250
|
+
const isLong = () => task.title.length > 160
|
|
251
|
+
return <li class="relay-task-card" data-status={task.status}>
|
|
252
|
+
<div class="relay-task-head">
|
|
253
|
+
<p class="relay-stage" data-stage={task.stage.toLowerCase().replace(/\s+/g, '-')}>{task.stage}{task.attempt ? ` · Attempt ${task.attempt}` : ''}</p>
|
|
254
|
+
<span class="relay-meta">Fix cycles: {task.fixCycles}</span>
|
|
255
|
+
</div>
|
|
256
|
+
<p class="relay-task-title" classList={{ 'relay-clamped': isLong() && !expanded() }}>{task.title}</p>
|
|
257
|
+
<Show when={isLong()}><button type="button" class="relay-link-btn" onClick={() => setExpanded(prev => !prev)}>{expanded() ? 'Show less' : 'Show full prompt'}</button></Show>
|
|
258
|
+
<Show when={task.scope}><p class="relay-chip relay-mono relay-scope">{task.scope}</p></Show>
|
|
259
|
+
<Show when={task.summary}><div class="relay-report-box"><p class="relay-report" title={task.summary}>{task.summary}</p></div></Show>
|
|
260
|
+
<Show when={task.findings || task.checks}>
|
|
261
|
+
<div class="relay-task-signals">
|
|
262
|
+
<Show when={task.findings}><p class="relay-signal" classList={{ 'relay-signal-warn': !task.findings.includes('(0 major)') }}>{task.findings}</p></Show>
|
|
263
|
+
<Show when={task.checks}><p class="relay-signal" classList={{ 'relay-signal-warn': task.checks.includes('failed') }}>{task.checks}</p></Show>
|
|
264
|
+
</div>
|
|
265
|
+
</Show>
|
|
266
|
+
<div class="relay-task-controls">
|
|
267
|
+
<label>Status<select value={task.status} disabled={busy() || !view().canEdit} onChange={event => mutate({ type: 'setTaskStatus', taskID: task.id, status: event.currentTarget.value as Status })}>
|
|
268
|
+
<For each={['pending', 'running', 'blocked', 'awaiting_approval', 'completed']}>{status => <option value={status} disabled={status === 'running' && (record()?.phase !== 'running' || !task.owner || task.status === 'running')}>{status.replaceAll('_', ' ')}</option>}</For>
|
|
269
|
+
</select></label>
|
|
270
|
+
<label>Owner role<select value={task.owner?.role ?? ''} aria-describedby={task.status === 'running' ? `relay-owner-${task.id}` : undefined} disabled={busy() || !view().canEdit || task.status === 'running'} onChange={event => { if (event.currentTarget.value) void mutate({ type: 'assignTask', taskID: task.id, owner: { role: event.currentTarget.value as Owner['role'] } }) }}>
|
|
271
|
+
<option value="" disabled>Unassigned</option><For each={['planner', 'builder', 'reviewer']}>{role => <option value={role}>{role}</option>}</For>
|
|
272
|
+
</select></label>
|
|
273
|
+
</div>
|
|
274
|
+
<Show when={task.status === 'running' || task.owner?.sessionID}>
|
|
275
|
+
<div class="relay-task-foot">
|
|
276
|
+
<Show when={task.status === 'running'}><p id={`relay-owner-${task.id}`} class="relay-meta">Owner is locked while the task is running</p></Show>
|
|
277
|
+
<Show when={task.owner?.sessionID}><p class="relay-meta relay-mono">Owner session: {task.owner!.sessionID}</p></Show>
|
|
278
|
+
</div>
|
|
279
|
+
</Show>
|
|
280
|
+
</li>
|
|
281
|
+
}}</For></ul>
|
|
282
|
+
</Show>
|
|
283
|
+
<Show when={view().canAdd}><div class="relay-form-card"><form onSubmit={async event => { event.preventDefault(); const paths = taskScope().split(',').map(item => item.trim()).filter(Boolean); if (!busy() && taskTitle().trim() && await mutate({ type: 'addTask', title: taskTitle(), ...(paths.length ? { allowedPaths: paths } : {}) })) { setTaskTitle(''); setTaskScope('') } }}>
|
|
284
|
+
<div class="relay-form-grid">
|
|
285
|
+
<label>Task title<input value={taskTitle()} onInput={event => setTaskTitle(event.currentTarget.value)} required /></label>
|
|
286
|
+
<label>Allowed paths (optional)<input placeholder="src/app.ts, src/styles/**" value={taskScope()} onInput={event => setTaskScope(event.currentTarget.value)} /></label>
|
|
287
|
+
</div>
|
|
288
|
+
<button disabled={busy()}>Add task</button>
|
|
289
|
+
</form></div></Show>
|
|
290
|
+
</section>
|
|
291
|
+
<section class="relay-verification" aria-label="Verification">
|
|
292
|
+
<div class="relay-section-head">
|
|
293
|
+
<h3>Verification</h3>
|
|
294
|
+
<Show when={record()!.checks.length}><span class="relay-count">{record()!.checks.length}</span></Show>
|
|
295
|
+
</div>
|
|
296
|
+
<Show when={record()!.checks.length} fallback={<p class="relay-meta">No verification checks.</p>}>
|
|
297
|
+
<ul><For each={record()!.checks}>{check => <li class="relay-check-card">
|
|
298
|
+
<div class="relay-check-head">
|
|
299
|
+
<p class="relay-check-name"><strong>{check.name}</strong></p>
|
|
300
|
+
<p class="relay-chip">{check.policy === 'not-applicable' ? checkView(check).label : `Policy: ${check.policy}${checkScope(check) === 'final' ? ' · Final gate' : ''}`}</p>
|
|
301
|
+
</div>
|
|
302
|
+
<p class="relay-code">{check.adapter}: {check.command}</p>
|
|
303
|
+
<Show when={record()!.phase === 'draft'}><div class="relay-actions"><button type="button" class="relay-btn-sm relay-btn-subtle" disabled={busy()} onClick={() => mutate({ type: 'removeCheck', checkID: check.id })}>Remove {check.name}</button></div></Show>
|
|
304
|
+
<For each={check.policy === 'not-applicable' ? [] : record()!.tasks}>{task => {
|
|
305
|
+
const latest = () => evidence().findLast(item => item.taskID === task.id && item.checkID === check.id)
|
|
306
|
+
const item = () => evidenceView(check, latest(), runs(), checkScope(check) === 'final' && !isFinalTask(record()!, task.id))
|
|
307
|
+
const [note, setNote] = createSignal('')
|
|
308
|
+
return <div class="relay-evidence" data-state={evidenceState(item().label, item().manual)} classList={{ 'relay-evidence-manual': item().manual }}>
|
|
309
|
+
<p title={task.title}>{evidenceTitle(task.title)}: {item().label}</p>
|
|
310
|
+
<Show when={item().screenshots}><p class="relay-meta">{item().screenshots}</p></Show>
|
|
311
|
+
<Show when={canRecordManual(record()!, task.id, check, evidence(), runs())}><form onSubmit={async event => { event.preventDefault(); const current = record()!; if (note().trim() && await run((api, options, sessionID) => api.recordManual({ id: current.id, revision: current.revision, taskID: task.id, checkID: check.id, note: note().trim(), sessionID }, options))) setNote('') }}><label>Manual verification note<input maxLength={1000} required value={note()} onInput={event => setNote(event.currentTarget.value)} /></label><button disabled={busy() || !note().trim()}>Record manual verification</button></form></Show>
|
|
312
|
+
</div>
|
|
313
|
+
}}</For>
|
|
314
|
+
</li>}</For></ul>
|
|
315
|
+
</Show>
|
|
316
|
+
<Show when={record()!.phase === 'draft'}><div class="relay-form-card"><form onSubmit={async event => { event.preventDefault(); if (await mutate({ type: 'addCheck', check: { id: crypto.randomUUID(), name: checkName().trim(), command: checkCommand().trim(), adapter: checkAdapter(), policy: checkPolicy(), ...(checkScopeValue() === 'final' ? { scope: 'final' } : {}), ...(checkPolicy() === 'not-applicable' ? { reason: checkReason().trim() } : {}) } })) { setCheckName(''); setCheckCommand(''); setCheckReason(''); setCheckScopeValue('task') } }}>
|
|
317
|
+
<div class="relay-form-grid">
|
|
318
|
+
<label>Check name<input maxLength={120} required value={checkName()} onInput={event => setCheckName(event.currentTarget.value)} /></label>
|
|
319
|
+
<label>Check command<input maxLength={160} required value={checkCommand()} onInput={event => setCheckCommand(event.currentTarget.value)} /></label>
|
|
320
|
+
</div>
|
|
321
|
+
<div class="relay-form-grid">
|
|
322
|
+
<label>Adapter<select value={checkAdapter()} onChange={event => setCheckAdapter(event.currentTarget.value as Check['adapter'])}><option value="command">Command</option><option value="playwright">Playwright</option></select></label>
|
|
323
|
+
<label>Verification policy<select value={checkPolicy()} onChange={event => setCheckPolicy(event.currentTarget.value as Check['policy'])}><option value="automated-required">Automated required</option><option value="manual-allowed">Manual allowed</option><option value="not-applicable">Not applicable</option></select></label>
|
|
324
|
+
<label>Check scope<select value={checkScopeValue()} onChange={event => setCheckScopeValue(event.currentTarget.value as 'task' | 'final')}><option value="task">Each task</option><option value="final">Final gate</option></select></label>
|
|
325
|
+
</div>
|
|
326
|
+
<Show when={checkPolicy() === 'not-applicable'}><label>Not applicable reason<input maxLength={500} required value={checkReason()} onInput={event => setCheckReason(event.currentTarget.value)} /></label></Show>
|
|
327
|
+
<p class="relay-meta">Commands run in the record directory with plugin privileges after plan approval. Playwright writes PNGs to .screenshots/.</p>
|
|
328
|
+
<button disabled={busy()}>Add check</button>
|
|
329
|
+
</form></div></Show>
|
|
330
|
+
</section>
|
|
331
|
+
<section class="relay-section" aria-label="Approvals">
|
|
332
|
+
<div class="relay-section-head"><h3>Approvals</h3></div>
|
|
333
|
+
<Show when={view().approvals.length} fallback={<p class="relay-meta">No plan approvals.</p>}><ul class="relay-approvals"><For each={view().approvals}>{approval => <li>{approval}</li>}</For></ul></Show>
|
|
334
|
+
<Show when={view().canApprove}><button type="button" class="relay-btn-primary" disabled={busy() || approving() || serverPending()} onClick={async () => { if (busy() || approving() || serverPending()) return; const current = record()!; await run((api, options, sessionID) => api.requestApproval({ recordID: current.id, expectedRevision: current.revision, kind: 'plan', sessionID }, options), true) }}>Request plan approval</button></Show>
|
|
335
|
+
</section>
|
|
336
|
+
<details ref={auditDetails} class="relay-audit" onToggle={event => { if (event.currentTarget.open) void loadAudit() }}><summary>Audit</summary>
|
|
337
|
+
<div class="relay-audit-body">
|
|
338
|
+
<Show when={audit().length}><ul class="relay-audit-list"><For each={audit()}>{summary => <li>{summary}</li>}</For></ul></Show>
|
|
339
|
+
<p class="relay-meta">Export and Copy use the current record.</p>
|
|
340
|
+
<div class="relay-actions"><button type="button" class="relay-btn-sm" disabled={exportBusy()} onClick={() => { void exportReport() }}>Export Markdown</button><button type="button" class="relay-btn-sm" disabled={exportBusy()} onClick={() => { void exportReport(true) }}>Copy</button></div>
|
|
341
|
+
<Show when={exportStatus()}><p class="relay-meta" role="status" aria-live="polite">{exportStatus()}</p></Show><Show when={auditError()}><p role="alert" class="relay-error">{auditError()}</p></Show>
|
|
342
|
+
</div>
|
|
343
|
+
</details>
|
|
344
|
+
</Show>
|
|
345
|
+
<Show when={connected()}><details ref={creationDetails}><summary>New record</summary><form onSubmit={async event => { event.preventDefault(); if (!busy() && title().trim() && await run((api, options, sessionID) => api.createRecord({ title: title(), sessionID }, options))) { setTitle(''); if (creationDetails) creationDetails.open = false } }}>
|
|
346
|
+
<label>Record title<input value={title()} onInput={event => setTitle(event.currentTarget.value)} required /></label><button disabled={busy()}>Create record</button>
|
|
347
|
+
</form></details></Show>
|
|
348
|
+
<section class="relay-config-section" aria-label="Role configuration">
|
|
349
|
+
<div class="relay-section-head">
|
|
350
|
+
<h3>Role configuration</h3>
|
|
351
|
+
<div class="relay-actions">
|
|
352
|
+
<button type="button" class="relay-btn-sm" disabled={configBusy()} onClick={() => { void checkConfig(false, 0, true) }}>Validate config</button>
|
|
353
|
+
<Show when={canProbe()}><button type="button" class="relay-btn-sm" disabled={configBusy()} onClick={() => { if (canProbe()) void checkConfig(true, 0, true) }}>Run image probe</button></Show>
|
|
354
|
+
</div>
|
|
355
|
+
</div>
|
|
356
|
+
<Show when={configNotice()}><p class="relay-meta">{configNotice()}</p></Show>
|
|
357
|
+
<Show when={configError()}><p class="relay-error" role="alert">{configError()}</p></Show>
|
|
358
|
+
<Show when={config()}>
|
|
359
|
+
<div class="relay-config-summary">
|
|
360
|
+
<Show when={config()!.summary}><span>{config()!.summary}</span></Show>
|
|
361
|
+
<span>Limits: {config()!.limits.maxRunningTasks} running tasks, {config()!.limits.maxFixCycles} fix cycles</span>
|
|
362
|
+
</div>
|
|
363
|
+
<div class="relay-role-grid">
|
|
364
|
+
<For each={config()!.roles}>{role => <div class="relay-role-card" data-state={roleState(role)}>
|
|
365
|
+
<div class="relay-role-head">
|
|
366
|
+
<span class="relay-role-dot" aria-hidden="true" />
|
|
367
|
+
<span>{role.role}: {role.model ? 'configured' : 'not configured'}</span>
|
|
368
|
+
</div>
|
|
369
|
+
<Show when={role.model}>
|
|
370
|
+
<div class="relay-role-identity">
|
|
371
|
+
<span>Provider: {role.model!.providerID}</span>
|
|
372
|
+
<span>Model: {role.model!.id}</span>
|
|
373
|
+
<Show when={role.model!.variant}><span>Variant: {role.model!.variant}</span></Show>
|
|
374
|
+
</div>
|
|
375
|
+
<p class="relay-role-validation">Validation: {role.errors.length ? 'invalid' : 'valid'}; image: {role.image}</p>
|
|
376
|
+
</Show>
|
|
377
|
+
<For each={role.errors}>{issue => <p class="relay-role-error">{issue}</p>}</For>
|
|
378
|
+
<Show when={role.probe}>
|
|
379
|
+
<p class="relay-role-validation">{role.probe!.status === 'error' ? `Probe error (not cached): ${role.probe!.answer}` : `Probe answer: ${role.probe!.answer}`}</p>
|
|
380
|
+
<p class="relay-role-validation relay-mono">Probe tokens: input {role.probe!.tokens.input}, output {role.probe!.tokens.output}, reasoning {role.probe!.tokens.reasoning}, cache read {role.probe!.tokens.cache.read}, cache write {role.probe!.tokens.cache.write}</p>
|
|
381
|
+
</Show>
|
|
382
|
+
</div>}</For>
|
|
383
|
+
</div>
|
|
384
|
+
<For each={config()!.errors}>{issue => <p class="relay-role-error">{issue}</p>}</For>
|
|
385
|
+
</Show>
|
|
386
|
+
</section>
|
|
387
|
+
</section>
|
|
388
|
+
}
|
|
389
|
+
export default Plugin.define({ setup(ctx) {
|
|
390
|
+
ctx.add(Style, css)
|
|
391
|
+
const tab = { id: 'relay-status', title: 'Relay', closable: 'hover' as const }
|
|
392
|
+
ctx.add(Panel, { id: 'relay-status', region: 'side', list: () => [tab], render: () => <RelayPanel ctx={ctx} /> })
|
|
393
|
+
ctx.add(Command, { id: 'relay-status', title: 'Relay status', slash: { name: 'relay-status' }, run: () => { const session = ctx.sessions.current(); if (session) ctx.layout.open(`${ctx.id}:relay-status`, session) } })
|
|
394
|
+
} })
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './server.ts'
|
package/src/model.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const statuses = ['pending', 'running', 'blocked', 'awaiting_approval', 'completed'] as const
|
|
2
|
+
export type Status = typeof statuses[number]
|
|
3
|
+
export const phases = ['draft', 'approved', 'running', 'interrupted', 'completed', 'cancelled'] as const
|
|
4
|
+
export type Phase = typeof phases[number]
|
|
5
|
+
export type Owner = { role: 'planner' | 'builder' | 'reviewer'; sessionID?: string }
|
|
6
|
+
export type BuildReport = { outcome: 'done' | 'blocked'; summary: string; checks: { command: string; result: 'passed' | 'failed' }[] }
|
|
7
|
+
export type Check = { id: string; name: string; adapter: 'command' | 'playwright'; command: string; policy: 'automated-required' | 'manual-allowed' | 'not-applicable'; scope?: 'task' | 'final'; reason?: string; screenshotDir?: string; timeoutMs?: number }
|
|
8
|
+
export function checkScope(check: Check): 'task' | 'final' { return check.scope ?? 'task' }
|
|
9
|
+
export function isFinalTask(record: RecordInfo, taskID: string) {
|
|
10
|
+
return record.tasks.length > 0 && record.tasks.every(task => task.id === taskID || task.status === 'completed')
|
|
11
|
+
}
|
|
12
|
+
export function applicableChecks(record: RecordInfo, taskID: string) {
|
|
13
|
+
const final = isFinalTask(record, taskID)
|
|
14
|
+
return record.checks.filter(check => check.policy !== 'not-applicable' && (checkScope(check) === 'task' || final))
|
|
15
|
+
}
|
|
16
|
+
export type Evidence = {
|
|
17
|
+
id: string; recordID: string; taskID: string; checkID: string; buildRunID: string
|
|
18
|
+
result: 'passed' | 'failed' | 'unverified' | 'manually verified'; source: 'adapter' | 'permission-assert'
|
|
19
|
+
reason?: string; note?: string; exitCode?: number; output?: string
|
|
20
|
+
screenshots: { path: string; sha256: string; bytes: number }[]; startedAt: number; endedAt: number; durationMs: number
|
|
21
|
+
}
|
|
22
|
+
export type ReviewReport = { verdict: 'approve' | 'changes'; summary: string; findings: { severity: 'major' | 'minor'; text: string }[]; inspected?: string[] }
|
|
23
|
+
export type RunInfo = {
|
|
24
|
+
id: string; recordID: string; taskID: string; stage: 'build' | 'review'; role: 'builder' | 'reviewer'
|
|
25
|
+
model: { providerID: string; id: string; variant?: string }; sessionID: string; attempt: number
|
|
26
|
+
status: 'active' | 'reported' | 'failed' | 'interrupted' | 'cancelled'; report?: BuildReport | ReviewReport
|
|
27
|
+
startedAt: string; endedAt?: string; durationMs?: number
|
|
28
|
+
evidenceIDs?: string[]
|
|
29
|
+
tokens?: { input: number; output: number; reasoning: number; cache: { read: number; write: number } }
|
|
30
|
+
}
|
|
31
|
+
export const transitions = { start: ['draft', 'approved'], interrupt: ['running'], resume: ['interrupted'], complete: ['running'], cancel: ['draft', 'approved', 'running', 'interrupted'] } satisfies Record<string, Phase[]>
|
|
32
|
+
export type PhaseAction = keyof typeof transitions
|
|
33
|
+
export function phaseActions(record: RecordInfo) {
|
|
34
|
+
return (Object.keys(transitions) as PhaseAction[]).filter(action => (transitions[action] as readonly Phase[]).includes(record.phase) && (!['start', 'resume'].includes(action) || isApproved(record, 'plan')) && (action !== 'complete' || record.tasks.length > 0 && record.tasks.every(task => task.status === 'completed')))
|
|
35
|
+
}
|
|
36
|
+
export type RecordInfo = {
|
|
37
|
+
cancelReason?: string
|
|
38
|
+
plannerSession?: { previousModel?: { providerID: string; id: string; variant?: string }; model?: { providerID: string; id: string; variant?: string }; tokensAtStart: NonNullable<RunInfo['tokens']>; tokensAtEnd?: NonNullable<RunInfo['tokens']>; restoredAt?: string }
|
|
39
|
+
schemaVersion: 3; id: string; revision: number; planRevision: number; phase: Phase; interruptReason?: string; title: string
|
|
40
|
+
location: { directory: string; projectID: string }; sessionID?: string
|
|
41
|
+
createdAt: string; updatedAt: string
|
|
42
|
+
pendingApproval?: { key: string; revision: number }
|
|
43
|
+
approvalResult?: { revision: number; outcome: 'approved' | 'rejected' | 'stale' | 'withdrawn'; at: string }
|
|
44
|
+
tasks: { id: string; title: string; status: Status; owner?: Owner; fixCycles: number; allowedPaths?: string[]; updatedAt: string }[]
|
|
45
|
+
checks: Check[]
|
|
46
|
+
approvals: { kind: 'plan'; revision: number; planRevision: number; approvedAt: string; source: 'permission-assert' }[]
|
|
47
|
+
}
|
|
48
|
+
export type Op = { type: 'addCheck'; check: Check } | { type: 'removeCheck'; checkID: string } | { type: 'addTask'; title: string; allowedPaths?: string[] } | { type: 'setTaskStatus'; taskID: string; status: Status } | { type: 'assignTask'; taskID: string; owner: Owner } | { type: 'start' | 'resume' | 'complete' } | { type: 'cancel'; cancelReason?: string } | { type: 'interrupt'; reason: string }
|
|
49
|
+
export function isApproved(record: RecordInfo, kind: 'plan') {
|
|
50
|
+
if ((record.schemaVersion as number) >= 2) return record.approvals.findLast(approval => approval.kind === kind)?.planRevision === record.planRevision
|
|
51
|
+
let revision = record.revision
|
|
52
|
+
for (const approval of [...record.approvals].reverse()) {
|
|
53
|
+
if (approval.revision + 1 !== revision) return false
|
|
54
|
+
if (approval.kind === kind) return true
|
|
55
|
+
revision = approval.revision
|
|
56
|
+
}
|
|
57
|
+
return false
|
|
58
|
+
}
|