retouche-dev 0.1.2 → 0.1.3

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/PROMPT.md CHANGED
@@ -55,7 +55,7 @@ An `allow` entry is `{ component?: "Text", classes?: ["text-muted-*"], propertie
55
55
 
56
56
  **Vite**
57
57
 
58
- - `vite.config.ts`: add `retouche()` from `retouche-dev/vite` to `plugins`.
58
+ - `vite.config.ts`: `import { retouche } from "retouche-dev/vite";` (a named export) and add `retouche()` to `plugins`.
59
59
  - The client entry (`src/main.tsx`): make `import "retouche-dev/instrument";` the very first import, before React. A framework that generates its client entry takes a custom one written as its docs show: TanStack Start's `src/client.tsx`, React Router's `app/entry.client.tsx` (`npx react-router reveal entry.client`).
60
60
  - Render `<Retouche config={config} />` from `retouche-dev` next to the app root, with `config` imported from `retouche.config.ts`. A framework that renders the whole document takes it inside the root route's `<body>`: TanStack Start's `__root.tsx`, the `Layout` in React Router's `app/root.tsx`.
61
61
  - An app with several entries, one per HTML page or window, needs both in every entry whose screens should be checked.
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as WATCHED_GROUPS } from "./class-groups-DKpPgmHx.js";
3
- import { A as voiceIdSchema, i as FOLLOW_OUTCOMES } from "./clock-BJi08VJS.js";
4
- import { d as FOLLOW_TOOL, l as reviewItems, p as mcpFollowPrompt, t as cardMarkdown, u as FOLLOW_PROMPT } from "./voice-markdown-BiOKT1SX.js";
5
- import { _ as failure, a as writeFollow, i as readFollower, l as readSessionFile, n as followedSession, o as writeFollower, r as readFollow, s as NO_FOLDER, t as EMPTY_FOLLOW, u as projectFolder } from "./follow-files-Dcya6bMQ.js";
3
+ import { i as FOLLOW_OUTCOMES, j as voiceIdSchema } from "./clock-Bmj-zl7l.js";
4
+ import { d as FOLLOW_TOOL, l as reviewItems, p as mcpFollowPrompt, t as cardMarkdown, u as FOLLOW_PROMPT } from "./voice-markdown-0BKH9ewO.js";
5
+ import { _ as failure, a as writeFollow, i as readFollower, l as readSessionFile, n as followedSession, o as writeFollower, r as readFollow, s as NO_FOLDER, t as EMPTY_FOLLOW, u as projectFolder } from "./follow-files-BiRHzUhr.js";
6
6
  import { existsSync, readFileSync } from "node:fs";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { z } from "zod";
@@ -23,6 +23,7 @@ const EDITORS = [
23
23
  "zed"
24
24
  ];
25
25
  const STATUS_MARKER = "retouche";
26
+ const STATUS_VOICE_PARAM = "voice";
26
27
  const BUILT_IN_AGENTS = [
27
28
  {
28
29
  id: "claude",
@@ -304,4 +305,4 @@ function clock(ms) {
304
305
  function recordedMs(session) {
305
306
  return Math.max(0, ...session.passages.map(({ endMs }) => endMs), ...session.moments.map(({ atMs, durationMs }) => atMs + durationMs), ...session.shots.map(({ atMs }) => atMs));
306
307
  }
307
- export { voiceIdSchema as A, sourceFileSchema as C, voiceFigureUploadSchema as D, voiceAnalysisRequestSchema as E, voiceShotUploadSchema as F, voiceStreamRequestSchema as I, voiceStreamSchema as L, voiceKeyRequestSchema as M, voiceSessionRequestSchema as N, voiceHistoryRequestSchema as O, voiceSessionSchema as P, voiceTranscriptRequestSchema as R, routeMarkerSchema as S, unpairedBodySchema as T, TRANSCRIBER_PROVIDER_NAMES as _, followCardSchema as a, isServerFrame as b, EDITORS as c, ROUTE_BASE as d, SERVER_FRAME_ORIGIN as f, TRANSCRIBER_PROVIDERS as g, STREAMED_TRANSCRIBERS as h, FOLLOW_OUTCOMES as i, voiceKeyAnswerSchema as j, voiceHistorySchema as k, ENDPOINTS as l, STATUS_MARKER as m, recordedMs as n, voiceFollowSchema as o, SERVER_FRAME_PREFIX as p, pendingPassages as r, BUILT_IN_AGENTS as s, clock as t, REQUEST_HEADER as u, VOICE_ID as v, statusSchema as w, pairTokenSchema as x, errorBodySchema as y, voiceTranscriptSchema as z };
308
+ export { voiceHistorySchema as A, voiceTranscriptSchema as B, routeMarkerSchema as C, voiceAnalysisRequestSchema as D, unpairedBodySchema as E, voiceSessionSchema as F, voiceShotUploadSchema as I, voiceStreamRequestSchema as L, voiceKeyAnswerSchema as M, voiceKeyRequestSchema as N, voiceFigureUploadSchema as O, voiceSessionRequestSchema as P, voiceStreamSchema as R, pairTokenSchema as S, statusSchema as T, TRANSCRIBER_PROVIDERS as _, followCardSchema as a, errorBodySchema as b, EDITORS as c, ROUTE_BASE as d, SERVER_FRAME_ORIGIN as f, STREAMED_TRANSCRIBERS as g, STATUS_VOICE_PARAM as h, FOLLOW_OUTCOMES as i, voiceIdSchema as j, voiceHistoryRequestSchema as k, ENDPOINTS as l, STATUS_MARKER as m, recordedMs as n, voiceFollowSchema as o, SERVER_FRAME_PREFIX as p, pendingPassages as r, BUILT_IN_AGENTS as s, clock as t, REQUEST_HEADER as u, TRANSCRIBER_PROVIDER_NAMES as v, sourceFileSchema as w, isServerFrame as x, VOICE_ID as y, voiceTranscriptRequestSchema as z };
@@ -1,4 +1,4 @@
1
- import { A as voiceIdSchema, P as voiceSessionSchema, a as followCardSchema, v as VOICE_ID } from "./clock-BJi08VJS.js";
1
+ import { F as voiceSessionSchema, a as followCardSchema, j as voiceIdSchema, y as VOICE_ID } from "./clock-Bmj-zl7l.js";
2
2
  import { z } from "zod";
3
3
  import { basename, dirname, join } from "node:path";
4
4
  import { createHash, randomBytes } from "node:crypto";
@@ -1,6 +1,6 @@
1
- import { D as voiceFigureUploadSchema, E as voiceAnalysisRequestSchema, F as voiceShotUploadSchema, I as voiceStreamRequestSchema, M as voiceKeyRequestSchema, N as voiceSessionRequestSchema, O as voiceHistoryRequestSchema, R as voiceTranscriptRequestSchema, _ as TRANSCRIBER_PROVIDER_NAMES, b as isServerFrame, c as EDITORS, d as ROUTE_BASE, g as TRANSCRIBER_PROVIDERS, h as STREAMED_TRANSCRIBERS, l as ENDPOINTS, m as STATUS_MARKER, n as recordedMs, p as SERVER_FRAME_PREFIX, r as pendingPassages, s as BUILT_IN_AGENTS, t as clock, u as REQUEST_HEADER, v as VOICE_ID } from "./clock-BJi08VJS.js";
2
- import { _ as failure$1, b as outcomeResponse, c as SessionFiles, d as projectId, f as userConfigFolder, g as errorResponse, h as deferred, i as readFollower, m as createKeyedQueue, p as writePrivateFile, r as readFollow, u as projectFolder, v as imageResponse, y as jsonResponse } from "./follow-files-Dcya6bMQ.js";
3
- import { n as passageRuns, r as spokenWords } from "./spoken-timeline-1xtFghWv.js";
1
+ import { D as voiceAnalysisRequestSchema, I as voiceShotUploadSchema, L as voiceStreamRequestSchema, N as voiceKeyRequestSchema, O as voiceFigureUploadSchema, P as voiceSessionRequestSchema, _ as TRANSCRIBER_PROVIDERS, c as EDITORS, d as ROUTE_BASE, g as STREAMED_TRANSCRIBERS, k as voiceHistoryRequestSchema, l as ENDPOINTS, m as STATUS_MARKER, n as recordedMs, p as SERVER_FRAME_PREFIX, r as pendingPassages, s as BUILT_IN_AGENTS, t as clock, u as REQUEST_HEADER, v as TRANSCRIBER_PROVIDER_NAMES, x as isServerFrame, y as VOICE_ID, z as voiceTranscriptRequestSchema } from "./clock-Bmj-zl7l.js";
2
+ import { _ as failure$1, b as outcomeResponse, c as SessionFiles, d as projectId, f as userConfigFolder, g as errorResponse, h as deferred, i as readFollower, m as createKeyedQueue, p as writePrivateFile, r as readFollow, u as projectFolder, v as imageResponse, y as jsonResponse } from "./follow-files-BiRHzUhr.js";
3
+ import { n as passageRuns, o as elementPlace, r as spokenWords } from "./spoken-timeline-CICeK4bI.js";
4
4
  import { constants, existsSync, readFileSync, realpathSync } from "node:fs";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { z } from "zod";
@@ -82,17 +82,21 @@ function answerPair(answer, request, response) {
82
82
  vary: "origin"
83
83
  }).end(JSON.stringify(body));
84
84
  }
85
- async function listen(allowedHosts) {
85
+ async function listen(listener) {
86
86
  const token = randomBytes(32).toString("base64url");
87
87
  const server = createServer((request, response) => {
88
88
  answerPair({
89
- allowedHosts,
89
+ allowedHosts: listener.allowedHosts,
90
90
  port: portOf(server),
91
91
  token
92
92
  }, request, response);
93
93
  });
94
94
  server.listen(0, LISTEN_HOST);
95
95
  await once(server, "listening");
96
+ server.on("error", () => {
97
+ listener.pairing = null;
98
+ server.close();
99
+ });
96
100
  server.unref();
97
101
  return {
98
102
  port: portOf(server),
@@ -101,7 +105,7 @@ async function listen(allowedHosts) {
101
105
  }
102
106
  async function startListening(listener) {
103
107
  try {
104
- return await listen(listener.allowedHosts);
108
+ return await listen(listener);
105
109
  } catch (error) {
106
110
  listener.pairing = null;
107
111
  throw error;
@@ -489,208 +493,6 @@ function resolveProjectRoots(appRoot) {
489
493
  };
490
494
  }
491
495
  }
492
- // src/server/source/jsx-range.ts
493
- const FAILED = -1;
494
- const MAX_TAG_LOOKBACK = 2;
495
- const TAG_NAME_START = /[A-Za-z_$]/;
496
- const TAG_NAME_CHAR = /[\w$.:-]/;
497
- const IDENTIFIER_CHAR = /[\w$]/;
498
- const WHITESPACE$1 = /\s/;
499
- const JSX_EXPRESSION_LEAD = /[([{,;=?:&|!>]/;
500
- const JSX_KEYWORD_LEADS = /* @__PURE__ */ new Set([
501
- "return",
502
- "yield",
503
- "default",
504
- "await"
505
- ]);
506
- function isTagStart(code, index) {
507
- if (code.charAt(index) !== "<") return false;
508
- const next = code.charAt(index + 1);
509
- return next === ">" || TAG_NAME_START.test(next);
510
- }
511
- function startsJsxInExpression(code, index) {
512
- let cursor = index - 1;
513
- while (cursor >= 0 && WHITESPACE$1.test(code.charAt(cursor))) cursor -= 1;
514
- if (cursor < 0) return true;
515
- const previous = code.charAt(cursor);
516
- if (JSX_EXPRESSION_LEAD.test(previous)) return true;
517
- let wordStart = cursor;
518
- while (wordStart > 0 && IDENTIFIER_CHAR.test(code.charAt(wordStart - 1))) wordStart -= 1;
519
- return JSX_KEYWORD_LEADS.has(code.slice(wordStart, cursor + 1));
520
- }
521
- function skipJsString(code, index) {
522
- const quote = code.charAt(index);
523
- let cursor = index + 1;
524
- while (cursor < code.length) {
525
- const char = code.charAt(cursor);
526
- if (char === "\\") cursor += 2;
527
- else if (char === quote) return cursor + 1;
528
- else if (char === "\n") return index + 1;
529
- else cursor += 1;
530
- }
531
- return index + 1;
532
- }
533
- function skipTemplate(code, index) {
534
- let cursor = index + 1;
535
- while (cursor < code.length) {
536
- const char = code.charAt(cursor);
537
- if (char === "\\") cursor += 2;
538
- else if (char === "`") return cursor + 1;
539
- else if (char === "$" && code.charAt(cursor + 1) === "{") {
540
- cursor = skipJsExpression(code, cursor + 1);
541
- if (cursor === FAILED) return FAILED;
542
- } else cursor += 1;
543
- }
544
- return FAILED;
545
- }
546
- function skipJsToken(code, index) {
547
- const char = code.charAt(index);
548
- const next = code.charAt(index + 1);
549
- if (char === "\"" || char === "'") return skipJsString(code, index);
550
- if (char === "`") return skipTemplate(code, index);
551
- if (char === "/" && next === "/") {
552
- const lineEnd = code.indexOf("\n", index);
553
- return lineEnd === -1 ? code.length : lineEnd;
554
- }
555
- if (char === "/" && next === "*") {
556
- const commentEnd = code.indexOf("*/", index + 2);
557
- return commentEnd === -1 ? FAILED : commentEnd + 2;
558
- }
559
- if (isTagStart(code, index) && startsJsxInExpression(code, index)) return skipElement(code, index);
560
- return index + 1;
561
- }
562
- function skipJsExpression(code, index) {
563
- let depth = 0;
564
- let cursor = index;
565
- while (cursor < code.length) {
566
- const char = code.charAt(cursor);
567
- if (char === "{" || char === "}") {
568
- depth += char === "{" ? 1 : -1;
569
- cursor += 1;
570
- if (depth === 0) return cursor;
571
- } else {
572
- cursor = skipJsToken(code, cursor);
573
- if (cursor === FAILED) return FAILED;
574
- }
575
- }
576
- return FAILED;
577
- }
578
- function skipTypeArguments(code, index) {
579
- let depth = 0;
580
- for (let cursor = index; cursor < code.length; cursor += 1) {
581
- const char = code.charAt(cursor);
582
- if (char === "<") depth += 1;
583
- else if (char === ">") {
584
- depth -= 1;
585
- if (depth === 0) return cursor + 1;
586
- }
587
- }
588
- return FAILED;
589
- }
590
- function skipAttributeToken(code, index) {
591
- const char = code.charAt(index);
592
- if (char === "{") return skipJsExpression(code, index);
593
- if (char === "\"" || char === "'") {
594
- const closingQuote = code.indexOf(char, index + 1);
595
- return closingQuote === -1 ? FAILED : closingQuote + 1;
596
- }
597
- return index + 1;
598
- }
599
- function readTagName(code, index) {
600
- let cursor = index;
601
- while (TAG_NAME_CHAR.test(code.charAt(cursor))) cursor += 1;
602
- return cursor;
603
- }
604
- function readOpeningTag(code, index) {
605
- const nameEnd = readTagName(code, index + 1);
606
- const name = code.slice(index + 1, nameEnd);
607
- let cursor = code.charAt(nameEnd) === "<" ? skipTypeArguments(code, nameEnd) : nameEnd;
608
- while (cursor !== FAILED && cursor < code.length) {
609
- const char = code.charAt(cursor);
610
- if (char === ">") return {
611
- end: cursor + 1,
612
- name,
613
- selfClosing: false
614
- };
615
- if (char === "/" && code.charAt(cursor + 1) === ">") return {
616
- end: cursor + 2,
617
- name,
618
- selfClosing: true
619
- };
620
- cursor = skipAttributeToken(code, cursor);
621
- }
622
- return null;
623
- }
624
- function readClosingTagEnd(code, index, name) {
625
- let cursor = index + 2;
626
- while (WHITESPACE$1.test(code.charAt(cursor))) cursor += 1;
627
- const nameEnd = readTagName(code, cursor);
628
- if (code.slice(cursor, nameEnd) !== name) return FAILED;
629
- cursor = nameEnd;
630
- while (WHITESPACE$1.test(code.charAt(cursor))) cursor += 1;
631
- return code.charAt(cursor) === ">" ? cursor + 1 : FAILED;
632
- }
633
- function skipChildren(code, index, name) {
634
- let cursor = index;
635
- while (cursor !== FAILED && cursor < code.length) {
636
- const char = code.charAt(cursor);
637
- if (char === "<" && code.charAt(cursor + 1) === "/") return readClosingTagEnd(code, cursor, name);
638
- if (char === "{") cursor = skipJsExpression(code, cursor);
639
- else if (isTagStart(code, cursor)) cursor = skipElement(code, cursor);
640
- else cursor += 1;
641
- }
642
- return FAILED;
643
- }
644
- function skipElement(code, index) {
645
- const tag = readOpeningTag(code, index);
646
- if (!tag) return FAILED;
647
- return tag.selfClosing ? tag.end : skipChildren(code, tag.end, tag.name);
648
- }
649
- function lineOffset(code, line) {
650
- if (!Number.isInteger(line) || line < 1) return FAILED;
651
- let offset = 0;
652
- for (let current = 1; current < line; current += 1) {
653
- const newline = code.indexOf("\n", offset);
654
- if (newline === -1) return FAILED;
655
- offset = newline + 1;
656
- }
657
- return offset;
658
- }
659
- function findTagStart(code, { column, lineEnd, lineStart }) {
660
- const origin = Math.min(lineStart + Math.max(column, 0), lineEnd);
661
- for (let back = 0; back <= MAX_TAG_LOOKBACK; back += 1) {
662
- const candidate = origin - back;
663
- if (candidate >= lineStart && isTagStart(code, candidate)) return candidate;
664
- }
665
- for (let candidate = origin + 1; candidate < lineEnd; candidate += 1) if (isTagStart(code, candidate)) return candidate;
666
- return FAILED;
667
- }
668
- function countNewlines(code, from, to) {
669
- let count = 0;
670
- let newline = code.indexOf("\n", from);
671
- while (newline !== -1 && newline < to) {
672
- count += 1;
673
- newline = code.indexOf("\n", newline + 1);
674
- }
675
- return count;
676
- }
677
- function jsxElementLines(code, line, column) {
678
- const lineStart = lineOffset(code, line);
679
- if (lineStart === FAILED) return null;
680
- const newline = code.indexOf("\n", lineStart);
681
- const tagStart = findTagStart(code, {
682
- column,
683
- lineEnd: newline === -1 ? code.length : newline,
684
- lineStart
685
- });
686
- if (tagStart === FAILED) return null;
687
- const elementEnd = skipElement(code, tagStart);
688
- if (elementEnd === FAILED) return null;
689
- return {
690
- end: line + countNewlines(code, tagStart, elementEnd - 1),
691
- start: line
692
- };
693
- }
694
496
  // src/server/source/server-frame.ts
