hopwire 0.0.0-stage → 0.1.1
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 +201 -0
- package/NOTICE +8 -0
- package/README.md +29 -2
- package/dist/account.js +168 -0
- package/dist/agent/redact.js +101 -0
- package/dist/agent/summary.js +32 -0
- package/dist/agent-socket.js +93 -0
- package/dist/bin.js +22 -0
- package/dist/body-capture.js +28 -0
- package/dist/browser.js +42 -0
- package/dist/cli.js +683 -0
- package/dist/commands/connect.js +221 -0
- package/dist/commands/doctor.js +107 -0
- package/dist/commands/http.js +108 -0
- package/dist/commands/login.js +133 -0
- package/dist/commands/mcp.js +69 -0
- package/dist/commands/rotate.js +57 -0
- package/dist/commands/up.js +149 -0
- package/dist/commands/watch.js +146 -0
- package/dist/config.js +302 -0
- package/dist/control-plane-client.js +300 -0
- package/dist/data-dir-holder.js +178 -0
- package/dist/edge-bridge.js +1031 -0
- package/dist/errors.js +53 -0
- package/dist/identity.js +134 -0
- package/dist/inspector/THIRD-PARTY-NOTICES.txt +330 -0
- package/dist/inspector/assets/index-BvwyMIFs.css +2 -0
- package/dist/inspector/assets/index-Ctrz3UJp.js +2 -0
- package/dist/inspector/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/inspector/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/dist/inspector/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/inspector/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/dist/inspector/assets/space-grotesk-latin-400-normal-CJ-V5oYT.woff2 +0 -0
- package/dist/inspector/assets/space-grotesk-latin-500-normal-lFbtlQH6.woff2 +0 -0
- package/dist/inspector/assets/space-grotesk-latin-ext-400-normal-CfP_5XZW.woff2 +0 -0
- package/dist/inspector/assets/space-grotesk-latin-ext-500-normal-DUe3BAxM.woff2 +0 -0
- package/dist/inspector/favicon.svg +1 -0
- package/dist/inspector/index.html +16 -0
- package/dist/inspector-api.js +508 -0
- package/dist/inspector-server.js +150 -0
- package/dist/interceptor.js +480 -0
- package/dist/log.js +393 -0
- package/dist/main.js +38 -0
- package/dist/mcp/body.js +134 -0
- package/dist/mcp/client.js +169 -0
- package/dist/mcp/jsonrpc.js +170 -0
- package/dist/mcp/tools.js +715 -0
- package/dist/output.js +249 -0
- package/dist/p2p-stream.js +226 -0
- package/dist/p2p.js +389 -0
- package/dist/prompt.js +62 -0
- package/dist/proxy-server.js +252 -0
- package/dist/serve.js +234 -0
- package/dist/style.js +60 -0
- package/dist/supervisor.js +146 -0
- package/dist/team-keys.js +129 -0
- package/dist/update-notice.js +67 -0
- package/dist/urls.js +45 -0
- package/dist/websocket.js +99 -0
- package/node_modules/@hopwire/protocol/LICENSE +201 -0
- package/node_modules/@hopwire/protocol/NOTICE +8 -0
- package/node_modules/@hopwire/protocol/dist/basic-auth.d.ts +9 -0
- package/node_modules/@hopwire/protocol/dist/basic-auth.js +21 -0
- package/node_modules/@hopwire/protocol/dist/constants.d.ts +91 -0
- package/node_modules/@hopwire/protocol/dist/constants.js +89 -0
- package/node_modules/@hopwire/protocol/dist/exchange.d.ts +54 -0
- package/node_modules/@hopwire/protocol/dist/exchange.js +71 -0
- package/node_modules/@hopwire/protocol/dist/frames.d.ts +177 -0
- package/node_modules/@hopwire/protocol/dist/frames.js +191 -0
- package/node_modules/@hopwire/protocol/dist/headers.d.ts +20 -0
- package/node_modules/@hopwire/protocol/dist/headers.js +58 -0
- package/node_modules/@hopwire/protocol/dist/index.d.ts +10 -0
- package/node_modules/@hopwire/protocol/dist/index.js +10 -0
- package/node_modules/@hopwire/protocol/dist/inspector.d.ts +46 -0
- package/node_modules/@hopwire/protocol/dist/inspector.js +42 -0
- package/node_modules/@hopwire/protocol/dist/p2p.d.ts +52 -0
- package/node_modules/@hopwire/protocol/dist/p2p.js +119 -0
- package/node_modules/@hopwire/protocol/dist/plan.d.ts +104 -0
- package/node_modules/@hopwire/protocol/dist/plan.js +180 -0
- package/node_modules/@hopwire/protocol/dist/subdomain.d.ts +10 -0
- package/node_modules/@hopwire/protocol/dist/subdomain.js +30 -0
- package/node_modules/@hopwire/protocol/dist/websocket.d.ts +70 -0
- package/node_modules/@hopwire/protocol/dist/websocket.js +113 -0
- package/node_modules/@hopwire/protocol/package.json +13 -0
- package/package.json +38 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Hopwire
|
|
2
|
+
Copyright 2026 The Hopwire authors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
"Hopwire" and the Hopwire logo are names and marks of the operator of Hopwire
|
|
7
|
+
(https://hopwire.to/imprint). The licence grants no right to use them, except
|
|
8
|
+
as needed to describe where the software comes from (section 6 of the licence).
|
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Hopwire
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Record, share and replay the HTTP traffic of your local services.
|
|
4
|
+
|
|
5
|
+
- **Private mode** (no account): every request that reaches your local service is recorded in a local traffic log
|
|
6
|
+
and shown in the inspector at `http://127.0.0.1:4040`. Share the log with teammates directly, peer to peer and
|
|
7
|
+
end-to-end encrypted, so they can watch it live and replay requests against their own `localhost`.
|
|
8
|
+
- **Public mode** (free account): a public HTTPS URL for your local service, for webhooks and demos.
|
|
9
|
+
|
|
10
|
+
Requires Node.js 20 or newer.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g hopwire
|
|
14
|
+
hopwire http 3000 # record and inspect the traffic of the service on port 3000
|
|
15
|
+
hopwire http 3000 --share # let teammates watch and replay it, peer to peer
|
|
16
|
+
hopwire login # once, for public URLs
|
|
17
|
+
hopwire http 3000 --public # a public HTTPS URL for the service
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Documentation: https://hopwire.to/docs. Terms: https://hopwire.to/terms. Security reports:
|
|
21
|
+
https://hopwire.to/security.
|
|
22
|
+
|
|
23
|
+
## Licence
|
|
24
|
+
|
|
25
|
+
The CLI, the inspector and the protocol are licensed under the Apache License, Version 2.0: see `LICENSE` and
|
|
26
|
+
`NOTICE`. The inspector's files contain third-party software and fonts (Vue, Tailwind CSS, JetBrains Mono, Space
|
|
27
|
+
Grotesk); their licences are in `dist/inspector/THIRD-PARTY-NOTICES.txt`. The hosted service (the edge behind public URLs and the account service) is not part of this package and
|
|
28
|
+
is used under the terms above.
|
|
29
|
+
|
|
30
|
+
"Hopwire" and the Hopwire logo are not covered by the licence. A fork or a modified build needs a name of its own.
|
package/dist/account.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { chmod, mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { HopwireError, errorCode } from './errors.js';
|
|
5
|
+
import { parseControlPlaneUrl, parseEdgeUrl } from './urls.js';
|
|
6
|
+
const ACCOUNT_FILE = 'config.json';
|
|
7
|
+
/**
|
|
8
|
+
* The hosted control plane (website and account pages on one host, decision 70 of the spec): what `hopwire login`
|
|
9
|
+
* uses when neither --api nor an earlier login names one. Only `hopwire login` reads it; nothing else contacts it.
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_CONTROL_PLANE_URL = 'https://hopwire.to';
|
|
12
|
+
/** An API token of the control plane: hw_ followed by 40 base62 characters. */
|
|
13
|
+
const API_TOKEN_PATTERN = /^hw_[0-9A-Za-z]{40}$/;
|
|
14
|
+
export function isApiToken(value) {
|
|
15
|
+
return API_TOKEN_PATTERN.test(value);
|
|
16
|
+
}
|
|
17
|
+
export function accountFile(dataDir) {
|
|
18
|
+
return path.join(dataDir, ACCOUNT_FILE);
|
|
19
|
+
}
|
|
20
|
+
/** The stored account, null when nobody is logged in. A file that is not what `hopwire login` wrote is refused. */
|
|
21
|
+
export async function readAccount(dataDir) {
|
|
22
|
+
const stored = await readStored(dataDir);
|
|
23
|
+
return stored === null || stored.apiToken === null
|
|
24
|
+
? null
|
|
25
|
+
: { apiToken: stored.apiToken, controlPlaneUrl: stored.controlPlaneUrl };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The control plane of the last login, also after a logout; null when this machine was never logged in. A file that
|
|
29
|
+
* is not what `hopwire login` wrote is refused.
|
|
30
|
+
*/
|
|
31
|
+
export async function readControlPlaneUrl(dataDir) {
|
|
32
|
+
return (await readStored(dataDir))?.controlPlaneUrl ?? null;
|
|
33
|
+
}
|
|
34
|
+
async function readStored(dataDir) {
|
|
35
|
+
const file = accountFile(dataDir);
|
|
36
|
+
let text;
|
|
37
|
+
try {
|
|
38
|
+
text = await readFile(file, 'utf8');
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (errorCode(error) === 'ENOENT') {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
const stored = parse(text);
|
|
47
|
+
if (stored === null) {
|
|
48
|
+
throw new HopwireError(`The file ${file} is damaged; run hopwire login again to replace it, or hopwire logout to remove it.`);
|
|
49
|
+
}
|
|
50
|
+
// Repairs a file that was copied or restored with wider permissions
|
|
51
|
+
await chmod(file, 0o600);
|
|
52
|
+
return stored;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Stores the account, replacing an earlier one. The file is complete and owner-only from the moment it exists. A new
|
|
56
|
+
* login binds the account to the edge its control plane names; without one, the next public start binds it.
|
|
57
|
+
*/
|
|
58
|
+
export async function writeAccount(dataDir, account, edgeUrl = null) {
|
|
59
|
+
await writeStored(dataDir, { ...account, edgeUrl: edgeUrl === null ? null : new URL(edgeUrl.origin) });
|
|
60
|
+
}
|
|
61
|
+
/** The edge the logged-in account is bound to; null when nobody is logged in or no edge is bound yet. */
|
|
62
|
+
export async function boundEdge(dataDir) {
|
|
63
|
+
const stored = await readStored(dataDir);
|
|
64
|
+
return stored === null || stored.apiToken === null ? null : stored.edgeUrl;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Binds the connect tokens of the logged-in account to one edge. The first public start that uses the account
|
|
68
|
+
* stores the origin of its edge; every later one gets that origin back and has to use the same edge, so a project
|
|
69
|
+
* file or an environment cannot send the account's tokens (and a channel into this machine's services) to an edge
|
|
70
|
+
* of its choosing. The caller of a first start passes the edge the control plane of the account names when it names
|
|
71
|
+
* one (cli.ts, accountEdge). Resolves with the bound edge. A new `hopwire login` clears the binding.
|
|
72
|
+
*/
|
|
73
|
+
export async function bindEdge(dataDir, edgeUrl) {
|
|
74
|
+
const stored = await readStored(dataDir);
|
|
75
|
+
if (stored === null || stored.apiToken === null) {
|
|
76
|
+
throw new HopwireError('This machine is not logged in; run hopwire login first.');
|
|
77
|
+
}
|
|
78
|
+
if (stored.edgeUrl !== null) {
|
|
79
|
+
return stored.edgeUrl;
|
|
80
|
+
}
|
|
81
|
+
await writeStored(dataDir, { ...stored, edgeUrl: new URL(edgeUrl.origin) });
|
|
82
|
+
return edgeUrl;
|
|
83
|
+
}
|
|
84
|
+
async function writeStored(dataDir, stored) {
|
|
85
|
+
// A data directory that has to be created holds key material and traffic: owner only
|
|
86
|
+
await mkdir(dataDir, { recursive: true, mode: 0o700 });
|
|
87
|
+
const file = accountFile(dataDir);
|
|
88
|
+
const content = JSON.stringify({
|
|
89
|
+
...(stored.apiToken === null ? {} : { apiToken: stored.apiToken }),
|
|
90
|
+
controlPlaneUrl: stored.controlPlaneUrl.origin,
|
|
91
|
+
...(stored.edgeUrl === null ? {} : { edgeUrl: stored.edgeUrl.origin }),
|
|
92
|
+
}, null, 4);
|
|
93
|
+
const draft = `${file}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`;
|
|
94
|
+
await writeFile(draft, `${content}\n`, { mode: 0o600, flag: 'wx' });
|
|
95
|
+
try {
|
|
96
|
+
await rename(draft, file);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
await unlink(draft).catch(() => { });
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Removes the stored API token and keeps the URL of the control plane it belonged to. A damaged file is removed as
|
|
105
|
+
* a whole. Resolves with false when no token was stored.
|
|
106
|
+
*/
|
|
107
|
+
export async function removeAccount(dataDir) {
|
|
108
|
+
let stored;
|
|
109
|
+
try {
|
|
110
|
+
stored = await readStored(dataDir);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (!(error instanceof HopwireError)) {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
// Damaged: whatever it holds, a token included, goes
|
|
117
|
+
await unlink(accountFile(dataDir)).catch((failure) => {
|
|
118
|
+
if (errorCode(failure) !== 'ENOENT') {
|
|
119
|
+
throw failure;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (stored === null || stored.apiToken === null) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
// Written anew and renamed into place: the token is in no file any more once this resolves
|
|
128
|
+
await writeStored(dataDir, { ...stored, apiToken: null });
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
function parse(text) {
|
|
132
|
+
let value;
|
|
133
|
+
try {
|
|
134
|
+
value = JSON.parse(text);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
if (typeof value !== 'object' ||
|
|
140
|
+
value === null ||
|
|
141
|
+
Array.isArray(value) ||
|
|
142
|
+
!('controlPlaneUrl' in value) ||
|
|
143
|
+
typeof value.controlPlaneUrl !== 'string') {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
// Without a token: logged out. With one, it has to be a token
|
|
147
|
+
let apiToken = null;
|
|
148
|
+
if ('apiToken' in value) {
|
|
149
|
+
if (typeof value.apiToken !== 'string' || !isApiToken(value.apiToken)) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
apiToken = value.apiToken;
|
|
153
|
+
}
|
|
154
|
+
// The same rule as at login: the token only ever travels over https, or to this machine
|
|
155
|
+
const controlPlaneUrl = parseControlPlaneUrl(value.controlPlaneUrl);
|
|
156
|
+
if (typeof controlPlaneUrl === 'string') {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
let edgeUrl = null;
|
|
160
|
+
if ('edgeUrl' in value) {
|
|
161
|
+
const parsed = typeof value.edgeUrl === 'string' ? parseEdgeUrl(value.edgeUrl) : 'malformed';
|
|
162
|
+
if (typeof parsed === 'string') {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
edgeUrl = parsed;
|
|
166
|
+
}
|
|
167
|
+
return { apiToken, controlPlaneUrl, edgeUrl };
|
|
168
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction of what a coding agent is shown (spec decision 73). It changes only what is displayed: the traffic log
|
|
3
|
+
* and every replay keep the stored bytes. The rules live here once, for the summaries route of the inspector API and
|
|
4
|
+
* for `hopwire mcp`.
|
|
5
|
+
*/
|
|
6
|
+
/** The start of every redacted value. An edit an agent sends that contains it is refused, so a placeholder never reaches a service. */
|
|
7
|
+
export const REDACTION_MARKER = '[redacted';
|
|
8
|
+
/** Headers that are always redacted, besides the names that match SENSITIVE_NAME */
|
|
9
|
+
const SENSITIVE_HEADERS = new Set(['authorization', 'proxy-authorization', 'cookie', 'set-cookie', 'x-api-key']);
|
|
10
|
+
/** Names of headers that carry credentials or signatures */
|
|
11
|
+
const SENSITIVE_NAME = /(token|secret|signature|password|passwd|session|api[-_]?key|auth)/i;
|
|
12
|
+
/** Names of query parameters, form fields and JSON keys: the header names plus payment data */
|
|
13
|
+
const SENSITIVE_FIELD = /(token|secret|signature|password|passwd|session|api[-_]?key|auth|card|cvc|cvv|iban)/i;
|
|
14
|
+
/** What is shown instead of a value: its length, nothing of its content. */
|
|
15
|
+
export function redacted(value) {
|
|
16
|
+
return `${REDACTION_MARKER}, ${[...value].length} chars]`;
|
|
17
|
+
}
|
|
18
|
+
export function isRedactedHeader(name) {
|
|
19
|
+
const lower = name.toLowerCase();
|
|
20
|
+
return SENSITIVE_HEADERS.has(lower) || SENSITIVE_NAME.test(lower);
|
|
21
|
+
}
|
|
22
|
+
export function isRedactedField(name) {
|
|
23
|
+
return SENSITIVE_FIELD.test(name);
|
|
24
|
+
}
|
|
25
|
+
/** The headers as shown: a redacted value keeps the scheme of an authorization header (`Bearer [redacted, 40 chars]`). */
|
|
26
|
+
export function redactHeaders(headers) {
|
|
27
|
+
return headers.map(([name, value]) => {
|
|
28
|
+
if (!isRedactedHeader(name)) {
|
|
29
|
+
return [name, value];
|
|
30
|
+
}
|
|
31
|
+
const lower = name.toLowerCase();
|
|
32
|
+
if (lower === 'authorization' || lower === 'proxy-authorization') {
|
|
33
|
+
const scheme = /^([A-Za-z][A-Za-z0-9!#$%&'*+.^_`|~-]*) +(.*)$/s.exec(value);
|
|
34
|
+
if (scheme?.[1] !== undefined && scheme[2] !== undefined) {
|
|
35
|
+
return [name, `${scheme[1]} ${redacted(scheme[2])}`];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [name, redacted(value)];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** A path with the values of sensitive query parameters redacted; the rest is kept as it was written. */
|
|
42
|
+
export function redactPath(requestPath) {
|
|
43
|
+
const at = requestPath.indexOf('?');
|
|
44
|
+
if (at === -1) {
|
|
45
|
+
return requestPath;
|
|
46
|
+
}
|
|
47
|
+
return `${requestPath.slice(0, at)}?${redactUrlEncoded(requestPath.slice(at + 1))}`;
|
|
48
|
+
}
|
|
49
|
+
/** `a=1&password=2` with the values of sensitive names redacted (query strings and form bodies). */
|
|
50
|
+
export function redactUrlEncoded(text) {
|
|
51
|
+
return text
|
|
52
|
+
.split('&')
|
|
53
|
+
.map((pair) => {
|
|
54
|
+
const at = pair.indexOf('=');
|
|
55
|
+
if (at === -1) {
|
|
56
|
+
return pair;
|
|
57
|
+
}
|
|
58
|
+
const name = decodeComponent(pair.slice(0, at));
|
|
59
|
+
const value = pair.slice(at + 1);
|
|
60
|
+
return isRedactedField(name) ? `${pair.slice(0, at)}=${redacted(decodeComponent(value))}` : pair;
|
|
61
|
+
})
|
|
62
|
+
.join('&');
|
|
63
|
+
}
|
|
64
|
+
/** A parsed JSON value with every value under a sensitive key redacted, however deep it lies. */
|
|
65
|
+
export function redactJson(value) {
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return value.map(redactJson);
|
|
68
|
+
}
|
|
69
|
+
if (typeof value === 'object' && value !== null) {
|
|
70
|
+
const result = {};
|
|
71
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
72
|
+
// Defined, not assigned: a key named __proto__ (JSON.parse makes it an own property) stays a key
|
|
73
|
+
Object.defineProperty(result, key, {
|
|
74
|
+
value: isRedactedField(key)
|
|
75
|
+
? redacted(typeof inner === 'string' ? inner : JSON.stringify(inner))
|
|
76
|
+
: redactJson(inner),
|
|
77
|
+
enumerable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function decodeComponent(text) {
|
|
87
|
+
try {
|
|
88
|
+
return decodeURIComponent(text.replace(/\+/g, ' '));
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return text;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* JSON text that does not parse (cut at the capture limit) with the values of sensitive keys redacted as far as
|
|
96
|
+
* they can be found: `"key": "value"` and `"key": 123`. An object or list under such a key is left as it is up to
|
|
97
|
+
* where the text ends, so the key is redacted when a value of its own follows it.
|
|
98
|
+
*/
|
|
99
|
+
export function redactJsonText(text) {
|
|
100
|
+
return text.replace(/"((?:[^"\\]|\\.)*)"(\s*:\s*)("(?:[^"\\]|\\.)*"?|[^,}\]\s"{[]+)/g, (whole, key, colon, value) => isRedactedField(key) ? `"${key}"${colon}"${redacted(value.replace(/^"|"$/g, ''))}"` : whole);
|
|
101
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getHeader, isWebSocketHandshake, } from '@hopwire/protocol';
|
|
2
|
+
import { redactPath } from './redact.js';
|
|
3
|
+
export function summarize({ index, exchange }) {
|
|
4
|
+
const { request, response } = exchange;
|
|
5
|
+
return {
|
|
6
|
+
id: exchange.id,
|
|
7
|
+
index,
|
|
8
|
+
timestamp: exchange.timestamp,
|
|
9
|
+
serviceName: exchange.serviceName,
|
|
10
|
+
source: exchange.source,
|
|
11
|
+
replayOf: exchange.replayOf ?? null,
|
|
12
|
+
method: request.method,
|
|
13
|
+
path: redactPath(request.path),
|
|
14
|
+
status: response.status,
|
|
15
|
+
durationMs: response.durationMs,
|
|
16
|
+
websocket: isWebSocketHandshake(exchange),
|
|
17
|
+
request: partSummary(request),
|
|
18
|
+
response: partSummary(response),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function partSummary(part) {
|
|
22
|
+
return {
|
|
23
|
+
contentType: getHeader(part.headers, 'content-type') ?? null,
|
|
24
|
+
bytes: base64Bytes(part.bodyBase64),
|
|
25
|
+
truncated: part.bodyTruncated,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Bytes a padded Base64 string decodes to, without decoding it. */
|
|
29
|
+
export function base64Bytes(value) {
|
|
30
|
+
const padding = value.endsWith('==') ? 2 : value.endsWith('=') ? 1 : 0;
|
|
31
|
+
return (value.length / 4) * 3 - padding;
|
|
32
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { once } from 'node:events';
|
|
2
|
+
import { chmod, lstat, mkdir, unlink } from 'node:fs/promises';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { HopwireError, errorCode } from './errors.js';
|
|
6
|
+
import { ApiError, sendError } from './inspector-api.js';
|
|
7
|
+
/**
|
|
8
|
+
* The agent socket of a tunnel started with --agent: the inspector API on a Unix socket that only this user can
|
|
9
|
+
* reach (`<dataDir>/run/agent.sock`, the directory 0700, the socket 0600), for `hopwire mcp`. It needs no access
|
|
10
|
+
* key, Host or Origin check: a browser cannot reach a Unix socket, and the file system decides who can.
|
|
11
|
+
*/
|
|
12
|
+
/** Longest socket path that fits `sun_path` on every system Hopwire runs on (104 bytes on macOS, with the NUL) */
|
|
13
|
+
export const AGENT_SOCKET_PATH_MAX_BYTES = 103;
|
|
14
|
+
/** Where a data directory's agent socket lies: the tunnel listens there, `hopwire mcp` connects there. */
|
|
15
|
+
export function agentSocketPath(dataDir) {
|
|
16
|
+
return path.join(path.resolve(dataDir), 'run', 'agent.sock');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks the directory of the socket: a real directory (no symlink), owned by this user, nobody else can enter it.
|
|
20
|
+
* Throws a HopwireError otherwise. A tunnel sets a wider mode back to 0700 first (`repair`); `hopwire mcp` only
|
|
21
|
+
* checks.
|
|
22
|
+
*/
|
|
23
|
+
export async function checkRunDirectory(dir, repair) {
|
|
24
|
+
const stats = await lstat(dir);
|
|
25
|
+
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
26
|
+
throw new HopwireError(`${dir} must be a directory, not a link or a file; remove it and start again.`);
|
|
27
|
+
}
|
|
28
|
+
if (stats.uid !== process.getuid?.()) {
|
|
29
|
+
throw new HopwireError(`${dir} belongs to another user; use a data directory of your own with --data-dir <path>.`);
|
|
30
|
+
}
|
|
31
|
+
if ((stats.mode & 0o077) !== 0) {
|
|
32
|
+
if (!repair) {
|
|
33
|
+
throw new HopwireError(`${dir} can be entered by other users; restart the tunnel with --agent to fix it.`);
|
|
34
|
+
}
|
|
35
|
+
await chmod(dir, 0o700);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function startAgentSocket(api, dataDir) {
|
|
39
|
+
if (process.platform === 'win32') {
|
|
40
|
+
throw new HopwireError('--agent needs a Unix socket and is not available on Windows.');
|
|
41
|
+
}
|
|
42
|
+
const socketPath = agentSocketPath(dataDir);
|
|
43
|
+
if (Buffer.byteLength(socketPath) > AGENT_SOCKET_PATH_MAX_BYTES) {
|
|
44
|
+
throw new HopwireError(`The agent socket ${socketPath} is longer than the ${AGENT_SOCKET_PATH_MAX_BYTES} bytes a Unix socket path may have; choose a shorter data directory with --data-dir <path>.`);
|
|
45
|
+
}
|
|
46
|
+
const dir = path.dirname(socketPath);
|
|
47
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
48
|
+
await checkRunDirectory(dir, true);
|
|
49
|
+
// The tunnel holds the lock of the data directory, so a socket left here is one of a run that ended
|
|
50
|
+
try {
|
|
51
|
+
const existing = await lstat(socketPath);
|
|
52
|
+
if (!existing.isSocket()) {
|
|
53
|
+
throw new HopwireError(`${socketPath} is not a socket; remove it and start again.`);
|
|
54
|
+
}
|
|
55
|
+
await unlink(socketPath);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (errorCode(error) !== 'ENOENT') {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const server = http.createServer((req, res) => {
|
|
63
|
+
handle(req, res).catch((error) => sendError(res, error, 'The tunnel'));
|
|
64
|
+
});
|
|
65
|
+
async function handle(req, res) {
|
|
66
|
+
const [fullPath = '/', query = ''] = (req.url ?? '/').split('?', 2);
|
|
67
|
+
const [first, ...route] = fullPath.split('/').slice(1);
|
|
68
|
+
if (first !== 'api') {
|
|
69
|
+
throw new ApiError(404, 'not_found', 'The agent socket only serves the inspector API under /api');
|
|
70
|
+
}
|
|
71
|
+
await api.handle(req, res, route, query);
|
|
72
|
+
}
|
|
73
|
+
// The directory keeps everyone else out from the start; the socket is narrowed right after it exists
|
|
74
|
+
server.listen(socketPath);
|
|
75
|
+
await once(server, 'listening');
|
|
76
|
+
try {
|
|
77
|
+
await chmod(socketPath, 0o600);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
server.close();
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
path: socketPath,
|
|
85
|
+
async close() {
|
|
86
|
+
server.close();
|
|
87
|
+
server.closeAllConnections();
|
|
88
|
+
await once(server, 'close');
|
|
89
|
+
// Node removes the socket file on close; one that is left is removed here
|
|
90
|
+
await unlink(socketPath).catch(() => { });
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { openBrowser } from './browser.js';
|
|
3
|
+
import { main } from './main.js';
|
|
4
|
+
import { promptHidden } from './prompt.js';
|
|
5
|
+
import { decorate, wantsColor } from './style.js';
|
|
6
|
+
const color = wantsColor(process.stdout, process.env);
|
|
7
|
+
await main({
|
|
8
|
+
argv: process.argv.slice(2),
|
|
9
|
+
env: process.env,
|
|
10
|
+
print: (line) => process.stdout.write(`${color ? decorate(line) : line}\n`),
|
|
11
|
+
error: (line) => process.stderr.write(`${line}\n`),
|
|
12
|
+
on: (signal, listener) => process.on(signal, listener),
|
|
13
|
+
exit: (code) => process.exit(code),
|
|
14
|
+
// Opened only when a command reads it
|
|
15
|
+
input: () => process.stdin,
|
|
16
|
+
// Only a terminal can be asked without showing the answer
|
|
17
|
+
promptSecret: process.stdin.isTTY
|
|
18
|
+
? (question, stop) => promptHidden(question, process.stdin, process.stderr, stop)
|
|
19
|
+
: undefined,
|
|
20
|
+
// hopwire login opens its sign-in page; the URL is printed too
|
|
21
|
+
openBrowser: (url) => openBrowser(url),
|
|
22
|
+
});
|