hydra-nano 0.3.2 → 0.3.3
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/package.json +1 -1
- package/skills/hydra/scripts/install.mjs +4 -1
- package/skills/hydra/scripts/lib/answer.mjs +3 -1
- package/skills/hydra/scripts/lib/bootstrap.mjs +2 -1
- package/skills/hydra/scripts/lib/git.mjs +58 -8
- package/skills/hydra/scripts/lib/integrations.mjs +2 -0
- package/skills/hydra/scripts/lib/ledger.mjs +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hydra-nano",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Small local models that take the noisy work off your coding agent: git history, test and build digests and OS inspection run on your machine, and only the lines that matter reach Claude Code, Codex, Cursor, OpenCode, Gemini CLI or Antigravity. Skill, MCP server and hooks.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -10,6 +10,8 @@ import { claudeDir, installHooks } from './lib/claude_hooks.mjs';
|
|
|
10
10
|
import * as integrations from './lib/integrations.mjs';
|
|
11
11
|
|
|
12
12
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
// The skills.sh CLI version the installer runs; 1.7.6 was checked to take --skill, --agent, --global and --yes.
|
|
14
|
+
const SKILLS_CLI = '1.7.6';
|
|
13
15
|
try {
|
|
14
16
|
if (Number(process.versions.node.split('.')[0]) < 18) throw new Error('Node 18 or newer is required');
|
|
15
17
|
const manifest = JSON.parse(readFileSync(path.join(here, 'runtime-manifest.json'), 'utf8'));
|
|
@@ -31,8 +33,9 @@ The server stays running until stopped or the computer restarts. Download time d
|
|
|
31
33
|
if (!process.argv.includes('--runtime-only')) {
|
|
32
34
|
const npx = findNpx();
|
|
33
35
|
if (!npx) throw new Error('Cannot locate npm npx-cli.js; install Node with npm or use --runtime-only');
|
|
36
|
+
// A pinned skills CLI: `npx --yes` would otherwise run whatever version is newest on the registry today.
|
|
34
37
|
for (const agent of agents) {
|
|
35
|
-
execFileSync(process.execPath, [npx, '--yes',
|
|
38
|
+
execFileSync(process.execPath, [npx, '--yes', `--package=skills@${SKILLS_CLI}`, 'skills', 'add', path.resolve(here, '..'), '--skill', 'hydra', '--agent', agent, '--global', '--yes'], { stdio: 'inherit' });
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
const config = await installRuntime(manifest);
|
|
@@ -72,7 +72,9 @@ export async function answer(question, sections, chat) {
|
|
|
72
72
|
return { text: `$ ${sections[0].cmd}\n${out}`, rawChars };
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
// A blame cut to the asked lines (-L, at most 100) is the answer itself.
|
|
76
|
+
const complete = section => COMPLETE_PROBES.has(section.probe) || (section.probe === 'blame' && Boolean(section.args?.lines));
|
|
77
|
+
if (rawChars <= PASS_THROUGH || sections.every(complete)) {
|
|
76
78
|
return { text: sections.map(section => `$ ${section.cmd}\n${section.out.trimEnd()}`).join('\n\n'), rawChars };
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -7,7 +7,8 @@ import path from 'node:path';
|
|
|
7
7
|
import { home, localConfig, stopLocal } from './local.mjs';
|
|
8
8
|
|
|
9
9
|
export function findNpx(dirs = [path.dirname(process.execPath), ...(process.env.PATH || '').split(path.delimiter)]) {
|
|
10
|
-
|
|
10
|
+
// An empty or relative PATH entry means "the current directory", where a project could plant its own npx.
|
|
11
|
+
for (const dir of dirs.filter(dir => dir && path.isAbsolute(dir))) {
|
|
11
12
|
for (const relative of ['node_modules/npm/bin/npx-cli.js', '../lib/node_modules/npm/bin/npx-cli.js', '../share/nodejs/npm/bin/npx-cli.js', 'npx']) {
|
|
12
13
|
const file = path.resolve(dir, relative);
|
|
13
14
|
if (existsSync(file)) {
|
|
@@ -55,10 +55,19 @@ const subjectTerm = question => (question.match(/\bwith\s+["'`]?([\w.-]+)["'`]?\
|
|
|
55
55
|
// "messages that mention main": the question searches message text for this word.
|
|
56
56
|
const searchesFor = (question, term) => subjectTerm(question)?.toLowerCase() === term.toLowerCase()
|
|
57
57
|
|| new RegExp(`\\b(?:mention\\w*|contain\\w*|says?|saying)\\s+["'\`]?${term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\w.-])`, 'i').test(question);
|
|
58
|
+
// "line 16", "lines 10-20", "lines 10 to 20" or "src/app.js:16": the lines of one file a question is about.
|
|
59
|
+
// Built from the question's own digits, never from the model; a range over 100 lines keeps the whole-file blame.
|
|
60
|
+
const MAX_BLAME_LINES = 100;
|
|
61
|
+
const lineRange = question => {
|
|
62
|
+
const m = question.match(/\blines?\s+(\d{1,6})(?:\s*(?:-|–|to|through)\s*(\d{1,6}))?\b/i) ?? question.match(/[\w.-]:(\d{1,6})(?:-(\d{1,6}))?\b/);
|
|
63
|
+
if (!m) return null;
|
|
64
|
+
const start = Number(m[1]), end = m[2] ? Number(m[2]) : start;
|
|
65
|
+
return start >= 1 && end >= start && end - start < MAX_BLAME_LINES ? `${start},${end}` : null;
|
|
66
|
+
};
|
|
58
67
|
// The first word of the question that is a file inside the repository, e.g. src/app.ts or Makefile.
|
|
59
68
|
function fileInQuestion(question, cwd) {
|
|
60
69
|
for (const word of question.split(/\s+/)) {
|
|
61
|
-
const name = word.replace(/^["'`(]+|["'`),;:!?]+$|\.$/g, '');
|
|
70
|
+
const name = word.replace(/^["'`(]+|["'`),;:!?]+$|\.$/g, '').replace(/:\d+(?:-\d+)?$/, '');
|
|
62
71
|
if (!name || name.startsWith('-') || path.isAbsolute(name)) continue;
|
|
63
72
|
const file = path.resolve(cwd, name), relative = path.relative(cwd, file);
|
|
64
73
|
if (!relative || relative.startsWith('..')) continue;
|
|
@@ -80,7 +89,18 @@ export async function git(cwd, argv) {
|
|
|
80
89
|
return { ok: r.ok, out: r.out || r.err };
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
|
|
92
|
+
// "master..origin/master" or "main...feature": a range the question writes out. Kept as written once git
|
|
93
|
+
// resolves both ends to commits; the log probe's own base..HEAD cannot say a range that does not end at HEAD.
|
|
94
|
+
async function explicitRange(question, cwd) {
|
|
95
|
+
const m = question.match(/(?:^|[\s(`'"])([\w./@^~{}-]+?)(\.{2,3})([\w./@^~{}-]*[\w/@^~{}-])/);
|
|
96
|
+
if (!m || m[1].startsWith('-') || m[3].startsWith('-')) return null;
|
|
97
|
+
for (const end of [m[1], m[3]]) {
|
|
98
|
+
if (!(await git(cwd, ['rev-parse', '--verify', '--quiet', `${end}^{commit}`])).ok) return null;
|
|
99
|
+
}
|
|
100
|
+
return `${m[1]}${m[2]}${m[3]}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const inRepo = async cwd =>(await git(cwd, ['rev-parse', '--is-inside-work-tree'])).out.trim() === 'true';
|
|
84
104
|
|
|
85
105
|
// The model picks from this menu and never writes a command. Every entry is read-only.
|
|
86
106
|
export const PROBES = {
|
|
@@ -98,7 +118,7 @@ export const PROBES = {
|
|
|
98
118
|
...(a.author || a.grep ? ['-i', '--fixed-strings'] : []),
|
|
99
119
|
...(a.author ? [`--author=${a.author}`] : []),
|
|
100
120
|
...(a.grep ? [`--grep=${a.grep}`] : []),
|
|
101
|
-
...(a.base ? [`${a.base}..HEAD`] : []),
|
|
121
|
+
...(a.range ? [a.range] : a.base ? [`${a.base}..HEAD`] : []),
|
|
102
122
|
...(a.path ? ['--', a.path] : []),
|
|
103
123
|
],
|
|
104
124
|
},
|
|
@@ -108,7 +128,7 @@ export const PROBES = {
|
|
|
108
128
|
argv: a => [
|
|
109
129
|
'diff',
|
|
110
130
|
...PATCH,
|
|
111
|
-
...(a.base ? [`${a.base}...HEAD`] : a.staged ? ['--staged'] : a.worktreeOnly ? [] : ['HEAD']),
|
|
131
|
+
...(a.range ? [a.range] : a.base ? [`${a.base}...HEAD`] : a.staged ? ['--staged'] : a.worktreeOnly ? [] : ['HEAD']),
|
|
112
132
|
...(a.path ? ['--', a.path] : []),
|
|
113
133
|
],
|
|
114
134
|
},
|
|
@@ -119,7 +139,7 @@ export const PROBES = {
|
|
|
119
139
|
blame: {
|
|
120
140
|
about: 'line-by-line attribution of who wrote each specific line of a file (not for whole-file history); needs path',
|
|
121
141
|
needs: 'path',
|
|
122
|
-
argv: a => ['blame', '--no-textconv', '--date=short', '--', a.path],
|
|
142
|
+
argv: a => ['blame', '--no-textconv', '--date=short', ...(a.lines ? ['-L', a.lines] : []), '--', a.path],
|
|
123
143
|
},
|
|
124
144
|
branches: {
|
|
125
145
|
about: 'local and remote branches with their latest commit',
|
|
@@ -185,7 +205,7 @@ Examples:
|
|
|
185
205
|
"commits present here but absent from main" -> {"probes":[{"probe":"log","base":"main","n":50}]}`;
|
|
186
206
|
|
|
187
207
|
// The model's arguments are untrusted: keep a value only when the question itself names it and git can confirm it.
|
|
188
|
-
async function clean(p, question, cwd) {
|
|
208
|
+
async function clean(p, question, cwd, range) {
|
|
189
209
|
const asked = question.toLowerCase();
|
|
190
210
|
const safe = s => typeof s === 'string' && s.trim() !== '' && !s.trim().startsWith('-') && asked.includes(s.trim().toLowerCase());
|
|
191
211
|
const a = { n: Number.isInteger(p.n) ? Math.min(Math.max(p.n, 1), 50) : 15, staged: false };
|
|
@@ -210,6 +230,8 @@ async function clean(p, question, cwd) {
|
|
|
210
230
|
existsSync(path.resolve(cwd, file)) || (await git(cwd, ['log', '-1', '--format=%h', '--', file])).out.trim();
|
|
211
231
|
if (known) a.path = file;
|
|
212
232
|
}
|
|
233
|
+
// The lines to blame are the caller's, read from the question like a count.
|
|
234
|
+
if (p.probe === 'blame' && a.path && lineRange(question)) a.lines = lineRange(question);
|
|
213
235
|
// A validated file named staged.js or index.txt is not a staging request.
|
|
214
236
|
const { index: asksIndex, unstaged: asksUnstaged } = scope(asked, a.path);
|
|
215
237
|
const asksBoth = asksUnstaged && asksIndex;
|
|
@@ -240,6 +262,14 @@ async function clean(p, question, cwd) {
|
|
|
240
262
|
}
|
|
241
263
|
// Commits this branch has over its base form a bounded set; return it whole unless a count was asked for.
|
|
242
264
|
if (p.probe === 'log' && a.base && requestedCount(question) === null) a.n = 50;
|
|
265
|
+
// The question's own range replaces any base the model or the fallback chose; it is just as bounded.
|
|
266
|
+
if (range && ['log', 'diff'].includes(p.probe)) {
|
|
267
|
+
delete a.base;
|
|
268
|
+
a.range = range;
|
|
269
|
+
// "what themes stand out in A..B" asks about the range, not for commits whose message says "themes".
|
|
270
|
+
if (a.grep && !asksMessage && !searchesFor(question, a.grep)) delete a.grep;
|
|
271
|
+
if (p.probe === 'log' && requestedCount(question) === null) a.n = 50;
|
|
272
|
+
}
|
|
243
273
|
return a;
|
|
244
274
|
}
|
|
245
275
|
|
|
@@ -265,6 +295,20 @@ export async function gather(question, cwd, chat) {
|
|
|
265
295
|
if (currentBranchRequest(question) && !has('status', 'branches')) plan.push({ probe: 'status' });
|
|
266
296
|
if (syncRequest(question) && !has('status', 'branches')) plan.push({ probe: 'status' });
|
|
267
297
|
if (untrackedRequest(question) && !has('status')) plan.push({ probe: 'status' });
|
|
298
|
+
// "which commit last changed line 16 of x.js" is about that line, not the file's log: blame the line.
|
|
299
|
+
const lineFile = lineRange(question) && !pendingEditRequest(question) ? fileInQuestion(question, cwd) ?? named : null;
|
|
300
|
+
if (lineFile) {
|
|
301
|
+
plan = plan.filter(p => !(p.probe === 'log' && (!p.path || p.path === lineFile)) && !(p.probe === 'show' && !p.rev) && !(p.probe === 'diff' && !p.base))
|
|
302
|
+
.map(p => (p.probe === 'blame' ? { ...p, path: lineFile } : p));
|
|
303
|
+
if (!has('blame')) plan.push({ probe: 'blame', path: lineFile });
|
|
304
|
+
}
|
|
305
|
+
const range = await explicitRange(question, cwd);
|
|
306
|
+
if (range) {
|
|
307
|
+
// HEAD's own patch says nothing about a range that the question wrote out.
|
|
308
|
+
plan = plan.filter(p => !(p.probe === 'show' && !p.rev));
|
|
309
|
+
// Files or a patch, or a three-dot range, read as a diff; anything else lists the range's commits.
|
|
310
|
+
if (!has('log', 'diff')) plan.push({ probe: range.includes('...') || /\b(?:files?|paths?|patch|touch\w*|diff\w*)\b/i.test(question) ? 'diff' : 'log' });
|
|
311
|
+
}
|
|
268
312
|
if (historyRequest(question) && named && !has('log', 'blame')) {
|
|
269
313
|
plan = plan.filter(p => !((p.probe === 'show' && !p.rev) || (p.probe === 'diff' && !p.base)));
|
|
270
314
|
plan.push({ probe: 'log', path: named });
|
|
@@ -277,7 +321,7 @@ export async function gather(question, cwd, chat) {
|
|
|
277
321
|
|
|
278
322
|
const chosen = new Map();
|
|
279
323
|
for (const p of plan) {
|
|
280
|
-
const args = await clean(p, question, cwd);
|
|
324
|
+
const args = await clean(p, question, cwd, range);
|
|
281
325
|
if (PROBES[p.probe].needs && !args[PROBES[p.probe].needs]) continue;
|
|
282
326
|
chosen.set(PROBES[p.probe].argv(args).join(' '), { probe: p.probe, args });
|
|
283
327
|
}
|
|
@@ -286,7 +330,13 @@ export async function gather(question, cwd, chat) {
|
|
|
286
330
|
return Promise.all(
|
|
287
331
|
[...chosen.values()].map(async ({ probe, args }) => {
|
|
288
332
|
const argv = PROBES[probe].argv(args);
|
|
289
|
-
|
|
333
|
+
const out = (await git(cwd, argv)).out || '(no output)';
|
|
334
|
+
// A range the question named is a set the caller asked for whole; say so when the count cap cut it.
|
|
335
|
+
if (probe === 'log' && args.range && out.trimEnd().split('\n').length >= args.n) {
|
|
336
|
+
const total = Number((await git(cwd, ['rev-list', '--count', ...argv.filter(arg => arg !== 'log' && !FORMAT.includes(arg) && !/^-n\d+$/.test(arg))])).out.trim());
|
|
337
|
+
if (total > args.n) return { probe, args, cmd: shown(argv), out: `${out.trimEnd()}\n(${args.n} of ${total} commits in ${args.range} shown; ask for a narrower range or a path for the rest)` };
|
|
338
|
+
}
|
|
339
|
+
return { probe, args, cmd: shown(argv), out };
|
|
290
340
|
}),
|
|
291
341
|
);
|
|
292
342
|
}
|
|
@@ -84,6 +84,8 @@ function jsonServer(file, key, entry) {
|
|
|
84
84
|
install() {
|
|
85
85
|
const snippet = JSON.stringify({ [key]: { hydra: entry } }, null, 2);
|
|
86
86
|
const settings = loadJson(file, snippet);
|
|
87
|
+
// Someone else's server under the same name is theirs to rename, not ours to replace.
|
|
88
|
+
if (settings[key]?.hydra && !mentionsOurs(settings[key].hydra)) throw new Manual(file, snippet, `already has a ${key}.hydra entry that Hydra did not write`);
|
|
87
89
|
settings[key] = { ...(settings[key] ?? {}), hydra: entry };
|
|
88
90
|
saveJson(file, settings);
|
|
89
91
|
return `${file}: ${key}.hydra`;
|
|
@@ -36,11 +36,15 @@ export function caller(session = process.env.CLAUDE_CODE_SESSION_ID) {
|
|
|
36
36
|
// Switches worth keeping readable in `hydra improve`; every other NAME=value is treated as a possible secret.
|
|
37
37
|
const PLAIN = /^(?:HYDRA_\w+|CI|NODE_ENV|DEBUG|FORCE_COLOR|NO_COLOR)$/;
|
|
38
38
|
|
|
39
|
+
// A value ends at whitespace or a shell separator (so `A=x;B=y` masks both); one already masked stays as it is,
|
|
40
|
+
// so masking twice changes nothing.
|
|
41
|
+
const VALUE = String.raw`("[^"]*"|'[^']*'|\*\*\*(?=[\s;&|'"]|$)|[^\s;&|]+)`;
|
|
42
|
+
|
|
39
43
|
/** A command with credential values masked: env assignments, URL passwords and secret-named flags. */
|
|
40
44
|
export const redact = text => String(text)
|
|
41
45
|
.replace(/([a-z][\w+.-]*:\/\/)[^\s/@]+@/gi, '$1***@')
|
|
42
|
-
.replace(
|
|
43
|
-
.replace(
|
|
46
|
+
.replace(new RegExp(String.raw`(^|[\s;&|(])([A-Za-z_]\w*)=${VALUE}`, 'g'), (all, before, name) => (PLAIN.test(name) ? all : `${before}${name}=***`))
|
|
47
|
+
.replace(new RegExp(String.raw`(--?[\w-]*(?:token|password|passwd|secret|api[-_]?key|auth)[\w-]*)([ =])${VALUE}`, 'gi'), '$1$2***');
|
|
44
48
|
|
|
45
49
|
export function record(entry) {
|
|
46
50
|
if (!enabled()) return;
|