@ait-co/devtools 0.1.107 → 0.1.109

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.
Files changed (54) hide show
  1. package/dist/bundle-KFs4t-wc.d.ts +96 -0
  2. package/dist/bundle-KFs4t-wc.d.ts.map +1 -0
  3. package/dist/cdp-connection-C0AP0tH2.d.ts +277 -0
  4. package/dist/cdp-connection-C0AP0tH2.d.ts.map +1 -0
  5. package/dist/in-app/auto.d.ts +17 -0
  6. package/dist/in-app/auto.d.ts.map +1 -1
  7. package/dist/in-app/auto.js +76 -0
  8. package/dist/in-app/auto.js.map +1 -1
  9. package/dist/in-app/index.d.ts +48 -1
  10. package/dist/in-app/index.d.ts.map +1 -1
  11. package/dist/in-app/index.js +60 -1
  12. package/dist/in-app/index.js.map +1 -1
  13. package/dist/mcp/cli.js +651 -9
  14. package/dist/mcp/cli.js.map +1 -1
  15. package/dist/mcp/server.d.ts.map +1 -1
  16. package/dist/mcp/server.js +59 -2
  17. package/dist/mcp/server.js.map +1 -1
  18. package/dist/panel/index.js +1 -1
  19. package/dist/pool-CuVMzWGB.d.ts +14577 -0
  20. package/dist/pool-CuVMzWGB.d.ts.map +1 -0
  21. package/dist/relay-worker-xxanNQGs.d.ts +74 -0
  22. package/dist/relay-worker-xxanNQGs.d.ts.map +1 -0
  23. package/dist/runtime-Wi5d6Ywz.d.ts +50 -0
  24. package/dist/runtime-Wi5d6Ywz.d.ts.map +1 -0
  25. package/dist/test-runner/bundle.d.ts +2 -0
  26. package/dist/test-runner/bundle.js +232 -0
  27. package/dist/test-runner/bundle.js.map +1 -0
  28. package/dist/test-runner/cli.d.ts +462 -0
  29. package/dist/test-runner/cli.d.ts.map +1 -0
  30. package/dist/test-runner/cli.js +516 -0
  31. package/dist/test-runner/cli.js.map +1 -0
  32. package/dist/test-runner/config.d.ts +80 -0
  33. package/dist/test-runner/config.d.ts.map +1 -0
  34. package/dist/test-runner/config.js +54 -0
  35. package/dist/test-runner/config.js.map +1 -0
  36. package/dist/test-runner/pool.d.ts +2 -0
  37. package/dist/test-runner/pool.js +136 -0
  38. package/dist/test-runner/pool.js.map +1 -0
  39. package/dist/test-runner/relay-worker.d.ts +2 -0
  40. package/dist/test-runner/relay-worker.js +96 -0
  41. package/dist/test-runner/relay-worker.js.map +1 -0
  42. package/dist/test-runner/rpc.d.ts +53 -0
  43. package/dist/test-runner/rpc.d.ts.map +1 -0
  44. package/dist/test-runner/rpc.js +78 -0
  45. package/dist/test-runner/rpc.js.map +1 -0
  46. package/dist/test-runner/task-graph.d.ts +38 -0
  47. package/dist/test-runner/task-graph.d.ts.map +1 -0
  48. package/dist/test-runner/task-graph.js +182 -0
  49. package/dist/test-runner/task-graph.js.map +1 -0
  50. package/dist/unplugin/index.d.cts +13 -32
  51. package/dist/unplugin/index.d.cts.map +1 -1
  52. package/dist/unplugin/index.d.ts +13 -32
  53. package/dist/unplugin/index.d.ts.map +1 -1
  54. package/package.json +13 -3
