tdd-guard
Version:
TDD Guard enforces Test-Driven Development principles using Claude Code hooks
34 lines (33 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HookEvents = void 0;
const toolSchemas_1 = require("../contracts/schemas/toolSchemas");
class HookEvents {
storage;
constructor(storage) {
this.storage = storage;
}
async processEvent(event) {
const hookResult = toolSchemas_1.HookDataSchema.safeParse(event);
if (!hookResult.success)
return;
const operation = this.extractToolOperation(hookResult.data);
if (!operation)
return;
await this.persistOperation(operation);
}
extractToolOperation(hook) {
const result = toolSchemas_1.ToolOperationSchema.safeParse(hook);
return result.success ? result.data : null;
}
async persistOperation(operation) {
const content = JSON.stringify(operation, null, 2);
if ((0, toolSchemas_1.isTodoWriteOperation)(operation)) {
await this.storage.saveTodo(content);
}
else {
await this.storage.saveModifications(content);
}
}
}
exports.HookEvents = HookEvents;