chill-agent 1.4.0 → 1.6.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.
- package/.agents/rules/ponytail.md +30 -0
- package/.claude-plugin/contrast-mcp-launcher.mjs +31 -0
- package/.claude-plugin/marketplace.json +17 -0
- package/.claude-plugin/plugin.json +8 -3
- package/.cline-plugin/plugin.js +6 -0
- package/.clinerules/ponytail.md +30 -0
- package/.codex-plugin/plugin.json +4 -3
- package/.cursor/rules/ponytail.mdc +36 -0
- package/.cursor-plugin/marketplace.json +16 -0
- package/.cursor-plugin/plugin.json +2 -2
- package/.devin-plugin/plugin.json +2 -2
- package/.grok-plugin/marketplace.json +16 -0
- package/.kimi-plugin/plugin.json +11 -29
- package/.kiro/steering/ponytail.md +35 -0
- package/.omp-plugin/marketplace.json +15 -0
- package/.openclaw/skills/ponytail/SKILL.md +47 -0
- package/.openclaw/skills/ponytail-audit/SKILL.md +100 -0
- package/.openclaw/skills/ponytail-debt/SKILL.md +43 -0
- package/.openclaw/skills/ponytail-gain/SKILL.md +51 -0
- package/.openclaw/skills/ponytail-help/SKILL.md +76 -0
- package/.openclaw/skills/ponytail-review/SKILL.md +98 -0
- 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/index.js +4 -0
- package/.opencode/plugins/ponytail-frontmatter.cjs +63 -0
- package/.opencode/plugins/ponytail.mjs +206 -0
- package/.qoder-plugin/plugin.json +12 -26
- package/.windsurf/rules/ponytail.md +30 -0
- package/AGENTS.md +32 -0
- package/__init__.py +228 -0
- package/assets/antislop-banner.png +0 -0
- package/assets/band/band.png +0 -0
- package/assets/band/board.png +0 -0
- package/assets/benchmark-3model.svg +21 -0
- package/assets/benchmark-agentic.svg +62 -0
- package/assets/codex-icon.png +0 -0
- package/assets/compare/code/after.webp +0 -0
- package/assets/compare/code/before.webp +0 -0
- package/assets/compare/text/after.webp +0 -0
- package/assets/compare/text/before.webp +0 -0
- package/assets/compare/ui/w-all.webp +0 -0
- package/assets/compare/ui/w-antislop.webp +0 -0
- package/assets/compare/ui/w-design.webp +0 -0
- package/assets/compare/ui/without.webp +0 -0
- package/assets/logo-dark.png +0 -0
- package/assets/logo-dark.svg +115 -0
- package/assets/logo-greenpt-dark.svg +27 -0
- package/assets/logo-greenpt.svg +27 -0
- package/assets/logo.png +0 -0
- package/assets/photoreunion-logo-dark.svg +4 -0
- package/assets/photoreunion-logo-light.svg +4 -0
- package/assets/profile.png +0 -0
- package/assets/retriever-logo-dark.svg +4 -0
- package/assets/retriever-logo-light.svg +4 -0
- package/assets/stories-banner.png +0 -0
- package/assets/v5/audit-es.png +0 -0
- package/assets/v5/audit-ja.png +0 -0
- package/assets/v5/audit-ko.png +0 -0
- package/assets/v5/audit-zh-CN.png +0 -0
- package/assets/v5/audit.png +0 -0
- package/assets/v5/beforeafter-es.png +0 -0
- package/assets/v5/beforeafter-ja.png +0 -0
- package/assets/v5/beforeafter-ko.png +0 -0
- package/assets/v5/beforeafter-zh-CN.png +0 -0
- package/assets/v5/beforeafter.png +0 -0
- package/assets/v5/chart-es.png +0 -0
- package/assets/v5/chart-ja.png +0 -0
- package/assets/v5/chart-ko.png +0 -0
- package/assets/v5/chart-zh-CN.png +0 -0
- package/assets/v5/chart.png +0 -0
- package/assets/v5/hero-es.jpg +0 -0
- package/assets/v5/hero-ja.jpg +0 -0
- package/assets/v5/hero-ko.jpg +0 -0
- package/assets/v5/hero-zh-CN.jpg +0 -0
- package/assets/v5/hero.jpg +0 -0
- package/assets/v5/ladder-es.png +0 -0
- package/assets/v5/ladder-ja.png +0 -0
- package/assets/v5/ladder-ko.png +0 -0
- package/assets/v5/ladder-zh-CN.png +0 -0
- package/assets/v5/ladder.png +0 -0
- package/assets/v5/review-es.png +0 -0
- package/assets/v5/review-ja.png +0 -0
- package/assets/v5/review-ko.png +0 -0
- package/assets/v5/review-zh-CN.png +0 -0
- package/assets/v5/review.png +0 -0
- package/assets/v5/tests-es.png +0 -0
- package/assets/v5/tests-ja.png +0 -0
- package/assets/v5/tests-ko.png +0 -0
- package/assets/v5/tests-zh-CN.png +0 -0
- package/assets/v5/tests.png +0 -0
- package/assets/waitlist-banner-es.png +0 -0
- package/assets/waitlist-banner-ja.png +0 -0
- package/assets/waitlist-banner-ko.png +0 -0
- package/assets/waitlist-banner-zh-CN.png +0 -0
- package/assets/waitlist-banner.png +0 -0
- package/benchmarks/.env.example +2 -0
- package/benchmarks/agentic/README.md +201 -0
- package/benchmarks/agentic/answer.py +288 -0
- package/benchmarks/agentic/compare.py +93 -0
- package/benchmarks/agentic/complete.py +178 -0
- package/benchmarks/agentic/judge.py +198 -0
- package/benchmarks/agentic/run.py +543 -0
- package/benchmarks/agentic/tasks.py +1544 -0
- package/benchmarks/arms/baseline.js +2 -0
- package/benchmarks/arms/caveman-SKILL.md +67 -0
- package/benchmarks/arms/caveman.js +8 -0
- package/benchmarks/arms/ponytail.js +8 -0
- package/benchmarks/behavior.js +54 -0
- package/benchmarks/behavior.yaml +40 -0
- package/benchmarks/correctness.js +291 -0
- package/benchmarks/loc.js +17 -19
- package/benchmarks/promptfooconfig.gemini.yaml +32 -0
- package/benchmarks/promptfooconfig.gpt-newest.yaml +33 -0
- package/benchmarks/promptfooconfig.yaml +41 -0
- package/benchmarks/results/2026-06-12-caveman-vs-ponytail.md +71 -0
- package/benchmarks/results/2026-06-12-v4-hardening-vs-caveman.md +125 -0
- package/benchmarks/results/2026-06-15-llama3.2-local.md +82 -0
- package/benchmarks/results/2026-06-16-correctness-gate-fix.md +113 -0
- package/benchmarks/results/2026-06-16-robustness-audit.md +135 -0
- package/benchmarks/results/2026-06-17-agentic-safety.md +164 -0
- package/benchmarks/results/2026-06-17-cost-verification.md +93 -0
- package/benchmarks/results/2026-06-18-agentic.md +219 -0
- package/benchmarks/results/2026-06-22-issue-245-217-comprehension.md +98 -0
- package/benchmarks/results/2026-10-07-agentic.md +186 -0
- package/cli/index.mjs +241 -0
- package/cli/lib/banner.mjs +21 -0
- package/cli/lib/install.mjs +498 -0
- package/cli/lib/settings.mjs +48 -0
- package/cli/package-lock.json +87 -0
- package/cli/package.json +42 -0
- package/cli/scripts/smoke-test.mjs +95 -0
- package/cli/scripts/smoke-worker.mjs +411 -0
- package/cli/scripts/sync-skills.mjs +81 -0
- package/commands/ponytail-audit.toml +2 -0
- package/commands/ponytail-debt.toml +2 -0
- package/commands/ponytail-gain.toml +2 -0
- package/commands/ponytail-help.toml +2 -0
- package/commands/ponytail-review.toml +2 -0
- package/commands/ponytail.toml +2 -0
- package/examples/email-validation.md +156 -0
- package/examples/group-by.md +35 -0
- package/examples/infinite-scroll.md +58 -0
- package/examples/number-formatting.md +37 -0
- package/examples/rate-limit.md +272 -0
- package/examples/react-countdown.md +390 -0
- package/examples/url-params.md +41 -0
- package/gemini-extension.json +2 -2
- package/hooks/band/board.ts +560 -0
- package/hooks/band/logo.ts +3 -0
- package/hooks/band/metrics.ts +311 -0
- package/hooks/band/register.tsx +495 -0
- package/hooks/band/types.d.ts +34 -0
- package/hooks/chill-statusline.ps1 +1 -1
- package/hooks/claude-band.json +6 -0
- package/hooks/claude-codex-hooks.json +34 -4
- package/hooks/copilot-hooks.json +12 -2
- package/hooks/cursor-hooks.json +2 -2
- package/hooks/ponytail-activate.js +201 -0
- package/hooks/ponytail-band-import.js +274 -0
- package/hooks/ponytail-config.js +175 -0
- package/hooks/ponytail-instructions.js +98 -0
- package/hooks/ponytail-map.js +111 -0
- package/hooks/ponytail-mode-tracker.js +216 -0
- package/hooks/ponytail-runtime.js +182 -0
- package/hooks/ponytail-statusline.ps1 +24 -0
- package/hooks/ponytail-statusline.sh +18 -0
- package/hooks/ponytail-subagent.js +94 -0
- package/hooks/qoder-hooks.json +19 -4
- package/i18n/README.ko.md +230 -0
- package/package.json +17 -6
- package/pi-extension/index.js +254 -0
- package/pi-extension/package.json +8 -0
- package/pi-extension/test/extension.test.js +367 -0
- package/pi-extension/test/helpers.test.js +179 -0
- package/plugin.yaml +21 -12
- package/rules/antislop.mdc +18 -0
- package/scripts/build-openclaw-skills.js +60 -0
- package/scripts/check-repo.mjs +389 -0
- package/scripts/check-rule-copies.js +74 -0
- package/scripts/check-versions.js +77 -0
- package/scripts/cursor-hooks.js +145 -0
- package/scripts/generate-chillslop.mjs +42 -0
- package/scripts/generate-examples.mjs +149 -0
- package/scripts/generate-plugin-doors.mjs +108 -0
- package/scripts/publish-openclaw-skills.js +75 -0
- package/scripts/skill-index.mjs +81 -0
- package/scripts/sync-ponytail.mjs +65 -0
- package/scripts/uninstall.js +92 -0
- package/skills/antislop/SKILL.md +700 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-copywriting/SKILL.md +407 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +121 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +344 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/plugin.json +5 -0
- package/skills/ponytail/SKILL.md +52 -0
- package/skills/ponytail-audit/SKILL.md +103 -0
- package/skills/ponytail-debt/SKILL.md +44 -0
- package/skills/ponytail-gain/SKILL.md +52 -0
- package/skills/ponytail-help/SKILL.md +76 -0
- package/skills/ponytail-review/SKILL.md +101 -0
- package/src/package.json +3 -0
- package/tests/activation-map.test.js +63 -0
- package/tests/band-import.test.js +111 -0
- package/tests/band.test.tsx +520 -0
- package/tests/behavior.test.js +80 -0
- package/tests/commands.test.js +94 -0
- package/tests/copilot-plugin.test.js +35 -0
- package/tests/correctness.test.js +245 -0
- package/tests/cursor-hooks.test.js +343 -0
- package/tests/gemini-extension.test.js +91 -0
- package/tests/grok-plugin.test.js +39 -0
- package/tests/hermes-plugin.test.js +403 -0
- package/tests/hooks-windows.test.js +205 -0
- package/tests/hooks.test.js +1005 -0
- package/tests/kimi-plugin.test.js +25 -0
- package/tests/loc.test.js +18 -0
- package/tests/map.test.js +30 -0
- package/tests/openclaw-skills.test.js +26 -0
- package/tests/opencode-plugin.test.js +340 -0
- package/tests/package-scripts.test.js +35 -0
- package/tests/package.test.js +23 -0
- package/tests/qoder-plugin.test.js +84 -0
- package/tests/uninstall.test.js +202 -0
- /package/bin/{chill-agent.js → chill-agent.mjs} +0 -0
- /package/tests/{manifests.test.js → manifests.test.mjs} +0 -0
- /package/tests/{rules.test.js → rules.test.mjs} +0 -0
|
@@ -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,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ponytail — codebase map: what already exists, so "reuse first" costs no search.
|
|
3
|
+
//
|
|
4
|
+
// Lists the top-level functions, classes and exports of the project's source files, one line
|
|
5
|
+
// per folder, inside a character budget. No model, no dependencies: `git ls-files` (or a short
|
|
6
|
+
// directory walk) plus a regex per language. Tests, generated and vendored files are skipped;
|
|
7
|
+
// shared code (utils, lib, services, components, hooks) is listed first when the budget is tight.
|
|
8
|
+
//
|
|
9
|
+
// ponytail: regex, not a parser. Misses nested or dynamic definitions; a tree-sitter index is the
|
|
10
|
+
// upgrade if the map ever needs to be exact.
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const { execFileSync } = require('child_process');
|
|
15
|
+
|
|
16
|
+
const BUDGET = Number(process.env.PONYTAIL_MAP_CHARS || 2000);
|
|
17
|
+
const MAX_FILES = 4000;
|
|
18
|
+
const SRC = /\.(py|js|jsx|mjs|cjs|ts|tsx|go|rs|rb|java|kt|php|swift|cs)$/;
|
|
19
|
+
const SKIP_DIR = /(^|\/)(node_modules|\.git|dist|build|out|vendor|venv|\.venv|__pycache__|coverage|\.next|target|migrations|versions|fixtures|tests?|__tests__|spec)(\/|$)/;
|
|
20
|
+
const SKIP_FILE = /(^|\/)(test_[^/]*|[^/]*(_test|\.test|\.spec|\.gen|\.min|\.d)\.[a-z]+)$/;
|
|
21
|
+
const NAME = /^(?:type\s+)?(?:[\w$]+\s+as\s+)?([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)?)$/;
|
|
22
|
+
const SAFE_PATH = /^[\w.@+$()[\]\/-]+$/;
|
|
23
|
+
const SHARED = /(util|helper|lib|common|shared|service|component|hook|core|model|schema|api)/i;
|
|
24
|
+
|
|
25
|
+
const PATTERNS = {
|
|
26
|
+
py: [/^(?:async\s+)?def\s+([A-Za-z]\w*)/gm, /^class\s+([A-Za-z]\w*)/gm],
|
|
27
|
+
js: [/^export\s+(?:default\s+)?(?:async\s+)?(?:function\*?|class|const|let|var|interface|type|enum)\s+([A-Za-z_$][\w$]*)/gm,
|
|
28
|
+
/^export\s*\{([^}]*)\}/gm],
|
|
29
|
+
go: [/^func\s+(?:\([^)]*\)\s*)?([A-Z]\w*)/gm, /^type\s+([A-Z]\w*)/gm],
|
|
30
|
+
rs: [/^pub\s+(?:async\s+)?(?:fn|struct|enum|trait|type)\s+(\w+)/gm],
|
|
31
|
+
rb: [/^\s*(?:def|class|module)\s+([A-Za-z][\w.]*)/gm],
|
|
32
|
+
jvm: [/^\s*(?:public\s+)?(?:static\s+)?(?:final\s+)?(?:class|interface|enum|record)\s+(\w+)/gm],
|
|
33
|
+
};
|
|
34
|
+
const LANG = { py: 'py', js: 'js', jsx: 'js', mjs: 'js', cjs: 'js', ts: 'js', tsx: 'js', go: 'go', rs: 'rs',
|
|
35
|
+
rb: 'rb', java: 'jvm', kt: 'jvm', swift: 'jvm', cs: 'jvm', php: 'jvm' };
|
|
36
|
+
|
|
37
|
+
function listFiles(root) {
|
|
38
|
+
try {
|
|
39
|
+
// 64 MiB: in repos with many tracked files `git ls-files` overflows Node's 1 MiB
|
|
40
|
+
// default, and the catch below reads that as "not a git repo" and falls back to a
|
|
41
|
+
// walk that ignores .gitignore. The list is capped at MAX_FILES * 5 lines anyway.
|
|
42
|
+
const tracked = execFileSync('git', ['ls-files'], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000, maxBuffer: 64 * 1024 * 1024 })
|
|
43
|
+
.split('\n').filter(Boolean).slice(0, MAX_FILES * 5);
|
|
44
|
+
if (tracked.length) return tracked;
|
|
45
|
+
} catch (e) { /* not a git repo: walk below */ }
|
|
46
|
+
{
|
|
47
|
+
// No git, or an untracked folder inside a parent repo (git ls-files is then empty, not an error).
|
|
48
|
+
const out = [];
|
|
49
|
+
(function walk(dir, depth) {
|
|
50
|
+
if (depth > 6 || out.length > MAX_FILES * 5) return;
|
|
51
|
+
for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
52
|
+
if (ent.name.startsWith('.')) continue;
|
|
53
|
+
const rel = path.relative(root, path.join(dir, ent.name)).replace(/\\/g, '/');
|
|
54
|
+
if (ent.isDirectory()) { if (!SKIP_DIR.test(rel + '/')) walk(path.join(dir, ent.name), depth + 1); }
|
|
55
|
+
else out.push(rel);
|
|
56
|
+
}
|
|
57
|
+
})(root, 0);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function namesIn(file, text) {
|
|
63
|
+
const lang = LANG[path.extname(file).slice(1)];
|
|
64
|
+
const names = [];
|
|
65
|
+
for (const re of PATTERNS[lang] || []) {
|
|
66
|
+
for (const m of text.matchAll(re)) {
|
|
67
|
+
for (const n of m[1].split(',').map((s) => (s.trim().match(NAME) || [])[1]).filter(Boolean)) {
|
|
68
|
+
if (!n.startsWith('_') && !names.includes(n)) names.push(n);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return names;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function buildMap(root = process.cwd()) {
|
|
76
|
+
const files = listFiles(root)
|
|
77
|
+
.filter((f) => SAFE_PATH.test(f) && SRC.test(f) && !SKIP_DIR.test(f) && !SKIP_FILE.test(f))
|
|
78
|
+
.slice(0, MAX_FILES)
|
|
79
|
+
.sort((a, b) => (SHARED.test(b) - SHARED.test(a)) || a.localeCompare(b));
|
|
80
|
+
// One line per directory: names are enough to know something exists; grep finds the file.
|
|
81
|
+
const dirs = new Map();
|
|
82
|
+
for (const f of files) {
|
|
83
|
+
let text;
|
|
84
|
+
try {
|
|
85
|
+
if (!fs.lstatSync(path.join(root, f)).isFile()) continue;
|
|
86
|
+
text = fs.readFileSync(path.join(root, f), 'utf8').slice(0, 65536);
|
|
87
|
+
} catch (e) { continue; }
|
|
88
|
+
const names = namesIn(f, text);
|
|
89
|
+
if (!names.length) continue;
|
|
90
|
+
const dir = path.dirname(f) === '.' ? '.' : path.dirname(f);
|
|
91
|
+
dirs.set(dir, [...(dirs.get(dir) || []), names]);
|
|
92
|
+
}
|
|
93
|
+
const lines = [];
|
|
94
|
+
let used = 0;
|
|
95
|
+
let skipped = 0;
|
|
96
|
+
for (const [dir, perFile] of dirs) {
|
|
97
|
+
// The first exports say what a file is; in a folder of many files (a UI kit) one name each.
|
|
98
|
+
const names = [...new Set(perFile.flatMap((n) => n.slice(0, perFile.length > 8 ? 1 : 3)))];
|
|
99
|
+
const line = `${dir}/: ${names.slice(0, 30).join(', ')}${names.length > 30 ? ', ...' : ''}`;
|
|
100
|
+
if (used + line.length > BUDGET) { skipped++; continue; }
|
|
101
|
+
lines.push(line);
|
|
102
|
+
used += line.length + 1;
|
|
103
|
+
}
|
|
104
|
+
if (!lines.length) return '';
|
|
105
|
+
return 'Codebase map (what already exists; reuse it, read a file only when you need its details):\n' +
|
|
106
|
+
lines.join('\n') + (skipped ? `\n(${skipped} more folders not listed)` : '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = { buildMap };
|
|
110
|
+
|
|
111
|
+
if (require.main === module) process.stdout.write(buildMap(process.argv[2] || process.cwd()) + '\n');
|
|
@@ -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);
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const { createHash } = require('crypto');
|
|
5
|
+
const { getClaudeDir, getQoderDir } = require('./ponytail-config');
|
|
6
|
+
|
|
7
|
+
const STATE_FILE = '.ponytail-active';
|
|
8
|
+
|
|
9
|
+
// ponytail: VS Code Copilot never sets COPILOT_PLUGIN_DATA — it only injects
|
|
10
|
+
// CLAUDE_PLUGIN_ROOT, pointed at an install path under .vscode/agent-plugins/
|
|
11
|
+
// (#528). Without this fallback isCopilot was false, so ponytail assumed
|
|
12
|
+
// native Claude Code and emitted the statusline nudge, which VS Code Copilot
|
|
13
|
+
// doesn't read.
|
|
14
|
+
function isVsCodeCopilotRoot(pluginRoot) {
|
|
15
|
+
if (!pluginRoot) return false;
|
|
16
|
+
return pluginRoot.split(/[\\/]+/).includes('agent-plugins') &&
|
|
17
|
+
pluginRoot.toLowerCase().includes('.vscode');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const isCopilot = Boolean(process.env.COPILOT_PLUGIN_DATA) ||
|
|
21
|
+
isVsCodeCopilotRoot(process.env.CLAUDE_PLUGIN_ROOT);
|
|
22
|
+
const isCodex = !isCopilot && Boolean(process.env.PLUGIN_DATA);
|
|
23
|
+
const isQoder = !isCopilot && !isCodex && Boolean(process.env.QODER_SESSION_ID);
|
|
24
|
+
// CodeBuddy (#854) loads the Claude-format plugin and sets CLAUDE_PLUGIN_ROOT
|
|
25
|
+
// too, but adds CODEBUDDY_PLUGIN_ROOT only for its own plugin hook processes.
|
|
26
|
+
const isCodeBuddy = !isCopilot && !isCodex && !isQoder && Boolean(process.env.CODEBUDDY_PLUGIN_ROOT);
|
|
27
|
+
// Cursor (#817): CURSOR_VERSION is set only in the environment Cursor builds
|
|
28
|
+
// for hook processes (Cursor 3.20.17 assigns it in exactly one place, the hook
|
|
29
|
+
// env builder), so it never leaks into a Claude Code session running inside
|
|
30
|
+
// Cursor's terminal. Cursor also sets it when it runs a Claude-format plugin's
|
|
31
|
+
// hooks next to CLAUDE_PLUGIN_ROOT, and it needs Cursor-shaped JSON either
|
|
32
|
+
// way, so this check comes after the hosts with their own data dirs.
|
|
33
|
+
const isCursor = !isCopilot && !isCodex && !isQoder && !isCodeBuddy && Boolean(process.env.CURSOR_VERSION);
|
|
34
|
+
|
|
35
|
+
let stateDir = getClaudeDir();
|
|
36
|
+
if (isCodex) stateDir = process.env.PLUGIN_DATA;
|
|
37
|
+
// COPILOT_PLUGIN_DATA is unset under VS Code Copilot, so fall back to
|
|
38
|
+
// getClaudeDir() rather than building a path from undefined.
|
|
39
|
+
if (isCopilot) stateDir = process.env.COPILOT_PLUGIN_DATA || getClaudeDir();
|
|
40
|
+
if (isQoder) stateDir = getQoderDir();
|
|
41
|
+
if (isCodeBuddy) stateDir = process.env.CODEBUDDY_CONFIG_DIR || path.join(os.homedir(), '.codebuddy');
|
|
42
|
+
if (isCursor) stateDir = path.join(os.homedir(), '.cursor');
|
|
43
|
+
|
|
44
|
+
const statePath = path.join(stateDir, STATE_FILE);
|
|
45
|
+
|
|
46
|
+
// Claude Code hands every hook its project dir, so the live mode is kept per
|
|
47
|
+
// project and concurrent sessions in different repos stop overwriting each other
|
|
48
|
+
// (#662, #809). Hosts without it keep the single shared flag.
|
|
49
|
+
// ponytail: sessions in the SAME repo still share one mode, and the statusline
|
|
50
|
+
// scripts read the shared flag (last write wins); key by session_id if either matters.
|
|
51
|
+
const projectDir = (process.env.CLAUDE_PROJECT_DIR || '').trim();
|
|
52
|
+
// Replacing separators with '_' aliases e.g. /work/a/b and /work/a_b (#662).
|
|
53
|
+
// Do not read old sanitized keys: they cannot be assigned to one project safely.
|
|
54
|
+
const projectStatePath = projectDir
|
|
55
|
+
? path.join(stateDir, 'ponytail-modes',
|
|
56
|
+
createHash('sha256').update(path.normalize(projectDir)).digest('hex'))
|
|
57
|
+
: null;
|
|
58
|
+
|
|
59
|
+
// The shared flag is still written, for the statusline and project-less hosts.
|
|
60
|
+
function setMode(mode) {
|
|
61
|
+
for (const file of [projectStatePath, statePath]) {
|
|
62
|
+
if (!file) continue;
|
|
63
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
64
|
+
fs.writeFileSync(file, mode);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function clearMode() {
|
|
69
|
+
for (const file of [projectStatePath, statePath]) {
|
|
70
|
+
if (file) try { fs.unlinkSync(file); } catch (e) {}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Live mode written by activate/mode-tracker. Absent flag = ponytail off.
|
|
75
|
+
function readMode() {
|
|
76
|
+
try {
|
|
77
|
+
return fs.readFileSync(projectStatePath || statePath, 'utf8').trim() || null;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Cursor's always-on project rule (.cursor/rules/ponytail.mdc) already puts the
|
|
84
|
+
// ruleset in front of every prompt and no hook can switch a rule off, so while
|
|
85
|
+
// it is in the workspace the hooks step back instead of injecting a second,
|
|
86
|
+
// possibly contradicting, copy (#817). Cursor hands every hook the workspace
|
|
87
|
+
// root as CURSOR_PROJECT_DIR; project hooks also run from that directory.
|
|
88
|
+
// ponytail: first workspace root only, a rule in a secondary folder of a
|
|
89
|
+
// multi-root workspace goes undetected.
|
|
90
|
+
function cursorRulePath() {
|
|
91
|
+
const root = process.env.CURSOR_PROJECT_DIR || process.cwd();
|
|
92
|
+
const rule = path.join(root, '.cursor', 'rules', 'ponytail.mdc');
|
|
93
|
+
return fs.existsSync(rule) ? rule : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function cursorRuleNotice(rule) {
|
|
97
|
+
return 'PONYTAIL: the always-on Cursor rule ' + rule + ' is active in this workspace and ' +
|
|
98
|
+
'already carries the ponytail ruleset, so the ponytail hooks injected nothing further. ' +
|
|
99
|
+
'Mode switching (/ponytail lite|full|ultra|off, "stop ponytail") is unavailable while ' +
|
|
100
|
+
'that rule exists. When the user tries to switch or turn off ponytail, tell them to ' +
|
|
101
|
+
'delete that rule so hooks.json can manage the level.';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Synchronous: every hook calls process.exit() right after this, and on macOS a pipe
|
|
105
|
+
// write is async, so a pending write died with the process (#1043).
|
|
106
|
+
function writeOut(text) {
|
|
107
|
+
fs.writeSync(1, text);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function writeHookOutput(event, mode, context = '') {
|
|
111
|
+
if (isCopilot) {
|
|
112
|
+
// Copilot reads additionalContext on SessionStart; ignores output elsewhere.
|
|
113
|
+
writeOut(JSON.stringify(
|
|
114
|
+
event === 'SessionStart' && context ? { additionalContext: context } : {}));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (isCodex) {
|
|
118
|
+
// No systemMessage: Codex maps it to a yellow `warning:` entry (and de-greens the
|
|
119
|
+
// completed-hook bullet), reading as an error every session (#605). The mode still
|
|
120
|
+
// shows via the additionalContext "hook context:" line — active level when on,
|
|
121
|
+
// "PONYTAIL MODE OFF" when off (that path passes context too).
|
|
122
|
+
// ponytail: if openai/codex#16933 lands and hides additionalContext, restore a
|
|
123
|
+
// non-warning mode signal here.
|
|
124
|
+
const output = {};
|
|
125
|
+
if (context) {
|
|
126
|
+
output.hookSpecificOutput = {
|
|
127
|
+
hookEventName: event,
|
|
128
|
+
additionalContext: context,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
writeOut(JSON.stringify(output));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (isQoder || isCodeBuddy) {
|
|
135
|
+
// Qoder: hookSpecificOutput JSON, same shape as Codex minus systemMessage.
|
|
136
|
+
// UserPromptSubmit additionalContext is injected into the Agent's conversation.
|
|
137
|
+
// CodeBuddy would take raw stdout too, but also echoes it into the chat.
|
|
138
|
+
const output = {};
|
|
139
|
+
if (context) {
|
|
140
|
+
output.hookSpecificOutput = {
|
|
141
|
+
hookEventName: event,
|
|
142
|
+
additionalContext: context,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
writeOut(JSON.stringify(output));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (isCursor) {
|
|
149
|
+
// Cursor parses stdout as JSON and treats empty stdout as "nothing to
|
|
150
|
+
// say"; raw text would be logged as a parse error. sessionStart takes
|
|
151
|
+
// additional_context into the conversation's system context;
|
|
152
|
+
// beforeSubmitPrompt needs continue:true and, in Cursor 3.20.17, injects
|
|
153
|
+
// additional_context into that turn (docs/cursor-hooks.md).
|
|
154
|
+
if (!context) return;
|
|
155
|
+
const output = { additional_context: context };
|
|
156
|
+
if (event === 'UserPromptSubmit') output.continue = true;
|
|
157
|
+
writeOut(JSON.stringify(output));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
// Native Claude: SessionStart accepts raw stdout, but SubagentStart needs the
|
|
161
|
+
// hookSpecificOutput JSON form or the context is dropped.
|
|
162
|
+
if (event === 'SubagentStart') {
|
|
163
|
+
writeOut(JSON.stringify(
|
|
164
|
+
{ hookSpecificOutput: { hookEventName: event, additionalContext: context } }));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
writeOut(context);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = {
|
|
171
|
+
clearMode,
|
|
172
|
+
cursorRuleNotice,
|
|
173
|
+
cursorRulePath,
|
|
174
|
+
isCodeBuddy,
|
|
175
|
+
isCodex,
|
|
176
|
+
isCopilot,
|
|
177
|
+
isCursor,
|
|
178
|
+
isQoder,
|
|
179
|
+
readMode,
|
|
180
|
+
setMode,
|
|
181
|
+
writeHookOutput,
|
|
182
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
# ultra is the high-intensity mode; flag it amber so it stands out from the
|
|
17
|
+
# default green. The level is still in the text, so color is a redundant cue.
|
|
18
|
+
$Color = if ($Mode -eq "ultra") { "173" } else { "108" }
|
|
19
|
+
if ([string]::IsNullOrEmpty($Mode) -or $Mode -eq "full") {
|
|
20
|
+
[Console]::Write("${Esc}[38;5;${Color}m[PONYTAIL]${Esc}[0m")
|
|
21
|
+
} else {
|
|
22
|
+
$Suffix = $Mode.ToUpperInvariant()
|
|
23
|
+
[Console]::Write("${Esc}[38;5;${Color}m[PONYTAIL:$Suffix]${Esc}[0m")
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
# ultra is the high-intensity mode; flag it amber so it stands out from the
|
|
9
|
+
# default green at a glance. The level is still in the text, so color is a
|
|
10
|
+
# redundant cue, not the only one.
|
|
11
|
+
color=108
|
|
12
|
+
[ "$mode" = "ultra" ] && color=173
|
|
13
|
+
|
|
14
|
+
if [ -z "$mode" ] || [ "$mode" = "full" ]; then
|
|
15
|
+
printf '\033[38;5;%sm[PONYTAIL]\033[0m' "$color"
|
|
16
|
+
else
|
|
17
|
+
printf '\033[38;5;%sm[PONYTAIL:%s]\033[0m' "$color" "$(printf '%s' "$mode" | tr '[:lower:]' '[:upper:]')"
|
|
18
|
+
fi
|