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

fix(ruflo-console): adopt pre-#4237 missions one at a time, keep offers and prune only after a save (#4254)

Mathew Beaneb1fb1666e01d
diff --git a/plugins/ruflo-console/CHANGELOG.md b/plugins/ruflo-console/CHANGELOG.md
index 040d78f181..d3aa0e7bd4 100644
--- a/plugins/ruflo-console/CHANGELOG.md
+++ b/plugins/ruflo-console/CHANGELOG.md
@@ -4,7 +4,7 @@ Newest first. One `## <version> — <date>` heading per version, then `feat:`, `
## 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.
+- 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"), each on its own row with adopt and not here, because the old key mixes missions from several projects; with two or more, one button turns them all away. Adopt records the project on that mission and takes it out of the old key, and only once the project's own save has succeeded; a mission older than the 20 a project keeps is not adopted rather than dropped. Not here keeps that mission's offer away there. An offer that came from the project's own key (a 0.44.3 copy) stays in that key until adopted, so a save no longer drops it. A mission the old key records for this project is taken in and removed from it without asking, again only after the save. A session that starts again in another directory begins with none of the last project's missions, goal or plan. Until every Claude Code session on the machine runs 0.44.4, a session still on 0.44.2 or 0.44.3 can write its in-memory missions back to the old shared key or a project's key, bringing back offers this version pruned. Restart those sessions after updating.
## 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.ts
index 3d04f29d30..22c218c37b 100644
--- a/plugins/ruflo-console/hooks/mission-control.ts
+++ b/plugins/ruflo-console/hooks/mission-control.ts
@@ -23,7 +23,7 @@ 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 { adoptLegacy, type AdoptResult, 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 }
@@ -177,6 +177,14 @@ export function researchOf(state: State): ResearchDraft {
export const setResearch = (state: State, patch: Partial<ResearchDraft>): void => void Object.assign(researchOf(state), patch)
+/** What Mission Control says after the person adopts one offered mission (#4254). */
+const ADOPT_SAYS: Record<AdoptResult, [string, boolean, string]> = {
+ adopted: ['adopted 1 mission', true, 'recorded under this project and removed from the old shared ledger'],
+ none: ['nothing to adopt', false, 'that mission is no longer offered here'],
+ full: ['not adopted', false, 'it is older than the 20 missions this project keeps, so the save would drop it; it stays offered'],
+ failed: ['not adopted', false, 'the store refused the write; the mission is still in the old shared ledger'],
+}
+
const wired = new WeakMap<State, { host: Host; actions: MissionActions; research: () => void | Promise<void> }>()
/** The host, actions and research start Mission Control was wired with, for the palette and the headless commands. */
@@ -307,12 +315,12 @@ export function missionActions(state: State, host: Host, runner: Runner): Missio
saveLedger(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'))
+ adoptLegacy: id => {
+ void adoptLegacy(state, host, id).then(result => say(...ADOPT_SAYS[result]))
},
- 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')
+ dismissLegacy: id => {
+ dismissLegacy(state, host, id)
+ say('not this project\'s', true, `${id === undefined ? 'the older missions stay' : 'it stays'} in the shared ledger for the project ${id === undefined ? 'they were' : 'it was'} made in`)
},
next: () => {
const mission = activeMission(state)
diff --git a/plugins/ruflo-console/hooks/mission-ledger.ts b/plugins/ruflo-console/hooks/mission-ledger.ts
index a27a2cc260..d1365ff545 100644
--- a/plugins/ruflo-console/hooks/mission-ledger.ts
+++ b/plugins/ruflo-console/hooks/mission-ledger.ts
@@ -17,22 +17,44 @@ 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 }
+ found = { goal: '', profile: 'feature', rigor: 'standard', isProfilePicked: false, planned: null, missions: new Map(), active: null, legacy: [], legacyDismissed: new Set(), 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 }
+/** `offered`: copies with no project that this project's own key held, kept until the person adopts them. `legacyDismissed` was `true` before it listed ids. */
+type SavedLedger = { active?: unknown; missions?: unknown; offered?: 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>()
+/** Offered missions that came from this project's own key: written back to it until adopted, so the offer outlives a save (#4254). */
+const heldOffers = new WeakMap<State, Map<string, MissionRecord>>()
-const writeLedger = (state: State, host: Host): Promise<void> => {
+const held = (state: State): Map<string, MissionRecord> => {
+ let found = heldOffers.get(state)
+
+ if (found === undefined) {
+ found = new Map()
+ heldOffers.set(state, found)
+ }
+
+ return found
+}
+
+/** The 20 missions the next save keeps, newest last. */
+const keptMissions = (missions: Map<string, MissionRecord>): MissionRecord[] => [...missions.values()].slice(-20)
+
+/** Saves this project's ledger. The ids of the missions it saved, or null when the store refused the write: nothing is pruned on null. */
+const writeLedger = (state: State, host: Host): Promise<string[] | null> => {
const mc = mcOf(state)
+ const missions = keptMissions(mc.missions)
+ const offered = [...held(state).values()].filter(m => !mc.missions.has(m.id)).slice(-20)
+ const dismissed = [...mc.legacyDismissed].slice(-100)
+ const saved = { active: mc.active, missions, ...(offered.length > 0 && { offered }), ...(dismissed.length > 0 && { legacyDismissed: dismissed }) }
- return host.storeSet(ledgerKeyOf(state.cwd), { active: mc.active, missions: [...mc.missions.values()].slice(-20), ...(mc.isLegacyDismissed && { legacyDismissed: true }) }).catch(() => undefined)
+ return host.storeSet(ledgerKeyOf(state.cwd), saved).then(() => missions.map(m => m.id), () => null)
}
export function saveLedger(state: State, host: Host): void {
@@ -49,12 +71,14 @@ function missionOf(raw: unknown): MissionRecord | 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
+const savedMissions = (saved: unknown, field: 'missions' | 'offered' = 'missions'): MissionRecord[] => {
+ const missions = (saved as SavedLedger | undefined)?.[field]
return Array.isArray(missions) ? missions.slice(0, 20).flatMap(raw => missionOf(raw) ?? []) : []
}
+const dismissedIds = (raw: unknown): string[] => (Array.isArray(raw) ? raw.filter((id): id is string => typeof id === 'string' && /^msn_[a-f0-9]{24}$/.test(id)).slice(-100) : [])
+
/** 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
@@ -71,7 +95,7 @@ async function pruneShared(host: Host, ids: readonly string[]): Promise<void> {
/**
* 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.
+ * made in (#4254). A copy of one that 0.44.3 wrote into this project's own key is offered the same way, and kept in that key until adopted.
*/
export async function loadLedger(state: State, host: Host): Promise<void> {
const cwd = state.cwd
@@ -81,7 +105,10 @@ export async function loadLedger(state: State, host: Host): Promise<void> {
mc.missions.clear()
mc.active = null
mc.legacy = []
- mc.isLegacyDismissed = false
+ mc.legacyDismissed = new Set()
+ held(state).clear()
+ // A goal planned in the last project must not be created in this one.
+ if (loadedFor.has(state)) Object.assign(mc, { goal: '', planned: null, guidance: null, screen: null })
loadedFor.set(state, cwd)
}
@@ -97,9 +124,12 @@ export async function loadLedger(state: State, host: Host): Promise<void> {
const offered = new Map<string, MissionRecord>()
const claimed: string[] = []
- for (const m of savedMissions(own)) {
+ for (const m of [...savedMissions(own), ...savedMissions(own, 'offered')]) {
if (isOurs(m)) mc.missions.set(m.id, m)
- else if (m.cwd === undefined) offered.set(m.id, m)
+ else if (m.cwd === undefined && !mc.missions.has(m.id)) {
+ offered.set(m.id, m)
+ held(state).set(m.id, m)
+ }
}
for (const m of shared) {
@@ -109,41 +139,61 @@ export async function loadLedger(state: State, host: Host): Promise<void> {
} 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()]
+ // 0.44.4 before review saved one `true` for the whole offer: it covered every mission offered then.
+ for (const id of own?.legacyDismissed === true ? offered.keys() : dismissedIds(own?.legacyDismissed)) mc.legacyDismissed.add(id)
+ mc.legacy = [...offered.values()].filter(m => !mc.legacyDismissed.has(m.id))
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.
+ // Written here before it leaves the shared ledger, and pruned only for what the write kept, so a mission is never in neither.
if (claimed.length > 0) {
- await writeLedger(state, host)
- await pruneShared(host, claimed)
+ const saved = await writeLedger(state, host)
+
+ if (saved !== null) await pruneShared(host, claimed.filter(id => saved.includes(id)))
}
}
-/** 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> {
+/** `full`: the mission is older than the 20 this project keeps, so adopting it would drop it. `failed`: the store refused the write. */
+export type AdoptResult = 'adopted' | 'none' | 'full' | 'failed'
+
+/**
+ * The person's yes for one offered mission: it joins this project's ledger, recorded under its directory, and leaves the shared one
+ * (#4254). One at a time, because an offer can mix missions from several projects and nothing records which.
+ */
+export async function adoptLegacy(state: State, host: Host, id: string): Promise<AdoptResult> {
const mc = mcOf(state)
- const taken = mc.legacy.map(m => ({ ...m, ...(state.cwd !== '' && { cwd: state.cwd }) }))
+ const offer = mc.legacy.find(m => m.id === id)
- if (taken.length === 0) return 0
+ if (offer === undefined) return 'none'
+ const before = mc.missions
// 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))
+ const next = new Map([...before.values(), { ...offer, ...(state.cwd !== '' && { cwd: state.cwd }) }].sort((a, b) => a.createdAtMs - b.createdAtMs).map(m => [m.id, m]))
+
+ if (!keptMissions(next).some(m => m.id === id)) return 'full'
+
+ mc.missions = next
+ const saved = await writeLedger(state, host)
+
+ if (saved === null) {
+ mc.missions = before
+ return 'failed'
+ }
+
+ mc.legacy = mc.legacy.filter(m => m.id !== id)
+ held(state).delete(id)
+ await pruneShared(host, [id])
- return taken.length
+ return 'adopted'
}
-/** 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 {
+/** The person's no, for one offered mission or (no id) all of them: not offered in this project again. They stay where they were for the project they were made in. */
+export function dismissLegacy(state: State, host: Host, id?: string): void {
const mc = mcOf(state)
- mc.legacy = []
- mc.isLegacyDismissed = true
+ for (const m of mc.legacy) if (id === undefined || m.id === id) mc.legacyDismissed.add(m.id)
+ mc.legacy = mc.legacy.filter(m => !mc.legacyDismissed.has(m.id))
saveLedger(state, host)
}
diff --git a/plugins/ruflo-console/hooks/mission-types.ts b/plugins/ruflo-console/hooks/mission-types.ts
index bb68a670b7..abdf880539 100644
--- a/plugins/ruflo-console/hooks/mission-types.ts
+++ b/plugins/ruflo-console/hooks/mission-types.ts
@@ -41,8 +41,8 @@ export type McState = {
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: boolean
+ /** Offered missions the person said are not this project's: not offered here again; they stay in the old ledger for the project they belong to. */
+ legacyDismissed: Set<string>
tab: McTab
/** The last instruction sent to Claude, kept so it can be edited and sent again. */
lastGuide: string
@@ -65,10 +65,10 @@ export type MissionActions = {
tab: (tab: McTab) => void
create: () => void
select: (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
+ /** Takes one offered pre-#4237 mission into this project (recorded under its directory) and removes it from the old shared ledger (#4254). */
+ adoptLegacy: (id: string) => void
+ /** Stops offering one of them (or, with no id, all of them) in this project; they stay in the old shared ledger for the project they belong to (#4254). */
+ dismissLegacy: (id?: string) => void
/** Hands the next ready task to the primary session (asks first: it starts a model turn). */
next: () => void
pause: () => void
diff --git a/plugins/ruflo-console/hooks/views/mission-control.ts b/plugins/ruflo-console/hooks/views/mission-control.ts
index defaca5492..5d5113d0a6 100644
--- a/plugins/ruflo-console/hooks/views/mission-control.ts
+++ b/plugins/ruflo-console/hooks/views/mission-control.ts
@@ -223,13 +223,19 @@ const flowRows = (ctx: Ctx): RenderElement[] => wrap(FLOW, Math.max(20, ctx.colu
*/
function legacyRows(ctx: Ctx, legacy: readonly MissionRecord[]): RenderElement[] {
const n = legacy.length
- const them = n === 1 ? 'it' : 'them'
+ // The offer can mix missions from several projects, so each one is adopted or turned away on its own row.
+ const offerRow = (m: MissionRecord) => row(ctx, [
+ text(ctx, ` ${m.id.slice(4, 10)} ${clip(m.objective, Math.max(16, ctx.columns - 36))} `, { dimColor: true }),
+ button(ctx, `mc-legacy-adopt-${m.id}`, ' adopt ', () => ctx.act.mission.adoptLegacy(m.id)),
+ text(ctx, ' '),
+ button(ctx, `mc-legacy-dismiss-${m.id}`, ' not here ', () => ctx.act.mission.dismissLegacy(m.id)),
+ ], `mc-legacy-${m.id}`)
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 })),
+ ...paragraph(ctx, ` ${n} mission${n === 1 ? '' : 's'} from before per-project storage, with no project recorded. Adopt one only if it was made in this project:`, { color: THEME.warn }),
+ ...legacy.slice(0, 5).map(offerRow),
...(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'),
+ ...(n > 1 ? [row(ctx, [text(ctx, ' '), button(ctx, 'mc-legacy-dismiss', ' none of these are this project\'s ', () => ctx.act.mission.dismissLegacy())], 'mc-legacy')] : []),
]
}
diff --git a/plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts b/plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts
index e26e5904d7..b92def5f31 100644
--- a/plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts
+++ b/plugins/ruflo-console/tests/mission-ledger-per-project.spec.ts
@@ -101,7 +101,7 @@ describe('mission ledger per project (#4237)', () => {
const host = storeHost(stored)
const b = stateIn(B)
await loadLedger(b, host)
- expect(await adoptLegacy(b, host)).toBe(1)
+ expect(await adoptLegacy(b, host, ID_OLD)).toBe('adopted')
expect(mcOf(b).missions.get(ID_OLD)?.cwd).toBe(B)
expect(mcOf(b).legacy).toEqual([])
expect(stored.get(LEDGER_KEY)).toEqual({ missions: [] })
@@ -185,8 +185,126 @@ describe('mission ledger per project (#4237)', () => {
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(button('mc-legacy-dismiss')).toBeUndefined()
+ ;(button(`mc-legacy-adopt-${ID_OLD}`)?.props.onPress as () => void)()
+ ;(button(`mc-legacy-dismiss-${ID_OLD}`)?.props.onPress as () => void)()
expect(pressed).toEqual(['adoptLegacy', 'dismissLegacy'])
+
+ // Two or more: each has its own row, and one button turns them all away.
+ mcOf(state).legacy.push(mission(ID_A))
+ expect(button(`mc-legacy-adopt-${ID_A}`)).toBeDefined()
+ ;(button('mc-legacy-dismiss')?.props.onPress as () => void)()
+ expect(pressed).toEqual(['adoptLegacy', 'dismissLegacy', 'dismissLegacy'])
+ })
+})
+
+// From the review of #4276: each of these asserted the defect against c85c5f3; here they assert the fix.
+describe('mission ledger offers after review (#4254)', () => {
+ const hex = (n: number) => 'msn_' + n.toString(16).padStart(24, '0')
+ const idsAt = (stored: Map<string, unknown>, key: string): string[] => ((stored.get(key) as { missions?: MissionRecord[] } | undefined)?.missions ?? []).map(m => m.id)
+
+ it("adopting one mission leaves the others offered, in this project and in the projects they came from", async () => {
+ const fromA = hex(1), fromX = hex(2), fromY = hex(3)
+ const stored = new Map<string, unknown>([[LEDGER_KEY, { active: fromY, missions: [mission(fromA), mission(fromX), mission(fromY)] }]])
+ const host = storeHost(stored)
+ const a = stateIn(A)
+ await loadLedger(a, host)
+ expect(await adoptLegacy(a, host, fromA)).toBe('adopted')
+ expect(idsAt(stored, ledgerKeyOf(A))).toEqual([fromA])
+ expect(mcOf(a).legacy.map(m => m.id)).toEqual([fromX, fromY])
+
+ const x = stateIn('/home/me/project-x')
+ await loadLedger(x, host)
+ expect(mcOf(x).legacy.map(m => m.id)).toEqual([fromX, fromY])
+ })
+
+ it('dismissing one mission keeps the rest offered, across a reload', async () => {
+ const one = hex(1), two = hex(2)
+ const stored = new Map<string, unknown>([[LEDGER_KEY, { missions: [mission(one), mission(two)] }]])
+ const host = storeHost(stored)
+ const b = stateIn(B)
+ await loadLedger(b, host)
+ dismissLegacy(b, host, one)
+ await flush()
+ expect(mcOf(b).legacy.map(m => m.id)).toEqual([two])
+
+ const again = stateIn(B)
+ await loadLedger(again, host)
+ expect(mcOf(again).legacy.map(m => m.id)).toEqual([two])
+ expect(idsAt(stored, LEDGER_KEY)).toEqual([one, two])
+ })
+
+ it('an offer saved by the earlier 0.44.4 as one dismissal still covers the missions offered then', async () => {
+ const stored = new Map<string, unknown>([[ledgerKeyOf(B), { active: null, missions: [], legacyDismissed: true }], [LEDGER_KEY, { missions: [mission(ID_OLD)] }]])
+ const b = stateIn(B)
+ await loadLedger(b, storeHost(stored))
+ expect(mcOf(b).legacy).toEqual([])
+ })
+
+ it('refuses to adopt past the cap instead of losing the mission', async () => {
+ const own = Array.from({ length: 20 }, (_, i) => mission(hex(100 + i), { cwd: A, createdAtMs: 100 + i }))
+ const old = mission(hex(1), { createdAtMs: 1 })
+ const stored = new Map<string, unknown>([[ledgerKeyOf(A), { active: null, missions: own }], [LEDGER_KEY, { missions: [old] }]])
+ const host = storeHost(stored)
+ const a = stateIn(A)
+ await loadLedger(a, host)
+ expect(await adoptLegacy(a, host, old.id)).toBe('full')
+ expect(idsAt(stored, LEDGER_KEY)).toEqual([old.id])
+ expect(mcOf(a).legacy.map(m => m.id)).toEqual([old.id])
+ expect(mcOf(a).missions.size).toBe(20)
+ })
+
+ it('an offer held only in the project key is still offered after a save and reload', async () => {
+ const L = hex(7)
+ const stored = new Map<string, unknown>([[ledgerKeyOf(A), { active: null, missions: [mission(L)] }]])
+ const host = storeHost(stored)
+ const a = stateIn(A)
+ await loadLedger(a, host)
+ expect(mcOf(a).legacy.map(m => m.id)).toEqual([L])
+ saveLedger(a, host)
+ await flush()
+
+ const again = stateIn(A)
+ await loadLedger(again, host)
+ expect(mcOf(again).legacy.map(m => m.id)).toEqual([L])
+ expect(mcOf(again).missions.size).toBe(0)
+
+ // Adopted, it becomes this project's and stops being held as an offer.
+ expect(await adoptLegacy(again, host, L)).toBe('adopted')
+ const saved = stored.get(ledgerKeyOf(A)) as { missions: MissionRecord[]; offered?: MissionRecord[] }
+ expect(saved.missions.map(m => [m.id, m.cwd])).toEqual([[L, A]])
+ expect(saved.offered).toBeUndefined()
+ })
+
+ it('a failed project-key write prunes nothing from the shared key', async () => {
+ const id = hex(8)
+ const stored = new Map<string, unknown>([[LEDGER_KEY, { missions: [mission(id)] }]])
+ const base = storeHost(stored)
+ const host = { ...base, storeSet: async (k: string, v: unknown) => { if (k === ledgerKeyOf(A)) throw new Error('write failed'); return base.storeSet(k, v) } } as Host
+ const a = stateIn(A)
+ await loadLedger(a, host)
+ expect(await adoptLegacy(a, host, id)).toBe('failed')
+ expect(idsAt(stored, LEDGER_KEY)).toEqual([id])
+ expect(mcOf(a).legacy.map(m => m.id)).toEqual([id])
+ expect(mcOf(a).missions.size).toBe(0)
+ })
+
+ it('a failed write while claiming on load leaves the mission in the shared key', async () => {
+ const stored = new Map<string, unknown>([[LEDGER_KEY, { missions: [mission(ID_A, { cwd: A })] }]])
+ const base = storeHost(stored)
+ const host = { ...base, storeSet: async (k: string, v: unknown) => { if (k === ledgerKeyOf(A)) throw new Error('write failed'); return base.storeSet(k, v) } } as Host
+ await loadLedger(stateIn(A), host)
+ expect(idsAt(stored, LEDGER_KEY)).toEqual([ID_A])
+ })
+
+ it('a session that moves to another project drops the goal and plan made in the last one', async () => {
+ const host = storeHost(new Map())
+ const state = stateIn(A)
+ await loadLedger(state, host)
+ Object.assign(mcOf(state), { goal: 'add dark mode', planned: { nodes: [] } })
+ state.cwd = B
+ await loadLedger(state, host)
+ expect(mcOf(state).goal).toBe('')
+ expect(mcOf(state).planned).toBeNull()
})
})