hrpc-inspector 0.0.0 → 0.1.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 +202 -0
- package/NOTICE +16 -0
- package/README.md +65 -0
- package/USAGE.md +180 -0
- package/bin/hrpc-inspector.mjs +79 -0
- package/dist/detect.js +21 -0
- package/dist/index.js +441 -0
- package/dist/observe.js +417 -0
- package/gui/index.html +996 -0
- package/gui/server.mjs +240 -0
- package/package.json +65 -1
- package/src/detect.ts +49 -0
- package/src/index.ts +37 -0
- package/src/init.mjs +89 -0
- package/src/observe.ts +430 -0
- package/src/reporters.ts +84 -0
- package/src/wrap-client.ts +140 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
bare-network-inspect
|
|
2
|
+
Copyright 2026 Holepunch
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Holepunch.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# hrpc-inspector
|
|
2
|
+
|
|
3
|
+
hrpc based debugging and observability for Bare. Tap an RPC client or a raw transport and read
|
|
4
|
+
endpoint, request, response, latency and live subscription streams — the same core across
|
|
5
|
+
**React Native** (via `react-native-bare-kit` worklets), **Pear/Bare**, **Electron/Node** and the
|
|
6
|
+
browser.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm i -D hrpc-inspector
|
|
10
|
+
npx hrpc-inspector init # detect the project, preview the plan (writes nothing)
|
|
11
|
+
npx hrpc-inspector init --write # apply (never overwrites an existing file)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Use
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { observe } from 'hrpc-inspector'
|
|
18
|
+
|
|
19
|
+
const obs = observe({
|
|
20
|
+
websocket: 'ws://127.0.0.1:9420/ws', // reliable local-dev viewer
|
|
21
|
+
allowInvoke: true, // opt in to GUI replay — DEV BUILDS ONLY
|
|
22
|
+
})
|
|
23
|
+
const client = obs.wrapClient(myRpcClient) // endpoint + request + response + streams
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npx hrpc-inspector gui # http://localhost:9420
|
|
28
|
+
adb reverse tcp:9420 tcp:9420 # Android only, or the device cannot reach your machine
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
No client to wrap? Tap the transport directly:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { observe, instrumentDataChannel } from 'hrpc-inspector'
|
|
35
|
+
instrumentDataChannel(dataChannel, peerId, observe({ websocket: 'ws://127.0.0.1:9420/ws' }).sink)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Two export paths, and the difference matters
|
|
39
|
+
|
|
40
|
+
Pass `websocket` and events stream to the local GUI over a plain WebSocket — reliable on every
|
|
41
|
+
runtime because it is not DHT holepunching. Omit it and, inside Bare/Pear, `observe()` auto-dials a
|
|
42
|
+
Hyperswarm hub so multiple peers merge into one timeline ordered by hybrid logical clock.
|
|
43
|
+
|
|
44
|
+
Redaction follows that split: **off** for the local viewer (localhost, never leaves the machine),
|
|
45
|
+
**on** for the hub (it leaves the device). Full reference in [USAGE.md](USAGE.md).
|
|
46
|
+
|
|
47
|
+
## Replay is opt-in
|
|
48
|
+
|
|
49
|
+
The GUI can re-run a call the app already made. That is an inbound execution surface, so it needs an
|
|
50
|
+
explicit `allowInvoke: true` and a `websocket:` viewer. The method is resolved from your app's own
|
|
51
|
+
call log and cannot be redirected from the wire; the **arguments are caller-supplied and unvalidated**,
|
|
52
|
+
so `canReplay(method, args)` is the only argument check in the system.
|
|
53
|
+
|
|
54
|
+
## Test
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
npm test
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Eleven dependency-free suites, including one that packs the tarball and runs the CLI out of it —
|
|
61
|
+
because every other suite runs against the worktree, where a packaging mistake is invisible.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
[Apache-2.0](LICENSE). Copyright notice in [NOTICE](NOTICE).
|
package/USAGE.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# hrpc-inspector — usage (all runtimes)
|
|
2
|
+
|
|
3
|
+
Observe an app's P2P / RPC traffic as a **network inspector** — endpoint, request, response,
|
|
4
|
+
latency, and **live subscription streams** — across React Native (bare-kit worklets), plain
|
|
5
|
+
Pear/Bare apps, desktop (Electron/Node), and the browser. One package, one GUI.
|
|
6
|
+
|
|
7
|
+
Signatures verified in `../../verification/{observe,wrap-client,ws-reporter,observe-redaction}.test.mjs`.
|
|
8
|
+
Ships as a bundled `dist/` (esbuild); source of truth is `src/`.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. Two ways to tap (pick what fits the app)
|
|
13
|
+
|
|
14
|
+
### A) `wrapClient` — tap an RPC / service client ★ recommended
|
|
15
|
+
For any object of namespaced methods (`client.namespace.method(...)`) that returns a **Promise**
|
|
16
|
+
(request/response) or a **stream** (subscription). This is the most useful and the most
|
|
17
|
+
portable tap — it produces named endpoints + request args + the actual response, and it
|
|
18
|
+
**monitors subscription streams** (so they don't sit "pending"). Works in every runtime.
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { observe } from 'hrpc-inspector'
|
|
22
|
+
const obs = observe({ websocket: 'ws://127.0.0.1:9420/ws' }) // where events go (see §2)
|
|
23
|
+
const client = obs.wrapClient(myRpcClient) // tap it; returns the same client
|
|
24
|
+
// use `client` exactly as before — calls now show up in the GUI
|
|
25
|
+
```
|
|
26
|
+
Emits `request.start` → `request.end` (promises) and `stream.open` → `stream.data*` →
|
|
27
|
+
`request.end` (subscriptions). Return values and `this` are preserved; a wrapped call behaves
|
|
28
|
+
identically. Opt out of stream monitoring with `obs.wrapClient(client, { monitorStreams: false })`.
|
|
29
|
+
|
|
30
|
+
### B) Transport adapters — tap a raw transport
|
|
31
|
+
When there's no RPC client, tap the transport bytes directly:
|
|
32
|
+
`instrumentDataChannel` / `instrumentPeerConnection` (WebRTC), `instrumentWebSocket`,
|
|
33
|
+
`instrumentHyperswarmStream` — each `(target, …, obs.sink)`, returning `{ restore() }`.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 2. Where events go (reporters / exporters)
|
|
38
|
+
|
|
39
|
+
`observe(options)` picks one, in this precedence:
|
|
40
|
+
|
|
41
|
+
| Option | Destination | Redaction default | Use when |
|
|
42
|
+
|---|---|---|---|
|
|
43
|
+
| `websocket: 'ws://host:port/ws'` | **local GUI over WebSocket** | **off** (localhost dev) | **local dev — every runtime.** Reliable (unlike DHT holepunch) |
|
|
44
|
+
| `exporter: <custom>` | your sink (Rozenite / OTLP) | on | custom pipeline |
|
|
45
|
+
| `stream: <duplex>` | a hub connection you provide | on | you already hold a hub socket |
|
|
46
|
+
| *(none)* | Bare/Pear → auto-dial the Hyperswarm hub; else buffer + `attach()` | on | multi-peer / field P2P |
|
|
47
|
+
|
|
48
|
+
| Capability | Default | Notes |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `allowInvoke: true` | **off** | Enables GUI replay. Requires a `websocket:` viewer. Dev builds only. |
|
|
51
|
+
| `canReplay(method, args)` | allow all | The only check on GUI-supplied replay arguments. |
|
|
52
|
+
|
|
53
|
+
### Replay is opt-in (off by default)
|
|
54
|
+
|
|
55
|
+
The GUI can re-run a call your app already made. That is an **inbound execution surface**, so it
|
|
56
|
+
is off unless you ask for it, in a dev build only:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
const obs = observe({
|
|
60
|
+
websocket: 'ws://127.0.0.1:9420/ws',
|
|
61
|
+
allowInvoke: true, // dev builds ONLY — never ship this
|
|
62
|
+
canReplay: (method, args) => method.startsWith('read.'), // your own gate, see below
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
It used to default on whenever no production signal was detectable — which is exactly what a
|
|
67
|
+
browser or Bare/Pear bundle looks like, so a shipped release could carry the surface. It now
|
|
68
|
+
requires the explicit flag.
|
|
69
|
+
|
|
70
|
+
What the boundary actually is, precisely:
|
|
71
|
+
|
|
72
|
+
- **The method is safe.** It is resolved from your app's own call log by `corrId` and never
|
|
73
|
+
crosses the wire, so a crafted frame cannot name a method your app did not already call.
|
|
74
|
+
- **The arguments are not.** The GUI's "Edit & replay" sends caller-supplied args, and the
|
|
75
|
+
library checks only that they are a JSON array. **`canReplay(method, args)` is the only
|
|
76
|
+
argument check in the system** — if a replayable method mutates state, implement it.
|
|
77
|
+
|
|
78
|
+
Redaction is the choke point before data leaves the device — hashes peer ids, strips URL
|
|
79
|
+
tokens, summarises bodies. It defaults **on** for export paths and **off** for the local
|
|
80
|
+
`websocket` viewer. Force either with `redact: true|false`.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 3. The GUI (ships in the package)
|
|
85
|
+
|
|
86
|
+
Run it on your dev machine — no extra install (dependency-free server):
|
|
87
|
+
```bash
|
|
88
|
+
npx hrpc-inspector gui # http://localhost:9420 (--port N, --demo)
|
|
89
|
+
```
|
|
90
|
+
Open **http://localhost:9420** — a request/response inspector: endpoint · status · ms · size,
|
|
91
|
+
click a row for request args + core response. Subscriptions render as **live streams**
|
|
92
|
+
(`streaming · N msgs`) with each response item.
|
|
93
|
+
|
|
94
|
+
**Connectivity (device → your Mac):**
|
|
95
|
+
|
|
96
|
+
| Runtime | `HOST` in `observe({ websocket })` | Setup |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| Android emulator/device | `127.0.0.1` | `adb reverse tcp:9420 tcp:9420` (like Metro's 8081) |
|
|
99
|
+
| iOS simulator | `127.0.0.1` | none |
|
|
100
|
+
| Real device (no adb) | your Mac's LAN IP | same Wi-Fi |
|
|
101
|
+
| Pear/Bare/Electron/Node/browser on the same machine | `127.0.0.1` | none |
|
|
102
|
+
|
|
103
|
+
### Device & app selectors (multiple sources)
|
|
104
|
+
|
|
105
|
+
When several apps/devices report to one GUI, pass a `source` so you can select between them —
|
|
106
|
+
by **physical device** or by **app id** (for multiple apps sharing one package):
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
observe({
|
|
110
|
+
websocket: 'ws://127.0.0.1:9420/ws',
|
|
111
|
+
source: { deviceId: options.deviceId, appId: APP_VARIANT, device: 'Pixel 7' },
|
|
112
|
+
})
|
|
113
|
+
```
|
|
114
|
+
The GUI shows source chips plus **all devices** / **all apps** dropdowns (filter by either).
|
|
115
|
+
The unique `id` derives from `deviceId:appId` (so same device + different app, or same app +
|
|
116
|
+
different device, stay distinct).
|
|
117
|
+
|
|
118
|
+
**Stable ids (reuse local storage) — design, browser-path untested in CI:**
|
|
119
|
+
- **Browser** — the package is *intended to* persist a stable id in `localStorage` (survives
|
|
120
|
+
reload, clears on delete-data). ⚠️ Not covered by the suite — there is no browser runtime in
|
|
121
|
+
CI, so this path is UNVERIFIED HERE; verify in a real browser.
|
|
122
|
+
- **React Native / Bare / Node** — the client passes `deviceId` from its own persistent store
|
|
123
|
+
(RN `AsyncStorage`, a Bare/Node file, or a platform id — many app cores already expose an `options.deviceId`).
|
|
124
|
+
Without it you get a **per-session id** that changes on restart (VERIFIED). The id derivation
|
|
125
|
+
itself (`deviceId`/`appId` → distinct ids) is VERIFIED in `verification/observe.test.mjs`.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 4. Export paths & symbols
|
|
130
|
+
|
|
131
|
+
| Path | Exports |
|
|
132
|
+
|---|---|
|
|
133
|
+
| `hrpc-inspector` | `observe`, `wrapClient`, `createWebSocketReporter`, `detectRuntime`, adapters, `CollectorSink`, `BatchFlusher`, `StreamFramer`/`encodeFrame`, `DEFAULT_TOPIC`, types |
|
|
134
|
+
| `hrpc-inspector/observe` | `observe`, `DEFAULT_TOPIC`, `ObserveOptions`, `ObserveHandle` |
|
|
135
|
+
| `hrpc-inspector/detect` | `detectRuntime`, `Runtime`, `RuntimeInfo` |
|
|
136
|
+
|
|
137
|
+
**`observe(options?) → handle`.** Options: `{ websocket?, exporter?, stream?, topic?, autoSwarm?, intervalMs?=200, redact?, redactor?, bodyAllowlist? }`.
|
|
138
|
+
Handle: `{ sink, report, wrapClient(client, opts?), flusher, redactor, runtime, mode, attach(stream), stop() }`.
|
|
139
|
+
|
|
140
|
+
**`wrapClient(client, report, opts?)`** — standalone form of `handle.wrapClient`.
|
|
141
|
+
**`createWebSocketReporter(url, opts?)`** — `{ export(batch), close() }`; queues while down, flushes on open, reconnects.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 5. Per-runtime recipes
|
|
146
|
+
|
|
147
|
+
**React Native** — the observability core runs in a `react-native-bare-kit` worklet OR you can
|
|
148
|
+
skip the worklet entirely and report over WebSocket from the RN JS thread. For an RPC-client
|
|
149
|
+
app (e.g. an app-core RPC client), wrap the client and report over WS:
|
|
150
|
+
```js
|
|
151
|
+
const obs = observe({ websocket: `ws://127.0.0.1:9420/ws` }) // Android: adb reverse first
|
|
152
|
+
const client = obs.wrapClient(rawRpcClient) // endpoints + responses + streams
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Pear / Bare app** — same call; either report over `websocket` (local GUI) or omit it to
|
|
156
|
+
auto-dial the Hyperswarm hub for multi-peer.
|
|
157
|
+
```js
|
|
158
|
+
const obs = observe({ websocket: 'ws://127.0.0.1:9420/ws' })
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Electron / Node** — runs in-process:
|
|
162
|
+
```js
|
|
163
|
+
const obs = observe({ websocket: 'ws://127.0.0.1:9420/ws' })
|
|
164
|
+
obs.wrapClient(serviceClient) // or instrument a raw socket via the adapters
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Browser** — `observe({ websocket })` uses the global `WebSocket`; wrap your service client
|
|
168
|
+
or instrument a `WebSocket`/`RTCDataChannel` via the adapters.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 6. Verified vs not
|
|
173
|
+
|
|
174
|
+
- **VERIFIED** (Node): runtime detection; observe() wiring; redaction-on-export + control;
|
|
175
|
+
`wrapClient` (endpoint/request/response, `this`/return preserved, subscription-stream
|
|
176
|
+
monitoring) + controls; `createWebSocketReporter` (queue → flush → send, close) + control.
|
|
177
|
+
- **UNVERIFIABLE HERE**: on-device RN (`react-native-bare-kit`), a live two-peer Hyperswarm
|
|
178
|
+
connection (one interface — C14/G4), static `tsc`. Verify those on real targets.
|
|
179
|
+
|
|
180
|
+
No silent postinstall — `npx hrpc-inspector init` is explicit and dry-runs by default.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// bare-observe CLI. One command, dry-run by default.
|
|
3
|
+
//
|
|
4
|
+
// npx hrpc-inspector init # detect project + PREVIEW the plan (writes nothing)
|
|
5
|
+
// npx hrpc-inspector init --write # apply the plan (never overwrites existing files)
|
|
6
|
+
// npx hrpc-inspector gui [--port N] # launch the inspector GUI (http://localhost:9420)
|
|
7
|
+
//
|
|
8
|
+
// Deliberately NOT a postinstall — see src/init.mjs for why.
|
|
9
|
+
|
|
10
|
+
import { readFileSync, existsSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { resolve } from 'node:path';
|
|
12
|
+
import { planInit } from '../src/init.mjs';
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const cmd = args[0];
|
|
16
|
+
const write = args.includes('--write');
|
|
17
|
+
const cwd = process.cwd();
|
|
18
|
+
|
|
19
|
+
function loadPkg() {
|
|
20
|
+
const p = resolve(cwd, 'package.json');
|
|
21
|
+
if (!existsSync(p)) return {};
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(readFileSync(p, 'utf8'));
|
|
24
|
+
} catch {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function runInit() {
|
|
30
|
+
const pkg = loadPkg();
|
|
31
|
+
const { runtime, actions, notes } = planInit({
|
|
32
|
+
pkg,
|
|
33
|
+
hasFile: (rel) => existsSync(resolve(cwd, rel)),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(`hrpc-inspector init — detected runtime: ${runtime}`);
|
|
37
|
+
console.log(write ? '(writing changes)\n' : '(dry run — pass --write to apply)\n');
|
|
38
|
+
|
|
39
|
+
for (const a of actions) {
|
|
40
|
+
if (write) {
|
|
41
|
+
const target = resolve(cwd, a.path);
|
|
42
|
+
if (existsSync(target)) {
|
|
43
|
+
console.log(` skip ${a.path} (exists, not overwriting)`);
|
|
44
|
+
} else {
|
|
45
|
+
writeFileSync(target, a.contents);
|
|
46
|
+
console.log(` create ${a.path} — ${a.reason}`);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
console.log(` would create ${a.path} — ${a.reason}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (actions.length === 0) console.log(' (no files needed for this runtime)');
|
|
53
|
+
|
|
54
|
+
if (notes.length) {
|
|
55
|
+
console.log('\nNext:');
|
|
56
|
+
for (const n of notes) console.log(n.includes('\n') || n.startsWith('//') ? `\n${n}` : ` - ${n}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (cmd === 'init') {
|
|
61
|
+
runInit();
|
|
62
|
+
} else if (cmd === 'gui') {
|
|
63
|
+
const i = args.indexOf('--port');
|
|
64
|
+
const port = i >= 0 ? Number(args[i + 1]) : Number(process.env.OBSERVE_PORT || 9420);
|
|
65
|
+
const hostIdx = args.indexOf('--host');
|
|
66
|
+
const { startGui } = await import('../gui/server.mjs');
|
|
67
|
+
startGui({
|
|
68
|
+
port,
|
|
69
|
+
demo: args.includes('--demo'),
|
|
70
|
+
...(hostIdx >= 0 ? { host: args[hostIdx + 1] } : {}),
|
|
71
|
+
// Escape hatch for a runtime whose WebSocket really does send `Origin: null`. Off by default:
|
|
72
|
+
// 'null' is a BROWSER value (a sandboxed or redirected page), so allowing it lets any page the
|
|
73
|
+
// developer visits read the capture and drive replay.
|
|
74
|
+
allowNullOrigin: args.includes('--allow-null-origin'),
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
console.log('Usage: hrpc-inspector <init [--write] | gui [--port N] [--host H] [--demo] [--allow-null-origin]>');
|
|
78
|
+
process.exit(cmd ? 1 : 0);
|
|
79
|
+
}
|
package/dist/detect.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/detect.ts
|
|
2
|
+
function detectRuntime(env = globalThis) {
|
|
3
|
+
const has = (v) => typeof v !== "undefined" && v !== null;
|
|
4
|
+
if (has(env.Pear)) return { runtime: "pear", isBareRuntime: true, isBridgeOnly: false };
|
|
5
|
+
if (has(env.Bare)) return { runtime: "bare", isBareRuntime: true, isBridgeOnly: false };
|
|
6
|
+
const rn = env.navigator?.product === "ReactNative" || has(env.__fbBatchedBridge) || has(env.HermesInternal);
|
|
7
|
+
if (rn) return { runtime: "react-native", isBareRuntime: false, isBridgeOnly: true };
|
|
8
|
+
if (has(env.process?.versions?.electron)) {
|
|
9
|
+
return { runtime: "electron", isBareRuntime: false, isBridgeOnly: false };
|
|
10
|
+
}
|
|
11
|
+
if (has(env.process?.versions?.node)) {
|
|
12
|
+
return { runtime: "node", isBareRuntime: false, isBridgeOnly: false };
|
|
13
|
+
}
|
|
14
|
+
if (has(env.window) && has(env.document)) {
|
|
15
|
+
return { runtime: "browser", isBareRuntime: false, isBridgeOnly: true };
|
|
16
|
+
}
|
|
17
|
+
return { runtime: "unknown", isBareRuntime: false, isBridgeOnly: false };
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
detectRuntime
|
|
21
|
+
};
|