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.
123#!/usr/bin/env nodeimport{text}from"node:stream/consumers";function isDigit(c){return c>=`0`&&c<=`9`}function isLowerAlpha(c){return c>=`a`&&c<=`z`}function isUpperAlpha(c){return c>=`A`&&c<=`Z`}function isAlphaNum(c){return isLowerAlpha(c)||isUpperAlpha(c)||isDigit(c)}function isWordChar(c){return isAlphaNum(c)||c===`_`}const PHRASE_NOT_FOUND=Symbol(`text-scan/phrase-not-found`);function boundariesSatisfied({haystack,phrase,index}){let before=index===0?``:haystack.charAt(index-1),afterIndex=index+phrase.length,after=afterIndex>=haystack.length?``:haystack.charAt(afterIndex),firstChar=phrase.charAt(0),lastChar=phrase.at(-1)??``,startBoundaryOk=!isWordChar(firstChar)||before===``||!isWordChar(before),endBoundaryOk=!isWordChar(lastChar)||after===``||!isWordChar(after);return startBoundaryOk&&endBoundaryOk}function containsWordBoundedPhrase({haystack,phrase}){if(phrase.length===0)return!1;let lowerHaystack=haystack.toLowerCase(),lowerPhrase=phrase.toLowerCase();for(let cursorIndex=lowerHaystack.indexOf(lowerPhrase,0);cursorIndex!==-1;cursorIndex=lowerHaystack.indexOf(lowerPhrase,cursorIndex+1))if(boundariesSatisfied({haystack:lowerHaystack,phrase:lowerPhrase,index:cursorIndex}))return!0;return!1}function containsAnyOfWordBounded({haystack,phrases}){for(let phrase of phrases)if(containsWordBoundedPhrase({haystack,phrase}))return{phrase};return PHRASE_NOT_FOUND}const CORRECTION_PHRASES=`demonstrably false.demonstrably wrong.you missed.didn't you.didnt you.you're wrong.youre wrong.you are wrong.shouldn't have.shouldnt have.should not have.why would you.that's wrong.thats wrong.this is wrong.you got that wrong.you got this wrong.you got it wrong.you're not feeling well.you're not feeling attention.you're not paying well.you're not paying attention.youre not feeling well.youre not feeling attention.youre not paying well.youre not paying attention.please be more careful.are you paying attention.are you not paying attention.aren't you paying attention.aren't you not paying attention.arent you paying attention.arent you not paying attention`.split(`.`);function normaliseApostrophes(prompt){return prompt.replaceAll(`‘`,`'`).replaceAll(`’`,`'`)}function detectCorrection(prompt){return containsAnyOfWordBounded({haystack:normaliseApostrophes(prompt),phrases:CORRECTION_PHRASES})!==PHRASE_NOT_FOUND}const CORRECTION_REMINDER_TEXT=[`<correction-detected>`,`The user is correcting a substantive claim from your previous response.`,`Per AGENTS.md rule CKB: a user correction is an`,`approach-change moment, not a small patch. The blind spot that produced`,`the original claim is still active for the revision.`,``,`Before your next substantive response, re-check the claim against primary`,`sources, local files, logs, or command output. Do not run a same-session`,"self-review or write an `Advisor pass: ...` line; self-review is not","independent evidence. See `doc/agent/self-review.md`.",`</correction-detected>`].join(``);function correctionReminderHandler(event){return{hookSpecificOutput:{hookEventName:`UserPromptSubmit`,additionalContext:detectCorrection(event.prompt)?CORRECTION_REMINDER_TEXT:``}}}function correctionReminderParser(raw){return JSON.parse(raw)}function correctionReminderWriter(output){return JSON.stringify(output)}const NO_STDOUT=Symbol(`claude-code-plugin-runtime/hook-intentionally-emits-no-stdout-bytes`);async function runHookPlugin({parser,handler,writer}){let serialized=writer(await handler(parser(await text(process.stdin))));serialized!==NO_STDOUT&&process.stdout.write(serialized)}await runHookPlugin({parser:correctionReminderParser,handler:correctionReminderHandler,writer:correctionReminderWriter});export{};