@reticlehq/vite-plugin 2.14.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -47,13 +47,13 @@ __export(index_exports, {
47
47
  module.exports = __toCommonJS(index_exports);
48
48
  var import_node_fs6 = require("node:fs");
49
49
 
50
- // src/missing-token.ts
50
+ // src/token/missing-token.ts
51
51
  function missingTokenWarning(token) {
52
52
  if (token !== void 0 && token.length > 0) return void 0;
53
53
  return "[reticle] no pairing token was available when this dev server started, so the app will connect and be refused \u2014 you will see NO SESSION even though the SDK loads and the socket opens. The token is written by the Reticle daemon: start it (`reticle serve`, or let your agent start it) and then RESTART this dev server, because the value is inlined at config time.";
54
54
  }
55
55
 
56
- // src/ensure-token.ts
56
+ // src/token/ensure-token.ts
57
57
  var import_node_fs = require("node:fs");
58
58
  var import_node_crypto = require("node:crypto");
59
59
  var import_node_path = require("node:path");
@@ -83,313 +83,7 @@ var import_node_path8 = require("node:path");
83
83
  var import_core6 = require("@babel/core");
84
84
  var import_babel_plugin = __toESM(require("@reticlehq/babel-plugin"), 1);
85
85
 
86
- // ../core/dist/constants.js
87
- var RETICLE_DEFAULT_PORT = 4400;
88
- var RETICLE_WS_PATH = "/reticle";
89
- var RETICLE_CLIENT_HOST = "localhost";
90
- function bridgeWsUrl(port = RETICLE_DEFAULT_PORT, host = RETICLE_CLIENT_HOST) {
91
- return `ws://${host}:${String(port)}${RETICLE_WS_PATH}`;
92
- }
93
- var ReticleEnv = {
94
- /** Shared-secret the browser SDK must present in HELLO; absent ⇒ loopback-trust only. */
95
- TOKEN: "RETICLE_TOKEN",
96
- /** Bridge bind host. Defaults to loopback; setting anything else is opt-in remote exposure. */
97
- HOST: "RETICLE_HOST",
98
- /** Comma-separated WS Origin allow-list for the bridge. */
99
- ALLOWED_ORIGINS: "RETICLE_ALLOWED_ORIGINS",
100
- /** Bridge/daemon WS port override. */
101
- PORT: "RETICLE_PORT",
102
- /** Daemon state — pidfiles, discovery registry, logs. Defaults to `~/.reticle`. Overridable
103
- * because a read-only $HOME (sandboxed agent, locked-down Windows profile, container) otherwise
104
- * makes the daemon unstartable with a raw EACCES naming nothing. Reported by a Windows user. */
105
- STATE_DIR: "RETICLE_STATE_DIR",
106
- /** Attach to an already-running browser over CDP instead of launching one. */
107
- CDP_URL: "RETICLE_CDP_URL",
108
- /** Max simultaneous leased headless contexts in the browser pool (resource cap). */
109
- MAX_CONTEXTS: "RETICLE_MAX_CONTEXTS",
110
- /**
111
- * Inbound events per second before the bridge starts SAMPLING (never disconnecting).
112
- *
113
- * Raise it for a legitimately busy app — a streaming dashboard, a live grid — rather than accept
114
- * partial coverage. Free and local: the daemon runs on the same machine, so a higher ceiling costs
115
- * nothing to anyone.
116
- */
117
- MAX_MESSAGES_PER_SECOND: "RETICLE_MAX_MESSAGES_PER_SECOND",
118
- /** Bearer token required by the optional `reticle serve --http` verify endpoint. */
119
- VERIFY_TOKEN: "RETICLE_VERIFY_TOKEN",
120
- /** Ms of continuous idleness (no agent, no browser session, no lease) before the daemon self-exits;
121
- * `0` disables. Keeps Reticle from lingering on a user's machine after the editor closes. */
122
- IDLE_SHUTDOWN: "RETICLE_IDLE_SHUTDOWN_MS",
123
- /** Idle re-check cadence (default 30s). Overridable so daemon-lifecycle-test can watch a full
124
- * exit/wake cycle in seconds rather than minutes. */
125
- IDLE_CHECK: "RETICLE_IDLE_CHECK_MS",
126
- /**
127
- * Grace for a daemon with an agent ATTACHED. Longer than the base on purpose: quiet with a client
128
- * present means a slow install or a thinking human, not an unwanted daemon — a flat 5 minutes was
129
- * killing live runs mid-install. Derived from the base when unset.
130
- */
131
- IDLE_ATTACHED: "RETICLE_IDLE_ATTACHED_MS",
132
- /**
133
- * How often the daemon writes `reticle_daemon_alive`, so a GAP in its log is evidence it died.
134
- *
135
- * Overridable for the same reason the idle windows are: a spec that has to prove "a killed daemon
136
- * is distinguishable from a tidy one" cannot wait 30 seconds per beat, and a spec that instead
137
- * re-implements the cadence is insensitive to the thing it claims to guard.
138
- */
139
- HEARTBEAT: "RETICLE_HEARTBEAT_MS",
140
- /** Directory holding the auto-provisioned pairing token. Defaults to ~/.reticle; relocatable for CI. */
141
- PAIRING_TOKEN_DIR: "RETICLE_PAIRING_TOKEN_DIR",
142
- /** Force the durable causal journal off (`0`/`false`/`off`) or on (`1`/`true`/`on`); default on. */
143
- JOURNAL: "RETICLE_JOURNAL",
144
- /**
145
- * Verbose internal flow tracing for people working ON Reticle (`1`/`true`/`on`); default off.
146
- *
147
- * Distinct from the journal, which records what the AGENT did to the app. This records what
148
- * RETICLE did to answer it: one line per internal stage, with its duration and nesting, so a
149
- * developer can see which code a tool call actually went through and where the time went.
150
- * Off by default and free when off — a trace on every tool call is a cost on the hot path.
151
- */
152
- TRACE: "RETICLE_TRACE",
153
- /**
154
- * How many consecutive reconnects the MCP proxy attempts before it stops retrying and goes
155
- * dormant. Overridable for the same reason the idle windows are: the real budget takes MINUTES to
156
- * exhaust, so the one spec that proves the proxy SURVIVES exhaustion could not run at all without
157
- * shortening it. A budget nobody can reach in a test is a budget nobody tests.
158
- */
159
- RECONNECT_ATTEMPTS: "RETICLE_RECONNECT_ATTEMPTS",
160
- /** Quiet window before an abandoned MCP stdio proxy exits; `0` disables the watcher. */
161
- MCP_PROXY_IDLE: "RETICLE_MCP_PROXY_IDLE_MS"
162
- };
163
- var TRANSPORT_LIMITS = {
164
- MAX_MESSAGE_BYTES: 1024 * 1024,
165
- /**
166
- * Inbound events per second before the bridge SAMPLES rather than records everything.
167
- *
168
- * This was 1000, and an ordinary React app with an active query cache blew through it: the
169
- * reporter's FIRST `act_and_wait` of the session came back `unknown` with `unclean_capture` and a
170
- * four-figure drop count, and setting the env override to twenty times the default fixed it (#316).
171
- * Reticle was right to refuse the verdict — a sampled window cannot support one, and the guard that
172
- * catches false greens is blindest exactly there — but landing that on the first drive after an
173
- * install, recoverable only by knowing an environment variable exists and inventing a number for
174
- * it, is the worst possible place to spend the honesty.
175
- *
176
- * 20000 is the value that was measured to work on the page that reported it. The cap exists to stop
177
- * a PATHOLOGICAL page (an animation loop firing DOM mutations every frame), not to throttle a busy
178
- * one, and the ceiling it has to defend is cheap: the daemon is on the same machine and a typical
179
- * event is a few hundred bytes, so this is single-digit MB/s over loopback.
180
- *
181
- * Raising it does not raise what a runaway page can make the bridge HOLD, and that separation is
182
- * what makes the change safe. Memory is bounded independently by the ring buffer, which evicts on
183
- * `RING_BUFFER_DEFAULTS.MAX_BYTES` (this same constant, reached through that alias) as well as on
184
- * a count and an age. Grep for `MAX_BUFFER_BYTES` alone and it looks like a constant nobody reads,
185
- * which is exactly the wrong conclusion to draw before touching this number: the rate cap defends
186
- * parse cost, the ring buffer defends memory, and they are not substitutes.
187
- */
188
- MAX_MESSAGES_PER_SECOND: 2e4,
189
- MAX_SESSIONS: 32,
190
- MAX_PENDING_CONNECTIONS: 16,
191
- HELLO_TIMEOUT_MS: 5e3,
192
- MAX_BUFFER_BYTES: 8 * 1024 * 1024,
193
- MAX_SESSION_ID_LENGTH: 128,
194
- MAX_URL_LENGTH: 4096,
195
- MAX_TITLE_LENGTH: 512,
196
- MAX_ADAPTERS: 32,
197
- MAX_ADAPTER_NAME_LENGTH: 128,
198
- MAX_TOKEN_LENGTH: 512,
199
- MAX_COMMAND_ID_LENGTH: 128,
200
- MAX_COMMAND_NAME_LENGTH: 128,
201
- MAX_REF_LENGTH: 128,
202
- MAX_ERROR_LENGTH: 4096,
203
- /** Cap on a captured stack trace before it crosses the wire — the console observer and both React
204
- * error hooks (error-boundary, hydration-error) all truncate to this, so it is one fact. */
205
- MAX_STACK_LENGTH: 4e3,
206
- MAX_SERIALIZE_DEPTH: 8,
207
- MAX_COLLECTION_ITEMS: 200,
208
- MAX_OBJECT_KEYS: 200,
209
- MAX_STRING_LENGTH: 64 * 1024,
210
- /** Human review marks: the note the human types when flagging a mistake on the page. */
211
- MAX_MARK_NOTE_LENGTH: 2e3,
212
- /** Human review marks: the legible element label that pins the mark (e.g. "Submit button"). */
213
- MAX_MARK_LABEL_LENGTH: 256
214
- };
215
- var ReticleDir = {
216
- ROOT: ".reticle",
217
- CONTRACT_FILE: "contract.json",
218
- FLOWS_SUBDIR: "flows",
219
- BASELINES_SUBDIR: "baselines",
220
- /** cross-run memory — outcomes of past runs (the "did it behave like last time?" file). */
221
- PROJECT_FILE: "project.json",
222
- /**
223
- * the user's own record of what Reticle has done for them — .reticle/impact.json.
224
- *
225
- * Local only, never uploaded, and deliberately NOT part of telemetry: telemetry answers our
226
- * questions about the product; this answers the user's question about their own work.
227
- */
228
- IMPACT_FILE: "impact.json",
229
- /** what changes were SUPPOSED to make true —.reticle/intent.json (git-checked, reviewed) */
230
- INTENT_FILE: "intent.json",
231
- /** opt-in pixel baselines —.reticle/visual/<name>.png + <name>.diff.png. */
232
- VISUAL_SUBDIR: "visual",
233
- /** verification-run artifacts —.reticle/runs/<runId>.json (the OEM/CI-consumable verdict). */
234
- RUNS_SUBDIR: "runs",
235
- /** fail-to-pass bug capsules —.reticle/capsules/<id>.json (a minimal failing flow + its evidence). */
236
- CAPSULES_SUBDIR: "capsules",
237
- /** durable causal journal —.reticle/sessions/<id>/{events,actions}.jsonl (the substrate). */
238
- SESSIONS_SUBDIR: "sessions",
239
- /** append-only event ledger inside a session dir (one ReticleEvent per line). */
240
- JOURNAL_EVENTS_FILE: "events.jsonl",
241
- /** append-only action ledger inside a session dir (one JournalAction per line). */
242
- JOURNAL_ACTIONS_FILE: "actions.jsonl",
243
- /** learned expected-envelopes per route, accumulated across runs (the deviation-report baseline). */
244
- ENVELOPES_FILE: "envelopes.json",
245
- /** learned ambient (action-less churn) region map — excluded from settle/summaries/envelopes. */
246
- AMBIENT_FILE: "ambient.json",
247
- /** per-flow flake ledger — replay outcomes that decide intermittent-failure quarantine. */
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",
267
- /** Per-flow assertion tiers recorded on each PASSING replay — the gate's anti-downgrade baseline. */
268
- TIERS_FILE: "assertion-tiers.json",
269
- /**
270
- * Auto-provisioned bridge pairing token, stored at ~/.reticle/pairing-token (mode 0600). Written by
271
- * the daemon, read Node-side by the build plugins to inject into connect. A browser sandbox cannot
272
- * read it, so a rogue localhost app can't present it — that's what stops cross-app session hijack.
273
- */
274
- PAIRING_TOKEN_FILE: "pairing-token"
275
- };
276
- var UpdateCheckIntervalMs = 24 * 60 * 60 * 1e3;
277
- var RING_BUFFER_DEFAULTS = {
278
- MAX_EVENTS: 2e3,
279
- MAX_AGE_MS: 6e4,
280
- MAX_BYTES: TRANSPORT_LIMITS.MAX_BUFFER_BYTES
281
- };
282
- var EventType = {
283
- DOM_ADDED: "dom.added",
284
- DOM_REMOVED: "dom.removed",
285
- DOM_ATTR: "dom.attr",
286
- DOM_TEXT: "dom.text",
287
- NET_REQUEST: "net.request",
288
- NET_PENDING: "net.pending",
289
- /** An SSE (EventSource) or WebSocket frame — a message on a long-lived streaming connection. */
290
- NET_STREAM: "net.stream",
291
- /** A web-perf metric a screenshot can't verify: LCP, cumulative layout shift, or a long task. */
292
- PERF: "perf",
293
- ROUTE_CHANGE: "route.change",
294
- CONSOLE_LOG: "console.log",
295
- CONSOLE_WARN: "console.warn",
296
- CONSOLE_ERROR: "console.error",
297
- CONSOLE_INFO: "console.info",
298
- CONSOLE_DEBUG: "console.debug",
299
- ERROR_UNCAUGHT: "error.uncaught",
300
- VISIBLE_SHOWN: "visible.shown",
301
- ANIM_START: "anim.start",
302
- ANIM_END: "anim.end",
303
- SCROLL_POSITION: "scroll.position",
304
- REVEAL_SHOWN: "reveal.shown",
305
- SIGNAL: "signal",
306
- STATE_CHANGE: "state.change",
307
- /** a write to localStorage/sessionStorage/cookies — `data: { area, key, old?, new? }` (values redacted). */
308
- STORAGE_CHANGE: "storage.change",
309
- /** page-level visibility/focus health (distinct from element-level VISIBLE_*). */
310
- PAGE_HEALTH: "page.health",
311
- /**
312
- * synthetic: the page called window.open, so the consequence of what was just clicked may live in
313
- * another browsing context this one cannot observe (an OAuth popup is the archetype).
314
- * `data: { href }` — the URL the page asked to open, when it named one.
315
- */
316
- CONTEXT_OPENED: "context.opened",
317
- /**
318
- * The app opened a native `alert`/`confirm`/`prompt` while Reticle was driving it.
319
- *
320
- * Recorded because Reticle ANSWERS these rather than letting them block — a native dialog halts
321
- * the main thread, and the SDK's own message pump is on that thread, so one `confirm` behind a
322
- * driven click made the tab permanently unresponsive with no recovery from inside the session.
323
- * Answering silently would trade a wedge for an invisible one, so the question the app asked, and
324
- * the answer given, ride out as an event.
325
- */
326
- DIALOG_OPENED: "dialog.opened",
327
- /** aggregated React commits over a throttle window (dev builds) — `data: { commits }`. Commit storms /
328
- * wasted re-renders show up here without a per-render flood. */
329
- RENDER_COMMIT: "render.commit",
330
- /** element focus moved — `data: { to, from, toBody }`. Focus dropping to body after an act is a regression. */
331
- FOCUS_CHANGE: "focus.change",
332
- /** browser → bridge: a human recording compiled in-page. */
333
- FLOW_RECORDED: "flow.recorded",
334
- /** synthetic: browser transport queue overflowed; events were dropped. `data: { dropped: number }`. */
335
- TRANSPORT_OVERFLOW: "transport.overflow",
336
- /**
337
- * synthetic: a per-channel cap truncated a batch (e.g. a DOM mutation flood). `data: { channel, dropped }`.
338
- * Marks downstream rollups/envelopes as built on incomplete data — a ledger that lies at scale is worse
339
- * than no ledger, so truncation is never silent.
340
- */
341
- TRUNCATED: "truncated",
342
- /**
343
- * synthetic: the SDK detected a region it CANNOT observe (a cross-origin iframe, a closed shadow root).
344
- * `data: { kind: BlindSpotKind, count }`. Surfaced on results as `coverage: partial` so a green never
345
- * implies it saw everything.
346
- */
347
- BLIND_SPOT: "blind-spot",
348
- /** synthetic: the SDK ITSELF failed (an observer threw). `data: { site, message, errorType }`.
349
- * Rides the existing bridge — no outbound request. See browser/observers/sdk-failure.ts. */
350
- SDK_FAILED: "sdk.failed",
351
- /**
352
- * synthetic (driven only): CDP/Playwright-authoritative network detail for a response the in-page
353
- * fetch/XHR wrapper also saw — full response headers + authoritative status/mimeType the page-side
354
- * wrapper can't reach. `data: { url, method?, status, headers, resourceType? }`. Merged onto the
355
- * matching in-page NET_REQUEST so the driven view never loses fidelity to an outside-in tool.
356
- */
357
- NET_DETAIL: "net.detail",
358
- /**
359
- * Live-control: browser → bridge. A human acted on the presenter panel.
360
- * `data: { kind: HumanControlKind; text?: string }`. Rides the existing EventMessage.
361
- */
362
- HUMAN_CONTROL: "human.control",
363
- /**
364
- * Human review: browser → bridge. A human pinned a mistake to an element on the running page
365
- * (the "annotate the bug where you see it" loop). `data` narrows to HumanMarkDataSchema — a note
366
- * plus a re-resolvable element anchor (and its source file:line when the framework stamped one) so
367
- * the agent that drains the mark knows exactly which element and which source to fix.
368
- */
369
- HUMAN_MARK: "human.mark",
370
- /**
371
- * The app produced a FILE — a Blob handed to `URL.createObjectURL`, usually saved by clicking an
372
- * anchor with `download`. `data: { filename?, mimeType, bytes, lines?, preview? }`. The one artifact
373
- * class no outside-the-browser tool can inspect: it never crosses the network, so there is no
374
- * request to intercept. See `observers/download.ts` for the defect that motivated it.
375
- */
376
- DOWNLOAD: "download"
377
- };
378
- var RETICLE_RENDER_PREHOOK = "__reticleRenderPreHook";
379
- var CONSOLE_LEVEL_PREFIX = "console.";
380
- var CONSOLE_LEVELS = [
381
- EventType.CONSOLE_LOG,
382
- EventType.CONSOLE_WARN,
383
- EventType.CONSOLE_ERROR,
384
- EventType.CONSOLE_INFO
385
- ].map((type) => type.slice(CONSOLE_LEVEL_PREFIX.length));
386
-
387
- // ../core/dist/source-constants.js
388
- var DATA_RETICLE_SOURCE_ATTR = "data-reticle-source";
389
- var RETICLE_ROOT_GLOBAL = "__RETICLE_ROOT__";
390
- var RETICLE_SDK_VERSION_GLOBAL = "__RETICLE_SDK_VERSION__";
391
-
392
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
86
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
393
87
  var external_exports = {};
394
88
  __export(external_exports, {
395
89
  BRAND: () => BRAND,
@@ -501,7 +195,7 @@ __export(external_exports, {
501
195
  void: () => voidType
502
196
  });
503
197
 
504
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
198
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
505
199
  var util;
506
200
  (function(util2) {
507
201
  util2.assertEqual = (_) => {
@@ -635,7 +329,7 @@ var getParsedType = (data) => {
635
329
  }
636
330
  };
637
331
 
638
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
332
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
639
333
  var ZodIssueCode = util.arrayToEnum([
640
334
  "invalid_type",
641
335
  "invalid_literal",
@@ -753,7 +447,7 @@ ZodError.create = (issues) => {
753
447
  return error;
754
448
  };
755
449
 
756
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
450
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
757
451
  var errorMap = (issue, _ctx) => {
758
452
  let message;
759
453
  switch (issue.code) {
@@ -856,7 +550,7 @@ var errorMap = (issue, _ctx) => {
856
550
  };
857
551
  var en_default = errorMap;
858
552
 
859
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
553
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
860
554
  var overrideErrorMap = en_default;
861
555
  function setErrorMap(map) {
862
556
  overrideErrorMap = map;
@@ -865,7 +559,7 @@ function getErrorMap() {
865
559
  return overrideErrorMap;
866
560
  }
867
561
 
868
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
562
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
869
563
  var makeIssue = (params) => {
870
564
  const { data, path, errorMaps, issueData } = params;
871
565
  const fullPath = [...path, ...issueData.path || []];
@@ -975,14 +669,14 @@ var isDirty = (x) => x.status === "dirty";
975
669
  var isValid = (x) => x.status === "valid";
976
670
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
977
671
 
978
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
672
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
979
673
  var errorUtil;
980
674
  (function(errorUtil2) {
981
675
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
982
676
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
983
677
  })(errorUtil || (errorUtil = {}));
984
678
 
985
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
679
+ // ../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
986
680
  var ParseInputLazyPath = class {
987
681
  constructor(parent, value, path, key) {
988
682
  this._cachedPath = [];
@@ -4339,98 +4033,436 @@ function custom(check, _params = {}, fatal) {
4339
4033
  var late = {
4340
4034
  object: ZodObject.lazycreate
4341
4035
  };
4342
- var ZodFirstPartyTypeKind;
4343
- (function(ZodFirstPartyTypeKind2) {
4344
- ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
4345
- ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
4346
- ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
4347
- ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
4348
- ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
4349
- ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
4350
- ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
4351
- ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
4352
- ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
4353
- ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
4354
- ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
4355
- ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
4356
- ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
4357
- ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
4358
- ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
4359
- ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
4360
- ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4361
- ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
4362
- ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
4363
- ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
4364
- ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
4365
- ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
4366
- ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
4367
- ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
4368
- ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
4369
- ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
4370
- ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
4371
- ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
4372
- ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
4373
- ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
4374
- ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
4375
- ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
4376
- ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4377
- ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4378
- ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4379
- ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
4380
- })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4381
- var instanceOfType = (cls, params = {
4382
- message: `Input not instance of ${cls.name}`
4383
- }) => custom((data) => data instanceof cls, params);
4384
- var stringType = ZodString.create;
4385
- var numberType = ZodNumber.create;
4386
- var nanType = ZodNaN.create;
4387
- var bigIntType = ZodBigInt.create;
4388
- var booleanType = ZodBoolean.create;
4389
- var dateType = ZodDate.create;
4390
- var symbolType = ZodSymbol.create;
4391
- var undefinedType = ZodUndefined.create;
4392
- var nullType = ZodNull.create;
4393
- var anyType = ZodAny.create;
4394
- var unknownType = ZodUnknown.create;
4395
- var neverType = ZodNever.create;
4396
- var voidType = ZodVoid.create;
4397
- var arrayType = ZodArray.create;
4398
- var objectType = ZodObject.create;
4399
- var strictObjectType = ZodObject.strictCreate;
4400
- var unionType = ZodUnion.create;
4401
- var discriminatedUnionType = ZodDiscriminatedUnion.create;
4402
- var intersectionType = ZodIntersection.create;
4403
- var tupleType = ZodTuple.create;
4404
- var recordType = ZodRecord.create;
4405
- var mapType = ZodMap.create;
4406
- var setType = ZodSet.create;
4407
- var functionType = ZodFunction.create;
4408
- var lazyType = ZodLazy.create;
4409
- var literalType = ZodLiteral.create;
4410
- var enumType = ZodEnum.create;
4411
- var nativeEnumType = ZodNativeEnum.create;
4412
- var promiseType = ZodPromise.create;
4413
- var effectsType = ZodEffects.create;
4414
- var optionalType = ZodOptional.create;
4415
- var nullableType = ZodNullable.create;
4416
- var preprocessType = ZodEffects.createWithPreprocess;
4417
- var pipelineType = ZodPipeline.create;
4418
- var ostring = () => stringType().optional();
4419
- var onumber = () => numberType().optional();
4420
- var oboolean = () => booleanType().optional();
4421
- var coerce = {
4422
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4423
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4424
- boolean: ((arg) => ZodBoolean.create({
4425
- ...arg,
4426
- coerce: true
4427
- })),
4428
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4429
- date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4036
+ var ZodFirstPartyTypeKind;
4037
+ (function(ZodFirstPartyTypeKind2) {
4038
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
4039
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
4040
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
4041
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
4042
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
4043
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
4044
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
4045
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
4046
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
4047
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
4048
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
4049
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
4050
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
4051
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
4052
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
4053
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
4054
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4055
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
4056
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
4057
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
4058
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
4059
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
4060
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
4061
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
4062
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
4063
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
4064
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
4065
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
4066
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
4067
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
4068
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
4069
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
4070
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4071
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4072
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4073
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
4074
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4075
+ var instanceOfType = (cls, params = {
4076
+ message: `Input not instance of ${cls.name}`
4077
+ }) => custom((data) => data instanceof cls, params);
4078
+ var stringType = ZodString.create;
4079
+ var numberType = ZodNumber.create;
4080
+ var nanType = ZodNaN.create;
4081
+ var bigIntType = ZodBigInt.create;
4082
+ var booleanType = ZodBoolean.create;
4083
+ var dateType = ZodDate.create;
4084
+ var symbolType = ZodSymbol.create;
4085
+ var undefinedType = ZodUndefined.create;
4086
+ var nullType = ZodNull.create;
4087
+ var anyType = ZodAny.create;
4088
+ var unknownType = ZodUnknown.create;
4089
+ var neverType = ZodNever.create;
4090
+ var voidType = ZodVoid.create;
4091
+ var arrayType = ZodArray.create;
4092
+ var objectType = ZodObject.create;
4093
+ var strictObjectType = ZodObject.strictCreate;
4094
+ var unionType = ZodUnion.create;
4095
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
4096
+ var intersectionType = ZodIntersection.create;
4097
+ var tupleType = ZodTuple.create;
4098
+ var recordType = ZodRecord.create;
4099
+ var mapType = ZodMap.create;
4100
+ var setType = ZodSet.create;
4101
+ var functionType = ZodFunction.create;
4102
+ var lazyType = ZodLazy.create;
4103
+ var literalType = ZodLiteral.create;
4104
+ var enumType = ZodEnum.create;
4105
+ var nativeEnumType = ZodNativeEnum.create;
4106
+ var promiseType = ZodPromise.create;
4107
+ var effectsType = ZodEffects.create;
4108
+ var optionalType = ZodOptional.create;
4109
+ var nullableType = ZodNullable.create;
4110
+ var preprocessType = ZodEffects.createWithPreprocess;
4111
+ var pipelineType = ZodPipeline.create;
4112
+ var ostring = () => stringType().optional();
4113
+ var onumber = () => numberType().optional();
4114
+ var oboolean = () => booleanType().optional();
4115
+ var coerce = {
4116
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4117
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4118
+ boolean: ((arg) => ZodBoolean.create({
4119
+ ...arg,
4120
+ coerce: true
4121
+ })),
4122
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4123
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4124
+ };
4125
+ var NEVER = INVALID;
4126
+
4127
+ // ../../../core/dist/wire/constants/constants.js
4128
+ var RETICLE_DEFAULT_PORT = 4400;
4129
+ var RETICLE_WS_PATH = "/reticle";
4130
+ var RETICLE_CLIENT_HOST = "localhost";
4131
+ function bridgeWsUrl(port = RETICLE_DEFAULT_PORT, host = RETICLE_CLIENT_HOST) {
4132
+ return `ws://${host}:${String(port)}${RETICLE_WS_PATH}`;
4133
+ }
4134
+ var ReticleEnv = {
4135
+ /** Shared-secret the browser SDK must present in HELLO; absent ⇒ loopback-trust only. */
4136
+ TOKEN: "RETICLE_TOKEN",
4137
+ /** Bridge bind host. Defaults to loopback; setting anything else is opt-in remote exposure. */
4138
+ HOST: "RETICLE_HOST",
4139
+ /** Comma-separated WS Origin allow-list for the bridge. */
4140
+ ALLOWED_ORIGINS: "RETICLE_ALLOWED_ORIGINS",
4141
+ /** Bridge/daemon WS port override. */
4142
+ PORT: "RETICLE_PORT",
4143
+ /** Daemon state — pidfiles, discovery registry, logs. Defaults to `~/.reticle`. Overridable
4144
+ * because a read-only $HOME (sandboxed agent, locked-down Windows profile, container) otherwise
4145
+ * makes the daemon unstartable with a raw EACCES naming nothing. Reported by a Windows user. */
4146
+ STATE_DIR: "RETICLE_STATE_DIR",
4147
+ /** Attach to an already-running browser over CDP instead of launching one. */
4148
+ CDP_URL: "RETICLE_CDP_URL",
4149
+ /** Max simultaneous leased headless contexts in the browser pool (resource cap). */
4150
+ MAX_CONTEXTS: "RETICLE_MAX_CONTEXTS",
4151
+ /**
4152
+ * Inbound events per second before the bridge starts SAMPLING (never disconnecting).
4153
+ *
4154
+ * Raise it for a legitimately busy app — a streaming dashboard, a live grid — rather than accept
4155
+ * partial coverage. Free and local: the daemon runs on the same machine, so a higher ceiling costs
4156
+ * nothing to anyone.
4157
+ */
4158
+ MAX_MESSAGES_PER_SECOND: "RETICLE_MAX_MESSAGES_PER_SECOND",
4159
+ /** Bearer token required by the optional `reticle serve --http` verify endpoint. */
4160
+ VERIFY_TOKEN: "RETICLE_VERIFY_TOKEN",
4161
+ /** Ms of continuous idleness (no agent, no browser session, no lease) before the daemon self-exits;
4162
+ * `0` disables. Keeps Reticle from lingering on a user's machine after the editor closes. */
4163
+ IDLE_SHUTDOWN: "RETICLE_IDLE_SHUTDOWN_MS",
4164
+ /** Idle re-check cadence (default 30s). Overridable so daemon-lifecycle-test can watch a full
4165
+ * exit/wake cycle in seconds rather than minutes. */
4166
+ IDLE_CHECK: "RETICLE_IDLE_CHECK_MS",
4167
+ /**
4168
+ * Grace for a daemon with an agent ATTACHED. Longer than the base on purpose: quiet with a client
4169
+ * present means a slow install or a thinking human, not an unwanted daemon — a flat 5 minutes was
4170
+ * killing live runs mid-install. Derived from the base when unset.
4171
+ */
4172
+ IDLE_ATTACHED: "RETICLE_IDLE_ATTACHED_MS",
4173
+ /**
4174
+ * How often the daemon writes `reticle_daemon_alive`, so a GAP in its log is evidence it died.
4175
+ *
4176
+ * Overridable for the same reason the idle windows are: a spec that has to prove "a killed daemon
4177
+ * is distinguishable from a tidy one" cannot wait 30 seconds per beat, and a spec that instead
4178
+ * re-implements the cadence is insensitive to the thing it claims to guard.
4179
+ */
4180
+ HEARTBEAT: "RETICLE_HEARTBEAT_MS",
4181
+ /** Directory holding the auto-provisioned pairing token. Defaults to ~/.reticle; relocatable for CI. */
4182
+ PAIRING_TOKEN_DIR: "RETICLE_PAIRING_TOKEN_DIR",
4183
+ /** Force the durable causal journal off (`0`/`false`/`off`) or on (`1`/`true`/`on`); default on. */
4184
+ JOURNAL: "RETICLE_JOURNAL",
4185
+ /**
4186
+ * Verbose internal flow tracing for people working ON Reticle (`1`/`true`/`on`); default off.
4187
+ *
4188
+ * Distinct from the journal, which records what the AGENT did to the app. This records what
4189
+ * RETICLE did to answer it: one line per internal stage, with its duration and nesting, so a
4190
+ * developer can see which code a tool call actually went through and where the time went.
4191
+ * Off by default and free when off — a trace on every tool call is a cost on the hot path.
4192
+ */
4193
+ TRACE: "RETICLE_TRACE",
4194
+ /**
4195
+ * How many consecutive reconnects the MCP proxy attempts before it stops retrying and goes
4196
+ * dormant. Overridable for the same reason the idle windows are: the real budget takes MINUTES to
4197
+ * exhaust, so the one spec that proves the proxy SURVIVES exhaustion could not run at all without
4198
+ * shortening it. A budget nobody can reach in a test is a budget nobody tests.
4199
+ */
4200
+ RECONNECT_ATTEMPTS: "RETICLE_RECONNECT_ATTEMPTS",
4201
+ /** Quiet window before an abandoned MCP stdio proxy exits; `0` disables the watcher. */
4202
+ MCP_PROXY_IDLE: "RETICLE_MCP_PROXY_IDLE_MS",
4203
+ /**
4204
+ * API key for the harness — the model that drives the app when no coding agent is in the loop.
4205
+ *
4206
+ * The standard Anthropic name, on purpose: a machine that can already run a coding agent can
4207
+ * already run the harness, with nothing to configure. Absent ⇒ the harness is simply unavailable
4208
+ * and every other part of Reticle is unaffected.
4209
+ */
4210
+ HARNESS_KEY: "ANTHROPIC_API_KEY",
4211
+ /** Model the harness drives with. Defaults to a small one — see `DEFAULT_HARNESS_MODEL`. */
4212
+ HARNESS_MODEL: "RETICLE_HARNESS_MODEL",
4213
+ /** Base URL for the harness's model API, for a proxy or a gateway. */
4214
+ HARNESS_BASE_URL: "RETICLE_HARNESS_BASE_URL",
4215
+ /** Hard ceiling on harness model turns in one drive. Bounds cost, not value. */
4216
+ HARNESS_MAX_STEPS: "RETICLE_HARNESS_MAX_STEPS"
4217
+ };
4218
+ var TRANSPORT_LIMITS = {
4219
+ MAX_MESSAGE_BYTES: 1024 * 1024,
4220
+ /**
4221
+ * Inbound events per second before the bridge SAMPLES rather than records everything.
4222
+ *
4223
+ * The cap exists to stop a PATHOLOGICAL page (an animation loop firing DOM mutations every frame),
4224
+ * not to throttle a busy one: an ordinary React app with an active query cache passes 1000/s, and a
4225
+ * sampled window cannot support a verdict, so too low a cap answers `unknown` with
4226
+ * `unclean_capture` on the first `act_and_wait` after an install (#316).
4227
+ *
4228
+ * The ceiling it defends is cheap — the daemon is on the same machine and a typical event is a few
4229
+ * hundred bytes, so 20000/s is single-digit MB/s over loopback. Raising it does not raise what a
4230
+ * runaway page can make the bridge HOLD: memory is bounded independently by the ring buffer, which
4231
+ * evicts on `RING_BUFFER_DEFAULTS.MAX_BYTES` (this same constant through that alias) as well as on
4232
+ * a count and an age. The rate cap defends parse cost, the ring buffer defends memory, and they are
4233
+ * not substitutes.
4234
+ */
4235
+ MAX_MESSAGES_PER_SECOND: 2e4,
4236
+ MAX_SESSIONS: 32,
4237
+ MAX_PENDING_CONNECTIONS: 16,
4238
+ HELLO_TIMEOUT_MS: 5e3,
4239
+ MAX_BUFFER_BYTES: 8 * 1024 * 1024,
4240
+ MAX_SESSION_ID_LENGTH: 128,
4241
+ MAX_URL_LENGTH: 4096,
4242
+ MAX_TITLE_LENGTH: 512,
4243
+ MAX_ADAPTERS: 32,
4244
+ /*
4245
+ * The cap on ONE vocabulary in `contractParts` — the commands, events or actions a peer says it
4246
+ * speaks.
4247
+ *
4248
+ * Its own number, and the reason is an outage this nearly shipped. `contractParts` reused
4249
+ * `MAX_ADAPTERS` (32), and this implementation's own event vocabulary is larger than that. The
4250
+ * field had never had a producer, so nothing had ever tried: the first build to actually send it
4251
+ * had every HELLO rejected by the schema and NO SESSION COULD CONNECT AT ALL. The unit gate is
4252
+ * blind to it — the schema accepts the shape in isolation, and only a real page talking to a real
4253
+ * daemon fails — so the e2e battery is what caught it.
4254
+ *
4255
+ * 128 leaves the vocabularies room to roughly triple. A cap here is still worth having: this
4256
+ * arrives on an unauthenticated HELLO, so it is an untrusted list and the bound is chosen here.
4257
+ */
4258
+ MAX_CONTRACT_NAMES: 128,
4259
+ MAX_ADAPTER_NAME_LENGTH: 128,
4260
+ MAX_TOKEN_LENGTH: 512,
4261
+ MAX_COMMAND_ID_LENGTH: 128,
4262
+ MAX_COMMAND_NAME_LENGTH: 128,
4263
+ MAX_REF_LENGTH: 128,
4264
+ MAX_ERROR_LENGTH: 4096,
4265
+ /** Cap on a captured stack trace before it crosses the wire — the console observer and both React
4266
+ * error hooks (error-boundary, hydration-error) all truncate to this, so it is one fact. */
4267
+ MAX_STACK_LENGTH: 4e3,
4268
+ MAX_SERIALIZE_DEPTH: 8,
4269
+ MAX_COLLECTION_ITEMS: 200,
4270
+ MAX_OBJECT_KEYS: 200,
4271
+ MAX_STRING_LENGTH: 64 * 1024,
4272
+ /** Human review marks: the note the human types when flagging a mistake on the page. */
4273
+ MAX_MARK_NOTE_LENGTH: 2e3,
4274
+ /** Human review marks: the legible element label that pins the mark (e.g. "Submit button"). */
4275
+ MAX_MARK_LABEL_LENGTH: 256
4276
+ };
4277
+ var ReticleDir = {
4278
+ ROOT: ".reticle",
4279
+ CONTRACT_FILE: "contract.json",
4280
+ FLOWS_SUBDIR: "flows",
4281
+ BASELINES_SUBDIR: "baselines",
4282
+ /** cross-run memory — outcomes of past runs (the "did it behave like last time?" file). */
4283
+ PROJECT_FILE: "project.json",
4284
+ /**
4285
+ * the user's own record of what Reticle has done for them — .reticle/impact.json.
4286
+ *
4287
+ * Local only, never uploaded, and deliberately NOT part of telemetry: telemetry answers questions
4288
+ * about the product; this answers the user's question about their own work.
4289
+ */
4290
+ IMPACT_FILE: "impact.json",
4291
+ /** what changes were SUPPOSED to make true —.reticle/intent.json (git-checked, reviewed) */
4292
+ INTENT_FILE: "intent.json",
4293
+ /** opt-in pixel baselines —.reticle/visual/<name>.png + <name>.diff.png. */
4294
+ VISUAL_SUBDIR: "visual",
4295
+ /** verification-run artifacts —.reticle/runs/<runId>.json (the OEM/CI-consumable verdict). */
4296
+ RUNS_SUBDIR: "runs",
4297
+ /** fail-to-pass bug capsules —.reticle/capsules/<id>.json (a minimal failing flow + its evidence). */
4298
+ CAPSULES_SUBDIR: "capsules",
4299
+ /** durable causal journal —.reticle/sessions/<id>/{events,actions}.jsonl (the substrate). */
4300
+ SESSIONS_SUBDIR: "sessions",
4301
+ /** append-only event ledger inside a session dir (one ReticleEvent per line). */
4302
+ JOURNAL_EVENTS_FILE: "events.jsonl",
4303
+ /** append-only action ledger inside a session dir (one JournalAction per line). */
4304
+ JOURNAL_ACTIONS_FILE: "actions.jsonl",
4305
+ /** learned expected-envelopes per route, accumulated across runs (the deviation-report baseline). */
4306
+ ENVELOPES_FILE: "envelopes.json",
4307
+ /** learned ambient (action-less churn) region map — excluded from settle/summaries/envelopes. */
4308
+ AMBIENT_FILE: "ambient.json",
4309
+ /** per-flow flake ledger — replay outcomes that decide intermittent-failure quarantine. */
4310
+ FLAKE_FILE: "flake.json",
4311
+ /**
4312
+ * the project's cloud binding — .reticle/cloud.json, written by `reticle link`. Git-checked and
4313
+ * non-secret: the project id, the API origin, and where its dashboard lives. The KEY lives in
4314
+ * ~/.reticle/credentials.json instead, because that one must never reach a repository.
4315
+ */
4316
+ CLOUD_LINK_FILE: "cloud.json",
4317
+ /**
4318
+ * local sync bookkeeping — .reticle/cloud-state.json. The pull cursor, when each half last ran,
4319
+ * and the last error. NOT git-checked: it describes this machine's conversation with the server,
4320
+ * and committing one machine's cursor would make every other machine skip what it had not seen.
4321
+ */
4322
+ CLOUD_STATE_FILE: "cloud-state.json",
4323
+ /**
4324
+ * triage decisions pulled BACK from the dashboard — .reticle/issues.json. What a human said about
4325
+ * a defect ("resolved", "not a bug"), so the HUD stops showing it and the next run does not
4326
+ * re-report it as though nobody had looked.
4327
+ */
4328
+ ISSUES_FILE: "issues.json",
4329
+ /** Per-flow assertion tiers recorded on each PASSING replay — the gate's anti-downgrade baseline. */
4330
+ TIERS_FILE: "assertion-tiers.json",
4331
+ /**
4332
+ * what to run when something happens — .reticle/hooks.json. Git-checked on purpose: a hook is a
4333
+ * decision the whole team shares, the same way a git hook or a package script is, and one that
4334
+ * only exists on the machine that wrote it is a rule nobody else is following.
4335
+ *
4336
+ * It names COMMANDS, so it is exactly as trusted as `package.json` scripts in the same repository
4337
+ * and no more: opening a repo does not run them, and Reticle runs one only when the event it is
4338
+ * attached to actually happens. The event payload is handed over on stdin, never interpolated into
4339
+ * the command line, so a defect's own text can never become part of a command.
4340
+ */
4341
+ HOOKS_FILE: "hooks.json",
4342
+ /**
4343
+ * Auto-provisioned bridge pairing token, stored at ~/.reticle/pairing-token (mode 0600). Written by
4344
+ * the daemon, read Node-side by the build plugins to inject into connect. A browser sandbox cannot
4345
+ * read it, so a rogue localhost app can't present it — that's what stops cross-app session hijack.
4346
+ */
4347
+ PAIRING_TOKEN_FILE: "pairing-token"
4348
+ };
4349
+ var UpdateCheckIntervalMs = 24 * 60 * 60 * 1e3;
4350
+ var RING_BUFFER_DEFAULTS = {
4351
+ MAX_EVENTS: 2e3,
4352
+ MAX_AGE_MS: 6e4,
4353
+ MAX_BYTES: TRANSPORT_LIMITS.MAX_BUFFER_BYTES
4430
4354
  };
4431
- var NEVER = INVALID;
4355
+ var EventType = {
4356
+ DOM_ADDED: "dom.added",
4357
+ DOM_REMOVED: "dom.removed",
4358
+ DOM_ATTR: "dom.attr",
4359
+ DOM_TEXT: "dom.text",
4360
+ NET_REQUEST: "net.request",
4361
+ NET_PENDING: "net.pending",
4362
+ /** An SSE (EventSource) or WebSocket frame — a message on a long-lived streaming connection. */
4363
+ NET_STREAM: "net.stream",
4364
+ /** A web-perf metric a screenshot can't verify: LCP, cumulative layout shift, or a long task. */
4365
+ PERF: "perf",
4366
+ ROUTE_CHANGE: "route.change",
4367
+ CONSOLE_LOG: "console.log",
4368
+ CONSOLE_WARN: "console.warn",
4369
+ CONSOLE_ERROR: "console.error",
4370
+ CONSOLE_INFO: "console.info",
4371
+ CONSOLE_DEBUG: "console.debug",
4372
+ ERROR_UNCAUGHT: "error.uncaught",
4373
+ VISIBLE_SHOWN: "visible.shown",
4374
+ ANIM_START: "anim.start",
4375
+ ANIM_END: "anim.end",
4376
+ SCROLL_POSITION: "scroll.position",
4377
+ REVEAL_SHOWN: "reveal.shown",
4378
+ SIGNAL: "signal",
4379
+ STATE_CHANGE: "state.change",
4380
+ /** a write to localStorage/sessionStorage/cookies — `data: { area, key, old?, new? }` (values redacted). */
4381
+ STORAGE_CHANGE: "storage.change",
4382
+ /** page-level visibility/focus health (distinct from element-level VISIBLE_*). */
4383
+ PAGE_HEALTH: "page.health",
4384
+ /**
4385
+ * synthetic: the page called window.open, so the consequence of what was just clicked may live in
4386
+ * another browsing context this one cannot observe (an OAuth popup is the archetype).
4387
+ * `data: { href }` — the URL the page asked to open, when it named one.
4388
+ */
4389
+ CONTEXT_OPENED: "context.opened",
4390
+ /**
4391
+ * The app opened a native `alert`/`confirm`/`prompt` while Reticle was driving it.
4392
+ *
4393
+ * Recorded because Reticle ANSWERS these rather than letting them block — a native dialog halts
4394
+ * the main thread, and the SDK's own message pump is on that thread, so one `confirm` behind a
4395
+ * driven click made the tab permanently unresponsive with no recovery from inside the session.
4396
+ * Answering silently would trade a wedge for an invisible one, so the question the app asked, and
4397
+ * the answer given, ride out as an event.
4398
+ */
4399
+ DIALOG_OPENED: "dialog.opened",
4400
+ /** aggregated React commits over a throttle window (dev builds) — `data: { commits }`. Commit storms /
4401
+ * wasted re-renders show up here without a per-render flood. */
4402
+ RENDER_COMMIT: "render.commit",
4403
+ /** element focus moved — `data: { to, from, toBody }`. Focus dropping to body after an act is a regression. */
4404
+ FOCUS_CHANGE: "focus.change",
4405
+ /** browser → bridge: a human recording compiled in-page. */
4406
+ FLOW_RECORDED: "flow.recorded",
4407
+ /** synthetic: browser transport queue overflowed; events were dropped. `data: { dropped: number }`. */
4408
+ TRANSPORT_OVERFLOW: "transport.overflow",
4409
+ /**
4410
+ * synthetic: a per-channel cap truncated a batch (e.g. a DOM mutation flood). `data: { channel, dropped }`.
4411
+ * Marks downstream rollups/envelopes as built on incomplete data — a ledger that lies at scale is worse
4412
+ * than no ledger, so truncation is never silent.
4413
+ */
4414
+ TRUNCATED: "truncated",
4415
+ /**
4416
+ * synthetic: the SDK detected a region it CANNOT observe (a cross-origin iframe, a closed shadow root).
4417
+ * `data: { kind: BlindSpotKind, count }`. Surfaced on results as `coverage: partial` so a green never
4418
+ * implies it saw everything.
4419
+ */
4420
+ BLIND_SPOT: "blind-spot",
4421
+ /** synthetic: the SDK ITSELF failed (an observer threw). `data: { site, message, errorType }`.
4422
+ * Rides the existing bridge — no outbound request. See browser/observers/sdk-failure.ts. */
4423
+ SDK_FAILED: "sdk.failed",
4424
+ /**
4425
+ * synthetic (driven only): CDP/Playwright-authoritative network detail for a response the in-page
4426
+ * fetch/XHR wrapper also saw — full response headers + authoritative status/mimeType the page-side
4427
+ * wrapper can't reach. `data: { url, method?, status, headers, resourceType? }`. Merged onto the
4428
+ * matching in-page NET_REQUEST so the driven view never loses fidelity to an outside-in tool.
4429
+ */
4430
+ NET_DETAIL: "net.detail",
4431
+ /**
4432
+ * Live-control: browser → bridge. A human acted on the presenter panel.
4433
+ * `data: { kind: HumanControlKind; text?: string }`. Rides the existing EventMessage.
4434
+ */
4435
+ HUMAN_CONTROL: "human.control",
4436
+ /**
4437
+ * Human review: browser → bridge. A human pinned a mistake to an element on the running page
4438
+ * (the "annotate the bug where you see it" loop). `data` narrows to HumanMarkDataSchema — a note
4439
+ * plus a re-resolvable element anchor (and its source file:line when the framework stamped one) so
4440
+ * the agent that drains the mark knows exactly which element and which source to fix.
4441
+ */
4442
+ HUMAN_MARK: "human.mark",
4443
+ /**
4444
+ * The app produced a FILE — a Blob handed to `URL.createObjectURL`, usually saved by clicking an
4445
+ * anchor with `download`. `data: { filename?, mimeType, bytes, lines?, preview? }`. The one artifact
4446
+ * class no outside-the-browser tool can inspect: it never crosses the network, so there is no
4447
+ * request to intercept. See `observers/download.ts` for the defect that motivated it.
4448
+ */
4449
+ DOWNLOAD: "download"
4450
+ };
4451
+ var RETICLE_RENDER_PREHOOK = "__reticleRenderPreHook";
4452
+ var CONSOLE_LEVEL_PREFIX = "console.";
4453
+ var CONSOLE_LEVELS = [
4454
+ EventType.CONSOLE_LOG,
4455
+ EventType.CONSOLE_WARN,
4456
+ EventType.CONSOLE_ERROR,
4457
+ EventType.CONSOLE_INFO
4458
+ ].map((type) => type.slice(CONSOLE_LEVEL_PREFIX.length));
4459
+
4460
+ // ../../../core/dist/identity/source-constants.js
4461
+ var DATA_RETICLE_SOURCE_ATTR = "data-reticle-source";
4462
+ var RETICLE_ROOT_GLOBAL = "__RETICLE_ROOT__";
4463
+ var RETICLE_SDK_VERSION_GLOBAL = "__RETICLE_SDK_VERSION__";
4432
4464
 
4433
- // ../core/dist/project-id.js
4465
+ // ../../../core/dist/identity/project-id.js
4434
4466
  var PROJECT_ID_HASH_LENGTH = 8;
4435
4467
  var FALLBACK_PROJECT_BASE = "app";
4436
4468
  function slugifyPackageName(name) {
@@ -4460,7 +4492,7 @@ function projectIdFrom(pkgName, rootPath, hash) {
4460
4492
  return `${base}-${hash(rootPath)}`;
4461
4493
  }
4462
4494
 
4463
- // ../core/dist/daemon-registry.js
4495
+ // ../../../core/dist/registry/daemon-registry.js
4464
4496
  var DAEMON_REGISTRY_PREFIX = "daemon-";
4465
4497
  var DAEMON_REGISTRY_SUFFIX = ".json";
4466
4498
  function daemonRegistryPort(fileName) {
@@ -4484,7 +4516,7 @@ function pickDaemonPort(entries, projectId, isAlive2) {
4484
4516
  return matches[0] ?? null;
4485
4517
  }
4486
4518
 
4487
- // ../core/dist/dev-server-registry.js
4519
+ // ../../../core/dist/registry/dev-server-registry.js
4488
4520
  var DEV_SERVER_PREFIX = "devserver-";
4489
4521
  var DEV_SERVER_SUFFIX = ".json";
4490
4522
  function devServerRegistryFileName(port) {
@@ -4517,25 +4549,26 @@ var DevServerEntrySchema = external_exports.object({
4517
4549
  var import_node_crypto2 = require("node:crypto");
4518
4550
  var import_node_path2 = require("node:path");
4519
4551
  var import_node_fs2 = require("node:fs");
4552
+ var RETICLE_CONFIG_BASENAME = ".reticle.json";
4520
4553
  function shortHash(input) {
4521
4554
  return (0, import_node_crypto2.createHash)("sha1").update(input).digest("hex").slice(0, PROJECT_ID_HASH_LENGTH);
4522
4555
  }
4523
4556
  function deriveProjectId(pkgName, rootPath) {
4524
4557
  return projectIdFrom(pkgName, rootPath, shortHash);
4525
4558
  }
4526
- function readNearestPackageName(startDir) {
4559
+ var readFileOrThrow = (path) => (0, import_node_fs2.readFileSync)(path, "utf8");
4560
+ var MAX_CONFIG_SEARCH_DEPTH = 6;
4561
+ var MAX_PACKAGE_SEARCH_DEPTH = 50;
4562
+ function readNearestField(startDir, basename, field, readFile, maxDepth) {
4527
4563
  let dir = startDir;
4528
- for (let depth = 0; depth < 50; depth++) {
4529
- const pkgPath = (0, import_node_path2.join)(dir, "package.json");
4530
- if ((0, import_node_fs2.existsSync)(pkgPath)) {
4531
- try {
4532
- const parsed = JSON.parse((0, import_node_fs2.readFileSync)(pkgPath, "utf8"));
4533
- if ("object" === typeof parsed && parsed !== null) {
4534
- const name = parsed["name"];
4535
- if ("string" === typeof name && name.length > 0) return name;
4536
- }
4537
- } catch {
4564
+ for (let depth = 0; depth <= maxDepth; depth++) {
4565
+ try {
4566
+ const parsed = JSON.parse(readFile((0, import_node_path2.join)(dir, basename)));
4567
+ if ("object" === typeof parsed && parsed !== null) {
4568
+ const value = parsed[field];
4569
+ if ("string" === typeof value && value.length > 0) return value;
4538
4570
  }
4571
+ } catch {
4539
4572
  }
4540
4573
  const parent = (0, import_node_path2.dirname)(dir);
4541
4574
  if (parent === dir) break;
@@ -4543,8 +4576,22 @@ function readNearestPackageName(startDir) {
4543
4576
  }
4544
4577
  return void 0;
4545
4578
  }
4546
- function resolveProjectId(explicit, cwd, readPkgName = readNearestPackageName) {
4579
+ function readNearestPackageName(startDir, readFile = readFileOrThrow) {
4580
+ return readNearestField(startDir, "package.json", "name", readFile, MAX_PACKAGE_SEARCH_DEPTH);
4581
+ }
4582
+ function readConfiguredProjectId(startDir, readFile = readFileOrThrow) {
4583
+ return readNearestField(
4584
+ startDir,
4585
+ RETICLE_CONFIG_BASENAME,
4586
+ "projectId",
4587
+ readFile,
4588
+ MAX_CONFIG_SEARCH_DEPTH
4589
+ );
4590
+ }
4591
+ function resolveProjectId(explicit, cwd, readPkgName = readNearestPackageName, readConfiguredId = readConfiguredProjectId) {
4547
4592
  if (explicit !== void 0 && explicit.length > 0) return explicit;
4593
+ const configured = readConfiguredId(cwd);
4594
+ if (configured !== void 0 && configured.length > 0) return configured;
4548
4595
  return deriveProjectId(readPkgName(cwd), cwd);
4549
4596
  }
4550
4597
 
@@ -4800,6 +4847,41 @@ function optimizerOptions(key, inherited, add) {
4800
4847
  };
4801
4848
  }
4802
4849
 
4850
+ // src/plugin-name.ts
4851
+ var RETICLE_VITE_PLUGIN_NAME = "reticle";
4852
+
4853
+ // src/injection-postcondition.ts
4854
+ var DEV_INJECTION_GRACE_MS = 1e4;
4855
+ var notInjectedMessage = () => `[${RETICLE_VITE_PLUGIN_NAME}] could not inject reticle.connect(): the HTML entry module was never matched, so this app carries no instrumentation and will never connect. Check that index.html references your entry with a <script type="module" src="...">, or pass \`inject: false\` and call reticle.connect({ token: __RETICLE_TOKEN__ }) yourself. The plugin still inlines that define; a connect without it is refused.`;
4856
+ var unconfirmedInjectionMessage = () => `[${RETICLE_VITE_PLUGIN_NAME}] could not confirm reticle.connect() was injected: the HTML entry module was not transformed this session. That is expected when Vite served it from its transform cache. If the app does not appear in \`reticle status\`, restart the dev server with \`--force\` to bypass the cache, then check that index.html references your entry with a <script type="module" src="...">.`;
4857
+ var htmlHookNeverRanMessage = () => `[${RETICLE_VITE_PLUGIN_NAME}] this app will never connect: the dev server never asked this plugin to transform any HTML, so reticle.connect() was never added to the page. That usually means your framework renders its own HTML instead of serving index.html \u2014 SvelteKit, Nuxt, Astro, React Router (framework mode) and TanStack Start all do. Fix: import '@reticlehq/browser' and call reticle.connect({ token: __RETICLE_TOKEN__ }) yourself from your app entry file, and pass \`inject: false\` to this plugin so the two do not both try.`;
4858
+ var defaultSchedule = (run, ms) => {
4859
+ const timer = setTimeout(run, ms);
4860
+ timer.unref?.();
4861
+ };
4862
+ function createInjectionWatch(deps) {
4863
+ let htmlRequested = false;
4864
+ const isDocumentRequest = (req) => true === req.headers?.accept?.includes("text/html");
4865
+ const checkHtmlHookRan = () => {
4866
+ if (deps.desktop || !deps.inject || deps.htmlTransformed()) return;
4867
+ if (!htmlRequested) return;
4868
+ deps.warn(htmlHookNeverRanMessage());
4869
+ };
4870
+ const noteHtmlRequest = () => {
4871
+ if (htmlRequested) return;
4872
+ htmlRequested = true;
4873
+ (deps.schedule ?? defaultSchedule)(checkHtmlHookRan, DEV_INJECTION_GRACE_MS);
4874
+ };
4875
+ const checkInjected = () => {
4876
+ if (!deps.desktop || !deps.inject || deps.injected()) return;
4877
+ deps.warn(unconfirmedInjectionMessage());
4878
+ };
4879
+ const armDesktopCheck = () => {
4880
+ (deps.schedule ?? defaultSchedule)(checkInjected, DEV_INJECTION_GRACE_MS);
4881
+ };
4882
+ return { noteHtmlRequest, isDocumentRequest, checkHtmlHookRan, checkInjected, armDesktopCheck };
4883
+ }
4884
+
4803
4885
  // src/watch-ignore.ts
4804
4886
  function mergeIgnored(existing, ours) {
4805
4887
  if (void 0 === existing || null === existing) return [ours];
@@ -4820,7 +4902,6 @@ function isVitestBrowserServer(config) {
4820
4902
  }
4821
4903
 
4822
4904
  // src/index.ts
4823
- var RETICLE_VITE_PLUGIN_NAME = "reticle";
4824
4905
  var RETICLE_PACKAGE2 = "@reticlehq/react";
4825
4906
  var RETICLE_SENSOR = "@reticlehq/browser";
4826
4907
  var RETICLE_TOKEN_GLOBAL = "__RETICLE_TOKEN__";
@@ -4848,7 +4929,6 @@ onScheduleFiberRoot:function(){},onCommitFiberRoot:fire,onPostCommitFiberRoot:fu
4848
4929
  }else{var prev=h.onCommitFiberRoot;h.onCommitFiberRoot=function(){try{fire.apply(null,arguments);}catch(e){}
4849
4930
  if(typeof prev==='function')return prev.apply(this,arguments);};}
4850
4931
  }catch(e){}})();`;
4851
- var DEV_INJECTION_GRACE_MS = 1e4;
4852
4932
  var CONNECT_CHURN_LIMIT = 5;
4853
4933
  var connectChurnWarning = () => `[${RETICLE_VITE_PLUGIN_NAME}] the injected connect module has changed ${String(CONNECT_CHURN_LIMIT)} times in one dev-server session. Something it depends on (the bridge port, the pairing token, or a reticle-dev module appearing and disappearing) is not settling, and that can make the page reload repeatedly. Reticle will keep serving the newest version. Please report this at https://github.com/ReticleHQ/reticle/issues with your vite.config and whether more than one daemon is running (\`npx @reticlehq/server status\`).`;
4854
4934
  function isHtmlEntry(id, specifier, root) {
@@ -4993,6 +5073,7 @@ function reticle(options = {}) {
4993
5073
  let vitestBrowser = false;
4994
5074
  const warn = options.onWarn ?? ((message) => globalThis.console.warn(message));
4995
5075
  let injected = false;
5076
+ let htmlTransformed = false;
4996
5077
  const resolveLazy = () => {
4997
5078
  const port = resolved.port ?? discoverDaemonPort(resolved.projectId);
4998
5079
  const withPort = port !== void 0 ? { ...resolved, port } : resolved;
@@ -5005,12 +5086,13 @@ function reticle(options = {}) {
5005
5086
  const currentConnectSource = () => connectModuleSource(resolveLazy(), root === void 0 ? null : findDevModule(root, import_node_fs6.existsSync));
5006
5087
  let lastServedConnectSource;
5007
5088
  let connectChanges = 0;
5008
- const notInjectedMessage = () => `[${RETICLE_VITE_PLUGIN_NAME}] could not inject reticle.connect(): the HTML entry module was never matched, so this app carries no instrumentation and will never connect. Check that index.html references your entry with a <script type="module" src="...">, or pass \`inject: false\` and call reticle.connect({ token: __RETICLE_TOKEN__ }) yourself. The plugin still inlines that define; a connect without it is refused.`;
5009
- const unconfirmedInjectionMessage = () => `[${RETICLE_VITE_PLUGIN_NAME}] could not confirm reticle.connect() was injected: the HTML entry module was not transformed this session. That is expected when Vite served it from its transform cache. If the app does not appear in \`reticle status\`, restart the dev server with \`--force\` to bypass the cache, then check that index.html references your entry with a <script type="module" src="...">.`;
5010
- const checkInjected = () => {
5011
- if (!desktop || !inject || injected) return;
5012
- warn(unconfirmedInjectionMessage());
5013
- };
5089
+ const watch = createInjectionWatch({
5090
+ desktop,
5091
+ inject,
5092
+ injected: () => injected,
5093
+ htmlTransformed: () => htmlTransformed,
5094
+ warn
5095
+ });
5014
5096
  return {
5015
5097
  name: RETICLE_VITE_PLUGIN_NAME,
5016
5098
  // Web: serve-only, so a production bundle can never carry the SDK — gating is the tool's job.
@@ -5021,9 +5103,9 @@ function reticle(options = {}) {
5021
5103
  /**
5022
5104
  * Declare the SDK itself and the optimizer cache fingerprint.
5023
5105
  *
5024
- * The browser SDK used to need extra CJS query-engine deps here. It no longer imports that
5025
- * second accessibility engine, so keeping those names would make Vite pre-bundle packages the
5026
- * app may not have and blame Reticle for a false `Failed to resolve dependency` warning.
5106
+ * The SDK itself only. It does not import a second accessibility engine, and naming CJS deps it
5107
+ * does not use would make Vite pre-bundle packages the app may not have, then blame Reticle for a
5108
+ * false `Failed to resolve dependency` warning.
5027
5109
  */
5028
5110
  config(config) {
5029
5111
  const appRoot = config.root ?? process.cwd();
@@ -5032,29 +5114,18 @@ function reticle(options = {}) {
5032
5114
  // Keep the daemon's journal out of the dev server's watcher.
5033
5115
  //
5034
5116
  // The daemon writes `.reticle/` into the PROJECT root — session journals, and `ambient.json`
5035
- // rewritten atomically as `ambient.json.tmp` + rename on a live session. Vite watches the
5036
- // project root and does not ignore that directory, so every journal write read as a project
5037
- // file changing and Vite answered with a full page reload.
5038
- //
5039
- // That is a loop with no exit: page loads -> SDK connects and streams events -> daemon
5040
- // journals them -> Vite reloads the page -> SDK reconnects -> more events. It ran several
5041
- // times a second for as long as the dev server was up, and the damage was total but
5042
- // misattributed: every ref went stale, every act_and_wait died mid-flight, and the log
5043
- // filled with connect/disconnect pairs that looked like a flapping SDK rather than a
5044
- // watcher chasing its own tail.
5117
+ // rewritten atomically as `ambient.json.tmp` + rename on a live session. Unignored, every
5118
+ // journal write reads as a project file changing and Vite answers with a full page reload,
5119
+ // which is a loop with no exit: page loads -> SDK connects and streams events -> daemon
5120
+ // journals them -> Vite reloads the page -> SDK reconnects.
5045
5121
  //
5046
- // A RegExp, not a glob, and that is the whole difference between this working and not.
5047
- // chokidar dropped glob support in v4 Vite 7+ ships v4/v5, where a pattern like
5048
- // `**/.reticle/**` is silently accepted and matches nothing. MEASURED against the chokidar
5049
- // this repo resolves: with the glob, a write to `.reticle/ambient.json` still fires; with
5050
- // this RegExp it does not, while a normal file still does. Vite's own defaults are globs and
5051
- // have the same problem, which is why it is not safe to copy their shape here.
5122
+ // A RegExp, NOT a glob: chokidar dropped glob support in v4, and Vite 7+ ships v4/v5, where
5123
+ // `**/.reticle/**` is silently accepted and matches nothing. Vite's own defaults are globs
5124
+ // and have the same problem, so their shape is not safe to copy here.
5052
5125
  //
5053
5126
  // Anchored on `^` or a separator so it matches the directory and not a file that merely ends
5054
5127
  // in those characters, and both separators are accepted because chokidar reports the path in
5055
- // the platform's own form.
5056
- //
5057
- // Appends to the app's list rather than replacing it, so nothing it already excluded is lost.
5128
+ // the platform's own form. Appends to the app's list rather than replacing it.
5058
5129
  server: {
5059
5130
  watch: {
5060
5131
  ignored: mergeIgnored(config.server?.watch?.ignored, JOURNAL_IGNORE)
@@ -5062,8 +5133,8 @@ function reticle(options = {}) {
5062
5133
  },
5063
5134
  // Expose the daemon's pairing token to hand-written connects in the same Vite app. The
5064
5135
  // plugin's own injected connect gets the token directly, but a connect the USER writes —
5065
- // SvelteKit's client hook, a custom entry — had no way to reach a file only Node can read,
5066
- // so it called connect() with no credential and the bridge answered "authentication
5136
+ // SvelteKit's client hook, a custom entry — cannot reach a file only Node can read, so it
5137
+ // would call connect() with no credential and the bridge would answer "authentication
5067
5138
  // failed". Empty until the daemon has provisioned one; the page reloads once it has.
5068
5139
  define: {
5069
5140
  ...config.define ?? {},
@@ -5148,25 +5219,21 @@ ${code}`;
5148
5219
  * Serve the connect module fresh, every time.
5149
5220
  *
5150
5221
  * `load` reads the daemon's pairing token at serve time precisely because the daemon may start
5151
- * after the dev server — but Vite caches the module it produced, and answers every later request
5152
- * from that cache, INCLUDING after a full page reload. So a dev server started first served a
5153
- * tokenless connect module once and then kept serving it: the SDK got a 1008 `authentication
5154
- * failed`, stopped retrying (correctly — a wrong token does not fix itself), and `reticle status`
5155
- * showed no session while the page demonstrably contained `/@reticle-connect`. Only restarting
5156
- * the dev server cleared it, which is not a step anybody guesses.
5222
+ * after the dev server — but Vite caches the module it produced and answers every later request
5223
+ * from that cache, INCLUDING after a full page reload. A dev server started first therefore keeps
5224
+ * serving a tokenless connect module: the SDK gets a 1008 `authentication failed` and stops
5225
+ * retrying (correctly — a wrong token does not fix itself), so `reticle status` shows no session
5226
+ * while the page demonstrably contains `/@reticle-connect`, and only a dev-server restart clears
5227
+ * it.
5157
5228
  *
5158
5229
  * Dropping the cached module before it is served makes `load` re-read the token, so starting the
5159
5230
  * daemon and reloading the page is enough.
5160
5231
  *
5161
- * Only when the source would ACTUALLY differ, though. This used to invalidate on every request
5162
- * for the module, forever and a module that is force-invalidated on every request is
5163
- * re-resolved against Vite's dep optimizer on every page load, which is the shape of a
5164
- * self-sustaining reload loop: reload request invalidate re-resolve reload. Reported
5165
- * from the field on a Vite + React Router app pinned to a non-default port: every route
5166
- * reloaded the whole page about once a second, `/@reticle-connect` was fetched in every cycle,
5167
- * and removing the plugin stopped it instantly. Comparing the source first costs one string
5168
- * compare, keeps the late-daemon fix intact (the token appearing IS a change), and makes the
5169
- * module inert once it has settled.
5232
+ * Only when the source would ACTUALLY differ, though. A module force-invalidated on every
5233
+ * request is re-resolved against Vite's dep optimizer on every page load, which is a
5234
+ * self-sustaining reload loop: reload request invalidate re-resolve reload. Comparing
5235
+ * the source first costs one string compare, keeps the late-daemon fix intact (the token
5236
+ * appearing IS a change), and makes the module inert once it has settled.
5170
5237
  */
5171
5238
  configureServer(server) {
5172
5239
  if (!inject) return;
@@ -5195,6 +5262,7 @@ ${code}`;
5195
5262
  announce();
5196
5263
  }
5197
5264
  server.middlewares.use((req, _res, next) => {
5265
+ if (!desktop && watch.isDocumentRequest(req)) watch.noteHtmlRequest();
5198
5266
  const requestPath = (req.url ?? "").split("?")[0];
5199
5267
  if (requestPath === RETICLE_CONNECT_MODULE || requestPath === connectModuleUrl(base)) {
5200
5268
  if (currentConnectSource() !== lastServedConnectSource) {
@@ -5216,12 +5284,12 @@ ${code}`;
5216
5284
  if (!desktop || !inject || injected) return;
5217
5285
  throw new Error(notInjectedMessage());
5218
5286
  },
5219
- checkInjectedForTest: checkInjected,
5287
+ checkInjectedForTest: watch.checkInjected,
5288
+ checkHtmlHookForTest: watch.checkHtmlHookRan,
5289
+ injectionWatchForTest: watch,
5220
5290
  transformIndexHtml() {
5221
- if (desktop && inject && "serve" === command) {
5222
- const timer = setTimeout(checkInjected, DEV_INJECTION_GRACE_MS);
5223
- timer.unref?.();
5224
- }
5291
+ htmlTransformed = true;
5292
+ if (desktop && inject && "serve" === command) watch.armDesktopCheck();
5225
5293
  if (!inject || desktop) return [];
5226
5294
  if (true !== options.inject && vitestBrowser) return [];
5227
5295
  return [