695
497
  const QUERY_OR_HASH = /[?#].*$/;
696
498
  const SOURCE_MAPPING_URL = /\/\/# sourceMappingURL=(?<url>\S+)\s*$/;
@@ -862,10 +664,6 @@ async function locateSourceFile(fileName, roots) {
862
664
  if (refusal !== null) return failure$1(refusal, 403);
863
665
  return failure$1(`Could not find ${fileName} in ${roots.workspaceRoot}.`, 404);
864
666
  }
865
- function columnWithinLine(code, line, column) {
866
- const text = code.split("\n")[line - 1] ?? "";
867
- return column !== null && column < text.length ? column : null;
868
- }
869
667
  async function namedRequest(frame, roots) {
870
668
  if (frame.fileName.length > MAX_FILE_NAME_LENGTH || frame.fileName.includes("\0")) return failure$1("That source file name is not a valid path.", 400);
871
669
  const mapped = isServerFrame(frame.fileName) ? await mapServerFrame(frame, roots.workspaceRoot) : {
@@ -893,14 +691,12 @@ async function readSourceFile(frame, roots) {
893
691
  const { realPath, relativePath, size } = located.value;
894
692
  if (size > MAX_SOURCE_BYTES) return failure$1(`${relativePath} is larger than 1 MB, too big to preview.`, 413);
895
693
  const code = await readFile(realPath, "utf-8");
896
- const column = request.line === null ? request.column : columnWithinLine(code, request.line, request.column);
897
694
  return {
898
695
  ok: true,
899
696
  value: {
900
697
  absolutePath: realPath,
901
698
  code,
902
- column,
903
- elementLines: request.line === null ? null : jsxElementLines(code, request.line, column ?? 0),
699
+ ...elementPlace(code, request),
904
700
  line: request.line,
905
701
  path: relativePath
906
702
  }
@@ -2867,6 +2663,23 @@ function readInteger(value, minimum) {
2867
2663
  const parsed = Number(value);
2868
2664
  return Number.isInteger(parsed) && parsed >= minimum ? parsed : null;
2869
2665
  }
2666
+ async function statusOf(context, request) {
2667
+ const { editor } = context.settings;
2668
+ if (!new URL(request.url).searchParams.has("voice")) return {
2669
+ agents: [],
2670
+ editor,
2671
+ follow: null,
2672
+ marker: STATUS_MARKER,
2673
+ transcribers: []
2674
+ };
2675
+ return {
2676
+ agents: await context.voice.agents(),
2677
+ editor,
2678
+ follow: context.voice.follow(),
2679
+ marker: STATUS_MARKER,
2680
+ transcribers: await context.voice.transcribers()
2681
+ };
2682
+ }
2870
2683
  function coreRoutes(context) {
2871
2684
  return {
2872
2685
  [ENDPOINTS.source]: { GET: async (request) => {
@@ -2877,13 +2690,7 @@ function coreRoutes(context) {
2877
2690
  line: readInteger(searchParams.get("line"), 1)
2878
2691
  }, context.projectRoots()));
2879
2692
  } },
2880
- [ENDPOINTS.status]: { GET: async () => jsonResponse({
2881
- agents: await context.voice.agents(),
2882
- editor: context.settings.editor,
2883
- follow: context.voice.follow(),
2884
- marker: STATUS_MARKER,
2885
- transcribers: await context.voice.transcribers()
2886
- }) }
2693
+ [ENDPOINTS.status]: { GET: async (request) => jsonResponse(await statusOf(context, request)) }
2887
2694
  };
2888
2695
  }
2889
2696
  async function routeRequest(request, routes) {
@@ -2922,10 +2729,10 @@ function createRouteHandler(options = {}, env = process.env, spawnEnv = env) {
2922
2729
  ...voice.routes
2923
2730
  };
2924
2731
  return async (request) => {
2925
- const rejection = rejectUntrustedHost(request, settings.allowedHosts) ?? rejectUntrustedCaller(request, settings.allowedHosts) ?? await rejectUnpaired(request, settings.allowedHosts);
2732
+ const rejection = rejectUntrustedHost(request, settings.allowedHosts) ?? rejectUntrustedCaller(request, settings.allowedHosts);
2926
2733
  if (rejection) return rejection;
2927
2734
  try {
2928
- return await routeRequest(request, routes);
2735
+ return await rejectUnpaired(request, settings.allowedHosts) ?? await routeRequest(request, routes);
2929
2736
  } catch (error) {
2930
2737
  const reason = error instanceof Error ? error.message : String(error);
2931
2738
  return errorResponse(`Retouche route failed: ${reason}`, 500);
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { c } from "react/compiler-runtime";
3
3
  import { Suspense, lazy, useSyncExternalStore } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  // src/retouche.tsx
6
- const Layer = process.env.NODE_ENV === "production" ? null : lazy(async () => await import("./layer-Bw5Xt2p7.js"));
6
+ const Layer = process.env.NODE_ENV === "production" ? null : lazy(async () => await import("./layer-Ed1eBWo9.js"));
7
7
  function subscribeToNothing() {
8
8
  return () => {};
9
9
  }