π 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
fix(ruflo-console): stop pre-#4237 missions leaking into every project (#4254)
Mathew Beaneffc2b082791f
diff --git a/plugins/ruflo-console/.claude-plugin/plugin.json b/plugins/ruflo-console/.claude-plugin/plugin.jsonindex 1628f7da22..a97cffe92d 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.44.3",+ "version": "0.44.4","author": {"name": "ruvnet","url": "https://github.com/ruvnet"diff --git a/plugins/ruflo-console/CHANGELOG.md b/plugins/ruflo-console/CHANGELOG.mdindex a6b3aa80be..040d78f181 100644--- a/plugins/ruflo-console/CHANGELOG.md+++ b/plugins/ruflo-console/CHANGELOG.md@@ -2,6 +2,10 @@Newest first. One `## <version> β <date>` heading per version, then `feat:`, `fix:`, `breaking:` and `chore:` bullets (ADR-478). Built from git history; older versions: `git log -- plugins/ruflo-console`.+## 0.44.4 β 2026-10-18+- fix: the mission ledger is kept per project (#4237, #4242, thanks @kevin9327). One machine-wide key let the active mission of one project show in, and go into the prompt of, every other project, and two sessions in different projects overwrote each other. Each project now has its own key, and a new mission records the project it was made in. This shipped in 3.57.0 under the same 0.44.3 version, so `claude plugin update` never offered it.+- fix: missions from before per-project storage no longer leak into every project (#4254). The old shared key's missions with no project recorded were still taken into each project that opened, and saved into its own key. Now Mission Control offers them ("N missions from before per-project storage") with adopt here and not this project. Adopt records the project on them and takes them out of the old key; not this project keeps the offer away there. A mission the old key records for this project is taken in and removed from it without asking. A session that starts again in another directory begins with none of the last project's missions.+## 0.44.3 β 2026-10-15- fix: the rest of Mission Control's prose wraps at 80 columns (tmux) instead of ending in "β¦" (#3899): a launch step's detail (Claude's guidance note, the screen verdict, the next task's title) moves onto wrapped rows under its step when it does not fit beside it, and the "Create the mission and its tasks" label no longer runs into its detail; on the record, the expanded mission's state, plan, evidence, executor and blocked-reason lines, the stale and attention notes, the legend and the observation note wrap; the Mission options "not offered by this session" hint wraps.diff --git a/plugins/ruflo-console/hooks/mission-control.ts b/plugins/ruflo-console/hooks/mission-control.tsindex 4e02dec7e0..3d04f29d30 100644--- a/plugins/ruflo-console/hooks/mission-control.ts+++ b/plugins/ruflo-console/hooks/mission-control.ts@@ -23,29 +23,13 @@ import { CLI_PREFIXES, type State } from './state'import type { Derived, LedgerEvent, LedgerTask, McState, McTab, MissionActions, MissionRecord } from './mission-types'import { checkpointPlan } from './mission-advisor-live'+import { adoptLegacy, dismissLegacy, mcOf, saveLedger } from './mission-ledger'import { cancelSpec, createSpec, createWhy, dispatchSpec, isInflight, MAX_HANDOUTS, resultOf, setPaused } from './mission-specs'export { cancelSpec, createSpec, createWhy, dispatchSpec, resultOf, setPaused }+export { adoptLegacy, dismissLegacy, LEDGER_KEY, ledgerKeyOf, loadLedger, mcOf, saveLedger } from './mission-ledger'export type { Derived, LedgerEvent, LedgerTask, McState, McTab, MissionActions, MissionRecord } from './mission-types'-const states = new WeakMap<State, McState>()-/** The pre-#4237 ledger key, shared by every project on the machine. Read once per project as a fallback, never written for a known cwd. */-export const LEDGER_KEY = 'mission-ledger'--/** The mission ledger is per project, like the UI view (`storeKeyOf`): one machine-wide key let one project's active mission drive another's. */-export const ledgerKeyOf = (cwd: string): string => (cwd === '' ? LEDGER_KEY : `${LEDGER_KEY}:${cwd}`)--export function mcOf(state: State): McState {- let found = states.get(state)-- if (found === undefined) {- found = { goal: '', profile: 'feature', rigor: 'standard', isProfilePicked: false, planned: null, missions: new Map(), active: null, tab: 'plan', lastGuide: '', guidance: null, screen: null, isScreenOn: true, last: null }- states.set(state, found)- }-- return found-}-export const activeMission = (state: State): MissionRecord | null => {const mc = mcOf(state)@@ -149,42 +133,6 @@ export function record(mission: MissionRecord, event: Omit<LedgerEvent, 'seq' |if (mission.events.length > 500) mission.events.splice(0, mission.events.length - 500)}-export function saveLedger(state: State, host: Host): void {- const mc = mcOf(state)-- void host.storeSet(ledgerKeyOf(state.cwd), { active: mc.active, missions: [...mc.missions.values()].slice(-20) }).catch(() => undefined)-}--export async function loadLedger(state: State, host: Host): Promise<void> {- const key = ledgerKeyOf(state.cwd)- const own = await host.storeGet(key).catch(() => undefined)- // A project with no ledger of its own falls back to the old machine-wide one, keeping only missions not recorded for another project and- // never its `active`: that was whichever project wrote last (#4237).- const isLegacy = own === undefined && key !== LEDGER_KEY- const saved = isLegacy ? await host.storeGet(LEDGER_KEY).catch(() => undefined) : own- const missions = (saved as { missions?: unknown } | undefined)?.missions- const mc = mcOf(state)-- if (!Array.isArray(missions)) return-- for (const raw of missions.slice(0, 20)) {- const m = raw as MissionRecord-- if (m?.cwd !== undefined && m.cwd !== state.cwd) continue-- const isShaped = Array.isArray(m?.tasks) && m.tasks.every(task => typeof task?.id === 'string' && Array.isArray(task.dependsOn)) && Array.isArray(m.events)-- // Auto-run never survives a restart: a new session starts by asking.- if (typeof m?.id === 'string' && /^msn_[a-f0-9]{24}$/.test(m.id) && isShaped) mc.missions.set(m.id, { ...m, auto: false, ...(Array.isArray(m.adrs) && { adrs: m.adrs.filter(file => typeof file === 'string' && /^[A-Za-z0-9][A-Za-z0-9._ -]{0,119}\.md$/.test(file)).slice(0, 8) }) })- }-- if (isLegacy) return-- const active = (saved as { active?: unknown }).active-- if (typeof active === 'string' && mc.missions.has(active)) mc.active = active-}-/*** The longest text a person's goal, question, aside or instruction may be (ADR-481). These reach Claude as a prompt or a slash command's* arguments through the session (no argv, no stdin of ours), and the AIDefence screen and guidance turn take the same text, so one bound serves.@@ -359,6 +307,13 @@ export function missionActions(state: State, host: Host, runner: Runner): MissiosaveLedger(state, host)host.invalidate()},+ adoptLegacy: () => {+ void adoptLegacy(state, host).then(count => say(count === 0 ? 'nothing to adopt' : `adopted ${count} mission${count === 1 ? '' : 's'}`, count > 0, count === 0 ? 'no missions from before per-project storage are offered here' : 'recorded under this project and removed from the old shared ledger'))+ },+ dismissLegacy: () => {+ dismissLegacy(state, host)+ say('not this project\'s', true, 'the older missions stay in the shared ledger for the project they were made in')+ },next: () => {const mission = activeMission(state)diff --git a/plugins/ruflo-console/hooks/mission-ledger.ts b/plugins/ruflo-console/hooks/mission-ledger.tsnew file mode 100644index 0000000000..a27a2cc260--- /dev/null+++ b/plugins/ruflo-console/hooks/mission-ledger.ts@@ -0,0 +1,149 @@+/**+ * The mission ledger in the host store: one key per project (#4237), and what is left of the machine-wide key that came before it. A+ * mission recorded for this project is taken out of the old key on load; one that names no project is offered, never taken in unasked (#4254).+ */+import type { Host } from './host'+import type { McState, MissionRecord } from './mission-types'+import type { State } from './state'++const states = new WeakMap<State, McState>()+/** The pre-#4237 ledger key, shared by every project on the machine. Read by each project for missions to claim or offer; written only to take them out. */+export const LEDGER_KEY = 'mission-ledger'++/** The mission ledger is per project, like the UI view (`storeKeyOf`): one machine-wide key let one project's active mission drive another's. */+export const ledgerKeyOf = (cwd: string): string => (cwd === '' ? LEDGER_KEY : `${LEDGER_KEY}:${cwd}`)++export function mcOf(state: State): McState {+ let found = states.get(state)++ if (found === undefined) {+ found = { goal: '', profile: 'feature', rigor: 'standard', isProfilePicked: false, planned: null, missions: new Map(), active: null, legacy: [], isLegacyDismissed: false, tab: 'plan', lastGuide: '', guidance: null, screen: null, isScreenOn: true, last: null }+ states.set(state, found)+ }++ return found+}++type SavedLedger = { active?: unknown; missions?: unknown; legacyDismissed?: unknown }++/** The project a State's ledger was last loaded for: one State lives through every session.start, and the session may have moved. */+const loadedFor = new WeakMap<State, string>()++const writeLedger = (state: State, host: Host): Promise<void> => {+ const mc = mcOf(state)++ return host.storeSet(ledgerKeyOf(state.cwd), { active: mc.active, missions: [...mc.missions.values()].slice(-20), ...(mc.isLegacyDismissed && { legacyDismissed: true }) }).catch(() => undefined)+}++export function saveLedger(state: State, host: Host): void {+ void writeLedger(state, host)+}++/** A saved mission, or null when it is not shaped like one. Auto-run never survives a restart: a new session starts by asking. */+function missionOf(raw: unknown): MissionRecord | null {+ const m = raw as MissionRecord+ const isShaped = Array.isArray(m?.tasks) && m.tasks.every(task => typeof task?.id === 'string' && Array.isArray(task.dependsOn)) && Array.isArray(m.events)++ if (typeof m?.id !== 'string' || !/^msn_[a-f0-9]{24}$/.test(m.id) || !isShaped) return null++ return { ...m, auto: false, ...(Array.isArray(m.adrs) && { adrs: m.adrs.filter(file => typeof file === 'string' && /^[A-Za-z0-9][A-Za-z0-9._ -]{0,119}\.md$/.test(file)).slice(0, 8) }) }+}++const savedMissions = (saved: unknown): MissionRecord[] => {+ const missions = (saved as SavedLedger | undefined)?.missions++ return Array.isArray(missions) ? missions.slice(0, 20).flatMap(raw => missionOf(raw) ?? []) : []+}++/** Takes missions out of the old shared ledger once a project holds them. The host store has no delete, so an emptied ledger is left as `{ missions: [] }`. */+async function pruneShared(host: Host, ids: readonly string[]): Promise<void> {+ const saved = (await host.storeGet(LEDGER_KEY).catch(() => undefined)) as SavedLedger | undefined++ if (!Array.isArray(saved?.missions)) return++ const drop = new Set(ids)+ const left = saved.missions.filter(raw => !drop.has(String((raw as { id?: unknown } | null)?.id)))++ // Its `active` goes too: it was whichever project wrote last, and no project reads it (#4237).+ if (left.length < saved.missions.length) await host.storeSet(LEDGER_KEY, { missions: left }).catch(() => undefined)+}++/**+ * This project's missions, from its own key. The old machine-wide ledger (#4237) is read as well: a mission recorded for this project is+ * taken in and removed from it, and one that names no project is only offered (`mc.legacy`), because nothing says which project it was+ * made in (#4254). A copy of one that 0.44.3 wrote into this project's own key is offered the same way.+ */+export async function loadLedger(state: State, host: Host): Promise<void> {+ const cwd = state.cwd+ const mc = mcOf(state)++ if (loadedFor.get(state) !== cwd) {+ mc.missions.clear()+ mc.active = null+ mc.legacy = []+ mc.isLegacyDismissed = false+ loadedFor.set(state, cwd)+ }++ const key = ledgerKeyOf(cwd)+ const own = (await host.storeGet(key).catch(() => undefined)) as SavedLedger | undefined+ const shared = key === LEDGER_KEY ? [] : savedMissions(await host.storeGet(LEDGER_KEY).catch(() => undefined))++ // The session moved to another project while the store was read: that load is the one that counts.+ if (state.cwd !== cwd) return++ // With no project directory the old key is this ledger, and a mission with no project is its own.+ const isOurs = (m: MissionRecord) => m.cwd === cwd || (key === LEDGER_KEY && m.cwd === undefined)+ const offered = new Map<string, MissionRecord>()+ const claimed: string[] = []++ for (const m of savedMissions(own)) {+ if (isOurs(m)) mc.missions.set(m.id, m)+ else if (m.cwd === undefined) offered.set(m.id, m)+ }++ for (const m of shared) {+ if (isOurs(m)) {+ if (!mc.missions.has(m.id)) mc.missions.set(m.id, m)+ claimed.push(m.id)+ } else if (m.cwd === undefined && !mc.missions.has(m.id)) offered.set(m.id, m)+ }++ if (own?.legacyDismissed === true) mc.isLegacyDismissed = true+ mc.legacy = mc.isLegacyDismissed ? [] : [...offered.values()]++ const active = own?.active++ if (typeof active === 'string' && mc.missions.has(active)) mc.active = active++ // Written here before it leaves the shared ledger, so a mission is never in neither.+ if (claimed.length > 0) {+ await writeLedger(state, host)+ await pruneShared(host, claimed)+ }+}++/** The person's yes to the offer: the missions join this project's ledger, recorded under its directory, and leave the shared one (#4254). */+export async function adoptLegacy(state: State, host: Host): Promise<number> {+ const mc = mcOf(state)+ const taken = mc.legacy.map(m => ({ ...m, ...(state.cwd !== '' && { cwd: state.cwd }) }))++ if (taken.length === 0) return 0++ // Oldest first, as they were made: the save keeps the newest 20.+ mc.missions = new Map([...mc.missions.values(), ...taken].sort((a, b) => a.createdAtMs - b.createdAtMs).map(m => [m.id, m]))+ mc.legacy = []+ await writeLedger(state, host)+ await pruneShared(host, taken.map(m => m.id))++ return taken.length+}++/** The person's no: not offered in this project again. The missions stay in the shared ledger for the project they were made in. */+export function dismissLegacy(state: State, host: Host): void {+ const mc = mcOf(state)++ mc.legacy = []+ mc.isLegacyDismissed = true+ saveLedger(state, host)+}diff --git a/plugins/ruflo-console/hooks/mission-types.ts b/plugins/ruflo-console/hooks/mission-types.tsindex 80ab426e3f..bb68a670b7 100644--- a/plugins/ruflo-console/hooks/mission-types.ts+++ b/plugins/ruflo-console/hooks/mission-types.ts@@ -39,6 +39,10 @@ export type McState = {planned: Plan | nullmissions: Map<string, MissionRecord>active: string | null+ /** Missions saved before #4237 that name no project (the old shared ledger, or a copy of it): offered here, never taken in without the person (#4254). */+ legacy: MissionRecord[]+ /** The person said the offered missions are not this project's: no offer here again; they stay in the old ledger for the project they belong to. */+ isLegacyDismissed: booleantab: McTab/** The last instruction sent to Claude, kept so it can be edited and sent again. */lastGuide: string@@ -61,6 +65,10 @@ export type MissionActions = {tab: (tab: McTab) => voidcreate: () => voidselect: (id: string) => void+ /** Takes the offered pre-#4237 missions into this project (recorded under its directory) and removes them from the old shared ledger (#4254). */+ adoptLegacy: () => void+ /** Stops offering them in this project; they stay in the old shared ledger for the project they belong to (#4254). */+ dismissLegacy: () => void/** Hands the next ready task to the primary session (asks first: it starts a model turn). */next: () => voidpause: () => voiddiff --git a/plugins/ruflo-console/hooks/version.ts b/plugins/ruflo-console/hooks/version.tsindex 7e00208bc0..cb818aeadf 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.44.3'+export const CONSOLE_VERSION = '0.44.4'diff --git a/plugins/ruflo-console/hooks/views/mission-control.ts b/plugins/ruflo-console/hooks/views/mission-control.tsindex f61109b121..defaca5492 100644--- a/plugins/ruflo-console/hooks/views/mission-control.ts+++ b/plugins/ruflo-console/hooks/views/mission-control.ts@@ -217,6 +217,22 @@ function controlRows(ctx: Ctx, mission: MissionRecord): RenderElement[] {const FLOW = 'research β create (ADRs, SOP) β build β test β validate β secure β benchmark β learn'const flowRows = (ctx: Ctx): RenderElement[] => wrap(FLOW, Math.max(20, ctx.columns - 4)).map((line, i) => text(ctx, `${i === 0 ? ' ' : ' '}${line}`, { dimColor: true }))+/**+ * Missions saved before the ledger was kept per project that name no project (#4254). They are listed as an offer and are not this+ * project's (not picked, not handed to Claude, not in the prompt) until the person adopts them here or says they belong elsewhere.+ */+function legacyRows(ctx: Ctx, legacy: readonly MissionRecord[]): RenderElement[] {+ const n = legacy.length+ const them = n === 1 ? 'it' : 'them'++ return [+ ...paragraph(ctx, ` ${n} mission${n === 1 ? '' : 's'} from before per-project storage, with no project recorded. Adopt ${them} only if ${n === 1 ? 'it was' : 'they were'} made in this project:`, { color: THEME.warn }),+ ...legacy.slice(0, 5).map(m => text(ctx, ` ${m.id.slice(4, 10)} ${clip(m.objective, Math.max(16, ctx.columns - 14))}`, { dimColor: true })),+ ...(n > 5 ? [text(ctx, ` β¦ and ${n - 5} more`, { dimColor: true })] : []),+ row(ctx, [button(ctx, 'mc-legacy-adopt', ` adopt ${them} here `, () => ctx.act.mission.adoptLegacy()), text(ctx, ' '), button(ctx, 'mc-legacy-dismiss', ' not this project ', () => ctx.act.mission.dismissLegacy())], 'mc-legacy'),+ ]+}+/*** Mission Control: a goal becomes a SPARC plan found by a goal-oriented planner, the plan a governed mission and a ruflo* task per node, and the Claude session does the work one task at a time with its result recorded in the task store@@ -238,6 +254,8 @@ export function missionControlView(ctx: Ctx): RenderElement {if (mc.missions.size > 1) rows.push(row(ctx, [...mc.missions.values()].slice(-6).map(candidate => chip(ctx, `mc-pick-${candidate.id}`, candidate.id.slice(4, 10), candidate.id === mc.active, () => ctx.act.mission.select(candidate.id))), 'mc-picker'))+ if (mc.legacy.length > 0) rows.push(...legacyRows(ctx, mc.legacy))+if (mission !== null) rows.push(...controlRows(ctx, mission))if (mc.last !== null) rows.push(...fullRows(ctx, ` ${mc.last.ok ? 'β' : 'β'} `, `${mc.last.label}${mc.last.detail === '' ? '' : ` β ${mc.last.detail}`}`, { key: 'mc-last', color: mc.last.ok ? THEME.ok : THEME.bad, maxLines: 12, hint: 'your text is still in its field' }), ...(mc.last.lines ?? []).slice(0, 8).map(line => text(ctx, ` ${line}`, { dimColor: true })))diff --git a/plugins/ruflo-console/scripts/smoke.sh b/plugins/ruflo-console/scripts/smoke.shindex c3ee11384a..93c86ef1ef 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.44.3"+step "1. plugin.json declares ruflo-console 0.44.4"grep -q '"name": "ruflo-console"' "$ROOT/.claude-plugin/plugin.json" \- && grep -q '"version": "0.44.3"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"+ && grep -q '"version": "0.44.4"' "$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/adr-integration.spec.ts b/plugins/ruflo-console/tests/adr-integration.spec.tsindex 808cdc5868..5853082d57 100644--- a/plugins/ruflo-console/tests/adr-integration.spec.ts+++ b/plugins/ruflo-console/tests/adr-integration.spec.ts@@ -14,7 +14,7 @@ import { adrOf, loadAdrs } from '../hooks/adr'import { adrBlockFor, attachedOf, DIGEST_FILE, draftSpec, mirrorDigest, scopeCheck, setAttached, suggestFor, syncAdrDigest } from '../hooks/adr-mission'import { contextSection, claudeActions } from '../hooks/mission-claude'import { missionContextText } from '../hooks/mission-context'-import { instructionOf, ledgerKeyOf, loadLedger, LEDGER_KEY, mcOf } from '../hooks/mission-control'+import { instructionOf, ledgerKeyOf, loadLedger, mcOf } from '../hooks/mission-control'import type { MissionRecord } from '../hooks/mission-types'import { settingsOf } from '../hooks/settings'import { newState } from '../hooks/state'@@ -69,9 +69,9 @@ describe('attach, suggest and detach on a mission', () => {it('a saved ledger is not trusted: hostile attached names are dropped on load', async () => {const { state, host } = await world('nygard', null)- const bad = missionOf({ adrs: ['../../x.md', 'ok.md', 7 as never, 'a/b.md', 'x'.repeat(300) + '.md'] })+ const bad = { ...missionOf({ adrs: ['../../x.md', 'ok.md', 7 as never, 'a/b.md', 'x'.repeat(300) + '.md'] }), cwd: state.cwd }- await host.storeSet(LEDGER_KEY, { active: bad.id, missions: [bad] })+ await host.storeSet(ledgerKeyOf(state.cwd), { active: bad.id, missions: [bad] })await loadLedger(state, host as never)expect(mcOf(state).missions.get(bad.id)?.adrs).toEqual(['ok.md'])})diff --git a/plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts b/plugins/ruflo-console/tests/mission-ledger-per-project.spec.tsindex 3f761e8dc1..e26e5904d7 100644--- a/plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts+++ b/plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts@@ -1,14 +1,17 @@/*** #4237: the mission ledger was stored under one machine-wide key, so the active mission of one project showed up (and was injected into the- * prompt) in every other project, and two sessions in different projects overwrote each other. Run with+ * prompt) in every other project, and two sessions in different projects overwrote each other. #4254: a mission from that key with no project+ * recorded was still taken into every project that opened. Run with* npx vitest run plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts*/import { describe, expect, it } from 'vitest'import type { Host } from '../hooks/host'-import { activeMission, ledgerKeyOf, loadLedger, LEDGER_KEY, mcOf, saveLedger } from '../hooks/mission-control'+import { activeMission, adoptLegacy, dismissLegacy, ledgerKeyOf, loadLedger, LEDGER_KEY, mcOf, saveLedger } from '../hooks/mission-control'import type { MissionRecord } from '../hooks/mission-types'import { newState, type State } from '../hooks/state'+import type { Ctx } from '../hooks/views/common'+import { missionControlView } from '../hooks/views/mission-control'const A = '/home/me/project-a'const B = '/home/me/project-b'@@ -84,11 +87,106 @@ describe('mission ledger per project (#4237)', () => {expect(stored.has(ledgerKeyOf(B))).toBe(true)})- it('reads the old shared ledger once, without adopting its active mission or other projects\' missions', async () => {+ it("offers the old shared ledger's missions with no project instead of taking them in, and never its active mission", async () => {const stored = new Map<string, unknown>([[LEDGER_KEY, { active: ID_OLD, missions: [mission(ID_OLD), mission(ID_A, { cwd: A })] }]])const b = stateIn(B)await loadLedger(b, storeHost(stored))- expect([...mcOf(b).missions.keys()]).toEqual([ID_OLD])+ expect(mcOf(b).missions.size).toBe(0)+ expect(mcOf(b).legacy.map(m => m.id)).toEqual([ID_OLD])+ expect(activeMission(b)).toBeNull()+ })++ it('adopting stamps the project on the missions and takes them out of the shared ledger, which is left empty', async () => {+ const stored = new Map<string, unknown>([[LEDGER_KEY, { active: ID_OLD, missions: [mission(ID_OLD)] }]])+ const host = storeHost(stored)+ const b = stateIn(B)+ await loadLedger(b, host)+ expect(await adoptLegacy(b, host)).toBe(1)+ expect(mcOf(b).missions.get(ID_OLD)?.cwd).toBe(B)+ expect(mcOf(b).legacy).toEqual([])+ expect(stored.get(LEDGER_KEY)).toEqual({ missions: [] })+ expect((stored.get(ledgerKeyOf(B)) as { missions: MissionRecord[] }).missions.map(m => [m.id, m.cwd])).toEqual([[ID_OLD, B]])++ // Another project no longer sees it.+ const c = stateIn('/home/me/project-c')+ await loadLedger(c, host)+ expect(mcOf(c).legacy).toEqual([])+ })++ it("takes a mission the shared ledger records for this project and prunes it there, leaving other projects' missions", async () => {+ const stored = new Map<string, unknown>([[LEDGER_KEY, { missions: [mission(ID_A, { cwd: A }), mission(ID_B, { cwd: B })] }]])+ const a = stateIn(A)+ await loadLedger(a, storeHost(stored))+ expect([...mcOf(a).missions.keys()]).toEqual([ID_A])+ expect((stored.get(ledgerKeyOf(A)) as { missions: MissionRecord[] }).missions.map(m => m.id)).toEqual([ID_A])+ expect((stored.get(LEDGER_KEY) as { missions: MissionRecord[] }).missions.map(m => m.id)).toEqual([ID_B])+ })++ it('dismissing keeps the offer away in this project and leaves the missions in the shared ledger for others', async () => {+ const stored = new Map<string, unknown>([[LEDGER_KEY, { missions: [mission(ID_OLD)] }]])+ const host = storeHost(stored)+ const b = stateIn(B)+ await loadLedger(b, host)+ dismissLegacy(b, host)+ await flush()++ const again = stateIn(B)+ await loadLedger(again, host)+ expect(mcOf(again).legacy).toEqual([])+ expect(mcOf(again).missions.size).toBe(0)++ const c = stateIn('/home/me/project-c')+ await loadLedger(c, host)+ expect(mcOf(c).legacy.map(m => m.id)).toEqual([ID_OLD])+ })++ it('offers, rather than keeps, a copy with no project that 0.44.3 wrote into this project\'s own key', async () => {+ const stored = new Map<string, unknown>([[ledgerKeyOf(B), { active: ID_OLD, missions: [mission(ID_OLD), mission(ID_B, { cwd: B })] }]])+ const b = stateIn(B)+ await loadLedger(b, storeHost(stored))+ expect([...mcOf(b).missions.keys()]).toEqual([ID_B])+ expect(mcOf(b).legacy.map(m => m.id)).toEqual([ID_OLD])expect(activeMission(b)).toBeNull()})++ it('a session that starts again in another project carries none of the last project\'s missions', async () => {+ const stored = new Map<string, unknown>([[ledgerKeyOf(A), { active: ID_A, missions: [mission(ID_A, { cwd: A })] }]])+ const host = storeHost(stored)+ const state = stateIn(A)+ await loadLedger(state, host)+ expect(activeMission(state)?.id).toBe(ID_A)++ // session.start reuses the same State with the new directory (register.ts).+ state.cwd = B+ await loadLedger(state, host)+ expect(activeMission(state)).toBeNull()+ expect(mcOf(state).missions.size).toBe(0)+ })++ it('Mission Control lists the offer with adopt and dismiss, and nothing when there is no offer', () => {+ type El = { kind: string; props: Record<string, unknown> }+ const node = (kind: string) => (props: Record<string, unknown>): El => ({ kind, props })+ const kit = { Box: node('Box'), Text: node('Text'), Button: node('Button'), Input: node('Input') }+ const flat = (el: unknown): El[] => {+ const n = el as El+ if (typeof n !== 'object' || n === null) return []+ const kids = n.props.children+ return [n, ...(Array.isArray(kids) ? kids.flatMap(flat) : typeof kids === 'object' ? flat(kids) : [])]+ }+ const pressed: string[] = []+ const act = new Proxy({ mission: new Proxy({}, { get: (_t, key) => () => void pressed.push(String(key)) }) }, { get: (t, key) => (key in t ? t[key as 'mission'] : () => undefined) })+ const state = stateIn(B)+ const ctx = { kit, state, nowMs: 5_000, columns: 100, pictures: new Map(), act, cards: false } as unknown as Ctx+ const words = () => flat(missionControlView(ctx)).filter(n => n.kind === 'Text').map(n => String(n.props.children)).join('\n')+ const button = (key: string) => flat(missionControlView(ctx)).find(n => n.kind === 'Button' && n.props.key === key)++ expect(button('mc-legacy-adopt')).toBeUndefined()++ mcOf(state).legacy = [mission(ID_OLD, { objective: 'an old goal from somewhere' })]+ expect(words()).toContain('1 mission from before per-project storage')+ expect(words()).toContain('an old goal from somewhere')+ ;(button('mc-legacy-adopt')?.props.onPress as () => void)()+ ;(button('mc-legacy-dismiss')?.props.onPress as () => void)()+ expect(pressed).toEqual(['adoptLegacy', 'dismissLegacy'])+ })})