feat: full plugin integration + cross-agent rules
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/env node
|
||||
// ponytail — Claude Code SessionStart activation hook
|
||||
//
|
||||
// Runs on every session start:
|
||||
// 1. Writes flag file at ~/.claude/.ponytail-active (statusline reads this)
|
||||
// 2. Emits ponytail ruleset as hidden SessionStart context
|
||||
// 3. Detects missing statusline config and emits setup nudge
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { getDefaultMode } = require('./ponytail-config');
|
||||
|
||||
const claudeDir = path.join(os.homedir(), '.claude');
|
||||
const flagPath = path.join(claudeDir, '.ponytail-active');
|
||||
const settingsPath = path.join(claudeDir, 'settings.json');
|
||||
|
||||
const mode = getDefaultMode();
|
||||
|
||||
// "off" mode — skip activation entirely, don't write flag or emit rules
|
||||
if (mode === 'off') {
|
||||
try { fs.unlinkSync(flagPath); } catch (e) {}
|
||||
process.stdout.write('OK');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// 1. Write flag file
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(flagPath), { recursive: true });
|
||||
fs.writeFileSync(flagPath, mode);
|
||||
} catch (e) {
|
||||
// Silent fail -- flag is best-effort, don't block the hook
|
||||
}
|
||||
|
||||
// 2. Emit the ponytail ruleset, filtered to the active intensity level.
|
||||
// A short summary is too weak — models drift back to over-building
|
||||
// mid-conversation, especially after context compression prunes it.
|
||||
// Full rules with examples anchor behavior much more reliably.
|
||||
//
|
||||
// Reads SKILL.md at runtime so edits to the source of truth propagate
|
||||
// automatically — no hardcoded duplication to go stale.
|
||||
|
||||
// Modes that have their own independent skill files — not intensity levels.
|
||||
// For these, emit a short activation line; the skill itself handles behavior.
|
||||
const INDEPENDENT_MODES = new Set(['review']);
|
||||
|
||||
if (INDEPENDENT_MODES.has(mode)) {
|
||||
process.stdout.write('PONYTAIL MODE ACTIVE — level: ' + mode + '. Behavior defined by /ponytail-' + mode + ' skill.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Read SKILL.md — the single source of truth for ponytail behavior.
|
||||
// Plugin installs: __dirname = <plugin_root>/hooks/, SKILL.md at <plugin_root>/skills/ponytail/SKILL.md
|
||||
let skillContent = '';
|
||||
try {
|
||||
skillContent = fs.readFileSync(
|
||||
path.join(__dirname, '..', 'skills', 'ponytail', 'SKILL.md'), 'utf8'
|
||||
);
|
||||
} catch (e) { /* standalone install — will use fallback below */ }
|
||||
|
||||
let output;
|
||||
|
||||
if (skillContent) {
|
||||
// Strip YAML frontmatter
|
||||
const body = skillContent.replace(/^---[\s\S]*?---\s*/, '');
|
||||
|
||||
// Filter intensity table: keep header rows + only the active level's row
|
||||
const filtered = body.split('\n').reduce((acc, line) => {
|
||||
// Intensity table rows start with | **level** |
|
||||
const tableRowMatch = line.match(/^\|\s*\*\*(\S+?)\*\*\s*\|/);
|
||||
if (tableRowMatch) {
|
||||
if (tableRowMatch[1] === mode) {
|
||||
acc.push(line);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
// Example lines start with "- level:" — keep only lines matching active level
|
||||
const exampleMatch = line.match(/^- (\S+?):\s/);
|
||||
if (exampleMatch) {
|
||||
if (exampleMatch[1] === mode) {
|
||||
acc.push(line);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc.push(line);
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
output = 'PONYTAIL MODE ACTIVE — level: ' + mode + '\n\n' + filtered.join('\n');
|
||||
} else {
|
||||
// Fallback when SKILL.md is not found (hook installed without skills dir).
|
||||
// Minimum viable ruleset — better than nothing.
|
||||
output =
|
||||
'PONYTAIL MODE ACTIVE — level: ' + mode + '\n\n' +
|
||||
'You are a lazy senior developer. Lazy means efficient, not careless. The best code is the code never written.\n\n' +
|
||||
'## Persistence\n\n' +
|
||||
'ACTIVE EVERY RESPONSE. No drift back to over-building. Still active if unsure. Off only: "stop ponytail" / "normal mode".\n\n' +
|
||||
'Current level: **' + mode + '**. Switch: `/ponytail lite|full|ultra`.\n\n' +
|
||||
'## The ladder\n\n' +
|
||||
'Before any code, stop at the first rung that holds:\n' +
|
||||
'1. Does this need to be built at all? (YAGNI)\n' +
|
||||
'2. Does the standard library do this? Use it.\n' +
|
||||
'3. Does a native platform feature cover it? Use it.\n' +
|
||||
'4. Does an already-installed dependency solve it? Use it.\n' +
|
||||
'5. Can this be one line? Make it one line.\n' +
|
||||
'6. Only then: write the minimum code that works.\n\n' +
|
||||
'## Rules\n\n' +
|
||||
'No abstractions that were not requested. No avoidable dependencies. No boilerplate nobody asked for. ' +
|
||||
'Deletion over addition. Boring over clever. Fewest files possible. ' +
|
||||
'Question complex requests: "Do you actually need X, or does Y cover it?" ' +
|
||||
'Mark intentional simplifications with a `ponytail:` comment.\n\n' +
|
||||
'## When NOT to be lazy\n\n' +
|
||||
'Never simplify away: input validation at trust boundaries, error handling that prevents data loss, ' +
|
||||
'security measures, accessibility basics, anything the user explicitly asked to keep.\n\n' +
|
||||
'## Boundaries\n\n' +
|
||||
'Ponytail governs what you build, not how you talk. "stop ponytail" or "normal mode": revert. Level persists until changed or session end.';
|
||||
}
|
||||
|
||||
// 3. Detect missing statusline config — nudge Claude to help set it up
|
||||
try {
|
||||
let hasStatusline = false;
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
||||
if (settings.statusLine) {
|
||||
hasStatusline = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasStatusline) {
|
||||
const isWindows = process.platform === 'win32';
|
||||
const scriptName = isWindows ? 'ponytail-statusline.ps1' : 'ponytail-statusline.sh';
|
||||
const scriptPath = path.join(__dirname, scriptName);
|
||||
const command = isWindows
|
||||
? `powershell -ExecutionPolicy Bypass -File "${scriptPath}"`
|
||||
: `bash "${scriptPath}"`;
|
||||
const statusLineSnippet =
|
||||
'"statusLine": { "type": "command", "command": ' + JSON.stringify(command) + ' }';
|
||||
output += "\n\n" +
|
||||
"STATUSLINE SETUP NEEDED: The ponytail plugin includes a statusline badge showing active mode " +
|
||||
"(e.g. [PONYTAIL], [PONYTAIL:ULTRA]). It is not configured yet. " +
|
||||
"To enable, add this to ~/.claude/settings.json: " +
|
||||
statusLineSnippet + " " +
|
||||
"Proactively offer to set this up for the user on first interaction.";
|
||||
}
|
||||
} catch (e) {
|
||||
// Silent fail — don't block session start over statusline detection
|
||||
}
|
||||
|
||||
process.stdout.write(output);
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env node
|
||||
// ponytail — shared configuration resolver
|
||||
//
|
||||
// Resolution order for default mode:
|
||||
// 1. PONYTAIL_DEFAULT_MODE environment variable
|
||||
// 2. Config file defaultMode field:
|
||||
// - $XDG_CONFIG_HOME/ponytail/config.json (any platform, if set)
|
||||
// - ~/.config/ponytail/config.json (macOS / Linux fallback)
|
||||
// - %APPDATA%\ponytail\config.json (Windows fallback)
|
||||
// 3. 'full'
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const VALID_MODES = ['off', 'lite', 'full', 'ultra', 'review'];
|
||||
|
||||
function getConfigDir() {
|
||||
if (process.env.XDG_CONFIG_HOME) {
|
||||
return path.join(process.env.XDG_CONFIG_HOME, 'ponytail');
|
||||
}
|
||||
if (process.platform === 'win32') {
|
||||
return path.join(
|
||||
process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'),
|
||||
'ponytail'
|
||||
);
|
||||
}
|
||||
return path.join(os.homedir(), '.config', 'ponytail');
|
||||
}
|
||||
|
||||
function getConfigPath() {
|
||||
return path.join(getConfigDir(), 'config.json');
|
||||
}
|
||||
|
||||
function getDefaultMode() {
|
||||
// 1. Environment variable (highest priority)
|
||||
const envMode = process.env.PONYTAIL_DEFAULT_MODE;
|
||||
if (envMode && VALID_MODES.includes(envMode.toLowerCase())) {
|
||||
return envMode.toLowerCase();
|
||||
}
|
||||
|
||||
// 2. Config file
|
||||
try {
|
||||
const configPath = getConfigPath();
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
if (config.defaultMode && VALID_MODES.includes(config.defaultMode.toLowerCase())) {
|
||||
return config.defaultMode.toLowerCase();
|
||||
}
|
||||
} catch (e) {
|
||||
// Config file doesn't exist or is invalid — fall through
|
||||
}
|
||||
|
||||
// 3. Default
|
||||
return 'full';
|
||||
}
|
||||
|
||||
module.exports = { getDefaultMode, getConfigDir, getConfigPath, VALID_MODES };
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env node
|
||||
// ponytail — UserPromptSubmit hook to track which ponytail mode is active
|
||||
// Inspects user input for /ponytail commands and writes mode to flag file
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { getDefaultMode } = require('./ponytail-config');
|
||||
|
||||
const flagPath = path.join(os.homedir(), '.claude', '.ponytail-active');
|
||||
|
||||
let input = '';
|
||||
process.stdin.on('data', chunk => { input += chunk; });
|
||||
process.stdin.on('end', () => {
|
||||
try {
|
||||
// Strip UTF-8 BOM some shells prepend when piping (breaks JSON.parse)
|
||||
const data = JSON.parse(input.replace(/^\uFEFF/, ''));
|
||||
const prompt = (data.prompt || '').trim().toLowerCase();
|
||||
|
||||
// Match /ponytail commands
|
||||
if (prompt.startsWith('/ponytail')) {
|
||||
const parts = prompt.split(/\s+/);
|
||||
const cmd = parts[0]; // /ponytail, /ponytail-review, /ponytail:ponytail, etc.
|
||||
const arg = parts[1] || '';
|
||||
|
||||
let mode = null;
|
||||
|
||||
if (cmd === '/ponytail-review' || cmd === '/ponytail:ponytail-review') {
|
||||
mode = 'review';
|
||||
} else if (cmd === '/ponytail' || cmd === '/ponytail:ponytail') {
|
||||
if (arg === 'lite') mode = 'lite';
|
||||
else if (arg === 'full') mode = 'full';
|
||||
else if (arg === 'ultra') mode = 'ultra';
|
||||
else if (arg === 'off') mode = 'off';
|
||||
else mode = getDefaultMode();
|
||||
}
|
||||
|
||||
if (mode && mode !== 'off') {
|
||||
fs.mkdirSync(path.dirname(flagPath), { recursive: true });
|
||||
fs.writeFileSync(flagPath, mode);
|
||||
} else if (mode === 'off') {
|
||||
try { fs.unlinkSync(flagPath); } catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
// Detect deactivation
|
||||
if (/\b(stop ponytail|normal mode)\b/i.test(prompt)) {
|
||||
try { fs.unlinkSync(flagPath); } catch (e) {}
|
||||
}
|
||||
} catch (e) {
|
||||
// Silent fail
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
$Flag = Join-Path $HOME ".claude/.ponytail-active"
|
||||
if (-not (Test-Path $Flag)) {
|
||||
exit 0
|
||||
}
|
||||
|
||||
$Mode = ""
|
||||
try {
|
||||
$Mode = (Get-Content $Flag -ErrorAction Stop | Select-Object -First 1).Trim()
|
||||
} catch {
|
||||
exit 0
|
||||
}
|
||||
|
||||
$Esc = [char]27
|
||||
if ([string]::IsNullOrEmpty($Mode) -or $Mode -eq "full") {
|
||||
[Console]::Write("${Esc}[38;5;108m[PONYTAIL]${Esc}[0m")
|
||||
} else {
|
||||
$Suffix = $Mode.ToUpperInvariant()
|
||||
[Console]::Write("${Esc}[38;5;108m[PONYTAIL:$Suffix]${Esc}[0m")
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
flag="$HOME/.claude/.ponytail-active"
|
||||
[ -f "$flag" ] || exit 0
|
||||
|
||||
mode=$(head -n1 "$flag" | tr -d '[:space:]')
|
||||
|
||||
if [ -z "$mode" ] || [ "$mode" = "full" ]; then
|
||||
printf '\033[38;5;108m[PONYTAIL]\033[0m'
|
||||
else
|
||||
printf '\033[38;5;108m[PONYTAIL:%s]\033[0m' "$(printf '%s' "$mode" | tr '[:lower:]' '[:upper:]')"
|
||||
fi
|
||||
Reference in New Issue
Block a user