scope-agent-workbench 0.2.0 → 0.2.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/bridge/agent-email-relay.mjs +160 -160
  3. package/bridge/app-server-websocket-transport.mjs +219 -219
  4. package/bridge/archive/service.mjs +130 -130
  5. package/bridge/auth-profile-failover.mjs +58 -58
  6. package/bridge/auth-profile-manager.mjs +215 -215
  7. package/bridge/capacity-recovery.mjs +90 -90
  8. package/bridge/gpu-usage-history.mjs +322 -322
  9. package/bridge/local/history.mjs +20 -5
  10. package/bridge/plugins/aliyun-dlc/monitor.mjs +236 -236
  11. package/bridge/plugins/aliyun-dlc/probe.mjs +701 -701
  12. package/bridge/private-gateway.mjs +371 -371
  13. package/bridge/private-start.mjs +22 -22
  14. package/bridge/probes/app-server-handoff-probe.mjs +87 -87
  15. package/bridge/probes/app-server-writer-probe.mjs +69 -69
  16. package/bridge/probes/assistant-search-probe.mjs +321 -321
  17. package/bridge/probes/dialogue-probe.mjs +462 -462
  18. package/bridge/probes/history-probe.mjs +430 -345
  19. package/bridge/probes/new-session-preflight.mjs +14 -14
  20. package/bridge/probes/profile-cancel-probe.mjs +17 -17
  21. package/bridge/probes/profile-delete-probe.mjs +26 -26
  22. package/bridge/probes/profile-list-probe.mjs +114 -114
  23. package/bridge/probes/profile-write-probe.mjs +109 -109
  24. package/bridge/probes/raw-context-probe.mjs +51 -51
  25. package/bridge/probes/remote-probe.mjs +627 -626
  26. package/bridge/probes/submission-probe.mjs +2 -2
  27. package/bridge/probes/takeover-probe.mjs +326 -326
  28. package/bridge/probes/vscode-open-preflight.mjs +21 -21
  29. package/bridge/providers/claude-interactive.py +463 -341
  30. package/bridge/providers/cli-command.mjs +103 -103
  31. package/bridge/providers/conversations.mjs +231 -231
  32. package/bridge/providers/native-commands.py +38 -38
  33. package/bridge/providers/native-session-state.mjs +14 -14
  34. package/bridge/providers/native-session-state.py +96 -96
  35. package/bridge/providers/remote-job.py +130 -130
  36. package/bridge/remote-app-server-command.mjs +121 -121
  37. package/bridge/remote-directory-listing.mjs +148 -148
  38. package/bridge/rollout-summary.mjs +20 -2
  39. package/bridge/routes/dialogue.mjs +48 -3
  40. package/bridge/routes/models.mjs +312 -312
  41. package/bridge/server.mjs +3357 -3332
  42. package/bridge/session-attachments.mjs +150 -150
  43. package/bridge/session-catalog/agy-history.py +141 -2
  44. package/bridge/session-catalog/catalog.mjs +17 -0
  45. package/bridge/session-catalog/probe.py +1207 -331
  46. package/bridge/session-catalog/routes.mjs +6 -0
  47. package/bridge/start.mjs +205 -205
  48. package/bridge/state-persistence.mjs +9 -1
  49. package/bridge/tmux-session-control.mjs +29 -29
  50. package/bridge/vscode-opener.mjs +157 -157
  51. package/bridge/web-terminal.mjs +52 -52
  52. package/bridge/workbench/manager-context.mjs +51 -51
  53. package/bridge/workbench/service.mjs +301 -301
  54. package/dist/client/.vite/manifest.json +4 -4
  55. package/dist/client/assets/{index-Enu1x0PS.js → index-BMior55c.js} +2 -2
  56. package/dist/client/assets/{layout-segment-context-CmJzExWq.js → layout-segment-context-DjGudgXn.js} +1 -1
  57. package/dist/client/assets/page-CJqXlhDs.js +551 -0
  58. package/dist/client/assets/page-LYzRz6_S.css +1 -0
  59. package/dist/client/favicon.svg +6 -6
  60. package/dist/server/__vite_rsc_assets_manifest.js +8 -8
  61. package/dist/server/index.js +7 -7
  62. package/dist/server/ssr/__vite_rsc_assets_manifest.js +8 -8
  63. package/dist/server/ssr/assets/{page-CYYyCnKD.js → page-BB9Dri2u.js} +2416 -271
  64. package/dist/server/ssr/assets/page-LYzRz6_S.css +1 -0
  65. package/dist/server/ssr/index.js +1 -1
  66. package/dist/server/ssr/vinext-server.json +1 -1
  67. package/dist/server/vinext-server.json +1 -1
  68. package/dist/server/wrangler.json +1 -1
  69. package/lib/browser-snapshot-cache.js +53 -53
  70. package/lib/formula-preview.js +1 -1
  71. package/lib/incremental-snapshot.js +300 -300
  72. package/lib/markdown-math.js +151 -151
  73. package/lib/remote-links.js +95 -95
  74. package/lib/runtime-config.js +70 -70
  75. package/lib/session-filters.js +38 -38
  76. package/lib/ssh-config.js +26 -26
  77. package/lib/stable-order.js +39 -39
  78. package/lib/subagent-display-prefs.ts +130 -0
  79. package/package.json +1 -1
  80. package/scripts/agent-email-relay.mjs +104 -104
  81. package/scripts/email-notification-cli.mjs +28 -28
  82. package/scripts/enable-private-access.ps1 +109 -109
  83. package/scripts/fixtures/native-conversations.mjs +164 -6
  84. package/scripts/fixtures/workbench-conversations.mjs +475 -352
  85. package/scripts/preview-workbench.mjs +669 -669
  86. package/dist/client/assets/page-COBv6VWj.css +0 -1
  87. package/dist/client/assets/page-DVjU6VG_.js +0 -550
  88. package/dist/server/ssr/assets/page-COBv6VWj.css +0 -1
