@developerz.ai/ui-debugger-mcp 1.9.0 → 1.11.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/README.md +63 -47
- package/dist/adapters/android/abortable.d.ts +6 -0
- package/dist/adapters/android/abortable.js +22 -0
- package/dist/adapters/android/abortable.js.map +1 -0
- package/dist/adapters/android/adb.d.ts +19 -7
- package/dist/adapters/android/adb.js +50 -13
- package/dist/adapters/android/adb.js.map +1 -1
- package/dist/adapters/android/android-adapter.d.ts +20 -12
- package/dist/adapters/android/android-adapter.js +113 -165
- package/dist/adapters/android/android-adapter.js.map +1 -1
- package/dist/adapters/android/commands.d.ts +10 -0
- package/dist/adapters/android/commands.js +22 -0
- package/dist/adapters/android/commands.js.map +1 -1
- package/dist/adapters/android/emulator.d.ts +41 -0
- package/dist/adapters/android/emulator.js +115 -0
- package/dist/adapters/android/emulator.js.map +1 -0
- package/dist/adapters/android/logcat.d.ts +87 -0
- package/dist/adapters/android/logcat.js +352 -0
- package/dist/adapters/android/logcat.js.map +1 -0
- package/dist/adapters/android/ports.js.map +1 -1
- package/dist/adapters/android/sdk.d.ts +65 -0
- package/dist/adapters/android/sdk.js +107 -0
- package/dist/adapters/android/sdk.js.map +1 -0
- package/dist/adapters/android/uiautomator.d.ts +23 -7
- package/dist/adapters/android/uiautomator.js +31 -7
- package/dist/adapters/android/uiautomator.js.map +1 -1
- package/dist/adapters/availability.d.ts +39 -0
- package/dist/adapters/availability.js +62 -0
- package/dist/adapters/availability.js.map +1 -0
- package/dist/adapters/browser/browser-adapter.d.ts +11 -22
- package/dist/adapters/browser/browser-adapter.js +90 -71
- package/dist/adapters/browser/browser-adapter.js.map +1 -1
- package/dist/adapters/browser/cdp.d.ts +22 -17
- package/dist/adapters/browser/cdp.js +118 -72
- package/dist/adapters/browser/cdp.js.map +1 -1
- package/dist/adapters/browser/exchange-read.d.ts +39 -0
- package/dist/adapters/browser/exchange-read.js +102 -0
- package/dist/adapters/browser/exchange-read.js.map +1 -0
- package/dist/adapters/browser/extractor.js +9 -2
- package/dist/adapters/browser/extractor.js.map +1 -1
- package/dist/adapters/browser/filters.d.ts +1 -1
- package/dist/adapters/browser/filters.js.map +1 -1
- package/dist/adapters/browser/geometry.js.map +1 -1
- package/dist/adapters/browser/launch.d.ts +14 -5
- package/dist/adapters/browser/launch.js +14 -5
- package/dist/adapters/browser/launch.js.map +1 -1
- package/dist/adapters/browser/lifecycle.d.ts +91 -0
- package/dist/adapters/browser/lifecycle.js +141 -0
- package/dist/adapters/browser/lifecycle.js.map +1 -0
- package/dist/adapters/browser/locate.d.ts +18 -2
- package/dist/adapters/browser/locate.js +48 -3
- package/dist/adapters/browser/locate.js.map +1 -1
- package/dist/adapters/browser/log-filters.d.ts +2 -2
- package/dist/adapters/browser/log-filters.js +15 -4
- package/dist/adapters/browser/log-filters.js.map +1 -1
- package/dist/adapters/browser/log-format.d.ts +23 -20
- package/dist/adapters/browser/log-format.js +133 -56
- package/dist/adapters/browser/log-format.js.map +1 -1
- package/dist/adapters/browser/tab-context.d.ts +30 -0
- package/dist/adapters/browser/tab-context.js +41 -0
- package/dist/adapters/browser/tab-context.js.map +1 -0
- package/dist/adapters/contract.d.ts +113 -10
- package/dist/adapters/contract.js +7 -2
- package/dist/adapters/contract.js.map +1 -1
- package/dist/adapters/desktop/atspi-busctl.d.ts +26 -0
- package/dist/adapters/desktop/atspi-busctl.js +332 -0
- package/dist/adapters/desktop/atspi-busctl.js.map +1 -0
- package/dist/adapters/desktop/atspi-parse.d.ts +39 -0
- package/dist/adapters/desktop/atspi-parse.js +155 -0
- package/dist/adapters/desktop/atspi-parse.js.map +1 -0
- package/dist/adapters/desktop/atspi.d.ts +81 -50
- package/dist/adapters/desktop/atspi.js +64 -285
- package/dist/adapters/desktop/atspi.js.map +1 -1
- package/dist/adapters/desktop/capture.d.ts +11 -20
- package/dist/adapters/desktop/capture.js +68 -37
- package/dist/adapters/desktop/capture.js.map +1 -1
- package/dist/adapters/desktop/desktop-adapter.d.ts +22 -2
- package/dist/adapters/desktop/desktop-adapter.js +202 -86
- package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
- package/dist/adapters/desktop/input.d.ts +19 -5
- package/dist/adapters/desktop/input.js +29 -13
- package/dist/adapters/desktop/input.js.map +1 -1
- package/dist/adapters/desktop/managed-app.d.ts +43 -0
- package/dist/adapters/desktop/managed-app.js +114 -0
- package/dist/adapters/desktop/managed-app.js.map +1 -0
- package/dist/adapters/desktop/proc.d.ts +34 -4
- package/dist/adapters/desktop/proc.js +37 -6
- package/dist/adapters/desktop/proc.js.map +1 -1
- package/dist/adapters/desktop/wait-poll.d.ts +17 -0
- package/dist/adapters/desktop/wait-poll.js +38 -0
- package/dist/adapters/desktop/wait-poll.js.map +1 -0
- package/dist/adapters/factory.d.ts +13 -6
- package/dist/adapters/factory.js +30 -4
- package/dist/adapters/factory.js.map +1 -1
- package/dist/adapters/log-format.d.ts +38 -0
- package/dist/adapters/log-format.js +47 -0
- package/dist/adapters/log-format.js.map +1 -0
- package/dist/agent/belt/act.d.ts +426 -23
- package/dist/agent/belt/act.js +44 -64
- package/dist/agent/belt/act.js.map +1 -1
- package/dist/agent/belt/look.d.ts +479 -16
- package/dist/agent/belt/look.js +94 -16
- package/dist/agent/belt/look.js.map +1 -1
- package/dist/agent/belt/observe.d.ts +652 -65
- package/dist/agent/belt/observe.js +119 -231
- package/dist/agent/belt/observe.js.map +1 -1
- package/dist/agent/belt/redact-output.d.ts +20 -0
- package/dist/agent/belt/redact-output.js +70 -0
- package/dist/agent/belt/redact-output.js.map +1 -0
- package/dist/agent/belt/report.d.ts +754 -48
- package/dist/agent/belt/report.js +121 -38
- package/dist/agent/belt/report.js.map +1 -1
- package/dist/agent/belt/same-origin.d.ts +21 -0
- package/dist/agent/belt/same-origin.js +38 -0
- package/dist/agent/belt/same-origin.js.map +1 -0
- package/dist/agent/belt/target-refs.d.ts +39 -0
- package/dist/agent/belt/target-refs.js +60 -0
- package/dist/agent/belt/target-refs.js.map +1 -0
- package/dist/agent/belt/trail.d.ts +44 -16
- package/dist/agent/belt/trail.js +46 -11
- package/dist/agent/belt/trail.js.map +1 -1
- package/dist/agent/belt/tree-targets.d.ts +79 -0
- package/dist/agent/belt/tree-targets.js +242 -0
- package/dist/agent/belt/tree-targets.js.map +1 -0
- package/dist/agent/capabilities.js.map +1 -1
- package/dist/agent/fallback.d.ts +33 -0
- package/dist/agent/fallback.js +84 -0
- package/dist/agent/fallback.js.map +1 -0
- package/dist/agent/loop-frames.d.ts +26 -0
- package/dist/agent/loop-frames.js +106 -0
- package/dist/agent/loop-frames.js.map +1 -0
- package/dist/agent/loop.d.ts +56 -65
- package/dist/agent/loop.js +122 -189
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/models.d.ts +10 -6
- package/dist/agent/models.js +15 -9
- package/dist/agent/models.js.map +1 -1
- package/dist/agent/prompts/compose.d.ts +1 -1
- package/dist/agent/prompts/debug-agent.js +48 -10
- package/dist/agent/prompts/debug-agent.js.map +1 -1
- package/dist/agent/prompts/web-addendum.d.ts +2 -2
- package/dist/agent/prompts/web-addendum.js +26 -25
- package/dist/agent/prompts/web-addendum.js.map +1 -1
- package/dist/agent/provider.d.ts +41 -1
- package/dist/agent/provider.js +59 -5
- package/dist/agent/provider.js.map +1 -1
- package/dist/boot.d.ts +64 -0
- package/dist/boot.js +147 -0
- package/dist/boot.js.map +1 -0
- package/dist/cli/chromium-libs.d.ts +267 -0
- package/dist/cli/chromium-libs.js +546 -0
- package/dist/cli/chromium-libs.js.map +1 -0
- package/dist/cli/control.js +79 -12
- package/dist/cli/control.js.map +1 -1
- package/dist/cli/init.d.ts +52 -3
- package/dist/cli/init.js +62 -10
- package/dist/cli/init.js.map +1 -1
- package/dist/config/load.d.ts +25 -8
- package/dist/config/load.js +50 -13
- package/dist/config/load.js.map +1 -1
- package/dist/config/schema.d.ts +18 -6
- package/dist/config/schema.js +34 -17
- package/dist/config/schema.js.map +1 -1
- package/dist/errors.d.ts +30 -15
- package/dist/errors.js +49 -30
- package/dist/errors.js.map +1 -1
- package/dist/findings/schema.d.ts +44 -6
- package/dist/findings/schema.js +39 -3
- package/dist/findings/schema.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +4 -82
- package/dist/main.js.map +1 -1
- package/dist/mcp/server.js +10 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/describe.d.ts +5 -4
- package/dist/mcp/tools/describe.js +14 -10
- package/dist/mcp/tools/describe.js.map +1 -1
- package/dist/mcp/tools/end-session.d.ts +3 -1
- package/dist/mcp/tools/end-session.js +8 -3
- package/dist/mcp/tools/end-session.js.map +1 -1
- package/dist/mcp/tools/output.d.ts +12 -4
- package/dist/mcp/tools/output.js +15 -2
- package/dist/mcp/tools/output.js.map +1 -1
- package/dist/mcp/tools/result.d.ts +10 -1
- package/dist/mcp/tools/result.js +12 -7
- package/dist/mcp/tools/result.js.map +1 -1
- package/dist/mcp/tools/start-debug.js +7 -5
- package/dist/mcp/tools/start-debug.js.map +1 -1
- package/dist/redact.d.ts +44 -0
- package/dist/redact.js +166 -0
- package/dist/redact.js.map +1 -0
- package/dist/services/auth-persona.d.ts +19 -0
- package/dist/services/auth-persona.js +32 -0
- package/dist/services/auth-persona.js.map +1 -0
- package/dist/services/catalog.d.ts +28 -0
- package/dist/services/catalog.js +65 -0
- package/dist/services/catalog.js.map +1 -0
- package/dist/services/debug-api.d.ts +179 -0
- package/dist/services/debug-api.js +9 -0
- package/dist/services/debug-api.js.map +1 -0
- package/dist/services/debug-service.d.ts +26 -174
- package/dist/services/debug-service.js +159 -227
- package/dist/services/debug-service.js.map +1 -1
- package/dist/services/foreign-findings.d.ts +22 -0
- package/dist/services/foreign-findings.js +38 -0
- package/dist/services/foreign-findings.js.map +1 -0
- package/dist/services/login-failure.d.ts +10 -0
- package/dist/services/login-failure.js +24 -0
- package/dist/services/login-failure.js.map +1 -0
- package/dist/services/login-selectors.d.ts +18 -0
- package/dist/services/login-selectors.js +44 -0
- package/dist/services/login-selectors.js.map +1 -0
- package/dist/services/login-session.d.ts +25 -0
- package/dist/services/login-session.js +59 -0
- package/dist/services/login-session.js.map +1 -0
- package/dist/services/login.d.ts +16 -29
- package/dist/services/login.js +269 -97
- package/dist/services/login.js.map +1 -1
- package/dist/services/replay.js +15 -3
- package/dist/services/replay.js.map +1 -1
- package/dist/services/retained-snapshot.d.ts +36 -0
- package/dist/services/retained-snapshot.js +63 -0
- package/dist/services/retained-snapshot.js.map +1 -0
- package/dist/services/session-builder.d.ts +26 -0
- package/dist/services/session-builder.js +63 -21
- package/dist/services/session-builder.js.map +1 -1
- package/dist/services/shutdown.d.ts +8 -4
- package/dist/services/shutdown.js +21 -8
- package/dist/services/shutdown.js.map +1 -1
- package/dist/services/start-guards.d.ts +37 -0
- package/dist/services/start-guards.js +61 -0
- package/dist/services/start-guards.js.map +1 -0
- package/dist/services/summarize.d.ts +12 -3
- package/dist/services/summarize.js +13 -5
- package/dist/services/summarize.js.map +1 -1
- package/dist/session/cleanup.d.ts +3 -2
- package/dist/session/cleanup.js +6 -2
- package/dist/session/cleanup.js.map +1 -1
- package/dist/session/finalize.d.ts +45 -0
- package/dist/session/finalize.js +150 -0
- package/dist/session/finalize.js.map +1 -0
- package/dist/session/findings-store.d.ts +2 -1
- package/dist/session/findings-store.js +30 -2
- package/dist/session/findings-store.js.map +1 -1
- package/dist/session/flock-backend.d.ts +117 -0
- package/dist/session/flock-backend.js +293 -0
- package/dist/session/flock-backend.js.map +1 -0
- package/dist/session/live-pointer.d.ts +19 -0
- package/dist/session/live-pointer.js +41 -0
- package/dist/session/live-pointer.js.map +1 -0
- package/dist/session/manager.d.ts +11 -1
- package/dist/session/manager.js +46 -2
- package/dist/session/manager.js.map +1 -1
- package/dist/session/owner-lock.d.ts +117 -0
- package/dist/session/owner-lock.js +218 -0
- package/dist/session/owner-lock.js.map +1 -0
- package/dist/session/process-identity.js.map +1 -1
- package/dist/session/session.js +40 -109
- package/dist/session/session.js.map +1 -1
- package/dist/session/state-file.d.ts +74 -14
- package/dist/session/state-file.js +211 -21
- package/dist/session/state-file.js.map +1 -1
- package/dist/session/workspace.d.ts +32 -2
- package/dist/session/workspace.js +65 -4
- package/dist/session/workspace.js.map +1 -1
- package/package.json +11 -11
- package/dist/adapters/android/android-adapter.test-helpers.d.ts +0 -52
- package/dist/adapters/android/android-adapter.test-helpers.js +0 -115
- package/dist/adapters/android/android-adapter.test-helpers.js.map +0 -1
- package/dist/mcp/server.test-helpers.d.ts +0 -23
- package/dist/mcp/server.test-helpers.js +0 -49
- package/dist/mcp/server.test-helpers.js.map +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The managed emulator process and its boot poll — split from the adapter so the
|
|
3
|
+
* adapter stays the contract wiring. {@link ManagedEmulator} owns the child (and its
|
|
4
|
+
* listeners) until {@link ManagedEmulator.terminate}; {@link awaitBooted} is the bounded
|
|
5
|
+
* replacement for `adb wait-for-device` + the `sys.boot_completed` poll.
|
|
6
|
+
*/
|
|
7
|
+
import { AdapterError } from '../../errors.js';
|
|
8
|
+
import { terminateGroup } from '../desktop/proc.js';
|
|
9
|
+
import { pendingStateOrThrow } from './adb.js';
|
|
10
|
+
/** Poll interval for the boot and `waitFor` loops. */
|
|
11
|
+
export const POLL_MS = 300;
|
|
12
|
+
export const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
13
|
+
/** The emulator child we started: its handle, and why it is unusable once it is. */
|
|
14
|
+
export class ManagedEmulator {
|
|
15
|
+
#spawn;
|
|
16
|
+
#child = null;
|
|
17
|
+
/**
|
|
18
|
+
* The process group we own. Outlives the child's liveness: a wrapper launcher may
|
|
19
|
+
* exit while the emulator it backgrounded keeps running in the same group, so the
|
|
20
|
+
* pid is kept until {@link ManagedEmulator.terminate} has reaped the group.
|
|
21
|
+
*/
|
|
22
|
+
#group = null;
|
|
23
|
+
/** Why the process is unusable (launch failure / early exit), or null. */
|
|
24
|
+
#down = null;
|
|
25
|
+
constructor(spawn) {
|
|
26
|
+
this.#spawn = spawn;
|
|
27
|
+
}
|
|
28
|
+
/** True while a launched child is tracked (cleared on exit, error or terminate). */
|
|
29
|
+
get running() {
|
|
30
|
+
return this.#child !== null;
|
|
31
|
+
}
|
|
32
|
+
get down() {
|
|
33
|
+
return this.#down;
|
|
34
|
+
}
|
|
35
|
+
/** Spawn `bin args` and track it. */
|
|
36
|
+
start(bin, args) {
|
|
37
|
+
const child = this.#spawn(bin, args);
|
|
38
|
+
this.#down = null;
|
|
39
|
+
// Both fire async (later tick): without a listener a bad `emulatorPath` would
|
|
40
|
+
// crash the whole server via an unhandled 'error' event. Capture the failure
|
|
41
|
+
// and let the boot poll surface it as a loud AdapterError.
|
|
42
|
+
// A handler acts only for the child it was bound to: a closed child's late
|
|
43
|
+
// event must not fail, or drop the handle of, the emulator a re-open spawned.
|
|
44
|
+
child.on('error', (err) => {
|
|
45
|
+
if (this.#child !== child)
|
|
46
|
+
return;
|
|
47
|
+
this.#down = `emulator ('${bin}') failed to launch: ${err.message}`;
|
|
48
|
+
this.#child = null;
|
|
49
|
+
});
|
|
50
|
+
child.on('exit', (code, signal) => {
|
|
51
|
+
if (this.#child !== child)
|
|
52
|
+
return;
|
|
53
|
+
this.#down ??= `emulator ('${bin}') exited before boot (${signal ?? code ?? 'unknown'})`;
|
|
54
|
+
this.#child = null;
|
|
55
|
+
});
|
|
56
|
+
this.#child = child;
|
|
57
|
+
this.#group = child.pid ?? null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* SIGTERM the group, escalate to SIGKILL, and keep the handle until death is
|
|
61
|
+
* confirmed — a dropped handle leaves a SIGTERM-ignoring emulator orphaned for good.
|
|
62
|
+
*/
|
|
63
|
+
async terminate() {
|
|
64
|
+
if (this.#group !== null)
|
|
65
|
+
await terminateGroup(this.#group);
|
|
66
|
+
this.#group = null;
|
|
67
|
+
this.#child = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Poll until the emulator answers `get-state` and reports `sys.boot_completed`, bounded
|
|
72
|
+
* by the absolute `deadline`. Fails loud when the emulator died, the poll hit a real
|
|
73
|
+
* error ({@link pendingStateOrThrow}) or the deadline passed — never hangs `open`.
|
|
74
|
+
* Every call carries the deadline, so a wedged `adb` cannot hold the boot past it.
|
|
75
|
+
*/
|
|
76
|
+
export async function awaitBooted(adb, emulator, deadline, ctx) {
|
|
77
|
+
const label = `emulator @${ctx.avd} (${ctx.serial})`;
|
|
78
|
+
const downError = () => emulator.down === null ? null : new AdapterError(`android: ${emulator.down}`);
|
|
79
|
+
for (;;) {
|
|
80
|
+
const died = downError();
|
|
81
|
+
if (died)
|
|
82
|
+
throw died;
|
|
83
|
+
// `get-state` exits non-zero while no device is connected — that alone is "keep
|
|
84
|
+
// waiting"; a missing `adb`, an ambiguous target or a wedged call surfaces now.
|
|
85
|
+
const state = await adb.adb(['get-state'], deadline).catch(pendingStateOrThrow);
|
|
86
|
+
if (Date.now() >= deadline) {
|
|
87
|
+
throw new AdapterError(`android: no device appeared within ${ctx.bootWaitMs}ms (${label})`);
|
|
88
|
+
}
|
|
89
|
+
if (state.trim() === 'device')
|
|
90
|
+
break;
|
|
91
|
+
await delay(POLL_MS);
|
|
92
|
+
}
|
|
93
|
+
for (;;) {
|
|
94
|
+
// The device can flap offline mid-boot, or the emulator can die after its device
|
|
95
|
+
// appeared: retry the former, report the latter as what it is — not as the
|
|
96
|
+
// `device not found` it makes `getprop` say.
|
|
97
|
+
const out = (await adb.shell(['getprop', 'sys.boot_completed'], deadline).catch((error) => {
|
|
98
|
+
const died = downError();
|
|
99
|
+
if (died)
|
|
100
|
+
throw died;
|
|
101
|
+
return pendingStateOrThrow(error);
|
|
102
|
+
})).trim();
|
|
103
|
+
// The emulator may have died while a successful reply was in flight.
|
|
104
|
+
const died = downError();
|
|
105
|
+
if (died)
|
|
106
|
+
throw died;
|
|
107
|
+
if (Date.now() >= deadline) {
|
|
108
|
+
throw new AdapterError(`android: ${label} did not boot within ${ctx.bootWaitMs}ms`);
|
|
109
|
+
}
|
|
110
|
+
if (out === '1')
|
|
111
|
+
return;
|
|
112
|
+
await delay(POLL_MS);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=emulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../../../src/adapters/android/emulator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAY,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEzD,sDAAsD;AACtD,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAE3B,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CACjD,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAKpD,oFAAoF;AACpF,MAAM,OAAO,eAAe;IACjB,MAAM,CAAgB;IAC/B,MAAM,GAAwB,IAAI,CAAC;IACnC;;;;OAIG;IACH,MAAM,GAAkB,IAAI,CAAC;IAC7B,0EAA0E;IAC1E,KAAK,GAAkB,IAAI,CAAC;IAE5B,YAAY,KAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,oFAAoF;IACpF,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,GAAW,EAAE,IAAc;QAC/B,MAAM,KAAK,GAAG,IA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,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,YAAY,CAAC,YAAY,KAAK,wBAAwB,GAAG,CAAC,UAAU,IAAI,CAAC,CAAC;QACtF,CAAC;QACD,IAAI,GAAG,KAAK,GAAG;YAAE,OAAO;QACxB,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logcat for the android adapter — `logcat -v epoch` parsing, the console filters,
|
|
3
|
+
* and the coverage bookkeeping that keeps the durable console trail free of repeats
|
|
4
|
+
* (`logcat -t N` re-dumps the same tail on every read). Pure; the adapter owns the I/O.
|
|
5
|
+
*/
|
|
6
|
+
import type { CaptureSink, ConsoleEntry, Filters } from '../contract.js';
|
|
7
|
+
/**
|
|
8
|
+
* One raw logcat row — the record exactly as logcat emitted it, before
|
|
9
|
+
* normalization. This is the row's dedup identity: keying the NORMALIZED entry
|
|
10
|
+
* instead would merge distinct rows (the timestamp rounds to whole milliseconds,
|
|
11
|
+
* `F` and `E` fold into one level, and PID/TID are dropped entirely).
|
|
12
|
+
*/
|
|
13
|
+
export interface RawLogcatRow {
|
|
14
|
+
/** Raw `sec.frac` text — the full precision logcat emitted, never rounded. */
|
|
15
|
+
time: string;
|
|
16
|
+
pid: string;
|
|
17
|
+
tid: string;
|
|
18
|
+
/** Raw priority letter — `F` and `E` normalize alike but are distinct rows. */
|
|
19
|
+
priority: string;
|
|
20
|
+
tag: string;
|
|
21
|
+
text: string;
|
|
22
|
+
}
|
|
23
|
+
/** Parse `logcat -v epoch` output into raw rows (oldest first, as emitted). */
|
|
24
|
+
export declare function parseRawLogcat(raw: string): RawLogcatRow[];
|
|
25
|
+
/** Normalize a raw row onto the adapter-agnostic {@link ConsoleEntry} shape. */
|
|
26
|
+
export declare function toConsoleEntry(row: RawLogcatRow): ConsoleEntry;
|
|
27
|
+
/**
|
|
28
|
+
* Parse `logcat -v epoch` output into {@link ConsoleEntry}s (oldest first, as emitted).
|
|
29
|
+
* Line shape: `1546300800.000 1000 1000 I Tag: message` — unmatched lines are skipped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseLogcat(raw: string): ConsoleEntry[];
|
|
32
|
+
/** Apply the whitelisted console `filters` (logcat). Loud on an unknown key or wrong type. */
|
|
33
|
+
export declare function applyLogFilters(entries: ConsoleEntry[], filters?: Filters): ConsoleEntry[];
|
|
34
|
+
/**
|
|
35
|
+
* The covered runs: disjoint spans of raw keys — every row the durable trail
|
|
36
|
+
* already holds, oldest first, capped at {@linkcode MAX_COVERED_KEYS} retained
|
|
37
|
+
* keys (see {@linkcode LogcatCoverage.stream} and {@linkcode LogcatCoverage.capCoverage}).
|
|
38
|
+
*/
|
|
39
|
+
export declare class LogcatCoverage {
|
|
40
|
+
#private;
|
|
41
|
+
/**
|
|
42
|
+
* Stream the drained logcat rows to the capture sink — one formatted line per row.
|
|
43
|
+
*
|
|
44
|
+
* The sink is the run's redacting durable writer (the session layer binds it);
|
|
45
|
+
* the adapter itself never writes to disk. `logcat -t N` re-dumps the same tail
|
|
46
|
+
* on every read, so the durable trail would otherwise repeat it — coverage
|
|
47
|
+
* prevents that without an ever-growing row set:
|
|
48
|
+
*
|
|
49
|
+
* Drains are chronological tails of one append-only log: each is a contiguous
|
|
50
|
+
* run of rows, and the log's newest row only moves forward. What the trail
|
|
51
|
+
* already holds is therefore a set of DISJOINT covered runs —
|
|
52
|
+
* {@linkcode CoveredSpan}, oldest first — and this drain decides each of its
|
|
53
|
+
* rows by locating every span inside it ({@linkcode LogcatCoverage.spanHit}):
|
|
54
|
+
*
|
|
55
|
+
* - the span's retained keys found as one contiguous block of the drain →
|
|
56
|
+
* the block and the span's rows directly below it are covered → skipped;
|
|
57
|
+
* rows above the block sit below the earlier tail's cutoff, never drained
|
|
58
|
+
* → streamed now (a wider `limit` back-fills them, once);
|
|
59
|
+
* - the drain found inside a span's retained keys (a narrower read of an
|
|
60
|
+
* already-covered stretch) → the whole drain is covered → skipped;
|
|
61
|
+
* - only the span's key suffix found at the drain's head (the span
|
|
62
|
+
* straddles the drain's cutoff — a narrower drain, the span's oldest rows
|
|
63
|
+
* slid out of the buffer, or fresh rows arrived past it) → that overlap
|
|
64
|
+
* is skipped, everything after it streams;
|
|
65
|
+
* - no span located → the drain's rows are all fresh → they stream.
|
|
66
|
+
*
|
|
67
|
+
* Everything outside the covered ranges streams — the fresh suffix, back-fill
|
|
68
|
+
* below an earlier cutoff, AND the unseen middle of a drain that bridged two
|
|
69
|
+
* disjoint spans. Matching whole key SEQUENCES — never a boundary key — keeps
|
|
70
|
+
* byte-identical records honest: a drain holding two copies of one record ends
|
|
71
|
+
* on the second copy, and only a sequence match finds it; a first-key
|
|
72
|
+
* `findIndex` would stop at the first copy and re-stream the rest. Under a
|
|
73
|
+
* fully periodic drain an overlap is genuinely ambiguous; the earliest
|
|
74
|
+
* (largest-skip) match wins, which never duplicates: two rows sharing a raw
|
|
75
|
+
* key format to the same trail line, so a skipped twin loses no content.
|
|
76
|
+
*
|
|
77
|
+
* After the drain its whole extent is covered (every row streamed or
|
|
78
|
+
* skipped), so it merges into one span — absorbing the spans it bridged,
|
|
79
|
+
* keeping a straddling span's retained rows on either side of the drain, and
|
|
80
|
+
* filing spans wholly below or above it where they were — and
|
|
81
|
+
* {@linkcode LogcatCoverage.capCoverage} bounds the retained keys, folding
|
|
82
|
+
* the oldest into the span's `below` count without forgetting their coverage.
|
|
83
|
+
*
|
|
84
|
+
* A failing sink never fails the read.
|
|
85
|
+
*/
|
|
86
|
+
stream(rows: RawLogcatRow[], sink: CaptureSink | undefined): void;
|
|
87
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logcat for the android adapter — `logcat -v epoch` parsing, the console filters,
|
|
3
|
+
* and the coverage bookkeeping that keeps the durable console trail free of repeats
|
|
4
|
+
* (`logcat -t N` re-dumps the same tail on every read). Pure; the adapter owns the I/O.
|
|
5
|
+
*/
|
|
6
|
+
import { AdapterError } from '../../errors.js';
|
|
7
|
+
import { formatConsoleLine } from '../log-format.js';
|
|
8
|
+
/**
|
|
9
|
+
* Cap on the retained console-coverage keys — the raw keys of the covered rows
|
|
10
|
+
* still remembered individually. Bounded no matter how long the run or how wide
|
|
11
|
+
* a one-off `limit` was. Trimming a span's oldest keys does NOT forget their
|
|
12
|
+
* coverage: the rows stay covered as the span's `below` count, anchored by the
|
|
13
|
+
* span's first retained key (a drain reaching them still contains that key —
|
|
14
|
+
* the logcat buffer drops rows oldest first, and the anchor is newer).
|
|
15
|
+
*/
|
|
16
|
+
const MAX_COVERED_KEYS = 4096;
|
|
17
|
+
/** Android logcat priority letter → normalized console {@link ConsoleEntry} level. */
|
|
18
|
+
const LOGCAT_LEVEL = {
|
|
19
|
+
V: 'log',
|
|
20
|
+
D: 'debug',
|
|
21
|
+
I: 'info',
|
|
22
|
+
W: 'warn',
|
|
23
|
+
E: 'error',
|
|
24
|
+
F: 'error',
|
|
25
|
+
};
|
|
26
|
+
/** The occurrence identity of a raw row: the whole record, at full precision. */
|
|
27
|
+
function rawRowKey(row) {
|
|
28
|
+
return `${row.time}|${row.pid}|${row.tid}|${row.priority}|${row.tag}|${row.text}`;
|
|
29
|
+
}
|
|
30
|
+
/** True when `needle` appears in `hay` contiguously starting at `start`. */
|
|
31
|
+
function matchesAt(hay, start, needle) {
|
|
32
|
+
for (let i = 0; i < needle.length; i++) {
|
|
33
|
+
if (hay[start + i] !== needle[i])
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/** True when the last `r` entries of `covered` equal the first `r` of `keys`. */
|
|
39
|
+
function overlapAtHead(covered, keys, r) {
|
|
40
|
+
for (let i = 0; i < r; i++) {
|
|
41
|
+
if (covered[covered.length - r + i] !== keys[i])
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
/** The raw epoch time a row key starts with — `1546300800.000|1000|…` → 1546300800. */
|
|
47
|
+
function keyTime(key) {
|
|
48
|
+
return Number(key.slice(0, key.indexOf('|')));
|
|
49
|
+
}
|
|
50
|
+
/** Merge the hits' covered ranges into one sorted, disjoint union (overlaps fold). */
|
|
51
|
+
function unionOfRanges(hits) {
|
|
52
|
+
const sorted = [...hits].sort((a, b) => a.from - b.from || a.to - b.to);
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const hit of sorted) {
|
|
55
|
+
const last = out[out.length - 1];
|
|
56
|
+
if (last !== undefined && hit.from <= last.to + 1) {
|
|
57
|
+
last.to = Math.max(last.to, hit.to);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
out.push({ from: hit.from, to: hit.to });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/** `1546300800.000 1000 1000 I Tag: message` — unmatched lines are skipped. */
|
|
66
|
+
const LOGCAT_ROW = /^\s*(\d+)\.(\d+)\s+(\d+)\s+(\d+)\s+([VDIWEF])\s+([^:]*):\s?(.*)$/;
|
|
67
|
+
/** Parse `logcat -v epoch` output into raw rows (oldest first, as emitted). */
|
|
68
|
+
export function parseRawLogcat(raw) {
|
|
69
|
+
const out = [];
|
|
70
|
+
for (const line of raw.split('\n')) {
|
|
71
|
+
const match = LOGCAT_ROW.exec(line);
|
|
72
|
+
if (!match)
|
|
73
|
+
continue;
|
|
74
|
+
const [, sec, frac, pid, tid, priority, tag, text] = match;
|
|
75
|
+
if (sec === undefined ||
|
|
76
|
+
frac === undefined ||
|
|
77
|
+
pid === undefined ||
|
|
78
|
+
tid === undefined ||
|
|
79
|
+
priority === undefined ||
|
|
80
|
+
text === undefined) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
// A time `Date` cannot represent would make the console line's ISO stamp throw a
|
|
84
|
+
// bare RangeError mid-read. Fail loud and name the row; dropping it silently would
|
|
85
|
+
// hide a log line.
|
|
86
|
+
if (!Number.isFinite(new Date(Number(`${sec}.${frac}`) * 1000).getTime())) {
|
|
87
|
+
throw new AdapterError(`android: logcat row has an out-of-range time: ${JSON.stringify(line)}`);
|
|
88
|
+
}
|
|
89
|
+
out.push({ time: `${sec}.${frac}`, pid, tid, priority, tag: (tag ?? '').trim(), text });
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** Normalize a raw row onto the adapter-agnostic {@link ConsoleEntry} shape. */
|
|
94
|
+
export function toConsoleEntry(row) {
|
|
95
|
+
return {
|
|
96
|
+
level: LOGCAT_LEVEL[row.priority] ?? 'log',
|
|
97
|
+
text: row.text,
|
|
98
|
+
location: row.tag === '' ? undefined : row.tag,
|
|
99
|
+
timestamp: Math.round(Number(row.time) * 1000),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Parse `logcat -v epoch` output into {@link ConsoleEntry}s (oldest first, as emitted).
|
|
104
|
+
* Line shape: `1546300800.000 1000 1000 I Tag: message` — unmatched lines are skipped.
|
|
105
|
+
*/
|
|
106
|
+
export function parseLogcat(raw) {
|
|
107
|
+
return parseRawLogcat(raw).map(toConsoleEntry);
|
|
108
|
+
}
|
|
109
|
+
/** Apply the whitelisted console `filters` (logcat). Loud on an unknown key or wrong type. */
|
|
110
|
+
export function applyLogFilters(entries, filters) {
|
|
111
|
+
if (!filters)
|
|
112
|
+
return entries;
|
|
113
|
+
let out = entries;
|
|
114
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
115
|
+
switch (key) {
|
|
116
|
+
case 'level_eq': {
|
|
117
|
+
if (typeof value !== 'string')
|
|
118
|
+
throw new AdapterError('filter `level_eq` expects a string');
|
|
119
|
+
out = out.filter((e) => e.level === value);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'level_in': {
|
|
123
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
|
|
124
|
+
throw new AdapterError('filter `level_in` expects a string[]');
|
|
125
|
+
}
|
|
126
|
+
out = out.filter((e) => value.includes(e.level));
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case 'text_contains': {
|
|
130
|
+
if (typeof value !== 'string') {
|
|
131
|
+
throw new AdapterError('filter `text_contains` expects a string');
|
|
132
|
+
}
|
|
133
|
+
const needle = value.toLowerCase();
|
|
134
|
+
out = out.filter((e) => e.text.toLowerCase().includes(needle));
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
default:
|
|
138
|
+
throw new AdapterError(`unknown filter \`${key}\` for android console (allowed: level_eq, level_in, text_contains)`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The covered runs: disjoint spans of raw keys — every row the durable trail
|
|
145
|
+
* already holds, oldest first, capped at {@linkcode MAX_COVERED_KEYS} retained
|
|
146
|
+
* keys (see {@linkcode LogcatCoverage.stream} and {@linkcode LogcatCoverage.capCoverage}).
|
|
147
|
+
*/
|
|
148
|
+
export class LogcatCoverage {
|
|
149
|
+
#covered = [];
|
|
150
|
+
/**
|
|
151
|
+
* Stream the drained logcat rows to the capture sink — one formatted line per row.
|
|
152
|
+
*
|
|
153
|
+
* The sink is the run's redacting durable writer (the session layer binds it);
|
|
154
|
+
* the adapter itself never writes to disk. `logcat -t N` re-dumps the same tail
|
|
155
|
+
* on every read, so the durable trail would otherwise repeat it — coverage
|
|
156
|
+
* prevents that without an ever-growing row set:
|
|
157
|
+
*
|
|
158
|
+
* Drains are chronological tails of one append-only log: each is a contiguous
|
|
159
|
+
* run of rows, and the log's newest row only moves forward. What the trail
|
|
160
|
+
* already holds is therefore a set of DISJOINT covered runs —
|
|
161
|
+
* {@linkcode CoveredSpan}, oldest first — and this drain decides each of its
|
|
162
|
+
* rows by locating every span inside it ({@linkcode LogcatCoverage.spanHit}):
|
|
163
|
+
*
|
|
164
|
+
* - the span's retained keys found as one contiguous block of the drain →
|
|
165
|
+
* the block and the span's rows directly below it are covered → skipped;
|
|
166
|
+
* rows above the block sit below the earlier tail's cutoff, never drained
|
|
167
|
+
* → streamed now (a wider `limit` back-fills them, once);
|
|
168
|
+
* - the drain found inside a span's retained keys (a narrower read of an
|
|
169
|
+
* already-covered stretch) → the whole drain is covered → skipped;
|
|
170
|
+
* - only the span's key suffix found at the drain's head (the span
|
|
171
|
+
* straddles the drain's cutoff — a narrower drain, the span's oldest rows
|
|
172
|
+
* slid out of the buffer, or fresh rows arrived past it) → that overlap
|
|
173
|
+
* is skipped, everything after it streams;
|
|
174
|
+
* - no span located → the drain's rows are all fresh → they stream.
|
|
175
|
+
*
|
|
176
|
+
* Everything outside the covered ranges streams — the fresh suffix, back-fill
|
|
177
|
+
* below an earlier cutoff, AND the unseen middle of a drain that bridged two
|
|
178
|
+
* disjoint spans. Matching whole key SEQUENCES — never a boundary key — keeps
|
|
179
|
+
* byte-identical records honest: a drain holding two copies of one record ends
|
|
180
|
+
* on the second copy, and only a sequence match finds it; a first-key
|
|
181
|
+
* `findIndex` would stop at the first copy and re-stream the rest. Under a
|
|
182
|
+
* fully periodic drain an overlap is genuinely ambiguous; the earliest
|
|
183
|
+
* (largest-skip) match wins, which never duplicates: two rows sharing a raw
|
|
184
|
+
* key format to the same trail line, so a skipped twin loses no content.
|
|
185
|
+
*
|
|
186
|
+
* After the drain its whole extent is covered (every row streamed or
|
|
187
|
+
* skipped), so it merges into one span — absorbing the spans it bridged,
|
|
188
|
+
* keeping a straddling span's retained rows on either side of the drain, and
|
|
189
|
+
* filing spans wholly below or above it where they were — and
|
|
190
|
+
* {@linkcode LogcatCoverage.capCoverage} bounds the retained keys, folding
|
|
191
|
+
* the oldest into the span's `below` count without forgetting their coverage.
|
|
192
|
+
*
|
|
193
|
+
* A failing sink never fails the read.
|
|
194
|
+
*/
|
|
195
|
+
stream(rows, sink) {
|
|
196
|
+
const oldest = rows[0];
|
|
197
|
+
if (sink === undefined || oldest === undefined)
|
|
198
|
+
return;
|
|
199
|
+
const keys = rows.map(rawRowKey);
|
|
200
|
+
// Locate every covered span inside this drain, and file the spans it does
|
|
201
|
+
// not touch: disjoint from the drain, a span sits wholly below it (older
|
|
202
|
+
// than the drain's oldest row) or wholly above (newer than its newest).
|
|
203
|
+
const hits = [];
|
|
204
|
+
const below = [];
|
|
205
|
+
const above = [];
|
|
206
|
+
const drainStart = keyTime(rawRowKey(oldest));
|
|
207
|
+
for (const span of this.#covered) {
|
|
208
|
+
const hit = this.#spanHit(span, keys);
|
|
209
|
+
if (hit !== null) {
|
|
210
|
+
hits.push(hit);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const newest = span.keys[span.keys.length - 1];
|
|
214
|
+
if (newest !== undefined && keyTime(newest) < drainStart)
|
|
215
|
+
below.push(span);
|
|
216
|
+
else
|
|
217
|
+
above.push(span);
|
|
218
|
+
}
|
|
219
|
+
// Stream every row outside the union of the covered ranges.
|
|
220
|
+
const ranges = unionOfRanges(hits);
|
|
221
|
+
let cursor = 0;
|
|
222
|
+
for (const [index, row] of rows.entries()) {
|
|
223
|
+
let range = ranges[cursor];
|
|
224
|
+
while (range !== undefined && range.to < index) {
|
|
225
|
+
cursor++;
|
|
226
|
+
range = ranges[cursor];
|
|
227
|
+
}
|
|
228
|
+
if (range !== undefined && index >= range.from)
|
|
229
|
+
continue;
|
|
230
|
+
try {
|
|
231
|
+
sink('console', formatConsoleLine(toConsoleEntry(row)));
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
// A sink failure must not crash the read — the entries still come back.
|
|
235
|
+
console.error(`android capture sink failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// The drain's whole extent is covered now — every row streamed or skipped —
|
|
239
|
+
// so it becomes one span. A straddling span's retained rows stay remembered
|
|
240
|
+
// on either side of the drain; when several spans straddle (fully periodic
|
|
241
|
+
// content), the most coverage kept wins, which never duplicates.
|
|
242
|
+
let belowAnchored = 0;
|
|
243
|
+
let headKeys = [];
|
|
244
|
+
let tailKeys = [];
|
|
245
|
+
for (const hit of hits) {
|
|
246
|
+
if (hit.belowAnchored + hit.headKeys.length > belowAnchored + headKeys.length) {
|
|
247
|
+
belowAnchored = hit.belowAnchored;
|
|
248
|
+
headKeys = hit.headKeys;
|
|
249
|
+
}
|
|
250
|
+
if (hit.tailKeys.length > tailKeys.length)
|
|
251
|
+
tailKeys = hit.tailKeys;
|
|
252
|
+
}
|
|
253
|
+
this.#covered = [
|
|
254
|
+
...below,
|
|
255
|
+
{ below: belowAnchored, keys: [...headKeys, ...keys, ...tailKeys] },
|
|
256
|
+
...above,
|
|
257
|
+
];
|
|
258
|
+
this.#capCoverage();
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Locate one covered span inside this drain's keys (both oldest first).
|
|
262
|
+
* Returns where the span's covered rows sit inside the drain — inclusive
|
|
263
|
+
* `[from, to]` indexes plus the span's covered rows outside the drain — or
|
|
264
|
+
* null when none of the span appears in it.
|
|
265
|
+
*/
|
|
266
|
+
#spanHit(span, keys) {
|
|
267
|
+
const m = span.keys.length;
|
|
268
|
+
const n = keys.length;
|
|
269
|
+
if (m === 0 || n === 0)
|
|
270
|
+
return null;
|
|
271
|
+
// The span's retained keys as one contiguous block of the drain — a drain
|
|
272
|
+
// at least as wide as the span's retained window. Earliest alignment wins
|
|
273
|
+
// (see the streamRows note). The span's rows below the block are covered
|
|
274
|
+
// too: the retained ones are anchored by the block, the trimmed ones by the
|
|
275
|
+
// span's `below` count.
|
|
276
|
+
if (n >= m) {
|
|
277
|
+
for (let i = 0; i + m <= n; i++) {
|
|
278
|
+
if (matchesAt(keys, i, span.keys)) {
|
|
279
|
+
return {
|
|
280
|
+
from: Math.max(0, i - span.below),
|
|
281
|
+
to: i + m - 1,
|
|
282
|
+
belowAnchored: span.below - Math.min(span.below, i),
|
|
283
|
+
headKeys: [],
|
|
284
|
+
tailKeys: [],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// The drain as one contiguous block of the span's retained keys — a
|
|
290
|
+
// narrower read of an already-covered stretch. The whole drain is covered,
|
|
291
|
+
// and the span's retained rows on either side of it stay covered.
|
|
292
|
+
if (m >= n) {
|
|
293
|
+
for (let q = 0; q + n <= m; q++) {
|
|
294
|
+
if (matchesAt(span.keys, q, keys)) {
|
|
295
|
+
return {
|
|
296
|
+
from: 0,
|
|
297
|
+
to: n - 1,
|
|
298
|
+
belowAnchored: span.below,
|
|
299
|
+
headKeys: span.keys.slice(0, q),
|
|
300
|
+
tailKeys: span.keys.slice(q + n),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Otherwise the drain's head sits inside the span: its longest suffix that
|
|
306
|
+
// matches the drain's prefix is the overlap (the span straddles the drain's
|
|
307
|
+
// cutoff, or its oldest rows slid out of the buffer).
|
|
308
|
+
for (let r = Math.min(m, n); r >= 1; r--) {
|
|
309
|
+
if (overlapAtHead(span.keys, keys, r)) {
|
|
310
|
+
return {
|
|
311
|
+
from: 0,
|
|
312
|
+
to: r - 1,
|
|
313
|
+
belowAnchored: span.below,
|
|
314
|
+
headKeys: span.keys.slice(0, m - r),
|
|
315
|
+
tailKeys: [],
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Bound the retained coverage keys at {@linkcode MAX_COVERED_KEYS}, oldest
|
|
323
|
+
* first. A span's trimmed keys stay covered as its `below` count — the rows
|
|
324
|
+
* sit directly below the span's new first key, contiguous with it and
|
|
325
|
+
* anchored by it, so a later drain reaching them still skips them. A span
|
|
326
|
+
* always keeps one anchor key; when every span is down to its anchor and the
|
|
327
|
+
* cap still bites, the oldest spans drop whole — by then their rows left the
|
|
328
|
+
* logcat buffer long before (the anchor is newer, and the buffer drops rows
|
|
329
|
+
* oldest first).
|
|
330
|
+
*/
|
|
331
|
+
#capCoverage() {
|
|
332
|
+
let total = this.#covered.reduce((sum, span) => sum + span.keys.length, 0);
|
|
333
|
+
for (const span of this.#covered) {
|
|
334
|
+
if (total <= MAX_COVERED_KEYS)
|
|
335
|
+
break;
|
|
336
|
+
const droppable = span.keys.length - 1;
|
|
337
|
+
if (droppable <= 0)
|
|
338
|
+
continue;
|
|
339
|
+
const drop = Math.min(droppable, total - MAX_COVERED_KEYS);
|
|
340
|
+
span.below += drop;
|
|
341
|
+
span.keys.splice(0, drop);
|
|
342
|
+
total -= drop;
|
|
343
|
+
}
|
|
344
|
+
while (total > MAX_COVERED_KEYS && this.#covered.length > 1) {
|
|
345
|
+
const dropped = this.#covered.shift();
|
|
346
|
+
if (dropped === undefined)
|
|
347
|
+
break;
|
|
348
|
+
total -= dropped.keys.length;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=logcat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logcat.js","sourceRoot":"","sources":["../../../src/adapters/android/logcat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,sFAAsF;AACtF,MAAM,YAAY,GAA0C;IAC1D,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,OAAO;CACX,CAAC;AAmBF,iFAAiF;AACjF,SAAS,SAAS,CAAC,GAAiB;IAClC,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CA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,EAAE,EAAE;IACtB,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QAC/D,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEL;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAK,GAAc,UAAU;IAClE,KAAK,IAAI,IAAI,GAAG,QAAQ,EAAE,IAAI,IAAI,QAAQ,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;QACtD,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;IAClE,CAAC;IACD,MAAM,IAAI,YAAY,CACpB,qCAAqC,QAAQ,IAAI,QAAQ,+BAA+B,CACzF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the managed emulator binary comes from — the pure decision, split from
|
|
3
|
+
* the adapter like its siblings (`ports.ts`, `launch.ts`).
|
|
4
|
+
*
|
|
5
|
+
* `emulatorPath: null` means "auto-detect from the SDK" (`config/schema.ts`).
|
|
6
|
+
* The old fallback (`?? 'emulator'`) spawned a bare `emulator` and leaned on
|
|
7
|
+
* PATH alone — a normal Android Studio install (macOS, Windows) never puts the
|
|
8
|
+
* emulator on PATH, so a perfectly bootable SDK went unnoticed and managed
|
|
9
|
+
* boot failed. Resolution order, first hit wins:
|
|
10
|
+
*
|
|
11
|
+
* 1. a configured `emulatorPath` — used verbatim, zero env/fs access;
|
|
12
|
+
* 2. the SDK layouts: `$ANDROID_HOME/emulator/`, `$ANDROID_SDK_ROOT/emulator/`,
|
|
13
|
+
* `~/Android/Sdk/emulator/` (Linux), `~/Library/Android/sdk/emulator/` (macOS);
|
|
14
|
+
* 3. a bare `emulator` on PATH — the old behaviour, kept as the last resort.
|
|
15
|
+
*
|
|
16
|
+
* An auto-detected hit is accepted only if it is an **executable file**: a
|
|
17
|
+
* non-executable candidate (a data file, a directory, a stub without +x)
|
|
18
|
+
* falls through to the next source instead of masking a runnable one behind
|
|
19
|
+
* it — existence alone would let `/a/emulator` shadow `/b/emulator`.
|
|
20
|
+
*
|
|
21
|
+
* A miss is a **result**, not a throw: `origin: 'missing'` plus every searched
|
|
22
|
+
* location, so the caller fails loud with where it looked. Env values and PATH
|
|
23
|
+
* entries are trimmed; an empty one counts as unset.
|
|
24
|
+
*/
|
|
25
|
+
/** Where a resolved emulator binary came from. */
|
|
26
|
+
export type EmulatorOrigin = 'config' | 'sdk' | 'path' | 'missing';
|
|
27
|
+
/** One resolution outcome: the binary to spawn and its provenance. */
|
|
28
|
+
export interface EmulatorBin {
|
|
29
|
+
/** Path to spawn. `''` when `origin` is `missing` — there is nothing to spawn. */
|
|
30
|
+
bin: string;
|
|
31
|
+
origin: EmulatorOrigin;
|
|
32
|
+
/**
|
|
33
|
+
* Provenance of `bin`: the source that produced it (`'$ANDROID_HOME'`,
|
|
34
|
+
* `'~/Android/Sdk'`, `'PATH'`, …), `'configured emulatorPath'` or `'not found'`.
|
|
35
|
+
*/
|
|
36
|
+
where: string;
|
|
37
|
+
/** Candidate labels probed before giving up — set only on `missing`. */
|
|
38
|
+
searched?: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Host state the resolution reads, named so tests can inject all of it — no
|
|
42
|
+
* test (or future caller) ever needs a real `process.env` or filesystem.
|
|
43
|
+
*/
|
|
44
|
+
export interface EmulatorSeams {
|
|
45
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
46
|
+
/**
|
|
47
|
+
* Eligibility of an auto-detected candidate: a regular file this process may
|
|
48
|
+
* execute. Existence alone is not enough — an ineligible first hit must fall
|
|
49
|
+
* through, or it masks the runnable candidate behind it.
|
|
50
|
+
*/
|
|
51
|
+
isExecutableFile: (path: string) => boolean;
|
|
52
|
+
home: string;
|
|
53
|
+
platform: NodeJS.Platform;
|
|
54
|
+
}
|
|
55
|
+
/** The real seams: the process environment, the real filesystem, this host. */
|
|
56
|
+
export declare function realEmulatorSeams(): EmulatorSeams;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the emulator binary for a managed boot. Never throws: a miss comes
|
|
59
|
+
* back as `origin: 'missing'` with the searched locations attached.
|
|
60
|
+
*
|
|
61
|
+
* A configured `emulatorPath` (trimmed non-empty) wins verbatim — it is never
|
|
62
|
+
* normalized or probed, so a typo'd path fails loud at spawn instead of being
|
|
63
|
+
* silently replaced by a detected binary.
|
|
64
|
+
*/
|
|
65
|
+
export declare function resolveEmulatorBin(explicit: string | null | undefined, seams?: EmulatorSeams): EmulatorBin;
|