chill-agent 1.4.0 → 1.5.0

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.
Files changed (67) hide show
  1. package/.agents/rules/ponytail.md +30 -0
  2. package/.claude-plugin/marketplace.json +17 -0
  3. package/.clinerules/ponytail.md +30 -0
  4. package/.cursor/rules/ponytail.mdc +36 -0
  5. package/.grok-plugin/marketplace.json +16 -0
  6. package/.kiro/steering/ponytail.md +35 -0
  7. package/.openclaw/skills/ponytail/SKILL.md +52 -0
  8. package/.openclaw/skills/ponytail-audit/SKILL.md +103 -0
  9. package/.openclaw/skills/ponytail-debt/SKILL.md +44 -0
  10. package/.openclaw/skills/ponytail-gain/SKILL.md +52 -0
  11. package/.openclaw/skills/ponytail-help/SKILL.md +76 -0
  12. package/.openclaw/skills/ponytail-review/SKILL.md +101 -0
  13. package/.opencode/command/ponytail-audit.md +5 -0
  14. package/.opencode/command/ponytail-debt.md +5 -0
  15. package/.opencode/command/ponytail-gain.md +5 -0
  16. package/.opencode/command/ponytail-help.md +5 -0
  17. package/.opencode/command/ponytail-review.md +5 -0
  18. package/.opencode/command/ponytail.md +5 -0
  19. package/.opencode/plugins/index.js +4 -0
  20. package/.opencode/plugins/ponytail-frontmatter.cjs +63 -0
  21. package/.opencode/plugins/ponytail.mjs +206 -0
  22. package/.windsurf/rules/ponytail.md +30 -0
  23. package/AGENTS.md +19 -0
  24. package/__init__.py +228 -0
  25. package/commands/ponytail-audit.toml +2 -0
  26. package/commands/ponytail-debt.toml +2 -0
  27. package/commands/ponytail-gain.toml +2 -0
  28. package/commands/ponytail-help.toml +2 -0
  29. package/commands/ponytail-review.toml +2 -0
  30. package/commands/ponytail.toml +2 -0
  31. package/hooks/chill-statusline.ps1 +1 -1
  32. package/hooks/ponytail-activate.js +201 -0
  33. package/hooks/ponytail-instructions.js +98 -0
  34. package/hooks/ponytail-mode-tracker.js +216 -0
  35. package/hooks/ponytail-runtime.js +182 -0
  36. package/hooks/ponytail-statusline.ps1 +24 -0
  37. package/hooks/ponytail-statusline.sh +18 -0
  38. package/package.json +9 -3
  39. package/pi-extension/index.js +254 -0
  40. package/pi-extension/package.json +8 -0
  41. package/scripts/check-rule-copies.js +74 -0
  42. package/scripts/check-versions.js +77 -0
  43. package/scripts/cursor-hooks.js +145 -0
  44. package/scripts/generate-chillslop.mjs +42 -0
  45. package/scripts/generate-examples.mjs +149 -0
  46. package/scripts/generate-plugin-doors.mjs +108 -0
  47. package/scripts/sync-ponytail.mjs +65 -0
  48. package/scripts/uninstall.js +92 -0
  49. package/skills/ponytail/SKILL.md +52 -0
  50. package/skills/ponytail-audit/SKILL.md +103 -0
  51. package/skills/ponytail-debt/SKILL.md +44 -0
  52. package/skills/ponytail-gain/SKILL.md +52 -0
  53. package/skills/ponytail-help/SKILL.md +76 -0
  54. package/skills/ponytail-review/SKILL.md +101 -0
  55. package/tests/commands.test.js +94 -0
  56. package/tests/copilot-plugin.test.js +35 -0
  57. package/tests/correctness.test.js +245 -0
  58. package/tests/cursor-hooks.test.js +343 -0
  59. package/tests/gemini-extension.test.js +91 -0
  60. package/tests/grok-plugin.test.js +39 -0
  61. package/tests/hermes-plugin.test.js +403 -0
  62. package/tests/hooks.test.js +1005 -0
  63. package/tests/kimi-plugin.test.js +25 -0
  64. package/tests/loc.test.js +18 -0
  65. package/tests/openclaw-skills.test.js +26 -0
  66. package/tests/opencode-plugin.test.js +340 -0
  67. package/tests/qoder-plugin.test.js +84 -0
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env node
2
+ // ponytail — Claude Code SessionStart activation hook (also Codex, Copilot,
3
+ // Grok, CodeBuddy and Cursor sessionStart)
4
+ //
5
+ // Runs on every session start:
6
+ // 1. Writes flag file at $CLAUDE_CONFIG_DIR/.ponytail-active (defaults to ~/.claude; statusline reads this)
7
+ // 2. Emits ponytail ruleset as hidden SessionStart context
8
+ // 3. Detects missing statusline config and emits setup nudge
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const { execFileSync } = require('child_process');
13
+ const { getDefaultMode, getClaudeDir, isShellSafe } = require('./ponytail-config');
14
+ const { getPonytailInstructions } = require('./ponytail-instructions');
15
+ const {
16
+ clearMode,
17
+ cursorRuleNotice,
18
+ cursorRulePath,
19
+ isCodeBuddy,
20
+ isCodex,
21
+ isCopilot,
22
+ isCursor,
23
+ readMode,
24
+ setMode,
25
+ writeHookOutput,
26
+ } = require('./ponytail-runtime');
27
+
28
+ const claudeDir = getClaudeDir();
29
+ const settingsPath = path.join(claudeDir, 'settings.json');
30
+
31
+ function activate(mode) {
32
+ // "off" mode — skip activation entirely, don't write flag or emit rules
33
+ if (mode === 'off') {
34
+ clearMode();
35
+ process.exit(0);
36
+ }
37
+
38
+ // Cursor with the always-on rule in the workspace: the rule already carries the
39
+ // ruleset and would contradict any other level, so leave the flag alone and
40
+ // hand the model a one-line notice instead of a second copy (#817).
41
+ if (isCursor) {
42
+ const rule = cursorRulePath();
43
+ if (rule) {
44
+ try {
45
+ writeHookOutput('SessionStart', mode, cursorRuleNotice(rule));
46
+ } catch (e) {
47
+ // Silent fail — stdout closed/EPIPE at hook exit must not surface as a hook failure
48
+ }
49
+ process.exit(0);
50
+ }
51
+ }
52
+
53
+ // 1. Write flag file
54
+ try {
55
+ setMode(mode);
56
+ } catch (e) {
57
+ // Silent fail -- flag is best-effort, don't block the hook
58
+ }
59
+
60
+ // 2. Emit the ponytail ruleset, filtered to the active intensity level.
61
+ let output = getPonytailInstructions(mode);
62
+
63
+ // 2b. Codebase map: what already exists, so "reuse first" costs no search. Fail open: the map
64
+ // gets 3 s, well inside the 15 s hook limit, so a stalled map never costs the rules (#1079, #1157).
65
+ // shortcut: a map slower than 3 s is still dropped; a cached per-repo map would lift that if it shows up.
66
+ if (mode !== 'review' && process.env.PONYTAIL_MAP !== '0') try {
67
+ const map = execFileSync(process.execPath, [path.join(__dirname, 'ponytail-map.js')], {
68
+ encoding: 'utf8', timeout: 3000, maxBuffer: 64 * 1024, stdio: ['ignore', 'pipe', 'ignore'],
69
+ }).trimEnd();
70
+ if (map) output += '\n\n' + map;
71
+ } catch (e) { /* no map */ }
72
+
73
+ // 3. Detect missing statusline config — nudge Claude to help set it up
74
+ if (!isCodex && !isCopilot && !isCursor && !isCodeBuddy) try {
75
+ const isWindows = process.platform === 'win32';
76
+ let statusCommand = null;
77
+ if (fs.existsSync(settingsPath)) {
78
+ // Strip UTF-8 BOM some editors prepend on Windows (breaks JSON.parse)
79
+ const raw = fs.readFileSync(settingsPath, 'utf8').replace(/^\uFEFF/, '');
80
+ const settings = JSON.parse(raw);
81
+ if (settings.statusLine) {
82
+ statusCommand = String(settings.statusLine.command || '');
83
+ }
84
+ }
85
+
86
+ // A statusLine already set up before #1032 can still run a script from a
87
+ // plugin version that has since been deleted. Only absolute paths are checked,
88
+ // so ~ or $HOME forms are never mistaken for missing files.
89
+ const ref = statusCommand &&
90
+ statusCommand.match(/"([^"]*ponytail-statusline\.(?:sh|ps1))"|(\S*ponytail-statusline\.(?:sh|ps1))/);
91
+ const refPath = ref ? (ref[1] || ref[2]) : null;
92
+ // isShellSafe keeps quotes, newlines and shell metacharacters from
93
+ // settings.json out of the model context.
94
+ // On Windows only drive-letter or UNC paths count: a Git Bash path such as
95
+ // /c/Users/... is absolute to Node but does not resolve, so it would be
96
+ // flagged as broken while it works.
97
+ const checkable = refPath && isShellSafe(refPath) && path.isAbsolute(refPath) &&
98
+ (!isWindows || /^([A-Za-z]:[\\/]|\\\\)/.test(refPath));
99
+ const stalePath = checkable && !fs.existsSync(refPath) ? refPath : null;
100
+
101
+ // The plugin root is a versioned cache dir (.../ponytail/4.12.0/) that Claude
102
+ // Code deletes on update, so a statusLine pointing into it goes blank after the
103
+ // next update (#1032). Point it at a copy in the config dir instead. A statusLine
104
+ // that already runs ponytail keeps its script type, so its copy stays fresh.
105
+ const usePs1 = refPath ? refPath.endsWith('.ps1') : isWindows;
106
+ const scriptName = usePs1 ? 'ponytail-statusline.ps1' : 'ponytail-statusline.sh';
107
+ const scriptPath = path.join(claudeDir, scriptName);
108
+
109
+ // Nudge at most once — the flag file marks that the user has already seen
110
+ // (and implicitly declined) the statusline setup offer. Repeating it every
111
+ // session start turns a helpful hint into a nag. A broken path is nudged once
112
+ // per path: the flag records it.
113
+ const nudgeFlagPath = path.join(claudeDir, '.ponytail-statusline-nudged');
114
+ let nudged = null;
115
+ try { nudged = fs.readFileSync(nudgeFlagPath, 'utf8'); } catch (e) { /* not nudged yet */ }
116
+ const nudge = stalePath ? nudged !== stalePath : statusCommand === null && nudged === null;
117
+
118
+ // Refresh the copy every session so script fixes ship with plugin updates.
119
+ // Copy to a new temp file, then rename: the rename replaces a symlink at
120
+ // scriptPath instead of writing through it, and a concurrent session never
121
+ // runs a half-written script.
122
+ if (nudge || fs.existsSync(scriptPath)) {
123
+ const tmpPath = scriptPath + '.' + process.pid + '.tmp';
124
+ try {
125
+ fs.copyFileSync(path.join(__dirname, scriptName), tmpPath, fs.constants.COPYFILE_EXCL);
126
+ fs.chmodSync(tmpPath, 0o644);
127
+ fs.renameSync(tmpPath, scriptPath);
128
+ } finally {
129
+ try { fs.unlinkSync(tmpPath); } catch (e) { /* renamed */ }
130
+ }
131
+ }
132
+
133
+ if (nudge) {
134
+ try { fs.writeFileSync(nudgeFlagPath, stalePath || ''); } catch (e) { /* best-effort */ }
135
+ if (stalePath) {
136
+ output += "\n\n" +
137
+ "STATUSLINE BROKEN: The statusLine in " + settingsPath + " runs " + stalePath +
138
+ ", which no longer exists (the ponytail plugin was updated and its old version removed), " +
139
+ "so the ponytail badge is blank. Replace that path with " + scriptPath + ", which survives updates, " +
140
+ "quoting it for your shell. Keep the rest of the command. " +
141
+ "Proactively offer to fix this for the user on first interaction.";
142
+ } else if (isShellSafe(scriptPath)) {
143
+ const command = isWindows
144
+ ? `powershell -ExecutionPolicy Bypass -File "${scriptPath}"`
145
+ : `bash "${scriptPath}"`;
146
+ const statusLineSnippet =
147
+ '"statusLine": { "type": "command", "command": ' + JSON.stringify(command) + ' }';
148
+ output += "\n\n" +
149
+ "STATUSLINE SETUP NEEDED: The ponytail plugin includes a statusline badge showing active mode " +
150
+ "(e.g. [PONYTAIL], [PONYTAIL:ULTRA]). It is not configured yet. " +
151
+ "To enable, add this to " + settingsPath + ": " +
152
+ statusLineSnippet + " " +
153
+ "Proactively offer to set this up for the user on first interaction.";
154
+ } else {
155
+ // ponytail: config dir path has shell metacharacters; don't embed it in a
156
+ // command snippet; have the agent wire it up by hand instead.
157
+ output += "\n\n" +
158
+ "STATUSLINE SETUP NEEDED: The ponytail plugin includes a statusline badge showing active mode. " +
159
+ "Its path contains characters unsafe to embed in a shell command, so configure it manually: " +
160
+ "add a statusLine command of type \"command\" that runs " + scriptName +
161
+ " from " + claudeDir + " to " + settingsPath + ", quoting/escaping the path for your shell. " +
162
+ "Proactively offer to set this up for the user on first interaction.";
163
+ }
164
+ }
165
+ } catch (e) {
166
+ // Silent fail — don't block session start over statusline detection
167
+ }
168
+
169
+ try {
170
+ writeHookOutput('SessionStart', mode, output);
171
+ } catch (e) {
172
+ // Silent fail — stdout closed/EPIPE at hook exit must not surface as a hook failure
173
+ }
174
+ }
175
+
176
+ // Compaction re-runs SessionStart inside the same conversation, so it keeps the
177
+ // live level (or stays off after "stop ponytail") instead of resetting to the
178
+ // default. Claude Code and Codex pass the trigger as `source` on stdin; reading
179
+ // it there keeps the hook entry, and the trust Codex gave it, unchanged.
180
+ let input = '';
181
+ let done = false;
182
+
183
+ function finish() {
184
+ if (done) return;
185
+ done = true;
186
+ let source = '';
187
+ try {
188
+ // Strip UTF-8 BOM some shells prepend when piping (breaks JSON.parse)
189
+ source = JSON.parse(input.replace(/^\uFEFF/, '')).source;
190
+ } catch (e) {
191
+ // No payload, or an unparseable one: treat it as a fresh session
192
+ }
193
+ activate(source === 'compact' ? (readMode() || 'off') : getDefaultMode());
194
+ }
195
+
196
+ process.stdin.on('data', chunk => { input += chunk; });
197
+ // Never hang the session start (#443, #790): like the mode tracker, recover on a
198
+ // stdin error or after a short ref'd fallback, and start at the default level.
199
+ process.stdin.on('end', () => { finish(); process.exit(0); });
200
+ process.stdin.on('error', () => { finish(); process.exit(0); });
201
+ setTimeout(() => { finish(); process.exit(0); }, 1000);
@@ -0,0 +1,98 @@
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
+ // Require a quoted value: every worked example is `- lite: "..."`. Without
29
+ // this, an ordinary rule bullet that happens to start with a mode word
30
+ // (e.g. "- Full: ...") is silently dropped in every other mode — it looks
31
+ // like a worked example but is really prose meant to survive verbatim.
32
+ const exampleLabel = line.match(/^-\s*([^:]+):\s*"/);
33
+ if (exampleLabel) {
34
+ const labelMode = normalizeMode(exampleLabel[1].trim());
35
+ if (labelMode) return labelMode === effectiveMode;
36
+ }
37
+
38
+ return true;
39
+ })
40
+ .join('\n');
41
+ }
42
+
43
+ function getFallbackInstructions(mode) {
44
+ // Used only when SKILL.md cannot be read: the same rules as AGENTS.md.
45
+ return 'PONYTAIL MODE ACTIVE — level: ' + mode + '\n\n' +
46
+ 'Switch level: `/ponytail lite|full|ultra`. Off: "stop ponytail" or "normal mode".\n\n' +
47
+ "You are a lazy senior developer. The best code is the code never written. You solve the whole problem with the least new code. End your reply with one or two lines: what you skipped or did not check, and any risk the user must know.\n" +
48
+ "\n" +
49
+ "## Before you write\n" +
50
+ "\n" +
51
+ "Read the task and the code it touches. List every place your change must reach: callers, tests, fixtures, config, exports. Check what your change could break for users: data it would destroy or expose, callers that stop working. That is scope. Extra features are not.\n" +
52
+ "\n" +
53
+ "## The smallest complete change\n" +
54
+ "\n" +
55
+ "Take the first option that fully works:\n" +
56
+ "\n" +
57
+ "1. Does it need to exist? Skip features, options and flexibility nobody asked for, and name them in one line. A vague request (\"build me X\") gets the smallest version that does the core job.\n" +
58
+ "2. Already in this codebase (a helper, component, service, pattern)? Use it the way the surrounding code does.\n" +
59
+ "3. Standard library or a platform feature? Use it, unless the project has its own. A house component beats a native widget.\n" +
60
+ "4. An installed dependency? Use it. Never add a dependency for a few lines.\n" +
61
+ "5. Can it be one line a reader gets at a glance? One line.\n" +
62
+ "6. Otherwise: the minimum code that works.\n" +
63
+ "\n" +
64
+ "- Be lazy about the solution, never about the change itself: finish every part the task needs, including the callers, tests and fixtures your change breaks.\n" +
65
+ "- No abstraction, wrapper, type conversion, option, config, boilerplate or \"for later\" code nobody asked for. Keep values in the form the platform already gives you. Deletion beats addition. Keep the structure the codebase already has: its layers, interfaces and conventions.\n" +
66
+ "- The shortest working diff wins, once you know everything it must touch. A one-liner that needs decoding is not short.\n" +
67
+ "- Comment only the why the code cannot show, in one line.\n" +
68
+ "- Bug fix: before you edit, grep every caller of the function you touch, then fix the root cause once in the shared code.\n" +
69
+ "- Code you move or merge keeps its error handling and validation.\n" +
70
+ "- Between options of equal size, take the one that is correct on edge cases.\n" +
71
+ "- Lazy code without its check is unfinished: new non-trivial logic (a branch, a loop, a parser, money or security, or a whole new script or app) leaves one small test or an assert-based self-check. Trivial changes need none.\n" +
72
+ "- A shortcut with a known limit gets a code comment in this form: `shortcut: <the limit>, <when to upgrade>`.\n" +
73
+ "\n" +
74
+ "Never cut: validation at trust boundaries, error handling that prevents data loss, security, accessibility, the calibration real hardware needs, anything the user asked for.\n";
75
+ }
76
+
77
+ function getPonytailInstructions(mode) {
78
+ const configuredMode = normalizePersistedMode(mode) || DEFAULT_MODE;
79
+
80
+ if (INDEPENDENT_MODES.has(configuredMode)) {
81
+ return 'PONYTAIL MODE ACTIVE — level: ' + configuredMode + '. Behavior defined by /ponytail-' + configuredMode + ' skill.';
82
+ }
83
+
84
+ const effectiveMode = normalizeMode(configuredMode) || DEFAULT_MODE;
85
+
86
+ try {
87
+ return 'PONYTAIL MODE ACTIVE — level: ' + effectiveMode + '\n\n' +
88
+ filterSkillBodyForMode(fs.readFileSync(SKILL_PATH, 'utf8'), effectiveMode);
89
+ } catch (e) {
90
+ return getFallbackInstructions(effectiveMode);
91
+ }
92
+ }
93
+
94
+ module.exports = {
95
+ filterSkillBodyForMode,
96
+ getFallbackInstructions,
97
+ getPonytailInstructions,
98
+ };
@@ -0,0 +1,216 @@
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 fs = require('fs');
6
+ const path = require('path');
7
+ const { spawn } = require('child_process');
8
+ const { getClaudeDir, getDefaultMode, isDeactivationCommand, writeDefaultMode } = require('./ponytail-config');
9
+ const {
10
+ clearMode,
11
+ cursorRuleNotice,
12
+ cursorRulePath,
13
+ isCodeBuddy,
14
+ isCodex,
15
+ isCopilot,
16
+ isCursor,
17
+ isQoder,
18
+ readMode,
19
+ setMode,
20
+ writeHookOutput,
21
+ } = require('./ponytail-runtime');
22
+ const { getPonytailInstructions } = require('./ponytail-instructions');
23
+
24
+ let input = '';
25
+ let done = false;
26
+
27
+ function finish() {
28
+ if (done) return;
29
+ done = true;
30
+ try {
31
+ // Strip UTF-8 BOM some shells prepend when piping (breaks JSON.parse)
32
+ const data = JSON.parse(input.replace(/^\uFEFF/, ''));
33
+ const prompt = (data.prompt || '').trim().toLowerCase();
34
+
35
+ // Cursor with the always-on rule in the workspace: no hook can change or
36
+ // switch off a rule, so answer the command with the notice instead of
37
+ // writing a mode the rule would contradict (#817). Ordinary prompts
38
+ // stay silent as usual.
39
+ if (isCursor && (/^[/@$]ponytail/.test(prompt) || isDeactivationCommand(prompt))) {
40
+ const rule = cursorRulePath();
41
+ if (rule) {
42
+ writeHookOutput('UserPromptSubmit', readMode() || 'off', cursorRuleNotice(rule));
43
+ return;
44
+ }
45
+ }
46
+
47
+ // Match /ponytail commands
48
+ let modeSwitched = false;
49
+ let deactivated = false;
50
+ let defaultNotice = '';
51
+ if (/^[/@$]ponytail/.test(prompt)) {
52
+ const parts = prompt.split(/\s+/);
53
+ const cmd = parts[0].replace(/^[@$]/, '/');
54
+ const arg = parts[1] || '';
55
+
56
+ let mode = null;
57
+ let isReportOnly = false;
58
+
59
+ // /ponytail-review is a one-shot skill, not a session level (#736).
60
+ // Matching it here used to setMode('review'), which latched
61
+ // INDEPENDENT_MODES for the rest of the session.
62
+ if (cmd === '/ponytail' || cmd === '/ponytail:ponytail') {
63
+ // `/ponytail default <mode>` persists the default to config (survives
64
+ // restarts). Plain switches stay session-scoped ("sticks until session
65
+ // end"), so this is the only path that writes config. review is not a
66
+ // valid default (#377), so only off/lite/full/ultra are accepted.
67
+ if (arg === 'default') {
68
+ const dmode = parts[2];
69
+ if (dmode === 'off' || dmode === 'lite' || dmode === 'full' || dmode === 'ultra') {
70
+ writeDefaultMode(dmode);
71
+ defaultNotice = 'PONYTAIL DEFAULT SET — new sessions start in ' + dmode + '.';
72
+ if (!isQoder) writeHookOutput('UserPromptSubmit', dmode, defaultNotice);
73
+ }
74
+ // Qoder still needs this turn's ruleset: the block below folds the
75
+ // notice into it. mode stays null, so the session level is untouched.
76
+ if (!isQoder) return; // don't fall through to the session-mode switch
77
+ }
78
+ // `/ponytail band [on|off]` shows or hides the band above the Claude Code
79
+ // prompt (hooks/band reads this flag). It outlives the session; absent = shown.
80
+ // Other hosts have no band, so there the word stays an unknown argument.
81
+ if (arg === 'band' && !isCopilot && !isCodex && !isQoder && !isCodeBuddy && !isCursor) {
82
+ // `/ponytail band import`: past sessions into the board, in the background, so the prompt
83
+ // is answered right away while the transcripts are read. Detached, it outlives this hook's
84
+ // process.exit below.
85
+ if (parts[2] === 'import') {
86
+ spawn(process.execPath, [path.join(__dirname, 'ponytail-band-import.js')], { detached: true, stdio: 'ignore' });
87
+ writeHookOutput('UserPromptSubmit', readMode() || 'off', 'PONYTAIL BAND IMPORT: past Claude Code sessions (cost, agent time, tokens) are being added to the board in the background. Open the board in a minute. Confirm in one short line.');
88
+ return;
89
+ }
90
+ const flag = path.join(getClaudeDir(), '.ponytail-band');
91
+ let hidden = false;
92
+ try { hidden = fs.readFileSync(flag, 'utf8').trim() === 'off'; } catch (e) {}
93
+ const show = parts[2] === 'on' ? true : parts[2] === 'off' ? false : hidden;
94
+ if (show) {
95
+ try { fs.unlinkSync(flag); } catch (e) {}
96
+ } else {
97
+ fs.mkdirSync(path.dirname(flag), { recursive: true });
98
+ fs.writeFileSync(flag, 'off');
99
+ }
100
+ writeHookOutput('UserPromptSubmit', readMode() || 'off', show
101
+ ? 'PONYTAIL BAND ON: the band shows above the prompt again. The ponytail level is unchanged. Confirm in one short line.'
102
+ : 'PONYTAIL BAND OFF: the band above the prompt is hidden, `/ponytail band` brings it back. The ponytail level is unchanged. Confirm in one short line.');
103
+ return;
104
+ }
105
+ if (arg === 'lite') mode = 'lite';
106
+ else if (arg === 'full') mode = 'full';
107
+ else if (arg === 'ultra') mode = 'ultra';
108
+ else if (arg === 'off') mode = 'off';
109
+ else if (arg === '') {
110
+ // Bare /ponytail switches ponytail on: off → the default level (full if
111
+ // the default is off too); already on → keep the level, report it (#639).
112
+ const live = readMode();
113
+ if (live && live !== 'off') {
114
+ isReportOnly = true;
115
+ mode = live;
116
+ } else {
117
+ mode = getDefaultMode() === 'off' ? 'full' : getDefaultMode();
118
+ }
119
+ }
120
+ }
121
+
122
+ if (isReportOnly) {
123
+ // On Qoder the ruleset block below already reports; a second write
124
+ // here would put two JSON objects on stdout.
125
+ if (!isQoder) {
126
+ writeHookOutput(
127
+ 'UserPromptSubmit',
128
+ mode,
129
+ 'PONYTAIL MODE ACTIVE — level: ' + mode,
130
+ );
131
+ }
132
+ } else if (mode && mode !== 'off') {
133
+ setMode(mode);
134
+ modeSwitched = true;
135
+ // ponytail: Qoder needs the full ruleset every turn, so when a mode
136
+ // switch happens we fold the confirmation into the ruleset output
137
+ // below (one JSON on stdout) instead of emitting two separate writes.
138
+ if (!isQoder) {
139
+ // Cursor (#817) and Codex have no /ponytail command that would load
140
+ // the skill body for the new level, and the SessionStart ruleset is
141
+ // filtered to the start level, so the tracker delivers that level's
142
+ // ruleset along with the confirmation.
143
+ const header = 'PONYTAIL MODE CHANGED — level: ' + mode;
144
+ writeHookOutput(
145
+ 'UserPromptSubmit',
146
+ mode,
147
+ (isCodex || isCursor) ? header + '\n\n' + getPonytailInstructions(mode) : header,
148
+ );
149
+ }
150
+ } else if (mode === 'off') {
151
+ if (isQoder) setMode('off');
152
+ else clearMode();
153
+
154
+ deactivated = true;
155
+ writeHookOutput('UserPromptSubmit', 'off', 'PONYTAIL MODE OFF');
156
+ }
157
+ }
158
+
159
+ // Detect deactivation
160
+ if (!modeSwitched && !deactivated && isDeactivationCommand(prompt)) {
161
+ if (isQoder) setMode('off');
162
+ else clearMode();
163
+
164
+ deactivated = true;
165
+ writeHookOutput('UserPromptSubmit', 'off', 'PONYTAIL MODE OFF');
166
+ }
167
+
168
+ // Qoder has no SessionStart event, so UserPromptSubmit does double duty:
169
+ // activate the default mode on first prompt (if no flag exists yet), then
170
+ // inject the ruleset on every prompt. Claude Code/Codex do this in
171
+ // SessionStart via ponytail-activate.js; Qoder can't, so we do it here.
172
+ // Skip when deactivated — user just turned ponytail off.
173
+ if (isQoder && !deactivated) {
174
+ let currentMode = readMode();
175
+ if (!currentMode) {
176
+ // First prompt in session — initialize from config/env default
177
+ currentMode = getDefaultMode();
178
+ if (currentMode !== 'off') {
179
+ try { setMode(currentMode); } catch (e) {}
180
+ }
181
+ }
182
+ if (currentMode && currentMode !== 'off') {
183
+ // ponytail: one JSON per invocation — mode-switch confirmation is
184
+ // folded into the ruleset header so Qoder gets both in one write.
185
+ const header = (defaultNotice ? defaultNotice + '\n\n' : '') + (modeSwitched
186
+ ? 'PONYTAIL MODE CHANGED — level: ' + currentMode + '\n\n'
187
+ : '');
188
+ writeHookOutput('UserPromptSubmit', currentMode, header + getPonytailInstructions(currentMode));
189
+ } else if (defaultNotice) {
190
+ writeHookOutput('UserPromptSubmit', currentMode, defaultNotice);
191
+ }
192
+ }
193
+ } catch (e) {
194
+ // Silent fail
195
+ }
196
+ }
197
+
198
+ process.stdin.on('data', chunk => { input += chunk; });
199
+ // Exit on 'end', not just finish(): the fallback timer below must stay ref'd
200
+ // (see #790) so it can actually fire when stdin is stuck, and a ref'd timer
201
+ // would otherwise keep the process alive for its full 1000ms on this normal
202
+ // fast path.
203
+ process.stdin.on('end', () => { finish(); process.exit(0); });
204
+
205
+ // Never hang the session. On Windows, Claude Code runs this hook through a
206
+ // PowerShell `if {}` wrapper that can swallow the piped prompt JSON, so stdin
207
+ // 'end' never fires and the hook blocks forever — freezing the session (#443).
208
+ // On error, or after a short fallback, process whatever arrived (recovering the
209
+ // mode if data came without EOF) and exit. The fallback timer MUST stay ref'd:
210
+ // on Windows a stuck ref'd stdin handle keeps the event loop alive, and an
211
+ // unref'd timer competing with it is never scheduled — so the fallback was
212
+ // dead code in exactly the #443/#790 case it exists for, and the hook hung
213
+ // until Claude Code's external 5s watchdog killed it (#790). Mirrors the
214
+ // best-effort, never-block contract the other lifecycle hooks already follow.
215
+ process.stdin.on('error', () => { finish(); process.exit(0); });
216
+ setTimeout(() => { finish(); process.exit(0); }, 1000);