self-evolve-framework 1.2.0 → 1.4.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 (64) hide show
  1. package/README.md +22 -11
  2. package/bin/cli.js +1 -0
  3. package/package.json +1 -1
  4. package/template/skills/ponytail/SKILL.md +133 -0
  5. package/template/skills/ponytail/scripts/hooks/claude-codex-hooks.json +44 -0
  6. package/template/skills/ponytail/scripts/hooks/copilot-hooks.json +21 -0
  7. package/template/skills/ponytail/scripts/hooks/ponytail-activate.js +91 -0
  8. package/template/skills/ponytail/scripts/hooks/ponytail-config.js +122 -0
  9. package/template/skills/ponytail/scripts/hooks/ponytail-instructions.js +94 -0
  10. package/template/skills/ponytail/scripts/hooks/ponytail-mode-tracker.js +55 -0
  11. package/template/skills/ponytail/scripts/hooks/ponytail-runtime.js +68 -0
  12. package/template/skills/ponytail/scripts/hooks/ponytail-statusline.ps1 +21 -0
  13. package/template/skills/ponytail/scripts/hooks/ponytail-statusline.sh +12 -0
  14. package/template/skills/ponytail/scripts/hooks/ponytail-subagent.js +22 -0
  15. package/template/skills/ponytail/scripts/mcp/README.md +46 -0
  16. package/template/skills/ponytail/scripts/mcp/index.js +48 -0
  17. package/template/skills/ponytail/scripts/mcp/instructions.js +26 -0
  18. package/template/skills/ponytail/scripts/mcp/package.json +13 -0
  19. package/template/skills/ponytail/scripts/mcp/test/instructions.test.js +22 -0
  20. package/template/skills/ponytail-audit/SKILL.md +41 -0
  21. package/template/skills/ponytail-debt/SKILL.md +44 -0
  22. package/template/skills/ponytail-gain/SKILL.md +50 -0
  23. package/template/skills/ponytail-help/SKILL.md +69 -0
  24. package/template/skills/ponytail-review/SKILL.md +57 -0
  25. package/template/skills/skillopt-sleep/SKILL.md +48 -34
  26. package/template/skills/skillopt-sleep/scripts/python/__init__.py +20 -0
  27. package/template/skills/skillopt-sleep/scripts/python/__main__.py +343 -0
  28. package/template/skills/skillopt-sleep/scripts/python/backend.py +1371 -0
  29. package/template/skills/skillopt-sleep/scripts/python/budget.py +75 -0
  30. package/template/skills/skillopt-sleep/scripts/python/config.py +162 -0
  31. package/template/skills/skillopt-sleep/scripts/python/consolidate.py +238 -0
  32. package/template/skills/skillopt-sleep/scripts/python/cycle.py +291 -0
  33. package/template/skills/skillopt-sleep/scripts/python/dream.py +138 -0
  34. package/template/skills/skillopt-sleep/scripts/python/experiments/__init__.py +1 -0
  35. package/template/skills/skillopt-sleep/scripts/python/experiments/gbrain_bench.py +119 -0
  36. package/template/skills/skillopt-sleep/scripts/python/experiments/personas.py +86 -0
  37. package/template/skills/skillopt-sleep/scripts/python/experiments/report.py +132 -0
  38. package/template/skills/skillopt-sleep/scripts/python/experiments/run_experiment.py +178 -0
  39. package/template/skills/skillopt-sleep/scripts/python/experiments/run_gbrain.py +209 -0
  40. package/template/skills/skillopt-sleep/scripts/python/experiments/run_transfer.py +155 -0
  41. package/template/skills/skillopt-sleep/scripts/python/experiments/sweep.py +164 -0
  42. package/template/skills/skillopt-sleep/scripts/python/gate.py +50 -0
  43. package/template/skills/skillopt-sleep/scripts/python/harvest.py +304 -0
  44. package/template/skills/skillopt-sleep/scripts/python/harvest_codex.py +253 -0
  45. package/template/skills/skillopt-sleep/scripts/python/harvest_sources.py +41 -0
  46. package/template/skills/skillopt-sleep/scripts/python/judges.py +84 -0
  47. package/template/skills/skillopt-sleep/scripts/python/llm_miner.py +134 -0
  48. package/template/skills/skillopt-sleep/scripts/python/memory.py +129 -0
  49. package/template/skills/skillopt-sleep/scripts/python/mine.py +312 -0
  50. package/template/skills/skillopt-sleep/scripts/python/replay.py +146 -0
  51. package/template/skills/skillopt-sleep/scripts/python/rollout.py +153 -0
  52. package/template/skills/skillopt-sleep/scripts/python/scheduler.py +138 -0
  53. package/template/skills/skillopt-sleep/scripts/python/slow_update.py +142 -0
  54. package/template/skills/skillopt-sleep/scripts/python/staging.py +103 -0
  55. package/template/skills/skillopt-sleep/scripts/python/state.py +96 -0
  56. package/template/skills/skillopt-sleep/scripts/python/tasks_file.py +81 -0
  57. package/template/skills/skillopt-sleep/scripts/python/types.py +146 -0
  58. package/template/skills/skillopt-sleep/scripts/shell/__init__.py +0 -0
  59. package/template/skills/skillopt-sleep/scripts/shell/eval_only.py +466 -0
  60. package/template/skills/skillopt-sleep/scripts/shell/materialize_searchqa.py +148 -0
  61. package/template/skills/skillopt-sleep/scripts/shell/run_alfworld.sh +60 -0
  62. package/template/skills/skillopt-sleep/scripts/shell/run_searchqa.sh +40 -0
  63. package/template/skills/skillopt-sleep/scripts/shell/run_spreadsheetbench.sh +39 -0
  64. package/template/skills/skillopt-sleep/scripts/shell/train.py +556 -0