@@ -0,0 +1,96 @@
1
+ //#region src/test-runner/bundle.d.ts
2
+ /**
3
+ * esbuild-based bundler for user test files.
4
+ *
5
+ * Bundles a single test file into a self-contained IIFE string that can be
6
+ * injected into a WebView via `Runtime.evaluate`. The bundle includes the
7
+ * test runtime (`runtime.ts`), which provides `describe/it/test/expect` and
8
+ * the `runTestModule(factory)` entry point.
9
+ *
10
+ * ## How the wiring works
11
+ *
12
+ * The bundle exposes two exports on `globalThis.__testBundle`:
13
+ * - `runTestModule` — the runtime's entry function.
14
+ * - `__userFactory` — an async function whose body is the user's top-level
15
+ * test registration code (describe/it/test calls).
16
+ *
17
+ * The Node-side RPC (`rpc.ts`) calls:
18
+ * `globalThis.__testBundle.runTestModule(globalThis.__testBundle.__userFactory)`
19
+ *
20
+ * `runTestModule` then installs `describe/it/test/expect` as globals, invokes
21
+ * the factory (which registers all tests), runs them, and returns a `RunReport`.
22
+ *
23
+ * ## Why a factory wrapper is needed
24
+ *
25
+ * Naively adding the runtime to `entryPoints` and bundling the user file would
26
+ * fail for two reasons:
27
+ * 1. `describe/it/test/expect` from the runtime are module-local in the IIFE
28
+ * scope. The user's top-level `describe(...)` calls expect them as globals —
29
+ * they are not globals until `runTestModule` installs them.
30
+ * 2. Even with globals pre-installed, the user file runs at IIFE-evaluation
31
+ * time, before the RPC layer calls `runTestModule` to reset state and start
32
+ * the test clock.
33
+ *
34
+ * The factory approach solves both: the user's registration code is deferred
35
+ * into a function that `runTestModule` calls AFTER installing the globals.
36
+ *
37
+ * ## Factory extraction algorithm
38
+ *
39
+ * The `userFactoryPlugin` reads the user file and splits lines into:
40
+ * - **top-level**: `import …` and re-export lines — kept at module scope
41
+ * (the only valid position for static `import` in ESM).
42
+ * - **body**: all other statements — moved into the body of the exported
43
+ * `__userFactory` async function.
44
+ *
45
+ * esbuild processes the re-generated module, following each static import
46
+ * through the normal dependency graph (including the SDK-redirect plugin).
47
+ *
48
+ * ## SDK redirect
49
+ *
50
+ * Imports of `@apps-in-toss/web-framework` (and sub-paths) are intercepted via
51
+ * the `sdkRedirectPlugin` and replaced with a virtual `window.__sdk` proxy that
52
+ * `src/in-app/auto.ts` installs at runtime. This works for both 2.x and 3.x SDK.
53
+ *
54
+ * SECRET-HANDLING: the returned bundle code is caller-managed; never log it.
55
+ */
56
+ /** Options accepted by `bundleTestFile`. */
57
+ interface BundleOptions {
58
+ /**
59
+ * Additional esbuild `external` patterns. The SDK package
60
+ * (`@apps-in-toss/web-framework` and `@apps-in-toss/web-framework/*`) is
61
+ * always handled by the SDK redirect plugin — callers may add more patterns
62
+ * to be left as globals.
63
+ */
64
+ extraExternals?: string[];
65
+ /**
66
+ * Global name for the IIFE output object. Defaults to `__testBundle`.
67
+ * The runtime entry uses this to call `__testBundle.runTestModule(__userFactory)`.
68
+ */
69
+ globalName?: string;
70
+ }
71
+ /**
72
+ * The result of bundling a test file.
73
+ * `code` is a self-contained IIFE string ready for `Runtime.evaluate`.
74
+ */
75
+ interface BundleResult {
76
+ code: string;
77
+ warnings: string[];
78
+ }
79
+ /**
80
+ * Bundles `absPath` into a single IIFE string suitable for `Runtime.evaluate`.
81
+ *
82
+ * The IIFE installs `window.__testBundle` (or the custom `globalName`) with:
83
+ * - `runTestModule` — the runtime entry (from `runtime.ts`).
84
+ * - `__userFactory` — an async function wrapping the user's test registration
85
+ * code so it runs AFTER `runTestModule` installs the globals.
86
+ *
87
+ * Callers (rpc.ts) invoke:
88
+ * `globalThis.__testBundle.runTestModule(globalThis.__testBundle.__userFactory)`
89
+ *
90
+ * @param absPath - Absolute path to the user test file.
91
+ * @param opts - Optional bundling overrides.
92
+ */
93
+ declare function bundleTestFile(absPath: string, opts?: BundleOptions): Promise<BundleResult>;
94
+ //#endregion
95
+ export { BundleResult as n, bundleTestFile as r, BundleOptions as t };
96
+ //# sourceMappingURL=bundle-KFs4t-wc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle-KFs4t-wc.d.ts","names":[],"sources":["../src/test-runner/bundle.ts"],"mappings":";;AAqEA;;;;;AAmBA;;;;;AA2LA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA9MiB,aAAA;;;;;;;EAOf,cAAA;;;;;EAKA,UAAA;AAAA;;;;;UAOe,YAAA;EACf,IAAA;EACA,QAAA;AAAA;;;;;;;;;;;;;;;iBAyLoB,cAAA,CAAe,OAAA,UAAiB,IAAA,GAAO,aAAA,GAAgB,OAAA,CAAQ,YAAA"}
@@ -0,0 +1,277 @@
1
+ //#region src/mcp/cdp-connection.d.ts
2
+ /**
3
+ * Injectable CDP connection abstraction for the debug-mode MCP server.
4
+ *
5
+ * The Phase 1 tool layer (`list_console_messages`, `list_network_requests`,
6
+ * `list_pages`) reads from CDP events captured off a Chii relay connection.
7
+ * To keep that tool layer CI-verifiable without a phone roundtrip, the actual
8
+ * relay websocket sits behind this interface. Production wires
9
+ * `ChiiCdpConnection` (see `chii-connection.ts`); tests inject a fake that
10
+ * emits canned `Runtime.consoleAPICalled` / `Network.*` events.
11
+ *
12
+ * Phase 2 adds CDP *commands* (request→response): `DOM.getDocument`,
13
+ * `DOMSnapshot.captureSnapshot`, `Page.captureScreenshot`. Unlike Phase 1's
14
+ * event streams these need a `send(method, params)` round-trip, so the
15
+ * connection grows a typed `send`. The fake returns canned command results.
16
+ *
17
+ * Phase 2 extension: `Runtime.evaluate` (read-only probe) added for the
18
+ * `measure_safe_area` tool — executes a JS snippet on the attached page and
19
+ * returns the result as a `RemoteObject`. The fake returns canned results for
20
+ * unit tests without a phone roundtrip.
21
+ *
22
+ * Only the slice of the Chrome DevTools Protocol the tools need is typed here.
23
+ */
24
+ /** A target (page) the Chii relay currently sees attached. */
25
+ interface CdpTarget {
26
+ /** Chii's internal target id (session UUID). */
27
+ id: string;
28
+ /** Page title reported by the in-app target. */
29
+ title: string;
30
+ /** Page URL reported by the in-app target. */
31
+ url: string;
32
+ }
33
+ /** `Runtime.RemoteObject` subset we surface for console args. */
34
+ interface CdpRemoteObject {
35
+ type: string;
36
+ subtype?: string;
37
+ value?: unknown;
38
+ description?: string;
39
+ className?: string;
40
+ }
41
+ /** Payload of a `Runtime.consoleAPICalled` event. */
42
+ interface ConsoleApiCalledEvent {
43
+ /** log | warning | error | info | debug | … */
44
+ type: string;
45
+ args: CdpRemoteObject[];
46
+ /** Milliseconds since epoch (CDP `Runtime.Timestamp`). */
47
+ timestamp: number;
48
+ executionContextId?: number;
49
+ stackTrace?: {
50
+ callFrames: Array<{
51
+ functionName: string;
52
+ url: string;
53
+ lineNumber: number;
54
+ columnNumber: number;
55
+ }>;
56
+ };
57
+ }
58
+ /** Payload of a `Network.requestWillBeSent` event (subset). */
59
+ interface NetworkRequestWillBeSentEvent {
60
+ requestId: string;
61
+ request: {
62
+ url: string;
63
+ method: string;
64
+ headers?: Record<string, string>;
65
+ };
66
+ /** CDP `Network.MonotonicTime` (seconds). */
67
+ timestamp: number;
68
+ /** Wall-clock seconds since epoch, when available. */
69
+ wallTime?: number;
70
+ type?: string;
71
+ }
72
+ /** Payload of a `Network.responseReceived` event (subset). */
73
+ interface NetworkResponseReceivedEvent {
74
+ requestId: string;
75
+ response: {
76
+ url: string;
77
+ status: number;
78
+ statusText: string;
79
+ mimeType?: string;
80
+ };
81
+ timestamp: number;
82
+ type?: string;
83
+ }
84
+ /**
85
+ * A single call frame in a `Runtime.exceptionThrown` stack trace.
86
+ * Subset of the CDP `Runtime.CallFrame` shape.
87
+ */
88
+ interface CdpCallFrame {
89
+ functionName: string;
90
+ scriptId?: string;
91
+ url: string;
92
+ lineNumber: number;
93
+ columnNumber: number;
94
+ }
95
+ /** Payload of a `Runtime.exceptionThrown` event. */
96
+ interface RuntimeExceptionThrownEvent {
97
+ /** Milliseconds since epoch (CDP `Runtime.Timestamp`). */
98
+ timestamp: number;
99
+ exceptionDetails: {
100
+ exceptionId: number;
101
+ text: string;
102
+ lineNumber: number;
103
+ columnNumber: number;
104
+ scriptId?: string;
105
+ url?: string;
106
+ stackTrace?: {
107
+ callFrames: CdpCallFrame[];
108
+ }; /** The thrown value as a CDP `RemoteObject`. */
109
+ exception?: CdpRemoteObject;
110
+ };
111
+ }
112
+ /** Map of the CDP event names Phase 1 consumes to their payload shapes. */
113
+ interface CdpEventMap {
114
+ 'Runtime.consoleAPICalled': ConsoleApiCalledEvent;
115
+ 'Network.requestWillBeSent': NetworkRequestWillBeSentEvent;
116
+ 'Network.responseReceived': NetworkResponseReceivedEvent;
117
+ 'Runtime.exceptionThrown': RuntimeExceptionThrownEvent;
118
+ }
119
+ type CdpEventName = keyof CdpEventMap;
120
+ /** A `DOM.Node` subset (recursive) returned by `DOM.getDocument`. */
121
+ interface CdpDomNode {
122
+ nodeId: number;
123
+ /** CDP node type (1 = element, 3 = text, 9 = document, …). */
124
+ nodeType: number;
125
+ nodeName: string;
126
+ /** Tag/local name for elements. */
127
+ localName?: string;
128
+ nodeValue?: string;
129
+ /** Flattened attribute list: `[name, value, name, value, …]`. */
130
+ attributes?: string[];
131
+ childNodeCount?: number;
132
+ children?: CdpDomNode[];
133
+ documentURL?: string;
134
+ baseURL?: string;
135
+ }
136
+ /** Result of `DOM.getDocument`. */
137
+ interface DomGetDocumentResult {
138
+ root: CdpDomNode;
139
+ }
140
+ /** Result of `DOMSnapshot.captureSnapshot` (subset we surface). */
141
+ interface DomSnapshotResult {
142
+ documents: unknown[];
143
+ strings: string[];
144
+ }
145
+ /** Result of `Page.captureScreenshot`. */
146
+ interface PageCaptureScreenshotResult {
147
+ /** Base64-encoded image bytes (PNG by default). */
148
+ data: string;
149
+ }
150
+ /**
151
+ * Params for `Runtime.evaluate`.
152
+ * Covers the subset used by the `measure_safe_area` read-only probe.
153
+ */
154
+ interface RuntimeEvaluateParams {
155
+ /** JavaScript expression to evaluate in the page context. */
156
+ expression: string;
157
+ /** Return the result as a plain JSON value (vs. a handle). Default false. */
158
+ returnByValue?: boolean;
159
+ /** Await a returned Promise before resolving. Default false. */
160
+ awaitPromise?: boolean;
161
+ }
162
+ /** Result of `Runtime.evaluate`. */
163
+ interface RuntimeEvaluateResult {
164
+ /** The evaluation result. */
165
+ result: CdpRemoteObject;
166
+ /** Present when evaluation threw an uncaught exception. */
167
+ exceptionDetails?: {
168
+ text: string;
169
+ exception?: CdpRemoteObject;
170
+ };
171
+ }
172
+ /**
173
+ * Map of CDP command method → params/result shape. Keeps `send` typed so a
174
+ * `DOM.getDocument` call resolves to a `DomGetDocumentResult`, etc.
175
+ */
176
+ interface CdpCommandMap {
177
+ 'DOM.getDocument': {
178
+ params: {
179
+ depth?: number;
180
+ pierce?: boolean;
181
+ };
182
+ result: DomGetDocumentResult;
183
+ };
184
+ 'DOMSnapshot.captureSnapshot': {
185
+ params: {
186
+ computedStyles?: string[];
187
+ };
188
+ result: DomSnapshotResult;
189
+ };
190
+ 'Page.captureScreenshot': {
191
+ params: {
192
+ format?: 'png' | 'jpeg' | 'webp';
193
+ quality?: number;
194
+ };
195
+ result: PageCaptureScreenshotResult;
196
+ };
197
+ 'Runtime.evaluate': {
198
+ params: RuntimeEvaluateParams;
199
+ result: RuntimeEvaluateResult;
200
+ };
201
+ }
202
+ type CdpCommandName = keyof CdpCommandMap;
203
+ /**
204
+ * The connection the tool layer reads from. The production implementation
205
+ * wraps the Chii relay's CDP websocket; tests inject a fake.
206
+ *
207
+ * Implementations are expected to maintain an internal ring buffer of recent
208
+ * events (so a tool call returns recent history rather than only live events).
209
+ */
210
+ interface CdpConnection {
211
+ /**
212
+ * Authoritative kind of this connection's transport (issue #348).
213
+ *
214
+ * - `'relay'` — backed by the Chii relay + cloudflared tunnel (a real-device
215
+ * WebView, env 3/4). `ChiiCdpConnection`.
216
+ * - `'local'` — backed by a direct CDP websocket to a local Chromium (env 1).
217
+ * `LocalCdpConnection`.
218
+ *
219
+ * This replaces the old `getEnvironment()` URL-pattern sniffing: the
220
+ * `mock` vs `relay` split is now a free, authoritative property of the
221
+ * connection itself, known before any target attaches. The `relay-dev` vs
222
+ * `relay-live` distinction is orthogonal (operator-supplied `liveIntent`,
223
+ * see `environment.ts`) because dog-food and production relays are
224
+ * byte-identical on the wire.
225
+ */
226
+ readonly kind: 'relay' | 'local';
227
+ /**
228
+ * Enable the CDP domains Phase 1 needs (`Runtime.enable`, `Network.enable`).
229
+ * Idempotent. Resolves once the relay has acknowledged (or immediately for a
230
+ * fake connection).
231
+ */
232
+ enableDomains(): Promise<void>;
233
+ /** Targets (pages) the relay currently sees attached. */
234
+ listTargets(): CdpTarget[];
235
+ /** Recent buffered events for a domain, oldest-first. */
236
+ getBufferedEvents<E extends CdpEventName>(event: E): ReadonlyArray<CdpEventMap[E]>;
237
+ /** Subscribe to live events. Returns an unsubscribe function. */
238
+ on<E extends CdpEventName>(event: E, listener: (payload: CdpEventMap[E]) => void): () => void;
239
+ /**
240
+ * Issue a CDP command (request → response). Phase 2's DOM/snapshot/screenshot
241
+ * tools use this; resolves with the typed result or rejects on a CDP error.
242
+ * Implementations must have called {@link enableDomains} first.
243
+ */
244
+ send<M extends CdpCommandName>(method: M, params?: CdpCommandMap[M]['params']): Promise<CdpCommandMap[M]['result']>;
245
+ /**
246
+ * Close the underlying transport and reject any in-flight commands.
247
+ * Optional so that minimal test fakes that don't need teardown remain
248
+ * compatible without change. Both `ChiiCdpConnection` and
249
+ * `LocalCdpConnection` already implement this.
250
+ */
251
+ close?(): void;
252
+ /**
253
+ * Refresh the attached-target list from the relay and return the result.
254
+ * Emits an internal `'target:attached'` event when a new target appears so
255
+ * that {@link waitForFirstTarget} can race against the polling round.
256
+ *
257
+ * Optional — only `ChiiCdpConnection` (relay mode) supports this; local
258
+ * connections and test fakes may omit it. Callers should guard with
259
+ * `connection.refreshTargets?.()`.
260
+ */
261
+ refreshTargets?(): Promise<CdpTarget[]>;
262
+ /**
263
+ * Waits until at least one target satisfying `filterFn` is attached, then
264
+ * resolves with the full target list at that moment.
265
+ *
266
+ * Optional — only `ChiiCdpConnection` provides the event-driven
267
+ * implementation. When absent, callers fall back to a generic polling loop.
268
+ *
269
+ * @param filterFn - Predicate the resolved targets must satisfy.
270
+ * @param timeoutMs - Reject after this many ms (default 90 000).
271
+ * @param pollIntervalMs - Fallback poll interval (default 500 ms).
272
+ */
273
+ waitForFirstTarget?(filterFn: (targets: CdpTarget[]) => boolean, timeoutMs?: number, pollIntervalMs?: number): Promise<CdpTarget[]>;
274
+ }
275
+ //#endregion
276
+ export { CdpConnection as t };
277
+ //# sourceMappingURL=cdp-connection-C0AP0tH2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdp-connection-C0AP0tH2.d.ts","names":[],"sources":["../src/mcp/cdp-connection.ts"],"mappings":";;AAwBA;;;;;;;;;AAUA;;;;;;;;;;;AASA;;UAnBiB,SAAA;EA2BI;EAzBnB,EAAA;EAoBA;EAlBA,KAAA;EAoBA;EAlBA,GAAA;AAAA;;UAIe,eAAA;EACf,IAAA;EACA,OAAA;EACA,KAAA;EACA,WAAA;EACA,SAAA;AAAA;AAsBF;AAAA,UAlBiB,qBAAA;;EAEf,IAAA;EACA,IAAA,EAAM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.
13
13
  *
