Roo-Code/src/hooks/optimisticLockPreWriteHook.ts
Yakob Dereje 3db3b0112a feat: implement deterministic hook system and intent-traceability ledger
- Added SelectActiveIntentTool for handshake protocol
- Implemented middleware gatekeeper in tool execution pipeline
- Integrated RecordAgentTraceTool for SHA-256 content hashing
- Created .orchestration/ artifacts for machine-readable audit trails
2026-02-21 23:00:24 +03:00

27 lines
821 B
TypeScript

import { getCurrentHash, StaleFileError, validateLock } from "../core/concurrency/OptimisticLock"
import type { HookResult, OptimisticLockContext } from "./types"
export interface OptimisticLockResult extends HookResult {
currentHash?: string
}
export async function runOptimisticLockPreWriteHook(context: OptimisticLockContext): Promise<OptimisticLockResult> {
const expectedHash = String(context.expectedHash ?? "").trim()
if (!expectedHash) {
return { ok: true }
}
const isValid = await validateLock(expectedHash, context.filePath)
if (isValid) {
return { ok: true }
}
const currentHash = await getCurrentHash(context.filePath).catch(() => "unavailable")
const error = new StaleFileError(context.filePath, expectedHash, currentHash)
return {
ok: false,
error: error.message,
currentHash,
}
}