@mikode13/harness 11.0.1 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -16
- package/dist/agent/domain/agent.d.ts +41 -3
- package/dist/agent/domain/agent.js.map +1 -1
- package/dist/agent/domain/approval.d.ts +20 -0
- package/dist/agent/domain/approval.js.map +1 -1
- package/dist/agent/domain/inbox.d.ts +42 -0
- package/dist/agent/domain/inbox.js +81 -0
- package/dist/agent/domain/inbox.js.map +1 -0
- package/dist/agent/domain/oneRunAtATime.d.ts +17 -0
- package/dist/agent/domain/oneRunAtATime.js +32 -0
- package/dist/agent/domain/oneRunAtATime.js.map +1 -0
- package/dist/agent/domain/runContext.d.ts +9 -0
- package/dist/agent/domain/runContext.js +5 -0
- package/dist/agent/domain/runContext.js.map +1 -1
- package/dist/agent/domain/session.d.ts +15 -0
- package/dist/agent/domain/session.js +80 -0
- package/dist/agent/domain/session.js.map +1 -0
- package/dist/engines/claude/infrastructure/model/claudeAgent.d.ts +6 -2
- package/dist/engines/claude/infrastructure/model/claudeAgent.js +20 -5
- package/dist/engines/claude/infrastructure/model/claudeAgent.js.map +1 -1
- package/dist/engines/codex/infrastructure/model/codexAgent.d.ts +5 -1
- package/dist/engines/codex/infrastructure/model/codexAgent.js +13 -2
- package/dist/engines/codex/infrastructure/model/codexAgent.js.map +1 -1
- package/dist/engines/domain/model/backgroundAgents.d.ts +5 -2
- package/dist/engines/domain/model/backgroundAgents.js +11 -3
- package/dist/engines/domain/model/backgroundAgents.js.map +1 -1
- package/dist/engines/domain/model/compactor.d.ts +40 -0
- package/dist/engines/domain/model/compactor.js +5 -0
- package/dist/engines/domain/model/compactor.js.map +1 -0
- package/dist/engines/domain/model/llmAgent.d.ts +53 -2
- package/dist/engines/domain/model/llmAgent.js +419 -24
- package/dist/engines/domain/model/llmAgent.js.map +1 -1
- package/dist/engines/domain/model/recentCompaction.d.ts +39 -0
- package/dist/engines/domain/model/recentCompaction.js +119 -0
- package/dist/engines/domain/model/recentCompaction.js.map +1 -0
- package/dist/engines/domain/model/stepContext.js +3 -0
- package/dist/engines/domain/model/stepContext.js.map +1 -1
- package/dist/engines/domain/model/triagedCompaction.d.ts +27 -0
- package/dist/engines/domain/model/triagedCompaction.js +60 -0
- package/dist/engines/domain/model/triagedCompaction.js.map +1 -0
- package/dist/factory/infrastructure/agentLLMFactory.d.ts +56 -15
- package/dist/factory/infrastructure/agentLLMFactory.js +144 -25
- package/dist/factory/infrastructure/agentLLMFactory.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/domain/contextTriage.d.ts +26 -0
- package/dist/llm/domain/contextTriage.js +3 -0
- package/dist/llm/domain/contextTriage.js.map +1 -0
- package/dist/llm/domain/llm.d.ts +18 -1
- package/dist/llm/domain/llm.js.map +1 -1
- package/dist/llm/domain/message.d.ts +18 -1
- package/dist/llm/domain/message.js +20 -0
- package/dist/llm/domain/message.js.map +1 -1
- package/dist/llm/infrastructure/claudeLLMClient.d.ts +4 -5
- package/dist/llm/infrastructure/claudeLLMClient.js +39 -13
- package/dist/llm/infrastructure/claudeLLMClient.js.map +1 -1
- package/dist/llm/infrastructure/jevContextTriage.d.ts +18 -0
- package/dist/llm/infrastructure/jevContextTriage.js +92 -0
- package/dist/llm/infrastructure/jevContextTriage.js.map +1 -0
- package/dist/llm/infrastructure/openAILLMClient.d.ts +4 -5
- package/dist/llm/infrastructure/openAILLMClient.js +20 -9
- package/dist/llm/infrastructure/openAILLMClient.js.map +1 -1
- package/dist/orchestration/domain/model/orchestratorAgent.d.ts +9 -1
- package/dist/orchestration/domain/model/orchestratorAgent.js +20 -3
- package/dist/orchestration/domain/model/orchestratorAgent.js.map +1 -1
- package/dist/recovery/domain/history.d.ts +10 -3
- package/dist/recovery/domain/history.js +1 -0
- package/dist/recovery/domain/history.js.map +1 -1
- package/dist/recovery/domain/recoveryStore.d.ts +14 -2
- package/dist/recovery/domain/recoveryStore.js.map +1 -1
- package/dist/recovery/infrastructure/fileRecoveryStore.d.ts +21 -2
- package/dist/recovery/infrastructure/fileRecoveryStore.js +58 -6
- package/dist/recovery/infrastructure/fileRecoveryStore.js.map +1 -1
- package/dist/recovery/infrastructure/folderClaims.d.ts +27 -0
- package/dist/recovery/infrastructure/folderClaims.js +124 -0
- package/dist/recovery/infrastructure/folderClaims.js.map +1 -0
- package/dist/shared/domain/session.d.ts +12 -0
- package/dist/shared/domain/session.js +2 -0
- package/dist/shared/domain/session.js.map +1 -0
- package/dist/tools/domain/preparedCall.d.ts +5 -2
- package/dist/tools/domain/preparedCall.js +7 -1
- package/dist/tools/domain/preparedCall.js.map +1 -1
- package/dist/tools/domain/readRegistry.d.ts +11 -0
- package/dist/tools/domain/readRegistry.js.map +1 -1
- package/dist/tools/infrastructure/agentAsTool.d.ts +6 -0
- package/dist/tools/infrastructure/agentAsTool.js +9 -0
- package/dist/tools/infrastructure/agentAsTool.js.map +1 -1
- package/dist/tools/infrastructure/commandTool.js +6 -1
- package/dist/tools/infrastructure/commandTool.js.map +1 -1
- package/dist/tools/infrastructure/exploreTool.js +2 -0
- package/dist/tools/infrastructure/exploreTool.js.map +1 -1
- package/dist/tools/infrastructure/fileTools.d.ts +2 -0
- package/dist/tools/infrastructure/fileTools.js +10 -1
- package/dist/tools/infrastructure/fileTools.js.map +1 -1
- package/dist/tools/infrastructure/removeWorktreeTool.d.ts +23 -0
- package/dist/tools/infrastructure/removeWorktreeTool.js +178 -0
- package/dist/tools/infrastructure/removeWorktreeTool.js.map +1 -0
- package/dist/tools/infrastructure/subagents.d.ts +3 -1
- package/dist/tools/infrastructure/subagents.js +2 -1
- package/dist/tools/infrastructure/subagents.js.map +1 -1
- package/dist/tools/infrastructure/trackedEdits.js +1 -0
- package/dist/tools/infrastructure/trackedEdits.js.map +1 -1
- package/dist/tools/infrastructure/workspaceWrites.d.ts +17 -1
- package/dist/tools/infrastructure/workspaceWrites.js +48 -17
- package/dist/tools/infrastructure/workspaceWrites.js.map +1 -1
- package/dist/tools/infrastructure/worktrees.d.ts +49 -0
- package/dist/tools/infrastructure/worktrees.js +154 -0
- package/dist/tools/infrastructure/worktrees.js.map +1 -0
- package/dist/tools/infrastructure/writeCeiling.d.ts +16 -0
- package/dist/tools/infrastructure/writeCeiling.js +49 -0
- package/dist/tools/infrastructure/writeCeiling.js.map +1 -0
- package/dist/tools/infrastructure/writeSession.d.ts +5 -1
- package/dist/tools/infrastructure/writeSession.js +7 -3
- package/dist/tools/infrastructure/writeSession.js.map +1 -1
- package/dist/workflow/domain/workflow.d.ts +3 -0
- package/dist/workflow/domain/workflow.js.map +1 -1
- package/dist/workflow/domain/workflowRunner.js +8 -2
- package/dist/workflow/domain/workflowRunner.js.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileRecoveryStore.js","sourceRoot":"","sources":["../../../src/recovery/infrastructure/fileRecoveryStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,EAAE,EACF,IAAI,EACJ,QAAQ,EACR,MAAM,GACN,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,WAAW,GACX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAmB,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EACN,YAAY,EAOZ,kBAAkB,EAOlB,kBAAkB,EAClB,mBAAmB,GAC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E,IAAI,CAAC,MAAM;iBAClB,CAAC,CAAC;YACJ,CAAC;YACD,IAAI,CAAC;gBACJ,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC3D,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;gBAC1D,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC,CAAC,CAAC;QACH,wFAAwF;QACxF,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC;IACd,CAAC;IAEO,UAAU;QACjB,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,uBAAuB,CAAC,CAAC;IAC9E,CAAC;CACD","sourcesContent":["import { createHash, randomBytes } from 'node:crypto';\nimport {\n\tlink,\n\tmkdir,\n\topen,\n\treaddir,\n\treadFile,\n\trealpath,\n\trename,\n\trm,\n\tstat,\n\ttruncate,\n\tunlink,\n} from 'node:fs/promises';\nimport type { FileHandle } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join } from 'node:path';\nimport type { ILogger } from '#src/shared/domain/logger';\nimport {\n\tclassifyHostFailure,\n\tdescribeFailure,\n\ttreatErrors,\n} from '#src/shared/domain/providerFailure';\nimport { Logger } from '#src/shared/infrastructure/logger';\nimport { type FileChange, fileChanges, sameState } from '../domain/fileChanges.ts';\nimport {\n\thistoryStart,\n\ttype FileState,\n\ttype JournalEntry,\n\ttype Manifest,\n\ttype ObservationMeasure,\n\ttype MoveConflict,\n\ttype MoveOptions,\n\tNothingToMoveError,\n\ttype Revision,\n\ttype RecoveryStore,\n\ttype RunJournal,\n\ttype RunRecord,\n\ttype RunStatus,\n\ttype UnrecordedChange,\n\tWorkspaceBusyError,\n\tWorkspaceMovedError,\n} from '../domain/recoveryStore.ts';\nimport { chainEntries, nextPruneStep } from '../domain/retention.ts';\nimport { HistoryExpiredError, redoTarget, route, UnknownRunError } from '../domain/runTree.ts';\nimport {\n\tcurrentState,\n\thasRealParents,\n\tremoveEmptyFolders,\n\tremoveFile,\n\tremoveTemporary,\n\ttemporaryPath,\n\twriteFileState,\n} from './workspaceFiles.ts';\n\nconst appName = 'mikode-harness';\n// The store holds source code the agent touched: only its owner may read it.\nconst privateDirectory = 0o700;\nconst privateFile = 0o600;\n\nconst firstJournal = 'journal.jsonl';\n\n// A run is roughly one prompt: enough to go back through a working session, not a project's life.\nconst defaultKeepRuns = 25;\n\nconst runIdPattern = /^\\d{8}T\\d{9}Z-[0-9a-f]{6}$/;\nconst hashPattern = /^[0-9a-f]{64}$/;\n\n/** Where an application keeps state that is neither configuration nor cache, per platform. */\nexport function defaultStateDirectory(\n\tenv: NodeJS.ProcessEnv = process.env,\n\tplatform: NodeJS.Platform = process.platform,\n\thome: string = homedir(),\n): string {\n\t// The XDG spec says to ignore a relative path, which here could land inside the repository.\n\tconst xdg = env.XDG_STATE_HOME;\n\tif (xdg && isAbsolute(xdg)) return join(xdg, appName);\n\tif (platform === 'darwin') return join(home, 'Library', 'Application Support', appName);\n\treturn join(home, '.local', 'state', appName);\n}\n\n/** Sorts by start time as text, so the latest run is the last one listed. */\nfunction newRunId(): string {\n\treturn `${new Date().toISOString().replace(/[-:.]/g, '')}-${randomBytes(3).toString('hex')}`;\n}\n\nfunction hashOf(content: Buffer): string {\n\treturn createHash('sha256').update(content).digest('hex');\n}\n\nfunction isNotFound(error: unknown): boolean {\n\treturn (error as NodeJS.ErrnoException).code === 'ENOENT';\n}\n\n/**\n * The runs and moves this process holds a workspace lock for and has not ended. A lock naming\n * this process and none of these was left by one whose release failed: it is as stale as a dead\n * process's, which a process that lives on would otherwise keep until it exits.\n */\nconst heldHere = new Set<string>();\n\n/** Whether the holder of a lock is still at work. */\nfunction isLiveHolder(holder: { runId: string; pid?: number }): boolean {\n\t// A holder that cannot be named cannot be shown to be gone.\n\tif (holder.pid === undefined) return true;\n\tif (holder.pid === process.pid) return heldHere.has(holder.runId);\n\treturn isAlive(holder.pid);\n}\n\n/** Whether a process still exists. One we may not signal exists too. */\nfunction isAlive(pid: number): boolean {\n\ttry {\n\t\tprocess.kill(pid, 0);\n\t\treturn true;\n\t} catch (error) {\n\t\treturn (error as NodeJS.ErrnoException).code === 'EPERM';\n\t}\n}\n\nasync function syncDirectory(path: string): Promise<void> {\n\tconst directory = await open(path, 'r');\n\ttry {\n\t\tawait directory.sync();\n\t} finally {\n\t\tawait directory.close();\n\t}\n}\n\n/**\n * Creates a private folder and any missing parents. A new folder only survives a crash once\n * its parent's entry for it is synced too, so each parent that gained one is.\n */\nasync function makeDirectory(path: string): Promise<void> {\n\tconst first = await mkdir(path, { recursive: true, mode: privateDirectory });\n\tif (first === undefined) return;\n\tfor (let created = path; ; created = dirname(created)) {\n\t\tawait syncDirectory(dirname(created));\n\t\tif (created === first) return;\n\t}\n}\n\n/**\n * Puts `content` at `path` all at once: a crash leaves either the old file or the new one, never\n * half of the new one. It returns only once the new file is on disk. With `exclusive`, it fails\n * with `EEXIST` instead of replacing a file already there.\n */\nasync function writeDurably(\n\tpath: string,\n\tcontent: string | Buffer,\n\t{ exclusive = false }: { exclusive?: boolean } = {},\n): Promise<void> {\n\tconst temporary = `${path}.${randomBytes(6).toString('hex')}.tmp`;\n\ttry {\n\t\tconst handle = await open(temporary, 'wx', privateFile);\n\t\ttry {\n\t\t\tawait handle.writeFile(content);\n\t\t\tawait handle.sync();\n\t\t} finally {\n\t\t\tawait handle.close();\n\t\t}\n\t\t// A link fails if the path is taken; a rename would replace it.\n\t\tawait (exclusive ? link : rename)(temporary, path);\n\t} finally {\n\t\tawait rm(temporary, { force: true });\n\t}\n\tawait syncDirectory(dirname(path));\n}\n\n/** A move not finished yet: the next move or run finishes it before anything else. */\ninterface PendingMove {\n\trevision: number;\n\tfrom?: string;\n\tto?: string;\n\treason?: string;\n\t/** Found by the steps already taken. */\n\tconflicts: MoveConflict[];\n\t/**\n\t * The temporary a file is being restored through, named before it is created, so finishing\n\t * the move removes this one and no file of the user's.\n\t */\n\ttemporary?: string;\n}\n\n/** `head.json`: the run the workspace is at, the moves made so far, and one in progress. */\ninterface Head {\n\trunId?: string;\n\trevision: number;\n\tpending?: PendingMove;\n}\n\ntype JournalLine =\n\t| ({ type: 'prepared'; sequence: number } & Omit<JournalEntry, 'sequence' | 'status'>)\n\t| { type: 'applied' | 'abandoned'; sequence: number }\n\t| { type: 'observing'; sequence: number; manifest: string; by: string }\n\t| { type: 'observed'; sequence: number; measure?: ObservationMeasure }\n\t| ({ type: 'unrecorded'; sequence: number } & UnrecordedChange);\n\n/** An observation a run began and never finished: what its command changed is not recorded yet. */\ninterface OpenObservation {\n\tsequence: number;\n\tmanifest: string;\n\tby: string;\n}\n\n/**\n * Stores `content` under its hash, unless it is stored already, and returns the hash and whether\n * it was new. It returns only once the content is on disk.\n */\nasync function storeContent(\n\tcontentDirectory: string,\n\tcontent: Buffer,\n): Promise<{ hash: string; written: boolean }> {\n\tconst hash = hashOf(content);\n\tconst path = contentPath(contentDirectory, hash);\n\tconst stored = await stat(path).then(\n\t\t() => true,\n\t\t(error: unknown) => {\n\t\t\tif (isNotFound(error)) return false;\n\t\t\tthrow error;\n\t\t},\n\t);\n\tif (!stored) {\n\t\tawait makeDirectory(dirname(path));\n\t\tawait writeDurably(path, content);\n\t}\n\treturn { hash, written: !stored };\n}\n\n/**\n * The recovery store on disk, in a private directory per workspace under the platform's state\n * directory:\n *\n * ```text\n * <directory>/workspaces/<hash of the root>/\n * workspace.json the root it belongs to\n * lock the run writing now, if any\n * head.json the run the workspace is at, and a move in progress\n * revisions.jsonl every move of the workspace through its history\n * content/<ab>/<hash> file contents, named by their SHA-256\n * runs/<runId>/run.json the run's record\n * runs/<runId>/journal.jsonl its changes, one line per step, appended and synced\n * ```\n *\n * The lock only keeps a second run of this harness from writing at the same time. It does not\n * stop an editor or another program, and two processes taking over a dead run's lock in the\n * same instant could both believe they hold it.\n */\nexport class FileRecoveryStore implements RecoveryStore {\n\treadonly workspaceId: string;\n\tprivate readonly root: string;\n\tprivate readonly directory: string;\n\tprivate readonly keepRuns: number;\n\tprivate readonly logger: ILogger;\n\n\tprivate constructor(\n\t\troot: string,\n\t\tdirectory: string,\n\t\tkeepRuns: number,\n\t\tlogger: ILogger,\n\t\tworkspaceId: string,\n\t) {\n\t\tthis.root = root;\n\t\tthis.directory = directory;\n\t\tthis.keepRuns = keepRuns;\n\t\tthis.logger = logger;\n\t\tthis.workspaceId = workspaceId;\n\t}\n\n\tstatic async open({\n\t\troot,\n\t\tdirectory = defaultStateDirectory(),\n\t\tkeepRuns = defaultKeepRuns,\n\t\tlogger = new Logger(),\n\t}: {\n\t\troot: string;\n\t\t/** Defaults to the platform's state directory. */\n\t\tdirectory?: string;\n\t\t/**\n\t\t * The most runs kept per workspace, the one being recorded included. Defaults to 25. At\n\t\t * least 3: the run the workspace is at is never removed, and the last run of its line has\n\t\t * no next run to be chained into, so pruning can leave two runs besides the new one.\n\t\t */\n\t\tkeepRuns?: number;\n\t\t/** Where it reports a failure it absorbs. Defaults to standard error. */\n\t\tlogger?: ILogger;\n\t}): Promise<FileRecoveryStore> {\n\t\tif (!Number.isInteger(keepRuns) || keepRuns < 3) {\n\t\t\tthrow new RangeError(`keepRuns must be an integer of at least 3; got ${String(keepRuns)}`);\n\t\t}\n\t\t// Two spellings of one folder, such as a symlinked path, are one workspace.\n\t\tconst realRoot = await realpath(root);\n\t\tconst workspace = join(\n\t\t\tdirectory,\n\t\t\t'workspaces',\n\t\t\tcreateHash('sha256').update(realRoot).digest('hex').slice(0, 16),\n\t\t);\n\t\tawait makeDirectory(join(workspace, 'runs'));\n\t\tawait makeDirectory(join(workspace, 'content'));\n\t\tawait writeDurably(join(workspace, 'workspace.json'), JSON.stringify({ root: realRoot }));\n\n\t\t// Real, so a state directory reached through a link is the history it holds.\n\t\treturn new FileRecoveryStore(realRoot, workspace, keepRuns, logger, await realpath(workspace));\n\t}\n\n\tasync startRun(): Promise<RunJournal> {\n\t\tconst runId = newRunId();\n\t\ttry {\n\t\t\t// Inside, because taking the lock can fail after publishing it. Unlocking removes only a\n\t\t\t// lock naming this run, never another run's.\n\t\t\tawait this.lock(runId);\n\t\t\tawait this.settleInterrupted(runId);\n\t\t\t// A run starts where the user last sent the workspace.\n\t\t\tawait this.finishPendingMove();\n\t\t\t// Before the new run exists, so it is never pruned, and after the move, so no run on its\n\t\t\t// route is.\n\t\t\tawait this.prune();\n\t\t\tconst head = await this.readHead();\n\t\t\tconst parentRunId = head.runId;\n\t\t\tconst runDirectory = join(this.directory, 'runs', runId);\n\t\t\tawait makeDirectory(runDirectory);\n\t\t\tconst record: RunRecord = {\n\t\t\t\trunId,\n\t\t\t\troot: this.root,\n\t\t\t\t...(parentRunId ? { parentRunId } : {}),\n\t\t\t\tstartedAt: new Date().toISOString(),\n\t\t\t\tstatus: 'running',\n\t\t\t\tpid: process.pid,\n\t\t\t};\n\t\t\tawait writeDurably(join(runDirectory, 'run.json'), JSON.stringify(record));\n\t\t\t// After the record, so the head never names a run that does not exist.\n\t\t\tawait this.writeHead({ runId, revision: head.revision });\n\t\t\tconst journal = await open(join(runDirectory, firstJournal), 'a', privateFile);\n\t\t\tawait syncDirectory(runDirectory);\n\n\t\t\treturn new FileRunJournal({\n\t\t\t\trecord,\n\t\t\t\trunDirectory,\n\t\t\t\tcontentDirectory: join(this.directory, 'content'),\n\t\t\t\tjournal,\n\t\t\t\tdiscard: () => this.discardRun(record),\n\t\t\t\tsettle: finished => this.settleAtFinish(finished),\n\t\t\t\trelease: () => this.unlock(runId),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tawait this.unlock(runId);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync listRuns(): Promise<{ head?: string; runs: RunRecord[] }> {\n\t\tconst ids = (await readdir(join(this.directory, 'runs'))).filter(id => runIdPattern.test(id));\n\t\tconst holder = await readLock(join(this.directory, 'lock'));\n\t\tconst runs: RunRecord[] = [];\n\t\tfor (const runId of ids.sort()) {\n\t\t\tconst record = await this.readRecord(runId).catch((error: unknown) => {\n\t\t\t\t// A crash between creating a run's folder and writing its record leaves the folder\n\t\t\t\t// empty: that run never changed anything.\n\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tif (record) runs.push(withLiveStatus(record, holder));\n\t\t}\n\t\t// A run retention removed or chained into a later one, whose folder a crash left behind, is\n\t\t// not in the history.\n\t\tconst gone = new Set([\n\t\t\t...runs.flatMap(run => run.absorbed ?? []),\n\t\t\t...(await this.listPruned()),\n\t\t]);\n\t\t// A dead run that changed nothing is not in the history either, though its removal did not\n\t\t// finish. No run follows it: the next run or move removes it before starting.\n\t\tfor (const run of runs) {\n\t\t\tif (run.status !== 'interrupted') continue;\n\t\t\t// A journal it cannot read leaves the run listed: whether it changed anything is unknown.\n\t\t\tconst journal = await this.readJournal(run.runId, run.journal).catch(() => undefined);\n\t\t\tif (journal && changedNothing(journal)) gone.add(run.runId);\n\t\t}\n\t\tconst parents = new Map(runs.map(run => [run.runId, run.parentRunId]));\n\t\tlet { runId: head } = await this.readHead();\n\t\twhile (head !== undefined && gone.has(head)) head = parents.get(head);\n\n\t\treturn { ...(head ? { head } : {}), runs: runs.filter(run => !gone.has(run.runId)) };\n\t}\n\n\tasync readRun(\n\t\trunId: string,\n\t): Promise<{ record: RunRecord; entries: JournalEntry[]; unrecorded: UnrecordedChange[] }> {\n\t\t// An id from outside is checked before it names a folder.\n\t\tif (!runIdPattern.test(runId)) throw new UnknownRunError(runId);\n\t\t// The lock first: a run that finishes between the two reads then shows as finished, not as\n\t\t// a `running` record nobody holds.\n\t\tconst holder = await readLock(join(this.directory, 'lock'));\n\t\t// Before the record: a crash can leave the folder of a run retention already took.\n\t\tawait this.assertNotAbsorbed(runId);\n\t\tconst record = await this.readRecord(runId).catch(async (error: unknown) => {\n\t\t\tif (!isNotFound(error)) throw error;\n\t\t\t// Retention may have taken it since the check above.\n\t\t\tawait this.assertNotAbsorbed(runId);\n\t\t\tthrow new UnknownRunError(runId);\n\t\t});\n\t\tconst { entries, unrecorded } = await this.readJournal(runId, record.journal);\n\t\treturn {\n\t\t\trecord: withLiveStatus(record, holder),\n\t\t\tentries,\n\t\t\tunrecorded: unrecorded.map(({ path, by }) => ({ path, by })),\n\t\t};\n\t}\n\n\tprivate async readRecord(runId: string): Promise<RunRecord> {\n\t\treturn JSON.parse(\n\t\t\tawait readFile(join(this.runDirectory(runId), 'run.json'), 'utf8'),\n\t\t) as RunRecord;\n\t}\n\n\tprivate runDirectory(runId: string): string {\n\t\t// The id names a folder, so it must never be a path of its own.\n\t\tif (!runIdPattern.test(runId)) throw new Error(`Not a run id: ${runId}`);\n\t\treturn join(this.directory, 'runs', runId);\n\t}\n\n\tprivate async readHead(): Promise<Head> {\n\t\ttry {\n\t\t\tconst head = JSON.parse(\n\t\t\t\tawait readFile(join(this.directory, 'head.json'), 'utf8'),\n\t\t\t) as Partial<Head>;\n\t\t\treturn { ...head, revision: head.revision ?? 0 };\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) return { revision: 0 };\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate async writeHead(head: Head): Promise<void> {\n\t\tawait writeDurably(join(this.directory, 'head.json'), JSON.stringify(head));\n\t}\n\n\tgoTo(target: string, options: MoveOptions = {}): Promise<Revision> {\n\t\treturn this.move(() => (target === historyStart ? undefined : target), options);\n\t}\n\n\tundo(options: MoveOptions = {}): Promise<Revision> {\n\t\treturn this.move(({ runs, head }) => {\n\t\t\tif (head === undefined) throw new NothingToMoveError('undo');\n\t\t\treturn runs.find(run => run.runId === head)?.parentRunId;\n\t\t}, options);\n\t}\n\n\tredo(options: MoveOptions = {}): Promise<Revision> {\n\t\treturn this.move(({ runs, head, revisions }) => {\n\t\t\tconst target = redoTarget(runs, revisions, head);\n\t\t\tif (target === undefined) throw new NothingToMoveError('redo');\n\t\t\treturn target;\n\t\t}, options);\n\t}\n\n\tasync listRevisions(): Promise<Revision[]> {\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = await readFile(join(this.directory, 'revisions.jsonl'), 'utf8');\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) return [];\n\t\t\tthrow error;\n\t\t}\n\t\tconst lines = text.split('\\n');\n\t\treturn lines.flatMap((line, index) => {\n\t\t\tif (line === '') return [];\n\t\t\ttry {\n\t\t\t\treturn [JSON.parse(line) as Revision];\n\t\t\t} catch (error) {\n\t\t\t\t// A crash in the middle of an append leaves half a line, always the last one. Its\n\t\t\t\t// move is still pending, and finishing it records it again.\n\t\t\t\tif (index === lines.length - 1) return [];\n\t\t\t\tthrow new Error(`The history of this workspace is corrupt at line ${String(index + 1)}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Holds the workspace like a run does, then moves it to the run `resolve` picks. */\n\tprivate async move(\n\t\tresolve: (history: {\n\t\t\truns: RunRecord[];\n\t\t\thead: string | undefined;\n\t\t\trevisions: Revision[];\n\t\t}) => string | undefined,\n\t\t{ reason, from }: MoveOptions,\n\t): Promise<Revision> {\n\t\tconst moveId = `move-${newRunId()}`;\n\t\ttry {\n\t\t\tawait this.lock(moveId);\n\t\t\tawait this.settleInterrupted(moveId);\n\t\t\tawait this.finishPendingMove();\n\t\t\tconst head = await this.readHead();\n\t\t\t// Only now, under the lock and once nothing is left unsettled, is the head the one the\n\t\t\t// move would start from.\n\t\t\tconst at = head.runId ?? historyStart;\n\t\t\tif (from !== undefined && from !== at) throw new WorkspaceMovedError(from, at);\n\t\t\tconst { runs } = await this.listRuns();\n\t\t\tconst to = resolve({ runs, head: head.runId, revisions: await this.listRevisions() });\n\t\t\tif (to !== undefined && !runs.some(run => run.runId === to)) {\n\t\t\t\tawait this.assertNotAbsorbed(to);\n\t\t\t}\n\n\t\t\treturn await this.takeSteps(head, runs, {\n\t\t\t\trevision: head.revision + 1,\n\t\t\t\t...(head.runId ? { from: head.runId } : {}),\n\t\t\t\t...(to ? { to } : {}),\n\t\t\t\t...(reason === undefined ? {} : { reason }),\n\t\t\t\tconflicts: [],\n\t\t\t});\n\t\t} finally {\n\t\t\tawait this.unlock(moveId);\n\t\t}\n\t}\n\n\t/** Finishes a move whose process stopped halfway, from the run its last step reached. */\n\tprivate async finishPendingMove(): Promise<void> {\n\t\tconst head = await this.readHead();\n\t\tconst { pending } = head;\n\t\tif (!pending) return;\n\t\t// It was recorded, and only clearing it from the head was missing.\n\t\tif ((await this.listRevisions()).some(revision => revision.revision === pending.revision)) {\n\t\t\tawait this.writeHead({\n\t\t\t\t...(pending.to ? { runId: pending.to } : {}),\n\t\t\t\trevision: pending.revision,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tawait this.takeSteps(head, (await this.listRuns()).runs, pending);\n\t}\n\n\t/**\n\t * Undoes, then redoes, one run at a time from where the head is to `pending.to`. After each\n\t * step the head names the run reached, with the move still pending, so a crash loses at\n\t * most the step in progress, and that step is safe to take again.\n\t */\n\tprivate async takeSteps(head: Head, runs: RunRecord[], pending: PendingMove): Promise<Revision> {\n\t\tconst { undo, redo } = route(runs, head.runId, pending.to);\n\t\tconst parents = new Map(runs.map(run => [run.runId, run.parentRunId]));\n\t\tlet reached = head.runId;\n\t\tconst save = () =>\n\t\t\tthis.writeHead({ ...(reached ? { runId: reached } : {}), revision: head.revision, pending });\n\n\t\t// What a write the crash interrupted left beside its file.\n\t\tif (pending.temporary) {\n\t\t\tawait removeTemporary(pending.temporary);\n\t\t\tdelete pending.temporary;\n\t\t}\n\t\tawait save();\n\t\tconst announce = async (temporary: string | undefined) => {\n\t\t\tif (temporary === undefined) delete pending.temporary;\n\t\t\telse pending.temporary = temporary;\n\t\t\tawait save();\n\t\t};\n\t\tfor (const runId of undo) {\n\t\t\tpending.conflicts.push(...(await this.step(runId, 'undo', announce)));\n\t\t\treached = parents.get(runId);\n\t\t\tawait save();\n\t\t}\n\t\tfor (const runId of redo) {\n\t\t\tpending.conflicts.push(...(await this.step(runId, 'redo', announce)));\n\t\t\treached = runId;\n\t\t\tawait save();\n\t\t}\n\n\t\t// Every write that started has finished, so no temporary is left to name.\n\t\tdelete pending.temporary;\n\t\tconst { conflicts, ...rest } = pending;\n\t\tconst revision: Revision = {\n\t\t\t...rest,\n\t\t\tat: new Date().toISOString(),\n\t\t\tcomplete: conflicts.length === 0,\n\t\t\tconflicts,\n\t\t};\n\t\tawait this.appendRevision(revision);\n\t\tawait this.writeHead({\n\t\t\t...(pending.to ? { runId: pending.to } : {}),\n\t\t\trevision: pending.revision,\n\t\t});\n\t\treturn revision;\n\t}\n\n\t/** Takes one run's changes back to its parent, or forward again, file by file. */\n\tprivate async step(\n\t\trunId: string,\n\t\tdirection: 'undo' | 'redo',\n\t\tannounce: (temporary: string | undefined) => Promise<void>,\n\t): Promise<MoveConflict[]> {\n\t\tconst { entries, unrecorded } = await this.readRun(runId);\n\t\tconst changes = fileChanges(entries, true);\n\t\t// What the history could not copy is left as it is, in either direction.\n\t\tconst conflicting = new Set(unrecorded.map(change => change.path));\n\t\t// Undone newest first, so a folder the run created is empty by the time its file goes.\n\t\tfor (const change of direction === 'undo' ? changes.reverse() : changes) {\n\t\t\tif (!(await this.moveFile(change, direction, announce))) conflicting.add(change.path);\n\t\t}\n\t\treturn [...conflicting].map((path): MoveConflict => ({ path, runId }));\n\t}\n\n\t/**\n\t * Writes the state the step leads to, only if the file holds the state it leaves. A file\n\t * already there is left alone, so taking a step again is safe. Returns whether the file\n\t * ends where the step leads.\n\t */\n\tprivate async moveFile(\n\t\tchange: FileChange,\n\t\tdirection: 'undo' | 'redo',\n\t\tannounce: (temporary: string | undefined) => Promise<void>,\n\t): Promise<boolean> {\n\t\tconst [source, destination] =\n\t\t\tdirection === 'undo' ? [change.after, change.before] : [change.before, change.after];\n\t\t// First, so a file reached through a folder that became a link is never taken for the\n\t\t// destination, and nothing is read or removed through it.\n\t\tif (!(await hasRealParents(change.path))) return false;\n\t\tconst current = await currentState(change.path);\n\n\t\tif (current && sameState(current, destination)) {\n\t\t\tif (direction === 'undo' && !destination.exists) {\n\t\t\t\tawait removeEmptyFolders(change.createdFolders);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tif (!current || !sameState(current, source)) return false;\n\t\t// Someone wrote to the file between two of the run's changes, and going back to before\n\t\t// the first would discard that.\n\t\tif (direction === 'undo' && !change.continuous) return false;\n\n\t\tif (destination.exists) {\n\t\t\tconst temporary = temporaryPath(change.path);\n\t\t\tawait announce(temporary);\n\t\t\tawait writeFileState(\n\t\t\t\tchange.path,\n\t\t\t\tawait this.readContent(destination.hash),\n\t\t\t\tdestination.mode,\n\t\t\t\ttemporary,\n\t\t\t);\n\t\t\tawait announce(undefined);\n\t\t} else {\n\t\t\tawait removeFile(change.path);\n\t\t\tif (direction === 'undo') await removeEmptyFolders(change.createdFolders);\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Throws `HistoryExpiredError` if retention removed `runId` or chained it into a later run. */\n\tprivate async assertNotAbsorbed(runId: string): Promise<void> {\n\t\tconst { runs } = await this.listRuns();\n\t\tconst keptIn = runs.find(run => run.absorbed?.includes(runId));\n\t\tif (keptIn) throw new HistoryExpiredError(runId, keptIn.runId);\n\t\tif ((await this.listPruned()).includes(runId)) throw new HistoryExpiredError(runId);\n\t}\n\n\tprivate async listPruned(): Promise<string[]> {\n\t\ttry {\n\t\t\tconst text = await readFile(join(this.directory, 'pruned.jsonl'), 'utf8');\n\t\t\treturn text.split('\\n').flatMap(line => {\n\t\t\t\ttry {\n\t\t\t\t\treturn [JSON.parse(line) as string];\n\t\t\t\t} catch {\n\t\t\t\t\t// Half a line a crash left, whose removal never happened.\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) return [];\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Brings the history down to `keepRuns - 1`, so the run about to start makes `keepRuns`, then\n\t * frees the contents no run kept refers to.\n\t */\n\tprivate async prune(): Promise<void> {\n\t\tawait this.finishChains();\n\t\tconst revisions = await this.listRevisions();\n\t\tfor (;;) {\n\t\t\tconst { head, runs } = await this.listRuns();\n\t\t\tconst step = nextPruneStep(runs, revisions, head, this.keepRuns - 1);\n\t\t\tif (!step) break;\n\t\t\tif (step.kind === 'remove') await this.removeRun(step.runId);\n\t\t\telse await this.chain(step.runId, step.into);\n\t\t}\n\t\tawait this.collectContent();\n\t}\n\n\t/**\n\t * Chains the changes of `older` into `newer`, its child: `newer` then hangs from `older`'s\n\t * parent and goes back to where `older` started. The new record is the commit point. Before\n\t * it, the history is as it was; after it, `finishChains` removes what is left of `older`.\n\t */\n\tprivate async chain(older: string, newer: string): Promise<void> {\n\t\tconst olderRecord = await this.readRecord(older);\n\t\tconst newerRecord = await this.readRecord(newer);\n\t\tconst olderJournal = await this.readJournal(older, olderRecord.journal);\n\t\tconst newerJournal = await this.readJournal(newer, newerRecord.journal);\n\t\tconst entries = chainEntries(olderJournal.entries, newerJournal.entries);\n\t\tconst journal = `journal-${randomBytes(4).toString('hex')}.jsonl`;\n\t\tconst lines = entries.flatMap(({ status, sequence, ...change }): JournalLine[] => [\n\t\t\t{ type: 'prepared', sequence, ...change },\n\t\t\t...(status === 'prepared' ? [] : [{ type: status, sequence } as const]),\n\t\t]);\n\t\t// What either run could not copy stays uncopied: undoing the chain cannot take it back.\n\t\tfor (const [index, { path, by }] of [\n\t\t\t...olderJournal.unrecorded,\n\t\t\t...newerJournal.unrecorded,\n\t\t].entries()) {\n\t\t\tlines.push({ type: 'unrecorded', sequence: entries.length + index + 1, path, by });\n\t\t}\n\t\tawait writeDurably(\n\t\t\tjoin(this.runDirectory(newer), journal),\n\t\t\tlines.map(line => `${JSON.stringify(line)}\\n`).join(''),\n\t\t);\n\n\t\tconst record: RunRecord = {\n\t\t\t...newerRecord,\n\t\t\tabsorbed: [...(olderRecord.absorbed ?? []), older, ...(newerRecord.absorbed ?? [])],\n\t\t\tjournal,\n\t\t};\n\t\t// It now hangs where `older` did: from its parent, or from the start.\n\t\tif (olderRecord.parentRunId) record.parentRunId = olderRecord.parentRunId;\n\t\telse delete record.parentRunId;\n\t\tawait writeDurably(join(this.runDirectory(newer), 'run.json'), JSON.stringify(record));\n\t\tawait this.finishChains();\n\t}\n\n\t/**\n\t * Removes what a chain or a removal a crash interrupted left behind: the folders of runs\n\t * pruned or absorbed by a kept run, and journals a run no longer reads.\n\t */\n\tprivate async finishChains(): Promise<void> {\n\t\tfor (const runId of await this.listPruned()) {\n\t\t\tawait rm(this.runDirectory(runId), { recursive: true, force: true });\n\t\t}\n\t\tconst { runs } = await this.listRuns();\n\t\tfor (const run of runs) {\n\t\t\tfor (const absorbed of run.absorbed ?? []) {\n\t\t\t\tawait rm(this.runDirectory(absorbed), { recursive: true, force: true });\n\t\t\t}\n\t\t\tconst current = run.journal ?? firstJournal;\n\t\t\tfor (const name of await readdir(this.runDirectory(run.runId))) {\n\t\t\t\tif (name.startsWith('journal') && name.endsWith('.jsonl') && name !== current) {\n\t\t\t\t\tawait rm(join(this.runDirectory(run.runId), name), { force: true });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes a run whole, recording its id first so a move to it reports an expired history.\n\t * Its record goes next, so a crash halfway leaves no run behind.\n\t */\n\tprivate async removeRun(runId: string): Promise<void> {\n\t\tawait appendWhole(join(this.directory, 'pruned.jsonl'), [runId]);\n\t\t// The log may be new: its entry in the folder must last before the run it names goes.\n\t\tawait syncDirectory(this.directory);\n\t\tawait rm(join(this.runDirectory(runId), 'run.json'), { force: true });\n\t\tawait syncDirectory(this.runDirectory(runId));\n\t\tawait rm(this.runDirectory(runId), { recursive: true, force: true });\n\t}\n\n\t/**\n\t * Takes a run that changed nothing out of the history, under the lock: the workspace goes back\n\t * to its parent first, so the head never names a run that is gone. Until the run is removed,\n\t * `listRuns` already hides it, and the next run or move finishes removing it. The contents it\n\t * saved are freed by the next prune.\n\t */\n\tprivate async discardRun(record: RunRecord): Promise<void> {\n\t\tconst { runId: headRunId, ...head } = await this.readHead();\n\t\tif (headRunId === record.runId) {\n\t\t\tawait this.writeHead({\n\t\t\t\t...head,\n\t\t\t\t...(record.parentRunId ? { runId: record.parentRunId } : {}),\n\t\t\t});\n\t\t}\n\t\tawait rm(join(this.runDirectory(record.runId), 'run.json'), { force: true });\n\t\tawait syncDirectory(this.runDirectory(record.runId));\n\t\tawait rm(this.runDirectory(record.runId), { recursive: true, force: true });\n\t}\n\n\t/**\n\t * Removes the stored contents no kept run refers to. An observation still open refers to its\n\t * manifest and to every content in it, which settling it needs.\n\t */\n\tprivate async collectContent(): Promise<void> {\n\t\tconst referenced = new Set<string>();\n\t\tfor (const run of (await this.listRuns()).runs) {\n\t\t\tconst { entries, observations } = await this.readJournal(run.runId, run.journal);\n\t\t\tfor (const entry of entries) {\n\t\t\t\tfor (const state of [entry.before, entry.after]) {\n\t\t\t\t\tif (state.exists) referenced.add(state.hash);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const observation of observations) {\n\t\t\t\treferenced.add(observation.manifest);\n\t\t\t\tconst stored = await this.readContent(observation.manifest).catch((error: unknown) => {\n\t\t\t\t\t// Never stored whole: settling it will find nothing to compare.\n\t\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t\tif (!stored) continue;\n\t\t\t\tconst manifest = JSON.parse(stored.toString('utf8')) as Manifest;\n\t\t\t\tfor (const state of Object.values(manifest.files)) {\n\t\t\t\t\tif (state.exists) referenced.add(state.hash);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst contentDirectory = join(this.directory, 'content');\n\t\tfor (const prefix of await readdir(contentDirectory)) {\n\t\t\tfor (const hash of await readdir(join(contentDirectory, prefix))) {\n\t\t\t\tif (hashPattern.test(hash) && !referenced.has(hash)) {\n\t\t\t\t\tawait rm(join(contentDirectory, prefix, hash), { force: true });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async appendRevision(revision: Revision): Promise<void> {\n\t\tawait appendWhole(join(this.directory, 'revisions.jsonl'), [revision]);\n\t\tawait syncDirectory(this.directory);\n\t}\n\n\t/**\n\t * Settles every other run left unfinished: one still recorded as `running` is `interrupted`,\n\t * since this run holds the lock and its process is gone, and one that finished `unsettled`\n\t * keeps its status.\n\t */\n\tprivate async settleInterrupted(ownRunId: string): Promise<void> {\n\t\tconst ids = (await readdir(join(this.directory, 'runs'))).filter(\n\t\t\tid => runIdPattern.test(id) && id !== ownRunId,\n\t\t);\n\t\tfor (const runId of ids) {\n\t\t\tconst record = await this.readRecord(runId).catch((error: unknown) => {\n\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tif (record?.status === 'running' || record?.unsettled) await this.settleRun(record);\n\t\t}\n\t}\n\n\t/**\n\t * Settles a run that finished with an observation open, under its own lock, before it releases\n\t * the workspace. If that fails, its record stays `unsettled`, and the next run or move settles\n\t * it, so the failure is reported and not thrown.\n\t */\n\tprivate async settleAtFinish(record: RunRecord): Promise<boolean> {\n\t\ttry {\n\t\t\treturn await this.settleRun(record, { finishing: true });\n\t\t} catch (error) {\n\t\t\ttreatErrors(\n\t\t\t\t() => {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t`The history could not settle what run ${record.runId} was observing when it finished; the next run or move settles it: ${describeFailure(error)}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tclassifyHostFailure,\n\t\t\t\t'Recovery store logger failed while reporting an unsettled run',\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t/**\n\t * Settles what a run left unfinished. Each change it left `prepared` is settled from what its\n\t * file holds now: its `after` means it was made, its `before` that it was not. A file that holds\n\t * neither stays `prepared`, because nothing tells whether the change reached it. Each\n\t * observation it left open is settled from its manifest. A run still `running` becomes\n\t * `interrupted`; any other keeps its status. Whether the run is still in the history: one that\n\t * changed nothing leaves it if it was still `running`, or if it is `finishing`, which unties\n\t * its turns from it. One that finished is kept otherwise, since the turns of a conversation may\n\t * name it.\n\t */\n\tprivate async settleRun(\n\t\trecord: RunRecord,\n\t\t{ finishing = false }: { finishing?: boolean } = {},\n\t): Promise<boolean> {\n\t\tconst { runId } = record;\n\t\tconst journal = await this.readJournal(runId, record.journal);\n\t\tconst lines: JournalLine[] = [];\n\t\tfor (const entry of journal.entries) {\n\t\t\tif (entry.status !== 'prepared' || !isAbsolute(entry.path)) continue;\n\t\t\tconst state = await currentState(entry.path);\n\t\t\tif (state && sameState(state, entry.after)) {\n\t\t\t\tlines.push({ type: 'applied', sequence: entry.sequence });\n\t\t\t} else if (state && sameState(state, entry.before)) {\n\t\t\t\tlines.push({ type: 'abandoned', sequence: entry.sequence });\n\t\t\t}\n\t\t}\n\t\tlet sequence = journal.lastSequence;\n\t\tfor (const observation of journal.observations) {\n\t\t\tconst observed = await this.settleObservation(observation, journal, sequence);\n\t\t\tsequence += observed.length;\n\t\t\tlines.push(...observed);\n\t\t}\n\t\tawait appendWhole(join(this.runDirectory(runId), record.journal ?? firstJournal), lines);\n\t\tconst leaves = finishing || record.status === 'running';\n\t\tif (leaves && changedNothing(await this.readJournal(runId, record.journal))) {\n\t\t\tawait this.discardRun(record);\n\t\t\treturn false;\n\t\t}\n\t\tconst settled: RunRecord = {\n\t\t\t...record,\n\t\t\tstatus: record.status === 'running' ? 'interrupted' : record.status,\n\t\t};\n\t\tdelete settled.unsettled;\n\t\t// Last, so a crash before it leaves a run that is settled again, and settling is idempotent.\n\t\tawait writeDurably(join(this.runDirectory(runId), 'run.json'), JSON.stringify(settled));\n\t\treturn true;\n\t}\n\n\t/**\n\t * The lines that record what a command an interrupted run was observing changed: every file of\n\t * its manifest that holds something else now, as changed by that command, and then the end of\n\t * the observation. A file recorded after the observation began is left alone: the run\n\t * recorded it itself. One that is now a folder, a link or too large to record, or that was one\n\t * and is no longer, or that cannot be read, is recorded as a change the history could not copy.\n\t */\n\tprivate async settleObservation(\n\t\tobservation: OpenObservation,\n\t\t{\n\t\t\tentries,\n\t\t\tunrecorded: uncopied,\n\t\t}: { entries: JournalEntry[]; unrecorded: { sequence: number; path: string }[] },\n\t\tlastSequence: number,\n\t): Promise<JournalLine[]> {\n\t\tconst stored = await this.readContent(observation.manifest).catch((error: unknown) => {\n\t\t\tif (isNotFound(error)) return undefined;\n\t\t\tthrow error;\n\t\t});\n\t\t// Its manifest was never stored whole: the command it was saved for never started.\n\t\tif (!stored) return [{ type: 'observed', sequence: observation.sequence }];\n\t\tconst manifest = JSON.parse(stored.toString('utf8')) as Manifest;\n\t\t// What the run recorded itself after the observation began, its changes and those it could\n\t\t// not copy, such as when a command could not be confirmed stopped.\n\t\tconst recorded = new Set(\n\t\t\t[...entries, ...uncopied]\n\t\t\t\t.filter(line => line.sequence > observation.sequence)\n\t\t\t\t.map(line => line.path),\n\t\t);\n\t\tconst lines: JournalLine[] = [];\n\t\tlet sequence = lastSequence;\n\t\tconst unrecorded = (path: string): JournalLine => ({\n\t\t\ttype: 'unrecorded',\n\t\t\tsequence: ++sequence,\n\t\t\tpath,\n\t\t\tby: observation.by,\n\t\t});\n\t\tfor (const [path, before] of Object.entries(manifest.files)) {\n\t\t\tif (!isAbsolute(path) || recorded.has(path)) continue;\n\t\t\tconst after = await this.saveState(path);\n\t\t\tif (after === undefined || after === 'unreadable') {\n\t\t\t\tlines.push(unrecorded(path));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (sameState(after, before)) continue;\n\t\t\tsequence++;\n\t\t\tlines.push(\n\t\t\t\t{ type: 'prepared', sequence, path, before, after, observedBy: observation.by },\n\t\t\t\t{ type: 'applied', sequence },\n\t\t\t);\n\t\t}\n\t\t// What it held before is unknown, so only a path that is no longer uncopyable has changed.\n\t\tfor (const path of manifest.uncopyable ?? []) {\n\t\t\tif (!isAbsolute(path) || recorded.has(path)) continue;\n\t\t\tconst now = await currentState(path).catch((error: unknown) => {\n\t\t\t\tthis.warnUnreadable(path, error);\n\t\t\t\treturn 'unreadable' as const;\n\t\t\t});\n\t\t\tif (now !== undefined) lines.push(unrecorded(path));\n\t\t}\n\t\tlines.push({ type: 'observed', sequence: observation.sequence });\n\t\treturn lines;\n\t}\n\n\tprivate warnUnreadable(path: string, error: unknown): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger.warn(\n\t\t\t\t\t`The history could not read ${path} to settle what a command changed, and records it as a change undo cannot take back: ${describeFailure(error)}`,\n\t\t\t\t);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'Recovery store logger failed while reporting an unreadable file',\n\t\t);\n\t}\n\n\t/**\n\t * What `path` holds now, with its content stored, or `undefined` for what no entry records.\n\t * A file it cannot read is `unreadable`, and reported: it cannot be undone either, and settling\n\t * never waits on it, or every later run would fail to start. A failure to store its content is\n\t * thrown, so the observation stays open and settling it is tried again.\n\t */\n\tprivate async saveState(path: string): Promise<FileState | undefined | 'unreadable'> {\n\t\tlet state: FileState | undefined;\n\t\tlet content: Buffer | undefined;\n\t\ttry {\n\t\t\tstate = await currentState(path);\n\t\t\tif (!state?.exists) return state;\n\t\t\tcontent = await readFile(path).catch((error: unknown) => {\n\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.warnUnreadable(path, error);\n\t\t\treturn 'unreadable';\n\t\t}\n\t\tif (!content) return { exists: false };\n\t\tconst { hash } = await storeContent(join(this.directory, 'content'), content);\n\t\t// Read again: the file may have changed between hashing it and storing it.\n\t\treturn hash === state.hash ? state : this.saveState(path);\n\t}\n\n\tprivate async readEntries(runId: string, journal = firstJournal): Promise<JournalEntry[]> {\n\t\treturn (await this.readJournal(runId, journal)).entries;\n\t}\n\n\t/**\n\t * A run's changes, the observations it began and never finished, and the highest sequence\n\t * number its journal uses, which the next line it gets must exceed.\n\t */\n\tprivate async readJournal(\n\t\trunId: string,\n\t\tjournal = firstJournal,\n\t): Promise<{\n\t\tentries: JournalEntry[];\n\t\tobservations: OpenObservation[];\n\t\t/** With the sequence of its line, which `readRun` leaves out. */\n\t\tunrecorded: (UnrecordedChange & { sequence: number })[];\n\t\tlastSequence: number;\n\t}> {\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = await readFile(join(this.runDirectory(runId), journal), 'utf8');\n\t\t} catch (error) {\n\t\t\t// A run that stopped before opening its journal never changed anything.\n\t\t\tif (isNotFound(error)) {\n\t\t\t\treturn { entries: [], observations: [], unrecorded: [], lastSequence: 0 };\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tconst lines = text.split('\\n');\n\n\t\tconst entries = new Map<number, JournalEntry>();\n\t\tconst observations = new Map<number, OpenObservation>();\n\t\tconst unrecorded: (UnrecordedChange & { sequence: number })[] = [];\n\t\tlet lastSequence = 0;\n\t\tlines.forEach((text, index) => {\n\t\t\tif (text === '') return;\n\t\t\tlet line: JournalLine;\n\t\t\ttry {\n\t\t\t\tline = JSON.parse(text) as JournalLine;\n\t\t\t} catch (error) {\n\t\t\t\t// A crash in the middle of an append leaves half a line, always the last one. Its\n\t\t\t\t// step never returned, so no change was made after it.\n\t\t\t\tif (index === lines.length - 1) return;\n\t\t\t\tthrow new Error(`The journal of run ${runId} is corrupt at line ${String(index + 1)}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t\tlastSequence = Math.max(lastSequence, line.sequence);\n\t\t\tif (line.type === 'prepared') {\n\t\t\t\tconst { sequence, path, before, after, createdFolders, observedBy } = line;\n\t\t\t\tentries.set(sequence, {\n\t\t\t\t\tsequence,\n\t\t\t\t\tpath,\n\t\t\t\t\tbefore,\n\t\t\t\t\tafter,\n\t\t\t\t\t...(createdFolders ? { createdFolders } : {}),\n\t\t\t\t\t...(observedBy === undefined ? {} : { observedBy }),\n\t\t\t\t\tstatus: 'prepared',\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (line.type === 'observing') {\n\t\t\t\tconst { sequence, manifest, by } = line;\n\t\t\t\tobservations.set(sequence, { sequence, manifest, by });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (line.type === 'observed') {\n\t\t\t\tobservations.delete(line.sequence);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (line.type === 'unrecorded') {\n\t\t\t\tunrecorded.push({ sequence: line.sequence, path: line.path, by: line.by });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst entry = entries.get(line.sequence);\n\t\t\tif (entry) entry.status = line.type;\n\t\t});\n\n\t\treturn {\n\t\t\tentries: [...entries.values()],\n\t\t\tobservations: [...observations.values()],\n\t\t\tunrecorded,\n\t\t\tlastSequence,\n\t\t};\n\t}\n\n\tasync readContent(hash: string): Promise<Buffer> {\n\t\tif (!hashPattern.test(hash)) throw new Error(`Not a content hash: ${hash}`);\n\t\treturn readFile(contentPath(join(this.directory, 'content'), hash));\n\t}\n\n\tprivate async lock(runId: string): Promise<void> {\n\t\tconst path = join(this.directory, 'lock');\n\t\t// Twice at most: once as it is, and once more after clearing a dead run's lock.\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\ttry {\n\t\t\t\t// Written whole before it appears, so a lock that exists always names its holder.\n\t\t\t\tawait writeDurably(path, JSON.stringify({ runId, pid: process.pid }), { exclusive: true });\n\t\t\t\theldHere.add(runId);\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tif ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n\t\t\t}\n\n\t\t\tconst holder = await readLock(path);\n\t\t\t// Released meanwhile: try again.\n\t\t\tif (!holder) continue;\n\t\t\tif (isLiveHolder(holder)) throw new WorkspaceBusyError(holder.runId);\n\t\t\t// Its process died, or its run ended, without releasing it. Read again just before\n\t\t\t// removing, so a lock another run has just taken is left alone.\n\t\t\tconst again = await readLock(path);\n\t\t\tif (again !== undefined && again.pid === holder.pid && again.runId === holder.runId) {\n\t\t\t\tawait unlink(path).catch((error: unknown) => {\n\t\t\t\t\tif (!isNotFound(error)) throw error;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tthrow new WorkspaceBusyError((await readLock(path))?.runId ?? 'unknown');\n\t}\n\n\tprivate async unlock(runId: string): Promise<void> {\n\t\t// First: the run has ended even if removing its lock fails, so that lock is stale.\n\t\theldHere.delete(runId);\n\t\tconst path = join(this.directory, 'lock');\n\t\t// Only its own lock: one cleared as stale and taken by another run is not this run's.\n\t\tif ((await readLock(path))?.runId === runId) await unlink(path);\n\t}\n}\n\n/**\n * No change it recorded may have reached a file: it recorded none, or abandoned each one, and\n * none it could not copy.\n */\nfunction changedNothing({\n\tentries,\n\tunrecorded,\n}: {\n\tentries: JournalEntry[];\n\tunrecorded: UnrecordedChange[];\n}): boolean {\n\treturn unrecorded.length === 0 && entries.every(entry => entry.status === 'abandoned');\n}\n\n/**\n * A run recorded as `running` only runs while it holds the lock, its process lives, and, in this\n * process, it has not ended. Any other is reported as `interrupted`, before the next run settles\n * it.\n */\nfunction withLiveStatus(\n\trecord: RunRecord,\n\tholder: { runId: string; pid?: number } | undefined,\n): RunRecord {\n\tif (record.status !== 'running') return record;\n\tconst live = holder?.runId === record.runId && holder.pid !== undefined && isLiveHolder(holder);\n\treturn live ? record : { ...record, status: 'interrupted' };\n}\n\n/**\n * Appends `lines`, as JSON, to a file of one line each, created private if missing. A crash may\n * have left its last line without a newline. A whole line, which the readers already count, is\n * kept and ended. Half a line would join the first new line, so it is cut off: whatever was\n * writing it never returned.\n */\nasync function appendWhole(path: string, lines: unknown[]): Promise<void> {\n\tif (lines.length === 0) return;\n\tlet text = '';\n\ttry {\n\t\ttext = await readFile(path, 'utf8');\n\t} catch (error) {\n\t\tif (!isNotFound(error)) throw error;\n\t}\n\tconst last = text.slice(text.lastIndexOf('\\n') + 1);\n\tlet separator = '';\n\tif (last !== '') {\n\t\tif (isWholeLine(last)) separator = '\\n';\n\t\telse await truncate(path, Buffer.byteLength(text) - Buffer.byteLength(last));\n\t}\n\tconst journal = await open(path, 'a', privateFile);\n\ttry {\n\t\tawait journal.appendFile(separator + lines.map(line => `${JSON.stringify(line)}\\n`).join(''));\n\t\tawait journal.sync();\n\t} finally {\n\t\tawait journal.close();\n\t}\n}\n\nfunction isWholeLine(text: string): boolean {\n\ttry {\n\t\tJSON.parse(text);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Who holds the lock, or `undefined` when nobody does. A lock this store did not write whole\n * has no `pid`, so it is never taken for a dead run's.\n */\nasync function readLock(path: string): Promise<{ runId: string; pid?: number } | undefined> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(path, 'utf8');\n\t} catch (error) {\n\t\tif (isNotFound(error)) return undefined;\n\t\tthrow error;\n\t}\n\ttry {\n\t\tconst { runId, pid } = JSON.parse(text) as { runId?: unknown; pid?: unknown };\n\t\tif (typeof runId === 'string' && Number.isInteger(pid)) return { runId, pid: pid as number };\n\t} catch {\n\t\t// Not JSON: named below as unknown.\n\t}\n\treturn { runId: 'unknown' };\n}\n\nfunction contentPath(contentDirectory: string, hash: string): string {\n\t// Two levels, so no folder holds every file a workspace ever stored.\n\treturn join(contentDirectory, hash.slice(0, 2), hash);\n}\n\nclass FileRunJournal implements RunJournal {\n\treadonly runId: string;\n\tprivate readonly record: RunRecord;\n\tprivate readonly runDirectory: string;\n\tprivate readonly contentDirectory: string;\n\tprivate readonly journal: FileHandle;\n\tprivate readonly discard: () => Promise<void>;\n\tprivate readonly settle: (record: RunRecord) => Promise<boolean>;\n\tprivate readonly release: () => Promise<void>;\n\tprivate sequence = 0;\n\tprivate stored = 0;\n\t// For the content state: what each change will leave, what each file held before the run first\n\t// changed it, and what it holds since its last applied change.\n\tprivate readonly pendingStates = new Map<number, { path: string; after: FileState }>();\n\tprivate readonly firstStates = new Map<string, FileState>();\n\tprivate readonly currentStates = new Map<string, FileState>();\n\tprivate readonly appliedInOrder: string[] = [];\n\tprivate state: { applied: number; hash: string } | undefined;\n\t// The changes recorded as prepared and not abandoned: those that may have reached a file. One\n\t// whose `prepared` line failed is not here, since nothing writes a file before that line.\n\tprivate readonly effects = new Set<number>();\n\t// The observations begun and not yet observed: what they saw is not all recorded.\n\tprivate readonly observing = new Set<number>();\n\t// A change it could not copy reached a file, and stays in the history.\n\tprivate lost = false;\n\t// Settling what it left open as it finished found that it changed nothing.\n\tprivate settledEmpty = false;\n\t// Appends run one after another, so the lines never interleave.\n\tprivate pending: Promise<unknown> = Promise.resolve();\n\tprivate finished = false;\n\t// Set when an append fails: it may have left part of a line, and anything after it would be\n\t// joined to that part and unreadable.\n\tprivate broken: unknown;\n\n\tconstructor({\n\t\trecord,\n\t\trunDirectory,\n\t\tcontentDirectory,\n\t\tjournal,\n\t\tdiscard,\n\t\tsettle,\n\t\trelease,\n\t}: {\n\t\trecord: RunRecord;\n\t\trunDirectory: string;\n\t\tcontentDirectory: string;\n\t\tjournal: FileHandle;\n\t\tdiscard: () => Promise<void>;\n\t\t/**\n\t\t * Settles the run's open observations, once its record names it `unsettled`, and tells\n\t\t * whether the run is still in the history.\n\t\t */\n\t\tsettle: (record: RunRecord) => Promise<boolean>;\n\t\trelease: () => Promise<void>;\n\t}) {\n\t\tthis.runId = record.runId;\n\t\tthis.record = record;\n\t\tthis.runDirectory = runDirectory;\n\t\tthis.contentDirectory = contentDirectory;\n\t\tthis.journal = journal;\n\t\tthis.discard = discard;\n\t\tthis.settle = settle;\n\t\tthis.release = release;\n\t}\n\n\tasync saveContent(content: Buffer): Promise<string> {\n\t\tthis.assertOpen();\n\t\tconst { hash, written } = await storeContent(this.contentDirectory, content);\n\t\tif (written) this.stored += content.length;\n\t\treturn hash;\n\t}\n\n\tasync prepare(change: Omit<JournalEntry, 'sequence' | 'status'>): Promise<number> {\n\t\tthis.assertOpen();\n\t\tconst sequence = ++this.sequence;\n\t\tawait this.append({ type: 'prepared', sequence, ...change });\n\t\tthis.effects.add(sequence);\n\t\tthis.pendingStates.set(sequence, { path: change.path, after: change.after });\n\t\tif (!this.firstStates.has(change.path)) this.firstStates.set(change.path, change.before);\n\t\treturn sequence;\n\t}\n\n\tasync applied(sequence: number): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'applied', sequence });\n\t\tconst change = this.pendingStates.get(sequence);\n\t\tif (!change) return;\n\t\tthis.pendingStates.delete(sequence);\n\t\tthis.currentStates.set(change.path, change.after);\n\t\tthis.appliedInOrder.push(change.path);\n\t}\n\n\tasync abandoned(sequence: number): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'abandoned', sequence });\n\t\t// Only once recorded: a change whose abandonment was not may still count as made.\n\t\tthis.effects.delete(sequence);\n\t\tthis.pendingStates.delete(sequence);\n\t}\n\n\tasync observe(manifest: string, by: string): Promise<number> {\n\t\tthis.assertOpen();\n\t\tconst sequence = ++this.sequence;\n\t\tawait this.append({ type: 'observing', sequence, manifest, by });\n\t\t// Until it is observed, whatever ran may have changed a file.\n\t\tthis.effects.add(sequence);\n\t\tthis.observing.add(sequence);\n\t\treturn sequence;\n\t}\n\n\tasync observed(sequence: number, measure?: ObservationMeasure): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'observed', sequence, ...(measure ? { measure } : {}) });\n\t\t// Its changes, if any, are entries of their own now.\n\t\tthis.effects.delete(sequence);\n\t\tthis.observing.delete(sequence);\n\t}\n\n\tasync unrecorded(path: string, by: string): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'unrecorded', sequence: ++this.sequence, path, by });\n\t\tthis.lost = true;\n\t}\n\n\tget storedBytes(): number {\n\t\treturn this.stored;\n\t}\n\n\tget appliedPaths(): readonly string[] {\n\t\treturn this.appliedInOrder;\n\t}\n\n\t// Computed again only after a change was applied.\n\tcontentState(): string {\n\t\tif (this.state?.applied !== this.appliedInOrder.length) {\n\t\t\tconst changed = [...this.currentStates]\n\t\t\t\t.filter(([path, current]) => {\n\t\t\t\t\tconst first = this.firstStates.get(path);\n\t\t\t\t\treturn !first || !sameState(first, current);\n\t\t\t\t})\n\t\t\t\t.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n\t\t\tthis.state = {\n\t\t\t\tapplied: this.appliedInOrder.length,\n\t\t\t\thash: hashOf(Buffer.from(JSON.stringify(changed))),\n\t\t\t};\n\t\t}\n\t\treturn this.state.hash;\n\t}\n\n\tget changed(): boolean {\n\t\treturn !this.settledEmpty && (this.lost || this.effects.size > 0);\n\t}\n\n\tasync finish(status: Exclude<RunStatus, 'running' | 'interrupted'>): Promise<void> {\n\t\tthis.assertOpen();\n\t\tthis.finished = true;\n\t\ttry {\n\t\t\tawait this.pending;\n\t\t\tawait this.journal.close();\n\t\t\t// Its record is left `running`: if removing it fails, readers already take it as gone.\n\t\t\tif (!this.changed) {\n\t\t\t\tawait this.discard();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst unsettled = this.observing.size > 0;\n\t\t\tconst record: RunRecord = {\n\t\t\t\t...this.record,\n\t\t\t\tstatus,\n\t\t\t\tfinishedAt: new Date().toISOString(),\n\t\t\t\t...(unsettled ? { unsettled } : {}),\n\t\t\t};\n\t\t\tawait writeDurably(join(this.runDirectory, 'run.json'), JSON.stringify(record));\n\t\t\t// Recorded first as unsettled, so a failure or a crash here leaves it to the next run.\n\t\t\tif (unsettled) this.settledEmpty = !(await this.settle(record));\n\t\t} finally {\n\t\t\tawait this.release();\n\t\t}\n\t}\n\n\tprivate append(line: JournalLine): Promise<void> {\n\t\tconst write = this.pending.then(async () => {\n\t\t\tif (this.broken !== undefined) {\n\t\t\t\tthrow new Error(`The journal of run ${this.runId} stopped after a failed write`, {\n\t\t\t\t\tcause: this.broken,\n\t\t\t\t});\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait this.journal.appendFile(`${JSON.stringify(line)}\\n`);\n\t\t\t\tawait this.journal.sync();\n\t\t\t} catch (error) {\n\t\t\t\tthis.broken = error ?? new Error('Unknown write failure');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\t\t// The chain goes on, so each later append reports the broken journal to its own caller.\n\t\tthis.pending = write.catch(() => undefined);\n\t\treturn write;\n\t}\n\n\tprivate assertOpen(): void {\n\t\tif (this.finished) throw new Error(`Run ${this.runId} has already finished`);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fileRecoveryStore.js","sourceRoot":"","sources":["../../../src/recovery/infrastructure/fileRecoveryStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,EAAE,EACF,IAAI,EACJ,QAAQ,EACR,MAAM,GACN,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,WAAW,GACX,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAmB,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EACN,YAAY,EAOZ,kBAAkB,EAOlB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACN,mBAAmB,EACnB,UAAU,EAEV,KAAK,E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I,EAAE,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;gBAC1D,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC,CAAC,CAAC;QACH,wFAAwF;QACxF,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC;IACd,CAAC;IAEO,UAAU;QACjB,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,uBAAuB,CAAC,CAAC;IAC9E,CAAC;CACD","sourcesContent":["import type { Session } from '#src/shared/domain/session';\nimport { createHash, randomBytes } from 'node:crypto';\nimport {\n\tlink,\n\tmkdir,\n\topen,\n\treaddir,\n\treadFile,\n\trealpath,\n\trename,\n\trm,\n\tstat,\n\ttruncate,\n\tunlink,\n} from 'node:fs/promises';\nimport type { FileHandle } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join, sep } from 'node:path';\nimport type { ILogger } from '#src/shared/domain/logger';\nimport { FolderClaims } from './folderClaims.ts';\nimport {\n\tclassifyHostFailure,\n\tdescribeFailure,\n\ttreatErrors,\n} from '#src/shared/domain/providerFailure';\nimport { Logger } from '#src/shared/infrastructure/logger';\nimport { type FileChange, fileChanges, sameState } from '../domain/fileChanges.ts';\nimport {\n\thistoryStart,\n\ttype FileState,\n\ttype JournalEntry,\n\ttype Manifest,\n\ttype ObservationMeasure,\n\ttype MoveConflict,\n\ttype MoveOptions,\n\tNothingToMoveError,\n\ttype Revision,\n\ttype RecoveryStore,\n\ttype RunJournal,\n\ttype RunRecord,\n\ttype RunStatus,\n\ttype UnrecordedChange,\n\tWorkspaceBusyError,\n\tWorkspaceMovedError,\n} from '../domain/recoveryStore.ts';\nimport { chainEntries, nextPruneStep } from '../domain/retention.ts';\nimport {\n\tHistoryExpiredError,\n\tredoTarget,\n\ttype Route,\n\troute,\n\tUnknownRunError,\n} from '../domain/runTree.ts';\nimport {\n\tcurrentState,\n\thasRealParents,\n\tremoveEmptyFolders,\n\tremoveFile,\n\tremoveTemporary,\n\ttemporaryPath,\n\twriteFileState,\n} from './workspaceFiles.ts';\n\nconst appName = 'mikode-harness';\n// The store holds source code the agent touched: only its owner may read it.\nconst privateDirectory = 0o700;\nconst privateFile = 0o600;\n\nconst firstJournal = 'journal.jsonl';\n\n// A run is roughly one prompt: enough to go back through a working session, not a project's life.\nconst defaultKeepRuns = 25;\n\nconst runIdPattern = /^\\d{8}T\\d{9}Z-[0-9a-f]{6}$/;\nconst hashPattern = /^[0-9a-f]{64}$/;\n\n/** Where an application keeps state that is neither configuration nor cache, per platform. */\nexport function defaultStateDirectory(\n\tenv: NodeJS.ProcessEnv = process.env,\n\tplatform: NodeJS.Platform = process.platform,\n\thome: string = homedir(),\n): string {\n\t// The XDG spec says to ignore a relative path, which here could land inside the repository.\n\tconst xdg = env.XDG_STATE_HOME;\n\tif (xdg && isAbsolute(xdg)) return join(xdg, appName);\n\tif (platform === 'darwin') return join(home, 'Library', 'Application Support', appName);\n\treturn join(home, '.local', 'state', appName);\n}\n\n/** Sorts by start time as text, so the latest run is the last one listed. */\nfunction newRunId(): string {\n\treturn `${new Date().toISOString().replace(/[-:.]/g, '')}-${randomBytes(3).toString('hex')}`;\n}\n\nfunction hashOf(content: Buffer): string {\n\treturn createHash('sha256').update(content).digest('hex');\n}\n\nfunction isNotFound(error: unknown): boolean {\n\treturn (error as NodeJS.ErrnoException).code === 'ENOENT';\n}\n\n/**\n * The runs and moves this process holds a workspace lock for and has not ended. A lock naming\n * this process and none of these was left by one whose release failed: it is as stale as a dead\n * process's, which a process that lives on would otherwise keep until it exits.\n */\nconst heldHere = new Set<string>();\n\n/** Whether the holder of a lock is still at work. */\nfunction isLiveHolder(holder: { runId: string; pid?: number }): boolean {\n\t// A holder that cannot be named cannot be shown to be gone.\n\tif (holder.pid === undefined) return true;\n\tif (holder.pid === process.pid) return heldHere.has(holder.runId);\n\treturn isAlive(holder.pid);\n}\n\n/** Whether a process still exists. One we may not signal exists too. */\nfunction isAlive(pid: number): boolean {\n\ttry {\n\t\tprocess.kill(pid, 0);\n\t\treturn true;\n\t} catch (error) {\n\t\treturn (error as NodeJS.ErrnoException).code === 'EPERM';\n\t}\n}\n\nasync function syncDirectory(path: string): Promise<void> {\n\tconst directory = await open(path, 'r');\n\ttry {\n\t\tawait directory.sync();\n\t} finally {\n\t\tawait directory.close();\n\t}\n}\n\n/**\n * Creates a private folder and any missing parents. A new folder only survives a crash once\n * its parent's entry for it is synced too, so each parent that gained one is.\n */\nasync function makeDirectory(path: string): Promise<void> {\n\tconst first = await mkdir(path, { recursive: true, mode: privateDirectory });\n\tif (first === undefined) return;\n\tfor (let created = path; ; created = dirname(created)) {\n\t\tawait syncDirectory(dirname(created));\n\t\tif (created === first) return;\n\t}\n}\n\n/**\n * Puts `content` at `path` all at once: a crash leaves either the old file or the new one, never\n * half of the new one. It returns only once the new file is on disk. With `exclusive`, it fails\n * with `EEXIST` instead of replacing a file already there.\n */\nasync function writeDurably(\n\tpath: string,\n\tcontent: string | Buffer,\n\t{ exclusive = false }: { exclusive?: boolean } = {},\n): Promise<void> {\n\tconst temporary = `${path}.${randomBytes(6).toString('hex')}.tmp`;\n\ttry {\n\t\tconst handle = await open(temporary, 'wx', privateFile);\n\t\ttry {\n\t\t\tawait handle.writeFile(content);\n\t\t\tawait handle.sync();\n\t\t} finally {\n\t\t\tawait handle.close();\n\t\t}\n\t\t// A link fails if the path is taken; a rename would replace it.\n\t\tawait (exclusive ? link : rename)(temporary, path);\n\t} finally {\n\t\tawait rm(temporary, { force: true });\n\t}\n\tawait syncDirectory(dirname(path));\n}\n\n/** A move not finished yet: the next move or run finishes it before anything else. */\ninterface PendingMove {\n\trevision: number;\n\tfrom?: string;\n\tto?: string;\n\treason?: string;\n\t/** Found by the steps already taken. */\n\tconflicts: MoveConflict[];\n\t/**\n\t * The temporary a file is being restored through, named before it is created, so finishing\n\t * the move removes this one and no file of the user's.\n\t */\n\ttemporary?: string;\n}\n\n/** `head.json`: the run the workspace is at, the moves made so far, and one in progress. */\ninterface Head {\n\trunId?: string;\n\trevision: number;\n\tpending?: PendingMove;\n}\n\ntype JournalLine =\n\t| ({ type: 'prepared'; sequence: number } & Omit<JournalEntry, 'sequence' | 'status'>)\n\t| { type: 'applied' | 'abandoned'; sequence: number }\n\t| { type: 'observing'; sequence: number; manifest: string; by: string }\n\t| { type: 'observed'; sequence: number; measure?: ObservationMeasure }\n\t| ({ type: 'unrecorded'; sequence: number } & UnrecordedChange);\n\n/** An observation a run began and never finished: what its command changed is not recorded yet. */\ninterface OpenObservation {\n\tsequence: number;\n\tmanifest: string;\n\tby: string;\n}\n\n/**\n * Stores `content` under its hash, unless it is stored already, and returns the hash and whether\n * it was new. It returns only once the content is on disk.\n */\nasync function storeContent(\n\tcontentDirectory: string,\n\tcontent: Buffer,\n): Promise<{ hash: string; written: boolean }> {\n\tconst hash = hashOf(content);\n\tconst path = contentPath(contentDirectory, hash);\n\tconst stored = await stat(path).then(\n\t\t() => true,\n\t\t(error: unknown) => {\n\t\t\tif (isNotFound(error)) return false;\n\t\t\tthrow error;\n\t\t},\n\t);\n\tif (!stored) {\n\t\tawait makeDirectory(dirname(path));\n\t\tawait writeDurably(path, content);\n\t}\n\treturn { hash, written: !stored };\n}\n\n/**\n * The recovery store on disk, in a private directory per workspace under the platform's state\n * directory:\n *\n * ```text\n * <directory>/workspaces/<hash of the root>/\n * workspace.json the root it belongs to\n * lock the run writing now, if any\n * head.json the run the workspace is at, and a move in progress\n * revisions.jsonl every move of the workspace through its history\n * content/<ab>/<hash> file contents, named by their SHA-256\n * runs/<runId>/run.json the run's record\n * runs/<runId>/journal.jsonl its changes, one line per step, appended and synced\n * ```\n *\n * The lock only keeps a second run of this harness from writing at the same time. It does not\n * stop an editor or another program, and two processes taking over a dead run's lock in the\n * same instant could both believe they hold it.\n */\nexport class FileRecoveryStore implements RecoveryStore {\n\treadonly workspaceId: string;\n\treadonly writeFolders: readonly string[];\n\tprivate readonly root: string;\n\tprivate readonly directory: string;\n\tprivate readonly keepRuns: number;\n\tprivate readonly logger: ILogger;\n\tprivate readonly claims: FolderClaims;\n\t// What releases the claim of each run or move holding the workspace.\n\tprivate readonly releases = new Map<string, () => Promise<void>>();\n\n\tprivate constructor(\n\t\troot: string,\n\t\tdirectory: string,\n\t\tkeepRuns: number,\n\t\tlogger: ILogger,\n\t\tworkspaceId: string,\n\t\t{ claims, folders }: { claims: FolderClaims; folders: string[] },\n\t) {\n\t\tthis.root = root;\n\t\tthis.directory = directory;\n\t\tthis.keepRuns = keepRuns;\n\t\tthis.logger = logger;\n\t\tthis.workspaceId = workspaceId;\n\t\tthis.claims = claims;\n\t\tthis.writeFolders = folders;\n\t}\n\n\tstatic async open({\n\t\troot,\n\t\tdirectory = defaultStateDirectory(),\n\t\tkeepRuns = defaultKeepRuns,\n\t\tlogger = new Logger(),\n\t\twriteRoots = [],\n\t}: {\n\t\troot: string;\n\t\t/** Defaults to the platform's state directory. */\n\t\tdirectory?: string;\n\t\t/**\n\t\t * The most runs kept per workspace, the one being recorded included. Defaults to 25. At\n\t\t * least 3: the run the workspace is at is never removed, and the last run of its line has\n\t\t * no next run to be chained into, so pruning can leave two runs besides the new one.\n\t\t */\n\t\tkeepRuns?: number;\n\t\t/** Where it reports a failure it absorbs. Defaults to standard error. */\n\t\tlogger?: ILogger;\n\t\t/**\n\t\t * The folders besides `root` that its runs may write in, such as the other `write` roots,\n\t\t * so no worktree they lie in is removed while a run writes there.\n\t\t */\n\t\twriteRoots?: readonly string[];\n\t}): Promise<FileRecoveryStore> {\n\t\tif (!Number.isInteger(keepRuns) || keepRuns < 3) {\n\t\t\tthrow new RangeError(`keepRuns must be an integer of at least 3; got ${String(keepRuns)}`);\n\t\t}\n\t\t// Two spellings of one folder, such as a symlinked path, are one workspace.\n\t\tconst realRoot = await realpath(root);\n\t\tconst workspace = join(\n\t\t\tdirectory,\n\t\t\t'workspaces',\n\t\t\tcreateHash('sha256').update(realRoot).digest('hex').slice(0, 16),\n\t\t);\n\t\tawait makeDirectory(join(workspace, 'runs'));\n\t\tawait makeDirectory(join(workspace, 'content'));\n\t\tawait writeDurably(join(workspace, 'workspace.json'), JSON.stringify({ root: realRoot }));\n\n\t\tconst folders = [\n\t\t\trealRoot,\n\t\t\t...(await Promise.all(writeRoots.map(path => realpath(path).catch(() => path)))),\n\t\t];\n\t\t// Real, so a state directory reached through a link is the history it holds.\n\t\treturn new FileRecoveryStore(realRoot, workspace, keepRuns, logger, await realpath(workspace), {\n\t\t\tclaims: new FolderClaims(await realpath(directory)),\n\t\t\tfolders,\n\t\t});\n\t}\n\n\tasync startRun({ session }: { session?: Session } = {}): Promise<RunJournal> {\n\t\tconst runId = newRunId();\n\t\ttry {\n\t\t\t// Inside, because taking the lock can fail after publishing it. Unlocking removes only a\n\t\t\t// lock naming this run, never another run's.\n\t\t\tawait this.lock(runId);\n\t\t\tawait this.settleInterrupted(runId);\n\t\t\t// A run starts where the user last sent the workspace.\n\t\t\tawait this.finishPendingMove();\n\t\t\t// Before the new run exists, so it is never pruned, and after the move, so no run on its\n\t\t\t// route is.\n\t\t\tawait this.prune();\n\t\t\tconst head = await this.readHead();\n\t\t\tconst parentRunId = head.runId;\n\t\t\tconst runDirectory = join(this.directory, 'runs', runId);\n\t\t\tawait makeDirectory(runDirectory);\n\t\t\tconst record: RunRecord = {\n\t\t\t\trunId,\n\t\t\t\troot: this.root,\n\t\t\t\t...(parentRunId ? { parentRunId } : {}),\n\t\t\t\tstartedAt: new Date().toISOString(),\n\t\t\t\tstatus: 'running',\n\t\t\t\tpid: process.pid,\n\t\t\t\t...(session ? { session } : {}),\n\t\t\t};\n\t\t\tawait writeDurably(join(runDirectory, 'run.json'), JSON.stringify(record));\n\t\t\t// After the record, so the head never names a run that does not exist.\n\t\t\tawait this.writeHead({ runId, revision: head.revision });\n\t\t\tconst journal = await open(join(runDirectory, firstJournal), 'a', privateFile);\n\t\t\tawait syncDirectory(runDirectory);\n\n\t\t\treturn new FileRunJournal({\n\t\t\t\trecord,\n\t\t\t\trunDirectory,\n\t\t\t\tcontentDirectory: join(this.directory, 'content'),\n\t\t\t\tjournal,\n\t\t\t\tdiscard: () => this.discardRun(record),\n\t\t\t\tsettle: finished => this.settleAtFinish(finished),\n\t\t\t\trelease: () => this.unlock(runId),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tawait this.unlock(runId);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync listRuns(): Promise<{ head?: string; runs: RunRecord[] }> {\n\t\tconst ids = (await readdir(join(this.directory, 'runs'))).filter(id => runIdPattern.test(id));\n\t\tconst holder = await readLock(join(this.directory, 'lock'));\n\t\tconst runs: RunRecord[] = [];\n\t\tfor (const runId of ids.sort()) {\n\t\t\tconst record = await this.readRecord(runId).catch((error: unknown) => {\n\t\t\t\t// A crash between creating a run's folder and writing its record leaves the folder\n\t\t\t\t// empty: that run never changed anything.\n\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tif (record) runs.push(withLiveStatus(record, holder));\n\t\t}\n\t\t// A run retention removed or chained into a later one, whose folder a crash left behind, is\n\t\t// not in the history.\n\t\tconst gone = new Set([\n\t\t\t...runs.flatMap(run => run.absorbed ?? []),\n\t\t\t...(await this.listPruned()),\n\t\t]);\n\t\t// A dead run that changed nothing is not in the history either, though its removal did not\n\t\t// finish. No run follows it: the next run or move removes it before starting.\n\t\tfor (const run of runs) {\n\t\t\tif (run.status !== 'interrupted') continue;\n\t\t\t// A journal it cannot read leaves the run listed: whether it changed anything is unknown.\n\t\t\tconst journal = await this.readJournal(run.runId, run.journal).catch(() => undefined);\n\t\t\tif (journal && changedNothing(journal)) gone.add(run.runId);\n\t\t}\n\t\tconst parents = new Map(runs.map(run => [run.runId, run.parentRunId]));\n\t\tlet { runId: head } = await this.readHead();\n\t\twhile (head !== undefined && gone.has(head)) head = parents.get(head);\n\n\t\treturn { ...(head ? { head } : {}), runs: runs.filter(run => !gone.has(run.runId)) };\n\t}\n\n\tasync readRun(\n\t\trunId: string,\n\t): Promise<{ record: RunRecord; entries: JournalEntry[]; unrecorded: UnrecordedChange[] }> {\n\t\t// An id from outside is checked before it names a folder.\n\t\tif (!runIdPattern.test(runId)) throw new UnknownRunError(runId);\n\t\t// The lock first: a run that finishes between the two reads then shows as finished, not as\n\t\t// a `running` record nobody holds.\n\t\tconst holder = await readLock(join(this.directory, 'lock'));\n\t\t// Before the record: a crash can leave the folder of a run retention already took.\n\t\tawait this.assertNotAbsorbed(runId);\n\t\tconst record = await this.readRecord(runId).catch(async (error: unknown) => {\n\t\t\tif (!isNotFound(error)) throw error;\n\t\t\t// Retention may have taken it since the check above.\n\t\t\tawait this.assertNotAbsorbed(runId);\n\t\t\tthrow new UnknownRunError(runId);\n\t\t});\n\t\tconst { entries, unrecorded } = await this.readJournal(runId, record.journal);\n\t\treturn {\n\t\t\trecord: withLiveStatus(record, holder),\n\t\t\tentries,\n\t\t\tunrecorded: unrecorded.map(({ path, by }) => ({ path, by })),\n\t\t};\n\t}\n\n\tprivate async readRecord(runId: string): Promise<RunRecord> {\n\t\treturn JSON.parse(\n\t\t\tawait readFile(join(this.runDirectory(runId), 'run.json'), 'utf8'),\n\t\t) as RunRecord;\n\t}\n\n\tprivate runDirectory(runId: string): string {\n\t\t// The id names a folder, so it must never be a path of its own.\n\t\tif (!runIdPattern.test(runId)) throw new Error(`Not a run id: ${runId}`);\n\t\treturn join(this.directory, 'runs', runId);\n\t}\n\n\tprivate async readHead(): Promise<Head> {\n\t\ttry {\n\t\t\tconst head = JSON.parse(\n\t\t\t\tawait readFile(join(this.directory, 'head.json'), 'utf8'),\n\t\t\t) as Partial<Head>;\n\t\t\treturn { ...head, revision: head.revision ?? 0 };\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) return { revision: 0 };\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate async writeHead(head: Head): Promise<void> {\n\t\tawait writeDurably(join(this.directory, 'head.json'), JSON.stringify(head));\n\t}\n\n\tgoTo(target: string, options: MoveOptions = {}): Promise<Revision> {\n\t\treturn this.move(() => (target === historyStart ? undefined : target), options);\n\t}\n\n\tundo(options: MoveOptions = {}): Promise<Revision> {\n\t\treturn this.move(({ runs, head }) => {\n\t\t\tif (head === undefined) throw new NothingToMoveError('undo');\n\t\t\treturn runs.find(run => run.runId === head)?.parentRunId;\n\t\t}, options);\n\t}\n\n\tredo(options: MoveOptions = {}): Promise<Revision> {\n\t\treturn this.move(({ runs, head, revisions }) => {\n\t\t\tconst target = redoTarget(runs, revisions, head);\n\t\t\tif (target === undefined) throw new NothingToMoveError('redo');\n\t\t\treturn target;\n\t\t}, options);\n\t}\n\n\tasync listRevisions(): Promise<Revision[]> {\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = await readFile(join(this.directory, 'revisions.jsonl'), 'utf8');\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) return [];\n\t\t\tthrow error;\n\t\t}\n\t\tconst lines = text.split('\\n');\n\t\treturn lines.flatMap((line, index) => {\n\t\t\tif (line === '') return [];\n\t\t\ttry {\n\t\t\t\treturn [JSON.parse(line) as Revision];\n\t\t\t} catch (error) {\n\t\t\t\t// A crash in the middle of an append leaves half a line, always the last one. Its\n\t\t\t\t// move is still pending, and finishing it records it again.\n\t\t\t\tif (index === lines.length - 1) return [];\n\t\t\t\tthrow new Error(`The history of this workspace is corrupt at line ${String(index + 1)}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t/** Holds the workspace like a run does, then moves it to the run `resolve` picks. */\n\tprivate async move(\n\t\tresolve: (history: {\n\t\t\truns: RunRecord[];\n\t\t\thead: string | undefined;\n\t\t\trevisions: Revision[];\n\t\t}) => string | undefined,\n\t\t{ reason, from }: MoveOptions,\n\t): Promise<Revision> {\n\t\tconst moveId = `move-${newRunId()}`;\n\t\ttry {\n\t\t\tawait this.lock(moveId);\n\t\t\tawait this.settleInterrupted(moveId);\n\t\t\tawait this.finishPendingMove();\n\t\t\tconst head = await this.readHead();\n\t\t\t// Only now, under the lock and once nothing is left unsettled, is the head the one the\n\t\t\t// move would start from.\n\t\t\tconst at = head.runId ?? historyStart;\n\t\t\tif (from !== undefined && from !== at) throw new WorkspaceMovedError(from, at);\n\t\t\tconst { runs } = await this.listRuns();\n\t\t\tconst to = resolve({ runs, head: head.runId, revisions: await this.listRevisions() });\n\t\t\tif (to !== undefined && !runs.some(run => run.runId === to)) {\n\t\t\t\tawait this.assertNotAbsorbed(to);\n\t\t\t}\n\n\t\t\treturn await this.takeSteps(head, runs, {\n\t\t\t\trevision: head.revision + 1,\n\t\t\t\t...(head.runId ? { from: head.runId } : {}),\n\t\t\t\t...(to ? { to } : {}),\n\t\t\t\t...(reason === undefined ? {} : { reason }),\n\t\t\t\tconflicts: [],\n\t\t\t});\n\t\t} finally {\n\t\t\tawait this.unlock(moveId);\n\t\t}\n\t}\n\n\t/** Finishes a move whose process stopped halfway, from the run its last step reached. */\n\tprivate async finishPendingMove(): Promise<void> {\n\t\tconst head = await this.readHead();\n\t\tconst { pending } = head;\n\t\tif (!pending) return;\n\t\t// It was recorded, and only clearing it from the head was missing.\n\t\tif ((await this.listRevisions()).some(revision => revision.revision === pending.revision)) {\n\t\t\tawait this.writeHead({\n\t\t\t\t...(pending.to ? { runId: pending.to } : {}),\n\t\t\t\trevision: pending.revision,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tawait this.takeSteps(head, (await this.listRuns()).runs, pending);\n\t}\n\n\t/**\n\t * Undoes, then redoes, one run at a time from where the head is to `pending.to`. After each\n\t * step the head names the run reached, with the move still pending, so a crash loses at\n\t * most the step in progress, and that step is safe to take again.\n\t */\n\tprivate async takeSteps(head: Head, runs: RunRecord[], pending: PendingMove): Promise<Revision> {\n\t\tconst { undo, redo } = route(runs, head.runId, pending.to);\n\t\tconst release = await this.claimFiles([...undo, ...redo]);\n\t\ttry {\n\t\t\treturn await this.stepAlong(head, runs, pending, { undo, redo });\n\t\t} finally {\n\t\t\tawait release();\n\t\t}\n\t}\n\n\t/**\n\t * Claims each file the runs on a route changed outside the folders this store claims: a run\n\t * may have written in a folder this store was not opened with, such as a second root a history\n\t * reopened by its first root alone does not know. A worktree holding one is not removed while\n\t * the move writes there.\n\t */\n\tprivate async claimFiles(runIds: readonly string[]): Promise<() => Promise<void>> {\n\t\tconst outside = new Set<string>();\n\t\tfor (const runId of runIds) {\n\t\t\tconst { entries } = await this.readRun(runId);\n\t\t\tfor (const { path } of fileChanges(entries, true)) {\n\t\t\t\tif (!this.writeFolders.some(folder => within(path, folder))) outside.add(path);\n\t\t\t}\n\t\t}\n\t\tif (outside.size === 0) return () => Promise.resolve();\n\t\treturn this.claims.claimWriting(`files-${newRunId()}`, [...outside]);\n\t}\n\n\tprivate async stepAlong(\n\t\thead: Head,\n\t\truns: RunRecord[],\n\t\tpending: PendingMove,\n\t\t{ undo, redo }: Route,\n\t): Promise<Revision> {\n\t\tconst parents = new Map(runs.map(run => [run.runId, run.parentRunId]));\n\t\tlet reached = head.runId;\n\t\tconst save = () =>\n\t\t\tthis.writeHead({ ...(reached ? { runId: reached } : {}), revision: head.revision, pending });\n\n\t\t// What a write the crash interrupted left beside its file.\n\t\tif (pending.temporary) {\n\t\t\tawait removeTemporary(pending.temporary);\n\t\t\tdelete pending.temporary;\n\t\t}\n\t\tawait save();\n\t\tconst announce = async (temporary: string | undefined) => {\n\t\t\tif (temporary === undefined) delete pending.temporary;\n\t\t\telse pending.temporary = temporary;\n\t\t\tawait save();\n\t\t};\n\t\tfor (const runId of undo) {\n\t\t\tpending.conflicts.push(...(await this.step(runId, 'undo', announce)));\n\t\t\treached = parents.get(runId);\n\t\t\tawait save();\n\t\t}\n\t\tfor (const runId of redo) {\n\t\t\tpending.conflicts.push(...(await this.step(runId, 'redo', announce)));\n\t\t\treached = runId;\n\t\t\tawait save();\n\t\t}\n\n\t\t// Every write that started has finished, so no temporary is left to name.\n\t\tdelete pending.temporary;\n\t\tconst { conflicts, ...rest } = pending;\n\t\tconst revision: Revision = {\n\t\t\t...rest,\n\t\t\tat: new Date().toISOString(),\n\t\t\tcomplete: conflicts.length === 0,\n\t\t\tconflicts,\n\t\t};\n\t\tawait this.appendRevision(revision);\n\t\tawait this.writeHead({\n\t\t\t...(pending.to ? { runId: pending.to } : {}),\n\t\t\trevision: pending.revision,\n\t\t});\n\t\treturn revision;\n\t}\n\n\t/** Takes one run's changes back to its parent, or forward again, file by file. */\n\tprivate async step(\n\t\trunId: string,\n\t\tdirection: 'undo' | 'redo',\n\t\tannounce: (temporary: string | undefined) => Promise<void>,\n\t): Promise<MoveConflict[]> {\n\t\tconst { entries, unrecorded } = await this.readRun(runId);\n\t\tconst changes = fileChanges(entries, true);\n\t\t// What the history could not copy is left as it is, in either direction.\n\t\tconst conflicting = new Set(unrecorded.map(change => change.path));\n\t\t// Undone newest first, so a folder the run created is empty by the time its file goes.\n\t\tfor (const change of direction === 'undo' ? changes.reverse() : changes) {\n\t\t\tif (!(await this.moveFile(change, direction, announce))) conflicting.add(change.path);\n\t\t}\n\t\treturn [...conflicting].map((path): MoveConflict => ({ path, runId }));\n\t}\n\n\t/**\n\t * Writes the state the step leads to, only if the file holds the state it leaves. A file\n\t * already there is left alone, so taking a step again is safe. Returns whether the file\n\t * ends where the step leads.\n\t */\n\tprivate async moveFile(\n\t\tchange: FileChange,\n\t\tdirection: 'undo' | 'redo',\n\t\tannounce: (temporary: string | undefined) => Promise<void>,\n\t): Promise<boolean> {\n\t\tconst [source, destination] =\n\t\t\tdirection === 'undo' ? [change.after, change.before] : [change.before, change.after];\n\t\t// First, so a file reached through a folder that became a link is never taken for the\n\t\t// destination, and nothing is read or removed through it.\n\t\tif (!(await hasRealParents(change.path))) return false;\n\t\tconst current = await currentState(change.path);\n\n\t\tif (current && sameState(current, destination)) {\n\t\t\tif (direction === 'undo' && !destination.exists) {\n\t\t\t\tawait removeEmptyFolders(change.createdFolders);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tif (!current || !sameState(current, source)) return false;\n\t\t// Someone wrote to the file between two of the run's changes, and going back to before\n\t\t// the first would discard that.\n\t\tif (direction === 'undo' && !change.continuous) return false;\n\n\t\tif (destination.exists) {\n\t\t\tconst temporary = temporaryPath(change.path);\n\t\t\tawait announce(temporary);\n\t\t\tawait writeFileState(\n\t\t\t\tchange.path,\n\t\t\t\tawait this.readContent(destination.hash),\n\t\t\t\tdestination.mode,\n\t\t\t\ttemporary,\n\t\t\t);\n\t\t\tawait announce(undefined);\n\t\t} else {\n\t\t\tawait removeFile(change.path);\n\t\t\tif (direction === 'undo') await removeEmptyFolders(change.createdFolders);\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Throws `HistoryExpiredError` if retention removed `runId` or chained it into a later run. */\n\tprivate async assertNotAbsorbed(runId: string): Promise<void> {\n\t\tconst { runs } = await this.listRuns();\n\t\tconst keptIn = runs.find(run => run.absorbed?.includes(runId));\n\t\tif (keptIn) throw new HistoryExpiredError(runId, keptIn.runId);\n\t\tif ((await this.listPruned()).includes(runId)) throw new HistoryExpiredError(runId);\n\t}\n\n\tprivate async listPruned(): Promise<string[]> {\n\t\ttry {\n\t\t\tconst text = await readFile(join(this.directory, 'pruned.jsonl'), 'utf8');\n\t\t\treturn text.split('\\n').flatMap(line => {\n\t\t\t\ttry {\n\t\t\t\t\treturn [JSON.parse(line) as string];\n\t\t\t\t} catch {\n\t\t\t\t\t// Half a line a crash left, whose removal never happened.\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (isNotFound(error)) return [];\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Brings the history down to `keepRuns - 1`, so the run about to start makes `keepRuns`, then\n\t * frees the contents no run kept refers to.\n\t */\n\tprivate async prune(): Promise<void> {\n\t\tawait this.finishChains();\n\t\tconst revisions = await this.listRevisions();\n\t\tfor (;;) {\n\t\t\tconst { head, runs } = await this.listRuns();\n\t\t\tconst step = nextPruneStep(runs, revisions, head, this.keepRuns - 1);\n\t\t\tif (!step) break;\n\t\t\tif (step.kind === 'remove') await this.removeRun(step.runId);\n\t\t\telse await this.chain(step.runId, step.into);\n\t\t}\n\t\tawait this.collectContent();\n\t}\n\n\t/**\n\t * Chains the changes of `older` into `newer`, its child: `newer` then hangs from `older`'s\n\t * parent and goes back to where `older` started. The new record is the commit point. Before\n\t * it, the history is as it was; after it, `finishChains` removes what is left of `older`.\n\t */\n\tprivate async chain(older: string, newer: string): Promise<void> {\n\t\tconst olderRecord = await this.readRecord(older);\n\t\tconst newerRecord = await this.readRecord(newer);\n\t\tconst olderJournal = await this.readJournal(older, olderRecord.journal);\n\t\tconst newerJournal = await this.readJournal(newer, newerRecord.journal);\n\t\tconst entries = chainEntries(olderJournal.entries, newerJournal.entries);\n\t\tconst journal = `journal-${randomBytes(4).toString('hex')}.jsonl`;\n\t\tconst lines = entries.flatMap(({ status, sequence, ...change }): JournalLine[] => [\n\t\t\t{ type: 'prepared', sequence, ...change },\n\t\t\t...(status === 'prepared' ? [] : [{ type: status, sequence } as const]),\n\t\t]);\n\t\t// What either run could not copy stays uncopied: undoing the chain cannot take it back.\n\t\tfor (const [index, { path, by }] of [\n\t\t\t...olderJournal.unrecorded,\n\t\t\t...newerJournal.unrecorded,\n\t\t].entries()) {\n\t\t\tlines.push({ type: 'unrecorded', sequence: entries.length + index + 1, path, by });\n\t\t}\n\t\tawait writeDurably(\n\t\t\tjoin(this.runDirectory(newer), journal),\n\t\t\tlines.map(line => `${JSON.stringify(line)}\\n`).join(''),\n\t\t);\n\n\t\tconst record: RunRecord = {\n\t\t\t...newerRecord,\n\t\t\tabsorbed: [...(olderRecord.absorbed ?? []), older, ...(newerRecord.absorbed ?? [])],\n\t\t\tjournal,\n\t\t};\n\t\t// It now hangs where `older` did: from its parent, or from the start.\n\t\tif (olderRecord.parentRunId) record.parentRunId = olderRecord.parentRunId;\n\t\telse delete record.parentRunId;\n\t\tawait writeDurably(join(this.runDirectory(newer), 'run.json'), JSON.stringify(record));\n\t\tawait this.finishChains();\n\t}\n\n\t/**\n\t * Removes what a chain or a removal a crash interrupted left behind: the folders of runs\n\t * pruned or absorbed by a kept run, and journals a run no longer reads.\n\t */\n\tprivate async finishChains(): Promise<void> {\n\t\tfor (const runId of await this.listPruned()) {\n\t\t\tawait rm(this.runDirectory(runId), { recursive: true, force: true });\n\t\t}\n\t\tconst { runs } = await this.listRuns();\n\t\tfor (const run of runs) {\n\t\t\tfor (const absorbed of run.absorbed ?? []) {\n\t\t\t\tawait rm(this.runDirectory(absorbed), { recursive: true, force: true });\n\t\t\t}\n\t\t\tconst current = run.journal ?? firstJournal;\n\t\t\tfor (const name of await readdir(this.runDirectory(run.runId))) {\n\t\t\t\tif (name.startsWith('journal') && name.endsWith('.jsonl') && name !== current) {\n\t\t\t\t\tawait rm(join(this.runDirectory(run.runId), name), { force: true });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes a run whole, recording its id first so a move to it reports an expired history.\n\t * Its record goes next, so a crash halfway leaves no run behind.\n\t */\n\tprivate async removeRun(runId: string): Promise<void> {\n\t\tawait appendWhole(join(this.directory, 'pruned.jsonl'), [runId]);\n\t\t// The log may be new: its entry in the folder must last before the run it names goes.\n\t\tawait syncDirectory(this.directory);\n\t\tawait rm(join(this.runDirectory(runId), 'run.json'), { force: true });\n\t\tawait syncDirectory(this.runDirectory(runId));\n\t\tawait rm(this.runDirectory(runId), { recursive: true, force: true });\n\t}\n\n\t/**\n\t * Takes a run that changed nothing out of the history, under the lock: the workspace goes back\n\t * to its parent first, so the head never names a run that is gone. Until the run is removed,\n\t * `listRuns` already hides it, and the next run or move finishes removing it. The contents it\n\t * saved are freed by the next prune.\n\t */\n\tprivate async discardRun(record: RunRecord): Promise<void> {\n\t\tconst { runId: headRunId, ...head } = await this.readHead();\n\t\tif (headRunId === record.runId) {\n\t\t\tawait this.writeHead({\n\t\t\t\t...head,\n\t\t\t\t...(record.parentRunId ? { runId: record.parentRunId } : {}),\n\t\t\t});\n\t\t}\n\t\tawait rm(join(this.runDirectory(record.runId), 'run.json'), { force: true });\n\t\tawait syncDirectory(this.runDirectory(record.runId));\n\t\tawait rm(this.runDirectory(record.runId), { recursive: true, force: true });\n\t}\n\n\t/**\n\t * Removes the stored contents no kept run refers to. An observation still open refers to its\n\t * manifest and to every content in it, which settling it needs.\n\t */\n\tprivate async collectContent(): Promise<void> {\n\t\tconst referenced = new Set<string>();\n\t\tfor (const run of (await this.listRuns()).runs) {\n\t\t\tconst { entries, observations } = await this.readJournal(run.runId, run.journal);\n\t\t\tfor (const entry of entries) {\n\t\t\t\tfor (const state of [entry.before, entry.after]) {\n\t\t\t\t\tif (state.exists) referenced.add(state.hash);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const observation of observations) {\n\t\t\t\treferenced.add(observation.manifest);\n\t\t\t\tconst stored = await this.readContent(observation.manifest).catch((error: unknown) => {\n\t\t\t\t\t// Never stored whole: settling it will find nothing to compare.\n\t\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t\tif (!stored) continue;\n\t\t\t\tconst manifest = JSON.parse(stored.toString('utf8')) as Manifest;\n\t\t\t\tfor (const state of Object.values(manifest.files)) {\n\t\t\t\t\tif (state.exists) referenced.add(state.hash);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst contentDirectory = join(this.directory, 'content');\n\t\tfor (const prefix of await readdir(contentDirectory)) {\n\t\t\tfor (const hash of await readdir(join(contentDirectory, prefix))) {\n\t\t\t\tif (hashPattern.test(hash) && !referenced.has(hash)) {\n\t\t\t\t\tawait rm(join(contentDirectory, prefix, hash), { force: true });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async appendRevision(revision: Revision): Promise<void> {\n\t\tawait appendWhole(join(this.directory, 'revisions.jsonl'), [revision]);\n\t\tawait syncDirectory(this.directory);\n\t}\n\n\t/**\n\t * Settles every other run left unfinished: one still recorded as `running` is `interrupted`,\n\t * since this run holds the lock and its process is gone, and one that finished `unsettled`\n\t * keeps its status.\n\t */\n\tprivate async settleInterrupted(ownRunId: string): Promise<void> {\n\t\tconst ids = (await readdir(join(this.directory, 'runs'))).filter(\n\t\t\tid => runIdPattern.test(id) && id !== ownRunId,\n\t\t);\n\t\tfor (const runId of ids) {\n\t\t\tconst record = await this.readRecord(runId).catch((error: unknown) => {\n\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tif (record?.status === 'running' || record?.unsettled) await this.settleRun(record);\n\t\t}\n\t}\n\n\t/**\n\t * Settles a run that finished with an observation open, under its own lock, before it releases\n\t * the workspace. If that fails, its record stays `unsettled`, and the next run or move settles\n\t * it, so the failure is reported and not thrown.\n\t */\n\tprivate async settleAtFinish(record: RunRecord): Promise<boolean> {\n\t\ttry {\n\t\t\treturn await this.settleRun(record, { finishing: true });\n\t\t} catch (error) {\n\t\t\ttreatErrors(\n\t\t\t\t() => {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t`The history could not settle what run ${record.runId} was observing when it finished; the next run or move settles it: ${describeFailure(error)}`,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tclassifyHostFailure,\n\t\t\t\t'Recovery store logger failed while reporting an unsettled run',\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t/**\n\t * Settles what a run left unfinished. Each change it left `prepared` is settled from what its\n\t * file holds now: its `after` means it was made, its `before` that it was not. A file that holds\n\t * neither stays `prepared`, because nothing tells whether the change reached it. Each\n\t * observation it left open is settled from its manifest. A run still `running` becomes\n\t * `interrupted`; any other keeps its status. Whether the run is still in the history: one that\n\t * changed nothing leaves it if it was still `running`, or if it is `finishing`, which unties\n\t * its turns from it. One that finished is kept otherwise, since the turns of a conversation may\n\t * name it.\n\t */\n\tprivate async settleRun(\n\t\trecord: RunRecord,\n\t\t{ finishing = false }: { finishing?: boolean } = {},\n\t): Promise<boolean> {\n\t\tconst { runId } = record;\n\t\tconst journal = await this.readJournal(runId, record.journal);\n\t\tconst lines: JournalLine[] = [];\n\t\tfor (const entry of journal.entries) {\n\t\t\tif (entry.status !== 'prepared' || !isAbsolute(entry.path)) continue;\n\t\t\tconst state = await currentState(entry.path);\n\t\t\tif (state && sameState(state, entry.after)) {\n\t\t\t\tlines.push({ type: 'applied', sequence: entry.sequence });\n\t\t\t} else if (state && sameState(state, entry.before)) {\n\t\t\t\tlines.push({ type: 'abandoned', sequence: entry.sequence });\n\t\t\t}\n\t\t}\n\t\tlet sequence = journal.lastSequence;\n\t\tfor (const observation of journal.observations) {\n\t\t\tconst observed = await this.settleObservation(observation, journal, sequence);\n\t\t\tsequence += observed.length;\n\t\t\tlines.push(...observed);\n\t\t}\n\t\tawait appendWhole(join(this.runDirectory(runId), record.journal ?? firstJournal), lines);\n\t\tconst leaves = finishing || record.status === 'running';\n\t\tif (leaves && changedNothing(await this.readJournal(runId, record.journal))) {\n\t\t\tawait this.discardRun(record);\n\t\t\treturn false;\n\t\t}\n\t\tconst settled: RunRecord = {\n\t\t\t...record,\n\t\t\tstatus: record.status === 'running' ? 'interrupted' : record.status,\n\t\t};\n\t\tdelete settled.unsettled;\n\t\t// Last, so a crash before it leaves a run that is settled again, and settling is idempotent.\n\t\tawait writeDurably(join(this.runDirectory(runId), 'run.json'), JSON.stringify(settled));\n\t\treturn true;\n\t}\n\n\t/**\n\t * The lines that record what a command an interrupted run was observing changed: every file of\n\t * its manifest that holds something else now, as changed by that command, and then the end of\n\t * the observation. A file recorded after the observation began is left alone: the run\n\t * recorded it itself. One that is now a folder, a link or too large to record, or that was one\n\t * and is no longer, or that cannot be read, is recorded as a change the history could not copy.\n\t */\n\tprivate async settleObservation(\n\t\tobservation: OpenObservation,\n\t\t{\n\t\t\tentries,\n\t\t\tunrecorded: uncopied,\n\t\t}: { entries: JournalEntry[]; unrecorded: { sequence: number; path: string }[] },\n\t\tlastSequence: number,\n\t): Promise<JournalLine[]> {\n\t\tconst stored = await this.readContent(observation.manifest).catch((error: unknown) => {\n\t\t\tif (isNotFound(error)) return undefined;\n\t\t\tthrow error;\n\t\t});\n\t\t// Its manifest was never stored whole: the command it was saved for never started.\n\t\tif (!stored) return [{ type: 'observed', sequence: observation.sequence }];\n\t\tconst manifest = JSON.parse(stored.toString('utf8')) as Manifest;\n\t\t// What the run recorded itself after the observation began, its changes and those it could\n\t\t// not copy, such as when a command could not be confirmed stopped.\n\t\tconst recorded = new Set(\n\t\t\t[...entries, ...uncopied]\n\t\t\t\t.filter(line => line.sequence > observation.sequence)\n\t\t\t\t.map(line => line.path),\n\t\t);\n\t\tconst lines: JournalLine[] = [];\n\t\tlet sequence = lastSequence;\n\t\tconst unrecorded = (path: string): JournalLine => ({\n\t\t\ttype: 'unrecorded',\n\t\t\tsequence: ++sequence,\n\t\t\tpath,\n\t\t\tby: observation.by,\n\t\t});\n\t\tfor (const [path, before] of Object.entries(manifest.files)) {\n\t\t\tif (!isAbsolute(path) || recorded.has(path)) continue;\n\t\t\tconst after = await this.saveState(path);\n\t\t\tif (after === undefined || after === 'unreadable') {\n\t\t\t\tlines.push(unrecorded(path));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (sameState(after, before)) continue;\n\t\t\tsequence++;\n\t\t\tlines.push(\n\t\t\t\t{ type: 'prepared', sequence, path, before, after, observedBy: observation.by },\n\t\t\t\t{ type: 'applied', sequence },\n\t\t\t);\n\t\t}\n\t\t// What it held before is unknown, so only a path that is no longer uncopyable has changed.\n\t\tfor (const path of manifest.uncopyable ?? []) {\n\t\t\tif (!isAbsolute(path) || recorded.has(path)) continue;\n\t\t\tconst now = await currentState(path).catch((error: unknown) => {\n\t\t\t\tthis.warnUnreadable(path, error);\n\t\t\t\treturn 'unreadable' as const;\n\t\t\t});\n\t\t\tif (now !== undefined) lines.push(unrecorded(path));\n\t\t}\n\t\tlines.push({ type: 'observed', sequence: observation.sequence });\n\t\treturn lines;\n\t}\n\n\tprivate warnUnreadable(path: string, error: unknown): void {\n\t\ttreatErrors(\n\t\t\t() => {\n\t\t\t\tthis.logger.warn(\n\t\t\t\t\t`The history could not read ${path} to settle what a command changed, and records it as a change undo cannot take back: ${describeFailure(error)}`,\n\t\t\t\t);\n\t\t\t},\n\t\t\tclassifyHostFailure,\n\t\t\t'Recovery store logger failed while reporting an unreadable file',\n\t\t);\n\t}\n\n\t/**\n\t * What `path` holds now, with its content stored, or `undefined` for what no entry records.\n\t * A file it cannot read is `unreadable`, and reported: it cannot be undone either, and settling\n\t * never waits on it, or every later run would fail to start. A failure to store its content is\n\t * thrown, so the observation stays open and settling it is tried again.\n\t */\n\tprivate async saveState(path: string): Promise<FileState | undefined | 'unreadable'> {\n\t\tlet state: FileState | undefined;\n\t\tlet content: Buffer | undefined;\n\t\ttry {\n\t\t\tstate = await currentState(path);\n\t\t\tif (!state?.exists) return state;\n\t\t\tcontent = await readFile(path).catch((error: unknown) => {\n\t\t\t\tif (isNotFound(error)) return undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.warnUnreadable(path, error);\n\t\t\treturn 'unreadable';\n\t\t}\n\t\tif (!content) return { exists: false };\n\t\tconst { hash } = await storeContent(join(this.directory, 'content'), content);\n\t\t// Read again: the file may have changed between hashing it and storing it.\n\t\treturn hash === state.hash ? state : this.saveState(path);\n\t}\n\n\tprivate async readEntries(runId: string, journal = firstJournal): Promise<JournalEntry[]> {\n\t\treturn (await this.readJournal(runId, journal)).entries;\n\t}\n\n\t/**\n\t * A run's changes, the observations it began and never finished, and the highest sequence\n\t * number its journal uses, which the next line it gets must exceed.\n\t */\n\tprivate async readJournal(\n\t\trunId: string,\n\t\tjournal = firstJournal,\n\t): Promise<{\n\t\tentries: JournalEntry[];\n\t\tobservations: OpenObservation[];\n\t\t/** With the sequence of its line, which `readRun` leaves out. */\n\t\tunrecorded: (UnrecordedChange & { sequence: number })[];\n\t\tlastSequence: number;\n\t}> {\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = await readFile(join(this.runDirectory(runId), journal), 'utf8');\n\t\t} catch (error) {\n\t\t\t// A run that stopped before opening its journal never changed anything.\n\t\t\tif (isNotFound(error)) {\n\t\t\t\treturn { entries: [], observations: [], unrecorded: [], lastSequence: 0 };\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tconst lines = text.split('\\n');\n\n\t\tconst entries = new Map<number, JournalEntry>();\n\t\tconst observations = new Map<number, OpenObservation>();\n\t\tconst unrecorded: (UnrecordedChange & { sequence: number })[] = [];\n\t\tlet lastSequence = 0;\n\t\tlines.forEach((text, index) => {\n\t\t\tif (text === '') return;\n\t\t\tlet line: JournalLine;\n\t\t\ttry {\n\t\t\t\tline = JSON.parse(text) as JournalLine;\n\t\t\t} catch (error) {\n\t\t\t\t// A crash in the middle of an append leaves half a line, always the last one. Its\n\t\t\t\t// step never returned, so no change was made after it.\n\t\t\t\tif (index === lines.length - 1) return;\n\t\t\t\tthrow new Error(`The journal of run ${runId} is corrupt at line ${String(index + 1)}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t\tlastSequence = Math.max(lastSequence, line.sequence);\n\t\t\tif (line.type === 'prepared') {\n\t\t\t\tconst { sequence, path, before, after, createdFolders, observedBy } = line;\n\t\t\t\tentries.set(sequence, {\n\t\t\t\t\tsequence,\n\t\t\t\t\tpath,\n\t\t\t\t\tbefore,\n\t\t\t\t\tafter,\n\t\t\t\t\t...(createdFolders ? { createdFolders } : {}),\n\t\t\t\t\t...(observedBy === undefined ? {} : { observedBy }),\n\t\t\t\t\tstatus: 'prepared',\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (line.type === 'observing') {\n\t\t\t\tconst { sequence, manifest, by } = line;\n\t\t\t\tobservations.set(sequence, { sequence, manifest, by });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (line.type === 'observed') {\n\t\t\t\tobservations.delete(line.sequence);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (line.type === 'unrecorded') {\n\t\t\t\tunrecorded.push({ sequence: line.sequence, path: line.path, by: line.by });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst entry = entries.get(line.sequence);\n\t\t\tif (entry) entry.status = line.type;\n\t\t});\n\n\t\treturn {\n\t\t\tentries: [...entries.values()],\n\t\t\tobservations: [...observations.values()],\n\t\t\tunrecorded,\n\t\t\tlastSequence,\n\t\t};\n\t}\n\n\tasync readContent(hash: string): Promise<Buffer> {\n\t\tif (!hashPattern.test(hash)) throw new Error(`Not a content hash: ${hash}`);\n\t\treturn readFile(contentPath(join(this.directory, 'content'), hash));\n\t}\n\n\tprivate async lock(runId: string): Promise<void> {\n\t\tconst path = join(this.directory, 'lock');\n\t\t// Twice at most: once as it is, and once more after clearing a dead run's lock.\n\t\tfor (let attempt = 0; attempt < 2; attempt++) {\n\t\t\ttry {\n\t\t\t\t// Written whole before it appears, so a lock that exists always names its holder.\n\t\t\t\tawait writeDurably(path, JSON.stringify({ runId, pid: process.pid }), { exclusive: true });\n\t\t\t\theldHere.add(runId);\n\t\t\t\t// Under the lock: a removal of a worktree this run may write in keeps it out. The\n\t\t\t\t// caller unlocks when this throws.\n\t\t\t\tthis.releases.set(runId, await this.claims.claimWriting(runId, this.writeFolders));\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tif ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n\t\t\t}\n\n\t\t\tconst holder = await readLock(path);\n\t\t\t// Released meanwhile: try again.\n\t\t\tif (!holder) continue;\n\t\t\tif (isLiveHolder(holder)) throw new WorkspaceBusyError(holder.runId);\n\t\t\t// Its process died, or its run ended, without releasing it. Read again just before\n\t\t\t// removing, so a lock another run has just taken is left alone.\n\t\t\tconst again = await readLock(path);\n\t\t\tif (again !== undefined && again.pid === holder.pid && again.runId === holder.runId) {\n\t\t\t\tawait unlink(path).catch((error: unknown) => {\n\t\t\t\t\tif (!isNotFound(error)) throw error;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tthrow new WorkspaceBusyError((await readLock(path))?.runId ?? 'unknown');\n\t}\n\n\tprivate async unlock(runId: string): Promise<void> {\n\t\t// First: the run has ended even if removing its lock fails, so that lock is stale.\n\t\theldHere.delete(runId);\n\t\tconst release = this.releases.get(runId);\n\t\tthis.releases.delete(runId);\n\t\tawait release?.();\n\t\tconst path = join(this.directory, 'lock');\n\t\t// Only its own lock: one cleared as stale and taken by another run is not this run's.\n\t\tif ((await readLock(path))?.runId === runId) await unlink(path);\n\t}\n}\n\n/**\n * No change it recorded may have reached a file: it recorded none, or abandoned each one, and\n * none it could not copy.\n */\nfunction changedNothing({\n\tentries,\n\tunrecorded,\n}: {\n\tentries: JournalEntry[];\n\tunrecorded: UnrecordedChange[];\n}): boolean {\n\treturn unrecorded.length === 0 && entries.every(entry => entry.status === 'abandoned');\n}\n\n/**\n * A run recorded as `running` only runs while it holds the lock, its process lives, and, in this\n * process, it has not ended. Any other is reported as `interrupted`, before the next run settles\n * it.\n */\nfunction withLiveStatus(\n\trecord: RunRecord,\n\tholder: { runId: string; pid?: number } | undefined,\n): RunRecord {\n\tif (record.status !== 'running') return record;\n\tconst live = holder?.runId === record.runId && holder.pid !== undefined && isLiveHolder(holder);\n\treturn live ? record : { ...record, status: 'interrupted' };\n}\n\n/**\n * Appends `lines`, as JSON, to a file of one line each, created private if missing. A crash may\n * have left its last line without a newline. A whole line, which the readers already count, is\n * kept and ended. Half a line would join the first new line, so it is cut off: whatever was\n * writing it never returned.\n */\nasync function appendWhole(path: string, lines: unknown[]): Promise<void> {\n\tif (lines.length === 0) return;\n\tlet text = '';\n\ttry {\n\t\ttext = await readFile(path, 'utf8');\n\t} catch (error) {\n\t\tif (!isNotFound(error)) throw error;\n\t}\n\tconst last = text.slice(text.lastIndexOf('\\n') + 1);\n\tlet separator = '';\n\tif (last !== '') {\n\t\tif (isWholeLine(last)) separator = '\\n';\n\t\telse await truncate(path, Buffer.byteLength(text) - Buffer.byteLength(last));\n\t}\n\tconst journal = await open(path, 'a', privateFile);\n\ttry {\n\t\tawait journal.appendFile(separator + lines.map(line => `${JSON.stringify(line)}\\n`).join(''));\n\t\tawait journal.sync();\n\t} finally {\n\t\tawait journal.close();\n\t}\n}\n\nfunction isWholeLine(text: string): boolean {\n\ttry {\n\t\tJSON.parse(text);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Who holds the lock, or `undefined` when nobody does. A lock this store did not write whole\n * has no `pid`, so it is never taken for a dead run's.\n */\nasync function readLock(path: string): Promise<{ runId: string; pid?: number } | undefined> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(path, 'utf8');\n\t} catch (error) {\n\t\tif (isNotFound(error)) return undefined;\n\t\tthrow error;\n\t}\n\ttry {\n\t\tconst { runId, pid } = JSON.parse(text) as { runId?: unknown; pid?: unknown };\n\t\tif (typeof runId === 'string' && Number.isInteger(pid)) return { runId, pid: pid as number };\n\t} catch {\n\t\t// Not JSON: named below as unknown.\n\t}\n\treturn { runId: 'unknown' };\n}\n\nfunction within(path: string, folder: string): boolean {\n\treturn path === folder || path.startsWith(`${folder}${sep}`);\n}\n\nfunction contentPath(contentDirectory: string, hash: string): string {\n\t// Two levels, so no folder holds every file a workspace ever stored.\n\treturn join(contentDirectory, hash.slice(0, 2), hash);\n}\n\nclass FileRunJournal implements RunJournal {\n\treadonly runId: string;\n\tprivate readonly record: RunRecord;\n\tprivate readonly runDirectory: string;\n\tprivate readonly contentDirectory: string;\n\tprivate readonly journal: FileHandle;\n\tprivate readonly discard: () => Promise<void>;\n\tprivate readonly settle: (record: RunRecord) => Promise<boolean>;\n\tprivate readonly release: () => Promise<void>;\n\tprivate sequence = 0;\n\tprivate stored = 0;\n\t// For the content state: what each change will leave, what each file held before the run first\n\t// changed it, and what it holds since its last applied change.\n\tprivate readonly pendingStates = new Map<number, { path: string; after: FileState }>();\n\tprivate readonly firstStates = new Map<string, FileState>();\n\tprivate readonly currentStates = new Map<string, FileState>();\n\tprivate readonly appliedInOrder: string[] = [];\n\tprivate state: { applied: number; hash: string } | undefined;\n\t// The changes recorded as prepared and not abandoned: those that may have reached a file. One\n\t// whose `prepared` line failed is not here, since nothing writes a file before that line.\n\tprivate readonly effects = new Set<number>();\n\t// The observations begun and not yet observed: what they saw is not all recorded.\n\tprivate readonly observing = new Set<number>();\n\t// A change it could not copy reached a file, and stays in the history.\n\tprivate lost = false;\n\t// Settling what it left open as it finished found that it changed nothing.\n\tprivate settledEmpty = false;\n\t// Appends run one after another, so the lines never interleave.\n\tprivate pending: Promise<unknown> = Promise.resolve();\n\tprivate finished = false;\n\t// Set when an append fails: it may have left part of a line, and anything after it would be\n\t// joined to that part and unreadable.\n\tprivate broken: unknown;\n\n\tconstructor({\n\t\trecord,\n\t\trunDirectory,\n\t\tcontentDirectory,\n\t\tjournal,\n\t\tdiscard,\n\t\tsettle,\n\t\trelease,\n\t}: {\n\t\trecord: RunRecord;\n\t\trunDirectory: string;\n\t\tcontentDirectory: string;\n\t\tjournal: FileHandle;\n\t\tdiscard: () => Promise<void>;\n\t\t/**\n\t\t * Settles the run's open observations, once its record names it `unsettled`, and tells\n\t\t * whether the run is still in the history.\n\t\t */\n\t\tsettle: (record: RunRecord) => Promise<boolean>;\n\t\trelease: () => Promise<void>;\n\t}) {\n\t\tthis.runId = record.runId;\n\t\tthis.record = record;\n\t\tthis.runDirectory = runDirectory;\n\t\tthis.contentDirectory = contentDirectory;\n\t\tthis.journal = journal;\n\t\tthis.discard = discard;\n\t\tthis.settle = settle;\n\t\tthis.release = release;\n\t}\n\n\tasync saveContent(content: Buffer): Promise<string> {\n\t\tthis.assertOpen();\n\t\tconst { hash, written } = await storeContent(this.contentDirectory, content);\n\t\tif (written) this.stored += content.length;\n\t\treturn hash;\n\t}\n\n\tasync prepare(change: Omit<JournalEntry, 'sequence' | 'status'>): Promise<number> {\n\t\tthis.assertOpen();\n\t\tconst sequence = ++this.sequence;\n\t\tawait this.append({ type: 'prepared', sequence, ...change });\n\t\tthis.effects.add(sequence);\n\t\tthis.pendingStates.set(sequence, { path: change.path, after: change.after });\n\t\tif (!this.firstStates.has(change.path)) this.firstStates.set(change.path, change.before);\n\t\treturn sequence;\n\t}\n\n\tasync applied(sequence: number): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'applied', sequence });\n\t\tconst change = this.pendingStates.get(sequence);\n\t\tif (!change) return;\n\t\tthis.pendingStates.delete(sequence);\n\t\tthis.currentStates.set(change.path, change.after);\n\t\tthis.appliedInOrder.push(change.path);\n\t}\n\n\tasync abandoned(sequence: number): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'abandoned', sequence });\n\t\t// Only once recorded: a change whose abandonment was not may still count as made.\n\t\tthis.effects.delete(sequence);\n\t\tthis.pendingStates.delete(sequence);\n\t}\n\n\tasync observe(manifest: string, by: string): Promise<number> {\n\t\tthis.assertOpen();\n\t\tconst sequence = ++this.sequence;\n\t\tawait this.append({ type: 'observing', sequence, manifest, by });\n\t\t// Until it is observed, whatever ran may have changed a file.\n\t\tthis.effects.add(sequence);\n\t\tthis.observing.add(sequence);\n\t\treturn sequence;\n\t}\n\n\tasync observed(sequence: number, measure?: ObservationMeasure): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'observed', sequence, ...(measure ? { measure } : {}) });\n\t\t// Its changes, if any, are entries of their own now.\n\t\tthis.effects.delete(sequence);\n\t\tthis.observing.delete(sequence);\n\t}\n\n\tasync unrecorded(path: string, by: string): Promise<void> {\n\t\tthis.assertOpen();\n\t\tawait this.append({ type: 'unrecorded', sequence: ++this.sequence, path, by });\n\t\tthis.lost = true;\n\t}\n\n\tget storedBytes(): number {\n\t\treturn this.stored;\n\t}\n\n\tget appliedPaths(): readonly string[] {\n\t\treturn this.appliedInOrder;\n\t}\n\n\t// Computed again only after a change was applied.\n\tcontentState(): string {\n\t\tif (this.state?.applied !== this.appliedInOrder.length) {\n\t\t\tconst changed = [...this.currentStates]\n\t\t\t\t.filter(([path, current]) => {\n\t\t\t\t\tconst first = this.firstStates.get(path);\n\t\t\t\t\treturn !first || !sameState(first, current);\n\t\t\t\t})\n\t\t\t\t.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n\t\t\tthis.state = {\n\t\t\t\tapplied: this.appliedInOrder.length,\n\t\t\t\thash: hashOf(Buffer.from(JSON.stringify(changed))),\n\t\t\t};\n\t\t}\n\t\treturn this.state.hash;\n\t}\n\n\tget changed(): boolean {\n\t\treturn !this.settledEmpty && (this.lost || this.effects.size > 0);\n\t}\n\n\tasync finish(status: Exclude<RunStatus, 'running' | 'interrupted'>): Promise<void> {\n\t\tthis.assertOpen();\n\t\tthis.finished = true;\n\t\ttry {\n\t\t\tawait this.pending;\n\t\t\tawait this.journal.close();\n\t\t\t// Its record is left `running`: if removing it fails, readers already take it as gone.\n\t\t\tif (!this.changed) {\n\t\t\t\tawait this.discard();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst unsettled = this.observing.size > 0;\n\t\t\tconst record: RunRecord = {\n\t\t\t\t...this.record,\n\t\t\t\tstatus,\n\t\t\t\tfinishedAt: new Date().toISOString(),\n\t\t\t\t...(unsettled ? { unsettled } : {}),\n\t\t\t};\n\t\t\tawait writeDurably(join(this.runDirectory, 'run.json'), JSON.stringify(record));\n\t\t\t// Recorded first as unsettled, so a failure or a crash here leaves it to the next run.\n\t\t\tif (unsettled) this.settledEmpty = !(await this.settle(record));\n\t\t} finally {\n\t\t\tawait this.release();\n\t\t}\n\t}\n\n\tprivate append(line: JournalLine): Promise<void> {\n\t\tconst write = this.pending.then(async () => {\n\t\t\tif (this.broken !== undefined) {\n\t\t\t\tthrow new Error(`The journal of run ${this.runId} stopped after a failed write`, {\n\t\t\t\t\tcause: this.broken,\n\t\t\t\t});\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait this.journal.appendFile(`${JSON.stringify(line)}\\n`);\n\t\t\t\tawait this.journal.sync();\n\t\t\t} catch (error) {\n\t\t\t\tthis.broken = error ?? new Error('Unknown write failure');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\t\t// The chain goes on, so each later append reports the broken journal to its own caller.\n\t\tthis.pending = write.catch(() => undefined);\n\t\treturn write;\n\t}\n\n\tprivate assertOpen(): void {\n\t\tif (this.finished) throw new Error(`Run ${this.runId} has already finished`);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who works in which folders, across every history kept in one state directory, so a folder is
|
|
3
|
+
* removed only while no run writes in it, and no run starts writing in a folder being removed.
|
|
4
|
+
* A run, or a move, claims the folders it may write while it holds its workspace; a removal
|
|
5
|
+
* claims the folder while it removes it. Each writes its own claim before it reads the others',
|
|
6
|
+
* so of two that start at once at least one sees the other, and gives way.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FolderClaims {
|
|
9
|
+
private readonly directory;
|
|
10
|
+
/** `stateDirectory` is the real path of the state directory. */
|
|
11
|
+
constructor(stateDirectory: string);
|
|
12
|
+
/**
|
|
13
|
+
* Claims `folders` for writing, and returns what releases the claim.
|
|
14
|
+
*
|
|
15
|
+
* @throws {WorkspaceBusyError} when a removal in progress covers one of them.
|
|
16
|
+
*/
|
|
17
|
+
claimWriting(id: string, folders: readonly string[]): Promise<() => Promise<void>>;
|
|
18
|
+
/**
|
|
19
|
+
* Claims `folder` for its removal, and returns what releases the claim.
|
|
20
|
+
*
|
|
21
|
+
* @throws {WorkspaceBusyError} when a run, or a move, may write in it.
|
|
22
|
+
*/
|
|
23
|
+
claimRemoval(folder: string): Promise<() => Promise<void>>;
|
|
24
|
+
private claim;
|
|
25
|
+
/** A live claim of `kind` covering one of `folders`, by its name, if any. */
|
|
26
|
+
private liveHolder;
|
|
27
|
+
}
|