14
+ * DEPRECATED for builds that require debug code to be PHYSICALLY ABSENT from
15
+ * the release bundle. This entry is a RUNTIME self-gate, not a build-time one:
16
+ * the imported chunk (Chii target.js injection, the SDK bridge, and the eruda
17
+ * console it pulls in via `maybeAttach()`) stays in the production bundle as a
18
+ * dormant chunk and is only kept asleep at runtime. If your threat model needs
19
+ * "zero bytes of debug surface in release" (no dormant chunk to extract or
20
+ * re-enable), do NOT use this entry. Instead guard the call site yourself:
21
+ *
22
+ * if (__DEBUG_BUILD__) {
23
+ * import('@ait-co/devtools/in-app').then((m) => m.maybeAttach());
24
+ * }
25
+ *
26
+ * with `define: { __DEBUG_BUILD__: 'false' }` in your release build — the
27
+ * bundler then dead-code-eliminates the whole `@ait-co/devtools/in-app` graph
28
+ * (verified on Vite 8/rolldown). This entry stays for the convenience case
29
+ * where a dormant chunk gated at runtime is acceptable.
30
+ *
14
31
  * When the gate passes it:
15
32
  * 1. Calls `maybeAttach()` — runs the full Layer B/C gate (host allowlist,
16
33
  * opt-in params, relay URL, TOTP) and injects the Chii `target.js` script.
