hail-hydra-cc 2.4.1 → 2.4.2
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/files/hooks/hydra-token-math.js +179 -163
- package/package.json +58 -58
|
@@ -1,163 +1,179 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Shared helper: parse Claude Code session JSONL, compute per-tier usage,
|
|
4
|
-
// actual cost, and savings vs all-Opus baseline.
|
|
5
|
-
//
|
|
6
|
-
// Used by:
|
|
7
|
-
// - hooks/hydra-statusline.js (cached, every statusline refresh)
|
|
8
|
-
// - commands/hydra/stats.md (fresh, on /hydra:stats invocation)
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const os = require('os');
|
|
13
|
-
|
|
14
|
-
const PRICING = {
|
|
15
|
-
'claude-haiku-4': { input: 1, output: 5 },
|
|
16
|
-
'claude-sonnet-4': { input: 3, output: 15 },
|
|
17
|
-
'claude-opus-4': { input: 5, output: 25 }
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function getPrice(model) {
|
|
21
|
-
for (const prefix in PRICING) {
|
|
22
|
-
if (model.startsWith(prefix)) return PRICING[prefix];
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getTier(model) {
|
|
28
|
-
if (model.startsWith('claude-haiku')) return 'haiku';
|
|
29
|
-
if (model.startsWith('claude-sonnet')) return 'sonnet';
|
|
30
|
-
if (model.startsWith('claude-opus')) return 'opus';
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function findActiveSessionFile() {
|
|
35
|
-
try {
|
|
36
|
-
const configDir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
|
37
|
-
const projectsDir = path.join(configDir, 'projects');
|
|
38
|
-
if (!fs.existsSync(projectsDir)) return null;
|
|
39
|
-
|
|
40
|
-
const cwd = process.cwd();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Shared helper: parse Claude Code session JSONL, compute per-tier usage,
|
|
4
|
+
// actual cost, and savings vs all-Opus baseline.
|
|
5
|
+
//
|
|
6
|
+
// Used by:
|
|
7
|
+
// - hooks/hydra-statusline.js (cached, every statusline refresh)
|
|
8
|
+
// - commands/hydra/stats.md (fresh, on /hydra:stats invocation)
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const os = require('os');
|
|
13
|
+
|
|
14
|
+
const PRICING = {
|
|
15
|
+
'claude-haiku-4': { input: 1, output: 5 },
|
|
16
|
+
'claude-sonnet-4': { input: 3, output: 15 },
|
|
17
|
+
'claude-opus-4': { input: 5, output: 25 }
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function getPrice(model) {
|
|
21
|
+
for (const prefix in PRICING) {
|
|
22
|
+
if (model.startsWith(prefix)) return PRICING[prefix];
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getTier(model) {
|
|
28
|
+
if (model.startsWith('claude-haiku')) return 'haiku';
|
|
29
|
+
if (model.startsWith('claude-sonnet')) return 'sonnet';
|
|
30
|
+
if (model.startsWith('claude-opus')) return 'opus';
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function findActiveSessionFile() {
|
|
35
|
+
try {
|
|
36
|
+
const configDir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
|
37
|
+
const projectsDir = path.join(configDir, 'projects');
|
|
38
|
+
if (!fs.existsSync(projectsDir)) return null;
|
|
39
|
+
|
|
40
|
+
const cwd = process.cwd();
|
|
41
|
+
// Claude Code names project dirs by replacing every non-alphanumeric char
|
|
42
|
+
// (including the leading separator) with '-'. Match that exactly — do NOT
|
|
43
|
+
// strip the leading dash, or exact matches fail for underscore/special paths.
|
|
44
|
+
const slug = cwd.replace(/[^a-zA-Z0-9-]/g, '-');
|
|
45
|
+
|
|
46
|
+
let sessionDir = path.join(projectsDir, slug);
|
|
47
|
+
if (!fs.existsSync(sessionDir)) {
|
|
48
|
+
const all = fs.readdirSync(projectsDir);
|
|
49
|
+
// Normalize basename the same way (underscores/specials → dashes) so the
|
|
50
|
+
// endsWith fallback compares like-for-like.
|
|
51
|
+
const baseSlug = path.basename(cwd).replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase();
|
|
52
|
+
const match = all.find(d => d === slug)
|
|
53
|
+
|| all.find(d => d.toLowerCase() === slug.toLowerCase())
|
|
54
|
+
|| all.find(d => d.toLowerCase().endsWith(baseSlug));
|
|
55
|
+
if (!match) {
|
|
56
|
+
if (process.env.HYDRA_DEBUG === '1') {
|
|
57
|
+
console.error('[hydra-token-math] No session dir matched.');
|
|
58
|
+
console.error(' cwd:', cwd);
|
|
59
|
+
console.error(' computed slug:', slug);
|
|
60
|
+
console.error(' projects dir contents:',
|
|
61
|
+
fs.existsSync(projectsDir) ? fs.readdirSync(projectsDir).slice(0, 10) : '(none)');
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
sessionDir = path.join(projectsDir, match);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const files = fs.readdirSync(sessionDir)
|
|
69
|
+
.filter(f => f.endsWith('.jsonl'))
|
|
70
|
+
.map(f => ({ p: path.join(sessionDir, f), m: fs.statSync(path.join(sessionDir, f)).mtimeMs }))
|
|
71
|
+
.sort((a, b) => b.m - a.m);
|
|
72
|
+
|
|
73
|
+
return files.length > 0 ? files[0].p : null;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function parseSession(sessionFile) {
|
|
80
|
+
const stats = {
|
|
81
|
+
haiku: { input: 0, output: 0, cache_read: 0, cache_create: 0, turns: 0 },
|
|
82
|
+
sonnet: { input: 0, output: 0, cache_read: 0, cache_create: 0, turns: 0 },
|
|
83
|
+
opus: { input: 0, output: 0, cache_read: 0, cache_create: 0, turns: 0 }
|
|
84
|
+
};
|
|
85
|
+
const unknownModels = new Set();
|
|
86
|
+
let totalTurns = 0;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const lines = fs.readFileSync(sessionFile, 'utf8').split('\n').filter(Boolean);
|
|
90
|
+
for (const line of lines) {
|
|
91
|
+
try {
|
|
92
|
+
const obj = JSON.parse(line);
|
|
93
|
+
if (obj.type !== 'assistant' || !obj.message || !obj.message.usage) continue;
|
|
94
|
+
const model = obj.message.model || '';
|
|
95
|
+
const tier = getTier(model);
|
|
96
|
+
if (!tier) { if (model) unknownModels.add(model); continue; }
|
|
97
|
+
const u = obj.message.usage;
|
|
98
|
+
stats[tier].input += u.input_tokens || 0;
|
|
99
|
+
stats[tier].output += u.output_tokens || 0;
|
|
100
|
+
stats[tier].cache_read += u.cache_read_input_tokens || 0;
|
|
101
|
+
stats[tier].cache_create += u.cache_creation_input_tokens || 0;
|
|
102
|
+
stats[tier].turns += 1;
|
|
103
|
+
totalTurns += 1;
|
|
104
|
+
} catch (e) { /* skip malformed line */ }
|
|
105
|
+
}
|
|
106
|
+
} catch (e) { /* file unreadable */ }
|
|
107
|
+
|
|
108
|
+
return { stats, totalTurns, unknownModels };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function tierCost(s, p) {
|
|
112
|
+
if (!p) return 0;
|
|
113
|
+
const inputCost = ((s.input + s.cache_create) * p.input) / 1_000_000;
|
|
114
|
+
const cacheReadCost = (s.cache_read * p.input * 0.1) / 1_000_000;
|
|
115
|
+
const outputCost = (s.output * p.output) / 1_000_000;
|
|
116
|
+
return inputCost + cacheReadCost + outputCost;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function asOpusCost(s) {
|
|
120
|
+
return tierCost(s, PRICING['claude-opus-4']);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function computeSummary() {
|
|
124
|
+
const sessionFile = findActiveSessionFile();
|
|
125
|
+
if (!sessionFile) return { available: false };
|
|
126
|
+
|
|
127
|
+
const { stats, totalTurns, unknownModels } = parseSession(sessionFile);
|
|
128
|
+
if (totalTurns === 0) return { available: false };
|
|
129
|
+
|
|
130
|
+
const haikuCost = tierCost(stats.haiku, PRICING['claude-haiku-4']);
|
|
131
|
+
const sonnetCost = tierCost(stats.sonnet, PRICING['claude-sonnet-4']);
|
|
132
|
+
const opusCost = tierCost(stats.opus, PRICING['claude-opus-4']);
|
|
133
|
+
const actualCost = haikuCost + sonnetCost + opusCost;
|
|
134
|
+
|
|
135
|
+
const hypotheticalCost =
|
|
136
|
+
asOpusCost(stats.haiku) + asOpusCost(stats.sonnet) + asOpusCost(stats.opus);
|
|
137
|
+
|
|
138
|
+
const savedUSD = Math.max(0, hypotheticalCost - actualCost);
|
|
139
|
+
const savedPct = hypotheticalCost > 0 ? (savedUSD / hypotheticalCost) * 100 : 0;
|
|
140
|
+
|
|
141
|
+
const delegatedTurns = stats.haiku.turns + stats.sonnet.turns;
|
|
142
|
+
const delegationRate = totalTurns > 0 ? (delegatedTurns / totalTurns) * 100 : 0;
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
available: true,
|
|
146
|
+
sessionFile,
|
|
147
|
+
totalTurns,
|
|
148
|
+
stats,
|
|
149
|
+
haikuCost, sonnetCost, opusCost,
|
|
150
|
+
actualCost, hypotheticalCost,
|
|
151
|
+
savedUSD, savedPct,
|
|
152
|
+
delegatedTurns, delegationRate,
|
|
153
|
+
unknownModels
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let _cache = null;
|
|
158
|
+
let _cacheExpiry = 0;
|
|
159
|
+
const CACHE_TTL_MS = 15000;
|
|
160
|
+
|
|
161
|
+
function computeSummaryCached() {
|
|
162
|
+
const now = Date.now();
|
|
163
|
+
if (_cache && now < _cacheExpiry) return _cache;
|
|
164
|
+
_cache = computeSummary();
|
|
165
|
+
_cacheExpiry = now + CACHE_TTL_MS;
|
|
166
|
+
return _cache;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = {
|
|
170
|
+
computeSummary,
|
|
171
|
+
computeSummaryCached,
|
|
172
|
+
parseSession,
|
|
173
|
+
findActiveSessionFile,
|
|
174
|
+
tierCost,
|
|
175
|
+
asOpusCost,
|
|
176
|
+
getTier,
|
|
177
|
+
getPrice,
|
|
178
|
+
PRICING
|
|
179
|
+
};
|
package/package.json
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "hail-hydra-cc",
|
|
3
|
-
"version": "2.4.
|
|
4
|
-
"description": "Multi-agent orchestration framework for Claude Code. Routes tasks to specialized Haiku/Sonnet subagents while Opus orchestrates — inspired by speculative decoding. ~50% API cost reduction.",
|
|
5
|
-
"bin": {
|
|
6
|
-
"hail-hydra-cc": "bin/cli.js"
|
|
7
|
-
},
|
|
8
|
-
"main": "./src/installer.js",
|
|
9
|
-
"engines": {
|
|
10
|
-
"node": ">=16.0.0"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"chalk": "^4.1.2",
|
|
14
|
-
"commander": "^11.1.0",
|
|
15
|
-
"inquirer": "^8.2.6"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"claude-code",
|
|
19
|
-
"ai-agents",
|
|
20
|
-
"multi-agent",
|
|
21
|
-
"orchestration",
|
|
22
|
-
"speculative-decoding",
|
|
23
|
-
"subagents",
|
|
24
|
-
"claude",
|
|
25
|
-
"anthropic",
|
|
26
|
-
"ai-coding",
|
|
27
|
-
"developer-tools",
|
|
28
|
-
"code-review",
|
|
29
|
-
"haiku",
|
|
30
|
-
"sonnet",
|
|
31
|
-
"opus",
|
|
32
|
-
"cost-optimization",
|
|
33
|
-
"token-savings",
|
|
34
|
-
"ai-framework",
|
|
35
|
-
"claude-subagents",
|
|
36
|
-
"coding-agent",
|
|
37
|
-
"agent-orchestration",
|
|
38
|
-
"hydra"
|
|
39
|
-
],
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"repository": {
|
|
42
|
-
"type": "git",
|
|
43
|
-
"url": "git+https://github.com/AR6420/Hail_Hydra.git"
|
|
44
|
-
},
|
|
45
|
-
"homepage": "https://github.com/AR6420/Hail_Hydra#readme",
|
|
46
|
-
"bugs": {
|
|
47
|
-
"url": "https://github.com/AR6420/Hail_Hydra/issues"
|
|
48
|
-
},
|
|
49
|
-
"files": [
|
|
50
|
-
"bin/",
|
|
51
|
-
"src/",
|
|
52
|
-
"files/"
|
|
53
|
-
],
|
|
54
|
-
"publishConfig": {
|
|
55
|
-
"registry": "https://registry.npmjs.org/",
|
|
56
|
-
"access": "public"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "hail-hydra-cc",
|
|
3
|
+
"version": "2.4.2",
|
|
4
|
+
"description": "Multi-agent orchestration framework for Claude Code. Routes tasks to specialized Haiku/Sonnet subagents while Opus orchestrates — inspired by speculative decoding. ~50% API cost reduction.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"hail-hydra-cc": "bin/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "./src/installer.js",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=16.0.0"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"chalk": "^4.1.2",
|
|
14
|
+
"commander": "^11.1.0",
|
|
15
|
+
"inquirer": "^8.2.6"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"claude-code",
|
|
19
|
+
"ai-agents",
|
|
20
|
+
"multi-agent",
|
|
21
|
+
"orchestration",
|
|
22
|
+
"speculative-decoding",
|
|
23
|
+
"subagents",
|
|
24
|
+
"claude",
|
|
25
|
+
"anthropic",
|
|
26
|
+
"ai-coding",
|
|
27
|
+
"developer-tools",
|
|
28
|
+
"code-review",
|
|
29
|
+
"haiku",
|
|
30
|
+
"sonnet",
|
|
31
|
+
"opus",
|
|
32
|
+
"cost-optimization",
|
|
33
|
+
"token-savings",
|
|
34
|
+
"ai-framework",
|
|
35
|
+
"claude-subagents",
|
|
36
|
+
"coding-agent",
|
|
37
|
+
"agent-orchestration",
|
|
38
|
+
"hydra"
|
|
39
|
+
],
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/AR6420/Hail_Hydra.git"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/AR6420/Hail_Hydra#readme",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/AR6420/Hail_Hydra/issues"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"bin/",
|
|
51
|
+
"src/",
|
|
52
|
+
"files/"
|
|
53
|
+
],
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"registry": "https://registry.npmjs.org/",
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|