MCPcopy
hub / github.com/claude-code-best/claude-code / attachRunStatePersistence

Function attachRunStatePersistence

src/workflow/persistence.ts:190–210  ·  view source on GitHub ↗
(
  bus: ProgressBus,
  store: ProgressStore,
  runsDirProvider: () => string = getRunsDir,
)

Source from the content-addressed store, hash-verified

188 * cannot monkey-patch getRunsDir itself).
189 */
190export function attachRunStatePersistence(
191 bus: ProgressBus,
192 store: ProgressStore,
193 runsDirProvider: () => string = getRunsDir,
194): () => void {
195 return bus.subscribe(event => {
196 if (event.type !== 'run_done') return
197 const run = store.get(event.runId)
198 if (!run) return
199 const dir = runsDirProvider()
200 void writeRunState(dir, run).then(() => {
201 // Sweep only after the new state lands on disk — avoids a race where the just-finished run
202 // itself gets pruned because its state.json wasn't counted yet.
203 void cleanupOldRuns(dir).catch(e => {
204 logForDebugging(
205 `[workflow warn] cleanupOldRuns after run_done threw: ${(e as Error).message}`,
206 )
207 })
208 })
209 })
210}

Callers 2

getWorkflowServiceFunction · 0.85

Calls 5

writeRunStateFunction · 0.85
cleanupOldRunsFunction · 0.85
getMethod · 0.65
logForDebuggingFunction · 0.50
subscribeMethod · 0.45

Tested by

no test coverage detected