haltija 1.13.0-beta.3 → 1.13.0-beta.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,81 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.13.0-beta.4 (2026-10-17)
4
+
5
+ ### Added
6
+
7
+ - **Dialogs can be let through to a person: `hj dialog-configure --alert show`** (virta #3274).
8
+ `show` is a new policy value for `alert`, `confirm` and `prompt` (also `POST /dialog/configure
9
+ {"alert":"show"}`). The dialog reaches the person at the page, and it is still recorded and
10
+ reported with their answer (`shown: true` in `/dialog/history`). It is opt-in: interception stays
11
+ the default, because a native modal blocks the page and an agent driving it cannot see or answer
12
+ one. The policy lives in the tab and resets on reload.
13
+ - `hj dialog-configure` and `hj dialog-history` are now real commands. Both endpoints declared
14
+ those CLI names, but neither was ever invokable.
15
+ - An unknown policy value is refused with the valid ones named. It used to answer success and
16
+ change nothing; for `prompt`, every prompt then returned `undefined`.
17
+ - The documented response shapes of both endpoints are corrected to `{ success, data: … }`.
18
+
19
+ ### Fixed
20
+
21
+ - **An intercepted `alert`, `confirm` or `prompt` now says so on the page's console** (virta #3274).
22
+ The dev channel answers native dialogs so an agent driving the page is never blocked, but a person
23
+ using the same page saw `alert()` do nothing, with no hint why. Each intercepted dialog now logs
24
+ one `[haltija] intercepted …` line naming what it answered and how to show dialogs instead. The line
25
+ goes to the real console only; it is not captured as page output in `/console`. Interception
26
+ itself is unchanged.
27
+
28
+ - **`press` in `haltija/test` (and `DevChannelClient.press`) is a real key sequence at the focused
29
+ element** (virta #3121). It goes through `/key`, like `hj key`: the modifier keys go down, then
30
+ keydown → … → keyup for the key, then the modifiers come up. It used to be one `keydown` dispatched
31
+ at `body`, so a handler on a focused input, or one listening for `keyup`, never fired. A test that
32
+ relied on the event's target being `body` will now see the focused element instead.
33
+
34
+ - **With nothing focused, `hj doctor` judges the tab commands actually reach** (virta #3123). It
35
+ picked the first visible tab, where the server picks the most recently seen active one, so its
36
+ `observability:` line could describe a tab no command goes to. `/status` now reports
37
+ `targetWindowId` (the server's own answer) and doctor reads it; against an older server it falls
38
+ back as before.
39
+
40
+ - **`clickAt` and `dragFrom` refuse the shared default 8700 like `click` does** (virta #3120). They
41
+ act through `eval`, which `haltija/test` leaves open on the shared port so reads keep working, so
42
+ with no `HALTIJA_PORT` / `HALTIJA_URL` they dispatched pointer events into whatever tab was focused
43
+ there, possibly another project's. `read` and `hj.eval` are unchanged; `HALTIJA_TEST_ALLOW_SHARED=1`
44
+ still opts in.
45
+
46
+ - **`hj test validate <file>` works** (GitHub #55). It returned HTTP 500 ("undefined is not an
47
+ object (evaluating 'test.steps.length')") for every file, because the CLI sends `{ test }` as the
48
+ schema documents and the server read only a bare test. Both shapes are accepted now; a body with
49
+ no `steps` array is a 400 that says so. The documented response shape is corrected to what the
50
+ endpoint returns: `{ valid, issues, stepCount }`.
51
+
52
+ - **The MCP server works from npm** (GitHub #46, #47). `haltija --setup-mcp` (Claude Desktop) and
53
+ `haltija-mcp-setup` (Claude Code) both exited 1 for every npm user: they looked for
54
+ `apps/mcp/build/index.js`, which the package never contained. Even if it had been shipped, that
55
+ file imported an SDK npm never installs for a nested package. The server now ships as
56
+ `dist/mcp.js` (bin `haltija-mcp`), one bundle with its dependencies inlined, about 170 KB gzipped,
57
+ and adds no dependencies to an install.
58
+ - Both setup commands write a command that starts it. When the package runs from an npx/bunx
59
+ cache, they write a version-pinned `npx -p haltija@<version> haltija-mcp` instead of a path the
60
+ cache will delete.
61
+ - The server sends `HALTIJA_TOKEN`, so it works against a server started with `--token`, and it
62
+ reports haltija's version instead of `0.1.0`.
63
+ - It compiles again: `tsc` failed with TS2589 on handler types inferred from a runtime-built shape.
64
+ In-range updates cleared ten advisories (1 critical, 3 high).
65
+ - Tested the way a user gets it: a new test packs the tarball, extracts it with no `node_modules`
66
+ above it, runs each setup command, and calls a tool through the written config against a live,
67
+ token-protected server.
68
+
69
+ - **The test runner's `wait` with `forWindow: true` no longer stops at an iframe, and returns as
70
+ soon as the window appears** (virta #2468). It accepted any new window, including a frame
71
+ injecting its own widget, and then slept a fixed 300 ms. A window registers on its `connected`
72
+ message, so it already takes commands at that point. The step now waits for a new tab or popup.
73
+
74
+ - **The desktop app says when it ignores your `DEV_CHANNEL_MODE`** (virta #1078). Its public
75
+ server always serves both transports, because it serves other projects' pages too. That is
76
+ unchanged, but an explicit `http` or `https` used to be dropped without a word. It now prints one
77
+ line naming what was ignored and why.
78
+
3
79
  ## 1.13.0-beta.3 (2026-10-08)
4
80
 
5
81
  ### Added
package/README.md CHANGED
@@ -31,7 +31,9 @@ Paste this into your agent conversation:
31
31
 
32
32
  > I have the `hj` browser tool. Run `hj tree` to see the page, `hj click <id>` to interact, and `hj docs` for help.
33
33
 
34
- Or for Claude Code with MCP: `bunx haltija --setup-mcp`
34
+ Or as MCP tools: `npx -p haltija haltija-mcp-setup` in a project (Claude Code, writes `.mcp.json`), or
35
+ `bunx haltija --setup-mcp` (Claude Desktop). Claude Code can load the haltija skill instead:
36
+ `/plugin marketplace add tonioloewald/haltija`, then `/plugin install haltija-skill@haltija`.
35
37
 
36
38
  ---
37
39
 
@@ -24,7 +24,7 @@ const os = require('os')
24
24
  const { spawn } = require('child_process')
25
25
  const http = require('http')
26
26
  const { attachNetwork, detachNetwork, getNetworkLog, getNetworkStats, clearNetwork, isMonitoring } = require('./cdp-network.js')
27
- const { buildServerEnv } = require('./server-env.js')
27
+ const { buildServerEnv, overriddenModeNotice } = require('./server-env.js')
28
28
  const { DEFAULT_HTTP_PORT, DEFAULT_INTERNAL_PORT, internalPortConflict } = require('./ports.js')
29
29
  // The wire protocol, generated from src/machine-channel.ts — NOT re-declared here. main.js used to
30
30
  // hand-roll the prefixes, the line split and the parse; that copy is where the __NEED_WINDOW__
@@ -1384,6 +1384,8 @@ ipcMain.handle('machine-request', async (_evt, path, init) => {
1384
1384
  function spawnHaltijaServer({ port, role, serverPath, useCompiledBinary, componentDir, portFile }) {
1385
1385
  // Built by src/desktop-server-env.ts, whose contract is unit-tested without launching Electron —
1386
1386
  // getting this wrong is silent (a child that ignores its port, binds the parent's, and dies).
1387
+ const modeNotice = overriddenModeNotice(process.env, role === 'public' ? 'public' : 'internal')
1388
+ if (modeNotice) console.warn(modeNotice)
1387
1389
  const env = buildServerEnv(process.env, {
1388
1390
  port,
1389
1391
  role: role === 'public' ? 'public' : 'internal',
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haltija-desktop",
3
- "version": "1.13.0-beta.3",
3
+ "version": "1.13.0-beta.4",
4
4
  "private": true,
5
5
  "description": "Haltija Desktop - God Mode Browser for AI Agents",
6
6
  "homepage": "https://github.com/tonioloewald/haltija",
@@ -46,7 +46,7 @@
46
46
  });
47
47
 
48
48
  // src/version.ts
49
- var VERSION = "1.13.0-beta.3";
49
+ var VERSION = "1.13.0-beta.4";
50
50
 
51
51
  // src/ws-url.ts
52
52
  function httpBaseFromWsUrl(wsUrl2, fallback = "http://localhost:8700") {
@@ -228,6 +228,29 @@
228
228
  return { width: W, height: H };
229
229
  }
230
230
 
231
+ // src/dialog-policy.ts
232
+ var DIALOG_POLICY_VALUES = {
233
+ alert: ["dismiss", "show"],
234
+ confirm: ["accept", "dismiss", "show"],
235
+ prompt: ["dismiss", "show", '{ "response": "text" }'],
236
+ beforeunload: ["allow", "block"]
237
+ };
238
+ function dialogPolicyError(payload2) {
239
+ if (!payload2)
240
+ return null;
241
+ for (const key of ["alert", "confirm", "beforeunload"]) {
242
+ const v = payload2[key];
243
+ if (v !== undefined && !DIALOG_POLICY_VALUES[key].includes(v)) {
244
+ return `dialog ${key} must be one of ${DIALOG_POLICY_VALUES[key].map((x) => `"${x}"`).join(", ")}; got ${JSON.stringify(v)}`;
245
+ }
246
+ }
247
+ const p = payload2.prompt;
248
+ if (p !== undefined && p !== "dismiss" && p !== "show" && !(p && typeof p === "object" && typeof p.response === "string")) {
249
+ return `dialog prompt must be "dismiss", "show" or { "response": "text" }; got ${JSON.stringify(p)}`;
250
+ }
251
+ return null;
252
+ }
253
+
231
254
  // src/component.ts
232
255
  var VERSION2 = VERSION;
233
256
  var PRODUCT_NAME = "Haltija";
@@ -6465,6 +6488,11 @@ ${elementSummary}${moreText}`;
6465
6488
  handleDialogMessage(msg2) {
6466
6489
  const { action: action2, payload: payload2 } = msg2;
6467
6490
  if (action2 === "configure") {
6491
+ const bad = dialogPolicyError(payload2);
6492
+ if (bad) {
6493
+ this.respond(msg2.id, false, undefined, bad);
6494
+ return;
6495
+ }
6468
6496
  if (payload2.alert !== undefined)
6469
6497
  this.dialogPolicy.alert = payload2.alert;
6470
6498
  if (payload2.confirm !== undefined)
@@ -8679,22 +8707,32 @@ ${elementSummary}${moreText}`;
8679
8707
  this.originalDialogs.confirm = window.confirm.bind(window);
8680
8708
  this.originalDialogs.prompt = window.prompt.bind(window);
8681
8709
  const self = this;
8710
+ const announce = (type, msg2, outcome) => {
8711
+ const info = self.originalConsole.info ?? console.info;
8712
+ const shown = msg2.length > 80 ? msg2.slice(0, 77) + "..." : msg2;
8713
+ info.call(console, `[haltija] intercepted ${type}(${JSON.stringify(shown)}) and ${outcome}: the dev channel answers native dialogs so an agent driving the page is never blocked by one. To show dialogs instead: hj dialog-configure --alert show (or --confirm / --prompt show).`);
8714
+ };
8682
8715
  window.alert = function(message) {
8683
8716
  if (self._inHaltijaUI)
8684
8717
  return self.originalDialogs.alert(message);
8685
8718
  const msg2 = String(message ?? "");
8686
- const entry = { type: "alert", message: msg2, response: undefined, timestamp: Date.now() };
8719
+ const shown = self.dialogPolicy.alert === "show";
8720
+ const entry = { type: "alert", message: msg2, response: undefined, shown, timestamp: Date.now() };
8687
8721
  self.dialogHistory.push(entry);
8688
8722
  if (self.dialogHistory.length > 50)
8689
8723
  self.dialogHistory = self.dialogHistory.slice(-25);
8690
- self.send("dialog", "opened", { type: "alert", message: msg2, windowId: self.windowId });
8724
+ self.send("dialog", "opened", { type: "alert", message: msg2, shown, windowId: self.windowId });
8725
+ if (shown)
8726
+ return self.originalDialogs.alert(message);
8727
+ announce("alert", msg2, "did not show it");
8691
8728
  };
8692
8729
  window.confirm = function(message) {
8693
8730
  if (self._inHaltijaUI)
8694
8731
  return self.originalDialogs.confirm(message);
8695
8732
  const msg2 = String(message ?? "");
8696
- const accept = self.dialogPolicy.confirm === "accept";
8697
- const entry = { type: "confirm", message: msg2, response: accept, timestamp: Date.now() };
8733
+ const shown = self.dialogPolicy.confirm === "show";
8734
+ const accept = shown ? self.originalDialogs.confirm(message) : self.dialogPolicy.confirm === "accept";
8735
+ const entry = { type: "confirm", message: msg2, response: accept, shown, timestamp: Date.now() };
8698
8736
  self.dialogHistory.push(entry);
8699
8737
  if (self.dialogHistory.length > 50)
8700
8738
  self.dialogHistory = self.dialogHistory.slice(-25);
@@ -8702,8 +8740,12 @@ ${elementSummary}${moreText}`;
8702
8740
  type: "confirm",
8703
8741
  message: msg2,
8704
8742
  response: accept,
8743
+ shown,
8705
8744
  windowId: self.windowId
8706
8745
  });
8746
+ if (shown)
8747
+ return accept;
8748
+ announce("confirm", msg2, `answered ${accept ? "OK" : "Cancel"} without showing it`);
8707
8749
  return accept;
8708
8750
  };
8709
8751
  window.prompt = function(message, defaultValue) {
@@ -8711,8 +8753,9 @@ ${elementSummary}${moreText}`;
8711
8753
  return self.originalDialogs.prompt(message, defaultValue);
8712
8754
  const msg2 = String(message ?? "");
8713
8755
  const policy = self.dialogPolicy.prompt;
8714
- const response = policy === "dismiss" ? null : policy.response;
8715
- const entry = { type: "prompt", message: msg2, defaultValue, response, timestamp: Date.now() };
8756
+ const shown = policy === "show";
8757
+ const response = shown ? self.originalDialogs.prompt(message, defaultValue) : policy === "dismiss" ? null : policy.response;
8758
+ const entry = { type: "prompt", message: msg2, defaultValue, response, shown, timestamp: Date.now() };
8716
8759
  self.dialogHistory.push(entry);
8717
8760
  if (self.dialogHistory.length > 50)
8718
8761
  self.dialogHistory = self.dialogHistory.slice(-25);
@@ -8721,8 +8764,12 @@ ${elementSummary}${moreText}`;
8721
8764
  message: msg2,
8722
8765
  defaultValue,
8723
8766
  response,
8767
+ shown,
8724
8768
  windowId: self.windowId
8725
8769
  });
8770
+ if (shown)
8771
+ return response;
8772
+ announce("prompt", msg2, `answered ${response === null ? "Cancel" : JSON.stringify(response)} without showing it`);
8726
8773
  return response;
8727
8774
  };
8728
8775
  }
@@ -40,9 +40,16 @@ var __export = (target, all) => {
40
40
  // src/desktop-server-env.ts
41
41
  var exports_desktop_server_env = {};
42
42
  __export(exports_desktop_server_env, {
43
- buildServerEnv: () => buildServerEnv
43
+ buildServerEnv: () => buildServerEnv,
44
+ overriddenModeNotice: () => overriddenModeNotice
44
45
  });
45
46
  module.exports = __toCommonJS(exports_desktop_server_env);
47
+ function overriddenModeNotice(base, role) {
48
+ const asked = base.DEV_CHANNEL_MODE?.trim();
49
+ if (role !== "public" || !asked || asked.toLowerCase() === "both")
50
+ return null;
51
+ return `[haltija] ignoring DEV_CHANNEL_MODE=${asked} for the desktop app's public server: it serves ` + `HTTP and HTTPS ('both'), because it serves other projects' pages too and one project's ` + `transport choice would decide for all of them whether https:// pages can connect (#32). For a ` + `single-transport server of your own, run \`haltija --server\` with that mode instead.`;
52
+ }
46
53
  function buildServerEnv(base, opts) {
47
54
  const port = String(opts.port);
48
55
  const env = {};
@@ -47,6 +47,8 @@ var ROUTED_COMMANDS = [
47
47
  "network-watch",
48
48
  "network-unwatch",
49
49
  "network-stats",
50
+ "dialog-configure",
51
+ "dialog-history",
50
52
  "recording",
51
53
  "recording-start",
52
54
  "recording-stop",
@@ -112,12 +112,14 @@ export const COMPOUND_PATHS = {
112
112
  'network-watch': '/network/watch',
113
113
  'network-unwatch': '/network/unwatch',
114
114
  'network-stats': '/network/stats',
115
+ 'dialog-configure': '/dialog/configure',
116
+ 'dialog-history': '/dialog/history',
115
117
  }
116
118
 
117
119
  // GET compound endpoints
118
120
  export const GET_COMPOUND = new Set([
119
121
  'mutations-status', 'events-stats', 'select-status', 'select-result', 'video-status',
120
- 'network-stats'
122
+ 'network-stats', 'dialog-history'
121
123
  ])
122
124
 
123
125
  // How to map positional args to body fields for each endpoint
@@ -344,6 +346,14 @@ export const ARG_MAPS = {
344
346
  return body
345
347
  },
346
348
  'video-stop': () => ({}),
349
+ // `--prompt` takes "dismiss", "show", or the text to answer with — any other word is the answer.
350
+ 'dialog-configure': (args) => {
351
+ const { flags } = takeFlags(args, { '--alert': 'str', '--confirm': 'str', '--prompt': 'str', '--beforeunload': 'str' })
352
+ if (typeof flags.prompt === 'string' && flags.prompt !== 'dismiss' && flags.prompt !== 'show') {
353
+ flags.prompt = { response: flags.prompt }
354
+ }
355
+ return flags
356
+ },
347
357
  'events-watch': (args) => ({ preset: presetArg(args, 'interactive') }),
348
358
  // These two had the ORIGINAL args[0] bug still in them, one line below the comment describing the
349
359
  // fix — `hj mutations-watch --preset smart` sent preset:'--preset', `FILTER_PRESETS[preset]` came
@@ -952,6 +962,7 @@ export const KNOWN_FLAGS = {
952
962
  refresh: ['--soft', '--no-wait', '--timeout'],
953
963
  navigate: ['--no-wait', '--timeout'],
954
964
  'test-run': ['--vars', '--seed', '--timeoutMs', '--allow-failures', '--allow-failures-streak', '--step-delay'],
965
+ 'dialog-configure': ['--alert', '--confirm', '--prompt', '--beforeunload'],
955
966
  'test-validate': ['--vars', '--seed', '--timeoutMs', '--allow-failures', '--allow-failures-streak', '--step-delay'],
956
967
  'test-suite': ['--vars', '--seed', '--timeoutMs', '--allow-failures', '--allow-failures-streak', '--step-delay'],
957
968
  // Added after an invariant test derived them from the parsers themselves. Missing entries are
@@ -1623,6 +1634,8 @@ export function listSubcommands() {
1623
1634
  refresh [--soft] [--no-wait] Reload page; waits for it to come back
1624
1635
  tabs ${dim('open|close|focus')} Tab management (default: list)
1625
1636
  eval <code> Run JS in browser
1637
+ dialog-configure --alert show Let alert/confirm/prompt reach a person (default: answered)
1638
+ dialog-history Dialogs the page opened, and how each was answered
1626
1639
 
1627
1640
  ${bold('Test')}
1628
1641
  test ${dim('run|suite|validate')} <file> Run tests (default: run)
package/bin/hj.mjs CHANGED
@@ -384,7 +384,10 @@ async function runDoctor(port, portSource, portSourceKind, jsonOutput) {
384
384
  ? routeByDeclaredOrigin(declaredOrigins.origins, tabs, focusedTab?.id ?? null)
385
385
  : null
386
386
  const pinned = routed?.kind === 'matched' ? tabs.find((w) => w.id === routed.windowId) ?? null : null
387
- const target = pinned ?? focusedTab ?? tabs.find((w) => isVisible(w)) ?? tabs[0] ?? null
387
+ // Unpinned, it is whatever the server says it would target (#3123); the local fallback is only
388
+ // for servers older than 1.13.0-beta.4, which don't report it.
389
+ const serverTarget = status.targetWindowId ? tabs.find((w) => w.id === status.targetWindowId) ?? null : null
390
+ const target = pinned ?? serverTarget ?? focusedTab ?? tabs.find((w) => isVisible(w)) ?? tabs[0] ?? null
388
391
  const targetLabel = target ? `${target.title && target.title !== '(untitled)' ? `"${target.title}" ` : ''}${target.url || target.id}` : ''
389
392
  // A tab that reported NEITHER field hasn't told us anything; `isVisible` had to assume. Say so
390
393
  // rather than counting the assumption as a passed check.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Where the MCP server is, and the command an MCP client should run to start it. ONE copy, used by
3
+ * both setup paths (`haltija --setup-mcp` for Claude Desktop, `haltija-mcp-setup` for Claude Code).
4
+ * They had a finder each, both looking for `apps/mcp/build/index.js`, which the npm package never
5
+ * contained — so setup failed for every npm user (GitHub #47).
6
+ *
7
+ * The server is `dist/mcp.js`, a single bundle with its dependencies inlined: npm never installs a
8
+ * nested package's dependencies, so an unbundled server could not have imported its SDK.
9
+ */
10
+ import { existsSync, readFileSync } from 'fs'
11
+ import { dirname, join } from 'path'
12
+ import { fileURLToPath } from 'url'
13
+
14
+ const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
15
+
16
+ /** Absolute path of the bundled MCP server in this package, or null (a checkout that never built). */
17
+ export function mcpServerPath(root = PACKAGE_ROOT) {
18
+ const p = join(root, 'dist', 'mcp.js')
19
+ return existsSync(p) ? p : null
20
+ }
21
+
22
+ /**
23
+ * The `{ command, args }` an MCP client config should hold. A package run through `npx` / `bunx`
24
+ * lives in a cache that gets cleaned, so an absolute path there works today and breaks later with
25
+ * nothing to say why; those get the version-pinned `npx` form instead.
26
+ */
27
+ export function mcpServerCommand(serverPath, root = PACKAGE_ROOT) {
28
+ if (/[\\/](_npx|bunx-[^\\/]*|\.bun[\\/]install[\\/]cache)[\\/]/.test(serverPath)) {
29
+ const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
30
+ return { command: 'npx', args: ['-y', '-p', `haltija@${version}`, 'haltija-mcp'] }
31
+ }
32
+ return { command: 'node', args: [serverPath] }
33
+ }
package/bin/mcp-setup.mjs CHANGED
@@ -13,7 +13,8 @@ import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'fs'
13
13
  import { homedir } from 'os'
14
14
  import { join, dirname } from 'path'
15
15
  import { fileURLToPath } from 'url'
16
- import { execSync, spawnSync } from 'child_process'
16
+ import { execSync } from 'child_process'
17
+ import { mcpServerPath, mcpServerCommand } from './mcp-locate.mjs'
17
18
 
18
19
  const __dirname = dirname(fileURLToPath(import.meta.url))
19
20
  const args = process.argv.slice(2)
@@ -50,34 +51,6 @@ ${bold('After setup:')}
50
51
  process.exit(0)
51
52
  }
52
53
 
53
- // Find the MCP server path
54
- function findMcpServerPath() {
55
- // Check if we're in the haltija package
56
- const localPath = join(__dirname, '../apps/mcp/build/index.js')
57
- if (existsSync(localPath)) {
58
- return localPath
59
- }
60
-
61
- // Check for globally installed package
62
- try {
63
- const result = spawnSync('npm', ['root', '-g'], { encoding: 'utf8' })
64
- if (result.status === 0) {
65
- const globalPath = join(result.stdout.trim(), 'haltija/apps/mcp/build/index.js')
66
- if (existsSync(globalPath)) {
67
- return globalPath
68
- }
69
- }
70
- } catch {}
71
-
72
- // Check node_modules in current directory
73
- const nodeModulesPath = join(process.cwd(), 'node_modules/haltija/apps/mcp/build/index.js')
74
- if (existsSync(nodeModulesPath)) {
75
- return nodeModulesPath
76
- }
77
-
78
- return null
79
- }
80
-
81
54
  // Check if Claude Code is installed
82
55
  function isClaudeCodeInstalled() {
83
56
  const claudeJsonPath = join(homedir(), '.claude.json')
@@ -125,13 +98,13 @@ function checkConfig() {
125
98
  }
126
99
 
127
100
  // Check MCP server build
128
- const mcpPath = findMcpServerPath()
101
+ const mcpPath = mcpServerPath()
129
102
  if (mcpPath) {
130
103
  console.log(green('✓') + ' MCP server found')
131
104
  console.log(dim(` Path: ${mcpPath}`))
132
105
  } else {
133
106
  console.log(red('✗') + ' MCP server not found')
134
- console.log(dim(' Run from haltija directory or install globally'))
107
+ console.log(dim(' In a haltija checkout, run: bun run build'))
135
108
  }
136
109
 
137
110
  // Check if Haltija server is running
@@ -148,10 +121,10 @@ function checkConfig() {
148
121
 
149
122
  // Create or update .mcp.json
150
123
  function setupProjectConfig() {
151
- const mcpPath = findMcpServerPath()
124
+ const mcpPath = mcpServerPath()
152
125
  if (!mcpPath) {
153
126
  console.log(red('Error:') + ' Could not find Haltija MCP server.')
154
- console.log('Make sure you run this from the haltija directory or have it installed.')
127
+ console.log('In a haltija checkout, run `bun run build` first; an installed package always has it.')
155
128
  process.exit(1)
156
129
  }
157
130
 
@@ -179,10 +152,7 @@ function setupProjectConfig() {
179
152
  }
180
153
 
181
154
  // Add Haltija configuration
182
- config.mcpServers.haltija = {
183
- command: 'node',
184
- args: [mcpPath]
185
- }
155
+ config.mcpServers.haltija = mcpServerCommand(mcpPath)
186
156
 
187
157
  writeFileSync(projectMcpPath, JSON.stringify(config, null, 2) + '\n')
188
158
 
@@ -198,15 +168,17 @@ function setupProjectConfig() {
198
168
 
199
169
  // Add to global Claude Code config
200
170
  function setupGlobalConfig() {
201
- const mcpPath = findMcpServerPath()
171
+ const mcpPath = mcpServerPath()
202
172
  if (!mcpPath) {
203
173
  console.log(red('Error:') + ' Could not find Haltija MCP server.')
204
174
  process.exit(1)
205
175
  }
206
176
 
177
+ const { command, args: commandArgs } = mcpServerCommand(mcpPath)
178
+ const addCommand = `claude mcp add --scope user haltija -- ${[command, ...commandArgs].map((a) => JSON.stringify(a)).join(' ')}`
207
179
  // Try using claude CLI first
208
180
  try {
209
- execSync(`claude mcp add haltija node "${mcpPath}" --scope user`, {
181
+ execSync(addCommand, {
210
182
  encoding: 'utf8',
211
183
  stdio: 'inherit'
212
184
  })
@@ -232,10 +204,10 @@ function setupGlobalConfig() {
232
204
 
233
205
  console.log(yellow('Note:') + ' Could not use claude CLI, please add manually:')
234
206
  console.log('')
235
- console.log('Run: ' + bold(`claude mcp add haltija node "${mcpPath}" --scope user`))
207
+ console.log('Run: ' + bold(addCommand))
236
208
  console.log('')
237
209
  console.log('Or add to ~/.claude.json under your project\'s mcpServers:')
238
- console.log(dim(JSON.stringify({ haltija: { command: 'node', args: [mcpPath] } }, null, 2)))
210
+ console.log(dim(JSON.stringify({ haltija: mcpServerCommand(mcpPath) }, null, 2)))
239
211
  console.log('')
240
212
  }
241
213
 
@@ -18,6 +18,7 @@ import { homedir, platform, tmpdir } from 'os'
18
18
  import { fileURLToPath } from 'url'
19
19
  import { dirname, join } from 'path'
20
20
  import { stalePrivateEntries, pidIsAlive } from './private-state.mjs'
21
+ import { mcpServerPath, mcpServerCommand } from './mcp-locate.mjs'
21
22
 
22
23
  const __dirname = dirname(fileURLToPath(import.meta.url))
23
24
  const serverPath = join(__dirname, '../dist/server.js')
@@ -154,26 +155,12 @@ function getClaudeDesktopConfigPath() {
154
155
  }
155
156
  }
156
157
 
157
- /** Find the Haltija MCP server entry point */
158
- function findMcpServerPath() {
159
- const candidates = [
160
- join(__dirname, '../apps/mcp/build/index.js'),
161
- join(__dirname, 'mcp/build/index.js'),
162
- join(process.cwd(), 'node_modules/haltija/apps/mcp/build/index.js'),
163
- ]
164
-
165
- for (const p of candidates) {
166
- if (existsSync(p)) return p
167
- }
168
- return null
169
- }
170
-
171
158
  /** Check MCP configuration status */
172
159
  function checkMcpConfig() {
173
160
  console.log(bold('\nHaltija MCP Configuration Status\n'))
174
161
 
175
162
  const configPath = getClaudeDesktopConfigPath()
176
- const mcpPath = findMcpServerPath()
163
+ const mcpPath = mcpServerPath()
177
164
 
178
165
  // Check Claude Desktop
179
166
  if (existsSync(dirname(configPath))) {
@@ -208,7 +195,7 @@ function checkMcpConfig() {
208
195
  console.log(dim(` Path: ${mcpPath}`))
209
196
  } else {
210
197
  console.log(red('✗') + ' MCP server not found')
211
- console.log(dim(` Run from haltija directory or rebuild`))
198
+ console.log(dim(` In a haltija checkout, run: bun run build`))
212
199
  }
213
200
 
214
201
  // Check if server is running
@@ -228,10 +215,10 @@ function checkMcpConfig() {
228
215
 
229
216
  /** Setup Claude Desktop MCP integration */
230
217
  function setupMcp() {
231
- const mcpPath = findMcpServerPath()
218
+ const mcpPath = mcpServerPath()
232
219
  if (!mcpPath) {
233
220
  console.log(red('Error:') + ' Could not find Haltija MCP server.')
234
- console.log('Make sure you run this from the haltija directory or have it installed.')
221
+ console.log('In a haltija checkout, run `bun run build` first; an installed package always has it.')
235
222
  process.exit(1)
236
223
  }
237
224
 
@@ -269,10 +256,7 @@ function setupMcp() {
269
256
  }
270
257
 
271
258
  // Add Haltija
272
- config.mcpServers.haltija = {
273
- command: 'node',
274
- args: [mcpPath]
275
- }
259
+ config.mcpServers.haltija = mcpServerCommand(mcpPath)
276
260
 
277
261
  try {
278
262
  writeFileSync(configPath, JSON.stringify(config, null, 2))
package/bin/version.mjs CHANGED
@@ -3,4 +3,4 @@
3
3
  * ⚠️ To change the version, update package.json and run: bun run build
4
4
  */
5
5
 
6
- export const HJ_VERSION = '1.13.0-beta.3'
6
+ export const HJ_VERSION = '1.13.0-beta.4'
@@ -15,7 +15,7 @@
15
15
  * command that exists.
16
16
  */
17
17
  /** Commands routed to a REST endpoint. */
18
- export declare const ROUTED_COMMANDS: readonly ["tree", "map", "query", "inspect", "inspectAll", "styles", "find", "form", "wait", "click", "type", "key", "drag", "scroll", "call", "navigate", "refresh", "location", "events", "events-watch", "events-unwatch", "console", "mutations-watch", "mutations-unwatch", "mutations-status", "eval", "fetch", "screenshot", "snapshot", "highlight", "unhighlight", "select-start", "select-result", "select-cancel", "select-clear", "windows", "tabs-open", "tabs-close", "tabs-focus", "video-start", "video-stop", "video-status", "network", "network-watch", "network-unwatch", "network-stats", "recording", "recording-start", "recording-stop", "recording-generate", "recordings", "test-run", "test-validate", "test-suite", "session-attach", "session-read", "session-write", "session-detach", "send", "send-message", "send-selection", "send-recording", "status", "version", "docs", "api", "stats", "where"];
18
+ export declare const ROUTED_COMMANDS: readonly ["tree", "map", "query", "inspect", "inspectAll", "styles", "find", "form", "wait", "click", "type", "key", "drag", "scroll", "call", "navigate", "refresh", "location", "events", "events-watch", "events-unwatch", "console", "mutations-watch", "mutations-unwatch", "mutations-status", "eval", "fetch", "screenshot", "snapshot", "highlight", "unhighlight", "select-start", "select-result", "select-cancel", "select-clear", "windows", "tabs-open", "tabs-close", "tabs-focus", "video-start", "video-stop", "video-status", "network", "network-watch", "network-unwatch", "network-stats", "dialog-configure", "dialog-history", "recording", "recording-start", "recording-stop", "recording-generate", "recordings", "test-run", "test-validate", "test-suite", "session-attach", "session-read", "session-write", "session-detach", "send", "send-message", "send-selection", "send-recording", "status", "version", "docs", "api", "stats", "where"];
19
19
  /** Commands `hj` handles itself — never routed, so they don't appear in the endpoint schema. */
20
20
  export declare const LOCAL_COMMANDS: readonly ["where", "servers", "ls", "doctor", "shutdown", "quit"];
21
21
  /**
package/dist/client.d.ts CHANGED
@@ -44,6 +44,11 @@ export declare class DevChannelClient {
44
44
  dispatch(event: SyntheticEventRequest): Promise<void>;
45
45
  focus(selector: string): Promise<void>;
46
46
  blur(selector: string): Promise<void>;
47
+ /**
48
+ * A key press at the focused element, through `/key`: the full keydown → … → keyup lifecycle,
49
+ * like `click` and `type` use their realistic endpoints. It used to dispatch one `keydown` at
50
+ * `body`, so a handler on a focused input, or one listening for `keyup`, never fired (#3121).
51
+ */
47
52
  press(key: string, modifiers?: {
48
53
  alt?: boolean;
49
54
  ctrl?: boolean;
package/dist/client.js CHANGED
@@ -98,17 +98,21 @@ class DevChannelClient {
98
98
  await this.dispatch({ selector, event: "blur" });
99
99
  }
100
100
  async press(key, modifiers) {
101
- await this.dispatch({
102
- selector: "body",
103
- event: "keydown",
104
- options: {
101
+ const res = await fetch(`${this.baseUrl}/key`, {
102
+ method: "POST",
103
+ headers: { "Content-Type": "application/json" },
104
+ body: JSON.stringify({
105
105
  key,
106
106
  altKey: modifiers?.alt,
107
107
  ctrlKey: modifiers?.ctrl,
108
108
  metaKey: modifiers?.meta,
109
109
  shiftKey: modifiers?.shift
110
- }
110
+ })
111
111
  });
112
+ const response = await res.json();
113
+ if (!response.success) {
114
+ throw new Error(response.error || `Key press failed: ${key}`);
115
+ }
112
116
  }
113
117
  navigationOutcome(response) {
114
118
  const data = response.data || {};
@@ -20,7 +20,7 @@
20
20
  * - Option+Tab toggles visibility (but active state always shows briefly)
21
21
  * - Localhost only by default
22
22
  */
23
- export declare const VERSION = "1.13.0-beta.3";
23
+ export declare const VERSION = "1.13.0-beta.4";
24
24
  export declare class DevChannel extends HTMLElement {
25
25
  static get tagName(): string;
26
26
  static elementCreator(): () => DevChannel;