@@ -1,151 +1,151 @@
1
- const CODE_TOKEN_PREFIX = "\uE000SCOPE_CODE_";
2
- const CODE_TOKEN_SUFFIX = "\uE001";
3
-
4
- function protectCode(source) {
5
- const protectedCode = [];
6
- const protect = (value) => {
7
- const index = protectedCode.push(value) - 1;
8
- return `${CODE_TOKEN_PREFIX}${index}${CODE_TOKEN_SUFFIX}`;
9
- };
10
-
11
- // Shield fenced blocks first, then inline code spans. LaTeX-looking examples in
12
- // code must stay literal instead of turning into rendered equations.
13
- const withoutFences = source.replace(
14
- /(^|\n)[ \t]{0,3}(`{3,}|~{3,})[^\n]*(?:\n[\s\S]*?\n[ \t]{0,3}\2[ \t]*(?=\n|$)|$)/g,
15
- protect,
16
- );
17
- const withoutCode = withoutFences.replace(/(`+)([\s\S]*?)\1/g, protect);
18
-
19
- return {
20
- value: withoutCode,
21
- restore(value) {
22
- return value.replace(
23
- new RegExp(`${CODE_TOKEN_PREFIX}(\\d+)${CODE_TOKEN_SUFFIX}`, "g"),
24
- (_match, index) => protectedCode[Number(index)] ?? "",
25
- );
26
- },
27
- };
28
- }
29
-
30
- function normalizeMathEnvironments(value) {
31
- return value.replace(
32
- /(?<!\\)\\begin\{(equation\*?|displaymath|align\*?|aligned|gather\*?|gathered|multline\*?|split)\}([\s\S]*?)\\end\{\1\}/g,
33
- (_match, environment, body) => {
34
- const content = body.trim();
35
- let displayContent = content;
36
-
37
- if (/^align\*?$/.test(environment) || environment === "aligned" || environment === "split") {
38
- displayContent = `\\begin{aligned}\n${content}\n\\end{aligned}`;
39
- } else if (/^gather\*?$/.test(environment) || environment === "gathered") {
40
- displayContent = `\\begin{gathered}\n${content}\n\\end{gathered}`;
41
- } else if (/^multline\*?$/.test(environment)) {
42
- displayContent = `\\begin{aligned}\n${content}\n\\end{aligned}`;
43
- }
44
-
45
- return `\n\n$$\n${displayContent}\n$$\n\n`;
46
- },
47
- );
48
- }
49
-
50
- /**
51
- * Make the LaTeX delimiters commonly emitted by Codex compatible with
52
- * remark-math, while leaving fenced and inline code untouched.
53
- *
54
- * @param {string} source
55
- * @returns {string}
56
- */
57
- export function normalizeLatexDelimiters(source) {
58
- if (!source || !source.includes("\\")) {
59
- return source;
60
- }
61
-
62
- const protectedSource = protectCode(source);
63
- let normalized = normalizeMathEnvironments(protectedSource.value);
64
-
65
- normalized = normalized.replace(
66
- /(?<!\\)\\\[([\s\S]*?)(?<!\\)\\\]/g,
67
- (_match, body) => `\n\n$$\n${body.trim()}\n$$\n\n`,
68
- );
69
- normalized = normalized.replace(
70
- /(?<!\\)\\\(([\s\S]*?)(?<!\\)\\\)/g,
71
- (_match, body) => `$${body.trim()}$`,
72
- );
73
-
74
- return protectedSource.restore(normalized);
75
- }
76
-
77
- function basenameFromFileUrl(uri) {
78
- const withoutHash = uri.split("#", 1)[0].split("?", 1)[0];
79
- const raw = withoutHash.split("/").filter(Boolean).pop() || uri;
80
- try {
81
- return decodeURIComponent(raw);
82
- } catch {
83
- return raw;
84
- }
85
- }
86
-
87
- /**
88
- * Normalize AGY / HTML-style file:// media and links outside code blocks so
89
- * react-markdown parses spaces in file:// targets, simple <img>/<video> tags,
90
- * and bare file:/// links cleanly through SCOPE's sanitized media pipeline.
91
- *
92
- * @param {string} source
93
- * @returns {string}
94
- */
95
- export function normalizeMarkdownMedia(source) {
96
- if (
97
- !source ||
98
- (!source.includes("file:") && !/<(?:img|video)\b/i.test(source))
99
- ) {
100
- return source;
101
- }
102
-
103
- const protectedSource = protectCode(source);
104
- let text = protectedSource.value;
105
-
106
- // Convert simple <img src="..."> and <video src="..."> tags into safe Markdown embeds.
107
- text = text.replace(
108
- /<(img|video)\b([^>]*?)\/?>\s*(?:<\/video>)?/gi,
109
- (match, tag, attrs) => {
110
- const srcMatch = attrs.match(/\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)')/i);
111
- const src = (srcMatch?.[1] || srcMatch?.[2] || "").trim();
112
- if (!src) return match;
113
- const altMatch = attrs.match(/\balt\s*=\s*(?:"([^"]*)"|'([^']*)')/i);
114
- const label = (altMatch?.[1] || altMatch?.[2] || basenameFromFileUrl(src) || tag).trim();
115
- return `![${label}](<${src}>)`;
116
- },
117
- );
118
-
119
- // Wrap unencoded file:// targets containing spaces inside Markdown links/images
120
- // as angle-bracketed destinations: ![cap](file:///a/b c.png) -> ![cap](<file:///a/b c.png>)
121
- text = text.replace(
122
- /(!?\[[^\]]*\]\()(file:\/\/\/?[^)\r\n<>]*[ \t][^)\r\n<>]*)(\))/gi,
123
- (_m, open, target, close) => `${open}<${target.trim()}>${close}`,
124
- );
125
-
126
- // Protect existing Markdown links/images before autolinking bare file:/// URIs.
127
- const links = [];
128
- text = text.replace(
129
- /!?\[[^\]]*\]\((?:<[^>\r\n]+>|[^)\r\n]+)\)/g,
130
- (match) => `\uE002SCOPE_LINK_${links.push(match) - 1}\uE003`,
131
- );
132
-
133
- // Autolink bare file:///... URLs (common in Antigravity / agent prose).
134
- text = text.replace(
135
- /(^|[\s(>\[(【::])(file:\/\/\/[^\s<>)"'\])】]+)/gi,
136
- (_match, prefix, rawUri) => {
137
- const trailing = rawUri.match(/[.,;:!?。,;:!?]+$/)?.[0] || "";
138
- const uri = trailing ? rawUri.slice(0, -trailing.length) : rawUri;
139
- const label = basenameFromFileUrl(uri);
140
- const isMedia = /\.(?:png|jpe?g|gif|webp|svg|bmp|ico|avif|mp4|m4v|webm|ogv|mov)(?:[?#]|$)/i.test(uri);
141
- return `${prefix}${isMedia ? "!" : ""}[${label}](<${uri}>)${trailing}`;
142
- },
143
- );
144
-
145
- text = text.replace(
146
- /\uE002SCOPE_LINK_(\d+)\uE003/g,
147
- (_match, idx) => links[Number(idx)] ?? "",
148
- );
149
-
150
- return protectedSource.restore(text);
151
- }
1
+ const CODE_TOKEN_PREFIX = "\uE000SCOPE_CODE_";
2
+ const CODE_TOKEN_SUFFIX = "\uE001";
3
+
4
+ function protectCode(source) {
5
+ const protectedCode = [];
6
+ const protect = (value) => {
7
+ const index = protectedCode.push(value) - 1;
8
+ return `${CODE_TOKEN_PREFIX}${index}${CODE_TOKEN_SUFFIX}`;
9
+ };
10
+
11
+ // Shield fenced blocks first, then inline code spans. LaTeX-looking examples in
12
+ // code must stay literal instead of turning into rendered equations.
13
+ const withoutFences = source.replace(
14
+ /(^|\n)[ \t]{0,3}(`{3,}|~{3,})[^\n]*(?:\n[\s\S]*?\n[ \t]{0,3}\2[ \t]*(?=\n|$)|$)/g,
15
+ protect,
16
+ );
17
+ const withoutCode = withoutFences.replace(/(`+)([\s\S]*?)\1/g, protect);
18
+
19
+ return {
20
+ value: withoutCode,
21
+ restore(value) {
22
+ return value.replace(
23
+ new RegExp(`${CODE_TOKEN_PREFIX}(\\d+)${CODE_TOKEN_SUFFIX}`, "g"),
24
+ (_match, index) => protectedCode[Number(index)] ?? "",
25
+ );
26
+ },
27
+ };
28
+ }
29
+
30
+ function normalizeMathEnvironments(value) {
31
+ return value.replace(
32
+ /(?<!\\)\\begin\{(equation\*?|displaymath|align\*?|aligned|gather\*?|gathered|multline\*?|split)\}([\s\S]*?)\\end\{\1\}/g,
33
+ (_match, environment, body) => {
34
+ const content = body.trim();
35
+ let displayContent = content;
36
+
37
+ if (/^align\*?$/.test(environment) || environment === "aligned" || environment === "split") {
38
+ displayContent = `\\begin{aligned}\n${content}\n\\end{aligned}`;
39
+ } else if (/^gather\*?$/.test(environment) || environment === "gathered") {
40
+ displayContent = `\\begin{gathered}\n${content}\n\\end{gathered}`;
41
+ } else if (/^multline\*?$/.test(environment)) {
42
+ displayContent = `\\begin{aligned}\n${content}\n\\end{aligned}`;
43
+ }
44
+
45
+ return `\n\n$$\n${displayContent}\n$$\n\n`;
46
+ },
47
+ );
48
+ }
49
+
50
+ /**
51
+ * Make the LaTeX delimiters commonly emitted by Codex compatible with
52
+ * remark-math, while leaving fenced and inline code untouched.
53
+ *
54
+ * @param {string} source
55
+ * @returns {string}
56
+ */
57
+ export function normalizeLatexDelimiters(source) {
58
+ if (!source || !source.includes("\\")) {
59
+ return source;
60
+ }
61
+
62
+ const protectedSource = protectCode(source);
63
+ let normalized = normalizeMathEnvironments(protectedSource.value);
64
+
65
+ normalized = normalized.replace(
66
+ /(?<!\\)\\\[([\s\S]*?)(?<!\\)\\\]/g,
67
+ (_match, body) => `\n\n$$\n${body.trim()}\n$$\n\n`,
68
+ );
69
+ normalized = normalized.replace(
70
+ /(?<!\\)\\\(([\s\S]*?)(?<!\\)\\\)/g,
71
+ (_match, body) => `$${body.trim()}$`,
72
+ );
73
+
74
+ return protectedSource.restore(normalized);
75
+ }
76
+
77
+ function basenameFromFileUrl(uri) {
78
+ const withoutHash = uri.split("#", 1)[0].split("?", 1)[0];
79
+ const raw = withoutHash.split("/").filter(Boolean).pop() || uri;
80
+ try {
81
+ return decodeURIComponent(raw);
82
+ } catch {
83
+ return raw;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Normalize AGY / HTML-style file:// media and links outside code blocks so
89
+ * react-markdown parses spaces in file:// targets, simple <img>/<video> tags,
90
+ * and bare file:/// links cleanly through SCOPE's sanitized media pipeline.
91
+ *
92
+ * @param {string} source
93
+ * @returns {string}
94
+ */
95
+ export function normalizeMarkdownMedia(source) {
96
+ if (
97
+ !source ||
98
+ (!source.includes("file:") && !/<(?:img|video)\b/i.test(source))
99
+ ) {
100
+ return source;
101
+ }
102
+
103
+ const protectedSource = protectCode(source);
104
+ let text = protectedSource.value;
105
+
106
+ // Convert simple <img src="..."> and <video src="..."> tags into safe Markdown embeds.
107
+ text = text.replace(
108
+ /<(img|video)\b([^>]*?)\/?>\s*(?:<\/video>)?/gi,
109
+ (match, tag, attrs) => {
110
+ const srcMatch = attrs.match(/\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)')/i);
111
+ const src = (srcMatch?.[1] || srcMatch?.[2] || "").trim();
112
+ if (!src) return match;
113
+ const altMatch = attrs.match(/\balt\s*=\s*(?:"([^"]*)"|'([^']*)')/i);
114
+ const label = (altMatch?.[1] || altMatch?.[2] || basenameFromFileUrl(src) || tag).trim();
115
+ return `![${label}](<${src}>)`;
116
+ },
117
+ );
118
+
119
+ // Wrap unencoded file:// targets containing spaces inside Markdown links/images
120
+ // as angle-bracketed destinations: ![cap](file:///a/b c.png) -> ![cap](<file:///a/b c.png>)
121
+ text = text.replace(
122
+ /(!?\[[^\]]*\]\()(file:\/\/\/?[^)\r\n<>]*[ \t][^)\r\n<>]*)(\))/gi,
123
+ (_m, open, target, close) => `${open}<${target.trim()}>${close}`,
124
+ );
125
+
126
+ // Protect existing Markdown links/images before autolinking bare file:/// URIs.
127
+ const links = [];
128
+ text = text.replace(
129
+ /!?\[[^\]]*\]\((?:<[^>\r\n]+>|[^)\r\n]+)\)/g,
130
+ (match) => `\uE002SCOPE_LINK_${links.push(match) - 1}\uE003`,
131
+ );
132
+
133
+ // Autolink bare file:///... URLs (common in Antigravity / agent prose).
134
+ text = text.replace(
135
+ /(^|[\s(>\[(【::])(file:\/\/\/[^\s<>)"'\])】]+)/gi,
136
+ (_match, prefix, rawUri) => {
137
+ const trailing = rawUri.match(/[.,;:!?。,;:!?]+$/)?.[0] || "";
138
+ const uri = trailing ? rawUri.slice(0, -trailing.length) : rawUri;
139
+ const label = basenameFromFileUrl(uri);
140
+ const isMedia = /\.(?:png|jpe?g|gif|webp|svg|bmp|ico|avif|mp4|m4v|webm|ogv|mov)(?:[?#]|$)/i.test(uri);
141
+ return `${prefix}${isMedia ? "!" : ""}[${label}](<${uri}>)${trailing}`;
142
+ },
143
+ );
144
+
145
+ text = text.replace(
146
+ /\uE002SCOPE_LINK_(\d+)\uE003/g,
147
+ (_match, idx) => links[Number(idx)] ?? "",
148
+ );
149
+
150
+ return protectedSource.restore(text);
151
+ }
@@ -1,95 +1,95 @@
1
- const FILE_URL_PREFIX = /^file:\/\/|^file:\//i;
2
- const EXTERNAL_SCHEME_PREFIX = /^[a-z][a-z0-9+.-]*:/i;
3
-
4
- function decodeRemotePath(value) {
5
- try {
6
- return decodeURIComponent(value);
7
- } catch {
8
- return value;
9
- }
10
- }
11
-
12
- function normalizePosixAbsolutePath(value) {
13
- const segments = [];
14
- for (const segment of value.replaceAll("\\", "/").split("/")) {
15
- if (!segment || segment === ".") continue;
16
- if (segment === "..") segments.pop();
17
- else segments.push(segment);
18
- }
19
- return `/${segments.join("/")}`;
20
- }
21
-
22
- function splitLineAndColumn(value) {
23
- const withColumn = value.match(/^(.*):(\d+):(\d+)$/);
24
- if (withColumn?.[1]) {
25
- return {
26
- path: withColumn[1],
27
- line: Number(withColumn[2]),
28
- column: Number(withColumn[3]),
29
- };
30
- }
31
- const withLine = value.match(/^(.*):(\d+)$/);
32
- if (!withLine?.[1]) return { path: value, line: null, column: null };
33
- return {
34
- path: withLine[1],
35
- line: Number(withLine[2]),
36
- column: null,
37
- };
38
- }
39
- /**
40
- * Resolve an absolute or relative Markdown href into a remote file target.
41
- * Supports Codex's common `file.md:line[:column]` and `file.md#Lline` forms.
42
- *
43
- * @param {string | undefined} href
44
- * @param {string | undefined} cwd
45
- * @returns {{ path: string, line: number | null, column: number | null } | null}
46
- */
47
- export function remoteFileTargetFromMarkdownHref(href, cwd = "") {
48
- if (!href) return null;
49
-
50
- const candidate = href.trim();
51
- let pathname = "";
52
- let fragment = "";
53
-
54
- if (FILE_URL_PREFIX.test(candidate)) {
55
- try {
56
- const normalizedUri = /^file:\/(?!\/)/i.test(candidate)
57
- ? `file://${candidate.slice("file:".length)}`
58
- : candidate;
59
- const parsed = new URL(normalizedUri);
60
- if (parsed.protocol !== "file:") return null;
61
- // The session host supplies the filesystem; never silently drop a URI authority.
62
- if (parsed.hostname && parsed.hostname !== "localhost") return null;
63
- pathname = parsed.pathname;
64
- fragment = parsed.hash.slice(1);
65
- } catch {
66
- return null;
67
- }
68
- } else {
69
- const hashIndex = candidate.indexOf("#");
70
- const withoutHash = hashIndex >= 0 ? candidate.slice(0, hashIndex) : candidate;
71
- fragment = hashIndex >= 0 ? candidate.slice(hashIndex + 1) : "";
72
- pathname = withoutHash.split("?", 1)[0];
73
- if (!pathname || pathname.startsWith("//")) return null;
74
- const windowsAbsolute = /^[a-z]:[\\/]/i.test(pathname);
75
- if (!pathname.startsWith("/") && !windowsAbsolute && EXTERNAL_SCHEME_PREFIX.test(pathname)) {
76
- return null;
77
- }
78
- if (!pathname.startsWith("/") && !windowsAbsolute) {
79
- if (!cwd.startsWith("/") && !/^[a-z]:[\\/]/i.test(cwd)) return null;
80
- pathname = `${cwd.replace(/\/+$/, "")}/${pathname}`;
81
- }
82
- }
83
-
84
- const positioned = splitLineAndColumn(decodeRemotePath(pathname));
85
- if (/[\u0000-\u001f\u007f]/.test(positioned.path)) return null;
86
- const normalizedPath = normalizePosixAbsolutePath(positioned.path);
87
- const fragmentMatch = fragment.match(/^L(\d+)(?:C(\d+))?(?:-L?\d+(?:C\d+)?)?$/i);
88
- return {
89
- path: /^\/[a-z]:\//i.test(normalizedPath) ? normalizedPath.slice(1) : normalizedPath,
90
- line: fragmentMatch ? Number(fragmentMatch[1]) : positioned.line,
91
- column: fragmentMatch?.[2]
92
- ? Number(fragmentMatch[2])
93
- : positioned.column,
94
- };
95
- }
1
+ const FILE_URL_PREFIX = /^file:\/\/|^file:\//i;
2
+ const EXTERNAL_SCHEME_PREFIX = /^[a-z][a-z0-9+.-]*:/i;
3
+
4
+ function decodeRemotePath(value) {
5
+ try {
6
+ return decodeURIComponent(value);
7
+ } catch {
8
+ return value;
9
+ }
10
+ }
11
+
12
+ function normalizePosixAbsolutePath(value) {
13
+ const segments = [];
14
+ for (const segment of value.replaceAll("\\", "/").split("/")) {
15
+ if (!segment || segment === ".") continue;
16
+ if (segment === "..") segments.pop();
17
+ else segments.push(segment);
18
+ }
19
+ return `/${segments.join("/")}`;
20
+ }
21
+
22
+ function splitLineAndColumn(value) {
23
+ const withColumn = value.match(/^(.*):(\d+):(\d+)$/);
24
+ if (withColumn?.[1]) {
25
+ return {
26
+ path: withColumn[1],
27
+ line: Number(withColumn[2]),
28
+ column: Number(withColumn[3]),
29
+ };
30
+ }
31
+ const withLine = value.match(/^(.*):(\d+)$/);
32
+ if (!withLine?.[1]) return { path: value, line: null, column: null };
33
+ return {
34
+ path: withLine[1],
35
+ line: Number(withLine[2]),
36
+ column: null,
37
+ };
38
+ }
39
+ /**
40
+ * Resolve an absolute or relative Markdown href into a remote file target.
41
+ * Supports Codex's common `file.md:line[:column]` and `file.md#Lline` forms.
42
+ *
43
+ * @param {string | undefined} href
44
+ * @param {string | undefined} cwd
45
+ * @returns {{ path: string, line: number | null, column: number | null } | null}
46
+ */
47
+ export function remoteFileTargetFromMarkdownHref(href, cwd = "") {
48
+ if (!href) return null;
49
+
50
+ const candidate = href.trim();
51
+ let pathname = "";
52
+ let fragment = "";
53
+
54
+ if (FILE_URL_PREFIX.test(candidate)) {
55
+ try {
56
+ const normalizedUri = /^file:\/(?!\/)/i.test(candidate)
57
+ ? `file://${candidate.slice("file:".length)}`
58
+ : candidate;
59
+ const parsed = new URL(normalizedUri);
60
+ if (parsed.protocol !== "file:") return null;
61
+ // The session host supplies the filesystem; never silently drop a URI authority.
62
+ if (parsed.hostname && parsed.hostname !== "localhost") return null;
63
+ pathname = parsed.pathname;
64
+ fragment = parsed.hash.slice(1);
65
+ } catch {
66
+ return null;
67
+ }
68
+ } else {
69
+ const hashIndex = candidate.indexOf("#");
70
+ const withoutHash = hashIndex >= 0 ? candidate.slice(0, hashIndex) : candidate;
71
+ fragment = hashIndex >= 0 ? candidate.slice(hashIndex + 1) : "";
72
+ pathname = withoutHash.split("?", 1)[0];
73
+ if (!pathname || pathname.startsWith("//")) return null;
74
+ const windowsAbsolute = /^[a-z]:[\\/]/i.test(pathname);
75
+ if (!pathname.startsWith("/") && !windowsAbsolute && EXTERNAL_SCHEME_PREFIX.test(pathname)) {
76
+ return null;
77
+ }
78
+ if (!pathname.startsWith("/") && !windowsAbsolute) {
79
+ if (!cwd.startsWith("/") && !/^[a-z]:[\\/]/i.test(cwd)) return null;
80
+ pathname = `${cwd.replace(/\/+$/, "")}/${pathname}`;
81
+ }
82
+ }
83
+
84
+ const positioned = splitLineAndColumn(decodeRemotePath(pathname));
85
+ if (/[\u0000-\u001f\u007f]/.test(positioned.path)) return null;
86
+ const normalizedPath = normalizePosixAbsolutePath(positioned.path);
87
+ const fragmentMatch = fragment.match(/^L(\d+)(?:C(\d+))?(?:-L?\d+(?:C\d+)?)?$/i);
88
+ return {
89
+ path: /^\/[a-z]:\//i.test(normalizedPath) ? normalizedPath.slice(1) : normalizedPath,
90
+ line: fragmentMatch ? Number(fragmentMatch[1]) : positioned.line,
91
+ column: fragmentMatch?.[2]
92
+ ? Number(fragmentMatch[2])
93
+ : positioned.column,
94
+ };
95
+ }
@@ -1,70 +1,70 @@
1
- export const DEFAULT_HOST_RUNTIME_CONFIG = Object.freeze({
2
- preLaunchCommand: "",
3
- updatePreCommand: "",
4
- yolo: true,
5
- residentSessionLimit: null,
6
- updatedAt: null,
7
- });
8
-
9
- export function normalizePreLaunchCommand(value, fallback = "") {
10
- const candidate = typeof value === "string" ? value : fallback;
11
- return String(candidate || "")
12
- .replaceAll("\0", "")
13
- .replace(/\r\n?/g, "\n")
14
- .trim()
15
- .slice(0, 4_000);
16
- }
17
-
18
- export function normalizeResidentSessionLimit(value, fallback = null) {
19
- const defaultLimit =
20
- Number.isInteger(fallback) && fallback >= 0 && fallback <= 64
21
- ? fallback
22
- : null;
23
- if (value === undefined) return defaultLimit;
24
- if (value === null || value === "") return null;
25
- const numeric =
26
- typeof value === "number" ? value : Number(String(value).trim());
27
- return Number.isInteger(numeric) && numeric >= 0 && numeric <= 64
28
- ? numeric
29
- : defaultLimit;
30
- }
31
-
32
- export function normalizeHostRuntimeConfig(value, fallback = {}) {
33
- const base = {
34
- ...DEFAULT_HOST_RUNTIME_CONFIG,
35
- ...(fallback && typeof fallback === "object" ? fallback : {}),
36
- };
37
- return {
38
- preLaunchCommand: normalizePreLaunchCommand(
39
- value?.preLaunchCommand,
40
- base.preLaunchCommand,
41
- ),
42
- updatePreCommand: normalizePreLaunchCommand(
43
- value?.updatePreCommand,
44
- base.updatePreCommand,
45
- ),
46
- yolo: typeof value?.yolo === "boolean" ? value.yolo : base.yolo !== false,
47
- residentSessionLimit: normalizeResidentSessionLimit(
48
- value?.residentSessionLimit,
49
- base.residentSessionLimit,
50
- ),
51
- updatedAt:
52
- typeof value?.updatedAt === "string" ? value.updatedAt : base.updatedAt || null,
53
- };
54
- }
55
-
56
- export function runtimePolicy(yolo = true) {
57
- return yolo === false
58
- ? {
59
- yolo: false,
60
- approvalPolicy: "on-request",
61
- sandbox: "workspace-write",
62
- sandboxPolicy: { type: "workspaceWrite" },
63
- }
64
- : {
65
- yolo: true,
66
- approvalPolicy: "never",
67
- sandbox: "danger-full-access",
68
- sandboxPolicy: { type: "dangerFullAccess" },
69
- };
70
- }
1
+ export const DEFAULT_HOST_RUNTIME_CONFIG = Object.freeze({
2
+ preLaunchCommand: "",
3
+ updatePreCommand: "",
4
+ yolo: true,
5
+ residentSessionLimit: null,
6
+ updatedAt: null,
7
+ });
8
+
9
+ export function normalizePreLaunchCommand(value, fallback = "") {
10
+ const candidate = typeof value === "string" ? value : fallback;
11
+ return String(candidate || "")
12
+ .replaceAll("\0", "")
13
+ .replace(/\r\n?/g, "\n")
14
+ .trim()
15
+ .slice(0, 4_000);
16
+ }
17
+
18
+ export function normalizeResidentSessionLimit(value, fallback = null) {
19
+ const defaultLimit =
20
+ Number.isInteger(fallback) && fallback >= 0 && fallback <= 64
21
+ ? fallback
22
+ : null;
23
+ if (value === undefined) return defaultLimit;
24
+ if (value === null || value === "") return null;
25
+ const numeric =
26
+ typeof value === "number" ? value : Number(String(value).trim());
27
+ return Number.isInteger(numeric) && numeric >= 0 && numeric <= 64
28
+ ? numeric
29
+ : defaultLimit;
30
+ }
31
+
32
+ export function normalizeHostRuntimeConfig(value, fallback = {}) {
33
+ const base = {
34
+ ...DEFAULT_HOST_RUNTIME_CONFIG,
35
+ ...(fallback && typeof fallback === "object" ? fallback : {}),
36
+ };
37
+ return {
38
+ preLaunchCommand: normalizePreLaunchCommand(
39
+ value?.preLaunchCommand,
40
+ base.preLaunchCommand,
41
+ ),
42
+ updatePreCommand: normalizePreLaunchCommand(
43
+ value?.updatePreCommand,
44
+ base.updatePreCommand,
45
+ ),
46
+ yolo: typeof value?.yolo === "boolean" ? value.yolo : base.yolo !== false,
47
+ residentSessionLimit: normalizeResidentSessionLimit(
48
+ value?.residentSessionLimit,
49
+ base.residentSessionLimit,
50
+ ),
51
+ updatedAt:
52
+ typeof value?.updatedAt === "string" ? value.updatedAt : base.updatedAt || null,
53
+ };
54
+ }
55
+
56
+ export function runtimePolicy(yolo = true) {
57
+ return yolo === false
58
+ ? {
59
+ yolo: false,
60
+ approvalPolicy: "on-request",
61
+ sandbox: "workspace-write",
62
+ sandboxPolicy: { type: "workspaceWrite" },
63
+ }
64
+ : {
65
+ yolo: true,
66
+ approvalPolicy: "never",
67
+ sandbox: "danger-full-access",
68
+ sandboxPolicy: { type: "dangerFullAccess" },
69
+ };
70
+ }