@@ -1 +1 @@
1
- {"version":3,"file":"auto.d.ts","names":[],"sources":["../../src/in-app/auto.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4HA;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAhGQ,MAAA;EAAA,UACI,MAAA;;;;;;;;;;IAUR,KAAA,GAAQ,MAAA;;;;;;;;;IAUR,SAAA,IACE,IAAA,aACG,IAAA,gBACA,OAAA;MAAU,EAAA;MAAa,KAAA;MAAiB,KAAA;IAAA;EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;iBAsCjC,eAAA,CAAA;;;;;;;;;;;;;;iBAkCA,cAAA,CACd,KAAA,YACA,SAAA"}
1
+ {"version":3,"file":"auto.d.ts","names":[],"sources":["../../src/in-app/auto.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6IA;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAhGQ,MAAA;EAAA,UACI,MAAA;;;;;;;;;;IAUR,KAAA,GAAQ,MAAA;;;;;;;;;IAUR,SAAA,IACE,IAAA,aACG,IAAA,gBACA,OAAA;MAAU,EAAA;MAAa,KAAA;MAAiB,KAAA;IAAA;EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;iBAsCjC,eAAA,CAAA;;;;;;;;;;;;;;iBAkCA,cAAA,CACd,KAAA,YACA,SAAA"}
@@ -40,6 +40,64 @@ const RELAY_AUTH_REJECT_CLOSE_CODE = 4401;
40
40
  */
41
41
  const RELAY_AUTH_REJECT_REASON = "totp-rejected";
42
42
  //#endregion
43
+ //#region src/in-app/eruda-overlay.ts
44
+ /**
45
+ * In-app eruda console overlay for the debug attach flow.
46
+ *
47
+ * Spec: docs/superpowers/specs/2026-05-18-in-app-debug-mcp.md
48
+ *
49
+ * This module mounts the eruda in-page console (https://github.com/liriliri/eruda)
50
+ * on the phone screen when a debug session attaches. It is the mobile-only
51
+ * counterpart to the Chii `target.js` injection in {@link attach.ts}: Chii is a
52
+ * REMOTE CDP transport (phone → relay → PC DevTools frontend), whereas eruda is
53
+ * a LOCAL in-page view — a floating button + console/network/DOM/storage panels
54
+ * rendered directly on the phone, with no relay or second device. The two are
55
+ * orthogonal and coexist (eruda opens no WebSocket, mounts into its own
56
+ * `#eruda` shadow host — it cannot collide with the relay WS or the Chii DOM).
57
+ *
58
+ * Build-time absence (the security contract): this module lives in the
59
+ * `@ait-co/devtools/in-app` graph. A consumer wraps its
60
+ * `import('@ait-co/devtools/in-app')` call site in `if (__DEBUG_BUILD__) { … }`;
61
+ * a release build folds that constant to `false` and dead-code-eliminates the
62
+ * whole module — so eruda (and its dynamic `import('eruda')` chunk) is simply
63
+ * absent from release bundles, exactly like the Chii target.js injection. The
64
+ * `import('eruda')` here is a dynamic import precisely so the bundler emits it
65
+ * as a separate chunk that the dead branch never pulls in.
66
+ *
67
+ * Runtime gate: `mountEruda()` is called only from `maybeAttach()` AFTER the
68
+ * full Layer B/C gate has passed (`gateResult.attach === true`) — host
69
+ * allowlist, `debug=1`, relay URL, and TOTP. So eruda inherits the same
70
+ * four-layer defence as the Chii injection, byte-for-byte, with no eruda-
71
+ * specific gate of its own.
72
+ *
73
+ * SECRET-HANDLING: this module reads no secret, TOTP code, relay URL, or host
74
+ * value, and logs none. eruda observes only the page it is mounted on.
75
+ */
76
+ /** Module-level guard against double mount across repeated `maybeAttach` calls. */
77
+ let erudaMounted = false;
78
+ /**
79
+ * Mounts the eruda in-page console once.
80
+ *
81
+ * Idempotent: repeated calls after a successful mount are no-ops, mirroring the
82
+ * `attached` guard in {@link attach.ts}. Fail-silent: if the dynamic import or
83
+ * `eruda.init()` throws (eruda absent, or a runtime that rejects it), the Chii
84
+ * debug session is unaffected — eruda is an additive convenience, not a
85
+ * dependency of the relay path.
86
+ *
87
+ * `eruda.init()` mounts eruda's own floating entry button on the phone screen;
88
+ * tapping it opens the console. We do not add a separate button.
89
+ */
90
+ async function mountEruda() {
91
+ if (erudaMounted || typeof document === "undefined") return;
92
+ erudaMounted = true;
93
+ try {
94
+ (await import("eruda")).default.init();
95
+ } catch (err) {
96
+ erudaMounted = false;
97
+ console.debug("[@ait-co/devtools] eruda console mount skipped:", err);
98
+ }
99
+ }
100
+ //#endregion
43
101
  //#region src/in-app/gate.ts
44
102
  /**
45
103
  * The host suffix the Toss app uses to serve dogfood / private mini-apps.
@@ -499,6 +557,7 @@ function maybeAttach(gateResult = checkDebugGate()) {
499
557
  };
500
558
  (document.head ?? document.documentElement).appendChild(script);
501
559
  attached = true;
560
+ mountEruda();
502
561
  if (typeof window !== "undefined" && new URLSearchParams(window.location.search).get("noKeepAwake") === "1") return;
503
562
  setScreenAwakeMode({ enabled: true }).then(() => {
504
563
  window.addEventListener("beforeunload", () => {
@@ -522,6 +581,23 @@ function maybeAttach(gateResult = checkDebugGate()) {
522
581
  * imported chunk stays dormant and `window.__sdk` / `window.__sdkCall` are
523
582
  * never installed on a normal production load.
524
583
  *
584
+ * DEPRECATED for builds that require debug code to be PHYSICALLY ABSENT from
585
+ * the release bundle. This entry is a RUNTIME self-gate, not a build-time one:
586
+ * the imported chunk (Chii target.js injection, the SDK bridge, and the eruda
587
+ * console it pulls in via `maybeAttach()`) stays in the production bundle as a
588
+ * dormant chunk and is only kept asleep at runtime. If your threat model needs
589
+ * "zero bytes of debug surface in release" (no dormant chunk to extract or
590
+ * re-enable), do NOT use this entry. Instead guard the call site yourself:
591
+ *
592
+ * if (__DEBUG_BUILD__) {
593
+ * import('@ait-co/devtools/in-app').then((m) => m.maybeAttach());
594
+ * }
595
+ *
596
+ * with `define: { __DEBUG_BUILD__: 'false' }` in your release build — the
597
+ * bundler then dead-code-eliminates the whole `@ait-co/devtools/in-app` graph
598
+ * (verified on Vite 8/rolldown). This entry stays for the convenience case
599
+ * where a dormant chunk gated at runtime is acceptable.
600
+ *
525
601
  * When the gate passes it:
526
602
  * 1. Calls `maybeAttach()` — runs the full Layer B/C gate (host allowlist,
527
603
  * opt-in params, relay URL, TOTP) and injects the Chii `target.js` script.