{"record":{"id":"f41e1959b4a008b0","repo":"thedotmack/claude-mem","slug":"plugin-scripts-bun-runner-js-is-missing-fixbrokens","errorCode":null,"errorMessage":"plugin/scripts/bun-runner.js is missing fixBrokenScriptPath — it is the Rule C runtime safety net behind Rule A. Do not remove it.","messagePattern":"plugin/scripts/bun-runner\\.js is missing fixBrokenScriptPath — it is the Rule C runtime safety net behind Rule A\\. Do not remove it\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"scripts/build-hooks.js","lineNumber":227,"sourceCode":"                `Regenerate via \\`node scripts/build-hooks.js --write-shell-templates\\` after an intentional generator change.`\n              );\n            }\n            entry.commandWindows = expected.commandWindows;\n            dirty = true;\n          }\n        }\n      }\n    }\n    if (dirty) {\n      fs.writeFileSync(filePath, JSON.stringify(parsed, null, 2) + '\\n');\n      console.log(`  ✏️  Regenerated shell templates in ${filePath}`);\n    }\n  }\n\n  // Rule C safety net (bun-runner.js fixBrokenScriptPath) must stay documented.\n  const bunRunner = fs.readFileSync('plugin/scripts/bun-runner.js', 'utf-8');\n  if (!bunRunner.includes('function fixBrokenScriptPath')) {\n    throw new Error(\n      'plugin/scripts/bun-runner.js is missing fixBrokenScriptPath — it is the Rule C runtime safety net behind Rule A. Do not remove it.'\n    );\n  }\n\n  // Parser-compat guard (issue #2791): bun-runner.js is invoked by hosts that\n  // may run a pre-ES2020 Node whose ESM loader throws on optional chaining.\n  // Strip comments, then forbid `?.` / `??` in executable code.\n  const bunRunnerCode = bunRunner\n    .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n    .replace(/(^|[^:])\\/\\/.*$/gm, '$1');\n  if (/\\?\\.|\\?\\?/.test(bunRunnerCode)) {\n    throw new Error(\n      'plugin/scripts/bun-runner.js uses optional chaining (?.) or nullish coalescing (??) — ' +\n      'this launcher must parse on pre-ES2020 Node (issue #2791). Rewrite with explicit guards.'\n    );\n  }\n\n  console.log('✓ Rule A shell templates match the canonical generator');","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/scripts/build-hooks.js#L209-L245","documentation":"A defensive guard ensuring plugin/scripts/bun-runner.js still defines function fixBrokenScriptPath. This function is the Rule C runtime safety net that repairs script paths when a host invokes the launcher with a stale or mismatched PLUGIN_ROOT. The build reads bun-runner.js and string-matches the function name; if absent it refuses to complete the build because removing the safety net would resurrect the script-path bugs Rule A/C were designed to prevent.","triggerScenarios":"Running the build after someone deleted or renamed fixBrokenScriptPath in plugin/scripts/bun-runner.js. Refactoring that moved the function into another file (so the string match fails even though the logic exists elsewhere). A bad merge that dropped the function.","commonSituations":"Aggressive refactor of bun-runner.js that 'inlines' or relocates path-fixing logic. Copy-paste of a minimal launcher that omits the safety net. Merge conflict resolution that drops the function.","solutions":["Restore function fixBrokenScriptPath in plugin/scripts/bun-runner.js (git checkout HEAD -- plugin/scripts/bun-runner.js if the deletion was unintentional).","If you intentionally relocated the logic, keep a thin `function fixBrokenScriptPath(...)` wrapper in bun-runner.js that calls the new location — the guard requires the symbol to live in this exact file.","Re-run node scripts/build-hooks.js; the guard passes once the string 'function fixBrokenScriptPath' is present.","Do not work around by editing the guard — Rule C exists because hosts ship stale PLUGIN_ROOT values and silently break; removing the net regresses that."],"exampleFix":"// before: fixBrokenScriptPath removed from plugin/scripts/bun-runner.js\n\n// restore it (canonical implementation lives in git history):\nfunction fixBrokenScriptPath(scriptPath) {\n  // Rule C: repair stale PLUGIN_ROOT-derived paths at runtime\n  // ... existing body ...\n}\n\n// then: node scripts/build-hooks.js succeeds","handlingStrategy":"validation","validationCode":"// Quick local check mirroring the guard:\nconst src = fs.readFileSync('plugin/scripts/bun-runner.js', 'utf8');\nif (!src.includes('function fixBrokenScriptPath')) {\n  throw new Error('Rule C safety net missing — restore fixBrokenScriptPath');\n}","typeGuard":null,"tryCatchPattern":"// Build-time only, intentional fail-fast. Do not catch. Restore the function\n// (git checkout HEAD -- plugin/scripts/bun-runner.js) or keep a wrapper that\n// delegates to the new location.","preventionTips":["Treat fixBrokenScriptPath as load-bearing — it's referenced as Rule C in the build.","When refactoring bun-runner.js, leave the symbol in place even if it delegates elsewhere.","Add a unit test that exercises fixBrokenScriptPath so deletions surface in tests, not just build."],"tags":["build","verification","rule-c","runtime-safety","bun-runner"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}