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(ruflo-console): loop-centric missions: guidance, plan phases, settings and a Help guide (ADR-441)

ruv15e076ac9ed0
diff --git a/plugins/ruflo-console/hooks/goap.ts b/plugins/ruflo-console/hooks/goap.ts
index 1c2433b391..6f1e083ac3 100644
--- a/plugins/ruflo-console/hooks/goap.ts
+++ b/plugins/ruflo-console/hooks/goap.ts
@@ -320,6 +320,45 @@ export function toMissionPlan(p: Plan, budgetMinorPerUnit = 100) {
}
}
+/**
+ * How a mission is driven (ADR-441): a bounded `/loop` whose every tick checks progress, fixes failures and runs the named gates until
+ * the finish condition holds. Writers get isolated worktrees and disjoint files. These are the user's settings; the defaults are stated
+ * up front so the loop never stops to ask. Nothing leaves the mission branch (push, publish) unless its setting is on.
+ */
+export const LOOP_INTERVALS = ['2m', '5m', '10m', '15m', '30m'] as const
+export const WRITER_CAPS = [1, 2, 4, 6, 8] as const
+export type LoopPrefs = {
+ loopInterval: (typeof LOOP_INTERVALS)[number]
+ /** Every writing agent works in its own git worktree. */
+ loopWorktrees: boolean
+ /** The loop may commit to the mission branch. */
+ loopCommit: boolean
+ loopPush: boolean
+ loopPublish: boolean
+ loopWriters: (typeof WRITER_CAPS)[number]
+}
+export const DEFAULT_LOOP: LoopPrefs = { loopInterval: '5m', loopWorktrees: true, loopCommit: true, loopPush: false, loopPublish: false, loopWriters: 6 }
+
+/** Agents that change files; the rest (research, review, audit, validate) only read. */
+const WRITERS = new Set(['coder', 'tester', 'api-docs', 'adr-architect', 'specification', 'pseudocode', 'architecture', 'security-architect', 'cicd-engineer', 'reasoningbank-learner'])
+export const isWriter = (action: Action): boolean => WRITERS.has(action.agent)
+
+/** The named gates a tick runs, from what the plan must prove: always the tests, then each check the plan's goal asks for. */
+export function gatesOf(p: Plan): string[] {
+ const gates = ['the full test suite']
+ const add = (fact: string, gate: string) => p.goal.includes(fact) && gates.push(gate)
+
+ add('integrated', 'the build and smoke checks')
+ add('reviewed', 'the review')
+ add('secured', 'the security review')
+ add('benchmarked', 'the benchmark against the baseline')
+
+ return gates
+}
+
+/** The one line that starts the loop: `/loop <interval> <objective>`, the objective on one line and bounded. */
+export const loopCommand = (goal: string, prefs: LoopPrefs): string => `/loop ${prefs.loopInterval} ${goal.replace(/\s+/g, ' ').trim().slice(0, 200)}`
+
/** The stages a plan runs, in lifecycle order, each with how many steps it holds. */
export const lifecycleOf = (p: Plan): { stage: Stage; steps: number }[] =>
STAGES.map(stage => ({ stage, steps: p.steps.filter(step => stageOf(step.action) === stage).length })).filter(entry => entry.steps > 0)
diff --git a/plugins/ruflo-console/hooks/help-topics-core.ts b/plugins/ruflo-console/hooks/help-topics-core.ts
index 88227a30fe..c55e5e55d9 100644
--- a/plugins/ruflo-console/hooks/help-topics-core.ts
+++ b/plugins/ruflo-console/hooks/help-topics-core.ts
@@ -110,9 +110,26 @@ export const CORE_TOPICS: readonly HelpTopic[] = [
{ text: 'Pause or resume any time. Cancel stops the mission. Guide and aside ask Claude for help on it.' },
],
tips: ['Small, clear goals work best. “Add rate limiting to the login route” beats “improve the API”.'],
- related: ['claims', 'swarm', 'approvals'],
+ related: ['mission-loop', 'claims', 'swarm', 'approvals'],
keywords: ['goal', 'plan', 'sparc', 'tasks', 'objective', 'project'],
},
+ {
+ id: 'mission-loop',
+ title: 'Drive a mission with a loop',
+ group: 'Work',
+ summary: 'a bounded /loop that checks, fixes and runs the gates until done',
+ 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: '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'],
+ },
{
id: 'swarm',
title: 'Start a swarm and spawn agents',
diff --git a/plugins/ruflo-console/hooks/mission-guidance.ts b/plugins/ruflo-console/hooks/mission-guidance.ts
index 74f6e11aeb..65f494a992 100644
--- a/plugins/ruflo-console/hooks/mission-guidance.ts
+++ b/plugins/ruflo-console/hooks/mission-guidance.ts
@@ -57,7 +57,7 @@ export function guidancePrompt(state: State, mc: McState, plan: Plan): string {
`Kind: ${plan.profile}. Rigor: ${plan.rigor}. Lifecycle: ${lifecycleOf(plan).map(entry => entry.stage).join(' → ')}.`,
'',
'THE PLAN THE PLANNER MADE:',
- planText(plan, mc.goal),
+ planText(plan, mc.goal, ai),
'',
'THIS INSTALLATION:',
`- ruflo plugins loaded in the session: ${plugins.length === 0 ? 'none reported' : plugins.join(', ')}`,
@@ -65,10 +65,13 @@ export function guidancePrompt(state: State, mc: McState, plan: Plan): string {
`- AI settings: claude model ${ai.claudeModel}, turn budget $${ai.budgetUsd}, ${ai.autoAccept ? 'always accept' : 'asks before AI turns'}`,
`- Settings level: ${settingsOf(state).level}`,
'',
+ 'The mission runs as a loop (the LOOP lines above are the user\u2019s settings; keep to them, ask nothing mid-loop, and never go beyond what they allow).',
+ '',
'Write detailed guidance, in markdown with one short heading per lifecycle stage that the plan has (Research, Create (ADRs and the SOP), Build, Test, Validate, Secure, Benchmark, Learn).',
'Under each heading: what to do for THIS goal, the acceptance evidence, and which ruflo capabilities to bring in (name the exact agents, plugins, skills, MCP tools or ruflo commands that fit, and why), preferring what is installed here and saying plainly what is not.',
+ 'Then add a "Loop" heading: the exact `/loop` line, what each tick checks, fixes and runs (name the gates), the finish condition, the defaults taken, and the stop rule, in your own words for THIS goal. Where a stage has parallel writers, say who owns which files, each in its own worktree.',
'Then add: "Suggestions" (other ruflo capabilities worth integrating that the plan does not use, such as swarm or hive-mind for parallel work, memory and pattern search for prior art, AIDefence, MetaHarness audits, the flywheel for self-optimization), and "Risks" (what could go wrong and how the plan guards against it).',
- 'Keep it under 700 words. No preamble.',
+ 'Keep it under 800 words. No preamble.',
].join('\n')
}
diff --git a/plugins/ruflo-console/hooks/mission-text.ts b/plugins/ruflo-console/hooks/mission-text.ts
index f3fdfbe95c..884adb65ff 100644
--- a/plugins/ruflo-console/hooks/mission-text.ts
+++ b/plugins/ruflo-console/hooks/mission-text.ts
@@ -1,23 +1,57 @@
/** Mission Control as text for the transcript: the plan, the status, and what a headless `/ruflo run mission-…` answers. */
-import { lifecycleOf, type Plan, stageOf } from './goap'
+import { gatesOf, isWriter, lifecycleOf, loopCommand, type LoopPrefs, type Plan, stageOf } from './goap'
import { activeMission, derive, mcOf, nextTask, progressOf } from './mission-control'
+import { settingsOf } from './settings'
import type { State } from './state'
-/** The plan as text for the transcript (`/ruflo plan <goal>`): phases, waves and what each step must show. */
-export function planText(p: Plan, goal: string): string {
+type PlanStep = Plan['steps'][number]
+
+/**
+ * How the mission runs as a loop (ADR-441), as lines: the command, the per-tick checklist, the gates, the finish condition, the
+ * defaults taken up front (so nothing is asked mid-loop) and the stop rule. What may leave the branch follows the settings, only.
+ */
+export function loopLines(p: Plan, goal: string, prefs: LoopPrefs): string[] {
+ const commit = prefs.loopCommit ? 'commit to the mission branch only' : 'make no commits: leave changes in the worktree for review'
+ const push = prefs.loopPush ? 'the mission branch may be pushed to its remote' : 'do not push'
+ const publish = prefs.loopPublish ? 'releases or packages the mission names may be published' : 'do not publish, release or deploy'
+ const writers = `${prefs.loopWorktrees ? 'each writer in its own git worktree' : 'writers share the checkout, one at a time'}; at most ${prefs.loopWriters} concurrent writers on disjoint files`
+
+ return [
+ `LOOP: ${loopCommand(goal, prefs)} (every ${prefs.loopInterval}, bounded: it ends at the finish condition or the stop rule)`,
+ 'each tick: 1 check progress against the plan; 2 fix what failed; 3 run the gates; 4 repeat until every phase is complete and green',
+ `gates: ${gatesOf(p).join(', ')}; a gate counts only when its real output was read, and a fix is mutation-checked (break it once, see the test fail, restore)`,
+ 'finish when: every phase’s acceptance checks pass and every gate is green on the same clean commit; then stop the loop and report',
+ `defaults taken, not asked: ${prefs.loopInterval} interval; ${writers}; ${commit}; ${push}; ${publish}`,
+ 'stop and ask only when: a gate fails the same way three ticks running, an acceptance check cannot be met within the scope, or an action would leave the branch without its setting',
+ ]
+}
+
+/** What a step must show, and who may write while it runs: a writer owns its files alone; readers only read. */
+function stepNotes(step: PlanStep, waveWriters: number, prefs: LoopPrefs): string[] {
+ const notes = [` accept: ${step.action.requirement}`]
+
+ if (!isWriter(step.action)) return [...notes, ' read-only']
+
+ return [...notes, ` owns: ${waveWriters > 1 ? 'its own files, disjoint from the other writers in this wave' : 'the files it changes'}${prefs.loopWorktrees ? ', in its own worktree' : ''}`]
+}
+
+/** The plan as text for the transcript (`/ruflo plan <goal>`): phases, waves, what each step must show, and (given the loop settings) how the loop runs it. */
+export function planText(p: Plan, goal: string, loop?: LoopPrefs): string {
const lines = [`SPARC plan (${p.profile}, ${p.rigor}) for: ${goal}`, `${p.steps.length} tasks · cost ${p.totalCost} · critical path ${p.criticalCost} · ${p.waves.length} waves`, `lifecycle: ${lifecycleOf(p).map(entry => entry.stage).join(' → ')}`]
for (const [i, wave] of p.waves.entries()) {
- lines.push(`wave ${i + 1}:`)
+ const members = wave.map(id => p.steps.find(candidate => candidate.id === id)).filter((step): step is PlanStep => step !== undefined)
+ const writers = members.filter(step => isWriter(step.action)).length
- for (const id of wave) {
- const step = p.steps.find(candidate => candidate.id === id)
+ lines.push(`wave ${i + 1}:${loop !== undefined && writers > 1 ? ` (${Math.min(writers, loop.loopWriters)} of ${writers} writers at a time)` : ''}`)
- if (step !== undefined) lines.push(` ${step.id} [${stageOf(step.action)}] ${step.action.title}${step.dependsOn.length > 0 ? ` (after ${step.dependsOn.join(', ')})` : ''} — ${step.action.agent}`)
+ for (const step of members) {
+ lines.push(` ${step.id} [${stageOf(step.action)}] ${step.action.title}${step.dependsOn.length > 0 ? ` (after ${step.dependsOn.join(', ')})` : ''} — ${step.action.agent}`)
+ if (loop !== undefined) lines.push(...stepNotes(step, writers, loop))
}
}
- return lines.join('\n')
+ return (loop === undefined ? lines : [...lines, ...loopLines(p, goal, loop)]).join('\n')
}
/** The active mission's state for the transcript: progress, each task's status from the ruflo task store, and what is next. */
@@ -45,7 +79,7 @@ export function missionAnswer(state: State, paletteId: string | null): string |
const mc = mcOf(state)
- if (paletteId === 'mission-goal') return mc.planned === null ? 'type a goal after the id: /ruflo plan <goal>' : planText(mc.planned, mc.goal)
+ if (paletteId === 'mission-goal') return mc.planned === null ? 'type a goal after the id: /ruflo plan <goal>' : planText(mc.planned, mc.goal, settingsOf(state).ai)
if (paletteId === 'mission-status') return statusText(state)
return mc.last === null ? null : `${mc.last.ok ? '✓' : '✗'} ${mc.last.label}${mc.last.detail === '' ? '' : ` — ${mc.last.detail}`}`
diff --git a/plugins/ruflo-console/hooks/settings.ts b/plugins/ruflo-console/hooks/settings.ts
index 082ceb412d..c911b4ad75 100644
--- a/plugins/ruflo-console/hooks/settings.ts
+++ b/plugins/ruflo-console/hooks/settings.ts
@@ -11,6 +11,7 @@
import type { ActionSpec } from './actions'
import { plain } from './data/parse'
import { RUFLO_MARKET } from './data/snapshot'
+import { DEFAULT_LOOP, LOOP_INTERVALS, type LoopPrefs, WRITER_CAPS } from './goap'
import type { Host } from './host'
import type { Runner } from './runner'
import type { State } from './state'
@@ -44,8 +45,24 @@ export const CORE: readonly CoreKey[] = [
export const CLAUDE_MODELS = ['default', 'haiku', 'sonnet', 'opus'] as const
export 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 }
-export const DEFAULT_AI: AiPrefs = { claudeModel: 'default', budgetUsd: 1, autoAccept: false, guidance: true }
+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 }
+
+const ON_OFF = ['on', 'off'] as const
+const onOff = (value: boolean) => (value ? 'on' : 'off')
+
+/**
+ * The loop-centric mission rows (ADR-441), stored with the AI preferences: the Settings page maps over this list and calls
+ * `ctx.act.settings.ai(row.patch(value))`, so a row is one entry here, not new storage.
+ */
+export const LOOP_ROWS: readonly { id: string; title: string; description: string; extra: string; options: readonly string[]; current: (p: LoopPrefs) => string; isChanged: (p: LoopPrefs) => boolean; patch: (value: string) => Partial<LoopPrefs> }[] = [
+ { id: 'loop-interval', title: 'Mission loop interval', description: 'how often a mission’s /loop ticks: each tick checks progress, fixes failures and runs the gates (default 5m)', extra: 'loop tick cadence minutes', options: LOOP_INTERVALS, current: p => p.loopInterval, isChanged: p => p.loopInterval !== DEFAULT_LOOP.loopInterval, patch: value => ({ loopInterval: LOOP_INTERVALS.find(item => item === value) ?? DEFAULT_LOOP.loopInterval }) },
+ { id: 'loop-worktrees', title: 'Worktree per writer', description: 'each writing agent works in its own git worktree, on disjoint files, so concurrent writers never collide (default on)', extra: 'loop git worktree isolation writers', options: ON_OFF, current: p => onOff(p.loopWorktrees), isChanged: p => !p.loopWorktrees, patch: value => ({ loopWorktrees: value === 'on' }) },
+ { id: 'loop-commit', title: 'Loop may commit', description: 'the loop may commit to the mission branch, and nowhere else (default on)', extra: 'loop commit branch', options: ON_OFF, current: p => onOff(p.loopCommit), isChanged: p => !p.loopCommit, patch: value => ({ loopCommit: value === 'on' }) },
+ { id: 'loop-push', title: 'Loop may push', description: 'the loop may push the mission branch to its remote (default off: it stops at the branch and says so)', extra: 'loop push remote github', options: ON_OFF, current: p => onOff(p.loopPush), isChanged: p => p.loopPush, patch: value => ({ loopPush: value === 'on' }) },
+ { id: 'loop-publish', title: 'Loop may publish', description: 'the loop may publish releases or packages the mission names (default off: nothing is published without your word)', extra: 'loop publish release npm deploy', options: ON_OFF, current: p => onOff(p.loopPublish), isChanged: p => p.loopPublish, patch: value => ({ loopPublish: value === 'on' }) },
+ { id: 'loop-writers', title: 'Max concurrent writers', description: 'the most writing agents a mission loop runs at once (default 6)', extra: 'loop concurrent parallel agents', options: WRITER_CAPS.map(String), current: p => String(p.loopWriters), isChanged: p => p.loopWriters !== DEFAULT_LOOP.loopWriters, patch: value => ({ loopWriters: WRITER_CAPS.find(item => String(item) === value) ?? DEFAULT_LOOP.loopWriters }) },
+]
export const AI_KEY = 'ai-prefs'
export type SettingsState = {
@@ -258,7 +275,21 @@ export async function loadAiPrefs(state: State, host: Host): Promise<void> {
const model = CLAUDE_MODELS.find(candidate => candidate === stored?.claudeModel)
const budget = AI_BUDGETS.find(candidate => candidate === stored?.budgetUsd)
- settingsOf(state).ai = { claudeModel: model ?? DEFAULT_AI.claudeModel, budgetUsd: budget ?? DEFAULT_AI.budgetUsd, autoAccept: stored?.autoAccept === true, guidance: stored?.guidance !== false }
+ const flag = (key: keyof LoopPrefs, fallback: boolean) => (typeof stored?.[key] === 'boolean' ? (stored[key] as boolean) : fallback)
+
+ settingsOf(state).ai = {
+ claudeModel: model ?? DEFAULT_AI.claudeModel,
+ budgetUsd: budget ?? DEFAULT_AI.budgetUsd,
+ autoAccept: stored?.autoAccept === true,
+ guidance: stored?.guidance !== false,
+ loopInterval: LOOP_INTERVALS.find(item => item === stored?.loopInterval) ?? DEFAULT_LOOP.loopInterval,
+ loopWorktrees: flag('loopWorktrees', DEFAULT_LOOP.loopWorktrees),
+ loopCommit: flag('loopCommit', DEFAULT_LOOP.loopCommit),
+ // Leaving the branch is opt-in: only an explicit stored true turns these on.
+ loopPush: stored?.loopPush === true,
+ loopPublish: stored?.loopPublish === true,
+ loopWriters: WRITER_CAPS.find(item => item === stored?.loopWriters) ?? DEFAULT_LOOP.loopWriters,
+ }
}
export function saveAiPrefs(state: State, host: Host, patch: Partial<AiPrefs>): void {
diff --git a/plugins/ruflo-console/tests/goap.spec.ts b/plugins/ruflo-console/tests/goap.spec.ts
index 7c2ed33a7d..37f00f2da9 100644
--- a/plugins/ruflo-console/tests/goap.spec.ts
+++ b/plugins/ruflo-console/tests/goap.spec.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
-import { lifecycleOf, plan, profileOf, PROFILES, RIGORS, STAGES, toMissionPlan, type Plan } from '../hooks/goap'
+import { DEFAULT_LOOP, gatesOf, isWriter, lifecycleOf, loopCommand, plan, profileOf, PROFILES, RIGORS, STAGES, toMissionPlan, type Plan } from '../hooks/goap'
const must = (profile: Parameters<typeof plan>[0], rigor: Parameters<typeof plan>[1]): Plan => plan(profile, rigor) as Plan
const ids = (p: Plan) => p.steps.map(step => step.action.id)
@@ -133,3 +133,27 @@ describe('goal-oriented action planner over SPARC', () => {
expect(lifecycleOf(must('research', 'standard')).map(entry => entry.stage)).toContain('Learn')
})
})
+
+describe('loop-centric helpers (ADR-441)', () => {
+ it('the defaults are the stated ones: 5m, worktrees on, commit on, push and publish off, six writers', () => {
+ expect(DEFAULT_LOOP).toEqual({ loopInterval: '5m', loopWorktrees: true, loopCommit: true, loopPush: false, loopPublish: false, loopWriters: 6 })
+ })
+
+ it('the loop command is one bounded line carrying the interval', () => {
+ expect(loopCommand('add a\ndark mode', DEFAULT_LOOP)).toBe('/loop 5m add a dark mode')
+ expect(loopCommand('x', { ...DEFAULT_LOOP, loopInterval: '15m' })).toBe('/loop 15m x')
+ expect(loopCommand('y'.repeat(500), DEFAULT_LOOP).length).toBe('/loop 5m '.length + 200)
+ })
+
+ it('the gates always include the tests and follow what the plan must prove', () => {
+ expect(gatesOf(must('bugfix', 'lean'))).toEqual(['the full test suite', 'the build and smoke checks'])
+ expect(gatesOf(must('feature', 'thorough'))).toEqual(['the full test suite', 'the build and smoke checks', 'the review', 'the security review', 'the benchmark against the baseline'])
+ })
+
+ it('writers are the agents that change files; researchers and reviewers only read', () => {
+ const p = must('feature', 'standard')
+
+ expect(p.steps.filter(step => step.action.id === 'implement').every(step => isWriter(step.action))).toBe(true)
+ expect(p.steps.filter(step => ['research-context', 'review', 'security-review'].includes(step.action.id)).some(step => isWriter(step.action))).toBe(false)
+ })
+})
diff --git a/plugins/ruflo-console/tests/mission-guidance.spec.ts b/plugins/ruflo-console/tests/mission-guidance.spec.ts
index b8bd9ec559..1cba642d5b 100644
--- a/plugins/ruflo-console/tests/mission-guidance.spec.ts
+++ b/plugins/ruflo-console/tests/mission-guidance.spec.ts
@@ -10,7 +10,9 @@ import type { Host } from '../hooks/host'
import { guidanceArgv, guidancePrompt, guidanceSpec, guidanceStatus, offerGuidance, pluginsOf, startGuidance, type Guidance } from '../hooks/mission-guidance'
import { mcOf, setGoal } from '../hooks/mission-control'
import type { Runner } from '../hooks/runner'
-import { saveAiPrefs, settingsOf } from '../hooks/settings'
+import { DEFAULT_AI, loadAiPrefs, LOOP_ROWS, saveAiPrefs, settingsOf } from '../hooks/settings'
+import { planText } from '../hooks/mission-text'
+import { TOPICS } from '../hooks/help-topics'
import { newState, type State } from '../hooks/state'
const json = (value: unknown) => `${JSON.stringify(value)}\n`
@@ -210,3 +212,89 @@ describe('mission guidance', () => {
expect(mcOf(state).guidance?.lines.join('')).toBe('ok red end')
})
})
+
+describe('loop-centric missions (ADR-441)', () => {
+ const promptWith = (patch: Partial<typeof DEFAULT_AI> = {}): string => {
+ const state = ready()
+
+ settingsOf(state).ai = { ...settingsOf(state).ai, ...patch }
+
+ return guidancePrompt(state, mcOf(state), mcOf(state).planned as never)
+ }
+
+ it('the guidance names the loop: its interval, per-tick checklist, gates, finish condition, defaults and stop rule', () => {
+ const prompt = promptWith()
+
+ expect(prompt).toContain('LOOP: /loop 5m add a dark mode toggle to settings')
+ expect(prompt).toContain('each tick: 1 check progress')
+ expect(prompt).toContain('2 fix what failed; 3 run the gates')
+ expect(prompt).toContain('gates: the full test suite')
+ expect(prompt).toContain('finish when: every phase')
+ expect(prompt).toContain('defaults taken, not asked')
+ expect(prompt).toContain('stop and ask only when')
+ expect(prompt).toContain('Then add a "Loop" heading')
+ expect(promptWith({ loopInterval: '15m' })).toContain('/loop 15m add a dark mode')
+ })
+
+ it('the plan phases carry acceptance checks and file ownership: writers in their own worktrees, readers read-only', () => {
+ const state = ready()
+ const text = planText(mcOf(state).planned as never, mcOf(state).goal, settingsOf(state).ai)
+
+ expect(text).toContain('accept: the change, with the new tests passing and no others broken')
+ expect(text).toMatch(/owns: the files it changes, in its own worktree/)
+ expect(text).toContain('read-only')
+ expect(text).toMatch(/owns: its own files, disjoint from the other writers in this wave/)
+ expect(planText(mcOf(state).planned as never, mcOf(state).goal)).not.toContain('accept:')
+ expect(planText(mcOf(state).planned as never, mcOf(state).goal, { ...settingsOf(state).ai, loopWorktrees: false })).not.toContain('in its own worktree')
+ })
+
+ it('never tells Claude to push or publish unless the setting says so', () => {
+ const off = promptWith()
+
+ expect(off).toContain('do not push')
+ expect(off).toContain('do not publish, release or deploy')
+ expect(off).not.toMatch(/may be pushed|may be published/)
+
+ expect(promptWith({ loopPush: true })).toContain('the mission branch may be pushed to its remote')
+ expect(promptWith({ loopPush: true })).toContain('do not publish, release or deploy')
+ expect(promptWith({ loopPublish: true })).toContain('may be published')
+ expect(promptWith({ loopPublish: true })).toContain('do not push')
+ expect(promptWith({ loopCommit: false })).toContain('make no commits')
+ expect(promptWith({ loopWriters: 2 })).toContain('at most 2 concurrent writers')
+ })
+
+ it('the rows default as stated and each pick writes only its own key', () => {
+ expect(LOOP_ROWS.map(row => row.id)).toEqual(['loop-interval', 'loop-worktrees', 'loop-commit', 'loop-push', 'loop-publish', 'loop-writers'])
+ expect(LOOP_ROWS.map(row => row.current(DEFAULT_AI))).toEqual(['5m', 'on', 'on', 'off', 'off', '6'])
+ expect(LOOP_ROWS.some(row => row.isChanged(DEFAULT_AI))).toBe(false)
+ expect(LOOP_ROWS.map(row => row.patch(row.options.find(option => option !== row.current(DEFAULT_AI)) as string))).toEqual([{ loopInterval: '2m' }, { loopWorktrees: false }, { loopCommit: false }, { loopPush: true }, { loopPublish: true }, { loopWriters: 1 }])
+ expect(LOOP_ROWS[0]?.patch('7m')).toEqual({ loopInterval: '5m' })
+ })
+
+ it('stores and reloads the loop settings; a bad or missing stored value is the default, and leaving the branch needs an explicit true', async () => {
+ const state = newState({})
+ const saved = new Map<string, unknown>()
+ const host = { invalidate: () => undefined, storeSet: async (key: string, value: unknown) => void saved.set(key, value), storeGet: async (key: string) => saved.get(key) } as unknown as Host
+
+ saveAiPrefs(state, host, { loopInterval: '10m', loopPush: true, loopWriters: 4 })
+ settingsOf(state).ai = { ...DEFAULT_AI }
+ await loadAiPrefs(state, host)
+ expect(settingsOf(state).ai).toMatchObject({ loopInterval: '10m', loopPush: true, loopWriters: 4, loopPublish: false, loopWorktrees: true })
+
+ saved.set('ai-prefs', { loopInterval: '7m', loopPush: 'yes', loopPublish: 1, loopWriters: 99, loopCommit: 'no' })
+ await loadAiPrefs(state, host)
+ expect(settingsOf(state).ai).toMatchObject({ loopInterval: '5m', loopPush: false, loopPublish: false, loopWriters: 6, loopCommit: true })
+
+ saved.delete('ai-prefs')
+ await loadAiPrefs(state, host)
+ expect(settingsOf(state).ai).toEqual(DEFAULT_AI)
+ })
+
+ it('has a Help guide on loop-centric missions, linked from the mission guide', () => {
+ const guide = TOPICS.find(topic => topic.id === 'mission-loop')
+
+ expect(guide?.steps.some(step => /5m/.test(step.text) && /push and publish are off/.test(step.text))).toBe(true)
+ expect(guide?.steps.map(step => step.text).join(' ')).toMatch(/finish condition/)
+ expect(TOPICS.find(topic => topic.id === 'mission')?.related).toContain('mission-loop')
+ })
+})
diff --git a/v3/docs/adr/ADR-441-loop-centric-missions.md b/v3/docs/adr/ADR-441-loop-centric-missions.md
new file mode 100644
index 0000000000..39bb6b012e
--- /dev/null
+++ b/v3/docs/adr/ADR-441-loop-centric-missions.md
@@ -0,0 +1,45 @@
+# ADR 441: Loop-centric missions: settings, guidance and plan phases
+
+Status: Proposed
+
+Date: 2026 10 04
+
+Scope: `plugins/ruflo-console` (mission guidance, the GOAP plan text, Settings, Help)
+
+Source: ADR 438 §1 (loop-centric missions). The approach is the one used to build the research-integration mission itself.
+
+## 1. Decision
+
+A mission is driven as a bounded loop, and the console's settings and guidance prompts say so and default to it.
+
+- **The loop.** `/loop <interval> <objective>`, default `5m`. Each tick (1) checks progress against the plan, (2) fixes what failed, (3) runs the named gates, (4) repeats until every phase is complete and green.
+- **Gates** come from the plan: always the full test suite, then the build and smoke checks, the review, the security review and the benchmark when the plan's goal asks for them. A gate counts only when its real output was read; a fix is mutation-checked (break it once, see the test fail, restore).
+- **Finish condition**, stated up front: every phase's acceptance checks pass and every gate is green on the same clean commit. Then the loop stops and reports.
+- **Defaults are stated, not asked**, so there are no mid-loop questions. The loop stops to ask only when a gate fails the same way three ticks running, an acceptance check cannot be met within the scope, or an action would leave the branch without its setting.
+- **Concurrent writers** work in isolated git worktrees on disjoint files; readers (research, review, audit, validate) only read. Plan waves show how many writers run at once (capped) and who owns what. Each plan step carries its acceptance check.
+- **Nothing leaves the branch without a setting.** Commits go to the mission branch only; push and publish are off by default, and the guidance says "do not push" / "do not publish, release or deploy" unless the setting is on.
+
+Surfaces: `loopLines` and `planText` (mission-text.ts) render the loop; `guidancePrompt` (mission-guidance.ts) carries it to Claude and asks for a "Loop" section; `goap.ts` holds the types, defaults, gates and writer roles; `settings.ts` stores the preferences with the AI preferences; Help has the guide `mission-loop`.
+
+## 2. Settings (stored with the AI preferences, key `ai-prefs`)
+
+| Row | Default | Choices |
+|---|---|---|
+| Mission loop interval | 5m | 2m 5m 10m 15m 30m |
+| Worktree per writer | on | on, off |
+| Loop may commit (mission branch) | on | on, off |
+| Loop may push | off | on, off |
+| Loop may publish | off | on, off |
+| Max concurrent writers | 6 | 1 2 4 6 8 |
+
+A bad or missing stored value is the default. Push and publish turn on only from an explicit stored `true`. `LOOP_ROWS` in `settings.ts` is the row list; the Settings page maps over it.
+
+## 3. Constraints
+
+- No new storage, no plugin.json `userConfig` key, no new network call. The console only prepares text; it never commits, pushes or publishes.
+- Defaults are the user's to change; the setting, not the prompt, decides what may leave the branch.
+
+## 4. Not decided here
+
+- Whether a loop line should be offered as a one-press start from the Missions page: left to the Missions owner.
+- Per-profile intervals (a bug fix may want a shorter tick than a security review) are deferred.