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

test(ruflo-console): end-to-end script against real ruflo state and a real Claude Code

ruv0e935d9fc676
diff --git a/plugins/ruflo-console/hooks/views/claims.ts b/plugins/ruflo-console/hooks/views/claims.ts
index fed6a546b9..6455dcc839 100644
--- a/plugins/ruflo-console/hooks/views/claims.ts
+++ b/plugins/ruflo-console/hooks/views/claims.ts
@@ -13,6 +13,7 @@ const who = (claim: ClaimRecord): string => (claim.claimant.kind === 'agent' ? `
export function claimsView(ctx: Ctx): RenderElement {
const snap = ctx.state.snapshot
const claims = snap?.claims ?? []
+ const agents = snap?.agents ?? []
const pick = selection(ctx.state)
const stealable = claims.filter(claim => claim.isStealable).length
const handoffs = claims.filter(claim => claim.handoffTo !== undefined || claim.status === 'handoff-pending').length
@@ -33,7 +34,8 @@ export function claimsView(ctx: Ctx): RenderElement {
claims.slice(0, 10).forEach(claim => {
const isPicked = pick.claim?.issueId === claim.issueId
- const flags = [claim.isStealable ? 'stealable' : '', claim.handoffTo !== undefined ? `→ ${claim.handoffTo}` : ''].filter(Boolean).join(' ')
+ const target = claim.handoffTo === undefined ? undefined : (agents.find(agent => agent.id === claim.handoffTo) ?? null)
+ const flags = [claim.isStealable ? 'stealable' : '', claim.handoffTo !== undefined ? `→ ${target?.name ?? target?.type ?? claim.handoffTo}` : ''].filter(Boolean).join(' ')
rows.push(
text(ctx, clip(`${isPicked ? '▸' : ' '} ${claim.issueId.padEnd(22)} ${who(claim).padEnd(34)} ${claim.status.padEnd(9)} ${claim.progress ?? 0}% ${flags}`, ctx.columns), {
@@ -46,13 +48,8 @@ export function claimsView(ctx: Ctx): RenderElement {
}
rows.push(rule(ctx, 'Act', ctx.state.isActing ? 'running…' : ''))
- rows.push(
- text(
- ctx,
- `claim ${pick.claim?.issueId ?? 'n/a'} · agent ${pick.agent !== null ? `${pick.agent.name ?? pick.agent.type} (${pick.agent.id})` : 'n/a — no agents on disk'} · task ${pick.task?.id ?? 'n/a — every task is claimed'}`,
- { dimColor: true },
- ),
- )
+ rows.push(text(ctx, `picked claim ${pick.claim?.issueId ?? 'n/a'} · agent ${pick.agent !== null ? `${pick.agent.name ?? pick.agent.type} (${pick.agent.id})` : 'n/a — no agents on disk'}`, { dimColor: true }))
+ rows.push(text(ctx, `open task ${pick.task === null ? 'n/a — every task is claimed' : `${pick.task.id}: ${pick.task.description || pick.task.type}`}`, { dimColor: true }))
if (ctx.columns >= 44) {
rows.push(
diff --git a/plugins/ruflo-console/scripts/e2e-lib.sh b/plugins/ruflo-console/scripts/e2e-lib.sh
new file mode 100644
index 0000000000..d942efa350
--- /dev/null
+++ b/plugins/ruflo-console/scripts/e2e-lib.sh
@@ -0,0 +1,130 @@
+# Helpers for e2e.sh (sourced). Results, an isolated Claude Code config, tmux driving, and screen regions.
+# Never prints a credential; the copied one is shredded by the EXIT trap e2e.sh installs.
+
+RESULTS=()
+
+result() { # status step assertion where
+ RESULTS+=("| $2 | $3 | $1 | $4 |")
+ printf '%-4s %-6s %s (%s)\n' "$1" "$2" "$3" "$4"
+}
+pass() { result PASS "$@"; }
+fail() { result FAIL "$@"; FAILED=$((FAILED + 1)); }
+skip() { result SKIP "$@"; }
+
+# check STEP ASSERTION WHERE COMMAND...: PASS when the command succeeds.
+check() {
+ local step="$1" what="$2" where="$3"
+ shift 3
+ if "$@" >/dev/null 2>&1; then pass "$step" "$what" "$where"; else fail "$step" "$what" "$where"; fi
+}
+
+has() { grep -qF -- "$2" "$1"; } # has FILE TEXT
+lacks() { ! grep -qF -- "$2" "$1"; }
+
+write_results() {
+ {
+ echo "# ruflo-console e2e — target $TARGET — $(date -u +%FT%TZ)"
+ echo
+ echo "Claude Code $("$CLAUDE" --version 2>/dev/null | head -1) · CLI $($CLI --version 2>/dev/null | tail -1) · live=${RUFLO_E2E_LIVE:-0}"
+ echo
+ echo "| step | assertion | result | captured in |"
+ echo "|---|---|---|---|"
+ printf '%s\n' "${RESULTS[@]}"
+ } >"$OUT/results.md"
+}
+
+# An isolated config dir: the person's login copied 0600 (shredded on exit), onboarding done, the project trusted,
+# and the project's .mcp.json servers disabled (an `npx @claude-flow/cli@latest mcp start` server can rewrite helpers).
+make_config() { # make_config PROJECT_DIR...
+ CFG="$(mktemp -d "$OUT/cfg.XXXX")"
+ install -m 600 "$HOME/.claude/.credentials.json" "$CFG/.credentials.json"
+ local version
+ version="$("$CLAUDE" --version 2>/dev/null | awk '{print $1}')"
+ node - "$CFG/.claude.json" "$version" "$@" <<'NODE'
+const fs = require('node:fs')
+const [file, version, ...projects] = process.argv.slice(2)
+const path = require('node:path')
+// Claude Code offers the .mcp.json servers of the project and of every folder above it: all of them are disabled.
+const serversOf = dir => {
+ const out = []
+ for (let at = path.resolve(dir); ; at = path.dirname(at)) {
+ try { out.push(...Object.keys(JSON.parse(fs.readFileSync(`${at}/.mcp.json`, 'utf8')).mcpServers ?? {})) } catch {}
+ if (path.dirname(at) === at) return [...new Set(out)]
+ }
+}
+const entry = dir => {
+ const servers = serversOf(dir)
+ return { hasTrustDialogAccepted: true, hasClaudeMdExternalIncludesApproved: true, hasClaudeMdExternalIncludesWarningShown: true, enabledMcpjsonServers: [], disabledMcpjsonServers: servers }
+}
+fs.writeFileSync(file, JSON.stringify({
+ hasCompletedOnboarding: true, hasCompletedClaudeInChromeOnboarding: true, lastOnboardingVersion: version, lastReleaseNotesSeen: version, theme: 'dark',
+ officialMarketplaceAutoInstallAttempted: true, shiftEnterKeyBindingInstalled: true, hasIdeOnboardingBeenShown: { vscode: true },
+ projects: Object.fromEntries(projects.map(dir => [dir, entry(dir)])),
+}, null, 2), { mode: 0o600 })
+NODE
+}
+
+shred_config() {
+ [[ -n "${CFG:-}" && -f "$CFG/.credentials.json" ]] && { shred -u "$CFG/.credentials.json" 2>/dev/null || rm -f "$CFG/.credentials.json"; }
+ [[ -n "${CFG:-}" ]] && rm -rf "$CFG/projects" "$CFG/sessions" 2>/dev/null
+ return 0
+}
+
+# claude_p NAME DIR ARGS...: one headless run in DIR with the isolated config; stdout to $OUT/NAME.txt, debug log to $OUT/NAME.log.
+claude_p() {
+ local name="$1" dir="$2"
+ shift 2
+ (cd "$dir" && CLAUDE_CONFIG_DIR="$CFG" timeout 180 "$CLAUDE" -p --debug-file "$OUT/$name.log" "$@" </dev/null >"$OUT/$name.txt" 2>&1)
+}
+
+# A refused tree or a failed hook of ours in a debug log.
+clean_log() { ! grep -E "does not validate|ruflo-(console|mods|swarm)[^ ]*: .*(refused|failed)" "$1" | grep -vE "fs\.(stat|list|read)" | grep -q .; }
+
+TMUX_SESSION="ruflo-e2e-$$"
+# A private tmux server: other agents on this machine kill or reuse the default one.
+TMUX_SOCKET="ruflo-e2e-$$"
+tmux() { command tmux -L "$TMUX_SOCKET" "$@"; }
+tmux_start() { # tmux_start DIR LOG ARGS...
+ local dir="$1" log="$2"
+ shift 2
+ tmux kill-session -t "$TMUX_SESSION" 2>/dev/null
+ tmux new-session -d -s "$TMUX_SESSION" -x 200 -y 55 \
+ "cd '$dir' && CLAUDE_CONFIG_DIR='$CFG' '$CLAUDE' --debug-file '$log' $* ; sleep 30"
+}
+# Answers the start-up dialogs as a cautious person would: rejects every project MCP server (Esc), so no
+# `npx … mcp start` server runs (one can rewrite .claude/helpers), and keeps browser tools off. Returns once the
+# prompt shows.
+settle_dialogs() {
+ local left=40
+ while ((left > 0)); do
+ tmux capture-pane -t "$TMUX_SESSION" -p >"$OUT/.settle.txt"
+ if grep -q "new MCP servers found" "$OUT/.settle.txt"; then tmux send-keys -t "$TMUX_SESSION" Escape; sleep 1; continue; fi
+ if grep -q "Claude in Chrome extension detected" "$OUT/.settle.txt"; then tmux send-keys -t "$TMUX_SESSION" Escape; sleep 1; continue; fi
+ grep -q "Do you trust\|trust this folder" "$OUT/.settle.txt" && { tmux send-keys -t "$TMUX_SESSION" Down Enter; sleep 1; continue; }
+ grep -q "❯" "$OUT/.settle.txt" && grep -q "⏵⏵\|? for shortcuts\|accept edits\|auto mode" "$OUT/.settle.txt" && return 0
+ sleep 1
+ left=$((left - 1))
+ done
+ return 1
+}
+tmux_keys() { tmux send-keys -t "$TMUX_SESSION" "$@"; }
+# Types a slash command, lets the completion menu settle, and submits it.
+tmux_cmd() { tmux send-keys -t "$TMUX_SESSION" -l "$1"; sleep 1; tmux send-keys -t "$TMUX_SESSION" Enter; }
+tmux_shot() { tmux capture-pane -t "$TMUX_SESSION" -p -e >"$OUT/$1.ansi"; tmux capture-pane -t "$TMUX_SESSION" -p >"$OUT/$1.txt"; }
+tmux_stop() { tmux kill-server 2>/dev/null; return 0; }
+
+# wait_for FILE-PREFIX TEXT SECONDS: re-captures until the screen holds TEXT.
+wait_for() {
+ local shot="$1" text="$2" left="${3:-20}"
+ while ((left > 0)); do
+ tmux_shot "$shot"
+ grep -qF -- "$text" "$OUT/$shot.txt" && return 0
+ sleep 1
+ left=$((left - 1))
+ done
+ return 1
+}
+
+# stable SHOT: a capture with colours (.ansi) minus the rows that change on their own (the status line's clock and any
+# "Ns ago"), so two captures differ only where something was drawn anew: the animation, or new data.
+stable() { grep -vE '⏱|[0-9]+[smhd] ago' "$OUT/$1.ansi"; }
diff --git a/plugins/ruflo-console/scripts/e2e.sh b/plugins/ruflo-console/scripts/e2e.sh
new file mode 100644
index 0000000000..ae27355078
--- /dev/null
+++ b/plugins/ruflo-console/scripts/e2e.sh
@@ -0,0 +1,216 @@
+#!/usr/bin/env bash
+# End-to-end test of ruflo-console against real ruflo state and a real Claude Code.
+#
+# bash plugins/ruflo-console/scripts/e2e.sh [--target scratch|repo]
+#
+# --target scratch (default) a fresh throwaway project: `ruflo init` from this branch's CLI, then real state.
+# --target repo this checkout itself: real state is made only with commands that write the gitignored
+# .claude-flow/ and .swarm/ (never `ruflo init`, which rewrites tracked files), and git
+# status must be the same before and after.
+#
+# Steps 1 and 5c-static run anywhere. Steps that start Claude Code need the person's login: they run only with
+# RUFLO_E2E_LIVE=1, which copies ~/.claude/.credentials.json into an isolated CLAUDE_CONFIG_DIR (never the real
+# ~/.claude) and shreds it on exit. Evidence lands in $RUFLO_E2E_DIR (default: a temp dir), results in results.md.
+set -u
+HERE="$(cd "$(dirname "$0")" && pwd)"
+PLUGIN="$(cd "$HERE/.." && pwd)"
+REPO="$(cd "$PLUGIN/../.." && pwd)"
+TARGET=scratch
+[[ "${1:-}" == "--target" ]] && TARGET="${2:-scratch}"
+[[ "$TARGET" == scratch || "$TARGET" == repo ]] || { echo "--target scratch|repo" >&2; exit 2; }
+BASE="${RUFLO_E2E_DIR:-${TMPDIR:-/tmp}/ruflo-console-e2e}"
+OUT="$BASE/$(date +%Y%m%dT%H%M%S)-$TARGET"
+mkdir -p "$OUT"
+CLAUDE="${CLAUDE_BIN:-$HOME/.local/bin/claude}"
+if [[ -f "$REPO/v3/@claude-flow/cli/dist/src/index.js" ]]; then CLI="node $REPO/v3/@claude-flow/cli/bin/cli.js"; else CLI="npx --offline -y @claude-flow/cli@latest"; fi
+LIVE="${RUFLO_E2E_LIVE:-0}"
+FAILED=0
+CFG=""
+# Issue ids carry the run, so a second run in the same project never collides with the first one's claims.
+RUN="$(date +%s)"
+PLUGINS=(--plugin-dir "$PLUGIN" --plugin-dir "$REPO/plugins/ruflo-mods" --plugin-dir "$REPO/plugins/ruflo-swarm")
+# shellcheck source=e2e-lib.sh
+source "$HERE/e2e-lib.sh"
+trap 'tmux_stop; shred_config; write_results' EXIT
+
+PROJ="$REPO"
+[[ "$TARGET" == scratch ]] && PROJ="$OUT/project"
+cli() { (cd "$PROJ" && $CLI "$@") >>"$OUT/cli.log" 2>&1; }
+json() { node -e "$1" "$PROJ" 2>/dev/null; }
+
+# ---------------------------------------------------------------- 1. real ruflo state
+if [[ "$TARGET" == repo ]]; then
+ git -C "$REPO" status --porcelain >"$OUT/git-before.txt"
+ git -C "$REPO" diff --stat -- .claude/helpers v3/@claude-flow/cli/.claude/helpers >"$OUT/helpers-before.txt"
+else
+ mkdir -p "$PROJ" && git -C "$PROJ" init -q
+ check S1 "ruflo init (branch CLI) makes a ruflo project, classic hooks included" cli.log cli init --force
+fi
+
+check S1 "swarm init hierarchical" cli.log cli swarm init --topology hierarchical --max-agents 6 --strategy specialized
+for name in e2e-coder e2e-tester e2e-reviewer; do check S1 "agent spawn $name" cli.log cli agent spawn --type "${name#e2e-}" --name "$name"; done
+check S1 "task create" cli.log cli task create --type implementation --description "e2e: build the console"
+check S1 "a task with hostile text (ESC, bidi override) is stored as given" cli.log cli task create --type implementation --description "$(printf 'evil\033[31m\u202eTEXT')"
+
+# The agent store keeps type and id, not the --name given at spawn: agents are found by type, newest first.
+AGENT() { json "const s=require(process.argv[1]+'/.claude-flow/agents/store.json');const a=Object.values(s.agents).filter(a=>a.agentType==='$1').at(-1);process.stdout.write(a?a.agentId:'')"; }
+CODER="$(AGENT coder)"
+TESTER="$(AGENT tester)"
+TASK="$(json "const s=require(process.argv[1]+'/.claude-flow/tasks/store.json');const t=Object.values(s.tasks).filter(t=>String(t.description).startsWith('e2e: build')).at(-1);process.stdout.write(t?t.taskId:'')")"
+[[ -n "$CODER" && -n "$TESTER" && -n "$TASK" ]] && pass S1 "agent and task ids read back from disk" cli.log || fail S1 "agent and task ids read back from disk" cli.log
+exec_tool() { cli mcp exec -t "$1" -p "$2"; }
+check S1 "claims_claim the task for e2e-coder" cli.log exec_tool claims_claim "{\"issueId\":\"$TASK\",\"claimant\":\"agent:$CODER:coder\"}"
+release_two() { exec_tool claims_claim "{\"issueId\":\"e2e-issue-2-$RUN\",\"claimant\":\"agent:$TESTER:tester\"}" && exec_tool claims_release "{\"issueId\":\"e2e-issue-2-$RUN\",\"claimant\":\"agent:$TESTER:tester\"}"; }
+handoff_three() { exec_tool claims_claim "{\"issueId\":\"e2e-issue-3-$RUN\",\"claimant\":\"agent:$CODER:coder\"}" && exec_tool claims_handoff "{\"issueId\":\"e2e-issue-3-$RUN\",\"from\":\"agent:$CODER:coder\",\"to\":\"agent:$TESTER:tester\"}"; }
+mk_hive() { cli hive-mind init --topology hierarchical && cli hive-mind consensus --action propose --type design --value 'e2e: adopt the console'; }
+mk_memory() { cli memory init; cli memory store --key e2e-k1 --value 'console e2e one' --namespace e2e && cli memory store --key e2e-k2 --value 'console e2e two' --namespace e2e && cli memory search --query 'console e2e'; }
+# Policy administration (init, rules, budgets) refuses a non-interactive caller by design ("requires an interactive
+# local terminal"); the e2e does not fake a terminal to get past that guard. It reads the policy status instead.
+mk_policy() { cli policy status; }
+check S1 "claims_claim + claims_release e2e-issue-2-$RUN" cli.log release_two
+check S1 "claims_claim + claims_handoff e2e-issue-3-$RUN coder → tester" cli.log handoff_three
+check S1 "hive-mind init + a proposal" cli.log mk_hive
+check S1 "memory store x2 + search" cli.log mk_memory
+check S1 "hooks route" cli.log cli hooks route --task "write unit tests for the parser" --format json
+check S1 "policy status reads (adding a rule needs a person at a terminal, by design)" cli.log mk_policy
+CLAIM_IDS="$(json "const s=require(process.argv[1]+'/.claude-flow/claims/claims.json');process.stdout.write(Object.keys(s.claims).join(','))")"
+MEM_N="$( (cd "$PROJ" && $CLI memory stats --format json 2>/dev/null) | node -e "let t='';process.stdin.on('data',d=>t+=d).on('end',()=>{const j=JSON.parse(t.slice(t.indexOf('{')));process.stdout.write(String(j.entries.total))})" 2>/dev/null)"
+echo "claims=$CLAIM_IDS memory=$MEM_N coder=$CODER tester=$TESTER task=$TASK" >"$OUT/state.txt"
+if [[ ",$CLAIM_IDS," == *",$TASK,"* && ",$CLAIM_IDS," == *",e2e-issue-3-$RUN,"* && ",$CLAIM_IDS," != *",e2e-issue-2-$RUN,"* ]]; then
+ pass S1 "claims.json holds the claim and the handoff, not the released one" state.txt
+else
+ fail S1 "claims.json holds the claim and the handoff, not the released one" state.txt
+fi
+
+if [[ "$LIVE" != 1 ]]; then
+ for step in S2 S3 S4 S5; do skip "$step" "needs RUFLO_E2E_LIVE=1 (starts Claude Code with the person's login)" -; done
+ [[ "$TARGET" == repo ]] && { git -C "$REPO" status --porcelain >"$OUT/git-after.txt"; check S6 "git status unchanged by the run" git-after.txt diff -q "$OUT/git-before.txt" "$OUT/git-after.txt"; }
+ exit $((FAILED > 0))
+fi
+
+make_config "$PROJ" "$OUT/empty"
+
+# ---------------------------------------------------------------- 2. headless: /ruflo answers from the real state
+claude_p s2-status "$PROJ" "${PLUGINS[@]}" "/ruflo status"
+check S2 "the module loaded" s2-status.log has "$OUT/s2-status.log" "hooks module ruflo-console@inline loaded"
+check S2 "/ruflo registered and answered (topology, claims count)" s2-status.txt has "$OUT/s2-status.txt" "hierarchical"
+claude_p s2-help "$PROJ" "${PLUGINS[@]}" "/ruflo help"
+check S2 "/ruflo help lists the swarm subcommands" s2-help.txt has "$OUT/s2-help.txt" "/ruflo swarm pane|status|topology|claims|consensus"
+claude_p s2-mods "$PROJ" "${PLUGINS[@]}" "/ruflo mods"
+check S2 "/ruflo mods answered by ruflo-mods" s2-mods.txt has "$OUT/s2-mods.txt" "owns:"
+claude_p s2-swarm "$PROJ" "${PLUGINS[@]}" "/ruflo swarm status"
+check S2 "/ruflo swarm status answered by ruflo-swarm" s2-swarm.txt has "$OUT/s2-swarm.txt" "agents:"
+claude_p s2-dump-swarm "$PROJ" "${PLUGINS[@]}" "/ruflo dump swarm"
+check S2 "swarm view shows the real agents (ids from the store)" s2-dump-swarm.txt has "$OUT/s2-dump-swarm.txt" "$CODER"
+claude_p s2-dump-claims "$PROJ" "${PLUGINS[@]}" "/ruflo dump claims"
+check S2 "claims view shows the claim held by e2e-coder" s2-dump-claims.txt has "$OUT/s2-dump-claims.txt" "$TASK"
+check S2 "claims view shows the handoff to the tester" s2-dump-claims.txt has "$OUT/s2-dump-claims.txt" "→ tester"
+claude_p s2-dump-memory "$PROJ" "${PLUGINS[@]}" "/ruflo dump memory"
+check S2 "memory view shows the CLI's entry count ($MEM_N)" s2-dump-memory.txt grep -qE "^entries +${MEM_N} " "$OUT/s2-dump-memory.txt"
+for name in s2-status s2-help s2-mods s2-swarm s2-dump-swarm s2-dump-claims s2-dump-memory; do check S2 "no refused tree or failed hook ($name)" "$name.log" clean_log "$OUT/$name.log"; done
+
+# ---------------------------------------------------------------- 3. interactive pane under tmux
+tmux_start "$PROJ" "$OUT/s3.log" "${PLUGINS[@]}"
+check S3 "the session starts (MCP servers rejected, prompt ready)" s3-open.txt settle_dialogs
+tmux_cmd "/ruflo"
+check S3 "/ruflo opens the pane holding the keys (title strip, tabs, keys on)" s3-open.txt wait_for s3-open "keys on" 20
+tmux_keys 3
+check S3 "hotkey 3 switches to Claims" s3-claims.txt wait_for s3-claims "Claims ─" 10
+tmux_keys p
+check S3 "hotkey p opens the palette" s3-palette.txt wait_for s3-palette "Palette ─" 10
+tmux_keys Escape
+sleep 1
+tmux_cmd "/ruflo claims"
+wait_for s3-claims2 "Claims ─" 10 >/dev/null
+# Walk the selection to this run's claim: in the repo, other claims may come first.
+for _ in $(seq 1 12); do
+ tmux_shot s3-pick
+ grep -q "picked claim $TASK" "$OUT/s3-pick.txt" && break
+ tmux_keys j
+ sleep 1
+done
+check S3 "j walks the selection to this run's claim" s3-pick.txt has "$OUT/s3-pick.txt" "picked claim $TASK"
+tmux_keys l
+check S3 "release asks to confirm" s3-confirm.txt wait_for s3-confirm "Confirm: release" 10
+tmux_keys y
+check S3 "release ran and the pane saw it on disk" s3-released.txt wait_for s3-released "· on disk" 30
+AFTER="$(json "const s=require(process.argv[1]+'/.claude-flow/claims/claims.json');process.stdout.write(Object.keys(s.claims).join(','))")"
+echo "claims after release: $AFTER" >>"$OUT/state.txt"
+[[ ",$AFTER," != *",$TASK,"* ]] && pass S3 "re-read from disk: $TASK no longer claimed" state.txt || fail S3 "re-read from disk: $TASK still claimed" state.txt
+tmux_cmd "/ruflo swarm"
+wait_for s3-swarm "Swarm ─" 10 >/dev/null
+sleep 1
+mtimes() { stat -c %Y "$PROJ"/.claude-flow/agents/store.json "$PROJ"/.claude-flow/claims/claims.json "$PROJ"/.claude-flow/swarm/swarm-state.json 2>/dev/null | tr '\n' ' '; }
+BEFORE_MT="$(mtimes)"
+tmux_shot s3-anim-a
+sleep 0.45
+tmux_shot s3-anim-b
+[[ "$BEFORE_MT" == "$(mtimes)" ]] && pass S3 "the swarm files did not change between the two captures" state.txt || fail S3 "the swarm files changed between the captures" state.txt
+if ! diff -q <(stable s3-anim-a) <(stable s3-anim-b) >/dev/null; then pass S3 "two captures differ while the data is unchanged (animation runs)" s3-anim-a.ansi; else fail S3 "two captures identical: no animation" s3-anim-a.ansi; fi
+tmux_cmd "/ruflo close"
+sleep 2
+tmux_shot s3-closed-a
+sleep 1
+tmux_shot s3-closed-b
+if diff -q <(stable s3-closed-a) <(stable s3-closed-b) >/dev/null; then pass S3 "closed: two captures identical (animation stopped)" s3-closed-a.ansi; else fail S3 "closed: the screen still changes" s3-closed-a.ansi; fi
+check S3 "no refused tree or failed hook" s3.log clean_log "$OUT/s3.log"
+tmux_stop
+
+# ---------------------------------------------------------------- 4. auto-start from project settings, no --plugin-dir
+SETTINGS="$PROJ/.claude/settings.local.json"
+[[ -f "$SETTINGS" ]] && cp "$SETTINGS" "$OUT/settings.local.json.before"
+mkdir -p "$PROJ/.claude"
+cat >"$SETTINGS" <<JSON
+{
+ "extraKnownMarketplaces": { "ruflo": { "source": { "source": "directory", "path": "$REPO" } } },
+ "enabledPlugins": { "ruflo-mods@ruflo": true, "ruflo-swarm@ruflo": true, "ruflo-console@ruflo": true },
+ "env": { "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS": "1" }
+}
+JSON
+cp "$SETTINGS" "$OUT/settings.local.json"
+tmux_start "$PROJ" "$OUT/s4.log"
+settle_dialogs >/dev/null
+check S4 "the band shows at session start" s4-start.txt wait_for s4-start "◆ ruflo ·" 40
+check S4 "ruflo-console loaded from the directory marketplace (ruflo-console@ruflo)" s4.log has "$OUT/s4.log" "hooks module ruflo-console@ruflo loaded"
+check S4 "the cockpit auto-opened (200 columns: it docks)" s4-start.txt wait_for s4-start "1: Ovr" 15
+check S4 "it did not take the keys" s4-start.txt has "$OUT/s4-start.txt" "keys off"
+check S4 "no refused tree or failed hook" s4.log clean_log "$OUT/s4.log"
+tmux_stop
+# After an interactive start the marketplace is known to this config, so a headless run loads from it too.
+claude_p s4-plugins "$PROJ" "/ruflo dump plugins"
+if grep -q "hooks module ruflo-console@ruflo loaded" "$OUT/s4-plugins.log"; then
+ pass S4 "settings.local.json alone loads ruflo-console@ruflo from the directory marketplace" s4-plugins.log
+else
+ fail S4 "settings.local.json did not load ruflo-console@ruflo (see s4-plugins.log)" s4-plugins.log
+fi
+check S4 "plugins view lists the working tree's marketplace (40+ plugins)" s4-plugins.txt grep -qE "lists (4[0-9]|[5-9][0-9]) plugins" "$OUT/s4-plugins.txt"
+if [[ -f "$OUT/settings.local.json.before" ]]; then cp "$OUT/settings.local.json.before" "$SETTINGS"; else rm -f "$SETTINGS"; fi
+
+# ---------------------------------------------------------------- 5. negative paths
+claude_p s5-classic "$PROJ" --model haiku "Reply with the single word ok."
+check S5 "no mod loaded: classic hooks still fire (UserPromptSubmit)" s5-classic.log grep -qE "Hook UserPromptSubmit.*success" "$OUT/s5-classic.log"
+check S5 "no mod loaded: no hooks module in the log" s5-classic.log lacks "$OUT/s5-classic.log" "hooks module ruflo-console"
+check S5 "hostile task text rendered without ESC or bidi override" s2-dump-claims.txt bash -c "grep -q 'evil' '$OUT/s2-dump-claims.txt' && ! grep -qP '\x1b|\x{202e}' '$OUT/s2-dump-claims.txt'"
+mkdir -p "$OUT/empty"
+for view in overview swarm claims federation plugins learning metaharness memory cost timeline approvals events; do
+ claude_p "s5-empty-$view" "$OUT/empty" "${PLUGINS[@]}" "/ruflo dump $view"
+ check S5 "empty project: $view draws, nothing undefined or NaN" "s5-empty-$view.txt" bash -c "test -s '$OUT/s5-empty-$view.txt' && ! grep -qE 'undefined|NaN|TypeError' '$OUT/s5-empty-$view.txt'"
+done
+check S5 "empty project: overview says n/a, not 0" s5-empty-overview.txt has "$OUT/s5-empty-overview.txt" "n/a — no swarm on disk"
+
+# ---------------------------------------------------------------- 6. the repo is untouched
+if [[ "$TARGET" == repo ]]; then
+ git -C "$REPO" status --porcelain >"$OUT/git-after.txt"
+ git -C "$REPO" diff --stat -- .claude/helpers v3/@claude-flow/cli/.claude/helpers >"$OUT/helpers-after.txt"
+ check S6 "git status unchanged (settings.local.json is gitignored and removed)" git-after.txt diff -q "$OUT/git-before.txt" "$OUT/git-after.txt"
+ check S6 ".claude/helpers unchanged" helpers-after.txt diff -q "$OUT/helpers-before.txt" "$OUT/helpers-after.txt"
+ check S6 "settings.local.json is gitignored" - git -C "$REPO" check-ignore -q .claude/settings.local.json
+ # A tracked file the run changed (say ruflo's memory writing agentdb.rvf) is reported above, then put back, but only
+ # when it was clean before the run: the run never discards a change it did not make.
+ comm -13 <(sort "$OUT/git-before.txt") <(sort "$OUT/git-after.txt") | awk '$1 == "M" { print $2 }' | while read -r path; do
+ git -C "$REPO" checkout -- "$path" && echo "restored $path" >>"$OUT/git-restored.txt"
+ done
+fi
+
+echo "evidence: $OUT"
+exit $((FAILED > 0))