@reticlehq/core 2.11.0 → 2.13.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/dist/constants.d.ts +40 -0
- package/dist/constants.js +41 -1
- package/dist/dev-server-registry.d.ts +85 -0
- package/dist/dev-server-registry.js +120 -0
- package/dist/document-identity.d.ts +39 -0
- package/dist/document-identity.js +53 -0
- package/dist/edit-epoch.d.ts +36 -0
- package/dist/edit-epoch.js +40 -0
- package/dist/event-payloads.d.ts +24 -4
- package/dist/event-payloads.js +13 -1
- package/dist/findings.d.ts +62 -0
- package/dist/findings.js +75 -0
- package/dist/flow-types.d.ts +88 -0
- package/dist/flow-types.js +22 -0
- package/dist/impact.d.ts +176 -0
- package/dist/impact.js +36 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/instrumentation-gap.d.ts +59 -1
- package/dist/instrumentation-gap.js +0 -0
- package/dist/intent.d.ts +332 -0
- package/dist/intent.js +133 -0
- package/dist/journal.d.ts +33 -0
- package/dist/journal.js +20 -0
- package/dist/messages.d.ts +84 -10
- package/dist/messages.js +20 -0
- package/dist/net.d.ts +34 -0
- package/dist/net.js +86 -0
- package/dist/no-session-reason.d.ts +35 -0
- package/dist/no-session-reason.js +34 -0
- package/dist/notices.d.ts +79 -6
- package/dist/notices.js +83 -6
- package/dist/run-context.d.ts +122 -0
- package/dist/run-context.js +118 -0
- package/dist/schema/event-message.json +10 -0
- package/dist/schema/event-type.json +1 -0
- package/dist/schema/reticle-event.json +10 -0
- package/dist/schema/reticle-message.json +10 -0
- package/dist/security.d.ts +8 -2
- package/dist/security.js +37 -3
- package/dist/session-constants.d.ts +8 -0
- package/dist/session-constants.js +8 -0
- package/dist/source-constants.cjs +9 -0
- package/dist/source-constants.d.cts +4 -0
- package/dist/telemetry-license.d.ts +12 -0
- package/dist/telemetry-license.js +12 -0
- package/dist/telemetry-refusal.d.ts +94 -0
- package/dist/telemetry-refusal.js +61 -0
- package/dist/telemetry-session.d.ts +151 -2
- package/dist/telemetry-session.js +114 -0
- package/dist/telemetry.d.ts +167 -95
- package/dist/telemetry.js +46 -44
- package/dist/types.d.ts +9 -0
- package/dist/unreachable-notice.d.ts +19 -0
- package/dist/unreachable-notice.js +26 -0
- package/dist/verified-constants.d.ts +8 -0
- package/dist/verified-constants.js +10 -0
- package/package.json +6 -2
package/dist/constants.d.ts
CHANGED
|
@@ -37,6 +37,20 @@ export declare const STATUS_PATH = "/status";
|
|
|
37
37
|
*/
|
|
38
38
|
export declare const DRIVE_PATH = "/drive";
|
|
39
39
|
export declare const RETICLE_PROTOCOL_VERSION = 1;
|
|
40
|
+
/**
|
|
41
|
+
* The host a CLIENT names when it dials the bridge, as opposed to the address the bridge BINDS.
|
|
42
|
+
*
|
|
43
|
+
* They are deliberately different values and both are correct. The daemon binds `127.0.0.1` so it can
|
|
44
|
+
* never be reached off-host; a client says `localhost`, which is the readable name every doc, log
|
|
45
|
+
* line and error message uses. The gap between them is covered by the IPv6 loopback alias
|
|
46
|
+
* (`loopback-alias.ts`), which serves `[::1]` too, so `localhost` reaches the daemon whichever family
|
|
47
|
+
* a platform resolves first.
|
|
48
|
+
*
|
|
49
|
+
* Named rather than inlined because it was inlined, and three generators then wrote their own: CRA
|
|
50
|
+
* emitted `127.0.0.1`, the Astro helper and the Next plugin each spelled out `localhost`. A default
|
|
51
|
+
* argument is not a single source of truth if it can be bypassed by typing the value.
|
|
52
|
+
*/
|
|
53
|
+
export declare const RETICLE_CLIENT_HOST = "localhost";
|
|
40
54
|
/**
|
|
41
55
|
* The one place the bridge WebSocket URL is built. The SDK connect default, the vite/next snippet
|
|
42
56
|
* generators, and the CLI's inject-connect all call this instead of hand-writing `ws://…${path}` —
|
|
@@ -210,6 +224,8 @@ export declare const ReticleDir: {
|
|
|
210
224
|
* questions about the product; this answers the user's question about their own work.
|
|
211
225
|
*/
|
|
212
226
|
readonly IMPACT_FILE: "impact.json";
|
|
227
|
+
/** what changes were SUPPOSED to make true —.reticle/intent.json (git-checked, reviewed) */
|
|
228
|
+
readonly INTENT_FILE: "intent.json";
|
|
213
229
|
/** opt-in pixel baselines —.reticle/visual/<name>.png + <name>.diff.png. */
|
|
214
230
|
readonly VISUAL_SUBDIR: "visual";
|
|
215
231
|
/** verification-run artifacts —.reticle/runs/<runId>.json (the OEM/CI-consumable verdict). */
|
|
@@ -228,6 +244,24 @@ export declare const ReticleDir: {
|
|
|
228
244
|
readonly AMBIENT_FILE: "ambient.json";
|
|
229
245
|
/** per-flow flake ledger — replay outcomes that decide intermittent-failure quarantine. */
|
|
230
246
|
readonly FLAKE_FILE: "flake.json";
|
|
247
|
+
/**
|
|
248
|
+
* the project's cloud binding — .reticle/cloud.json, written by `reticle link`. Git-checked and
|
|
249
|
+
* non-secret: the project id, the API origin, and where its dashboard lives. The KEY lives in
|
|
250
|
+
* ~/.reticle/credentials.json instead, because that one must never reach a repository.
|
|
251
|
+
*/
|
|
252
|
+
readonly CLOUD_LINK_FILE: "cloud.json";
|
|
253
|
+
/**
|
|
254
|
+
* local sync bookkeeping — .reticle/cloud-state.json. The pull cursor, when each half last ran,
|
|
255
|
+
* and the last error. NOT git-checked: it describes this machine's conversation with the server,
|
|
256
|
+
* and committing one machine's cursor would make every other machine skip what it had not seen.
|
|
257
|
+
*/
|
|
258
|
+
readonly CLOUD_STATE_FILE: "cloud-state.json";
|
|
259
|
+
/**
|
|
260
|
+
* triage decisions pulled BACK from the dashboard — .reticle/issues.json. What a human said about
|
|
261
|
+
* a defect ("resolved", "not a bug"), so the HUD stops showing it and the next run does not
|
|
262
|
+
* re-report it as though nobody had looked.
|
|
263
|
+
*/
|
|
264
|
+
readonly ISSUES_FILE: "issues.json";
|
|
231
265
|
/** Per-flow assertion tiers recorded on each PASSING replay — the gate's anti-downgrade baseline. */
|
|
232
266
|
readonly TIERS_FILE: "assertion-tiers.json";
|
|
233
267
|
/**
|
|
@@ -330,6 +364,12 @@ export declare const EventType: {
|
|
|
330
364
|
readonly STORAGE_CHANGE: "storage.change";
|
|
331
365
|
/** page-level visibility/focus health (distinct from element-level VISIBLE_*). */
|
|
332
366
|
readonly PAGE_HEALTH: "page.health";
|
|
367
|
+
/**
|
|
368
|
+
* synthetic: the page called window.open, so the consequence of what was just clicked may live in
|
|
369
|
+
* another browsing context this one cannot observe (an OAuth popup is the archetype).
|
|
370
|
+
* `data: { href }` — the URL the page asked to open, when it named one.
|
|
371
|
+
*/
|
|
372
|
+
readonly CONTEXT_OPENED: "context.opened";
|
|
333
373
|
/** aggregated React commits over a throttle window (dev builds) — `data: { commits }`. Commit storms /
|
|
334
374
|
* wasted re-renders show up here without a per-render flood. */
|
|
335
375
|
readonly RENDER_COMMIT: "render.commit";
|
package/dist/constants.js
CHANGED
|
@@ -37,13 +37,27 @@ export const STATUS_PATH = '/status';
|
|
|
37
37
|
*/
|
|
38
38
|
export const DRIVE_PATH = '/drive';
|
|
39
39
|
export const RETICLE_PROTOCOL_VERSION = 1;
|
|
40
|
+
/**
|
|
41
|
+
* The host a CLIENT names when it dials the bridge, as opposed to the address the bridge BINDS.
|
|
42
|
+
*
|
|
43
|
+
* They are deliberately different values and both are correct. The daemon binds `127.0.0.1` so it can
|
|
44
|
+
* never be reached off-host; a client says `localhost`, which is the readable name every doc, log
|
|
45
|
+
* line and error message uses. The gap between them is covered by the IPv6 loopback alias
|
|
46
|
+
* (`loopback-alias.ts`), which serves `[::1]` too, so `localhost` reaches the daemon whichever family
|
|
47
|
+
* a platform resolves first.
|
|
48
|
+
*
|
|
49
|
+
* Named rather than inlined because it was inlined, and three generators then wrote their own: CRA
|
|
50
|
+
* emitted `127.0.0.1`, the Astro helper and the Next plugin each spelled out `localhost`. A default
|
|
51
|
+
* argument is not a single source of truth if it can be bypassed by typing the value.
|
|
52
|
+
*/
|
|
53
|
+
export const RETICLE_CLIENT_HOST = 'localhost';
|
|
40
54
|
/**
|
|
41
55
|
* The one place the bridge WebSocket URL is built. The SDK connect default, the vite/next snippet
|
|
42
56
|
* generators, and the CLI's inject-connect all call this instead of hand-writing `ws://…${path}` —
|
|
43
57
|
* so the wire string can never drift across the four call sites. Host defaults to `localhost` (the
|
|
44
58
|
* dev app connects from the browser); pass it only for a non-default bind.
|
|
45
59
|
*/
|
|
46
|
-
export function bridgeWsUrl(port = RETICLE_DEFAULT_PORT, host =
|
|
60
|
+
export function bridgeWsUrl(port = RETICLE_DEFAULT_PORT, host = RETICLE_CLIENT_HOST) {
|
|
47
61
|
return `ws://${host}:${String(port)}${RETICLE_WS_PATH}`;
|
|
48
62
|
}
|
|
49
63
|
/**
|
|
@@ -212,6 +226,8 @@ export const ReticleDir = {
|
|
|
212
226
|
* questions about the product; this answers the user's question about their own work.
|
|
213
227
|
*/
|
|
214
228
|
IMPACT_FILE: 'impact.json',
|
|
229
|
+
/** what changes were SUPPOSED to make true —.reticle/intent.json (git-checked, reviewed) */
|
|
230
|
+
INTENT_FILE: 'intent.json',
|
|
215
231
|
/** opt-in pixel baselines —.reticle/visual/<name>.png + <name>.diff.png. */
|
|
216
232
|
VISUAL_SUBDIR: 'visual',
|
|
217
233
|
/** verification-run artifacts —.reticle/runs/<runId>.json (the OEM/CI-consumable verdict). */
|
|
@@ -230,6 +246,24 @@ export const ReticleDir = {
|
|
|
230
246
|
AMBIENT_FILE: 'ambient.json',
|
|
231
247
|
/** per-flow flake ledger — replay outcomes that decide intermittent-failure quarantine. */
|
|
232
248
|
FLAKE_FILE: 'flake.json',
|
|
249
|
+
/**
|
|
250
|
+
* the project's cloud binding — .reticle/cloud.json, written by `reticle link`. Git-checked and
|
|
251
|
+
* non-secret: the project id, the API origin, and where its dashboard lives. The KEY lives in
|
|
252
|
+
* ~/.reticle/credentials.json instead, because that one must never reach a repository.
|
|
253
|
+
*/
|
|
254
|
+
CLOUD_LINK_FILE: 'cloud.json',
|
|
255
|
+
/**
|
|
256
|
+
* local sync bookkeeping — .reticle/cloud-state.json. The pull cursor, when each half last ran,
|
|
257
|
+
* and the last error. NOT git-checked: it describes this machine's conversation with the server,
|
|
258
|
+
* and committing one machine's cursor would make every other machine skip what it had not seen.
|
|
259
|
+
*/
|
|
260
|
+
CLOUD_STATE_FILE: 'cloud-state.json',
|
|
261
|
+
/**
|
|
262
|
+
* triage decisions pulled BACK from the dashboard — .reticle/issues.json. What a human said about
|
|
263
|
+
* a defect ("resolved", "not a bug"), so the HUD stops showing it and the next run does not
|
|
264
|
+
* re-report it as though nobody had looked.
|
|
265
|
+
*/
|
|
266
|
+
ISSUES_FILE: 'issues.json',
|
|
233
267
|
/** Per-flow assertion tiers recorded on each PASSING replay — the gate's anti-downgrade baseline. */
|
|
234
268
|
TIERS_FILE: 'assertion-tiers.json',
|
|
235
269
|
/**
|
|
@@ -338,6 +372,12 @@ export const EventType = {
|
|
|
338
372
|
STORAGE_CHANGE: 'storage.change',
|
|
339
373
|
/** page-level visibility/focus health (distinct from element-level VISIBLE_*). */
|
|
340
374
|
PAGE_HEALTH: 'page.health',
|
|
375
|
+
/**
|
|
376
|
+
* synthetic: the page called window.open, so the consequence of what was just clicked may live in
|
|
377
|
+
* another browsing context this one cannot observe (an OAuth popup is the archetype).
|
|
378
|
+
* `data: { href }` — the URL the page asked to open, when it named one.
|
|
379
|
+
*/
|
|
380
|
+
CONTEXT_OPENED: 'context.opened',
|
|
341
381
|
/** aggregated React commits over a throttle window (dev builds) — `data: { commits }`. Commit storms /
|
|
342
382
|
* wasted re-renders show up here without a per-render flood. */
|
|
343
383
|
RENDER_COMMIT: 'render.commit',
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The registry filename for a dev server listening on `port`. */
|
|
3
|
+
export declare function devServerRegistryFileName(port: number): string;
|
|
4
|
+
/**
|
|
5
|
+
* The port from a registry filename, or null when the name is not one.
|
|
6
|
+
*
|
|
7
|
+
* Strict about the whole shape, because the daemon's own `daemon-<port>.json` sits in the same
|
|
8
|
+
* directory: reading one of those as a dev server would report the daemon as an instrumented app,
|
|
9
|
+
* which is the precise false green this signal exists to prevent.
|
|
10
|
+
*/
|
|
11
|
+
export declare function devServerRegistryPort(fileName: string): number | null;
|
|
12
|
+
/** One dev server's entry: enough to name it, reach it, and prove it is still alive. */
|
|
13
|
+
export declare const DevServerEntrySchema: z.ZodObject<{
|
|
14
|
+
port: z.ZodNumber;
|
|
15
|
+
pid: z.ZodNumber;
|
|
16
|
+
/** The project directory the dev server is serving — how a monorepo tells its apps apart. */
|
|
17
|
+
root: z.ZodString;
|
|
18
|
+
/** Where the app is actually served, as the dev server itself reports it. Never assembled here. */
|
|
19
|
+
url: z.ZodString;
|
|
20
|
+
/**
|
|
21
|
+
* The SDK version in the bundle, so a skew can be named rather than guessed at.
|
|
22
|
+
*
|
|
23
|
+
* Optional, and ABSENT rather than empty when it cannot be resolved. `""` reads as "the version is
|
|
24
|
+
* empty"; a missing field reads as "not known", which is the true statement — and the difference
|
|
25
|
+
* matters to the one reader who exists for this field, a skew diagnosis.
|
|
26
|
+
*/
|
|
27
|
+
sdkVersion: z.ZodOptional<z.ZodString>;
|
|
28
|
+
startedAt: z.ZodNumber;
|
|
29
|
+
/**
|
|
30
|
+
* Optional because an app can be running before `init` has ever named it — which is exactly the
|
|
31
|
+
* state this signal has to be able to describe.
|
|
32
|
+
*/
|
|
33
|
+
projectId: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
url: string;
|
|
36
|
+
port: number;
|
|
37
|
+
pid: number;
|
|
38
|
+
startedAt: number;
|
|
39
|
+
root: string;
|
|
40
|
+
projectId?: string | undefined;
|
|
41
|
+
sdkVersion?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
url: string;
|
|
44
|
+
port: number;
|
|
45
|
+
pid: number;
|
|
46
|
+
startedAt: number;
|
|
47
|
+
root: string;
|
|
48
|
+
projectId?: string | undefined;
|
|
49
|
+
sdkVersion?: string | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
export type DevServerEntry = z.infer<typeof DevServerEntrySchema>;
|
|
52
|
+
/**
|
|
53
|
+
* The entries whose process is still running, lowest port first.
|
|
54
|
+
*
|
|
55
|
+
* Liveness is checked rather than trusted for the same reason the daemon registry checks it: a dev
|
|
56
|
+
* server killed with SIGKILL runs no cleanup, so its file outlives it. A stale entry read as live is
|
|
57
|
+
* worse than no entry at all — it reports a running, instrumented app over a dead port, and sends
|
|
58
|
+
* the reader to look at their browser instead of at their terminal.
|
|
59
|
+
*
|
|
60
|
+
* Pure, so both the CLI and the plugins share one rule and it is testable without real processes.
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* The live entries that belong to THIS project.
|
|
64
|
+
*
|
|
65
|
+
* Scoping is not a refinement here, it is the difference between a diagnosis and a wrong answer. A
|
|
66
|
+
* dev server registry is machine-wide — one directory holds every app on the box — so "a dev server
|
|
67
|
+
* is running" is satisfied by somebody else's app, by another package in the same monorepo, by
|
|
68
|
+
* yesterday's terminal. Reported unscoped, `init` for app A told the user their dev server was wired
|
|
69
|
+
* and handed them app B's URL: confident, specific, and about a project they were not setting up.
|
|
70
|
+
*
|
|
71
|
+
* Two ways to belong, because both are true and neither covers the other:
|
|
72
|
+
*
|
|
73
|
+
* - the projectId matches, which is exact and survives a moved directory
|
|
74
|
+
* - the entry's root is the directory being set up, or inside it, which is what makes `init` at a
|
|
75
|
+
* monorepo root see the apps underneath it — they genuinely are its apps
|
|
76
|
+
*
|
|
77
|
+
* With neither known nothing matches, and the caller gets the same less specific answer it had
|
|
78
|
+
* before. That is the conservative direction on purpose: a missed match costs one vaguer sentence,
|
|
79
|
+
* a wrong match sends somebody to another team's app.
|
|
80
|
+
*/
|
|
81
|
+
export declare function devServersForProject(entries: readonly DevServerEntry[], scope: {
|
|
82
|
+
projectId?: string | undefined;
|
|
83
|
+
root?: string | undefined;
|
|
84
|
+
}): DevServerEntry[];
|
|
85
|
+
export declare function liveDevServers(entries: readonly DevServerEntry[], isAlive: (pid: number) => boolean): DevServerEntry[];
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The dev-server discovery registry — the return leg of `daemon-registry.ts`.
|
|
4
|
+
*
|
|
5
|
+
* A live daemon already drops `daemon-<port>.json` here so a build plugin can FIND it by projectId
|
|
6
|
+
* rather than being told a port in two places. Nothing went the other way: the daemon, and `init`,
|
|
7
|
+
* had no way to know a dev server existed at all.
|
|
8
|
+
*
|
|
9
|
+
* That gap is why setup fails silently. Ten things must be true before a tool call can see anything,
|
|
10
|
+
* and the commonest miss — a plugin added to a config the running dev server already read — is
|
|
11
|
+
* invisible from outside the dev server's own process. So `init` wrote files, printed instructions,
|
|
12
|
+
* and left; the person with an uninstrumented page was never told.
|
|
13
|
+
*
|
|
14
|
+
* The alternative was for `init` to run the dev command itself. It cannot: the command, the script
|
|
15
|
+
* name, the package manager, the port and the framework are all things the user or their agent may
|
|
16
|
+
* change, and a setup step that hardcodes any of them is a setup step that breaks on the project it
|
|
17
|
+
* was most needed for. So nothing here starts anything or names a command. The plugin ALREADY runs
|
|
18
|
+
* Node-side when the dev server boots; it announces there, and the reader waits.
|
|
19
|
+
*
|
|
20
|
+
* With both legs present the diagnosis is three-way and every branch is an observed fact:
|
|
21
|
+
*
|
|
22
|
+
* no entry, no session nothing with Reticle loaded is running — start or restart it
|
|
23
|
+
* entry, no session the bundle is wired and no page dialled — and `url` names where to look
|
|
24
|
+
* entry and session working
|
|
25
|
+
*
|
|
26
|
+
* A file rather than a request, deliberately: at `init` time there is frequently no daemon to POST
|
|
27
|
+
* to yet, and a signal that requires the thing it is diagnosing to already be up is no signal.
|
|
28
|
+
*/
|
|
29
|
+
const DEV_SERVER_PREFIX = 'devserver-';
|
|
30
|
+
const DEV_SERVER_SUFFIX = '.json';
|
|
31
|
+
/** The registry filename for a dev server listening on `port`. */
|
|
32
|
+
export function devServerRegistryFileName(port) {
|
|
33
|
+
return `${DEV_SERVER_PREFIX}${String(port)}${DEV_SERVER_SUFFIX}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The port from a registry filename, or null when the name is not one.
|
|
37
|
+
*
|
|
38
|
+
* Strict about the whole shape, because the daemon's own `daemon-<port>.json` sits in the same
|
|
39
|
+
* directory: reading one of those as a dev server would report the daemon as an instrumented app,
|
|
40
|
+
* which is the precise false green this signal exists to prevent.
|
|
41
|
+
*/
|
|
42
|
+
export function devServerRegistryPort(fileName) {
|
|
43
|
+
if (!fileName.startsWith(DEV_SERVER_PREFIX) || !fileName.endsWith(DEV_SERVER_SUFFIX))
|
|
44
|
+
return null;
|
|
45
|
+
const mid = fileName.slice(DEV_SERVER_PREFIX.length, -DEV_SERVER_SUFFIX.length);
|
|
46
|
+
return /^\d+$/.test(mid) ? Number(mid) : null;
|
|
47
|
+
}
|
|
48
|
+
/** One dev server's entry: enough to name it, reach it, and prove it is still alive. */
|
|
49
|
+
export const DevServerEntrySchema = z.object({
|
|
50
|
+
port: z.number(),
|
|
51
|
+
pid: z.number(),
|
|
52
|
+
/** The project directory the dev server is serving — how a monorepo tells its apps apart. */
|
|
53
|
+
root: z.string(),
|
|
54
|
+
/** Where the app is actually served, as the dev server itself reports it. Never assembled here. */
|
|
55
|
+
url: z.string(),
|
|
56
|
+
/**
|
|
57
|
+
* The SDK version in the bundle, so a skew can be named rather than guessed at.
|
|
58
|
+
*
|
|
59
|
+
* Optional, and ABSENT rather than empty when it cannot be resolved. `""` reads as "the version is
|
|
60
|
+
* empty"; a missing field reads as "not known", which is the true statement — and the difference
|
|
61
|
+
* matters to the one reader who exists for this field, a skew diagnosis.
|
|
62
|
+
*/
|
|
63
|
+
sdkVersion: z.string().min(1).optional(),
|
|
64
|
+
startedAt: z.number(),
|
|
65
|
+
/**
|
|
66
|
+
* Optional because an app can be running before `init` has ever named it — which is exactly the
|
|
67
|
+
* state this signal has to be able to describe.
|
|
68
|
+
*/
|
|
69
|
+
projectId: z.string().optional(),
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* The entries whose process is still running, lowest port first.
|
|
73
|
+
*
|
|
74
|
+
* Liveness is checked rather than trusted for the same reason the daemon registry checks it: a dev
|
|
75
|
+
* server killed with SIGKILL runs no cleanup, so its file outlives it. A stale entry read as live is
|
|
76
|
+
* worse than no entry at all — it reports a running, instrumented app over a dead port, and sends
|
|
77
|
+
* the reader to look at their browser instead of at their terminal.
|
|
78
|
+
*
|
|
79
|
+
* Pure, so both the CLI and the plugins share one rule and it is testable without real processes.
|
|
80
|
+
*/
|
|
81
|
+
/**
|
|
82
|
+
* The live entries that belong to THIS project.
|
|
83
|
+
*
|
|
84
|
+
* Scoping is not a refinement here, it is the difference between a diagnosis and a wrong answer. A
|
|
85
|
+
* dev server registry is machine-wide — one directory holds every app on the box — so "a dev server
|
|
86
|
+
* is running" is satisfied by somebody else's app, by another package in the same monorepo, by
|
|
87
|
+
* yesterday's terminal. Reported unscoped, `init` for app A told the user their dev server was wired
|
|
88
|
+
* and handed them app B's URL: confident, specific, and about a project they were not setting up.
|
|
89
|
+
*
|
|
90
|
+
* Two ways to belong, because both are true and neither covers the other:
|
|
91
|
+
*
|
|
92
|
+
* - the projectId matches, which is exact and survives a moved directory
|
|
93
|
+
* - the entry's root is the directory being set up, or inside it, which is what makes `init` at a
|
|
94
|
+
* monorepo root see the apps underneath it — they genuinely are its apps
|
|
95
|
+
*
|
|
96
|
+
* With neither known nothing matches, and the caller gets the same less specific answer it had
|
|
97
|
+
* before. That is the conservative direction on purpose: a missed match costs one vaguer sentence,
|
|
98
|
+
* a wrong match sends somebody to another team's app.
|
|
99
|
+
*/
|
|
100
|
+
export function devServersForProject(entries, scope) {
|
|
101
|
+
const { projectId, root } = scope;
|
|
102
|
+
if ((projectId === undefined || 0 === projectId.length) &&
|
|
103
|
+
(root === undefined || 0 === root.length)) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
return entries.filter((e) => (projectId !== undefined && 0 < projectId.length && e.projectId === projectId) ||
|
|
107
|
+
isWithin(e.root, root));
|
|
108
|
+
}
|
|
109
|
+
/** `path` is `base`, or sits under it. Separator-aware, so `/repo/app2` is not inside `/repo/app`. */
|
|
110
|
+
function isWithin(path, base) {
|
|
111
|
+
if (base === undefined || 0 === base.length)
|
|
112
|
+
return false;
|
|
113
|
+
const norm = (p) => p.split('\\').join('/').replace(/\/+$/, '');
|
|
114
|
+
const target = norm(path);
|
|
115
|
+
const parent = norm(base);
|
|
116
|
+
return target === parent || target.startsWith(`${parent}/`);
|
|
117
|
+
}
|
|
118
|
+
export function liveDevServers(entries, isAlive) {
|
|
119
|
+
return entries.filter((e) => isAlive(e.pid)).sort((a, b) => a.port - b.port);
|
|
120
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which document an observation belongs to.
|
|
3
|
+
*
|
|
4
|
+
* Evidence used to be scoped by time and by ring-buffer capacity and by nothing else. A request
|
|
5
|
+
* observed under a PREVIOUS document — or under a previous run of the application entirely — could
|
|
6
|
+
* therefore be counted against an action taken now. Field reports describe exactly that, including
|
|
7
|
+
* one where the failing request Reticle cited named a database row that no longer exists: true about
|
|
8
|
+
* the bytes, false about the world, which is the worst kind of wrong a verification tool can be.
|
|
9
|
+
*
|
|
10
|
+
* A document id is minted once per real document and dies with it. A full navigation replaces the
|
|
11
|
+
* document and so replaces the id. An SPA route change does NOT, which is correct rather than a
|
|
12
|
+
* limitation: same JavaScript context, same in-flight requests, same evidence.
|
|
13
|
+
*
|
|
14
|
+
* This lives in `core` because it crosses the wire, and every wire value is defined here.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Long enough not to collide within a session, short enough to stamp on every event.
|
|
18
|
+
*
|
|
19
|
+
* The cost is paid thousands of times per session, so this is a deliberate trade rather than a
|
|
20
|
+
* default: eight base-36 characters is a little over forty bits, against a population of at most a
|
|
21
|
+
* handful of documents per session. Collisions are not the risk being managed here; wire weight is.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DOCUMENT_ID_LENGTH = 8;
|
|
24
|
+
/**
|
|
25
|
+
* Mint an id for the current document.
|
|
26
|
+
*
|
|
27
|
+
* `random` is injected for the same reason the clock is: a generator that reaches for `Math.random()`
|
|
28
|
+
* cannot be unit-tested and cannot be replayed, and this repo forbids both.
|
|
29
|
+
*/
|
|
30
|
+
export declare function newDocumentId(random: () => number): string;
|
|
31
|
+
/**
|
|
32
|
+
* Does this evidence belong to the document currently under observation?
|
|
33
|
+
*
|
|
34
|
+
* **Unstamped evidence counts as current.** An SDK older than this field stamps nothing, and
|
|
35
|
+
* excluding it would make those installations silently stop reporting real contradictions. A
|
|
36
|
+
* verification tool that quietly finds nothing is far worse than one that occasionally over-reports,
|
|
37
|
+
* and this change exists to remove quietly-wrong answers rather than to trade one kind for another.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isSameDocument(evidenceDocumentId: string | undefined, currentDocumentId: string | undefined): boolean;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which document an observation belongs to.
|
|
3
|
+
*
|
|
4
|
+
* Evidence used to be scoped by time and by ring-buffer capacity and by nothing else. A request
|
|
5
|
+
* observed under a PREVIOUS document — or under a previous run of the application entirely — could
|
|
6
|
+
* therefore be counted against an action taken now. Field reports describe exactly that, including
|
|
7
|
+
* one where the failing request Reticle cited named a database row that no longer exists: true about
|
|
8
|
+
* the bytes, false about the world, which is the worst kind of wrong a verification tool can be.
|
|
9
|
+
*
|
|
10
|
+
* A document id is minted once per real document and dies with it. A full navigation replaces the
|
|
11
|
+
* document and so replaces the id. An SPA route change does NOT, which is correct rather than a
|
|
12
|
+
* limitation: same JavaScript context, same in-flight requests, same evidence.
|
|
13
|
+
*
|
|
14
|
+
* This lives in `core` because it crosses the wire, and every wire value is defined here.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Long enough not to collide within a session, short enough to stamp on every event.
|
|
18
|
+
*
|
|
19
|
+
* The cost is paid thousands of times per session, so this is a deliberate trade rather than a
|
|
20
|
+
* default: eight base-36 characters is a little over forty bits, against a population of at most a
|
|
21
|
+
* handful of documents per session. Collisions are not the risk being managed here; wire weight is.
|
|
22
|
+
*/
|
|
23
|
+
export const DOCUMENT_ID_LENGTH = 8;
|
|
24
|
+
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
25
|
+
/**
|
|
26
|
+
* Mint an id for the current document.
|
|
27
|
+
*
|
|
28
|
+
* `random` is injected for the same reason the clock is: a generator that reaches for `Math.random()`
|
|
29
|
+
* cannot be unit-tested and cannot be replayed, and this repo forbids both.
|
|
30
|
+
*/
|
|
31
|
+
export function newDocumentId(random) {
|
|
32
|
+
let out = '';
|
|
33
|
+
for (let i = 0; i < DOCUMENT_ID_LENGTH; i++) {
|
|
34
|
+
const pick = Math.floor(random() * ALPHABET.length);
|
|
35
|
+
// A generator returning exactly 1 (or a rounding artefact at the top of the range) would index
|
|
36
|
+
// past the end and produce `undefined` in the string. Clamp rather than trust the caller.
|
|
37
|
+
out += ALPHABET[Math.min(Math.max(pick, 0), ALPHABET.length - 1)];
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Does this evidence belong to the document currently under observation?
|
|
43
|
+
*
|
|
44
|
+
* **Unstamped evidence counts as current.** An SDK older than this field stamps nothing, and
|
|
45
|
+
* excluding it would make those installations silently stop reporting real contradictions. A
|
|
46
|
+
* verification tool that quietly finds nothing is far worse than one that occasionally over-reports,
|
|
47
|
+
* and this change exists to remove quietly-wrong answers rather than to trade one kind for another.
|
|
48
|
+
*/
|
|
49
|
+
export function isSameDocument(evidenceDocumentId, currentDocumentId) {
|
|
50
|
+
if (undefined === evidenceDocumentId || undefined === currentDocumentId)
|
|
51
|
+
return true;
|
|
52
|
+
return evidenceDocumentId === currentDocumentId;
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which round of source edits an observation belongs to.
|
|
3
|
+
*
|
|
4
|
+
* `document-identity` scopes evidence to the DOCUMENT it was recorded under, because a navigation
|
|
5
|
+
* throws the page away and takes the truth of everything observed under it with it. This is the same
|
|
6
|
+
* problem for EDITS, and the document id cannot see it: a hot update swaps modules and re-renders
|
|
7
|
+
* inside the same document, so the id never moves. The agent that Reticle is increasingly driven by
|
|
8
|
+
* edits source and re-verifies in a loop — so it routinely reads observations describing code it has
|
|
9
|
+
* already replaced, and refs minted against nodes the framework has already thrown away.
|
|
10
|
+
*
|
|
11
|
+
* An epoch is a counter that advances once per applied hot update. It is NOT a clock and NOT an
|
|
12
|
+
* identity: only the ordering matters, and only within one document (a navigation mints a new
|
|
13
|
+
* document, and a new SDK instance starts the count again — which is correct, because the document
|
|
14
|
+
* scoping already excludes everything from before it).
|
|
15
|
+
*
|
|
16
|
+
* This lives in `core` because it crosses the wire, and every wire value is defined here.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The epoch of a page in which no hot update has been observed.
|
|
20
|
+
*
|
|
21
|
+
* ABSENCE OF EVIDENCE, NOT EVIDENCE OF ABSENCE. Most pages Reticle instruments have no channel that
|
|
22
|
+
* can report a hot update at all — Next, Electron, Tauri, a plain script tag — and a Vite page has
|
|
23
|
+
* none until the first update arrives. So this value means "no edits observed", never "no edits
|
|
24
|
+
* happened", and nothing may be excluded or accused on the strength of it.
|
|
25
|
+
*/
|
|
26
|
+
export declare const NO_EDITS_OBSERVED = 0;
|
|
27
|
+
/**
|
|
28
|
+
* Was this evidence recorded under the edit epoch currently in force?
|
|
29
|
+
*
|
|
30
|
+
* **Unstamped evidence counts as current**, following `isSameDocument` exactly rather than inventing
|
|
31
|
+
* a stricter rule beside it. An SDK older than this field stamps nothing, and so does a perfectly
|
|
32
|
+
* current SDK in a page with no hot-update channel. Reading either as foreign would make those
|
|
33
|
+
* installations silently stop reporting real contradictions, and a verification tool that quietly
|
|
34
|
+
* finds nothing is worse than one that occasionally over-reports.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isSameEditEpoch(evidenceEpoch: number | undefined, currentEpoch: number | undefined): boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which round of source edits an observation belongs to.
|
|
3
|
+
*
|
|
4
|
+
* `document-identity` scopes evidence to the DOCUMENT it was recorded under, because a navigation
|
|
5
|
+
* throws the page away and takes the truth of everything observed under it with it. This is the same
|
|
6
|
+
* problem for EDITS, and the document id cannot see it: a hot update swaps modules and re-renders
|
|
7
|
+
* inside the same document, so the id never moves. The agent that Reticle is increasingly driven by
|
|
8
|
+
* edits source and re-verifies in a loop — so it routinely reads observations describing code it has
|
|
9
|
+
* already replaced, and refs minted against nodes the framework has already thrown away.
|
|
10
|
+
*
|
|
11
|
+
* An epoch is a counter that advances once per applied hot update. It is NOT a clock and NOT an
|
|
12
|
+
* identity: only the ordering matters, and only within one document (a navigation mints a new
|
|
13
|
+
* document, and a new SDK instance starts the count again — which is correct, because the document
|
|
14
|
+
* scoping already excludes everything from before it).
|
|
15
|
+
*
|
|
16
|
+
* This lives in `core` because it crosses the wire, and every wire value is defined here.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The epoch of a page in which no hot update has been observed.
|
|
20
|
+
*
|
|
21
|
+
* ABSENCE OF EVIDENCE, NOT EVIDENCE OF ABSENCE. Most pages Reticle instruments have no channel that
|
|
22
|
+
* can report a hot update at all — Next, Electron, Tauri, a plain script tag — and a Vite page has
|
|
23
|
+
* none until the first update arrives. So this value means "no edits observed", never "no edits
|
|
24
|
+
* happened", and nothing may be excluded or accused on the strength of it.
|
|
25
|
+
*/
|
|
26
|
+
export const NO_EDITS_OBSERVED = 0;
|
|
27
|
+
/**
|
|
28
|
+
* Was this evidence recorded under the edit epoch currently in force?
|
|
29
|
+
*
|
|
30
|
+
* **Unstamped evidence counts as current**, following `isSameDocument` exactly rather than inventing
|
|
31
|
+
* a stricter rule beside it. An SDK older than this field stamps nothing, and so does a perfectly
|
|
32
|
+
* current SDK in a page with no hot-update channel. Reading either as foreign would make those
|
|
33
|
+
* installations silently stop reporting real contradictions, and a verification tool that quietly
|
|
34
|
+
* finds nothing is worse than one that occasionally over-reports.
|
|
35
|
+
*/
|
|
36
|
+
export function isSameEditEpoch(evidenceEpoch, currentEpoch) {
|
|
37
|
+
if (undefined === evidenceEpoch || undefined === currentEpoch)
|
|
38
|
+
return true;
|
|
39
|
+
return evidenceEpoch === currentEpoch;
|
|
40
|
+
}
|
package/dist/event-payloads.d.ts
CHANGED
|
@@ -46,10 +46,17 @@ export declare const ScrollDirection: {
|
|
|
46
46
|
readonly DOWN: "down";
|
|
47
47
|
};
|
|
48
48
|
export type ScrollDirection = (typeof ScrollDirection)[keyof typeof ScrollDirection];
|
|
49
|
+
/**
|
|
50
|
+
* The three readable client-side storage areas.
|
|
51
|
+
*
|
|
52
|
+
* `cookies` is plural because that is what the storage tool accepts, what the browser returns and
|
|
53
|
+
* what the docs publish. This member read `cookie` for as long as it had no callers, which is
|
|
54
|
+
* exactly how long a name can disagree with every use of it for free.
|
|
55
|
+
*/
|
|
49
56
|
export declare const StorageArea: {
|
|
50
57
|
readonly LOCAL: "local";
|
|
51
58
|
readonly SESSION: "session";
|
|
52
|
-
readonly COOKIE: "
|
|
59
|
+
readonly COOKIE: "cookies";
|
|
53
60
|
};
|
|
54
61
|
export type StorageArea = (typeof StorageArea)[keyof typeof StorageArea];
|
|
55
62
|
/**
|
|
@@ -108,6 +115,7 @@ export declare const EVENT_PAYLOAD_SCHEMAS: {
|
|
|
108
115
|
ok: z.ZodBoolean;
|
|
109
116
|
durationMs: z.ZodNumber;
|
|
110
117
|
initiator: z.ZodString;
|
|
118
|
+
urlRaw: z.ZodOptional<z.ZodString>;
|
|
111
119
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
112
120
|
id: z.ZodString;
|
|
113
121
|
method: z.ZodString;
|
|
@@ -116,6 +124,7 @@ export declare const EVENT_PAYLOAD_SCHEMAS: {
|
|
|
116
124
|
ok: z.ZodBoolean;
|
|
117
125
|
durationMs: z.ZodNumber;
|
|
118
126
|
initiator: z.ZodString;
|
|
127
|
+
urlRaw: z.ZodOptional<z.ZodString>;
|
|
119
128
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
120
129
|
id: z.ZodString;
|
|
121
130
|
method: z.ZodString;
|
|
@@ -124,22 +133,26 @@ export declare const EVENT_PAYLOAD_SCHEMAS: {
|
|
|
124
133
|
ok: z.ZodBoolean;
|
|
125
134
|
durationMs: z.ZodNumber;
|
|
126
135
|
initiator: z.ZodString;
|
|
136
|
+
urlRaw: z.ZodOptional<z.ZodString>;
|
|
127
137
|
}, z.ZodTypeAny, "passthrough">>;
|
|
128
138
|
"net.pending": z.ZodObject<{
|
|
129
139
|
id: z.ZodString;
|
|
130
140
|
method: z.ZodString;
|
|
131
141
|
url: z.ZodString;
|
|
132
142
|
initiator: z.ZodString;
|
|
143
|
+
urlRaw: z.ZodOptional<z.ZodString>;
|
|
133
144
|
}, "strip", z.ZodTypeAny, {
|
|
134
145
|
url: string;
|
|
135
146
|
id: string;
|
|
136
147
|
method: string;
|
|
137
148
|
initiator: string;
|
|
149
|
+
urlRaw?: string | undefined;
|
|
138
150
|
}, {
|
|
139
151
|
url: string;
|
|
140
152
|
id: string;
|
|
141
153
|
method: string;
|
|
142
154
|
initiator: string;
|
|
155
|
+
urlRaw?: string | undefined;
|
|
143
156
|
}>;
|
|
144
157
|
"net.stream": z.ZodObject<{
|
|
145
158
|
transport: z.ZodNativeEnum<{
|
|
@@ -367,18 +380,18 @@ export declare const EVENT_PAYLOAD_SCHEMAS: {
|
|
|
367
380
|
area: z.ZodNativeEnum<{
|
|
368
381
|
readonly LOCAL: "local";
|
|
369
382
|
readonly SESSION: "session";
|
|
370
|
-
readonly COOKIE: "
|
|
383
|
+
readonly COOKIE: "cookies";
|
|
371
384
|
}>;
|
|
372
385
|
key: z.ZodString;
|
|
373
386
|
old: z.ZodOptional<z.ZodString>;
|
|
374
387
|
new: z.ZodOptional<z.ZodString>;
|
|
375
388
|
}, "strip", z.ZodTypeAny, {
|
|
376
|
-
area: "local" | "session" | "
|
|
389
|
+
area: "local" | "session" | "cookies";
|
|
377
390
|
key: string;
|
|
378
391
|
old?: string | undefined;
|
|
379
392
|
new?: string | undefined;
|
|
380
393
|
}, {
|
|
381
|
-
area: "local" | "session" | "
|
|
394
|
+
area: "local" | "session" | "cookies";
|
|
382
395
|
key: string;
|
|
383
396
|
old?: string | undefined;
|
|
384
397
|
new?: string | undefined;
|
|
@@ -444,6 +457,13 @@ export declare const EVENT_PAYLOAD_SCHEMAS: {
|
|
|
444
457
|
readonly OTHER: "other";
|
|
445
458
|
}>>;
|
|
446
459
|
}, z.ZodTypeAny, "passthrough">>;
|
|
460
|
+
"context.opened": z.ZodObject<{
|
|
461
|
+
href: z.ZodOptional<z.ZodString>;
|
|
462
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
463
|
+
href: z.ZodOptional<z.ZodString>;
|
|
464
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
465
|
+
href: z.ZodOptional<z.ZodString>;
|
|
466
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
447
467
|
"render.commit": z.ZodObject<{
|
|
448
468
|
commits: z.ZodNumber;
|
|
449
469
|
}, "strip", z.ZodTypeAny, {
|
package/dist/event-payloads.js
CHANGED
|
@@ -34,7 +34,14 @@ export const StreamTransport = { SSE: 'sse', WS: 'ws', FETCH: 'fetch' };
|
|
|
34
34
|
/** `CLOSE` pairs with `OPEN`: until it arrives, the body is still being written. */
|
|
35
35
|
export const StreamDirection = { OPEN: 'open', IN: 'in', OUT: 'out', CLOSE: 'close' };
|
|
36
36
|
export const ScrollDirection = { UP: 'up', DOWN: 'down' };
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The three readable client-side storage areas.
|
|
39
|
+
*
|
|
40
|
+
* `cookies` is plural because that is what the storage tool accepts, what the browser returns and
|
|
41
|
+
* what the docs publish. This member read `cookie` for as long as it had no callers, which is
|
|
42
|
+
* exactly how long a name can disagree with every use of it for free.
|
|
43
|
+
*/
|
|
44
|
+
export const StorageArea = { LOCAL: 'local', SESSION: 'session', COOKIE: 'cookies' };
|
|
38
45
|
const elementLabel = z.object({ role: z.string().optional(), name: z.string().optional() });
|
|
39
46
|
/**
|
|
40
47
|
* A file the app produced. `preview`/`lines` are present only when body capture is on, for the same
|
|
@@ -66,6 +73,7 @@ const netRequestSchema = z
|
|
|
66
73
|
ok: z.boolean(),
|
|
67
74
|
durationMs: z.number(),
|
|
68
75
|
initiator: z.string(),
|
|
76
|
+
urlRaw: z.string().optional(),
|
|
69
77
|
})
|
|
70
78
|
.passthrough();
|
|
71
79
|
const consoleSchema = z.object({ message: z.string() }).passthrough();
|
|
@@ -86,6 +94,7 @@ export const EVENT_PAYLOAD_SCHEMAS = {
|
|
|
86
94
|
method: z.string(),
|
|
87
95
|
url: z.string(),
|
|
88
96
|
initiator: z.string(),
|
|
97
|
+
urlRaw: z.string().optional(),
|
|
89
98
|
}),
|
|
90
99
|
[EventType.NET_STREAM]: netStreamSchema,
|
|
91
100
|
[EventType.DOWNLOAD]: downloadSchema,
|
|
@@ -145,6 +154,9 @@ export const EVENT_PAYLOAD_SCHEMAS = {
|
|
|
145
154
|
brand: z.nativeEnum(BrowserBrand).optional(),
|
|
146
155
|
})
|
|
147
156
|
.passthrough(),
|
|
157
|
+
// The page called window.open — the clicked consequence may continue in a context the SDK cannot
|
|
158
|
+
// enter (#508). `href` is what the page asked to open, omitted for the blank-tab form.
|
|
159
|
+
[EventType.CONTEXT_OPENED]: z.object({ href: z.string().optional() }).passthrough(),
|
|
148
160
|
[EventType.RENDER_COMMIT]: z.object({ commits: z.number() }),
|
|
149
161
|
[EventType.FOCUS_CHANGE]: z.object({
|
|
150
162
|
to: z.string().optional(),
|