Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

feat(console): merge the five Workflows features and wire their seams (ADR-459..463)

ruv533849de541e
diff --git a/plugins/ruflo-console/.claude-plugin/plugin.json b/plugins/ruflo-console/.claude-plugin/plugin.json
index 3893ab70f5..0dfe935072 100644
--- a/plugins/ruflo-console/.claude-plugin/plugin.json
+++ b/plugins/ruflo-console/.claude-plugin/plugin.json
@@ -91,6 +91,24 @@
"title": "Boot screen",
"description": "With the bbs look, play a dial-up boot screen (modem connect, the RUFLO logo drawing in, every area of the console coming online in a log, a loading bar for the first ruflo reads) when the cockpit opens. At least 5.4 s, at most 8 s.",
"default": true
+ },
+ "wfBudgetRunUsd": {
+ "type": "number",
+ "title": "Workflow budget per run (USD)",
+ "description": "The Workflows page flags a run whose measured cost passes this many dollars (0.01 to 10000; 0 turns the guard off). It only warns: the console cannot stop a running workflow.",
+ "default": 0
+ },
+ "wfBudgetDayUsd": {
+ "type": "number",
+ "title": "Workflow budget per day (USD)",
+ "description": "The Workflows page flags the day's measured workflow cost past this many dollars (0.01 to 10000; 0 turns the guard off). It only warns.",
+ "default": 0
+ },
+ "wfAlertRules": {
+ "type": "string",
+ "title": "Workflow alert rules",
+ "description": "Space-separated rules for the Workflows page: stuck>20m (no progress for 20 minutes), tokens>2M (agent context size), dirty (a worktree has uncommitted changes). Empty turns them all off.",
+ "default": ""
}
}
}
diff --git a/plugins/ruflo-console/hooks/bindings.ts b/plugins/ruflo-console/hooks/bindings.ts
index b42e0a96fa..f504857d31 100644
--- a/plugins/ruflo-console/hooks/bindings.ts
+++ b/plugins/ruflo-console/hooks/bindings.ts
@@ -19,6 +19,7 @@ import { saveAllowed } from './remember'
import { pluginNames, settingsActions } from './settings'
import { catalogOf } from './plugin-catalog'
import { wireAnatole } from './anatole'
+import { wireWorkflows } from './wf-wire'
import { devtoolsActions } from './devtools'
import { HARNESSES, harnessSpec, isAutoAccept, isLive, newSession, send, whyNotRun } from './harness'
import { helpActions } from './help-actions'
@@ -80,6 +81,7 @@ export function actionsOf(state: State, host: Host, runner: Runner, steps: Steps
}
wireAnatole(state, host)
+ wireWorkflows(state, host)
const actions: Actions = {
view: setView,
remember: () => {
diff --git a/plugins/ruflo-console/hooks/data/wf-export.ts b/plugins/ruflo-console/hooks/data/wf-export.ts
index 88ac47077a..55b44f4abe 100644
--- a/plugins/ruflo-console/hooks/data/wf-export.ts
+++ b/plugins/ruflo-console/hooks/data/wf-export.ts
@@ -96,4 +96,4 @@ export function exportSpec(path: string, markdown: string, label: string, hasDir
}
/** A file name for a run's summary: its name and id with anything unsafe turned into a dash. */
-export const exportName = (run: WfRun): string => `${`${run.name}-${run.id}`.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^[^A-Za-z0-9]+/, '').slice(0, 90) || 'run'}.md`
+export const exportName = (run: WfRun): string => `${(run.name === run.id ? run.id : `${run.name}-${run.id}`).replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^[^A-Za-z0-9]+/, '').slice(0, 90) || 'run'}.md`
diff --git a/plugins/ruflo-console/hooks/state.ts b/plugins/ruflo-console/hooks/state.ts
index be93c78573..c782268ac8 100644
--- a/plugins/ruflo-console/hooks/state.ts
+++ b/plugins/ruflo-console/hooks/state.ts
@@ -1,4 +1,5 @@
import type { PluginOptions, Timer } from 'claude-code'
+import { guardOptionsOf, type GuardOptions } from './data/wf-alerts'
import { emptyAuto, type AutoState } from './data/automate'
import type { ProbeResult } from './data/cli'
@@ -96,7 +97,7 @@ export const CLI_PREFIXES = {
export type CliChoice = keyof typeof CLI_PREFIXES
-export type Options = {
+export type Options = GuardOptions & {
cli: CliChoice
/** How often the disk is re-read while the pane or band shows (seconds, 2-60). */
refreshSeconds: number
@@ -133,6 +134,7 @@ export function optionsOf(raw: PluginOptions | undefined): Options {
federationNetwork: value.federationNetwork === true,
look: value.look === 'plain' ? 'plain' : 'bbs',
boot: value.boot !== false,
+ ...guardOptionsOf(raw),
}
}
diff --git a/plugins/ruflo-console/hooks/views/wf-detail.ts b/plugins/ruflo-console/hooks/views/wf-detail.ts
index 37b657ca6b..e4318f3f21 100644
--- a/plugins/ruflo-console/hooks/views/wf-detail.ts
+++ b/plugins/ruflo-console/hooks/views/wf-detail.ts
@@ -248,7 +248,7 @@ const KEYS: readonly { verb: Verb; label: string; letters: string }[] = [
{ verb: 'out', label: 'â—‚ back', letters: 'zq' },
{ verb: 'next', label: 'â–¾ next', letters: 'mc' },
{ verb: 'prev', label: 'â–´ prev', letters: 'wa' },
- { verb: 'sub', label: 'tab â–¸', letters: 'tv' },
+ { verb: 'sub', label: 'tab â–¸', letters: 'tqv' },
{ verb: 'follow', label: 'follow', letters: 'fs' },
{ verb: 'filter', label: 'level', letters: 'vy' },
{ verb: 'search', label: 'search', letters: 'sk0123456789' },
diff --git a/plugins/ruflo-console/hooks/views/wf-export.ts b/plugins/ruflo-console/hooks/views/wf-export.ts
index c0491c7a4d..631c88b24a 100644
--- a/plugins/ruflo-console/hooks/views/wf-export.ts
+++ b/plugins/ruflo-console/hooks/views/wf-export.ts
@@ -30,7 +30,12 @@ export const setExportRoots = (scratchDir: string | null): void => void (scratch
export const setExportCostSource = (source: (run: WfRun) => ExportCost | null): void => void (costOf = source)
/** For tests. */
-export const resetExport = (): void => (said.clear(), (scratch = null), (fsOf = null), (costOf = () => null))
+export function resetExport(): void {
+ said.clear()
+ scratch = null
+ fsOf = null
+ costOf = () => null
+}
export const rootsOf = (cwd: string): Roots => ({ cwd, scratch })
export const defaultPathOf = (cwd: string, run: WfRun): string => `${cwd.replace(/\/+$/, '')}/${EXPORT_DIR}/${exportName(run)}`
@@ -70,7 +75,7 @@ export function exportBody(env: SlotEnv, run: WfRun, fs: StatFs | null): RenderE
return [
text(ctx, ` Writes a markdown summary: phases, agents, tokens, time, results (cost: n/a unless a source is wired). Credentials and control characters are masked.`, { dimColor: true }),
- text(ctx, ` Allowed: under ${clip(roots.cwd, 40)}${roots.scratch === null ? '' : ` or ${clip(roots.scratch, 40)}`} · name ends in .md · no .. · never overwrites · you confirm first`, { dimColor: true }),
+ text(ctx, ` Allowed: under ${clip(roots.cwd, 40)}${roots.scratch === null || roots.scratch === undefined ? '' : ` or ${clip(roots.scratch, 40)}`} · name ends in .md · no .. · never overwrites · you confirm first`, { dimColor: true }),
ctx.kit.Input === undefined ? text(ctx, ' This surface has no text field: use the default path button.', { dimColor: true }) : ctx.kit.Input({ key: 'wf-export-path', label: 'path', placeholder: `${EXPORT_DIR}/${exportName(run)}`, submitLabel: 'export', onSubmit: value => go(value) }),
row(ctx, [button(ctx, 'wf-export-default', 'Export to the default path', () => go(defaultPathOf(ctx.state.cwd, run)))], 'wf-export-controls'),
...(note === undefined ? [] : [text(ctx, ` ${note.text}`, note.ok ? { color: THEME.ok } : { color: THEME.warn })]),
diff --git a/plugins/ruflo-console/hooks/views/wf-register.ts b/plugins/ruflo-console/hooks/views/wf-register.ts
index 9d177e5227..84ff69c6d4 100644
--- a/plugins/ruflo-console/hooks/views/wf-register.ts
+++ b/plugins/ruflo-console/hooks/views/wf-register.ts
@@ -1,9 +1,16 @@
/**
* The one file the merge owner edits to switch a Workflows slot on (ADR-464): each feature that registers slots
- * (views/wf-slots.ts) is imported here for its side effect, one line apiece, e.g.
+ * (views/wf-slots.ts) is imported here for its side effect, one line apiece. The seams that need the state or the host
+ * (read-after hooks, the export filesystem, the drill's reader) are bound once in hooks/wf-wire.ts.
*
- * import '../wf-drill'
- *
- * Nothing is imported yet: the page draws exactly the board until a feature module is added below.
+ * The order matters for hotkeys only: worktrees and templates name the keys w, t, c and g and have no fallback, while the drill's
+ * keys each carry a list of letters and take the first one free (views/wf-detail.ts KEYS), so the drill is imported after them.
+ * tests/wf-merge.spec.ts holds the outcome.
*/
-export {}
+import './wf-worktrees'
+import './wf-templates'
+import './wf-anatole'
+import '../wf-drill'
+import './wf-guide'
+import './wf-replay'
+import './wf-triage'
diff --git a/plugins/ruflo-console/hooks/views/wf-slots.ts b/plugins/ruflo-console/hooks/views/wf-slots.ts
index 665772b4b3..5413b4fa55 100644
--- a/plugins/ruflo-console/hooks/views/wf-slots.ts
+++ b/plugins/ruflo-console/hooks/views/wf-slots.ts
@@ -42,7 +42,7 @@ export const RESERVED_KEYS: readonly string[] = ['p', 'x', 'r', 'h', 'y', 'n', '
export const DETAIL_TAB = 'detail'
const ID = /^[a-z][a-z0-9-]{1,31}$/
-const MAX_PER_KIND = 12
+const MAX_PER_KIND = 24
const registry: Slot[] = []
diff --git a/plugins/ruflo-console/hooks/views/wf-worktrees.ts b/plugins/ruflo-console/hooks/views/wf-worktrees.ts
index e940c36f7c..fc6c1fd95d 100644
--- a/plugins/ruflo-console/hooks/views/wf-worktrees.ts
+++ b/plugins/ruflo-console/hooks/views/wf-worktrees.ts
@@ -113,7 +113,7 @@ export function boardRows(env: SlotEnv): RenderElement[] {
if (hosts.get(ctx.state) === undefined) return [text(ctx, ' worktrees: not wired into this console yet (wireWfWorktrees)', { color: THEME.warn })]
if (store.error !== null) rows.push(text(ctx, ` the last read failed (${clip(store.error, 80)})${store.read === null ? '' : ': showing the read before it'}`, { color: THEME.warn }))
- if (store.read === null) return [...rows, text(ctx, store.isReading ? ' reading the worktrees…' : ' not read yet: it reads while this page is open, or press the read button (w)', { dimColor: true })]
+ if (store.read === null) return [...rows, text(ctx, store.isReading ? ' reading the worktrees…' : store.error === null ? ' not read yet: it reads while this page is open, or press the read button (w)' : ' press the read button (w) to try again', { dimColor: true })]
const { read, check } = store
const plan = planRemoval(read, check, nowMs)
diff --git a/plugins/ruflo-console/hooks/wf-live.ts b/plugins/ruflo-console/hooks/wf-live.ts
index 6b3a67e47c..bf70ac7740 100644
--- a/plugins/ruflo-console/hooks/wf-live.ts
+++ b/plugins/ruflo-console/hooks/wf-live.ts
@@ -16,6 +16,10 @@ import type { State } from './state'
import { slotsFor } from './views/wf-slots'
import type { WorkflowsModel } from './views/workflows'
+/** What runs after each successful read, registered once by hooks/wf-wire.ts (a module that needs this one cannot be imported here). */
+export type AfterRead = (state: State, host: Host, before: readonly WfRun[] | null, runs: readonly WfRun[], nowMs: number) => void | Promise<void>
+export const afterRead: AfterRead[] = []
+
/** The notices one read raises: a workflow run that ended since the last read (finished, or failed), seen against each run's earlier state. */
export function runNotices(prev: ReadonlyMap<string, string> | null, next: readonly WfRun[]): NoticeDraft[] {
if (prev === null) return []
@@ -78,6 +82,14 @@ export async function refreshWorkflows(state: State, host: Host, force = false,
// A slot that throws raises nothing; the page still reads.
}
}
+
+ for (const hook of afterRead) {
+ try {
+ await hook(state, host, before, runs, nowMs)
+ } catch {
+ // A hook that throws loses its own work only.
+ }
+ }
} catch (error) {
wf.error = cleanText(plain(error instanceof Error ? error.message : String(error), 100)) || 'the read was refused'
} finally {
diff --git a/plugins/ruflo-console/hooks/wf-wire.ts b/plugins/ruflo-console/hooks/wf-wire.ts
new file mode 100644
index 0000000000..8ba04aa19c
--- /dev/null
+++ b/plugins/ruflo-console/hooks/wf-wire.ts
@@ -0,0 +1,36 @@
+/**
+ * The Workflows page's one wiring point (ADR-464), kept out of the controller (its 500-line limit): bindings.ts calls
+ * `wireWorkflows(state, host)` once, where the state and the built host both exist. It hands each feature the host it cannot get
+ * from a slot's environment, and registers what runs after every read of the run folders (views/../wf-live.ts `afterRead`):
+ * the mission-event ledger, the saved views, and the cost and guard figures. Every hook is isolated: one that throws leaves the rest.
+ */
+import type { Host } from './host'
+import type { State } from './state'
+import { refreshWfGuards } from './wf-cost-live'
+import { bindWorkflowDrill } from './wf-drill'
+import { afterRead } from './wf-live'
+import { syncSavedViews } from './wf-saved-live'
+import { recordRunEvents } from './views/wf-guide'
+import { setExportFs } from './views/wf-export'
+import { wireWfAnatole } from './views/wf-anatole'
+import { wireWfTemplates } from './views/wf-templates'
+import { wireWfWorktrees } from './views/wf-worktrees'
+
+let isWired = false
+
+export function wireWorkflows(state: State, host: Host): void {
+ bindWorkflowDrill(state, host)
+ setExportFs(host.fs)
+ wireWfWorktrees(state, host)
+ wireWfTemplates(state, host)
+ wireWfAnatole(state, host)
+
+ if (isWired) return
+
+ isWired = true
+ afterRead.push(
+ (s, h, before, runs, nowMs) => void recordRunEvents(s, h, before, runs, nowMs),
+ (s, h, _before, _runs, nowMs) => syncSavedViews(s, h, nowMs),
+ (s, h, _before, _runs, nowMs) => refreshWfGuards(s, h, false, nowMs),
+ )
+}
diff --git a/plugins/ruflo-console/tests/wf-export.spec.ts b/plugins/ruflo-console/tests/wf-export.spec.ts
index d34700aaed..4880f6d368 100644
--- a/plugins/ruflo-console/tests/wf-export.spec.ts
+++ b/plugins/ruflo-console/tests/wf-export.spec.ts
@@ -53,6 +53,7 @@ describe('the markdown', () => {
it('names the file from the run, safely', () => {
expect(exportName(runOf('wf_a', BASE, {}, '../../etc/pass wd'))).toBe('etc-pass-wd-wf_a.md')
+ expect(exportName(runOf('wf_a', BASE, {}, 'wf_a'))).toBe('wf_a.md')
})
})
diff --git a/plugins/ruflo-console/tests/wf-merge.spec.ts b/plugins/ruflo-console/tests/wf-merge.spec.ts
new file mode 100644
index 0000000000..50501f6012
--- /dev/null
+++ b/plugins/ruflo-console/tests/wf-merge.spec.ts
@@ -0,0 +1,84 @@
+/**
+ * The merged Workflows features (ADR-464 seams): every feature's slots register with no refusal and no hotkey clash, the one wiring
+ * point adds its hooks once, a hook runs after each read and one that throws costs only itself, and the guard options are read from
+ * the settings checked. Pure and fast: an in-memory disk, no engine. Run with
+ * npx vitest run plugins/ruflo-console/tests/wf-merge.spec.ts --testTimeout=30000
+ */
+import { describe, expect, it } from 'vitest'
+
+import { guardOptionsOf } from '../hooks/data/wf-alerts'
+import type { Host } from '../hooks/host'
+import { newState, optionsOf } from '../hooks/state'
+import '../hooks/views/wf-register'
+import { refused } from '../hooks/wf-drill'
+import { afterRead, refreshWorkflows } from '../hooks/wf-live'
+import { slotsFor } from '../hooks/views/wf-slots'
+import { wireWorkflows } from '../hooks/wf-wire'
+
+const host = { fs: { read: async () => Promise.reject(new Error('ENOENT')), stat: async () => Promise.reject(new Error('ENOENT')), list: async () => Promise.reject(new Error('ENOENT')) }, invalidate: () => undefined, run: async () => ({ ok: false, stdout: '', stderr: '' }) } as unknown as Host
+
+describe('registration', () => {
+ it('registers every feature with no refusal, so no slot or hotkey was turned away', () => {
+ expect(refused).toEqual([])
+ })
+
+ it('gives each hotkey to exactly one slot, and the worktree and template keys are held', () => {
+ const keys = slotsFor('key').map(s => s.key)
+
+ expect(new Set(keys).size).toBe(keys.length)
+ expect(slotsFor('key').find(s => s.key === 'w')?.id).toBe('wt-read')
+ expect(slotsFor('key').find(s => s.key === 't')?.id).toBe('wf-template-next')
+ expect(slotsFor('action').find(s => s.hotkey === 'g')?.id).toBe('wf-template-launch')
+ expect(slotsFor('key').filter(s => s.id.startsWith('drill-')).length).toBe(8)
+ const hotkeys = slotsFor('action').map(s => s.hotkey)
+
+ expect(hotkeys).toEqual(expect.arrayContaining(['c', 'g']))
+ expect(new Set([...keys, ...hotkeys]).size).toBe(keys.length + hotkeys.length)
+ })
+
+ it('registers the boards of all five features', () => {
+ const ids = slotsFor('board').map(s => s.id)
+
+ expect(slotsFor('tab').map(s => s.id)).toEqual(expect.arrayContaining(['anatole', 'mission', 'guide']))
+ expect(slotsFor('notice').map(s => s.id)).toEqual(expect.arrayContaining(['links', 'wf-guard', 'wt-timer', 'anatole-read', 'drill-follow']))
+
+ for (const id of ['drill', 'links', 'replay', 'wf-triage', 'wf-cost', 'worktrees', 'templates', 'anatole']) expect(ids).toContain(id)
+ })
+})
+
+describe('after a read', () => {
+ it('adds its three hooks once however often it is wired', () => {
+ const state = newState({})
+ const start = afterRead.length
+
+ wireWorkflows(state, host)
+ wireWorkflows(state, host)
+ expect(afterRead.length - start).toBe(3)
+ })
+
+ it('runs each hook with the runs read, and a hook that throws costs only itself', async () => {
+ const state = newState({})
+ const seen: number[] = []
+
+ state.view = 'workflows'
+ state.isInteractive = false
+ state.configDir = '/nowhere/.claude'
+ state.cwd = '/work/proj'
+ afterRead.push(() => Promise.reject(new Error('boom')), (_s, _h, before, runs) => void seen.push(runs.length + (before === null ? 100 : 0)))
+ await refreshWorkflows(state, host, true, 1_000)
+ expect(seen).toEqual([100])
+ expect(state.wf.error).toBeNull()
+ })
+})
+
+describe('guard options', () => {
+ it('reads the three settings checked: out-of-range and wrong-typed values are off', () => {
+ expect(guardOptionsOf({ wfBudgetRunUsd: 5, wfBudgetDayUsd: 20000, wfAlertRules: 'stuck>20m dirty' })).toEqual({ wfBudgetRunUsd: 5, wfBudgetDayUsd: 0, wfAlertRules: 'stuck>20m dirty' })
+ expect(guardOptionsOf({ wfBudgetRunUsd: 'lots', wfAlertRules: 7 })).toEqual({ wfBudgetRunUsd: 0, wfBudgetDayUsd: 0, wfAlertRules: '' })
+ })
+
+ it('reaches state.options through optionsOf', () => {
+ expect(optionsOf({ wfBudgetRunUsd: 2.5 }).wfBudgetRunUsd).toBe(2.5)
+ expect(optionsOf(undefined).wfAlertRules).toBe('')
+ })
+})
diff --git a/plugins/ruflo-console/tests/wf-replay-views.spec.ts b/plugins/ruflo-console/tests/wf-replay-views.spec.ts
index 4216f89115..f6b39efdbf 100644
--- a/plugins/ruflo-console/tests/wf-replay-views.spec.ts
+++ b/plugins/ruflo-console/tests/wf-replay-views.spec.ts
@@ -42,7 +42,7 @@ const press = (tree: unknown, key: string): void => {
if (found === undefined) throw new Error(`no button ${key}`)
;(found.props.onPress as () => void)()
}
-const inputOf = (tree: unknown): El | undefined => flat(tree).find(el => el.kind === 'Input')
+const inputOf = (tree: unknown): El | undefined => flat(tree).find(el => el.kind === 'Input' && el.props.label === 'path')
const tick = (): Promise<void> => new Promise(resolve => setTimeout(resolve, 0))
const NOW = T0 + 600_000
@@ -81,10 +81,11 @@ describe('registration', () => {
it('adds four board slots after the board, takes no hotkey and no other kind of slot', () => {
world().page()
- expect(slotsFor('board').map(s => s.id)).toEqual(['replay', 'compare', 'export', 'saved'])
- expect(slotsFor('key')).toHaveLength(0)
- expect(slotsFor('action')).toHaveLength(0)
- expect(slotsFor('tab')).toHaveLength(0)
+ expect(slotsFor('board').map(s => s.id).filter(id => ['replay', 'compare', 'export', 'saved'].includes(id))).toEqual(['replay', 'compare', 'export', 'saved'])
+
+ const ours = new Set(['replay', 'compare', 'export', 'saved'])
+
+ for (const kind of ['key', 'action', 'tab'] as const) expect(slotsFor(kind).filter(s => ours.has(s.id))).toHaveLength(0)
})
it('every slot is folded shut with a one-line summary until opened, and a narrow page still draws', () => {
diff --git a/plugins/ruflo-console/tests/wf-wire.spec.ts b/plugins/ruflo-console/tests/wf-wire.spec.ts
index f77575e083..a154881878 100644
--- a/plugins/ruflo-console/tests/wf-wire.spec.ts
+++ b/plugins/ruflo-console/tests/wf-wire.spec.ts
@@ -373,8 +373,8 @@ describe('the slot registry', () => {
expect(registerSlot({ kind: 'action', id: 'second', label: 'x', hotkey: 'm', why: 'w', spec: () => null })).toMatchObject({ ok: false, why: expect.stringContaining('taken by slot "first"') })
})
- it('keeps at most twelve slots of a kind, boards ordered by `order` then registration', () => {
- for (let i = 0; i < 12; i += 1) expect(registerSlot(board(`b-${i}`, i === 5 ? 1 : undefined))).toEqual({ ok: true })
+ it('keeps at most twenty-four slots of a kind (twelve held too few for the merged features), boards ordered by `order` then registration', () => {
+ for (let i = 0; i < 24; i += 1) expect(registerSlot(board(`b-${i}`, i === 5 ? 1 : undefined))).toEqual({ ok: true })
expect(registerSlot(board('b-last'))).toMatchObject({ ok: false })
expect(slotsFor('board').map(slot => slot.id).slice(0, 3)).toEqual(['b-5', 'b-0', 'b-1'])