ponytail-activate.js and ponytail-runtime.js hardcoded ~/.claude for the flag file and settings lookup, ignoring CLAUDE_CONFIG_DIR. Add a shared getClaudeDir() to ponytail-config.js and use it in both. Regression test added to hooks.test.js. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40 lines
945 B
JavaScript
40 lines
945 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { getClaudeDir } = require('./ponytail-config');
|
|
|
|
const isCodex = Boolean(process.env.PLUGIN_DATA);
|
|
const statePath = isCodex
|
|
? path.join(process.env.PLUGIN_DATA, '.ponytail-active')
|
|
: path.join(getClaudeDir(), '.ponytail-active');
|
|
|
|
function setMode(mode) {
|
|
fs.mkdirSync(path.dirname(statePath), { recursive: true });
|
|
fs.writeFileSync(statePath, mode);
|
|
}
|
|
|
|
function clearMode() {
|
|
try { fs.unlinkSync(statePath); } catch (e) {}
|
|
}
|
|
|
|
function writeHookOutput(event, mode, context = '') {
|
|
if (!isCodex) {
|
|
process.stdout.write(context);
|
|
return;
|
|
}
|
|
const output = { systemMessage: `PONYTAIL:${mode.toUpperCase()}` };
|
|
if (context) {
|
|
output.hookSpecificOutput = {
|
|
hookEventName: event,
|
|
additionalContext: context,
|
|
};
|
|
}
|
|
process.stdout.write(JSON.stringify(output));
|
|
}
|
|
|
|
module.exports = {
|
|
clearMode,
|
|
isCodex,
|
|
setMode,
|
|
writeHookOutput,
|
|
};
|