Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249/** Stable policy results for transaction-specific failures. @module */import { caughtValueText, } from '@monochromatic-dev/module-caught-value/ts';
import type { PolicyTrigger, } from '../api/policy-types.ts';import { CommitTransactionGitError, } from './commit-transaction-git.ts';import { createEngineFailureEvent, type EngineFailureCode,} from './events.ts';import type { PolicyEngineResult, } from './types.ts';
/** Produces transaction failure before policy pass exists. @param args - exact wrapper arguments @param message - failure description @param code - stable transaction failure classification @param trigger - lifecycle point owning failure @param path - optional path owning failure @returns blocking engine result @example ```ts initialTransactionFailure({ args: ['commit'], message: 'blocked' }); ``` */export function initialTransactionFailure({ args, message, code = 'transaction-failed', trigger = 'pre-forward', path,}: Readonly<{ args: readonly string[]; message: string; code?: EngineFailureCode; trigger?: PolicyTrigger; path?: string;}>,): PolicyEngineResult { return { args, escapedPolicyIds: new Set(), events: [createEngineFailureEvent({ sequence: 0, code, message, trigger, ...(path === undefined ? {} : { path, }), },),], patches: [], exitCode: 2, shouldForward: false, };}
/** Produces failure retaining transformed command facts. @param previous - latest policy pass @param message - transaction failure description @param code - stable transaction failure classification @param trigger - lifecycle point owning failure @param path - optional path owning failure @returns blocking engine result @example ```ts transactionFailure({ previous, message: 'blocked' }); ``` */export function transactionFailure({ previous, message, code = 'transaction-failed', trigger = 'pre-forward', path,}: Readonly<{ previous: PolicyEngineResult; message: string; code?: EngineFailureCode; trigger?: PolicyTrigger; path?: string;}>,): PolicyEngineResult { return { args: previous.args, escapedPolicyIds: previous.escapedPolicyIds, events: [createEngineFailureEvent({ sequence: 0, code, message, trigger, ...(path === undefined ? {} : { path, }), },),], patches: [], exitCode: 2, shouldForward: false, };}
/** Produces stable changed-pass-limit failure. @param previous - latest provisional policy pass @param trigger - fixable lifecycle point @returns blocking pass-limit result @example ```ts fixPassLimitFailure({ previous, trigger: 'direct-fix' }); ``` */export function fixPassLimitFailure({ previous, trigger,}: Readonly<{ previous: PolicyEngineResult; trigger: Extract<PolicyTrigger, 'pre-forward' | 'direct-fix'>;}>,): PolicyEngineResult { return transactionFailure({ previous, code: 'fix-pass-limit', message: 'Policy patches did not converge within eight changed passes.', trigger, },);}
/** Produces stable invalid patch-target failure. @param previous - latest provisional policy pass @param trigger - fixable lifecycle point @param path - stale or mutable patch target @returns blocking invalid-patch result @example ```ts patchTargetFailure({ previous, trigger: 'pre-forward', path: 'a.txt' }); ``` */export function patchTargetFailure({ previous, trigger, path,}: Readonly<{ previous: PolicyEngineResult; trigger: Extract<PolicyTrigger, 'pre-forward' | 'direct-fix'>; path: string;}>,): PolicyEngineResult { return transactionFailure({ previous, code: 'patch-invalid', message: `Patch target is stale, undeclared, or mutable: ${path}`, trigger, path, },);}
/** Classifies private patch validation and Git application failures. @param previous - latest provisional policy pass @param trigger - fixable lifecycle point @param path - declared patch target @param error - validation or Git application failure @returns blocking classified patch result @mutates error - `caughtValueText` may invoke string-conversion hooks. @example ```ts patchApplicationFailure({ previous, trigger: 'direct-fix', path: 'a.txt', error }); ``` */export function patchApplicationFailure({ previous, trigger, path, error,}: Readonly<{ previous: PolicyEngineResult; trigger: Extract<PolicyTrigger, 'pre-forward' | 'direct-fix'>; path: string; error: unknown;}>,): PolicyEngineResult { return transactionFailure({ previous, code: error instanceof CommitTransactionGitError ? 'patch-conflict' : 'patch-invalid', message: caughtValueText(error,), trigger, path, },);}
/** Produces stable exact candidate-cycle failure. @param previous - latest provisional policy pass @param trigger - fixable lifecycle point @param message - lifecycle-specific cycle explanation @returns blocking cycle result @example ```ts fixCycleFailure({ previous, trigger: 'pre-forward', message: 'Repeated state.' }); ``` */export function fixCycleFailure({ previous, trigger, message,}: Readonly<{ previous: PolicyEngineResult; trigger: Extract<PolicyTrigger, 'pre-forward' | 'direct-fix'>; message: string;}>,): PolicyEngineResult { return transactionFailure({ previous, code: 'fix-cycle', message, trigger, },);}