mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
fix(console): scroll workflows lists with the cursor, fix narrow layout, mask secrets and strip control chars, harden tests (ADR-458)
Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
1 parent
2169b620b9
commit
ebea124e52
4 files changed
+72
-9
No files matched your search
@@ -64,7 +64,18 @@ export type WfRun = {
|
||||
}
|
||||
|
||||
const asRecord = (value: unknown): Record<string, unknown> | null => (typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null)
|
||||
const str = (value: unknown, max = 200): string | undefined => (typeof value === 'string' && value !== '' ? value.slice(0, max) : undefined)
|
||||
/** Control characters (an ANSI escape in a label would drive the terminal) are dropped from every string a file supplies. */
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/g
|
||||
const str = (value: unknown, max = 200): string | undefined => {
|
||||
const clean = typeof value === 'string' ? value.replace(CONTROL, ' ').slice(0, max) : ''
|
||||
|
||||
return clean === '' ? undefined : clean
|
||||
}
|
||||
|
||||
/** A result preview is agent output: anything shaped like a credential is masked before it is kept or drawn. */
|
||||
const SECRETISH = /\b(?:sk|pk|ghp|gho|ghs|github_pat|xox[abprs]|AKIA|AIza)[-_A-Za-z0-9]{12,}|\bBearer\s+\S{8,}|\b[A-Za-z0-9+_-]{32,}={0,2}|(?:key|token|secret|passw(?:or)?d)\s*[=:]\s*\S+/gi
|
||||
export const maskSecrets = (text: string): string => text.replace(SECRETISH, '‹masked›')
|
||||
const num = (value: unknown): number | undefined => (typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined)
|
||||
|
||||
/** JSONL as records: a line that does not parse (a half-written tail) is dropped, never thrown on. */
|
||||
@@ -105,7 +116,7 @@ export function parseJournal(text: string | null): { isLaunched: boolean; agents
|
||||
byId.set(id, { agentId: id, label: str(event.label, 80) ?? id, hasResult: false, ...(phase !== undefined && { phase }) })
|
||||
} else if (event.type === 'result' && id !== undefined) {
|
||||
const held = byId.get(id) ?? { agentId: id, label: id, hasResult: false }
|
||||
const preview = typeof event.result === 'string' ? event.result.replace(/\s+/g, ' ').slice(0, 160) : asRecord(event.result) !== null ? `structured result (${Object.keys(event.result as object).length} fields)` : undefined
|
||||
const preview = typeof event.result === 'string' ? maskSecrets(event.result.replace(CONTROL, ' ').replace(/\s+/g, ' ')).slice(0, 160) : asRecord(event.result) !== null ? `structured result (${Object.keys(event.result as object).length} fields)` : undefined
|
||||
|
||||
byId.set(id, { ...held, hasResult: true, ...(preview !== undefined && preview !== '' && { resultPreview: preview }) })
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ function phaseMark(phase: WfPhase, nowMs: number): { mark: string; color: string
|
||||
return { mark: '○', color: undefined }
|
||||
}
|
||||
|
||||
/** First row drawn so the cursor row is always inside a window of `size` rows (the list scrolls with it). */
|
||||
const windowStart = (total: number, cursor: number, size: number): number => Math.max(0, Math.min(total - size, cursor - size + 1))
|
||||
|
||||
const mb = (bytes: number): string => `${(bytes / 1_000_000).toFixed(1)} MB`
|
||||
|
||||
/** The run header: its name and state, then agents running, done and failed, and the tokens the agents' records add up to. */
|
||||
@@ -97,7 +100,7 @@ function inspect(ctx: Ctx, run: WfRun, agent: WfAgent, hooks: WorkflowsHooks): R
|
||||
|
||||
rows.push(kv(ctx, 'model', agent.model === undefined ? 'n/a' : `${modelName(agent.model)} (${agent.model})`))
|
||||
rows.push(kv(ctx, 'tokens', `${fmtTokens(agent.tokens, agent.isTokensPartial)} context tokens of its latest request${agent.isTokensPartial === true ? ' (tail of the transcript only: a floor)' : ''}`))
|
||||
rows.push(kv(ctx, 'elapsed', `${fmtElapsed(agent.elapsedMs)}${agent.startedMs === undefined ? '' : ` · started ${new Date(agent.startedMs).toISOString().slice(11, 19)}Z`}`))
|
||||
rows.push(kv(ctx, 'elapsed', `${fmtElapsed(agent.elapsedMs)}${Number.isNaN(new Date(agent.startedMs ?? Number.NaN).getTime()) ? '' : ` · started ${new Date(agent.startedMs as number).toISOString().slice(11, 19)}Z`}`))
|
||||
rows.push(kv(ctx, 'worktree', agent.hasWorktree ? (agent.worktreePath ?? 'yes') : 'none'))
|
||||
if (agent.toolCalls !== undefined) rows.push(kv(ctx, 'tool calls', `${agent.toolCalls}${agent.lastTool === undefined ? '' : ` · last ${agent.lastTool}`}`))
|
||||
if (agent.resultPreview !== undefined) rows.push(text(ctx, `result: ${agent.resultPreview}`, { dimColor: true }))
|
||||
@@ -139,7 +142,7 @@ export function workflowsView(ctx: Ctx, model: WorkflowsModel | null, ui: WfUi,
|
||||
const wide = ctx.columns >= 56
|
||||
const left = wide ? Math.min(26, Math.max(18, Math.floor(ctx.columns / 3))) : ctx.columns
|
||||
const current = currentPhase(run.phases)
|
||||
const right = Math.max(20, ctx.columns - left - 3)
|
||||
const right = wide ? Math.max(20, ctx.columns - left - 3) : Math.max(20, ctx.columns - 1)
|
||||
const phase = here.phase
|
||||
|
||||
rows.push(rule(ctx, 'Phases', phase === null ? '' : `${phase.title}${phase.detail === undefined ? '' : ` · ${clip(phase.detail, 40)}`}`))
|
||||
@@ -148,8 +151,10 @@ export function workflowsView(ctx: Ctx, model: WorkflowsModel | null, ui: WfUi,
|
||||
const rowsMax = 14
|
||||
const phaseTotal = run.phases.length
|
||||
const agentList = phase?.agents ?? []
|
||||
const phases = run.phases.slice(0, rowsMax).map((entry, i) => phaseCell(ctx, entry, i, { isHere: i === here.ui.phase && here.ui.column === 'phases', isCurrent: i === current, width: left }))
|
||||
const agents = agentList.slice(0, rowsMax).map((entry, i) => agentCell(ctx, entry, i === here.ui.agent && here.ui.column === 'agents', right))
|
||||
const phaseFrom = windowStart(phaseTotal, here.ui.phase, rowsMax)
|
||||
const agentFrom = windowStart(agentList.length, here.ui.agent, rowsMax)
|
||||
const phases = run.phases.slice(phaseFrom, phaseFrom + rowsMax).map((entry, n) => phaseCell(ctx, entry, phaseFrom + n, { isHere: phaseFrom + n === here.ui.phase && here.ui.column === 'phases', isCurrent: phaseFrom + n === current, width: left }))
|
||||
const agents = agentList.slice(agentFrom, agentFrom + rowsMax).map((entry, n) => agentCell(ctx, entry, agentFrom + n === here.ui.agent && here.ui.column === 'agents', right))
|
||||
|
||||
if (run.phases.length === 0) rows.push(text(ctx, 'This run has no agents yet.', { dimColor: true }))
|
||||
else if (wide) {
|
||||
@@ -162,7 +167,7 @@ export function workflowsView(ctx: Ctx, model: WorkflowsModel | null, ui: WfUi,
|
||||
|
||||
const hidden = Math.max(phaseTotal, agentList.length) - rowsMax
|
||||
|
||||
if (hidden > 0) rows.push(text(ctx, `+${hidden} more (j/k walks all of them)`, { dimColor: true }))
|
||||
if (hidden > 0) rows.push(text(ctx, `+${hidden} more (j/k scrolls to them)`, { dimColor: true }))
|
||||
if (phase !== null && phase.agents.length === 0) rows.push(text(ctx, 'No agent has started in this phase yet.', { dimColor: true }))
|
||||
|
||||
if (here.ui.isInspecting && here.agent !== null) rows.push(...inspect(ctx, run, here.agent, hooks))
|
||||
|
||||
@@ -148,6 +148,14 @@ describe('buildRun', () => {
|
||||
expect(currentPhase(run.phases)).toBe(0)
|
||||
})
|
||||
|
||||
it('stale starts after 15 minutes without a sign of life, not before', () => {
|
||||
const at = (idle: number) => buildRun(liveInput({ nowMs: T0 + 40_000 + idle, lastActivityMs: T0 + 40_000 })).phases[0]?.agents.find(a => a.label === 'build:memmap')?.state
|
||||
|
||||
expect(STALE_MS).toBe(15 * 60_000)
|
||||
expect(at(14 * 60_000)).toBe('running')
|
||||
expect(at(16 * 60_000)).toBe('stale')
|
||||
})
|
||||
|
||||
it('a tail-read transcript makes tokens a floor and gives no start time', () => {
|
||||
const run = buildRun(liveInput({ agents: new Map([['a1', { meta: null, transcript: transcript([{ at: 5, id: 'm1', input: 1, write: 1, read: 1, output: 1 }, { at: 9, id: 'm2', input: 1, write: 1, read: 1, output: 1 }]), isTail: true, path: '/p' }]]), journal: journal(started('a1', 'big', 'Build')) }))
|
||||
const agent = run.phases[0]?.agents[0]
|
||||
@@ -279,6 +287,15 @@ describe('reader', () => {
|
||||
expect(found.skipped).toEqual([])
|
||||
})
|
||||
|
||||
it('a finished run never opens a transcript', async () => {
|
||||
const files = { ...base(), [`${root}/${session}/workflows/wf_live.json`]: record() }
|
||||
const opened: string[] = []
|
||||
const inner = memoryFs(files)
|
||||
|
||||
await read({ ...inner, read: async path => (opened.push(path), inner.read(path)) })
|
||||
expect(opened.filter(path => path.endsWith('.jsonl') && !path.endsWith('journal.jsonl'))).toEqual([])
|
||||
})
|
||||
|
||||
it('an oversized transcript is tail-read where the host can, else left unread and counted', async () => {
|
||||
const big = { [`${runDir}/agent-a1.jsonl`]: TRANSCRIPT_CAP + 1 }
|
||||
const files = base()
|
||||
@@ -337,6 +354,36 @@ describe('view', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('scrolls so the cursor row is always drawn, however far down it is', () => {
|
||||
const many = buildRun({ ...liveInput(), journal: journal(...Array.from({ length: 500 }, (_, i) => started(`x${i}`, `agent ${i}`, 'Build'))), agents: new Map() })
|
||||
|
||||
for (const columns of [110, 50]) {
|
||||
const ui = { ...startOn(newWfUi(), many), column: 'agents' as const, agent: 300 }
|
||||
const out = lines(workflowsView(ctxOf(columns), model([many]), ui, hooks))
|
||||
|
||||
expect(out.some(l => l.includes('▸') && l.includes('agent 300'))).toBe(true)
|
||||
expect(out.filter(l => /agent \d/.test(l)).length).toBe(14)
|
||||
}
|
||||
})
|
||||
|
||||
it('strips control characters from labels, masks credential-shaped text in a result preview, and survives an absurd start time', () => {
|
||||
const run = buildRun({
|
||||
...liveInput(),
|
||||
journal: journal(started('z1', '\u001b[31mevil\u001b[0m label', 'Build'), result('z1', 'token=abc123 and sk-abcdefghijklmnop1234 ok see src/some/long/path/to/a/file/name/here.ts')),
|
||||
agents: new Map(),
|
||||
record: record({ workflowProgress: [{ type: 'workflow_agent', agentId: 'z1', startedAt: 1e20, state: 'done' }] }),
|
||||
})
|
||||
const agent = run.phases[0]?.agents[0]
|
||||
|
||||
expect(agent?.label).not.toMatch(/\u001b/)
|
||||
expect(agent?.resultPreview).not.toMatch(/abc123|sk-abcdef/)
|
||||
expect(agent?.resultPreview).toContain('src/some/long/path/to/a/file/name/here.ts')
|
||||
|
||||
const ui = { ...startOn(newWfUi(), run), column: 'agents' as const, isInspecting: true }
|
||||
|
||||
expect(() => lines(workflowsView(ctxOf(110), model([run]), ui, hooks))).not.toThrow()
|
||||
})
|
||||
|
||||
it('narrow screens drop the model and badge instead of overflowing', () => {
|
||||
const out = lines(workflowsView(ctxOf(50), model(), startOn(newWfUi(), live), hooks))
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ No file in the console's existing registries is edited by this change; the wirin
|
||||
## 3. Consequences
|
||||
|
||||
- One page for both swarms, from files already on disk; no new probe, no network, no secrets. A result is shown only as the
|
||||
first 160 characters of the string the journal already holds (a structured result as a field count), in the inspect panel.
|
||||
first 160 characters of the string the journal already holds (a structured result as a field count), in the inspect panel, with credential-shaped text (`sk-…`, `token=…`, `Bearer …`, 32+ character tokens) masked and control characters stripped from every file-supplied string. Lists longer than 14 rows scroll with the cursor.
|
||||
- A live run's figures are derived and say so; a finished run's are Claude Code's own.
|
||||
- `stale` is a heuristic with a stated threshold, not a fact. The page never reports a failure it cannot read.
|
||||
- Reading cost: measured 72 ms for 6 real runs including one live run (this one), on the 2026-10-05 host. A finished run costs
|
||||
@@ -68,7 +68,7 @@ No file in the console's existing registries is edited by this change; the wirin
|
||||
|
||||
## 4. Test and benchmark plan
|
||||
|
||||
`plugins/ruflo-console/tests/workflows.spec.ts` (27 tests) with fixtures that copy the shape of a real run and none of its
|
||||
`plugins/ruflo-console/tests/workflows.spec.ts` (32 tests) with fixtures that copy the shape of a real run and none of its
|
||||
content: parsers (unknown events, a half-written line, a cut tail), streamed-message dedupe, live vs finished vs stale vs
|
||||
tail-read runs, the ruflo swarm run, key movement and clamping, the reader against an in-memory disk (oversize, tail,
|
||||
limits, empty), and the page through a recording kit (columns, narrow width, inspect, buttons and their argv, empty states).
|
||||
|
||||
Reference in new issue
Block a user