hooc-connector 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jonathan Berling
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,155 @@
1
- # Temporary Holding Version
1
+ # Hooc connector
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
+ A small local server that lets Claude (Claude Code and the Claude desktop app) read and manage the scripts in Hooc. It speaks MCP to Claude and talks to Hooc's service worker over a WebSocket.
4
+
5
+ ```
6
+ Claude Code / Claude app ──MCP over stdio──▶ hooc-connector ◀──WebSocket (ws://127.0.0.1:17345)── Hooc in Chrome
7
+ ```
8
+
9
+ - **Claude starts it when it needs it.** It is not a background service; nothing runs while Claude isn't using it.
10
+ - **Off by default in Hooc.** Hooc only connects after you click **Connect Claude** in its Settings and pair it once.
11
+ - **You approve anything that adds access.** New scripts, and changes that add `@grant`, `@match`/`@include` or `@connect` entries, open Hooc's review page. Code-only edits apply at once, but the old version goes to History (marked "Replaced by Claude") so you can roll back.
12
+ - **Kill switch.** The toolbar popup and Settings can pause the connector for 1 hour, until tomorrow, or until you turn it back on. Pausing drops the connection at once and Hooc refuses every request until the pause ends.
13
+
14
+ ## Set it up
15
+
16
+ You need Hooc in Chrome and either the Claude app or Claude Code. No Terminal for the Claude app.
17
+
18
+ **1. Add the connector to Claude (once).**
19
+
20
+ - **Claude app** (Mac or Windows): download `hooc-connector.mcpb` from https://hooc.berling.biz/connector, open it (double-click, or drag it onto Claude's **Settings → Extensions**) and click **Install**. It runs on the Node.js built into the Claude app.
21
+ - **Claude Code** (works in every project; needs Node.js 20 or newer):
22
+
23
+ ```bash
24
+ claude mcp add --scope user hooc -- npx -y hooc-connector
25
+ ```
26
+
27
+ **2. Pair (once).** In Chrome, open Hooc → **Settings → Claude connector** and click **Connect Claude**. Hooc shows a one-time code like `K7QM-2XPA`. In a Claude chat, say:
28
+
29
+ > Pair with Hooc using code K7QM-2XPA
30
+
31
+ Claude calls `pair_with_hooc` with it, and Hooc switches to **Connected**. The code works once, expires after 10 minutes and allows 5 tries; **New code** makes a fresh one. Hooc's page says **Looking for Claude…** until the connector is running (Claude starts it when the app or a Claude Code session opens) and **Claude's connector is running** once it can take the code.
32
+
33
+ ### Check that it works
34
+
35
+ - **Claude Code:** run `/mcp`. `hooc` should be listed as connected. Then ask: *"List my Hooc scripts."*
36
+ - **Claude app:** start a new chat and ask the same thing. The first time, Claude asks to allow the Hooc tools.
37
+ - Ask: *"Make a Hooc script that adds a red border to every image on example.com."* Chrome shows **Claude wants to install a script**. Click **Install**, and Claude reports that you approved it.
38
+ - In Hooc's popup, switch **Claude connector** off and choose **1 hour**. Ask Claude to list your scripts again: it says Hooc has paused the connector.
39
+
40
+ If the first request after starting Claude takes up to 30 seconds, that is Hooc's worker waking up to reconnect.
41
+
42
+ ### Developers: run it from this folder
43
+
44
+ ```bash
45
+ npm install
46
+ npm run build && npm run build:connector
47
+ node connector/dist/index.js setup # prints the exact commands for this computer
48
+ ```
49
+
50
+ Then reload Hooc in `chrome://extensions`. `setup` prints a `claude mcp add` line and a `claude_desktop_config.json` entry that point at `connector/dist/index.js` (the Claude app needs the full path to `node`; `sh connector/add-to-claude-desktop.sh` adds it while Claude is quit). You can pair with **Connect Claude** as above, or the old way: run `node connector/dist/index.js pair` and type the code it prints into Hooc → Settings → Claude connector → **Advanced** → **Pairing code**.
51
+
52
+ ## What Claude can do
53
+
54
+ | Tool | What it does |
55
+ | --- | --- |
56
+ | `pair_with_hooc` | Pair with Hooc using the one-time code the user reads from Hooc's Connect Claude |
57
+ | `list_scripts` | Scripts with id, version, on/off, sites, grants, `@connect` hosts |
58
+ | `get_script` | Full source, parsed header, Hooc settings and tags |
59
+ | `get_logs` | Captured console output and errors (per script, level filter, newest N) |
60
+ | `get_values` | A script's `GM_setValue` storage |
61
+ | `get_status` | Connected? Scripts running? Allow User Scripts on? |
62
+ | `create_script` | Install a new script, always through the review page |
63
+ | `update_script` | Replace a script's code; review only if it adds permissions |
64
+ | `check_approval` | Outcome of a review that was still open when the call returned |
65
+ | `set_enabled` | Turn a script on or off |
66
+ | `trash_script` | Move a script to the Trash (restorable) |
67
+ | `run_on_open_tab` | Run a script once on the current tab, for testing. If Claude changed the code since you last saw it, Hooc asks you first |
68
+
69
+ Claude can't delete scripts for good, restore from the Trash, export backups, change Hooc's settings or turn off the kill switch.
70
+
71
+ ## Commands
72
+
73
+ ```bash
74
+ npx -y hooc-connector # MCP server on stdio (what Claude runs); or node connector/dist/index.js
75
+ npx -y hooc-connector pair # one-time code to type into Hooc (developers; users use Connect Claude)
76
+ npx -y hooc-connector unpair # forget the paired Hooc (it has to pair again)
77
+ npx -y hooc-connector status # address, config folder, paired or not
78
+ npx -y hooc-connector setup # setup steps for this computer
79
+ ```
80
+
81
+ ## Settings
82
+
83
+ Environment variables, or `~/.hooc-connector/config.json` (for example `{ "port": 17400 }`):
84
+
85
+ | Variable | Default | Meaning |
86
+ | --- | --- | --- |
87
+ | `HOOC_CONNECTOR_HOST` | `127.0.0.1` | Address the WebSocket server listens on |
88
+ | `HOOC_CONNECTOR_PORT` | `17345` | Port. Change Hooc's server address to match (Settings → Claude connector → Advanced). In the Claude app it's the extension's **Port** setting |
89
+ | `HOOC_CONNECTOR_HOME` | `~/.hooc-connector` | Folder for `config.json` and `state.json` |
90
+
91
+ `state.json` holds the pairing token. It is created readable by you only (mode 600).
92
+
93
+ ## How it stays safe
94
+
95
+ - It listens on `127.0.0.1` only, unless you set another host yourself. Hooc, for its part, only connects to an address on this computer (`127.0.0.1`, `localhost` or `[::1]`).
96
+ - New scripts, and changes that add permissions, open Hooc's review page. If Claude changed a script's code directly and then wants to run it on your open tab, Hooc shows the code and the tab first and runs it only after you click **Run once** (it remembers that until Chrome restarts, for that exact code).
97
+ - Web pages can't connect. Browsers always send a page's `Origin`, and the connector only accepts `chrome-extension://` origins (after pairing, only that one Hooc). A second connector (see below) sends no Origin and must have the token.
98
+ - Every socket must authenticate within 5 seconds: Hooc with its token, Hooc waiting to pair, a pair-command code, or a code passed on by a second connector.
99
+ - **Connect Claude pairing:** Hooc makes the code, shows it only on its own Settings page and keeps it in `chrome.storage.session` (gone when Chrome closes, never in backups). It never sends the code anywhere. The connector forwards whatever code Claude was given to the Hooc that is waiting, and Hooc says yes or no. Only after a yes does the connector make a token, and it sends it on that same socket, so the token belongs to the extension that showed the code. Hooc ignores a "paired" message it didn't say yes to. Guessing is hopeless: about 39 bits, 5 tries per code (then the code is thrown away), 10 minutes, and the connector accepts at most one try a second and 10 per 10 minutes. Another program on this computer could try codes through the connector too, but it can't see the code and gets the same limits.
100
+ - Pair-command codes (developers): single-use, expire after 10 minutes and stop working after 5 wrong tries.
101
+ - Hooc checks every request against a fixed list of methods and validates the parameters before acting. The token lives in `chrome.storage.local` under its own key, so it never ends up in a Hooc backup.
102
+ - Limit: a program running as you that grabs port 17345 before the connector starts could pose as the connector to Hooc (it would still need Hooc's review page for new scripts and added permissions). That's true of any local helper; programs running as you can already read your files.
103
+
104
+ ### Claude Code and the Claude app at the same time
105
+
106
+ Each app starts its own connector. The first one takes the port; the second notices and sends its requests through the first. If the first one exits, the second takes over the port and Hooc reconnects to it.
107
+
108
+ ## Troubleshooting
109
+
110
+ - **"Hooc isn't connected"**: Chrome is closed, the connector is off in Hooc, or Hooc is still waking up. Open Hooc → Settings → Claude connector and click **Connect now**.
111
+ - **"isn't paired"**: click **Connect Claude** in Hooc and tell Claude the code.
112
+ - **"Hooc isn't waiting for a pairing code"**: Hooc's Connect Claude page isn't showing a code, or Chrome is closed. Click **Connect Claude** (or **New code**) and try again.
113
+ - **Hooc stays on "Looking for Claude…"**: the connector isn't running. Open the Claude app (or start Claude Code) and check the connector is installed (Claude app: Settings → Extensions; Claude Code: `/mcp`). If you changed the port, set the same port under **Advanced** in Hooc.
114
+ - **Pairing says "Unknown token" later**: you ran `unpair`, reinstalled the connector, or paired another Chrome profile. Unpair in Hooc and connect again.
115
+ - **Port in use by something else**: set `HOOC_CONNECTOR_PORT` (or `config.json`) and change Hooc's server address to match.
116
+ - Logs go to stderr. Claude Code shows them with `claude --debug`; the Claude app writes them to `~/Library/Logs/Claude/mcp-server-hooc.log`.
117
+
118
+ ## Moving to a Raspberry Pi later
119
+
120
+ The connector is built to move, but the Pi setup isn't done yet. What changes:
121
+
122
+ 0. **Hooc's address check.** Hooc only accepts a connector address on this computer (`parseServerUrl` in `src/core/connector-policy.ts`, kept strict for the Chrome Web Store). Allowing the Pi means relaxing that, for example behind a setting, and updating the store notes that say "local only".
123
+ 1. **Bind address.** On the Pi, set `HOOC_CONNECTOR_HOST` to its LAN address (or `0.0.0.0`). The connector prints a warning whenever it listens beyond the local machine.
124
+ 2. **TLS.** Plain `ws://` sends the token unencrypted, so on a network use `wss://`. The WebSocket listener lives in `src/ws-server.ts` on purpose: a TLS listener (an `https` server with a certificate, or a reverse proxy such as Caddy in front) goes next to it. Hooc's server address then becomes `wss://raspberrypi.local:17345`.
125
+ 3. **Token.** Pair again against the Pi (`pair` on the Pi, code into Hooc's Advanced section). Each Chrome profile is one pairing; the Mac's `state.json` doesn't move.
126
+ 4. **`host_permissions`.** Hooc already has `<all_urls>`. If that is ever narrowed, add the Pi's address (for example `wss://raspberrypi.local/*`) to `manifest.config.ts`.
127
+ 5. **Remote MCP config.** Claude can't start a program on the Pi over stdio. Add an MCP Streamable HTTP transport next to `src/transport-stdio.ts` (the SDK has `StreamableHTTPServerTransport`), protect it with its own token, and add it to Claude Code with `claude mcp add --transport http hooc https://raspberrypi.local:17346/mcp`. The connector would then run all the time on the Pi (a systemd service) instead of starting on demand.
128
+
129
+ ## Development
130
+
131
+ ```bash
132
+ npm run build:connector # tsc → connector/dist (what the e2e tests and `setup` use)
133
+ npm run bundle:connector # release build → connector/dist-bundle/ (see below)
134
+ npm test # unit tests include tests/unit/connector-*.test.ts
135
+ npm run e2e # builds all three, then the connector*.spec.ts files run the real connector
136
+ ```
137
+
138
+ ### Release builds
139
+
140
+ `npm run bundle:connector` (`connector/scripts/bundle.mjs`) makes:
141
+
142
+ - `connector/dist-bundle/hooc-connector.js`: the whole connector in one file with no dependencies (bundled with Vite), so it runs with plain `node`. This is the npm package's `bin`.
143
+ - `connector/dist-bundle/hooc-connector.mcpb`: an [MCP Bundle](https://github.com/anthropics/mcpb) for the Claude app: `manifest.json` (manifest_version 0.4, tools list read from the bundled server itself, a **Port** setting), `server/index.js` and `icon.png` (`connector/assets/icon.png`, made with `node scripts/make-icons.mjs connector`). It is validated and zipped with the official `@anthropic-ai/mcpb` CLI.
144
+
145
+ The version comes from `connector/package.json`; `src/version.ts` must say the same (the build checks). To try the npm package locally without publishing:
146
+
147
+ ```bash
148
+ cd connector && npm pack && npx -y ./hooc-connector-0.2.0.tgz status
149
+ ```
150
+
151
+ `npm pack` and `npm publish` run the release build first (`prepack`). Not published yet. The connector is MIT licensed (`connector/LICENSE`).
152
+
153
+ Code: `src/index.ts` (CLI), `src/transport-stdio.ts` (MCP stdio), `src/tools.ts` (tool definitions), `src/link.ts` (listen or relay), `src/ws-server.ts` (WebSocket listener, auth and Connect Claude pairing), `src/relay.ts`, `src/pairing.ts`, `src/config.ts`, `src/protocol.ts` (wire format) and `src/pair-code.ts` (pairing codes), both shared with the extension through `src/core/connector-protocol.ts` and `src/core/pair-code.ts`. The extension side is `src/background/connector.ts`, `connector-api.ts` and `approvals.ts`.
154
+
155
+ Dependencies (all bundled into the release file, so the published package has none): `@modelcontextprotocol/sdk` (the official MCP implementation, used for the server and the e2e client), `ws` (Node has a WebSocket client built in but no server) and `zod` (the SDK's schema library for tool inputs). Build only: `@anthropic-ai/mcpb` (official MCP Bundle validator and packer) and `vite` (already used for Hooc).