retouche-dev 0.1.1 → 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 { a as writeFollow, g as failure, 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-CfuW6Ah5.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";
@@ -36,12 +36,26 @@ function failure(error, status) {
36
36
  function outcomeResponse(outcome) {
37
37
  return outcome.ok ? jsonResponse(outcome.value) : errorResponse(outcome.error, outcome.status);
38
38
  }
39
+ // src/server/deferred.ts
40
+ const unsettled = () => {};
41
+ function deferred() {
42
+ let settle = unsettled;
43
+ let fail = unsettled;
44
+ return {
45
+ promise: new Promise((resolve, reject) => {
46
+ settle = resolve;
47
+ fail = reject;
48
+ }),
49
+ reject: fail,
50
+ resolve: settle
51
+ };
52
+ }
39
53
  // src/server/voice/keyed-queue.ts
40
54
  function createKeyedQueue() {
41
55
  const tails = /* @__PURE__ */ new Map();
42
56
  return async (key, task) => {
43
57
  const previous = tails.get(key);
44
- const { promise: done, resolve } = Promise.withResolvers();
58
+ const { promise: done, resolve } = deferred();
45
59
  tails.set(key, done);
46
60
  try {
47
61
  await previous;
@@ -268,4 +282,4 @@ async function followedSession(projectFolder) {
268
282
  const follow = await readFollow(newest.folder);
269
283
  return follow !== null && follow.closedAt === null ? newest : null;
270
284
  }
271
- export { imageResponse as _, writeFollow as a, SessionFiles as c, projectId as d, userConfigFolder as f, failure as g, errorResponse as h, readFollower as i, readSessionFile as l, createKeyedQueue as m, followedSession as n, writeFollower as o, writePrivateFile as p, readFollow as r, NO_FOLDER as s, EMPTY_FOLLOW as t, projectFolder as u, jsonResponse as v, outcomeResponse as y };
285
+ export { failure as _, writeFollow as a, outcomeResponse as b, SessionFiles as c, projectId as d, userConfigFolder as f, errorResponse as g, deferred as h, readFollower as i, readSessionFile as l, createKeyedQueue as m, followedSession as n, writeFollower as o, writePrivateFile as p, readFollow as r, NO_FOLDER as s, EMPTY_FOLLOW as t, projectFolder as u, imageResponse as v, jsonResponse as y };
@@ -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 imageResponse, c as SessionFiles, d as projectId, f as userConfigFolder, g as failure$1, h as errorResponse, i as readFollower, m as createKeyedQueue, p as writePrivateFile, r as readFollow, u as projectFolder, v as jsonResponse, y as outcomeResponse } from "./follow-files-CfuW6Ah5.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;
@@ -426,31 +430,32 @@ function readsEnv(options) {
426
430
  const read = /* @__PURE__ */ new Set([...PRESET_KEY_ENVS, ...optionKeyEnvs(options.voice)]);
427
431
  return (name) => name.startsWith(OWN_PREFIX) || read.has(name);
428
432
  }
429
- function withEnvFiles(files, options) {
433
+ const ENV_FILE_NAME = /^\s*(?:export\s+)?(?<name>[\w.-]+)(?:\s*=|:\s)/gmu;
434
+ function envFileNames({ folders, mode }) {
435
+ const files = [
436
+ ".env",
437
+ ".env.local",
438
+ `.env.${mode}`,
439
+ `.env.${mode}.local`
440
+ ];
441
+ const paths = folders.flatMap((folder) => files.map((file) => join(folder, file)));
442
+ return new Set(paths.flatMap((path) => existsSync(path) ? [...readFileSync(path, "utf-8").matchAll(ENV_FILE_NAME)].flatMap((match) => match.groups?.name ?? []) : []));
443
+ }
444
+ function withoutNames(env, drop) {
445
+ return Object.fromEntries(Object.entries(env).filter(([name]) => !drop(name)));
446
+ }
447
+ function appEnvs(loaded, files, options) {
430
448
  const isRead = readsEnv(options);
431
- const picked = Object.entries(files).filter(([name]) => isRead(name));
449
+ const fromFiles = envFileNames(files);
450
+ const env = withoutNames(loaded, (name) => fromFiles.has(name) && !isRead(name));
432
451
  return {
433
- ...process.env,
434
- ...Object.fromEntries(picked)
452
+ env,
453
+ spawnEnv: withoutNames(env, (name) => fromFiles.has(name) && !name.startsWith(OWN_PREFIX))
435
454
  };
436
455
  }
437
- const APP_ENV_FILES = [
438
- ".env",
439
- ".env.local",
440
- ".env.development",
441
- ".env.development.local"
442
- ];
443
- const ENV_FILE_NAME = /^\s*(?:export\s+)?(?<name>[\w.-]+)\s*=/gmu;
444
- function envFileNames(root) {
445
- return new Set(APP_ENV_FILES.flatMap((file) => {
446
- const path = join(root, file);
447
- return existsSync(path) ? [...readFileSync(path, "utf-8").matchAll(ENV_FILE_NAME)].flatMap((match) => match.groups?.name ?? []) : [];
448
- }));
449
- }
450
- function withoutEnvFiles(env, options) {
451
- const isRead = readsEnv(options);
452
- const fromFiles = envFileNames(resolve(presentValue(options.root) ?? process.cwd()));
453
- return Object.fromEntries(Object.entries(env).filter(([name]) => !fromFiles.has(name) || isRead(name)));
456
+ function appEnvFolders(options) {
457
+ const root = resolve(presentValue(options.root) ?? process.cwd());
458
+ return [.../* @__PURE__ */ new Set([process.cwd(), root])];
454
459
  }
455
460
  function resolveServerOptions(options, env) {
456
461
  return {
@@ -488,208 +493,6 @@ function resolveProjectRoots(appRoot) {
488
493
  };
489
494
  }
490
495
  }
491
- // src/server/source/jsx-range.ts
492
- const FAILED = -1;
493
- const MAX_TAG_LOOKBACK = 2;
494
- const TAG_NAME_START = /[A-Za-z_$]/;
495
- const TAG_NAME_CHAR = /[\w$.:-]/;
496
- const IDENTIFIER_CHAR = /[\w$]/;
497
- const WHITESPACE$1 = /\s/;
498
- const JSX_EXPRESSION_LEAD = /[([{,;=?:&|!>]/;
499
- const JSX_KEYWORD_LEADS = /* @__PURE__ */ new Set([
500
- "return",
501
- "yield",
502
- "default",
503
- "await"
504
- ]);
505
- function isTagStart(code, index) {
506
- if (code.charAt(index) !== "<") return false;
507
- const next = code.charAt(index + 1);
508
- return next === ">" || TAG_NAME_START.test(next);
509
- }
510
- function startsJsxInExpression(code, index) {
511
- let cursor = index - 1;
512
- while (cursor >= 0 && WHITESPACE$1.test(code.charAt(cursor))) cursor -= 1;
513
- if (cursor < 0) return true;
514
- const previous = code.charAt(cursor);
515
- if (JSX_EXPRESSION_LEAD.test(previous)) return true;
516
- let wordStart = cursor;
517
- while (wordStart > 0 && IDENTIFIER_CHAR.test(code.charAt(wordStart - 1))) wordStart -= 1;
518
- return JSX_KEYWORD_LEADS.has(code.slice(wordStart, cursor + 1));
519
- }
520
- function skipJsString(code, index) {
521
- const quote = code.charAt(index);
522
- let cursor = index + 1;
523
- while (cursor < code.length) {
524
- const char = code.charAt(cursor);
525
- if (char === "\\") cursor += 2;
526
- else if (char === quote) return cursor + 1;
527
- else if (char === "\n") return index + 1;
528
- else cursor += 1;
529
- }
530
- return index + 1;
531
- }
532
- function skipTemplate(code, index) {
533
- let cursor = index + 1;
534
- while (cursor < code.length) {
535
- const char = code.charAt(cursor);
536
- if (char === "\\") cursor += 2;
537
- else if (char === "`") return cursor + 1;
538
- else if (char === "$" && code.charAt(cursor + 1) === "{") {
539
- cursor = skipJsExpression(code, cursor + 1);
540
- if (cursor === FAILED) return FAILED;
541
- } else cursor += 1;
542
- }
543
- return FAILED;
544
- }
545
- function skipJsToken(code, index) {
546
- const char = code.charAt(index);
547
- const next = code.charAt(index + 1);
548
- if (char === "\"" || char === "'") return skipJsString(code, index);
549
- if (char === "`") return skipTemplate(code, index);
550
- if (char === "/" && next === "/") {
551
- const lineEnd = code.indexOf("\n", index);
552
- return lineEnd === -1 ? code.length : lineEnd;
553
- }
554
- if (char === "/" && next === "*") {
555
- const commentEnd = code.indexOf("*/", index + 2);
556
- return commentEnd === -1 ? FAILED : commentEnd + 2;
557
- }
558
- if (isTagStart(code, index) && startsJsxInExpression(code, index)) return skipElement(code, index);
559
- return index + 1;
560
- }
561
- function skipJsExpression(code, index) {
562
- let depth = 0;
563
- let cursor = index;
564
- while (cursor < code.length) {
565
- const char = code.charAt(cursor);
566
- if (char === "{" || char === "}") {
567
- depth += char === "{" ? 1 : -1;
568
- cursor += 1;
569
- if (depth === 0) return cursor;
570
- } else {
571
- cursor = skipJsToken(code, cursor);
572
- if (cursor === FAILED) return FAILED;
573
- }
574
- }
575
- return FAILED;
576
- }
577
- function skipTypeArguments(code, index) {
578
- let depth = 0;
579
- for (let cursor = index; cursor < code.length; cursor += 1) {
580
- const char = code.charAt(cursor);
581
- if (char === "<") depth += 1;
582
- else if (char === ">") {
583
- depth -= 1;
584
- if (depth === 0) return cursor + 1;
585
- }
586
- }
587
- return FAILED;
588
- }
589
- function skipAttributeToken(code, index) {
590
- const char = code.charAt(index);
591
- if (char === "{") return skipJsExpression(code, index);
592
- if (char === "\"" || char === "'") {
593
- const closingQuote = code.indexOf(char, index + 1);
594
- return closingQuote === -1 ? FAILED : closingQuote + 1;
595
- }
596
- return index + 1;
597
- }
598
- function readTagName(code, index) {
599
- let cursor = index;
600
- while (TAG_NAME_CHAR.test(code.charAt(cursor))) cursor += 1;
601
- return cursor;
602
- }
603
- function readOpeningTag(code, index) {
604
- const nameEnd = readTagName(code, index + 1);
605
- const name = code.slice(index + 1, nameEnd);
606
- let cursor = code.charAt(nameEnd) === "<" ? skipTypeArguments(code, nameEnd) : nameEnd;
607
- while (cursor !== FAILED && cursor < code.length) {
608
- const char = code.charAt(cursor);
609
- if (char === ">") return {
610
- end: cursor + 1,
611
- name,
612
- selfClosing: false
613
- };
614
- if (char === "/" && code.charAt(cursor + 1) === ">") return {
615
- end: cursor + 2,
616
- name,
617
- selfClosing: true
618
- };
619
- cursor = skipAttributeToken(code, cursor);
620
- }
621
- return null;
622
- }
623
- function readClosingTagEnd(code, index, name) {
624
- let cursor = index + 2;
625
- while (WHITESPACE$1.test(code.charAt(cursor))) cursor += 1;
626
- const nameEnd = readTagName(code, cursor);
627
- if (code.slice(cursor, nameEnd) !== name) return FAILED;
628
- cursor = nameEnd;
629
- while (WHITESPACE$1.test(code.charAt(cursor))) cursor += 1;
630
- return code.charAt(cursor) === ">" ? cursor + 1 : FAILED;
631
- }
632
- function skipChildren(code, index, name) {
633
- let cursor = index;
634
- while (cursor !== FAILED && cursor < code.length) {
635
- const char = code.charAt(cursor);
636
- if (char === "<" && code.charAt(cursor + 1) === "/") return readClosingTagEnd(code, cursor, name);
637
- if (char === "{") cursor = skipJsExpression(code, cursor);
638
- else if (isTagStart(code, cursor)) cursor = skipElement(code, cursor);
639
- else cursor += 1;
640
- }
641
- return FAILED;
642
- }
643
- function skipElement(code, index) {
644
- const tag = readOpeningTag(code, index);
645
- if (!tag) return FAILED;
646
- return tag.selfClosing ? tag.end : skipChildren(code, tag.end, tag.name);
647
- }
648
- function lineOffset(code, line) {
649
- if (!Number.isInteger(line) || line < 1) return FAILED;
650
- let offset = 0;
651
- for (let current = 1; current < line; current += 1) {
652
- const newline = code.indexOf("\n", offset);
653
- if (newline === -1) return FAILED;
654
- offset = newline + 1;
655
- }
656
- return offset;
657
- }
658
- function findTagStart(code, { column, lineEnd, lineStart }) {
659
- const origin = Math.min(lineStart + Math.max(column, 0), lineEnd);
660
- for (let back = 0; back <= MAX_TAG_LOOKBACK; back += 1) {
661
- const candidate = origin - back;
662
- if (candidate >= lineStart && isTagStart(code, candidate)) return candidate;
663
- }
664
- for (let candidate = origin + 1; candidate < lineEnd; candidate += 1) if (isTagStart(code, candidate)) return candidate;
665
- return FAILED;
666
- }
667
- function countNewlines(code, from, to) {
668
- let count = 0;
669
- let newline = code.indexOf("\n", from);
670
- while (newline !== -1 && newline < to) {
671
- count += 1;
672
- newline = code.indexOf("\n", newline + 1);
673
- }
674
- return count;
675
- }
676
- function jsxElementLines(code, line, column) {
677
- const lineStart = lineOffset(code, line);
678
- if (lineStart === FAILED) return null;
679
- const newline = code.indexOf("\n", lineStart);
680
- const tagStart = findTagStart(code, {
681
- column,
682
- lineEnd: newline === -1 ? code.length : newline,
683
- lineStart
684
- });
685
- if (tagStart === FAILED) return null;
686
- const elementEnd = skipElement(code, tagStart);
687
- if (elementEnd === FAILED) return null;
688
- return {
689
- end: line + countNewlines(code, tagStart, elementEnd - 1),
690
- start: line
691
- };
692
- }
693
496
  // src/server/source/server-frame.ts
694
497
  const QUERY_OR_HASH = /[?#].*$/;
695
498
  const SOURCE_MAPPING_URL = /\/\/# sourceMappingURL=(?<url>\S+)\s*$/;
@@ -861,10 +664,6 @@ async function locateSourceFile(fileName, roots) {
861
664
  if (refusal !== null) return failure$1(refusal, 403);
862
665
  return failure$1(`Could not find ${fileName} in ${roots.workspaceRoot}.`, 404);
863
666
  }
864
- function columnWithinLine(code, line, column) {
865
- const text = code.split("\n")[line - 1] ?? "";
866
- return column !== null && column < text.length ? column : null;
867
- }
868
667
  async function namedRequest(frame, roots) {
869
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);
870
669
  const mapped = isServerFrame(frame.fileName) ? await mapServerFrame(frame, roots.workspaceRoot) : {
@@ -892,14 +691,12 @@ async function readSourceFile(frame, roots) {
892
691
  const { realPath, relativePath, size } = located.value;
893
692
  if (size > MAX_SOURCE_BYTES) return failure$1(`${relativePath} is larger than 1 MB, too big to preview.`, 413);
894
693
  const code = await readFile(realPath, "utf-8");
895
- const column = request.line === null ? request.column : columnWithinLine(code, request.line, request.column);
896
694
  return {
897
695
  ok: true,
898
696
  value: {
899
697
  absolutePath: realPath,
900
698
  code,
901
- column,
902
- elementLines: request.line === null ? null : jsxElementLines(code, request.line, column ?? 0),
699
+ ...elementPlace(code, request),
903
700
  line: request.line,
904
701
  path: relativePath
905
702
  }
@@ -992,8 +789,8 @@ async function chatRequest(config, prompt) {
992
789
  }
993
790
  });
994
791
  }
995
- function createEndpointBackend(config) {
996
- return { run: async ({ env, prompt, signal }) => {
792
+ function createEndpointBackend(config, env) {
793
+ return { run: async ({ prompt, signal }) => {
997
794
  const reply = await callEndpoint({
998
795
  answer: chatCompletionSchema,
999
796
  body: await chatRequest(config, prompt),
@@ -1100,7 +897,7 @@ function createStopper(child) {
1100
897
  };
1101
898
  }
1102
899
  async function runProcess(call) {
1103
- const { promise, resolve } = Promise.withResolvers();
900
+ const { promise, resolve } = deferred();
1104
901
  const child = spawn(call.command, call.args, {
1105
902
  cwd: call.cwd,
1106
903
  env: agentEnv(call.env),
@@ -1179,8 +976,8 @@ function watchExit(child) {
1179
976
  child.stderr.setEncoding("utf-8").on("data", (chunk) => {
1180
977
  stderr = (stderr + chunk).slice(-4096);
1181
978
  });
1182
- const exit = Promise.withResolvers();
1183
- const ended = Promise.withResolvers();
979
+ const exit = deferred();
980
+ const ended = deferred();
1184
981
  child.once("error", (error) => {
1185
982
  ended.resolve(null);
1186
983
  exit.resolve({
@@ -1339,7 +1136,7 @@ function failure(error) {
1339
1136
  };
1340
1137
  }
1341
1138
  function deadline(signal) {
1342
- const { promise, resolve } = Promise.withResolvers();
1139
+ const { promise, resolve } = deferred();
1343
1140
  const onAbort = () => {
1344
1141
  resolve("aborted");
1345
1142
  };
@@ -1383,7 +1180,7 @@ async function cancelTurn(running) {
1383
1180
  const { connection, sessionId } = running;
1384
1181
  if (sessionId === null || connection.signal.aborted) return;
1385
1182
  await connection.agent.notify(methods.agent.session.cancel, { sessionId }).catch(() => null);
1386
- const { promise, resolve } = Promise.withResolvers();
1183
+ const { promise, resolve } = deferred();
1387
1184
  const timer = setTimeout(resolve, CANCEL_GRACE_MS, null);
1388
1185
  await Promise.race([running.turn.catch(() => null), promise]);
1389
1186
  clearTimeout(timer);
@@ -1780,18 +1577,18 @@ async function builtInAgent({ id, name }, env) {
1780
1577
  kind: "command"
1781
1578
  };
1782
1579
  }
1783
- async function configuredAgent(config, env) {
1580
+ async function configuredAgent(config, { env, spawnEnv }) {
1784
1581
  const agent = {
1785
1582
  id: agentIdOf(config.name),
1786
1583
  name: config.name
1787
1584
  };
1788
1585
  if (config.kind === "endpoint") return isEndpointReady(config, env) ? {
1789
1586
  agent,
1790
- backend: createEndpointBackend(config),
1587
+ backend: createEndpointBackend(config, env),
1791
1588
  checkSignIn: null,
1792
1589
  kind: "endpoint"
1793
1590
  } : null;
1794
- const command = await findCommand(config.command, env);
1591
+ const command = await findCommand(config.command, spawnEnv);
1795
1592
  return command === null ? null : {
1796
1593
  agent,
1797
1594
  backend: createAcpBackend({
@@ -1802,8 +1599,11 @@ async function configuredAgent(config, env) {
1802
1599
  kind: "command"
1803
1600
  };
1804
1601
  }
1805
- async function findAvailable({ agents, env }) {
1806
- return (await Promise.all([...BUILT_IN_AGENTS.map(async (agent) => await builtInAgent(agent, env)), ...agents.map(async (config) => await configuredAgent(config, env))])).filter((entry) => entry !== null);
1602
+ async function findAvailable({ agents, env, spawnEnv }) {
1603
+ return (await Promise.all([...BUILT_IN_AGENTS.map(async (agent) => await builtInAgent(agent, spawnEnv)), ...agents.map(async (config) => await configuredAgent(config, {
1604
+ env,
1605
+ spawnEnv
1606
+ }))])).filter((entry) => entry !== null);
1807
1607
  }
1808
1608
  async function listAgents(registered) {
1809
1609
  return await Promise.all(registered.map(async ({ agent, checkSignIn, kind }) => ({
@@ -2551,7 +2351,7 @@ var MistralStream = class {
2551
2351
  #keyOrigin;
2552
2352
  #chunkBytes;
2553
2353
  #session;
2554
- #done = Promise.withResolvers();
2354
+ #done = deferred();
2555
2355
  #queued = [];
2556
2356
  #text = "";
2557
2357
  #failure = null;
@@ -2805,15 +2605,16 @@ function transcriptionRoutes(transcription) {
2805
2605
  };
2806
2606
  }
2807
2607
  function createVoiceRoutes(context) {
2808
- const { env, voice } = context;
2608
+ const { env, spawnEnv, voice } = context;
2809
2609
  const store = new SessionFiles(() => projectFolder(env, projectId(context.root())));
2810
2610
  const agents = createAgentRegistry({
2811
2611
  agents: voice.agents,
2812
- env
2612
+ env,
2613
+ spawnEnv
2813
2614
  });
2814
2615
  const analyze = createAnalyzer({
2815
2616
  agents,
2816
- env,
2617
+ env: spawnEnv,
2817
2618
  store
2818
2619
  });
2819
2620
  const transcription = {
@@ -2862,6 +2663,23 @@ function readInteger(value, minimum) {
2862
2663
  const parsed = Number(value);
2863
2664
  return Number.isInteger(parsed) && parsed >= minimum ? parsed : null;
2864
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
+ }
2865
2683
  function coreRoutes(context) {
2866
2684
  return {
2867
2685
  [ENDPOINTS.source]: { GET: async (request) => {
@@ -2872,13 +2690,7 @@ function coreRoutes(context) {
2872
2690
  line: readInteger(searchParams.get("line"), 1)
2873
2691
  }, context.projectRoots()));
2874
2692
  } },
2875
- [ENDPOINTS.status]: { GET: async () => jsonResponse({
2876
- agents: await context.voice.agents(),
2877
- editor: context.settings.editor,
2878
- follow: context.voice.follow(),
2879
- marker: STATUS_MARKER,
2880
- transcribers: await context.voice.transcribers()
2881
- }) }
2693
+ [ENDPOINTS.status]: { GET: async (request) => jsonResponse(await statusOf(context, request)) }
2882
2694
  };
2883
2695
  }
2884
2696
  async function routeRequest(request, routes) {
@@ -2895,7 +2707,7 @@ async function rejectUnpaired(request, allowedHosts) {
2895
2707
  const isStatus = endpointOf(new URL(request.url).pathname) === ENDPOINTS.status;
2896
2708
  return jsonResponse(unpaired, isStatus ? 200 : 401);
2897
2709
  }
2898
- function createRouteHandler(options = {}, env = process.env) {
2710
+ function createRouteHandler(options = {}, env = process.env, spawnEnv = env) {
2899
2711
  const settings = resolveServerOptions(options, env);
2900
2712
  let roots = null;
2901
2713
  const projectRoots = () => {
@@ -2905,6 +2717,7 @@ function createRouteHandler(options = {}, env = process.env) {
2905
2717
  const voice = createVoiceRoutes({
2906
2718
  env,
2907
2719
  root: () => projectRoots().root,
2720
+ spawnEnv,
2908
2721
  voice: settings.voice
2909
2722
  });
2910
2723
  const routes = {
@@ -2916,14 +2729,14 @@ function createRouteHandler(options = {}, env = process.env) {
2916
2729
  ...voice.routes
2917
2730
  };
2918
2731
  return async (request) => {
2919
- 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);
2920
2733
  if (rejection) return rejection;
2921
2734
  try {
2922
- return await routeRequest(request, routes);
2735
+ return await rejectUnpaired(request, settings.allowedHosts) ?? await routeRequest(request, routes);
2923
2736
  } catch (error) {
2924
2737
  const reason = error instanceof Error ? error.message : String(error);
2925
2738
  return errorResponse(`Retouche route failed: ${reason}`, 500);
2926
2739
  }
2927
2740
  };
2928
2741
  }
2929
- export { withoutEnvFiles as a, withEnvFiles as i, BODY_LIMIT_ERROR as n, isLoopbackAddress as o, MAX_BODY_BYTES as r, createRouteHandler as t };
2742
+ export { appEnvs as a, appEnvFolders as i, BODY_LIMIT_ERROR as n, isLoopbackAddress as o, MAX_BODY_BYTES as r, createRouteHandler as t };
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-Ce6QQdAy.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
  }