package/README.md CHANGED
@@ -42,13 +42,17 @@ npx self-evolve-framework init --skip-impeccable
42
42
  ```
43
43
  .codebuddy/
44
44
  ├── rules/
45
- │ ├── self-evolve.mdc ← 编排层(always 激活)
45
+ │ ├── self-evolve.mdc ← 进化编排(always 激活)
46
46
  │ └── ponytail.mdc ← 代码最小化原则
47
47
  ├── skills/
48
- │ ├── skillopt-sleep/
49
- │ └── SKILL.md 离线进化分析
50
- └── impeccable/
51
- └── SKILL.md 设计质量审计
48
+ │ ├── skillopt-sleep/ ← 离线进化分析
49
+ ├── impeccable/ 设计质量审计(含脚本和参考文档)
50
+ ├── ponytail/ ← 代码最小化主 skill
51
+ ├── ponytail-audit/ 代码审计
52
+ │ ├── ponytail-debt/ ← 技术债分析
53
+ │ ├── ponytail-gain/ ← 收益分析
54
+ │ ├── ponytail-help/ ← 帮助文档
55
+ │ └── ponytail-review/ ← 代码审查
52
56
  CLAUDE.md ← 追加自我进化章节
53
57
  ```
54
58
 
@@ -76,6 +80,9 @@ skillopt-sleep adopt → 采纳建议
76
80
  impeccable audit → 设计质量技术审计
77
81
  impeccable critique → 设计评审
78
82
  impeccable polish → 页面润色
83
+ ponytail → 代码最小化懒人模式
84
+ ponytail audit → 代码审计
85
+ ponytail review → 代码审查
79
86
  ```
80
87
 
81
88
  ### 设计上下文
@@ -96,12 +103,16 @@ self-evolve-framework/
96
103
  ├── bin/cli.js # CLI 安装工具
97
104
  ├── template/
98
105
  │ ├── rules/
99
- │ │ ├── self-evolve.mdc ← 编排层(含 Impeccable 集成)
100
- │ │ └── ponytail.mdc
106
+ │ │ ├── self-evolve.mdc ← 进化编排
107
+ │ │ └── ponytail.mdc ← 代码最小化原则
101
108
  │ └── skills/
102
- │ ├── skillopt-sleep/
103
- │ └── SKILL.md 离线进化引擎(含设计质量分析)
104
- └── impeccable/
105
- └── SKILL.md 设计质量审计 skill
109
+ │ ├── skillopt-sleep/ ← 离线进化引擎
110
+ ├── impeccable/ 设计质量审计(含脚本)
111
+ ├── ponytail/ ← 代码最小化主 skill
112
+ ├── ponytail-audit/ 代码审计
113
+ │ ├── ponytail-debt/ ← 技术债分析
114
+ │ ├── ponytail-gain/ ← 收益分析
115
+ │ ├── ponytail-help/ ← 帮助
116
+ │ └── ponytail-review/ ← 代码审查
106
117
  └── README.md
107
118
  ```
