runhmd 0.0.0-stage → 2.4.6

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/README.md CHANGED
@@ -1,3 +1,65 @@
1
- # Temporary Holding Version
1
+ # runhmd
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Front door to [hmd](https://runheimdall.dev): one command, no setup.
4
+
5
+ ```bash
6
+ npx runhmd <path> # runs: hmd attack <path>
7
+ npx runhmd attack . # the same, spelled out
8
+ npx runhmd prove # any other hmd subcommand passes straight through
9
+ ```
10
+
11
+ `attack` is the default command. A first argument that is an hmd subcommand (the list is
12
+ `subcommands.txt`, kept in step with hmd's own dispatch by the repo's tests) passes through
13
+ untouched; anything else - a path, a PR URL, a flag such as `--json` - is a target for `attack`.
14
+ A directory that is named like a subcommand has to be spelled as a path: `npx runhmd ./team`.
15
+
16
+ `npx runhmd --version` and `npx runhmd --help` are answered by the wrapper itself: nothing is
17
+ fetched, installed or run.
18
+
19
+ ## First run
20
+
21
+ hmd has to be on the machine. `runhmd` looks for it on `PATH`, then in `~/.local/bin`, then in
22
+ `~/.heimdall/bin`. If it finds none - or finds one older than the hmd release this package is
23
+ pinned to (`runhmd --version` prints it) - it runs the pinned installer first:
24
+
25
+ 1. fetch `install.sh` for the pinned release tag,
26
+ 2. compute its sha256 and compare it with the checksum baked into this package at publish time,
27
+ 3. only if they are equal, hand it to `bash`.
28
+
29
+ A mismatch aborts before a single byte runs, and `runhmd` does not fall back to an hmd it
30
+ already found: this package runs the hmd it was published with, or nothing. An hmd newer than
31
+ the pin is never downgraded.
32
+
33
+ It is the installer `npx runheimdall` runs - same pin, same checks (the two wrappers' pinning
34
+ code is kept identical by `test/runhmd-parity.test.sh` in the repository) - so it writes the same
35
+ files: `~/.heimdall/`, `~/.local/bin/hmd`, a PATH line in your shell profile, Claude Code's
36
+ `settings.json`, and on macOS a nightly LaunchAgent (`HEIMDALL_NO_DREAM_SCHEDULE=1` skips it).
37
+ [What the installer writes](https://github.com/randomittin/heimdall#install) lists each one, and
38
+ `hmd uninstall` reverses them - for every subcommand except the two in the next section.
39
+
40
+ ## Zero footprint
41
+
42
+ `npx runhmd attack ...` and `npx runhmd demo --offline` are the trial path, so they leave nothing
43
+ behind. They run with `HOME` redirected into one temp dir, together with the overrides that would walk
44
+ past it (`HEIMDALL_HOME`, `CLAUDE_CONFIG_DIR`, `HEIMDALL_LAUNCH_AGENTS_DIR`, `HEIMDALL_TEAM_DIR`), and the
45
+ temp dir is removed when the command ends. If hmd has to be installed first, the same pinned, sha256-checked
46
+ installer runs there - from an empty work dir, with the nightly LaunchAgent off - and goes with it. Your shell
47
+ profile, `~/Library/LaunchAgents`, `~/.claude`, `~/.heimdall` and the repository you run it in are not touched.
48
+
49
+ A temp dir inside, or an `--out` aimed at, `~/.zshrc` (and its siblings), `~/Library/LaunchAgents` or
50
+ `~/.claude` is refused with exit 2 before anything runs. `demo --offline` makes no network call (and neither
51
+ does `attack`'s built-in engine). Because `HOME` moves, a toolchain shim that finds its versions through `$HOME`
52
+ (asdf, volta) needs its own `*_DIR`/`*_HOME` variable exported; the node running `runhmd` is kept first on `PATH`.
53
+ `test/zero-footprint.test.sh` in the repository is the proof. Every other subcommand (`team`, `update`, ...)
54
+ keeps the installer's normal footprint.
55
+
56
+ Prerequisites are hmd's own: Claude Code, git and `jq`. Node 16 or newer, and bash.
57
+
58
+ ## Two names
59
+
60
+ `runheimdall` installs hmd and stops. `runhmd` is the same verified install plus the default
61
+ command. Both are published from the same release and pin the same `install.sh`.
62
+
63
+ ## License
64
+
65
+ MIT
package/bin/runhmd.js ADDED
@@ -0,0 +1,476 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /*
5
+ * runhmd — npx front door to hmd.
6
+ *
7
+ * runhmd <path> runs hmd attack <path> (attack is the default command)
8
+ * runhmd <subcommand> … runs hmd <subcommand> … (any subcommand hmd itself dispatches)
9
+ * runhmd --version|--help answered here — nothing is installed, fetched or run
10
+ *
11
+ * hmd is located the way a shell (or the installer, which links it into ~/.local/bin) would
12
+ * have left it. If it is missing — or reports a release older than the one this package is
13
+ * pinned to — the pinned install.sh is fetched, its sha256 asserted against the checksum baked in
14
+ * at publish time, and only then handed to bash. That is the SAME installer, pin and check as
15
+ * `npx runheimdall` (packages/runheimdall/bin/runheimdall.js): the pinning code below is
16
+ * mirrored from it line for line, and test/runhmd-parity.test.sh fails when the two diverge.
17
+ *
18
+ * Trust model: we never run a single byte we did not first verify. The script is buffered
19
+ * fully, hashed, compared, and only then handed to bash. A mismatch (tampered CDN, wrong tag,
20
+ * truncated download) aborts before exec — and aborts the whole command: an hmd that happens to
21
+ * be installed already is NOT run as a fallback, because the point of the pin is that this
22
+ * package runs the hmd it was published with, or nothing.
23
+ *
24
+ * Offline-testable: set RUNHMD_INSTALL_SCRIPT to a local file path to use its bytes instead of
25
+ * fetching over the network. The sha256 assertion runs identically against the local bytes —
26
+ * point it at a file + a matching RUNHMD_SHA256 to prove the run path, or a mismatching one to
27
+ * prove the abort.
28
+ *
29
+ * Zero footprint: `attack` and `demo --offline` are the trial path - a stranger runs them once to see
30
+ * what runhmd does - so they leave nothing behind. They run with HOME (and every override that would
31
+ * walk past it: HEIMDALL_HOME, CLAUDE_CONFIG_DIR, HEIMDALL_LAUNCH_AGENTS_DIR, HEIMDALL_TEAM_DIR)
32
+ * redirected into one temp dir that is removed when the command ends; the pinned installer, if it has
33
+ * to run, installs there and runs from an empty work dir, with the LaunchAgent schedule off and Python
34
+ * bytecode writing off. A temp dir inside, or an --out aimed at, ~/.zshrc and its siblings,
35
+ * ~/Library/LaunchAgents or ~/.claude is refused with exit 2 before anything runs. Every other
36
+ * subcommand keeps the installer's normal footprint (see README). test/zero-footprint.test.sh proves it.
37
+ */
38
+
39
+ const fs = require('fs');
40
+ const os = require('os');
41
+ const path = require('path');
42
+ const crypto = require('crypto');
43
+ const { spawnSync } = require('child_process');
44
+
45
+ const pkg = require(path.join(__dirname, '..', 'package.json'));
46
+ const meta = pkg.heimdall || {};
47
+
48
+ // `URL` keeps runheimdall.js's name for the install URL so the two files stay line-for-line
49
+ // comparable. It shadows the global URL class, which fetchHttps therefore reaches through
50
+ // require('url') — the one sanctioned divergence (see test/runhmd-parity.test.sh).
51
+ const TAG = process.env.RUNHMD_TAG || meta.tag;
52
+ const URL = process.env.RUNHMD_INSTALL_URL || meta.installScriptUrl;
53
+ const EXPECTED_SHA = (process.env.RUNHMD_SHA256 || meta.sha256 || '').toLowerCase();
54
+ const LOCAL_OVERRIDE = process.env.RUNHMD_INSTALL_SCRIPT;
55
+ // The real home, read before zero-footprint mode redirects HOME; ZF is that mode's state (null = off).
56
+ const REAL_HOME = os.homedir();
57
+ let ZF = null;
58
+
59
+ function die(msg) {
60
+ process.stderr.write('runhmd: ' + msg + '\n');
61
+ process.exit(1);
62
+ }
63
+
64
+ // Narration of runhmd's own extra steps. Every such line carries ': note: ' so the parity test
65
+ // can tell it apart from the verification and refusal output, which must match runheimdall's.
66
+ function note(msg) {
67
+ process.stderr.write('runhmd: note: ' + msg + '\n');
68
+ }
69
+
70
+ // Exit 2 (usage/config) is the refusal code across the runhmd tools. die() stays exactly as
71
+ // runheimdall.js has it - the parity test compares it - so zero-footprint refusals use their own.
72
+ function refuse(msg) {
73
+ process.stderr.write('runhmd: ' + msg + '\n');
74
+ process.exit(2);
75
+ }
76
+
77
+ function sha256(buf) {
78
+ return crypto.createHash('sha256').update(buf).digest('hex');
79
+ }
80
+
81
+ // Read the install script bytes, either from a local override (offline tests)
82
+ // or by fetching the pinned-tag URL over HTTPS. Returns a Buffer.
83
+ function loadScript() {
84
+ if (LOCAL_OVERRIDE) {
85
+ if (!fs.existsSync(LOCAL_OVERRIDE)) {
86
+ die('RUNHMD_INSTALL_SCRIPT points at a missing file: ' + LOCAL_OVERRIDE);
87
+ }
88
+ return Promise.resolve(fs.readFileSync(LOCAL_OVERRIDE));
89
+ }
90
+ if (!URL) {
91
+ die('no install script URL configured (package.json heimdall.installScriptUrl is empty)');
92
+ }
93
+ return fetchHttps(URL);
94
+ }
95
+
96
+ function fetchHttps(url, redirects) {
97
+ redirects = redirects || 0;
98
+ if (redirects > 5) {
99
+ return Promise.reject(new Error('too many redirects fetching ' + url));
100
+ }
101
+ const https = require('https');
102
+ return new Promise(function (resolve, reject) {
103
+ const req = https.get(url, { headers: { 'User-Agent': 'runhmd/' + pkg.version } }, function (res) {
104
+ const status = res.statusCode || 0;
105
+ // Follow the 302 (runheimdall.dev/install) and any GitHub raw redirects.
106
+ if (status >= 300 && status < 400 && res.headers.location) {
107
+ res.resume();
108
+ const next = new (require('url').URL)(res.headers.location, url).toString();
109
+ resolve(fetchHttps(next, redirects + 1));
110
+ return;
111
+ }
112
+ if (status !== 200) {
113
+ res.resume();
114
+ reject(new Error('HTTP ' + status + ' fetching ' + url));
115
+ return;
116
+ }
117
+ const chunks = [];
118
+ res.on('data', function (c) { chunks.push(c); });
119
+ res.on('end', function () { resolve(Buffer.concat(chunks)); });
120
+ res.on('error', reject);
121
+ });
122
+ req.on('error', reject);
123
+ req.setTimeout(30000, function () {
124
+ req.destroy(new Error('timed out fetching ' + url));
125
+ });
126
+ });
127
+ }
128
+
129
+ // The two guards that run before anything else: a wrapper whose pin is missing, still the
130
+ // publish-time placeholder, or not a sha256 was not built by release/sync-release.sh and is
131
+ // not trusted to run anything at all — not the installer, and not an hmd that is already there.
132
+ function assertPinWellFormed() {
133
+ if (!EXPECTED_SHA || EXPECTED_SHA === 'replace_at_publish') {
134
+ die('no published checksum baked in — this wrapper was not built by release/sync-release.sh. Refusing to run an unverified script.');
135
+ }
136
+ if (!/^[0-9a-f]{64}$/.test(EXPECTED_SHA)) {
137
+ die('configured sha256 is not a 64-char hex digest: ' + EXPECTED_SHA);
138
+ }
139
+ }
140
+
141
+ // Fetch (or read) the install script and assert its sha256 against the pin. Resolves with the
142
+ // verified bytes; dies on a mismatch before anything has been executed.
143
+ function verifiedScript() {
144
+ return loadScript().then(function (buf) {
145
+ const actual = sha256(buf);
146
+ if (actual !== EXPECTED_SHA) {
147
+ die(
148
+ 'checksum mismatch — refusing to run.\n' +
149
+ ' tag: ' + (TAG || '(unknown)') + '\n' +
150
+ ' source: ' + (LOCAL_OVERRIDE || URL) + '\n' +
151
+ ' expected: ' + EXPECTED_SHA + '\n' +
152
+ ' actual: ' + actual
153
+ );
154
+ }
155
+ process.stderr.write('runhmd: verified install.sh (' + (TAG || 'pinned') + ', sha256 ' + actual.slice(0, 12) + '…) — running.\n');
156
+ return buf;
157
+ });
158
+ }
159
+
160
+ // Hand the verified script to bash and return its exit status. The buffer goes to a temp file
161
+ // (bash needs a path for $0 to be meaningful), and the file is removed whatever happens. The
162
+ // installer gets NO arguments: runhmd's arguments are for hmd.
163
+ function runScript(buf) {
164
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'runhmd-'));
165
+ const scriptPath = path.join(tmpDir, 'install.sh');
166
+ fs.writeFileSync(scriptPath, buf, { mode: 0o700 });
167
+ let result;
168
+ try {
169
+ result = spawnSync('bash', [scriptPath], { stdio: 'inherit', env: process.env, cwd: ZF ? ZF.work : undefined });
170
+ } finally {
171
+ try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch (e) { /* best effort cleanup */ }
172
+ }
173
+ if (result.error) {
174
+ die('failed to run installer: ' + result.error.message);
175
+ }
176
+ if (typeof result.status !== 'number') {
177
+ die('installer terminated by signal ' + result.signal);
178
+ }
179
+ return result.status;
180
+ }
181
+
182
+ // ── routing ──────────────────────────────────────────────────────────────────
183
+
184
+ // The subcommands hmd itself dispatches: subcommands.txt, one word per line, #-comments.
185
+ function loadSubcommands() {
186
+ let text;
187
+ try {
188
+ text = fs.readFileSync(path.join(__dirname, '..', 'subcommands.txt'), 'utf8');
189
+ } catch (e) {
190
+ die('cannot read subcommands.txt (' + e.message + ') — without it runhmd cannot tell a subcommand from a path');
191
+ }
192
+ const words = text.split('\n')
193
+ .map(function (line) { return line.trim(); })
194
+ .filter(function (line) { return line !== '' && line.charAt(0) !== '#'; });
195
+ if (words.length === 0) {
196
+ die('subcommands.txt lists no subcommands — without it runhmd cannot tell a subcommand from a path');
197
+ }
198
+ return new Set(words);
199
+ }
200
+
201
+ function defaultCommand() {
202
+ if (!meta.defaultCommand) {
203
+ die('package.json heimdall.defaultCommand is not set — there is nothing to run for a bare path');
204
+ }
205
+ return meta.defaultCommand;
206
+ }
207
+
208
+ // A first argument that is an hmd subcommand passes through untouched; anything else — a path,
209
+ // a PR URL, a flag, nothing at all — is a target for the default command.
210
+ function route(args, subcommands, dflt) {
211
+ if (args.length > 0 && subcommands.has(args[0])) {
212
+ return args;
213
+ }
214
+ return [dflt].concat(args);
215
+ }
216
+
217
+ // ── zero-footprint mode ──────────────────────────────────────────────────────
218
+
219
+ // What a trial run must never touch in the real home: the shell profiles the installer appends its
220
+ // PATH line to, LaunchAgents (a HOME redirect does not isolate launchd), and Claude Code's settings.
221
+ const PROTECTED_FILES = ['.zshrc', '.zprofile', '.zshenv', '.bashrc', '.bash_profile', '.profile'];
222
+ const PROTECTED_TREES = [path.join('Library', 'LaunchAgents'), '.claude'];
223
+ // Overrides the installer and hmd honour INSTEAD of $HOME: left in the environment they walk straight
224
+ // past the redirect (a Claude Code user very likely has CLAUDE_CONFIG_DIR set).
225
+ const HOME_OVERRIDES = ['HEIMDALL_HOME', 'HEIMDALL_TEAM_DIR', 'HEIMDALL_LAUNCH_AGENTS_DIR', 'CLAUDE_CONFIG_DIR'];
226
+
227
+ function wantsZeroFootprint(hmdArgs) {
228
+ return hmdArgs[0] === 'attack' || (hmdArgs[0] === 'demo' && hmdArgs.indexOf('--offline') !== -1);
229
+ }
230
+
231
+ // realpath of the deepest ancestor that exists, plus the part that does not exist yet.
232
+ function resolveLoose(p) {
233
+ let head = path.resolve(p);
234
+ const rest = [];
235
+ while (true) {
236
+ try {
237
+ return path.join.apply(path, [fs.realpathSync(head)].concat(rest));
238
+ } catch (e) {
239
+ const parent = path.dirname(head);
240
+ if (parent === head) {
241
+ return path.resolve(p);
242
+ }
243
+ rest.unshift(path.basename(head));
244
+ head = parent;
245
+ }
246
+ }
247
+ }
248
+
249
+ // Which protected location (as the user would write it) p is, or lies inside; null if none.
250
+ function protectedReason(p) {
251
+ const target = resolveLoose(p);
252
+ for (let i = 0; i < PROTECTED_FILES.length; i++) {
253
+ if (target === resolveLoose(path.join(REAL_HOME, PROTECTED_FILES[i]))) {
254
+ return '~/' + PROTECTED_FILES[i];
255
+ }
256
+ }
257
+ for (let i = 0; i < PROTECTED_TREES.length; i++) {
258
+ const tree = resolveLoose(path.join(REAL_HOME, PROTECTED_TREES[i]));
259
+ if (target === tree || target.indexOf(tree + path.sep) === 0) {
260
+ return '~/' + PROTECTED_TREES[i];
261
+ }
262
+ }
263
+ return null;
264
+ }
265
+
266
+ // The directories handed to --out: `--out DIR` and `--out=DIR`.
267
+ function outTargets(args) {
268
+ const found = [];
269
+ args.forEach(function (a, i) {
270
+ if (a === '--out' && i + 1 < args.length) {
271
+ found.push(args[i + 1]);
272
+ } else if (a.indexOf('--out=') === 0) {
273
+ found.push(a.slice('--out='.length));
274
+ }
275
+ });
276
+ return found;
277
+ }
278
+
279
+ // Refuse (exit 2) anything that would write a protected path, then move the whole run into a temp dir
280
+ // that is removed when this process exits - on every path out, die() and refuse() included.
281
+ function enterZeroFootprint(hmdArgs) {
282
+ const tmpInside = protectedReason(os.tmpdir());
283
+ if (tmpInside) {
284
+ refuse('zero-footprint: the temporary directory (' + os.tmpdir() + ') is inside ' + tmpInside + ' - refusing to create anything there. Point TMPDIR somewhere else.');
285
+ }
286
+ outTargets(hmdArgs).forEach(function (out) {
287
+ const why = protectedReason(out);
288
+ if (why) {
289
+ refuse('zero-footprint: --out ' + out + ' would write into ' + why + ' - refusing. Pick another directory.');
290
+ }
291
+ });
292
+
293
+ let root;
294
+ try {
295
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'runhmd-zf-'));
296
+ } catch (e) {
297
+ die('cannot create a temporary directory under ' + os.tmpdir() + ': ' + e.message);
298
+ }
299
+ ['home', 'work', 'tmp'].forEach(function (d) { fs.mkdirSync(path.join(root, d)); });
300
+ process.on('exit', function () {
301
+ try { fs.rmSync(root, { recursive: true, force: true }); } catch (e) { /* the OS reaps its temp dir */ }
302
+ });
303
+
304
+ HOME_OVERRIDES.forEach(function (name) { delete process.env[name]; });
305
+ process.env.HOME = path.join(root, 'home');
306
+ process.env.TMPDIR = path.join(root, 'tmp');
307
+ process.env.HEIMDALL_NO_DREAM_SCHEDULE = '1';
308
+ process.env.PYTHONDONTWRITEBYTECODE = '1';
309
+ // The node that is running this wrapper stays first: a shim that finds its versions through $HOME cannot.
310
+ process.env.PATH = path.dirname(process.execPath) + path.delimiter + (process.env.PATH || '');
311
+ return { root: root, home: path.join(root, 'home'), work: path.join(root, 'work') };
312
+ }
313
+
314
+ // ── hmd discovery ────────────────────────────────────────────────────────────
315
+
316
+ function isExecutableFile(p) {
317
+ try {
318
+ fs.accessSync(p, fs.constants.X_OK);
319
+ return fs.statSync(p).isFile();
320
+ } catch (e) {
321
+ return false;
322
+ }
323
+ }
324
+
325
+ // PATH first, then where the installer links it (~/.local/bin/hmd) and where it lives
326
+ // (~/.heimdall/bin/heimdall) — a fresh install is usable in this very process even though the
327
+ // PATH line it appended to the shell profile only reaches NEW shells.
328
+ function findHmd(homes, searchPath) {
329
+ const dirs = searchPath === false ? [] : (process.env.PATH || '').split(path.delimiter).filter(Boolean);
330
+ const candidates = dirs.map(function (dir) { return path.join(dir, 'hmd'); });
331
+ (homes || [os.homedir()]).forEach(function (home) {
332
+ candidates.push(path.join(home, '.local', 'bin', 'hmd'), path.join(home, '.heimdall', 'bin', 'heimdall'));
333
+ });
334
+ for (let i = 0; i < candidates.length; i++) {
335
+ if (isExecutableFile(candidates[i])) {
336
+ return candidates[i];
337
+ }
338
+ }
339
+ return null;
340
+ }
341
+
342
+ // "Heimdall vX.Y.Z" (first line of `hmd --version`) -> [X, Y, Z]; null when unreadable.
343
+ function parseVersion(text) {
344
+ const m = /v?(\d+)\.(\d+)\.(\d+)/.exec(String(text).split('\n')[0]);
345
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
346
+ }
347
+
348
+ function compareVersions(a, b) {
349
+ for (let i = 0; i < 3; i++) {
350
+ if (a[i] !== b[i]) {
351
+ return a[i] < b[i] ? -1 : 1;
352
+ }
353
+ }
354
+ return 0;
355
+ }
356
+
357
+ function formatVersion(v) {
358
+ return 'v' + v.join('.');
359
+ }
360
+
361
+ function installedVersion(hmd) {
362
+ const r = spawnSync(hmd, ['--version'], { encoding: 'utf8', timeout: 20000 });
363
+ if (r.error || r.status !== 0) {
364
+ return null;
365
+ }
366
+ return parseVersion(r.stdout);
367
+ }
368
+
369
+ // Return a path to an hmd at least as new as the pinned release — running the pinned installer
370
+ // first when there is none. An hmd older than the pin is never run: a release that predates a
371
+ // subcommand treats it as a free-text task prompt and starts an agent session instead.
372
+ async function ensureHmd(pinned) {
373
+ let hmd = findHmd(ZF ? [REAL_HOME] : undefined); // zero-footprint: HOME is already the temp dir, so look in the real one
374
+ let have = hmd ? installedVersion(hmd) : null;
375
+ if (hmd && have && compareVersions(have, pinned) >= 0) {
376
+ return hmd;
377
+ }
378
+
379
+ if (!hmd) {
380
+ note('hmd is not installed — running the pinned installer (' + TAG + ') first.');
381
+ } else if (!have) {
382
+ note('could not read the version of ' + hmd + ' — running the pinned installer (' + TAG + ') first.');
383
+ } else {
384
+ note('installed hmd ' + formatVersion(have) + ' is older than the ' + TAG + " this runhmd is pinned to — running the pinned installer first.");
385
+ }
386
+ if (ZF) {
387
+ note('zero-footprint: installing into a throwaway directory (' + ZF.root + ', removed when this command ends) - nothing is written to your home directory, shell profile, LaunchAgents or Claude Code settings.');
388
+ } else {
389
+ note('same installer and footprint as `npx runheimdall`: ~/.heimdall, ~/.local/bin, a PATH line in your shell profile, Claude Code settings, and on macOS a nightly LaunchAgent (HEIMDALL_NO_DREAM_SCHEDULE=1 skips it). `hmd uninstall` reverses it.');
390
+ }
391
+
392
+ const status = runScript(await verifiedScript());
393
+ if (status !== 0) {
394
+ die('installer exited with status ' + status + ' — not running hmd.');
395
+ }
396
+
397
+ // zero-footprint: the installer ran with HOME = the temp dir, so what it installed is there and only there
398
+ hmd = ZF ? findHmd([ZF.home], false) : findHmd();
399
+ if (!hmd) {
400
+ die('the installer finished but no hmd was found (looked ' + (ZF ? 'in ' + ZF.home + '/.local/bin and ' + ZF.home + '/.heimdall/bin' : 'on PATH, in ~/.local/bin and in ~/.heimdall/bin') + ').');
401
+ }
402
+ have = installedVersion(hmd);
403
+ if (!have || compareVersions(have, pinned) < 0) {
404
+ die('the installer finished but ' + hmd + ' reports ' + (have ? formatVersion(have) : 'no readable version') + ', older than the pinned ' + TAG + ' — refusing to run hmd on a build that predates this release.');
405
+ }
406
+ return hmd;
407
+ }
408
+
409
+ // ── local flags ──────────────────────────────────────────────────────────────
410
+
411
+ function printVersion() {
412
+ process.stdout.write(
413
+ 'runhmd ' + pkg.version + '\n' +
414
+ 'pinned hmd release: ' + (meta.tag || '(none)') + '\n' +
415
+ 'pinned install.sh sha256: ' + (meta.sha256 ? meta.sha256.slice(0, 12) + '…' : '(none baked in)') + '\n'
416
+ );
417
+ }
418
+
419
+ function printHelp() {
420
+ process.stdout.write([
421
+ 'runhmd - front door to hmd',
422
+ '',
423
+ 'usage:',
424
+ ' runhmd [<path>|<pr-url>] [options] run `hmd attack` (the default command) on a target',
425
+ ' runhmd <subcommand> [args...] pass through to `hmd <subcommand> [args...]`',
426
+ ' runhmd --version this package, and the hmd release it is pinned to',
427
+ ' runhmd --help this text',
428
+ '',
429
+ 'A first argument that is not an hmd subcommand is a target for `hmd attack`. To attack a',
430
+ 'directory that is named like a subcommand, spell it as a path: runhmd ./team',
431
+ '',
432
+ 'If hmd is missing - or older than the release this package is pinned to - the pinned',
433
+ 'install.sh is fetched, checked against the sha256 baked into this package, and only then run:',
434
+ 'the installer `npx runheimdall` runs, with the same footprint. `hmd uninstall` reverses it.',
435
+ ''
436
+ ].join('\n'));
437
+ }
438
+
439
+ // ── main ─────────────────────────────────────────────────────────────────────
440
+
441
+ async function main() {
442
+ const args = process.argv.slice(2);
443
+
444
+ if (['--version', '-v', '-V'].indexOf(args[0]) !== -1) {
445
+ printVersion();
446
+ return;
447
+ }
448
+ if (['--help', '-h'].indexOf(args[0]) !== -1) {
449
+ printHelp();
450
+ return;
451
+ }
452
+
453
+ assertPinWellFormed();
454
+ const hmdArgs = route(args, loadSubcommands(), defaultCommand());
455
+ const pinned = parseVersion(TAG);
456
+ if (!pinned) {
457
+ die('the pinned release "' + TAG + '" is not a vX.Y.Z version');
458
+ }
459
+
460
+ if (wantsZeroFootprint(hmdArgs)) {
461
+ ZF = enterZeroFootprint(hmdArgs);
462
+ }
463
+ const hmd = await ensureHmd(pinned);
464
+ const result = spawnSync(hmd, hmdArgs, { stdio: 'inherit', env: process.env });
465
+ if (result.error) {
466
+ die('failed to run hmd: ' + result.error.message);
467
+ }
468
+ if (typeof result.status !== 'number') {
469
+ die('hmd terminated by signal ' + result.signal);
470
+ }
471
+ process.exitCode = result.status;
472
+ }
473
+
474
+ main().catch(function (err) {
475
+ die(err && err.message ? err.message : String(err));
476
+ });
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "runhmd",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.4.6",
4
+ "description": "Front door to hmd: `npx runhmd <path>` runs `hmd attack <path>`, any other hmd subcommand passes through. Installs the pinned, sha256-verified hmd first when it is missing or too old. Nothing ships unproven.",
5
+ "bin": {
6
+ "runhmd": "bin/runhmd.js"
7
+ },
8
+ "files": [
9
+ "bin/runhmd.js",
10
+ "subcommands.txt",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=16"
15
+ },
16
+ "keywords": [
17
+ "hmd",
18
+ "heimdall",
19
+ "claude-code",
20
+ "ai-agent",
21
+ "verification",
22
+ "false-green",
23
+ "code-review",
24
+ "cli",
25
+ "npx",
26
+ "sha256"
27
+ ],
28
+ "homepage": "https://runheimdall.dev",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/randomittin/heimdall.git",
32
+ "directory": "packages/runhmd"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/randomittin/heimdall/issues"
36
+ },
37
+ "license": "MIT",
38
+ "author": "Heimdall",
39
+ "heimdall": {
40
+ "tag": "v2.4.6",
41
+ "installScriptUrl": "https://raw.githubusercontent.com/randomittin/heimdall/v2.4.6/install.sh",
42
+ "sha256": "b8fade0307594068c5d7b21ba4c0a08d738dec69ed00c0b40adf17d7c07638c4",
43
+ "defaultCommand": "attack"
44
+ }
45
+ }
@@ -0,0 +1,86 @@
1
+ # The hmd subcommands `runhmd` passes straight through. Anything else - a path, a PR URL, a
2
+ # flag - is a target for the default command: `runhmd <path>` runs `hmd attack <path>`.
3
+ #
4
+ # One word per line; blank lines and #-comments are ignored. Keep it in step with the top-level
5
+ # dispatch in bin/heimdall: test/runhmd-parity.test.sh fails when a dispatched subcommand is
6
+ # missing here (it would silently become `hmd attack <word>`), and when a listed word is neither
7
+ # dispatched nor planned.
8
+
9
+ # the default command, and its sibling - planned, not dispatched by every hmd release yet
10
+ attack
11
+ prove
12
+
13
+ # dispatched by bin/heimdall, in dispatch order
14
+ version
15
+ help
16
+ demo
17
+ rr
18
+ sigil
19
+ sigil-png
20
+ guard
21
+ uninstall
22
+ team
23
+ invite
24
+ join
25
+ connect
26
+ presence
27
+ context
28
+ chat
29
+ link
30
+ beat
31
+ roster
32
+ dashboard
33
+ god
34
+ telemetry
35
+ init
36
+ verdict
37
+ receipt
38
+ sla
39
+ badge
40
+ metrics
41
+ clip
42
+ funnel
43
+ watch
44
+ rules
45
+ route
46
+ modules
47
+ tier
48
+ caveman
49
+ volatile-repo-guard
50
+ ui
51
+ inbox
52
+ app
53
+ dash
54
+ settings-guard
55
+ hooks
56
+ caveman-audit
57
+ cost-forensics
58
+ branch-context
59
+ collision
60
+ task
61
+ land
62
+ issue
63
+ memory
64
+ vm-bench
65
+ caveman-eval
66
+ web
67
+ plan-verify
68
+ metric-audit
69
+ status
70
+ cursor-statusline
71
+ weekly-log
72
+ weekly-review
73
+ report
74
+ report-issue
75
+ designmatch
76
+ check
77
+ redum
78
+ authenticity-check
79
+ queue
80
+ quota-advisor
81
+ 529-scan
82
+ delivery-audit
83
+ unconnected
84
+ wrap
85
+ unwrap
86
+ update