@dietrichgebert/ponytail 4.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/command/ponytail-audit.md +5 -0
- package/.opencode/command/ponytail-debt.md +5 -0
- package/.opencode/command/ponytail-gain.md +5 -0
- package/.opencode/command/ponytail-help.md +5 -0
- package/.opencode/command/ponytail-review.md +5 -0
- package/.opencode/command/ponytail.md +5 -0
- package/.opencode/plugins/ponytail.mjs +100 -0
- package/AGENTS.md +32 -0
- package/LICENSE +21 -0
- package/README.es.md +250 -0
- package/README.md +289 -0
- package/assets/benchmark-3model.svg +21 -0
- package/assets/benchmark-agentic.svg +62 -0
- package/assets/logo-dark.png +0 -0
- package/assets/logo-dark.svg +115 -0
- package/assets/logo.png +0 -0
- package/assets/social-preview.png +0 -0
- package/hooks/claude-codex-hooks.json +31 -0
- package/hooks/copilot-hooks.json +21 -0
- package/hooks/ponytail-activate.js +91 -0
- package/hooks/ponytail-config.js +122 -0
- package/hooks/ponytail-instructions.js +94 -0
- package/hooks/ponytail-mode-tracker.js +55 -0
- package/hooks/ponytail-runtime.js +51 -0
- package/hooks/ponytail-statusline.ps1 +21 -0
- package/hooks/ponytail-statusline.sh +12 -0
- package/package.json +43 -0
- package/pi-extension/index.js +189 -0
- package/pi-extension/package.json +8 -0
- package/pi-extension/test/extension.test.js +167 -0
- package/pi-extension/test/helpers.test.js +92 -0
- package/skills/ponytail/SKILL.md +117 -0
- package/skills/ponytail-audit/SKILL.md +41 -0
- package/skills/ponytail-debt/SKILL.md +44 -0
- package/skills/ponytail-gain/SKILL.md +50 -0
- package/skills/ponytail-help/SKILL.md +69 -0
- package/skills/ponytail-review/SKILL.md +57 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Shared Ponytail instruction builder for Claude hooks and Pi extension.
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { DEFAULT_MODE, normalizeMode, normalizePersistedMode } = require('./ponytail-config');
|
|
7
|
+
|
|
8
|
+
const INDEPENDENT_MODES = new Set(['review']);
|
|
9
|
+
const SKILL_PATH = path.join(__dirname, '..', 'skills', 'ponytail', 'SKILL.md');
|
|
10
|
+
|
|
11
|
+
function filterSkillBodyForMode(body, mode) {
|
|
12
|
+
const effectiveMode = normalizeMode(mode) || DEFAULT_MODE;
|
|
13
|
+
const withoutFrontmatter = String(body || '').replace(/^---[\s\S]*?---\s*/, '');
|
|
14
|
+
|
|
15
|
+
// Only the intensity table rows and worked examples are mode-specific, and
|
|
16
|
+
// both are keyed by a mode name (lite/full/ultra). A bullet whose label is
|
|
17
|
+
// not a mode — e.g. "No unrequested abstractions: ..." — is a normal rule
|
|
18
|
+
// and must be kept verbatim.
|
|
19
|
+
return withoutFrontmatter
|
|
20
|
+
.split(/\r?\n/)
|
|
21
|
+
.filter((line) => {
|
|
22
|
+
const tableLabel = line.match(/^\|\s*\*\*(.+?)\*\*\s*\|/);
|
|
23
|
+
if (tableLabel) {
|
|
24
|
+
const labelMode = normalizeMode(tableLabel[1].trim());
|
|
25
|
+
if (labelMode) return labelMode === effectiveMode;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const exampleLabel = line.match(/^-\s*([^:]+):\s*/);
|
|
29
|
+
if (exampleLabel) {
|
|
30
|
+
const labelMode = normalizeMode(exampleLabel[1].trim());
|
|
31
|
+
if (labelMode) return labelMode === effectiveMode;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
})
|
|
36
|
+
.join('\n');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getFallbackInstructions(mode) {
|
|
40
|
+
return 'PONYTAIL MODE ACTIVE — level: ' + mode + '\n\n' +
|
|
41
|
+
'You are a lazy senior developer. Lazy means efficient, not careless. The best code is the code never written.\n\n' +
|
|
42
|
+
'## Persistence\n\n' +
|
|
43
|
+
'ACTIVE EVERY RESPONSE. No drift back to over-building. Still active if unsure. Off only: "stop ponytail" / "normal mode".\n\n' +
|
|
44
|
+
'Current level: **' + mode + '**. Switch: `/ponytail lite|full|ultra`.\n\n' +
|
|
45
|
+
'## The ladder\n\n' +
|
|
46
|
+
'Before any code, stop at the first rung that holds (the ladder runs after you understand the problem, not instead of it — read the code it touches and trace the real flow first):\n' +
|
|
47
|
+
'1. Does this need to be built at all? (YAGNI)\n' +
|
|
48
|
+
'2. Does it already exist in this codebase? Reuse what is already here, do not re-write it.\n' +
|
|
49
|
+
'3. Does the standard library do this? Use it.\n' +
|
|
50
|
+
'4. Does a native platform feature cover it? Use it.\n' +
|
|
51
|
+
'5. Does an already-installed dependency solve it? Use it.\n' +
|
|
52
|
+
'6. Can this be one line? Make it one line.\n' +
|
|
53
|
+
'7. Only then: write the minimum code that works.\n\n' +
|
|
54
|
+
'Bug fix = root cause, not symptom: grep every caller of the function you touch and fix the shared function once (a smaller diff than one guard per caller); patching only the path the ticket names leaves a sibling caller broken.\n\n' +
|
|
55
|
+
'## Rules\n\n' +
|
|
56
|
+
'No abstractions that were not requested. No avoidable dependencies. No boilerplate nobody asked for. ' +
|
|
57
|
+
'Deletion over addition. Boring over clever. Fewest files possible. ' +
|
|
58
|
+
'Ship the lazy version and question the complex request in the same response — never stall. ' +
|
|
59
|
+
'Between two same-size stdlib options, pick the one correct on edge cases. ' +
|
|
60
|
+
'Mark intentional simplifications with a `ponytail:` comment — a shortcut with a known ceiling names the ceiling and the upgrade path in the comment.\n\n' +
|
|
61
|
+
'## Output\n\n' +
|
|
62
|
+
'Code first. Then at most three short lines: what was skipped, when to add it. ' +
|
|
63
|
+
'If the explanation is longer than the code, delete the explanation. ' +
|
|
64
|
+
'Explanation the user explicitly asked for is not debt, give it in full.\n\n' +
|
|
65
|
+
'## When NOT to be lazy\n\n' +
|
|
66
|
+
'Never simplify away: understanding the problem (read it fully and trace the real flow before picking a rung — a small diff you do not understand is just laziness dressed up as efficiency), input validation at trust boundaries, error handling that prevents data loss, ' +
|
|
67
|
+
'security measures, accessibility basics, the calibration real hardware needs (the platform is never the spec ideal), anything the user explicitly asked to keep. ' +
|
|
68
|
+
'Lazy code without its check is unfinished: non-trivial logic leaves ONE runnable check behind (assert-based demo/self-check or one small test file; no frameworks). Trivial one-liners need no test.\n\n' +
|
|
69
|
+
'## Boundaries\n\n' +
|
|
70
|
+
'Ponytail governs what you build, not how you talk. "stop ponytail" or "normal mode": revert. Level persists until changed or session end.';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getPonytailInstructions(mode) {
|
|
74
|
+
const configuredMode = normalizePersistedMode(mode) || DEFAULT_MODE;
|
|
75
|
+
|
|
76
|
+
if (INDEPENDENT_MODES.has(configuredMode)) {
|
|
77
|
+
return 'PONYTAIL MODE ACTIVE — level: ' + configuredMode + '. Behavior defined by /ponytail-' + configuredMode + ' skill.';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const effectiveMode = normalizeMode(configuredMode) || DEFAULT_MODE;
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
return 'PONYTAIL MODE ACTIVE — level: ' + effectiveMode + '\n\n' +
|
|
84
|
+
filterSkillBodyForMode(fs.readFileSync(SKILL_PATH, 'utf8'), effectiveMode);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return getFallbackInstructions(effectiveMode);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
filterSkillBodyForMode,
|
|
92
|
+
getFallbackInstructions,
|
|
93
|
+
getPonytailInstructions,
|
|
94
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ponytail — UserPromptSubmit hook to track which ponytail mode is active
|
|
3
|
+
// Inspects user input for /ponytail commands and writes mode to flag file
|
|
4
|
+
|
|
5
|
+
const { getDefaultMode, isDeactivationCommand } = require('./ponytail-config');
|
|
6
|
+
const { clearMode, setMode, writeHookOutput } = require('./ponytail-runtime');
|
|
7
|
+
|
|
8
|
+
let input = '';
|
|
9
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
10
|
+
process.stdin.on('end', () => {
|
|
11
|
+
try {
|
|
12
|
+
// Strip UTF-8 BOM some shells prepend when piping (breaks JSON.parse)
|
|
13
|
+
const data = JSON.parse(input.replace(/^\uFEFF/, ''));
|
|
14
|
+
const prompt = (data.prompt || '').trim().toLowerCase();
|
|
15
|
+
|
|
16
|
+
// Match /ponytail commands
|
|
17
|
+
if (/^[/@$]ponytail/.test(prompt)) {
|
|
18
|
+
const parts = prompt.split(/\s+/);
|
|
19
|
+
const cmd = parts[0].replace(/^[@$]/, '/');
|
|
20
|
+
const arg = parts[1] || '';
|
|
21
|
+
|
|
22
|
+
let mode = null;
|
|
23
|
+
|
|
24
|
+
if (cmd === '/ponytail-review' || cmd === '/ponytail:ponytail-review') {
|
|
25
|
+
mode = 'review';
|
|
26
|
+
} else if (cmd === '/ponytail' || cmd === '/ponytail:ponytail') {
|
|
27
|
+
if (arg === 'lite') mode = 'lite';
|
|
28
|
+
else if (arg === 'full') mode = 'full';
|
|
29
|
+
else if (arg === 'ultra') mode = 'ultra';
|
|
30
|
+
else if (arg === 'off') mode = 'off';
|
|
31
|
+
else mode = getDefaultMode();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (mode && mode !== 'off') {
|
|
35
|
+
setMode(mode);
|
|
36
|
+
writeHookOutput(
|
|
37
|
+
'UserPromptSubmit',
|
|
38
|
+
mode,
|
|
39
|
+
'PONYTAIL MODE CHANGED — level: ' + mode,
|
|
40
|
+
);
|
|
41
|
+
} else if (mode === 'off') {
|
|
42
|
+
clearMode();
|
|
43
|
+
writeHookOutput('UserPromptSubmit', 'off', 'PONYTAIL MODE OFF');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Detect deactivation
|
|
48
|
+
if (isDeactivationCommand(prompt)) {
|
|
49
|
+
clearMode();
|
|
50
|
+
writeHookOutput('UserPromptSubmit', 'off', 'PONYTAIL MODE OFF');
|
|
51
|
+
}
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// Silent fail
|
|
54
|
+
}
|
|
55
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { getClaudeDir } = require('./ponytail-config');
|
|
4
|
+
|
|
5
|
+
const STATE_FILE = '.ponytail-active';
|
|
6
|
+
const isCopilot = Boolean(process.env.COPILOT_PLUGIN_DATA);
|
|
7
|
+
const isCodex = !isCopilot && Boolean(process.env.PLUGIN_DATA);
|
|
8
|
+
|
|
9
|
+
let stateDir = getClaudeDir();
|
|
10
|
+
if (isCodex) stateDir = process.env.PLUGIN_DATA;
|
|
11
|
+
if (isCopilot) stateDir = process.env.COPILOT_PLUGIN_DATA;
|
|
12
|
+
|
|
13
|
+
const statePath = path.join(stateDir, STATE_FILE);
|
|
14
|
+
|
|
15
|
+
function setMode(mode) {
|
|
16
|
+
fs.mkdirSync(path.dirname(statePath), { recursive: true });
|
|
17
|
+
fs.writeFileSync(statePath, mode);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function clearMode() {
|
|
21
|
+
try { fs.unlinkSync(statePath); } catch (e) {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function writeHookOutput(event, mode, context = '') {
|
|
25
|
+
if (isCopilot) {
|
|
26
|
+
// Copilot reads additionalContext on SessionStart; ignores output elsewhere.
|
|
27
|
+
process.stdout.write(JSON.stringify(
|
|
28
|
+
event === 'SessionStart' && context ? { additionalContext: context } : {}));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (isCodex) {
|
|
32
|
+
const output = { systemMessage: `PONYTAIL:${mode.toUpperCase()}` };
|
|
33
|
+
if (context) {
|
|
34
|
+
output.hookSpecificOutput = {
|
|
35
|
+
hookEventName: event,
|
|
36
|
+
additionalContext: context,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
process.stdout.write(JSON.stringify(output));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
process.stdout.write(context);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
clearMode,
|
|
47
|
+
isCodex,
|
|
48
|
+
isCopilot,
|
|
49
|
+
setMode,
|
|
50
|
+
writeHookOutput,
|
|
51
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# CLAUDE_CONFIG_DIR overrides ~/.claude, matching where the hooks write the flag (issue #34)
|
|
2
|
+
$ClaudeDir = if ($env:CLAUDE_CONFIG_DIR) { $env:CLAUDE_CONFIG_DIR } else { Join-Path $HOME ".claude" }
|
|
3
|
+
$Flag = Join-Path $ClaudeDir ".ponytail-active"
|
|
4
|
+
if (-not (Test-Path $Flag)) {
|
|
5
|
+
exit 0
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$Mode = ""
|
|
9
|
+
try {
|
|
10
|
+
$Mode = (Get-Content $Flag -ErrorAction Stop | Select-Object -First 1).Trim()
|
|
11
|
+
} catch {
|
|
12
|
+
exit 0
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
$Esc = [char]27
|
|
16
|
+
if ([string]::IsNullOrEmpty($Mode) -or $Mode -eq "full") {
|
|
17
|
+
[Console]::Write("${Esc}[38;5;108m[PONYTAIL]${Esc}[0m")
|
|
18
|
+
} else {
|
|
19
|
+
$Suffix = $Mode.ToUpperInvariant()
|
|
20
|
+
[Console]::Write("${Esc}[38;5;108m[PONYTAIL:$Suffix]${Esc}[0m")
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# CLAUDE_CONFIG_DIR overrides ~/.claude, matching where the hooks write the flag (issue #34)
|
|
3
|
+
flag="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.ponytail-active"
|
|
4
|
+
[ -f "$flag" ] || exit 0
|
|
5
|
+
|
|
6
|
+
mode=$(head -n1 "$flag" | tr -d '[:space:]')
|
|
7
|
+
|
|
8
|
+
if [ -z "$mode" ] || [ "$mode" = "full" ]; then
|
|
9
|
+
printf '\033[38;5;108m[PONYTAIL]\033[0m'
|
|
10
|
+
else
|
|
11
|
+
printf '\033[38;5;108m[PONYTAIL:%s]\033[0m' "$(printf '%s' "$mode" | tr '[:lower:]' '[:upper:]')"
|
|
12
|
+
fi
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dietrichgebert/ponytail",
|
|
3
|
+
"version": "4.8.1",
|
|
4
|
+
"description": "Lazy senior dev mode for AI agents. The best code is the code you never wrote.",
|
|
5
|
+
"keywords": ["opencode-plugin", "opencode", "ponytail", "pi-package", "pi", "skills"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Dietrich Gebert",
|
|
9
|
+
"url": "https://github.com/DietrichGebert"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/DietrichGebert/ponytail",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/DietrichGebert/ponytail.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/DietrichGebert/ponytail/issues"
|
|
18
|
+
},
|
|
19
|
+
"main": "./.opencode/plugins/ponytail.mjs",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./.opencode/plugins/ponytail.mjs",
|
|
22
|
+
"./plugin": "./.opencode/plugins/ponytail.mjs"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"AGENTS.md",
|
|
26
|
+
"hooks/",
|
|
27
|
+
"skills/",
|
|
28
|
+
".opencode/",
|
|
29
|
+
"pi-extension/",
|
|
30
|
+
"assets/",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "node --test tests/*.test.js && npm test --prefix pi-extension"
|
|
35
|
+
},
|
|
36
|
+
"pi": {
|
|
37
|
+
"extensions": ["./pi-extension/index.js"],
|
|
38
|
+
"skills": ["./skills"]
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const {
|
|
5
|
+
DEFAULT_MODE,
|
|
6
|
+
getDefaultMode,
|
|
7
|
+
normalizeMode,
|
|
8
|
+
normalizeConfigMode,
|
|
9
|
+
normalizePersistedMode,
|
|
10
|
+
isDeactivationCommand,
|
|
11
|
+
writeDefaultMode,
|
|
12
|
+
} = require("../hooks/ponytail-config.js");
|
|
13
|
+
const { getPonytailInstructions, filterSkillBodyForMode } = require("../hooks/ponytail-instructions.js");
|
|
14
|
+
|
|
15
|
+
export { filterSkillBodyForMode };
|
|
16
|
+
export const readDefaultMode = getDefaultMode;
|
|
17
|
+
|
|
18
|
+
export function resolveSessionMode(entries, fallbackMode = DEFAULT_MODE) {
|
|
19
|
+
const fallback = normalizePersistedMode(fallbackMode) || DEFAULT_MODE;
|
|
20
|
+
if (!Array.isArray(entries)) return fallback;
|
|
21
|
+
|
|
22
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
23
|
+
const entry = entries[i];
|
|
24
|
+
if (entry?.type !== "custom" || entry?.customType !== "ponytail-mode") continue;
|
|
25
|
+
|
|
26
|
+
const mode = normalizePersistedMode(entry?.data?.mode);
|
|
27
|
+
if (mode) return mode;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return fallback;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function parsePonytailCommand(text, defaultMode = DEFAULT_MODE) {
|
|
34
|
+
const fallback = normalizePersistedMode(defaultMode) || DEFAULT_MODE;
|
|
35
|
+
const normalizedText = String(text || "").trim().toLowerCase();
|
|
36
|
+
|
|
37
|
+
if (!normalizedText) {
|
|
38
|
+
return { type: "set-mode", mode: fallback === "off" ? "full" : fallback };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const [primary, secondary] = normalizedText.split(/\s+/);
|
|
42
|
+
|
|
43
|
+
if (primary === "status") return { type: "status" };
|
|
44
|
+
|
|
45
|
+
if (primary === "default") {
|
|
46
|
+
const mode = normalizeConfigMode(secondary);
|
|
47
|
+
return mode ? { type: "set-default", mode } : { type: "invalid", reason: "invalid-default-mode" };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const mode = normalizeMode(primary);
|
|
51
|
+
return mode ? { type: "set-mode", mode } : { type: "invalid", reason: "invalid-mode", mode: primary };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { writeDefaultMode };
|
|
55
|
+
|
|
56
|
+
export default function ponytailExtension(pi) {
|
|
57
|
+
let currentMode = DEFAULT_MODE;
|
|
58
|
+
let configuredDefaultMode = getDefaultMode();
|
|
59
|
+
let isActive = false;
|
|
60
|
+
let lastCtx = null;
|
|
61
|
+
|
|
62
|
+
// -- Status bar --
|
|
63
|
+
function syncStatus(ctx) {
|
|
64
|
+
if (ctx) lastCtx = ctx;
|
|
65
|
+
const c = ctx || lastCtx;
|
|
66
|
+
if (!c?.ui?.setStatus || !c.ui.theme?.fg) return;
|
|
67
|
+
const theme = c.ui.theme;
|
|
68
|
+
if (currentMode === "off") {
|
|
69
|
+
c.ui.setStatus("ponytail", "");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const levelIcons = { lite: "🌿", full: "⚡", ultra: "🔥" };
|
|
73
|
+
const icon = levelIcons[currentMode] || "";
|
|
74
|
+
const label = currentMode.toUpperCase();
|
|
75
|
+
const indicator = isActive ? theme.fg("accent", "●") : theme.fg("dim", "○");
|
|
76
|
+
c.ui.setStatus("ponytail", indicator + " 🐴 " + theme.fg("muted", "ponytail: ") + theme.fg("text", icon + " " + label));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const setMode = (mode, ctx) => {
|
|
80
|
+
const normalized = normalizePersistedMode(mode);
|
|
81
|
+
if (!normalized) return;
|
|
82
|
+
|
|
83
|
+
currentMode = normalized;
|
|
84
|
+
pi.appendEntry("ponytail-mode", { mode: normalized });
|
|
85
|
+
syncStatus(ctx);
|
|
86
|
+
ctx?.ui?.notify?.(`Ponytail mode set to ${normalized}.`, "info");
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const sendAlias = (skillName, args, ctx) => {
|
|
90
|
+
const normalized = String(args || "").trim();
|
|
91
|
+
const message = normalized ? `${skillName} ${normalized}` : skillName;
|
|
92
|
+
|
|
93
|
+
if (ctx?.isIdle?.() === false) {
|
|
94
|
+
pi.sendUserMessage(message, { deliverAs: "followUp" });
|
|
95
|
+
ctx?.ui?.notify?.(`${skillName} queued as follow-up.`, "info");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
pi.sendUserMessage(message);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
pi.registerCommand("ponytail", {
|
|
103
|
+
description: "Set or report Ponytail mode",
|
|
104
|
+
handler: async (args, ctx) => {
|
|
105
|
+
const parsed = parsePonytailCommand(args, configuredDefaultMode);
|
|
106
|
+
|
|
107
|
+
if (parsed.type === "status") {
|
|
108
|
+
ctx?.ui?.notify?.(`Ponytail: current ${currentMode} • default ${configuredDefaultMode}`, "info");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (parsed.type === "set-default") {
|
|
113
|
+
const written = writeDefaultMode(parsed.mode);
|
|
114
|
+
if (written) {
|
|
115
|
+
configuredDefaultMode = getDefaultMode();
|
|
116
|
+
const message = configuredDefaultMode === written
|
|
117
|
+
? `Default Ponytail mode set to ${written}.`
|
|
118
|
+
: `Saved default ${written}, but env override keeps default at ${configuredDefaultMode}.`;
|
|
119
|
+
ctx?.ui?.notify?.(message, "info");
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (parsed.type === "set-mode") {
|
|
125
|
+
setMode(parsed.mode, ctx);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
ctx?.ui?.notify?.("Unknown or unsupported /ponytail mode.", "warning");
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
pi.registerCommand("ponytail-review", {
|
|
134
|
+
description: "Run /skill:ponytail-review",
|
|
135
|
+
handler: (_args, ctx) => sendAlias("/skill:ponytail-review", "", ctx),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
pi.registerCommand("ponytail-audit", {
|
|
139
|
+
description: "Run /skill:ponytail-audit",
|
|
140
|
+
handler: (_args, ctx) => sendAlias("/skill:ponytail-audit", "", ctx),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
pi.registerCommand("ponytail-gain", {
|
|
144
|
+
description: "Run /skill:ponytail-gain",
|
|
145
|
+
handler: (_args, ctx) => sendAlias("/skill:ponytail-gain", "", ctx),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
pi.registerCommand("ponytail-debt", {
|
|
149
|
+
description: "Run /skill:ponytail-debt",
|
|
150
|
+
handler: (_args, ctx) => sendAlias("/skill:ponytail-debt", "", ctx),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
pi.registerCommand("ponytail-help", {
|
|
154
|
+
description: "Run /skill:ponytail-help",
|
|
155
|
+
handler: (_args, ctx) => sendAlias("/skill:ponytail-help", "", ctx),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
pi.on("input", async (event) => {
|
|
159
|
+
if (event?.source === "extension") return;
|
|
160
|
+
|
|
161
|
+
const text = String(event?.text || "");
|
|
162
|
+
if (currentMode !== "off" && isDeactivationCommand(text)) {
|
|
163
|
+
setMode("off");
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
168
|
+
const entries = ctx?.sessionManager?.getBranch?.() || ctx?.sessionManager?.getEntries?.() || [];
|
|
169
|
+
configuredDefaultMode = getDefaultMode();
|
|
170
|
+
currentMode = resolveSessionMode(entries, configuredDefaultMode);
|
|
171
|
+
syncStatus(ctx);
|
|
172
|
+
ctx?.ui?.notify?.(`Ponytail loaded: ${currentMode}`, "info");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
pi.on("agent_start", async (_event, ctx) => {
|
|
176
|
+
isActive = true;
|
|
177
|
+
syncStatus(ctx);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
pi.on("agent_end", async (_event, ctx) => {
|
|
181
|
+
isActive = false;
|
|
182
|
+
syncStatus(ctx);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
pi.on("before_agent_start", async (event) => {
|
|
186
|
+
if (!currentMode || currentMode === "off") return;
|
|
187
|
+
return { systemPrompt: `${event.systemPrompt}\n\n${getPonytailInstructions(currentMode)}` };
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
|
|
7
|
+
import ponytailExtension from "../index.js";
|
|
8
|
+
|
|
9
|
+
function createPiHarness() {
|
|
10
|
+
const events = new Map();
|
|
11
|
+
const commands = new Map();
|
|
12
|
+
const appendedEntries = [];
|
|
13
|
+
const sentUserMessages = [];
|
|
14
|
+
|
|
15
|
+
const pi = {
|
|
16
|
+
on(eventName, handler) {
|
|
17
|
+
events.set(eventName, handler);
|
|
18
|
+
},
|
|
19
|
+
registerCommand(name, options) {
|
|
20
|
+
commands.set(name, options);
|
|
21
|
+
},
|
|
22
|
+
appendEntry(customType, data) {
|
|
23
|
+
appendedEntries.push({ customType, data });
|
|
24
|
+
},
|
|
25
|
+
sendUserMessage(text, options) {
|
|
26
|
+
sentUserMessages.push({ text, options });
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
ponytailExtension(pi);
|
|
31
|
+
return { events, commands, appendedEntries, sentUserMessages };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function createCommandContext(overrides = {}) {
|
|
35
|
+
return {
|
|
36
|
+
isIdle: () => true,
|
|
37
|
+
sessionManager: { getEntries: () => [] },
|
|
38
|
+
ui: { notify() {} },
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function withTempConfig(fn) {
|
|
44
|
+
const tempConfigHome = mkdtempSync(join(tmpdir(), "ponytail-test-"));
|
|
45
|
+
const previousXdg = process.env.XDG_CONFIG_HOME;
|
|
46
|
+
process.env.XDG_CONFIG_HOME = tempConfigHome;
|
|
47
|
+
|
|
48
|
+
return Promise.resolve()
|
|
49
|
+
.then(fn)
|
|
50
|
+
.finally(() => {
|
|
51
|
+
if (previousXdg === undefined) delete process.env.XDG_CONFIG_HOME;
|
|
52
|
+
else process.env.XDG_CONFIG_HOME = previousXdg;
|
|
53
|
+
rmSync(tempConfigHome, { recursive: true, force: true });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
test("extension registers Ponytail commands", () => {
|
|
58
|
+
const { commands } = createPiHarness();
|
|
59
|
+
|
|
60
|
+
assert.deepEqual([...commands.keys()].sort(), ["ponytail", "ponytail-audit", "ponytail-debt", "ponytail-gain", "ponytail-help", "ponytail-review"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("/ponytail updates session mode and injects instructions", async () => withTempConfig(async () => {
|
|
64
|
+
const { commands, events, appendedEntries } = createPiHarness();
|
|
65
|
+
const ctx = createCommandContext();
|
|
66
|
+
|
|
67
|
+
await events.get("session_start")({ reason: "startup" }, ctx);
|
|
68
|
+
await commands.get("ponytail").handler("ultra", ctx);
|
|
69
|
+
|
|
70
|
+
assert.deepEqual(appendedEntries.at(-1), {
|
|
71
|
+
customType: "ponytail-mode",
|
|
72
|
+
data: { mode: "ultra" },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
|
|
76
|
+
assert.ok(result.systemPrompt.includes("PONYTAIL MODE ACTIVE"));
|
|
77
|
+
assert.ok(result.systemPrompt.includes("ultra"));
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
test("session_start restores latest persisted mode", async () => withTempConfig(async () => {
|
|
81
|
+
const { events } = createPiHarness();
|
|
82
|
+
const ctx = createCommandContext({
|
|
83
|
+
sessionManager: {
|
|
84
|
+
getEntries: () => [
|
|
85
|
+
{ type: "custom", customType: "ponytail-mode", data: { mode: "lite" } },
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await events.get("session_start")({ reason: "resume" }, ctx);
|
|
91
|
+
const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
|
|
92
|
+
|
|
93
|
+
assert.ok(result.systemPrompt.includes("lite"));
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
test("skill alias commands delegate to Pi skill commands", async () => {
|
|
97
|
+
const { commands, sentUserMessages } = createPiHarness();
|
|
98
|
+
const ctx = createCommandContext();
|
|
99
|
+
|
|
100
|
+
await commands.get("ponytail-review").handler("", ctx);
|
|
101
|
+
await commands.get("ponytail-audit").handler("", ctx);
|
|
102
|
+
await commands.get("ponytail-debt").handler("", ctx);
|
|
103
|
+
await commands.get("ponytail-gain").handler("", ctx);
|
|
104
|
+
await commands.get("ponytail-help").handler("", ctx);
|
|
105
|
+
|
|
106
|
+
assert.deepEqual(sentUserMessages.map((entry) => entry.text), [
|
|
107
|
+
"/skill:ponytail-review",
|
|
108
|
+
"/skill:ponytail-audit",
|
|
109
|
+
"/skill:ponytail-debt",
|
|
110
|
+
"/skill:ponytail-gain",
|
|
111
|
+
"/skill:ponytail-help",
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("normal mode disables persistent instructions", async () => withTempConfig(async () => {
|
|
116
|
+
const { commands, events } = createPiHarness();
|
|
117
|
+
const ctx = createCommandContext();
|
|
118
|
+
|
|
119
|
+
await events.get("session_start")({ reason: "startup" }, ctx);
|
|
120
|
+
await commands.get("ponytail").handler("ultra", ctx);
|
|
121
|
+
await events.get("input")({ text: "normal mode", source: "interactive" }, ctx);
|
|
122
|
+
|
|
123
|
+
const disabled = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
|
|
124
|
+
assert.equal(disabled, undefined);
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
test("a request mentioning normal mode stays active", async () => withTempConfig(async () => {
|
|
128
|
+
const { commands, events } = createPiHarness();
|
|
129
|
+
const ctx = createCommandContext();
|
|
130
|
+
|
|
131
|
+
await events.get("session_start")({ reason: "startup" }, ctx);
|
|
132
|
+
await commands.get("ponytail").handler("ultra", ctx);
|
|
133
|
+
await events.get("input")({ text: "add a normal mode toggle next to dark mode", source: "interactive" }, ctx);
|
|
134
|
+
|
|
135
|
+
const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
|
|
136
|
+
assert.match(result.systemPrompt, /PONYTAIL MODE ACTIVE/);
|
|
137
|
+
}));
|
|
138
|
+
|
|
139
|
+
test("status bar renders the mode and flips active on agent_start", async () => withTempConfig(async () => {
|
|
140
|
+
const { events } = createPiHarness();
|
|
141
|
+
const statusWrites = [];
|
|
142
|
+
const ctx = createCommandContext({
|
|
143
|
+
sessionManager: { getEntries: () => [{ type: "custom", customType: "ponytail-mode", data: { mode: "ultra" } }] },
|
|
144
|
+
ui: { notify() {}, setStatus: (key, text) => statusWrites.push({ key, text }), theme: { fg: (_color, text) => text } },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
await events.get("session_start")({ reason: "resume" }, ctx);
|
|
148
|
+
await events.get("agent_start")({}, ctx);
|
|
149
|
+
|
|
150
|
+
assert.equal(statusWrites.at(-2).key, "ponytail");
|
|
151
|
+
assert.match(statusWrites.at(-2).text, /○.*ULTRA/);
|
|
152
|
+
assert.match(statusWrites.at(-1).text, /●.*ULTRA/);
|
|
153
|
+
}));
|
|
154
|
+
|
|
155
|
+
test("status bar stays silent when ui lacks a theme", async () => withTempConfig(async () => {
|
|
156
|
+
const { events } = createPiHarness();
|
|
157
|
+
const calls = [];
|
|
158
|
+
const ctx = createCommandContext({
|
|
159
|
+
sessionManager: { getEntries: () => [{ type: "custom", customType: "ponytail-mode", data: { mode: "ultra" } }] },
|
|
160
|
+
ui: { notify() {}, setStatus: (_key, text) => calls.push(text) }, // setStatus present, theme absent
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
await events.get("session_start")({ reason: "resume" }, ctx);
|
|
164
|
+
await events.get("agent_start")({}, ctx);
|
|
165
|
+
|
|
166
|
+
assert.deepEqual(calls, []);
|
|
167
|
+
}));
|