package/bin/cli.js CHANGED
@@ -151,6 +151,7 @@ async function init(args) {
151
151
  console.log(" skillopt-sleep dry-run → 每日健康检查")
152
152
  console.log(" skillopt-sleep run → 周改进提案")
153
153
  console.log(" impeccable audit/critique → 设计质量审查")
154
+ console.log(" ponytail → 代码最小化(懒人模式)")
154
155
  console.log(" npx self-evolve-framework list → 查看所有可用 skill")
155
156
  }
156
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "self-evolve-framework",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "CodeBuddy 自我进化飞轮 — 仅适用于 CodeBuddy IDE。Post-Edit 验证闭环 + 规则自动推荐 + 离线进化分析",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,133 @@
1
+ ---
2
+ name: ponytail
3
+ description: >
4
+ Forces the laziest solution that actually works, simplest, shortest, most
5
+ minimal. Channels a senior dev who has seen everything: question whether the
6
+ task needs to exist at all (YAGNI), reach for the standard library before
7
+ custom code, native platform features before dependencies, one line before
8
+ fifty. Supports intensity levels: lite, full (default), ultra. Use whenever
9
+ the user says "ponytail", "be lazy", "lazy mode", "simplest solution",
10
+ "minimal solution", "yagni", "do less", or "shortest path", and whenever
11
+ they complain about over-engineering, bloat, boilerplate, or unnecessary
12
+ dependencies.
13
+ argument-hint: "[lite|full|ultra]"
14
+ license: MIT
15
+ ---
16
+
17
+ # Ponytail
18
+
19
+ You are a lazy senior developer. Lazy means efficient, not careless. You have
20
+ seen every over-engineered codebase and been paged at 3am for one. The best
21
+ code is the code never written.
22
+
23
+ ## Persistence
24
+
25
+ ACTIVE EVERY RESPONSE. No drift back to over-building. Still active if
26
+ unsure. Off only: "stop ponytail" / "normal mode". Default: **full**.
27
+ Switch: `/ponytail lite|full|ultra`.
28
+
29
+ ## The ladder
30
+
31
+ Stop at the first rung that holds:
32
+
33
+ 1. **Does this need to exist at all?** Speculative need = skip it, say so in one line. (YAGNI)
34
+ 2. **Already in this codebase?** A helper, util, type, or pattern that already lives here → reuse it. Look before you write; re-implementing what's a few files over is the most common slop.
35
+ 3. **Stdlib does it?** Use it.
36
+ 4. **Native platform feature covers it?** `<input type="date">` over a picker lib, CSS over JS, DB constraint over app code.
37
+ 5. **Already-installed dependency solves it?** Use it. Never add a new one for what a few lines can do.
38
+ 6. **Can it be one line?** One line.
39
+ 7. **Only then:** the minimum code that works.
40
+
41
+ The ladder is a reflex, not a research project — but it runs *after* you
42
+ understand the problem, not instead of it. Read the task and the code it
43
+ touches first, trace the real flow end to end, then climb. Two rungs work →
44
+ take the higher one and move on. The first lazy solution that works is the
45
+ right one — once you actually know what the change has to touch.
46
+
47
+ **Bug fix = root cause, not symptom.** A report names a symptom. Before you
48
+ edit, grep every caller of the function you're about to touch. The lazy fix IS
49
+ the root-cause fix: one guard in the shared function is a smaller diff than a
50
+ guard in every caller — and patching only the path the ticket names leaves
51
+ every sibling caller still broken. Fix it once, where all callers route through.
52
+
53
+ ## Rules
54
+
55
+ - No unrequested abstractions: no interface with one implementation, no factory for one product, no config for a value that never changes.
56
+ - No boilerplate, no scaffolding "for later", later can scaffold for itself.
57
+ - Deletion over addition. Boring over clever, clever is what someone decodes at 3am.
58
+ - Fewest files possible. Shortest working diff wins — but only once you understand the problem. The smallest change in the wrong place isn't lazy, it's a second bug.
59
+ - Complex request? Ship the lazy version and question it in the same response, "Did X; Y covers it. Need full X? Say so." Never stall on an answer you can default.
60
+ - Two stdlib options, same size? Take the one that's correct on edge cases. Lazy means writing less code, not picking the flimsier algorithm.
61
+ - Mark deliberate simplifications with a `ponytail:` comment (`// ponytail: this exists`), simple reads as intent, not ignorance. Shortcut with a known ceiling (global lock, O(n²) scan, naive heuristic)? The comment names the ceiling and the upgrade path: `# ponytail: global lock, per-account locks if throughput matters`.
62
+
63
+ ## Output
64
+
65
+ Code first. Then at most three short lines: what was skipped, when to add it.
66
+ No essays, no feature tours, no design notes. If the explanation is longer
67
+ than the code, delete the explanation, every paragraph defending a
68
+ simplification is complexity smuggled back in as prose. Explanation the user
69
+ explicitly asked for (a report, a walkthrough, per-phase notes) is not debt,
70
+ give it in full, the rule is only against unrequested prose.
71
+
72
+ Pattern: `[code] → skipped: [X], add when [Y].`
73
+
74
+ ## Intensity
75
+
76
+ | Level | What change |
77
+ |-------|------------|
78
+ | **lite** | Build what's asked, but name the lazier alternative in one line. User picks. |
79
+ | **full** | The ladder enforced. Stdlib and native first. Shortest diff, shortest explanation. Default. |
80
+ | **ultra** | YAGNI extremist. Deletion before addition. Ship the one-liner and challenge the rest of the requirement in the same breath. |
81
+
82
+ Example: "Add a cache for these API responses."
83
+ - lite: "Done, cache added. FYI: `functools.lru_cache` covers this in one line if you'd rather not own a cache class."
84
+ - full: "`@lru_cache(maxsize=1000)` on the fetch function. Skipped custom cache class, add when lru_cache measurably falls short."
85
+ - ultra: "No cache until a profiler says so. When it does: `@lru_cache`. A hand-rolled TTL cache class is a bug farm with a hit rate."
86
+
87
+ ## When NOT to be lazy
88
+
89
+ Never simplify away: input validation at trust boundaries, error handling
90
+ that prevents data loss, security measures, accessibility basics, anything
91
+ explicitly requested. User insists on the full version → build it, no
92
+ re-arguing.
93
+
94
+ Never lazy about understanding the problem. The ladder shortens the
95
+ solution, never the reading. Trace the whole thing first — every file the
96
+ change touches, the actual flow — before picking a rung. Laziness that skips
97
+ comprehension to ship a small diff is the dangerous kind: it dresses up as
98
+ efficiency and ships a confident wrong fix. Read fully, then be lazy.
99
+
100
+ Hardware is never the ideal on paper: a real clock drifts, a real sensor
101
+ reads off, a PCA9685 runs a few percent fast. Leave the calibration knob, not
102
+ just less code, the physical world needs tuning a minimal model can't see.
103
+
104
+ Lazy code without its check is unfinished. Non-trivial logic (a branch, a
105
+ loop, a parser, a money/security path) leaves ONE runnable check behind, the
106
+ smallest thing that fails if the logic breaks: an `assert`-based
107
+ `demo()`/`__main__` self-check or one small `test_*.py`. No frameworks, no
108
+ fixtures, no per-function suites unless asked. Trivial one-liners need no
109
+ test, YAGNI applies to tests too.
110
+
111
+ ## Boundaries
112
+
113
+ Ponytail governs what you build, not how you talk (pair with Caveman for
114
+ terse prose). "stop ponytail" / "normal mode": revert. Level persists until
115
+ changed or session end.
116
+
117
+ The shortest path to done is the right path.
118
+
119
+ ## 执行引擎
120
+
121
+ 此 skill 附带 [DietrichGebert/ponytail](https://github.com/DietrichGebert/ponytail) 的完整执行组件:
122
+
123
+ | 组件 | 路径 | 用途 |
124
+ |------|------|------|
125
+ | MCP 服务器 | `scripts/mcp/` | 与 IDE 深度集成,提供上下文感知的懒人建议 |
126
+ | Hooks | `scripts/hooks/` | 代码提交/保存时自动触发懒人审计 |
127
+ | AGENTS.md | 项目根目录 | 安装后自动注入的 agent 指令 |
128
+
129
+ 首次安装后,如果需要激活 MCP 集成:
130
+
131
+ ```bash
132
+ node .codebuddy/skills/ponytail/scripts/mcp/index.js
133
+ ```
@@ -0,0 +1,44 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "matcher": "startup|resume|clear|compact",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/ponytail-activate.js\"; exit 0",
10
+ "commandWindows": "if (Get-Command node -ErrorAction SilentlyContinue) { node \"$env:CLAUDE_PLUGIN_ROOT\\hooks\\ponytail-activate.js\" }",
11
+ "timeout": 5,
12
+ "statusMessage": "Loading ponytail mode..."
13
+ }
14
+ ]
15
+ }
16
+ ],
17
+ "SubagentStart": [
18
+ {
19
+ "hooks": [
20
+ {
21
+ "type": "command",
22
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/ponytail-subagent.js\"; exit 0",
23
+ "commandWindows": "if (Get-Command node -ErrorAction SilentlyContinue) { node \"$env:CLAUDE_PLUGIN_ROOT\\hooks\\ponytail-subagent.js\" }",
24
+ "timeout": 5,
25
+ "statusMessage": "Loading ponytail mode..."
26
+ }
27
+ ]
28
+ }
29
+ ],
30
+ "UserPromptSubmit": [
31
+ {
32
+ "hooks": [
33
+ {
34
+ "type": "command",
35
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/ponytail-mode-tracker.js\"; exit 0",
36
+ "commandWindows": "if (Get-Command node -ErrorAction SilentlyContinue) { node \"$env:CLAUDE_PLUGIN_ROOT\\hooks\\ponytail-mode-tracker.js\" }",
37
+ "timeout": 5,
38
+ "statusMessage": "Tracking ponytail mode..."
39
+ }
40
+ ]
41
+ }
42
+ ]
43
+ }
44
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "version": 1,
3
+ "hooks": {
4
+ "sessionStart": [
5
+ {
6
+ "type": "command",
7
+ "bash": "node \"${PLUGIN_ROOT}/hooks/ponytail-activate.js\"",
8
+ "powershell": "node \"${PLUGIN_ROOT}\\hooks\\ponytail-activate.js\"",
9
+ "timeoutSec": 5
10
+ }
11
+ ],
12
+ "userPromptSubmitted": [
13
+ {
14
+ "type": "command",
15
+ "bash": "node \"${PLUGIN_ROOT}/hooks/ponytail-mode-tracker.js\"",
16
+ "powershell": "node \"${PLUGIN_ROOT}\\hooks\\ponytail-mode-tracker.js\"",
17
+ "timeoutSec": 5
18
+ }
19
+ ]
20
+ }
21
+ }
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ // ponytail — Claude Code SessionStart activation hook
3
+ //
4
+ // Runs on every session start:
5
+ // 1. Writes flag file at $CLAUDE_CONFIG_DIR/.ponytail-active (defaults to ~/.claude; statusline reads this)
6
+ // 2. Emits ponytail ruleset as hidden SessionStart context
7
+ // 3. Detects missing statusline config and emits setup nudge
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const { getDefaultMode, getClaudeDir, isShellSafe } = require('./ponytail-config');
12
+ const { getPonytailInstructions } = require('./ponytail-instructions');
13
+ const {
14
+ clearMode,
15
+ isCodex,
16
+ isCopilot,
17
+ setMode,
18
+ writeHookOutput,
19
+ } = require('./ponytail-runtime');
20
+
21
+ const claudeDir = getClaudeDir();
22
+ const settingsPath = path.join(claudeDir, 'settings.json');
23
+
24
+ const mode = getDefaultMode();
25
+
26
+ // "off" mode — skip activation entirely, don't write flag or emit rules
27
+ if (mode === 'off') {
28
+ clearMode();
29
+ const hookOutput = (isCodex || isCopilot) ? '' : 'OK';
30
+ writeHookOutput('SessionStart', 'off', hookOutput);
31
+ process.exit(0);
32
+ }
33
+
34
+ // 1. Write flag file
35
+ try {
36
+ setMode(mode);
37
+ } catch (e) {
38
+ // Silent fail -- flag is best-effort, don't block the hook
39
+ }
40
+
41
+ // 2. Emit the ponytail ruleset, filtered to the active intensity level.
42
+ let output = getPonytailInstructions(mode);
43
+
44
+ // 3. Detect missing statusline config — nudge Claude to help set it up
45
+ if (!isCodex && !isCopilot) try {
46
+ let hasStatusline = false;
47
+ if (fs.existsSync(settingsPath)) {
48
+ // Strip UTF-8 BOM some editors prepend on Windows (breaks JSON.parse)
49
+ const raw = fs.readFileSync(settingsPath, 'utf8').replace(/^\uFEFF/, '');
50
+ const settings = JSON.parse(raw);
51
+ if (settings.statusLine) {
52
+ hasStatusline = true;
53
+ }
54
+ }
55
+
56
+ if (!hasStatusline) {
57
+ const isWindows = process.platform === 'win32';
58
+ const scriptName = isWindows ? 'ponytail-statusline.ps1' : 'ponytail-statusline.sh';
59
+ const scriptPath = path.join(__dirname, scriptName);
60
+ if (isShellSafe(scriptPath)) {
61
+ const command = isWindows
62
+ ? `powershell -ExecutionPolicy Bypass -File "${scriptPath}"`
63
+ : `bash "${scriptPath}"`;
64
+ const statusLineSnippet =
65
+ '"statusLine": { "type": "command", "command": ' + JSON.stringify(command) + ' }';
66
+ output += "\n\n" +
67
+ "STATUSLINE SETUP NEEDED: The ponytail plugin includes a statusline badge showing active mode " +
68
+ "(e.g. [PONYTAIL], [PONYTAIL:ULTRA]). It is not configured yet. " +
69
+ "To enable, add this to ~/.claude/settings.json: " +
70
+ statusLineSnippet + " " +
71
+ "Proactively offer to set this up for the user on first interaction.";
72
+ } else {
73
+ // ponytail: install path has shell metacharacters — don't embed it in a
74
+ // command snippet; have the agent wire it up by hand instead.
75
+ output += "\n\n" +
76
+ "STATUSLINE SETUP NEEDED: The ponytail plugin includes a statusline badge showing active mode. " +
77
+ "Its install path contains characters unsafe to embed in a shell command, so configure it manually: " +
78
+ "add a statusLine command of type \"command\" that runs " + scriptName +
79
+ " from the plugin's hooks directory to ~/.claude/settings.json, quoting/escaping the path for your shell. " +
80
+ "Proactively offer to set this up for the user on first interaction.";
81
+ }
82
+ }
83
+ } catch (e) {
84
+ // Silent fail — don't block session start over statusline detection
85
+ }
86
+
87
+ try {
88
+ writeHookOutput('SessionStart', mode, output);
89
+ } catch (e) {
90
+ // Silent fail — stdout closed/EPIPE at hook exit must not surface as a hook failure
91
+ }
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ // ponytail — shared configuration resolver
3
+ //
4
+ // Resolution order for default mode:
5
+ // 1. PONYTAIL_DEFAULT_MODE environment variable
6
+ // 2. Config file defaultMode field:
7
+ // - $XDG_CONFIG_HOME/ponytail/config.json (any platform, if set)
8
+ // - ~/.config/ponytail/config.json (macOS / Linux fallback)
9
+ // - %APPDATA%\ponytail\config.json (Windows fallback)
10
+ // 3. 'full'
11
+
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const os = require('os');
15
+
16
+ const DEFAULT_MODE = 'full';
17
+ const VALID_MODES = ['off', 'lite', 'full', 'ultra', 'review'];
18
+ const RUNTIME_MODES = ['off', 'lite', 'full', 'ultra'];
19
+
20
+ function normalizeMode(mode) {
21
+ if (typeof mode !== 'string') return null;
22
+ const normalized = mode.trim().toLowerCase();
23
+ return RUNTIME_MODES.includes(normalized) ? normalized : null;
24
+ }
25
+
26
+ function normalizeConfigMode(mode) {
27
+ if (typeof mode !== 'string') return null;
28
+ const normalized = mode.trim().toLowerCase();
29
+ return VALID_MODES.includes(normalized) ? normalized : null;
30
+ }
31
+
32
+ function normalizePersistedMode(mode) {
33
+ return normalizeMode(mode) || normalizeConfigMode(mode);
34
+ }
35
+
36
+ // "stop ponytail" / "normal mode" turn ponytail off, but only as a standalone
37
+ // command. Matching the phrase anywhere in the message turned it off mid-task
38
+ // for ordinary requests like "add a normal mode toggle" — so require the whole
39
+ // message to be the command, ignoring case and trailing punctuation.
40
+ function isDeactivationCommand(text) {
41
+ const t = String(text || '').trim().toLowerCase().replace(/[.!?\s]+$/, '');
42
+ return t === 'stop ponytail' || t === 'normal mode';
43
+ }
44
+
45
+ // ponytail: only embed the plugin install path in a statusline shell command when
46
+ // it's made of ordinary path characters. An allowlist beats escaping every shell's
47
+ // metacharacters; a hostile clone path (quotes, &, $, backtick, ;, etc.) falls back
48
+ // to manual setup instead. Allows : \ / for normal Windows and POSIX paths. Full
49
+ // per-shell escaper only if a real need appears.
50
+ function isShellSafe(p) {
51
+ return typeof p === 'string' && /^[A-Za-z0-9 _.\-:/\\~]+$/.test(p);
52
+ }
53
+
54
+ function getConfigDir() {
55
+ if (process.env.XDG_CONFIG_HOME) {
56
+ return path.join(process.env.XDG_CONFIG_HOME, 'ponytail');
57
+ }
58
+ if (process.platform === 'win32') {
59
+ return path.join(
60
+ process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'),
61
+ 'ponytail'
62
+ );
63
+ }
64
+ return path.join(os.homedir(), '.config', 'ponytail');
65
+ }
66
+
67
+ function getConfigPath() {
68
+ return path.join(getConfigDir(), 'config.json');
69
+ }
70
+
71
+ function getClaudeDir() {
72
+ // ponytail: CLAUDE_CONFIG_DIR overrides ~/.claude, matching Claude Code.
73
+ return process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
74
+ }
75
+
76
+ function getDefaultMode() {
77
+ // 1. Environment variable (highest priority)
78
+ const envMode = process.env.PONYTAIL_DEFAULT_MODE;
79
+ if (envMode && VALID_MODES.includes(envMode.toLowerCase())) {
80
+ return envMode.toLowerCase();
81
+ }
82
+
83
+ // 2. Config file
84
+ try {
85
+ const configPath = getConfigPath();
86
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
87
+ if (config.defaultMode && VALID_MODES.includes(config.defaultMode.toLowerCase())) {
88
+ return config.defaultMode.toLowerCase();
89
+ }
90
+ } catch (e) {
91
+ // Config file doesn't exist or is invalid — fall through
92
+ }
93
+
94
+ // 3. Default
95
+ return DEFAULT_MODE;
96
+ }
97
+
98
+ function writeDefaultMode(mode) {
99
+ const normalized = normalizeConfigMode(mode);
100
+ if (!normalized) return null;
101
+
102
+ const configPath = getConfigPath();
103
+ fs.mkdirSync(path.dirname(configPath), { recursive: true });
104
+ fs.writeFileSync(configPath, JSON.stringify({ defaultMode: normalized }, null, 2), 'utf8');
105
+ return normalized;
106
+ }
107
+
108
+ module.exports = {
109
+ DEFAULT_MODE,
110
+ VALID_MODES,
111
+ RUNTIME_MODES,
112
+ getDefaultMode,
113
+ getConfigDir,
114
+ getConfigPath,
115
+ getClaudeDir,
116
+ isShellSafe,
117
+ normalizeMode,
118
+ normalizeConfigMode,
119
+ normalizePersistedMode,
120
+ isDeactivationCommand,
121
+ writeDefaultMode,
122
+ };
@@ -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
+ });