🌊 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
feat(ruflo-console): missions Claude knows about, gate evidence, mission spend and a loop manager (ADR-443)
ruv3ed6c7963b4a
diff --git a/plugins/ruflo-console/.claude-plugin/plugin.json b/plugins/ruflo-console/.claude-plugin/plugin.jsonindex 280c50344c..eff5be1bc7 100644--- a/plugins/ruflo-console/.claude-plugin/plugin.json+++ b/plugins/ruflo-console/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "ruflo-console","description": "ruflo's cockpit inside Claude Code and the one /ruflo command for every ruflo mod (function hooks, early access). Views: overview with health alerts, swarm topology graph, claims flow with TTL rings, federation map, plugin health matrix, learning curve and pipeline, MetaHarness radar and audit trend, memory, cost gauge, agent timeline, approvals queue, event stream, a main menu, an x.ruv.io federation board, an AI terminal (codex, claude or both in remembered sessions, streamed), Skills (npx skills), a Hive-Mind view, a MetaHarness lab, agent drill-down; a command palette for confirm-gated actions through the ruflo CLI; a band above the prompt. Reads ruflo's files and the CLI's local JSON; anything not measured reads n/a. The one network call it makes by itself is a daily read of the published plugin.json at github.com/ruvnet/ruflo to offer an update (Settings → Updates: ask, auto, or off); it installs only through Claude Code's own claude plugin update, and never a new major version without asking.",- "version": "0.28.1",+ "version": "0.29.0","author": {"name": "ruvnet","url": "https://github.com/ruvnet"diff --git a/plugins/ruflo-console/hooks/bindings.ts b/plugins/ruflo-console/hooks/bindings.tsindex 2c3a6bb5f1..fb7eae5ae5 100644--- a/plugins/ruflo-console/hooks/bindings.ts+++ b/plugins/ruflo-console/hooks/bindings.ts@@ -30,6 +30,7 @@ import { skillActions } from './skills'import { moreSkillActions } from './skills-lab'import { CLI_PREFIXES, NAV_KEY, PANE_ID, viewOf, type State } from './state'import { runUpdateCheck } from './update-flow'+import { claudeActions } from './mission-claude'import { UPDATES_KEY } from './updates'import { vectorActions } from './vector'import type { Actions } from './views/common'@@ -360,7 +361,7 @@ export function actionsOf(state: State, host: Host, runner: Runner, steps: Stepsvector: vectorActions(state, runner, text => actions.term.load('claude', text)),evolve: evolveActions(state, host, text => actions.term.ask('claude', text)),settings: settingsActions(state, host, runner, (agent, text) => actions.term.ask(agent, text), () => CLI_PREFIXES[state.options.cli], () => pluginNames(state, (catalogOf(state).plugins ?? []).filter(plugin => plugin.options.length > 0).map(plugin => plugin.name))),- mission: missionActions(state, host, runner),+ mission: { ...missionActions(state, host, runner), ...claudeActions(state, host, runner) },ask: askActions(state, host, runner, () => actions),ruhelp: helpActions(state, host, runner, () => actions),loops: loopActions(state, host, runner),diff --git a/plugins/ruflo-console/hooks/controller.ts b/plugins/ruflo-console/hooks/controller.tsindex 72a7d528f4..8970c86ce7 100644--- a/plugins/ruflo-console/hooks/controller.ts+++ b/plugins/ruflo-console/hooks/controller.ts@@ -6,7 +6,7 @@import { actionsOf } from './bindings'import type { Catalog } from './data/catalog'import { PROBES, probeArgv, probeReady, type ProbeResult } from './data/cli'-import { COST_PROBES } from './data/cost-ledger'+import { ALL_COST_PROBES as COST_PROBES } from './data/cost-probes'import { X_PROBES } from './data/xruv'import { diffEvents, record } from './data/events'import { plain } from './data/parse'diff --git a/plugins/ruflo-console/hooks/data/cost-probes.ts b/plugins/ruflo-console/hooks/data/cost-probes.tsnew file mode 100644index 0000000000..75b81d513a--- /dev/null+++ b/plugins/ruflo-console/hooks/data/cost-probes.ts@@ -0,0 +1,37 @@+/**+ * Every probe of the cost-tracker plugin's ledger: the Cost page's seven-day reading, and the active mission's spend (ADR-443). The+ * mission's needs a newer tracker than the Cost page's (the `--from`, `--to` and `--project` filters), so an older one is "not ready",+ * and the probe does not run. Local only: nothing here reaches the network.+ */+import { activeMission } from '../mission-control'+import { bumpKind, parseSemver } from '../updates'+import type { State } from '../state'+import { COST_PLUGIN, costLedgerProbe, trackerOf } from './cost-ledger'+import { missionCostArgv, parseMissionCost, type MissionCost } from './mission-cost'+import type { Probe } from './cli'++/** The first tracker release whose ledger takes the window and project filters. */+export const MISSION_COST_FROM = '0.27.1'++function missionCostArgs(state: State): readonly string[] | null {+ const tracker = trackerOf(state)+ const mission = activeMission(state)++ if (tracker.kind !== 'ready' || mission === null) return null++ const version = state.snapshot?.plugins.installed?.find(plugin => plugin.id === COST_PLUGIN)?.version ?? ''++ // Older than the filters (or not a version we can read): not ready, never guessed at.+ if (parseSemver(version) === null || bumpKind(version, MISSION_COST_FROM) !== null) return null++ // A finished or cancelled mission's window closes at its last event; a live one stays open at the right.+ const end = mission.cancelled ? Math.max(mission.createdAtMs, ...mission.events.map(event => event.atMs)) : null++ return missionCostArgv(tracker.root, mission.createdAtMs, end, state.cwd)+}++export const missionCostProbe: Probe<MissionCost> = {+ id: 'mission-cost', args: [], argvOf: missionCostArgs, views: ['missions'], everyMs: 120_000, timeoutMs: 60_000, parse: parseMissionCost,+}++export const ALL_COST_PROBES = [costLedgerProbe, missionCostProbe] as constdiff --git a/plugins/ruflo-console/hooks/data/mission-cost.ts b/plugins/ruflo-console/hooks/data/mission-cost.tsindex 62594a7606..0ed4159653 100644--- a/plugins/ruflo-console/hooks/data/mission-cost.ts+++ b/plugins/ruflo-console/hooks/data/mission-cost.ts@@ -9,7 +9,7 @@ import { jsonAfter } from './cli'import { safeInstallPath } from './cost-ledger'import { numberOf, plain, recordOf } from './parse'-export type MissionCost = { usd: number | null; credits: number | null; unpriced: string[]; rows: number }+export type MissionCost = { usd: number | null; credits: number | null; unpriced: string[]; rows: number; /** The window's start the ledger reports back: it says which mission the reading is for. */ fromMs: number | null }export type CapLevel = 'none' | 'OK' | 'INFO' | 'WARNING' | 'CRITICAL' | 'HARD_STOP'export type CapState = { level: CapLevel; percent: number | null }@@ -55,9 +55,17 @@ export function parseMissionCost(stdout: string): MissionCost | null {credits: credits !== undefined && credits >= 0 ? credits : null,unpriced: Object.keys(recordOf(value.unpriced) ?? {}).slice(0, 10).map(name => plain(name, 50)),rows,+ fromMs: windowFromMs(value.window),}}+function windowFromMs(window: unknown): number | null {+ const from = recordOf(window)?.from+ const ms = typeof from === 'string' ? Date.parse(from) : NaN++ return Number.isFinite(ms) ? ms : null+}+/** Where `spendUsd` sits on the ladder of `cap`; `none` without a spend or a cap. `percent` is the share of the cap used. */export function capState(spendUsd: number | null, cap: number | null): CapState {if (spendUsd === null || cap === null || !Number.isFinite(spendUsd) || !Number.isFinite(cap) || cap <= 0 || spendUsd < 0) return { level: 'none', percent: null }diff --git a/plugins/ruflo-console/hooks/help-topics-core.ts b/plugins/ruflo-console/hooks/help-topics-core.tsindex e1d0b14806..41d9d60d40 100644--- a/plugins/ruflo-console/hooks/help-topics-core.ts+++ b/plugins/ruflo-console/hooks/help-topics-core.ts@@ -121,14 +121,15 @@ export const CORE_TOPICS: readonly HelpTopic[] = [steps: [{ text: 'Set the loop in Settings: the interval (5m by default), a worktree per writer, whether it may commit, push or publish (push and publish are off), and the most concurrent writers (6).', go: { view: 'settings' }, label: 'Open Settings' },{ text: 'Enter your goal. The plan and Claude’s guidance now name the /loop line, each tick’s checklist, the gates, the finish condition and the stop rule.', go: { view: 'missions' }, label: 'Open Missions' },- { text: 'Each tick the loop checks progress, fixes what failed, runs the gates (tests, build and smoke, and the checks the plan asks for), and repeats until every phase is green.' },- { text: 'Writers work at once, each in its own worktree on its own files. Each phase has acceptance checks, and a result counts when its real output was read.' },- { text: 'Defaults are stated up front, so the loop does not stop to ask. It stops only on the finish condition, or when a gate keeps failing the same way.' },+ { text: 'Each tick the loop checks progress, fixes what failed, runs the gates and repeats until every phase is green. Writers work at once, each in its own worktree; defaults are stated up front, so it does not stop to ask.' },+ { text: 'On a long mission open its Loop tab. Start puts the /loop line in your prompt box (you press Enter); the console counts ticks, shows the next one and the time left, and warns before the 7-day expiry. Re-arm prepares a fresh one.', go: { view: 'missions' }, label: 'Open Missions' },+ { text: 'Verify runs your own gate commands (Settings → Mission gates). Each asks first, runs without a shell, and its exit code is recorded as evidence.' },+ { text: 'Set a spend cap in Settings: auto-run pauses when the mission reaches it. Spend is a list-price estimate from the cost ledger.' },{ text: 'Nothing leaves the mission branch unless you turned it on: no push, no release, no deploy.' },],- tips: ['A fix is checked by breaking it once: the test must fail, then pass again.'],- related: ['mission', 'swarm', 'verify'],- keywords: ['loop', 'tick', 'interval', 'worktree', 'gates', 'finish', 'concurrent', 'writers', 'autopilot', 'defaults'],+ tips: ['A fix is checked by breaking it once: the test must fail, then pass again.', 'The active task rides in Claude’s prompt (Settings → Mission context) and changes only when the task does, so the cache stays warm.'],+ related: ['mission', 'swarm', 'verify', 'cost'],+ keywords: ['loop', 'tick', 'interval', 'worktree', 'gates', 'finish', 'concurrent', 'writers', 'autopilot', 'defaults', 'long', 'expire', 're-arm', 'cap', 'verify', 'evidence'],},{id: 'swarm',diff --git a/plugins/ruflo-console/hooks/mission-claude.ts b/plugins/ruflo-console/hooks/mission-claude.tsnew file mode 100644index 0000000000..0d293a5600--- /dev/null+++ b/plugins/ruflo-console/hooks/mission-claude.ts@@ -0,0 +1,185 @@+/**+ * Missions that Claude knows about (ADR-443): the glue between Mission Control and four pure modules. The context section Claude reads+ * every turn (mission-context.ts), gate evidence (mission-verify.ts), the loop manager (mission-loop.ts) and the mission's spend+ * (data/mission-cost.ts, mission-guard.ts). Nothing here reaches the network or runs anything unasked: a gate run and a loop hand-off+ * both go through the confirm row, and the loop is only ever prepared in the prompt box (Claude owns the schedule).+ */+import type { ActionSpec } from './actions'+import type { Host } from './host'+import { activeMission, derive, mcOf, nextTask, record, saveLedger } from './mission-control'+import { CONTEXT_SECTION_ID, contextEnabled, missionContextKey, missionContextText, turnNote, type TurnReason } from './mission-context'+import { armed, isTick, parseLoop, rearmCommand, startCommand, stop, stopRequest, tick, tickPlan, type LoopState } from './mission-loop'+import { evidenceEvent, parseGates } from './mission-verify'+import { costOf, capOf } from './mission-guard'+import { plain } from './data/parse'+import type { LedgerTask, MissionActions, MissionRecord } from './mission-types'+import type { Runner } from './runner'+import { settingsOf } from './settings'+import type { State } from './state'++/** The mission's loop as it was saved (validated; a bad value is no loop). */+export const loopOf = (mission: MissionRecord): LoopState | null => parseLoop(mission.loop)++const setLoop = (mission: MissionRecord, loop: LoopState): void => void (mission.loop = loop)++/** The task Claude is on, else the next ready one: what the context section describes. */+function currentTask(state: State, mission: MissionRecord): { task: LedgerTask | null; status: ReturnType<typeof derive> extends Map<string, infer S> ? S : never } {+ const tasks = state.snapshot?.tasks ?? []+ const statuses = derive(mission, tasks)+ const task = mission.tasks.find(candidate => statuses.get(candidate.id) === 'running') ?? nextTask(mission, tasks)++ return { task, status: task === null ? 'ready' : (statuses.get(task.id) ?? 'ready') }+}++let held: { key: string; text: string } | null = null++/**+ * The section `prompt.compose` adds, or null (no mission, a finished one, or the setting off). The text is rebuilt only when its key+ * changes, and the key changes only with the task: a changed system prompt makes Claude re-read the whole conversation.+ */+export function contextSection(state: State): { id: string; text: string; scope: 'session' } | null {+ const mission = activeMission(state)++ if (mission === null || !contextEnabled(settingsOf(state).ai.missionContext)) return null++ const statuses = derive(mission, state.snapshot?.tasks ?? [])++ if (mission.tasks.length > 0 && mission.tasks.every(task => statuses.get(task.id) === 'done')) return null++ const { task, status } = currentTask(state, mission)+ const loop = loopOf(mission)+ const info = loop === null || loop.status === 'idle' ? null : { interval: loop.interval, status: loop.status }+ const key = missionContextKey(mission, task, info, status)++ if (held?.key !== key) held = { key, text: missionContextText(mission, task, info, status) }++ return { id: CONTEXT_SECTION_ID, text: held.text, scope: 'session' }+}++/** A turn ended: note it on the running task (never that the task finished: the task store says that). */+export function onTurnComplete(state: State, host: Host, reason: TurnReason): void {+ const mission = activeMission(state)++ if (mission === null) return++ const running = mission.tasks.find(task => derive(mission, state.snapshot?.tasks ?? []).get(task.id) === 'running') ?? null+ const note = turnNote(reason, running)++ if (note === null) return++ record(mission, note)+ saveLedger(state, host)+}++/** A prompt was submitted: when it carries a mission's loop marker it is that loop's tick (or its first run). */+export function onPromptSubmit(state: State, host: Host, text: string): void {+ const now = Date.now()++ for (const mission of mcOf(state).missions.values()) {+ if (!isTick(text, mission.id)) continue++ const prefs = settingsOf(state).ai+ const before = loopOf(mission)+ const loop = before !== null && before.status === 'armed' ? before : armed(before, mission, before?.interval ?? prefs.loopInterval, now)+ const cost = costOf(state, mission)+ const plan = tickPlan({ mission, loop, prefs, gatesConfigured: parseGates(prefs.loopGates).gates.length > 0, spendUsd: cost?.usd ?? null, capUsd: capOf(state), nowMs: now, taskStatus: derive(mission, state.snapshot?.tasks ?? []) })++ setLoop(mission, tick(loop, now))+ record(mission, { type: 'loop.tick', note: plain(`${plan.action}: ${plan.reason}`, 200) })+ saveLedger(state, host)+ host.invalidate()+ }+}++/** The actions the Loop tab calls: verify with the person's gates, and the loop manager's start, stop and re-arm. */+export function claudeActions(state: State, host: Host, runner: Runner): Pick<MissionActions, 'verify' | 'loop'> {+ const say = (label: string, ok: boolean, detail: string) => {+ mcOf(state).last = { label, ok, detail }+ host.invalidate()+ }+ const prepare = (label: string, text: string, done: () => void): ActionSpec => ({+ label,+ scope: 'controls',+ args: [],+ shows: `in the prompt box, for you to send: “${plain(text, 160)}”`,+ expect: 'the text in Claude’s prompt box',+ note: 'Claude owns the recurring schedule; the console only prepares the text and watches the ticks. Nothing is scheduled until you press Enter there.',+ run: async () => {+ const isFilled = await host.fillPrompt(text).catch(() => false)++ if (isFilled) done()+ say(label, isFilled, isFilled ? 'prepared in the prompt box: press Enter there' : 'no prompt box to fill here')+ },+ })++ return {+ verify: () => {+ const mission = activeMission(state)+ const gates = parseGates(settingsOf(state).ai.loopGates).gates++ if (mission === null) return say('verify', false, 'no active mission')+ if (gates.length === 0) return say('verify', false, 'no gates configured: add your own commands in Settings → Mission gates')++ const { task } = currentTask(state, mission)+ const taskId = task?.id++ runner.ask(+ {+ label: `run ${gates.length} gate${gates.length === 1 ? '' : 's'}${taskId === undefined ? '' : ` for ${taskId}`}`,+ scope: 'controls',+ args: [],+ shows: gates.map(gate => gate.argv.join(' ')).join(' · '),+ expect: 'each gate’s exit code and a short output summary recorded as evidence on the mission',+ note: 'Runs the commands you configured, one after another, without a shell, in this project. Their output is evidence; nothing is changed by the console.',+ run: async () => {+ let failed = 0++ for (const gate of gates) {+ const result = await host.run(gate.argv, 180_000).catch(() => null)++ record(mission, evidenceEvent(gate, result === null ? { exitCode: null, stdout: '', stderr: '' } : { exitCode: result.exitCode ?? null, stdout: result.stdout, stderr: result.stderr }, taskId))+ if (result === null || result.exitCode !== 0) failed += 1+ }++ saveLedger(state, host)+ say('gates', failed === 0, failed === 0 ? `all ${gates.length} passed` : `${failed} of ${gates.length} did not pass: see Evidence`)+ },+ },+ 'nothing to run',+ )+ },+ loop: {+ start: () => {+ const mission = activeMission(state)++ if (mission === null) return say('loop', false, 'no active mission')++ const prefs = settingsOf(state).ai+ const interval = loopOf(mission)?.interval ?? prefs.loopInterval++ runner.ask(prepare('start the mission loop', startCommand(mission, prefs, interval), () => record(mission, { type: 'loop.prepared', note: `/loop ${interval}` })), 'no active mission')+ },+ stop: () => {+ const mission = activeMission(state)+ const loop = mission === null ? null : loopOf(mission)++ if (mission === null || loop === null) return say('loop', false, 'no loop to stop')++ runner.ask(prepare('ask Claude to stop the mission loop', stopRequest(loop, mission), () => {+ setLoop(mission, stop(loop))+ record(mission, { type: 'loop.stop-requested' })+ saveLedger(state, host)+ }), 'no loop to stop')+ },+ rearm: () => {+ const mission = activeMission(state)+ const loop = mission === null ? null : loopOf(mission)+ const command = mission === null ? null : rearmCommand(loop, mission, settingsOf(state).ai, Date.now())++ if (mission === null || command === null) return say('loop', false, 'the loop is not stopped, expired or overdue')++ runner.ask(prepare('re-arm the mission loop', command, () => record(mission, { type: 'loop.rearm-prepared' })), 'nothing to re-arm')+ },+ },+ }+}diff --git a/plugins/ruflo-console/hooks/mission-control.ts b/plugins/ruflo-console/hooks/mission-control.tsindex ab2665d07b..0ef8e91265 100644--- a/plugins/ruflo-console/hooks/mission-control.ts+++ b/plugins/ruflo-console/hooks/mission-control.ts@@ -9,6 +9,7 @@*/import type { ActionSpec } from './actions'import { PHASE_NAME, plan as planOf, stageOf, type Plan, type Profile, profileOf, type Rigor, toMissionPlan } from './goap'+import { isCapReached } from './mission-guard'import type { Host } from './host'import { plain, type TaskRecord } from './data/parse'import { isAvailable, MISSION_SKILLS, slashOf, GOALS_PLUGIN } from './mission-skills'@@ -374,6 +375,16 @@ export function advance(state: State, host: Host): void {if (mission === null || !mission.auto || state.turnActive) return+ // The spend cap (ADR-443): a reading at or past the person's cap pauses the mission instead of handing out the next task.+ if (isCapReached(state, mission)) {+ mission.paused = true+ record(mission, { type: 'cap.reached', note: 'spend cap reached: auto-run paused' })+ saveLedger(state, host)+ host.invalidate()++ return+ }+const task = nextTask(mission, state.snapshot?.tasks ?? [])if (task === null || isInflight(task)) returndiff --git a/plugins/ruflo-console/hooks/mission-guard.ts b/plugins/ruflo-console/hooks/mission-guard.tsnew file mode 100644index 0000000000..c6f8471132--- /dev/null+++ b/plugins/ruflo-console/hooks/mission-guard.ts@@ -0,0 +1,30 @@+/**+ * Auto-run's spend guard (ADR-443): a leaf module, so `advance()` in mission-control.ts can ask it without a cycle. The spend is the+ * cost ledger's reading for the mission's window and project (the `mission-cost` probe), a list-price estimate; the cap is the person's+ * own Settings value. No cap, no reading, or a reading for another mission means no pause: a missing number is never a reason to stop.+ */+import { capState, shouldPause, type MissionCost } from './data/mission-cost'+import { live } from './views/common'+import { settingsOf } from './settings'+import type { MissionRecord } from './mission-types'+import type { State } from './state'++/** The mission's cost reading, only while it is the one the probe was asked about (its window starts when the mission did). */+export function costOf(state: State, mission: MissionRecord): MissionCost | null {+ const cost = live<MissionCost>(state.probes.get('mission-cost'))++ return cost !== null && cost.fromMs === mission.createdAtMs ? cost : null+}++export const capOf = (state: State): number | null => {+ const text = settingsOf(state).ai.missionCapUsd++ return text === '' ? null : Number(text)+}++/** True when auto-run should stop handing out tasks because this mission's spend reached its cap. */+export function isCapReached(state: State, mission: MissionRecord): boolean {+ const cost = costOf(state, mission)++ return cost !== null && shouldPause(capState(cost.usd, capOf(state)), mission.auto)+}diff --git a/plugins/ruflo-console/hooks/mission-types.ts b/plugins/ruflo-console/hooks/mission-types.tsindex 37f5751824..82858e33c8 100644--- a/plugins/ruflo-console/hooks/mission-types.ts+++ b/plugins/ruflo-console/hooks/mission-types.ts@@ -2,6 +2,7 @@import type { Guidance } from './mission-guidance'import type { Screen } from './mission-options'import type { Plan, Profile, Rigor } from './goap'+import type { LoopActions } from './views/mission-loop'export type LedgerTask = { id: string; title: string; phase: string; stage?: string; agent: string; requirement: string; dependsOn: string[]; rufloTaskId?: string; dispatchedAtMs?: number }export type LedgerEvent = { seq: number; atMs: number; type: string; taskId?: string; status?: string; evidenceRef?: string; note?: string }@@ -18,8 +19,10 @@ export type MissionRecord = {cancelled: booleanauto: booleancreatedAtMs: number+ /** The mission's loop manager state (ADR-443), validated by parseLoop where it is read. */+ loop?: unknown}-export type McTab = 'plan' | 'tasks' | 'agents' | 'evidence' | 'record'+export type McTab = 'plan' | 'tasks' | 'agents' | 'evidence' | 'record' | 'loop'export type Derived = 'done' | 'running' | 'ready' | 'waiting' | 'failed' | 'cancelled'export type McState = {@@ -68,4 +71,8 @@ export type MissionActions = {capability: (slash: string) => void/** Turns the AIDefence screen of mission text on or off. */screen: (on: boolean) => void+ /** Runs the person's own gate commands on the active mission (asks first) and records each exit code as evidence. */+ verify: () => void+ /** The loop manager (ADR-443): prepares the /loop text, a stop request or a re-arm in the prompt box. */+ loop: LoopActions}diff --git a/plugins/ruflo-console/hooks/register.ts b/plugins/ruflo-console/hooks/register.tsindex ed058ab8ef..b8caedfc9c 100644--- a/plugins/ruflo-console/hooks/register.ts+++ b/plugins/ruflo-console/hooks/register.ts@@ -13,6 +13,7 @@ import { BAR_KEY, barView } from './views/bar'import { setBootChecks } from './boot-checks'import { buildOf, isOurCheckout, setBuild } from './build'import { runUpdateCheck } from './update-flow'+import { contextSection, onPromptSubmit, onTurnComplete } from './mission-claude'import { parseMode, RECHECK_EVERY_MS, UPDATES_KEY } from './updates'import { selfCheckResults } from './self-check'import type { Kit } from './views/common'@@ -335,6 +336,34 @@ export const register: Register = (on, raw: PluginOptions) => {on('turn.complete', ($, e, next) => {if (e.agentId === undefined) control?.markFrame('', false)+ if (e.agentId === undefined && host !== null) {+ try {+ onTurnComplete(state, host, e.reason)+ } catch {+ // A note that could not be recorded never changes the turn.+ }+ }++ return next(e)+ })++ // The mission Claude is working on rides in the system prompt (ADR-443); the text changes only when the task does.+ on('prompt.compose', async ($, e, next) => {+ const result = await next(e)+ const section = contextSection(state)++ return section === null ? result : { sections: [...result.sections, section] }+ })++ // A prompt carrying a mission's loop marker is that loop's tick.+ on('prompt.submit', ($, e, next) => {+ if (host !== null) {+ try {+ onPromptSubmit(state, host, e.text)+ } catch {+ // Counting a tick never blocks the prompt.+ }+ }return next(e)})diff --git a/plugins/ruflo-console/hooks/settings.ts b/plugins/ruflo-console/hooks/settings.tsindex c911b4ad75..54eec9589a 100644--- a/plugins/ruflo-console/hooks/settings.ts+++ b/plugins/ruflo-console/hooks/settings.ts@@ -45,8 +45,8 @@ export const CORE: readonly CoreKey[] = [export const CLAUDE_MODELS = ['default', 'haiku', 'sonnet', 'opus'] as constexport const AI_BUDGETS = [0.25, 0.5, 1, 2] as const/** `autoAccept`: claude, codex and swarm turns go straight out with no confirm (they stay read-only, in plan mode, under the budget); ruflo commands still ask. */-export type AiPrefs = { claudeModel: (typeof CLAUDE_MODELS)[number]; budgetUsd: (typeof AI_BUDGETS)[number]; autoAccept: boolean; /** Claude writes guidance after a mission goal is entered. */ guidance: boolean } & LoopPrefs-export const DEFAULT_AI: AiPrefs = { claudeModel: 'default', budgetUsd: 1, autoAccept: false, guidance: true, ...DEFAULT_LOOP }+export type AiPrefs = { claudeModel: (typeof CLAUDE_MODELS)[number]; budgetUsd: (typeof AI_BUDGETS)[number]; autoAccept: boolean; /** Claude writes guidance after a mission goal is entered. */ guidance: boolean; /** ADR-443: the active mission and task ride in Claude's prompt (changes only when the task changes). */ missionContext: boolean; /** ADR-443: the person's own gate commands, one per line or `\n`-separated (parseGates validates). */ loopGates: string; /** ADR-443: a USD cap for one mission's spend ('' none). */ missionCapUsd: string } & LoopPrefs+export const DEFAULT_AI: AiPrefs = { claudeModel: 'default', budgetUsd: 1, autoAccept: false, guidance: true, missionContext: true, loopGates: '', missionCapUsd: '', ...DEFAULT_LOOP }const ON_OFF = ['on', 'off'] as constconst onOff = (value: boolean) => (value ? 'on' : 'off')@@ -282,6 +282,9 @@ export async function loadAiPrefs(state: State, host: Host): Promise<void> {budgetUsd: budget ?? DEFAULT_AI.budgetUsd,autoAccept: stored?.autoAccept === true,guidance: stored?.guidance !== false,+ missionContext: stored?.missionContext !== false,+ loopGates: typeof stored?.loopGates === 'string' ? stored.loopGates.slice(0, 800) : '',+ missionCapUsd: typeof stored?.missionCapUsd === 'string' && /^\d{1,5}(\.\d{1,2})?$/.test(stored.missionCapUsd) ? stored.missionCapUsd : '',loopInterval: LOOP_INTERVALS.find(item => item === stored?.loopInterval) ?? DEFAULT_LOOP.loopInterval,loopWorktrees: flag('loopWorktrees', DEFAULT_LOOP.loopWorktrees),loopCommit: flag('loopCommit', DEFAULT_LOOP.loopCommit),diff --git a/plugins/ruflo-console/hooks/version.ts b/plugins/ruflo-console/hooks/version.tsindex 6eb4fb183b..adff5d234f 100644--- a/plugins/ruflo-console/hooks/version.ts+++ b/plugins/ruflo-console/hooks/version.ts@@ -2,4 +2,4 @@* The console's version, shown on the header so a person can tell which build is running. Kept equal to the plugin's manifest* (`.claude-plugin/plugin.json`); tests/version.spec.ts fails if the two drift.*/-export const CONSOLE_VERSION = '0.28.1'+export const CONSOLE_VERSION = '0.29.0'diff --git a/plugins/ruflo-console/hooks/views/mission-claude.ts b/plugins/ruflo-console/hooks/views/mission-claude.tsnew file mode 100644index 0000000000..2103a72747--- /dev/null+++ b/plugins/ruflo-console/hooks/views/mission-claude.ts@@ -0,0 +1,57 @@+import type { RenderElement } from 'claude-code'++import { button, kv, live, row, rule, sourceLine, text, type Ctx } from './common'+import { capOf, costOf } from '../mission-guard'+import { loopOf } from '../mission-claude'+import { tickPlan } from '../mission-loop'+import { derive } from '../mission-control'+import { parseGates, verdictOf } from '../mission-verify'+import { settingsOf } from '../settings'+import type { MissionRecord } from '../mission-types'+import { loopRows } from './mission-loop'+import { missionCostRows } from './mission-cost'++function verifyRows(ctx: Ctx, mission: MissionRecord): RenderElement[] {+ const prefs = settingsOf(ctx.state).ai+ const { gates, rejected } = parseGates(prefs.loopGates)+ const rows = [rule(ctx, 'Verify', gates.length === 0 ? 'no gates' : `${gates.length} gate${gates.length === 1 ? '' : 's'} · asks first`)]++ if (gates.length === 0) {+ rows.push(text(ctx, ' No gates: add your own commands in', { dimColor: true }))+ rows.push(text(ctx, ' Settings → Mission gates. Nothing is invented.', { dimColor: true }))+ } else {+ for (const gate of gates) rows.push(kv(ctx, gate.label.slice(0, 16), gate.argv.join(' ')))+ rows.push(row(ctx, [button(ctx, 'mc-verify', 'Run the gates…', () => ctx.act.mission.verify())]))+ }++ for (const item of rejected.slice(0, 3)) rows.push(text(ctx, ` skipped: ${item.line.slice(0, 30)} (${item.why})`, { dimColor: true }))++ const statuses = derive(mission, ctx.state.snapshot?.tasks ?? [])++ for (const task of mission.tasks.slice(0, 8)) {+ const verdict = verdictOf(mission, task.id, gates)++ rows.push(text(ctx, ` ${task.id.padEnd(4)} ${(statuses.get(task.id) ?? 'waiting').padEnd(8)} ${verdict.state}${verdict.state === 'no-gates' ? '' : `: ${verdict.detail}`}`.slice(0, 80), { dimColor: verdict.state === 'unverified' || verdict.state === 'no-gates' }))+ }++ return rows+}++/** The Loop tab: the loop manager, this mission's spend against its cap, and the gates that verify its tasks. */+export function loopTabRows(ctx: Ctx, mission: MissionRecord): RenderElement[] {+ const loop = loopOf(mission)+ const cost = costOf(ctx.state, mission)+ const prefs = settingsOf(ctx.state).ai+ const result = ctx.state.probes.get('mission-cost')+ const rows = [...loopRows(ctx, loop, ctx.act.mission.loop, ctx.nowMs)]++ if (loop !== null) {+ const plan = tickPlan({ mission, loop, prefs, gatesConfigured: parseGates(prefs.loopGates).gates.length > 0, spendUsd: cost?.usd ?? null, capUsd: capOf(ctx.state), nowMs: ctx.nowMs, taskStatus: derive(mission, ctx.state.snapshot?.tasks ?? []) })++ rows.push(kv(ctx, 'next tick', `${plan.action}: ${plan.reason}`.slice(0, 60)))+ }++ rows.push(...missionCostRows(ctx, cost, capOf(ctx.state), live(result) === null ? sourceLine(result, ctx.nowMs, 'mission spend').text : 'ledger: cost-tracker plugin'), ...verifyRows(ctx, mission))++ return rows+}diff --git a/plugins/ruflo-console/hooks/views/mission-control.ts b/plugins/ruflo-console/hooks/views/mission-control.tsindex 8b6dc240cf..8f22699ce6 100644--- a/plugins/ruflo-console/hooks/views/mission-control.ts+++ b/plugins/ruflo-console/hooks/views/mission-control.ts@@ -8,6 +8,7 @@ import { barCells, percentOf, stripStatus } from '../mission-strip'import { ago, button, clip, col, confirmHere, isBbs, row, rule, section, text, THEME, wrap, type Ctx } from './common'import { GOALS_PLUGIN, isAvailable, MISSION_SKILLS, slashOf } from '../mission-skills'import { observationRows } from './missions'+import { loopTabRows } from './mission-claude'import { capabilityRows, launchRows } from './mission-launch'import { researchStartRows } from './research-start'@@ -18,6 +19,7 @@ const TABS: readonly { id: McTab; label: string }[] = [{ id: 'tasks', label: 'Tasks' },{ id: 'agents', label: 'Agents' },{ id: 'evidence', label: 'Evidence' },+ { id: 'loop', label: 'Loop' },{ id: 'record', label: 'Record' },]@@ -237,7 +239,7 @@ export function missionControlView(ctx: Ctx): RenderElement {const tab = mission === null && mc.tab !== 'record' ? 'plan' : mc.tab- rows.push(...(mission === null ? (tab === 'record' ? observationRows(ctx) : planRows(ctx)) : tab === 'plan' ? planRows(ctx) : tab === 'tasks' ? tasksRows(ctx, mission) : tab === 'agents' ? agentsRows(ctx, mission) : tab === 'evidence' ? evidenceRows(ctx, mission) : recordRows(ctx, mission)))+ rows.push(...(mission === null ? (tab === 'record' ? observationRows(ctx) : planRows(ctx)) : tab === 'plan' ? planRows(ctx) : tab === 'tasks' ? tasksRows(ctx, mission) : tab === 'agents' ? agentsRows(ctx, mission) : tab === 'evidence' ? evidenceRows(ctx, mission) : tab === 'loop' ? loopTabRows(ctx, mission) : recordRows(ctx, mission)))return col(ctx, rows, 'mission-control')}diff --git a/plugins/ruflo-console/hooks/views/settings.ts b/plugins/ruflo-console/hooks/views/settings.tsindex eedee5b0dc..f5ef14f65f 100644--- a/plugins/ruflo-console/hooks/views/settings.ts+++ b/plugins/ruflo-console/hooks/views/settings.ts@@ -160,6 +160,9 @@ function aiItems(ctx: Ctx): Item[] {one('budget', 'Turn budget (USD)', 'claude -p --max-budget-usd: the most one turn may spend; the sandbox stays read-only', String(ai.budgetUsd), AI_BUDGETS.map(String), ai.budgetUsd !== DEFAULT_AI.budgetUsd, value => ctx.act.settings.ai({ budgetUsd: Number(value) as (typeof AI_BUDGETS)[number] }), 'cost spend cap'),one('guidance', 'Mission guidance', 'after a mission goal is entered, claude -p writes detailed guidance by lifecycle stage and suggests ruflo capabilities to bring in (it asks first unless always accept)', ai.guidance ? 'on' : 'off', ['on', 'off'], !ai.guidance, value => ctx.act.settings.ai({ guidance: value === 'on' }), 'mission goal guidance advice suggestions'),...LOOP_ROWS.map(row => one(row.id, row.title, row.description, row.current(ai), row.options, row.isChanged(ai), value => ctx.act.settings.ai(row.patch(value)), row.extra)),+ one('ctx-mission', 'Mission context in Claude’s prompt', 'the active mission and task ride in Claude’s system prompt, and change only when the task does (a changed prompt makes Claude re-read the chat)', ai.missionContext ? 'on' : 'off', ['on', 'off'], !ai.missionContext, value => ctx.act.settings.ai({ missionContext: value === 'on' }), 'mission context prompt cache claude'),+ one('loop-gates', 'Mission gates', 'your own commands a mission may run to verify a task, one per line; each asks first and shows its exact argv; no shell characters', ai.loopGates, [], ai.loopGates !== '', value => ctx.act.settings.ai({ loopGates: value.slice(0, 800) }), 'gates verify tests smoke evidence'),+ one('mission-cap', 'Mission spend cap (USD)', 'auto-run pauses when one mission’s spend reaches this (list-price estimate; empty means no cap)', ai.missionCapUsd, [], ai.missionCapUsd !== '', value => ctx.act.settings.ai({ missionCapUsd: /^\d{1,5}(\.\d{1,2})?$/.test(value.trim()) ? value.trim() : '' }), 'mission cap budget spend cost'),one('accept', 'Ask before each AI turn', 'always accept sends claude, codex and swarm turns straight out (read-only, plan mode, under the budget); ruflo commands still ask', ai.autoAccept ? 'always accept' : 'ask each time', ['ask each time', 'always accept'], ai.autoAccept, value => ctx.act.settings.ai({ autoAccept: value === 'always accept' }), 'confirm accept approve'),]}diff --git a/plugins/ruflo-console/scripts/smoke.sh b/plugins/ruflo-console/scripts/smoke.shindex 24616492f1..413e7c11ef 100755--- a/plugins/ruflo-console/scripts/smoke.sh+++ b/plugins/ruflo-console/scripts/smoke.sh@@ -11,9 +11,9 @@ step() { printf "→ %s ... " "$1"; }ok() { printf "PASS\n"; PASS=$((PASS+1)); }bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }-step "1. plugin.json declares ruflo-console 0.28.1"+step "1. plugin.json declares ruflo-console 0.29.0"grep -q '"name": "ruflo-console"' "$ROOT/.claude-plugin/plugin.json" \- && grep -q '"version": "0.28.1"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"+ && grep -q '"version": "0.29.0"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"step "2. hooks.json names exactly one module and no classic hook commands"grep -q '"modules": \["./register.ts"\]' "$HOOKS/hooks.json" && ! grep -q '"command"' "$HOOKS/hooks.json" \diff --git a/plugins/ruflo-console/tests/mission-claude.spec.ts b/plugins/ruflo-console/tests/mission-claude.spec.tsnew file mode 100644index 0000000000..8f6c9d27f6--- /dev/null+++ b/plugins/ruflo-console/tests/mission-claude.spec.ts@@ -0,0 +1,284 @@+/**+ * The wiring of ADR-443: the mission in Claude's prompt (changing only with the task), loop ticks recognised by their marker, gate+ * evidence, the loop manager's hand-offs, the spend cap in auto-run, the probe's readiness and the Loop tab. The pure modules have+ * their own specs; this is what joins them to Mission Control.+ */+import { describe, expect, it } from 'vitest'++import type { ActionSpec } from '../hooks/actions'+import { missionCostProbe } from '../hooks/data/cost-probes'+import type { TaskRecord } from '../hooks/data/parse'+import type { Host } from '../hooks/host'+import { claudeActions, contextSection, loopOf, onPromptSubmit, onTurnComplete } from '../hooks/mission-claude'+import { activeMission, advance, mcOf, record, type MissionRecord } from '../hooks/mission-control'+import { loopMarker } from '../hooks/mission-loop'+import type { Runner } from '../hooks/runner'+import { settingsOf } from '../hooks/settings'+import { newState, type State } from '../hooks/state'+import type { Actions } from '../hooks/views/common'+import { viewText } from '../hooks/views/pane'++const ID = `msn_${'a'.repeat(24)}`+const OTHER = `msn_${'b'.repeat(24)}`+const task = (id: string, status: string, tags: string[]): TaskRecord => ({ id, type: 'feature', description: '', status, assignedTo: [], tags })++const mission = (id = ID): MissionRecord => ({+ id,+ objective: 'add a dark mode toggle',+ profile: 'feature',+ rigor: 'standard',+ tasks: [+ { id: 't1', title: 'Specify', phase: 'S', agent: 'specification', requirement: 'a written specification', dependsOn: [], rufloTaskId: 'r1' },+ { id: 't2', title: 'Design', phase: 'A', agent: 'architecture', requirement: 'a design', dependsOn: ['t1'], rufloTaskId: 'r2' },+ ],+ acceptance: [{ id: 'ac-1', check: 'a specification exists' }],+ events: [],+ paused: false,+ cancelled: false,+ auto: false,+ createdAtMs: 1_000,+})++function stateWith(tasks: TaskRecord[], m: MissionRecord = mission()): State {+ const state = newState({})++ state.snapshot = { tasks, agents: [], claims: [], swarm: null, plugins: { missingFromClone: [], installed: [] }, alerts: [] } as never+ mcOf(state).missions.set(m.id, m)+ mcOf(state).active = m.id++ return state+}++const open = [task('r1', 'pending', [`mission:${ID}`, 'task:t1']), task('r2', 'pending', [`mission:${ID}`, 'task:t2'])]+const t1Done = [task('r1', 'completed', [`mission:${ID}`, 'task:t1']), task('r2', 'pending', [`mission:${ID}`, 'task:t2'])]+const t1Running = [task('r1', 'in_progress', [`mission:${ID}`, 'task:t1']), task('r2', 'pending', [`mission:${ID}`, 'task:t2'])]++function fakeHost() {+ const log = { runs: [] as (readonly string[])[], fills: [] as string[], stored: new Map<string, unknown>() }+ const host = {+ run: async (argv: readonly string[]) => {+ log.runs.push([...argv])++ return { exitCode: argv.includes('fail') ? 2 : 0, stdout: 'ok\n', stderr: '' }+ },+ storeGet: async (key: string) => log.stored.get(key),+ storeSet: async (key: string, value: unknown) => void log.stored.set(key, value),+ fillPrompt: async (text: string) => (log.fills.push(text), true),+ invalidate: () => undefined,+ after: () => ({ cancel: () => undefined }),+ } as unknown as Host++ return { host, log }+}++function fakeRunner() {+ const asked: ActionSpec[] = []+ const runner = { ask: (spec: ActionSpec | null) => void (spec !== null && asked.push(spec)) } as unknown as Runner++ return { runner, asked }+}++describe('the mission in Claude\'s prompt', () => {+ it('is absent without a mission, with the setting off, and once every task is done', () => {+ expect(contextSection(newState({}))).toBeNull()++ const off = stateWith(open)++ settingsOf(off).ai.missionContext = false+ expect(contextSection(off)).toBeNull()+ expect(contextSection(stateWith([task('r1', 'completed', [`mission:${ID}`, 'task:t1']), task('r2', 'completed', [`mission:${ID}`, 'task:t2'])]))).toBeNull()+ })++ it('names the mission and the task Claude is on, as a session section', () => {+ const section = contextSection(stateWith(t1Running))++ expect(section).toMatchObject({ id: 'ruflo-console:mission', scope: 'session' })+ expect(section?.text).toContain('add a dark mode toggle')+ expect(section?.text).toContain('Specify')+ })++ it('does not change when events pile up, only when the task does (a changed prompt makes Claude re-read the chat)', () => {+ const state = stateWith(t1Running)+ const first = contextSection(state)?.text++ for (let i = 0; i < 20; i++) record(activeMission(state) as MissionRecord, { type: 'turn', note: `turn ${i}` })+ expect(contextSection(state)?.text).toBe(first)++ state.snapshot = { ...(state.snapshot as object), tasks: t1Done } as never+ expect(contextSection(state)?.text).not.toBe(first)+ expect(contextSection(state)?.text).toContain('Design')+ })+})++describe('turns and loop ticks', () => {+ it('notes a turn on the running task and says nothing when no task is running', () => {+ const { host } = fakeHost()+ const running = stateWith(t1Running)+ const idle = stateWith(open)++ onTurnComplete(running, host, 'answer')+ onTurnComplete(idle, host, 'answer')+ expect(activeMission(running)?.events.map(event => event.type)).toEqual(['turn'])+ expect(activeMission(idle)?.events).toEqual([])+ })++ it('counts only a prompt that carries this mission\'s marker as a tick, arming the loop on the first', () => {+ const { host } = fakeHost()+ const state = stateWith(open, mission())+ const other = mission(OTHER)++ mcOf(state).missions.set(other.id, other)+ onPromptSubmit(state, host, 'just a prompt')+ onPromptSubmit(state, host, `${loopMarker(OTHER)} check progress`)+ expect(loopOf(activeMission(state) as MissionRecord)).toBeNull()+ expect(loopOf(other)?.ticks).toBe(1)++ onPromptSubmit(state, host, `/loop 5m ${loopMarker(ID)} check progress`)+ onPromptSubmit(state, host, `${loopMarker(ID)} check progress`)+ expect(loopOf(activeMission(state) as MissionRecord)).toMatchObject({ status: 'armed', ticks: 2 })+ expect(activeMission(state)?.events.filter(event => event.type === 'loop.tick')).toHaveLength(2)+ })+})++describe('verify and the loop manager', () => {+ it('says there are no gates rather than inventing any', () => {+ const { host } = fakeHost()+ const { runner, asked } = fakeRunner()+ const state = stateWith(t1Running)++ claudeActions(state, host, runner).verify()+ expect(asked).toEqual([])+ expect(mcOf(state).last).toMatchObject({ ok: false })+ expect(mcOf(state).last?.detail).toContain('no gates configured')+ })++ it('asks first with the exact commands, runs them without a shell, and records each exit code as evidence', async () => {+ const { host, log } = fakeHost()+ const { runner, asked } = fakeRunner()+ const state = stateWith(t1Running)++ settingsOf(state).ai.loopGates = 'npm test\nnode check.mjs fail'+ claudeActions(state, host, runner).verify()+ expect(asked).toHaveLength(1)+ expect(asked[0]?.shows).toContain('npm test')+ expect(log.runs).toEqual([])++ await asked[0]?.run?.()+ expect(log.runs).toEqual([['npm', 'test'], ['node', 'check.mjs', 'fail']])+ expect(activeMission(state)?.events.filter(event => event.type === 'evidence.gate').map(event => event.status)).toEqual(['passed', 'failed'])+ expect(mcOf(state).last?.ok).toBe(false)+ })++ it('refuses a gate with shell characters', () => {+ const { host } = fakeHost()+ const { runner, asked } = fakeRunner()+ const state = stateWith(t1Running)++ settingsOf(state).ai.loopGates = 'npm test; rm x'+ claudeActions(state, host, runner).verify()+ expect(asked).toEqual([])+ })++ it('prepares the /loop text (with the marker) in the prompt box only after the confirm, and schedules nothing itself', async () => {+ const { host, log } = fakeHost()+ const { runner, asked } = fakeRunner()+ const state = stateWith(open)++ claudeActions(state, host, runner).loop.start()+ expect(asked[0]?.shows).toContain('/loop 5m')+ expect(log.fills).toEqual([])++ await asked[0]?.run?.()+ expect(log.fills[0]).toContain(loopMarker(ID))+ expect(log.fills[0]?.startsWith('/loop 5m')).toBe(true)+ expect(activeMission(state)?.events.map(event => event.type)).toContain('loop.prepared')+ })++ it('has nothing to stop or re-arm without a loop', () => {+ const { host } = fakeHost()+ const { runner, asked } = fakeRunner()+ const state = stateWith(open)+ const actions = claudeActions(state, host, runner)++ actions.loop.stop()+ actions.loop.rearm()+ expect(asked).toEqual([])+ })+})++describe('the spend cap in auto-run', () => {+ const reading = (fromMs: number, usd: number) => ({ value: { usd, credits: null, unpriced: [], rows: 3, fromMs }, okAtMs: 1, error: null, errorAtMs: null, isRunning: false })++ it('pauses an auto-run mission whose spend reached its cap, and says so in the ledger', () => {+ const { host } = fakeHost()+ const state = stateWith(t1Running)+ const m = activeMission(state) as MissionRecord++ m.auto = true+ settingsOf(state).ai.missionCapUsd = '5'+ state.probes.set('mission-cost', reading(m.createdAtMs, 5))+ advance(state, host)+ expect(m.paused).toBe(true)+ expect(m.events.map(event => event.type)).toContain('cap.reached')+ })++ it('does not pause below the cap, with no cap, or on a reading for another mission', () => {+ for (const [cap, usd, from] of [['5', 4.99, 1_000], ['', 50, 1_000], ['5', 50, 999]] as const) {+ const { host } = fakeHost()+ const state = stateWith(t1Running)+ const m = activeMission(state) as MissionRecord++ m.auto = true+ settingsOf(state).ai.missionCapUsd = cap+ state.probes.set('mission-cost', reading(from, usd))+ advance(state, host)+ expect(m.paused, `${cap} ${usd} ${from}`).toBe(false)+ }+ })+})++describe('the mission spend probe', () => {+ const installed = (version: string) => ({ id: 'ruflo-cost-tracker@ruflo', name: 'ruflo-cost-tracker', marketplace: 'ruflo', version, scope: 'user', installPath: '/p/ruflo-cost-tracker/x' })+ const withTracker = (version: string | null, withMission = true) => {+ const state = withMission ? stateWith(open) : newState({})++ state.cwd = '/work/app'+ state.snapshot = { ...(state.snapshot ?? { tasks: [] }), plugins: { installed: version === null ? [] : [installed(version)], missingFromClone: [] } } as never++ return state+ }++ it('runs only with a mission and a tracker new enough to filter by window, and asks for that mission\'s window and project', () => {+ expect(missionCostProbe.argvOf?.(withTracker(null))).toBeNull()+ expect(missionCostProbe.argvOf?.(withTracker('0.27.0'))).toBeNull()+ expect(missionCostProbe.argvOf?.(withTracker('0.27.1', false))).toBeNull()++ const argv = missionCostProbe.argvOf?.(withTracker('0.27.1')) ?? []++ expect(argv.slice(0, 2)).toEqual(['node', '/p/ruflo-cost-tracker/x/scripts/ledger.mjs'])+ expect(argv).toContain('--project')+ expect(argv[argv.indexOf('--project') + 1]).toBe('/work/app')+ expect(argv[argv.indexOf('--from') + 1]).toBe(new Date(1_000).toISOString())+ expect(argv).not.toContain('--to')+ })+})++describe('the Loop tab and the Settings rows', () => {+ const act = { mission: { verify: () => undefined, loop: { start: () => undefined, stop: () => undefined, rearm: () => undefined } } } as unknown as Actions++ it('shows the loop manager, the mission\'s spend and the gates', () => {+ const state = stateWith(open)++ mcOf(state).tab = 'loop'++ const text = viewText({ state, nowMs: 5_000, columns: 100, act }, 'missions')++ for (const word of ['Loop manager', 'Mission spend', 'Verify', 'No gates']) expect(text, word).toContain(word)+ })++ it('lists the three new settings', () => {+ const text = viewText({ state: newState({}), nowMs: 5, columns: 110, act: {} as Actions }, 'settings')++ for (const title of ['Mission context in Claude', 'Mission gates', 'Mission spend cap']) expect(text, title).toContain(title)+ })+})diff --git a/plugins/ruflo-console/tests/mission-cost.spec.ts b/plugins/ruflo-console/tests/mission-cost.spec.tsindex be1e0e2c2f..886db6d27a 100644--- a/plugins/ruflo-console/tests/mission-cost.spec.ts+++ b/plugins/ruflo-console/tests/mission-cost.spec.ts@@ -37,9 +37,18 @@ describe('missionCostArgv', () => {})})+describe('parseMissionCost window',()=>{+ it('reads which window the ledger answered for, so a reading is never shown for another mission', () => {+ const out = JSON.stringify({ totals: { usd: 1 }, rows: 1, window: { from: '2026-10-04T00:00:00.000Z', to: null, project: '/p' } })++ expect(parseMissionCost(out)?.fromMs).toBe(Date.parse('2026-10-04T00:00:00.000Z'))+ expect(parseMissionCost(JSON.stringify({ totals: { usd: 1 }, window: { from: 'not a date' } }))?.fromMs).toBeNull()+ })+})+describe('parseMissionCost', () => {it('keeps USD and credits apart and lists unpriced models', () => {- expect(parseMissionCost(LEDGER({ unpriced: { 'gpt-5.6-sol': { messages: 3 } } }))).toEqual({ usd: 12.5, credits: 300, unpriced: ['gpt-5.6-sol'], rows: 4 })+ expect(parseMissionCost(LEDGER({ unpriced: { 'gpt-5.6-sol': { messages: 3 } } }))).toEqual({ usd: 12.5, credits: 300, unpriced: ['gpt-5.6-sol'], rows: 4, fromMs: null })})it('treats a window with no rows as a real zero, but all-unpriced rows as unknown', () => {diff --git a/plugins/ruflo-cost-tracker/.claude-plugin/plugin.json b/plugins/ruflo-cost-tracker/.claude-plugin/plugin.jsonindex 0adbd8778f..a70d367c25 100644--- a/plugins/ruflo-cost-tracker/.claude-plugin/plugin.json+++ b/plugins/ruflo-cost-tracker/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "ruflo-cost-tracker","description": "Token usage tracking, model cost attribution per agent, budget alerts, and optimization recommendations — uses memory_* (namespace-routed) for cost-tracking and cost-patterns; pairs with federation budget circuit breaker (ADR-097)",- "version": "0.27.0",+ "version": "0.27.1","author": {"name": "ruvnet","url": "https://github.com/ruvnet"diff --git a/plugins/ruflo-cost-tracker/scripts/smoke.sh b/plugins/ruflo-cost-tracker/scripts/smoke.shindex ec2cd4e5b2..e801060ba8 100755--- a/plugins/ruflo-cost-tracker/scripts/smoke.sh+++ b/plugins/ruflo-cost-tracker/scripts/smoke.sh@@ -1,5 +1,5 @@#!/usr/bin/env bash-# Structural smoke test for ruflo-cost-tracker v0.27.0.+# Structural smoke test for ruflo-cost-tracker v0.27.1.set -uROOT="$(cd "$(dirname "$0")/.." && pwd)"PASS=0@@ -8,10 +8,10 @@ step() { printf "→ %s ... " "$1"; }ok() { printf "PASS\n"; PASS=$((PASS+1)); }bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }-step "1. plugin.json declares 0.27.0 with new keywords"+step "1. plugin.json declares 0.27.1 with new keywords"v=$(grep -E '"version"' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)-if [[ "$v" != "0.27.0" ]]; then- bad "expected 0.27.0, got '$v'"+if [[ "$v" != "0.27.1" ]]; then+ bad "expected 0.27.1, got '$v'"elsemiss=""for k in namespace-routing mcp agentic-flow agent-booster tier1-routing model-routing benchmarking verified telemetry budget projection forecast counterfactual drift-detection trend-alert anomaly-detection outlier-detection health-check composite-gate auto-track stop-hook snapshot-diff pr-regression git-context traceability drill-down per-message; dodiff --git a/plugins/ruflo-cost-tracker/skills/cost-ledger/SKILL.md b/plugins/ruflo-cost-tracker/skills/cost-ledger/SKILL.mdindex 20ed594b47..1b106db177 100644--- a/plugins/ruflo-cost-tracker/skills/cost-ledger/SKILL.md+++ b/plugins/ruflo-cost-tracker/skills/cost-ledger/SKILL.md@@ -1,7 +1,7 @@---name: cost-ledgerdescription: One cost view across Claude Code and Codex on this machine — spend, tokens, cache hit ratio per provider and model, with unpriced models flagged. Use when asked "what did I spend", "how much did Codex cost", or to compare providers. Local logs only, nothing is sent.-argument-hint: "[--since 7d|24h|all] [--provider claude|codex|all] [--format json|markdown]"+argument-hint: "[--since 7d|24h|all] [--from <ISO> --to <ISO>] [--project <path>] [--provider claude|codex|all] [--format json|markdown]"allowed-tools: Bash---@@ -16,6 +16,10 @@ node ${CLAUDE_PLUGIN_ROOT}/scripts/ledger.mjs --since 7dnode ${CLAUDE_PLUGIN_ROOT}/scripts/ledger.mjs --provider codex --format json```+## One mission, or one project++`--from` and `--to` (ISO times) cut the window and `--project <absolute path>` keeps one project's rows; the console's mission page uses them for a mission's spend. An explicit `--from`/`--to` replaces the default 7-day look-back.+## Read the result correctly- **USD and Codex credits are never added.** GPT-6 Codex models are priced in credits; their cached-input rate is unpublished, so the figure is an upper bound.diff --git a/v3/docs/adr/ADR-443-mission-claude-integration.md b/v3/docs/adr/ADR-443-mission-claude-integration.mdindex c6687536ef..15fa10e60f 100644--- a/v3/docs/adr/ADR-443-mission-claude-integration.md+++ b/v3/docs/adr/ADR-443-mission-claude-integration.md@@ -1,6 +1,6 @@# ADR 443: Missions that Claude knows about, verified evidence, mission spend and a loop manager-Status: Proposed+Status: Accepted (ships in ruflo-console 0.29.0 with ruflo-cost-tracker 0.27.1)Date: 2026 10 04