dsh-extra-paths 0.2.0 → 0.3.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.
Files changed (52) hide show
  1. package/README.md +192 -28
  2. package/README.zh.md +166 -21
  3. package/lib/argv.js +96 -24
  4. package/lib/argv.js.map +1 -1
  5. package/lib/client.js +1310 -450
  6. package/lib/config.js +140 -44
  7. package/lib/config.js.map +1 -1
  8. package/lib/context.js +48 -12
  9. package/lib/context.js.map +1 -1
  10. package/lib/denial.js +132 -0
  11. package/lib/denial.js.map +1 -0
  12. package/lib/index.js +40 -5
  13. package/lib/index.js.map +1 -1
  14. package/lib/name-rule.js +217 -0
  15. package/lib/name-rule.js.map +1 -0
  16. package/lib/paths.js +155 -27
  17. package/lib/paths.js.map +1 -1
  18. package/lib/pattern.js +128 -62
  19. package/lib/pattern.js.map +1 -1
  20. package/lib/platform.js +325 -0
  21. package/lib/platform.js.map +1 -0
  22. package/lib/preview.js +47 -20
  23. package/lib/preview.js.map +1 -1
  24. package/lib/resolve.js +345 -64
  25. package/lib/resolve.js.map +1 -1
  26. package/lib/schema.js +19 -6
  27. package/lib/schema.js.map +1 -1
  28. package/lib/shell-dialect.js +92 -0
  29. package/lib/shell-dialect.js.map +1 -0
  30. package/lib/tool-guard.js +214 -0
  31. package/lib/tool-guard.js.map +1 -0
  32. package/lib/types/argv.d.ts +50 -12
  33. package/lib/types/config.d.ts +29 -13
  34. package/lib/types/context.d.ts +6 -1
  35. package/lib/types/denial.d.ts +88 -0
  36. package/lib/types/index.d.ts +8 -4
  37. package/lib/types/name-rule.d.ts +112 -0
  38. package/lib/types/paths.d.ts +55 -10
  39. package/lib/types/pattern.d.ts +43 -5
  40. package/lib/types/platform.d.ts +148 -0
  41. package/lib/types/preview.d.ts +39 -3
  42. package/lib/types/resolve.d.ts +129 -23
  43. package/lib/types/schema.d.ts +24 -8
  44. package/lib/types/shell-dialect.d.ts +60 -0
  45. package/lib/types/tool-guard.d.ts +103 -0
  46. package/lib/types/wrap-fs.d.ts +86 -4
  47. package/lib/types/wrap-sandbox.d.ts +26 -6
  48. package/lib/wrap-fs.js +323 -47
  49. package/lib/wrap-fs.js.map +1 -1
  50. package/lib/wrap-sandbox.js +149 -12
  51. package/lib/wrap-sandbox.js.map +1 -1
  52. package/package.json +3 -1
package/lib/client.js CHANGED
@@ -29,24 +29,287 @@ window.__ModuleLoader__.load({
29
29
  let react = require("react");
30
30
  react = __toESM(react, 1);
31
31
  let react_jsx_runtime = require("react/jsx-runtime");
32
- //#region src/client/paths.ts
32
+ //#region src/client/locales.ts
33
+ /** English copy — the fallback locale for every non-Chinese UI language. */
34
+ const en = {
35
+ navLabel: "Extra writable paths",
36
+ summaryLoading: "Extra writable paths: loading…",
37
+ summaryUnavailable: "Extra writable paths: not offered by this host",
38
+ summaryEmpty: "Extra writable paths: not configured yet",
39
+ summaryCount: "Extra writable paths: {count} saved · writing needs no approval",
40
+ introCollapsed: "Extra writable paths outside the workspace, writable without approval; edit them line by line.",
41
+ expand: "Show details",
42
+ collapse: "Hide details",
43
+ introBefore: "These paths stay writable outside the session workspace, ",
44
+ introNoApproval: "without approval",
45
+ introAfter: "; each rule's access level and surfaces decide what the write tools and the terminal may do.",
46
+ introRuleBefore: "Relative spellings resolve against the base workspace; enforcement uses ",
47
+ introRuleEmphasis: "each session's own workspace",
48
+ introRuleAfter: ", so one configuration points at different directories in different sessions. deny/read rules win over writable ones.",
49
+ baseWorkspace: "Base workspace",
50
+ notSelected: "(none selected)",
51
+ basePlaceholder: "Absolute path (drive letters / UNC included), or start with ~/",
52
+ manualBase: "Type a path",
53
+ pickBase: "Pick from list",
54
+ baseHint: "Preview and inline resolution only",
55
+ baseForeign: "This host cannot express that base path (platform mismatch); the same configuration still works on a matching host.",
56
+ baseWaiting: "Waiting for the host platform facts (first preview)…",
57
+ save: "Save",
58
+ saving: "Saving…",
59
+ dirty: "Unsaved changes",
60
+ synced: "In sync with the configuration",
61
+ textMode: "Text mode",
62
+ textModeHint: "One rule per line: path | access | surfaces. The last two may be omitted — they then inherit the defaults shown below. Expand \"Examples and supported forms\" for the common spellings.",
63
+ editorDefaults: "Omitted fields use: access = {access}, surfaces = {surfaces} (from the config document: defaultAccess / defaultSurfaces).",
64
+ examplesTitle: "Examples and supported forms",
65
+ examplesBody: `# fs-tools protection only -> bare name (.git / .env)
66
+ # bash must be covered too -> a pattern (**/.git)
67
+ # 1-7 below are grouped by purpose; lines starting with # are comments
68
+
69
+ # 1) writable while the session is workspace-write (fs tools AND bash)
70
+ ~/projects/notes/home
71
+ ../../notes/shared | write | fs+shell
72
+
73
+ # 2) read-only: reads allowed, writes refused (also inside the workspace)
74
+ ../shared/docs | read
75
+
76
+ # 3) deny: content reads, listings and writes are refused (fs tools)
77
+ ~/.ssh | deny
78
+
79
+ # 4) always writable (even under read-only), fs tools only
80
+ <work root>/build | always-write | fs
81
+
82
+ # 5) bare name = name rule: that component at any depth under the
83
+ # workspace and the configured writable roots (fs tools only)
84
+ .git | deny | fs
85
+ .env | read | fs
86
+
87
+ # 6) patterns: * = one level, ** = up to three; both surfaces can be covered
88
+ **/.git | read | fs+shell
89
+ **/.env | deny | fs+shell
90
+ <work root>/*/notes | write | fs
91
+
92
+ # 7) Windows / WSL spellings are recognised or translated per host
93
+ C:\work\shared | write
94
+ /mnt/c/work/shared | write
95
+
96
+ # access: deny | read | write | always-write (omitted -> defaultAccess, default write)
97
+ # surfaces: fs | shell | fs+shell (omitted -> defaultSurfaces, default fs+shell)
98
+ # relative paths resolve against the base workspace; ~ is your home directory;
99
+ # lines starting with # and blank lines are ignored`,
100
+ textModeInvalid: "The text has errors and was not applied:",
101
+ textErrorAtLine: "Line {line}: ",
102
+ textErrorEmptyPath: "the path must not be empty",
103
+ textErrorUnknownAccess: "unknown access level \"{value}\" (use deny, read, write or always-write)",
104
+ textErrorUnknownSurfaces: "unknown surfaces \"{value}\" (use fs, shell or fs+shell)",
105
+ textErrorTooManyFields: "too many fields (at most path | access | surfaces)",
106
+ accessDeny: "Deny access",
107
+ accessRead: "Read-only",
108
+ accessWrite: "Writable (follows session)",
109
+ accessAlways: "Always writable",
110
+ statusOk: "active",
111
+ statusMissing: "missing",
112
+ statusRejected: "rejected",
113
+ statusForeign: "not applicable on this host",
114
+ resolveBaseInvalid: "The base workspace must be absolute (a drive or UNC path on Windows too) or start with ~/; a relative path cannot be the base",
115
+ nameRuleHint: "Name rule: matches this component at any depth under the workspace and all configured writable roots — fs tools only; bash is not restricted by it (use a **/<name> path pattern if bash must be covered)",
116
+ nameRuleMatches: "{count} matches right now",
117
+ nameRuleNoMatches: "No matches right now (it still applies to paths created later)",
118
+ previewTitle: "Resolution preview",
119
+ previewDirty: " (including unsaved changes)",
120
+ previewEffective: "{count} effective writable roots",
121
+ previewReadOnly: "{count} read-only",
122
+ previewDenied: "{count} denied",
123
+ previewNoBase: "Choose or type a base workspace above and the host's effective roots appear here.",
124
+ previewBadBase: "The base workspace must be absolute or start with ~/; a relative path cannot be the base.",
125
+ previewExpandingHome: "Expanding ~: the host home directory arrives with the first preview.",
126
+ previewUnavailable: "Preview unavailable (the host did not offer the route, the connection is not ready, or it rejected the base workspace).",
127
+ previewEmpty: "Nothing to resolve yet.",
128
+ unresolved: "(unresolved)",
129
+ capabilityShellLimit: "The shell sandbox on this host ({dialect}) cannot enforce deny/read rules: bash will not honor them, but the fs tools still enforce them.",
130
+ saveRefused: "The host refused the save: this configuration may be overridden by a home patch or a command-line overlay (the settings page only writes the profile cordis.patch.yml). Remove the same-id override from ~/.dsh/cordis.patch.yml, or edit the profile patch and restart."
131
+ };
132
+ /** Simplified Chinese copy. */
133
+ const zh = {
134
+ navLabel: "额外可写路径",
135
+ summaryLoading: "额外可写路径:读取中…",
136
+ summaryUnavailable: "额外可写路径:宿主未提供该设置",
137
+ summaryEmpty: "额外可写路径:尚未配置",
138
+ summaryCount: "额外可写路径:{count} 条 · 保存即生效,写入无需审批",
139
+ introCollapsed: "工作区之外的额外可写路径,写入无需审批;支持按行批量编辑。",
140
+ expand: "展开",
141
+ collapse: "收起",
142
+ introBefore: "这些路径在会话工作区之外也可以写,",
143
+ introNoApproval: "不需要审批",
144
+ introAfter: ";访问级别与「作用面」决定写工具和终端各自的行为。",
145
+ introRuleBefore: "相对路径按「基准工作区」解析——执法时用的是",
146
+ introRuleEmphasis: "各会话自己的工作区",
147
+ introRuleAfter: ",所以同一份配置在不同会话会指向不同目录。deny/只读规则优先于可写规则。",
148
+ baseWorkspace: "基准工作区",
149
+ notSelected: "(未选择)",
150
+ basePlaceholder: "绝对路径(含 Windows 盘符/UNC),或以 ~/ 开头",
151
+ manualBase: "手填",
152
+ pickBase: "从列表选",
153
+ baseHint: "仅用于预览与行内解析",
154
+ baseForeign: "当前宿主无法表达这个基准路径(平台不匹配);同一份配置在匹配的宿主上仍然可用。",
155
+ baseWaiting: "正在等待宿主返回平台信息(首次预览)…",
156
+ save: "保存",
157
+ saving: "保存中…",
158
+ dirty: "有未保存的修改",
159
+ synced: "已与配置同步",
160
+ textMode: "文本模式",
161
+ textModeHint: "每行一条规则:路径 | 访问级别 | 作用面。后两段可省略,省略时使用下方显示的默认值。展开「示例与支持的写法」查看常用形式。",
162
+ editorDefaults: "省略字段时的默认值:访问级别 = {access},作用面 = {surfaces}(来自配置文档的 defaultAccess / defaultSurfaces)。",
163
+ examplesTitle: "示例与支持的写法",
164
+ examplesBody: `# 仅保护 fs 工具 -> 裸名(.git / .env)
165
+ # 要让 bash 也受约束 -> 模式(**/.git)
166
+ # 下面 1-7 按用途分组;# 开头的行都是注释
167
+
168
+ # 1) 可写(随会话):fs 工具与 bash 都放行
169
+ ~/projects/notes/home
170
+ ../../notes/shared | write | fs+shell
171
+
172
+ # 2) 只读:读允许、写拒绝(工作区内的目录也能这样降级)
173
+ ../shared/docs | read
174
+
175
+ # 3) 禁止访问:内容读取、目录列举与写入都拒绝(fs 工具)
176
+ ~/.ssh | deny
177
+
178
+ # 4) 始终可写(read-only 会话也放行),只作用于 fs 工具
179
+ <工作根>/build | always-write | fs
180
+
181
+ # 5) 裸名 = 名称规则:工作区与可写根内任意深度的同名路径(仅 fs 工具)
182
+ .git | deny | fs
183
+ .env | read | fs
184
+
185
+ # 6) 模式:* 一层 / ** 最多三层;可同时覆盖 fs 与 shell
186
+ **/.git | read | fs+shell
187
+ **/.env | deny | fs+shell
188
+ <工作根>/*/notes | write | fs
189
+
190
+ # 7) Windows / WSL 写法会按当前宿主识别或互译
191
+ C:\work\shared | write
192
+ /mnt/c/work/shared | write
193
+
194
+ # 级别:deny | read | write | always-write (省略 -> defaultAccess,默认 write)
195
+ # 作用面:fs | shell | fs+shell (省略 -> defaultSurfaces,默认 fs+shell)
196
+ # 相对路径按「基准工作区」解析;~ 是家目录;# 开头为注释、空行忽略`,
197
+ textModeInvalid: "文本有误,尚未应用:",
198
+ textErrorAtLine: "第 {line} 行:",
199
+ textErrorEmptyPath: "路径不能为空",
200
+ textErrorUnknownAccess: "未知的访问级别「{value}」(可用 deny、read、write、always-write)",
201
+ textErrorUnknownSurfaces: "未知的作用面「{value}」(可用 fs、shell、fs+shell)",
202
+ textErrorTooManyFields: "字段过多(最多 path | access | surfaces 三段)",
203
+ accessDeny: "禁止访问",
204
+ accessRead: "只读",
205
+ accessWrite: "可写(随会话)",
206
+ accessAlways: "始终可写",
207
+ statusOk: "生效",
208
+ statusMissing: "缺失",
209
+ statusRejected: "已拒绝",
210
+ statusForeign: "当前平台不适用",
211
+ resolveBaseInvalid: "基准工作区需要绝对路径(含 Windows 盘符/UNC),或以 ~/ 开头;相对路径不能当基准用",
212
+ nameRuleHint: "名称规则:工作区与所有可写根内任意深度匹配(仅 fs 工具;bash 不受此规则约束;要让 bash 也生效请改用 **/<名字> 模式)",
213
+ nameRuleMatches: "当前匹配 {count} 处",
214
+ nameRuleNoMatches: "当前暂无匹配(对新建路径仍生效)",
215
+ previewTitle: "解析预览",
216
+ previewDirty: "(含未保存修改)",
217
+ previewEffective: "生效根 {count} 条",
218
+ previewReadOnly: "只读 {count} 条",
219
+ previewDenied: "禁止 {count} 条",
220
+ previewNoBase: "先在上面选择或填写「基准工作区」,这里就会显示宿主解析出的生效根。",
221
+ previewBadBase: "基准工作区需要绝对路径,或以 ~/ 开头;相对路径不能当基准用。",
222
+ previewExpandingHome: "正在展开 ~:宿主的家目录会在第一次预览返回后给出。",
223
+ previewUnavailable: "预览不可用(宿主没提供该路由、连接还没就绪,或基准工作区被宿主拒绝)。",
224
+ previewEmpty: "还没有可解析的路径。",
225
+ unresolved: "(未解析)",
226
+ capabilityShellLimit: "当前 shell 沙箱({dialect})无法执行「禁止访问/只读」规则:bash 不受该限制,但 fs 工具仍按规则拦截。",
227
+ saveRefused: "保存被宿主拒绝:该配置可能被 home patch 或命令行覆盖(设置页只写 profile 的 cordis.patch.yml)。请删掉 ~/.dsh/cordis.patch.yml 里同 id 的覆盖,或直接改 profile patch 后重启。"
228
+ };
229
+ /** Fill `{name}` placeholders; unknown names stay verbatim, like the host seat. */
230
+ function format(template, params) {
231
+ if (params === void 0) return template;
232
+ return template.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match);
233
+ }
234
+ /**
235
+ * The built-in translate function: Chinese copy, `{name}` placeholders.
236
+ * Used when the host supplies no locale seat (0.1.5 slots, unit tests).
237
+ */
238
+ const fallbackTranslate = (key, params) => format(zh[key], params);
239
+ //#endregion
240
+ //#region src/platform.ts
241
+ /** The default WSL drive mount root. */
242
+ const DEFAULT_WSL_MOUNT_ROOT = "/mnt";
243
+ /** Extended-length prefix `\\?\` (and `\\?\UNC\`). */
244
+ const EXTENDED_PREFIX = /^\\\\\?\\/;
245
+ const EXTENDED_UNC_PREFIX = /^\\\\\?\\UNC\\/i;
246
+ /** `C:\` or `C:/` — a drive-rooted absolute path. */
247
+ const WIN_DRIVE_ABSOLUTE = /^[A-Za-z]:[\\/]/;
248
+ /** `C:foo` — drive-RELATIVE (resolved against that drive's current directory). */
249
+ const WIN_DRIVE_RELATIVE = /^[A-Za-z]:(?![\\/])/;
250
+ /** `\\server\share\x` — a UNC path (two leading backslashes, a server name). */
251
+ const WIN_UNC = /^\\\\[^\\]/;
252
+ /** `//server/share/x` — UNC spelled with forward separators. */
253
+ const WIN_UNC_FORWARD = /^\/\/[^/]+\/[^/]+/;
254
+ /** A single leading separator that is neither `\\` nor `/`: `\foo` (current drive). */
255
+ const WIN_CURRENT_DRIVE = /^\\(?!\\)/;
256
+ /** Strip a Windows extended-length prefix, which only adds noise to comparison. */
257
+ function stripWindowsPrefix(spelling) {
258
+ if (EXTENDED_UNC_PREFIX.test(spelling)) return `\\\\${spelling.slice(8)}`;
259
+ if (EXTENDED_PREFIX.test(spelling)) return spelling.slice(4);
260
+ return spelling;
261
+ }
262
+ /** The logical host dialect. */
263
+ function hostDialect(facts) {
264
+ return facts.platform === "win32" ? "windows" : "posix";
265
+ }
266
+ /**
267
+ * Classify one spelling without consulting the host.
268
+ * @param spelling - the raw configured spelling (trimmed by the caller).
269
+ * @returns what kind of path it is.
270
+ */
271
+ function classifySpelling(spelling) {
272
+ if (spelling === "~") return "home";
273
+ if (spelling.startsWith("~/")) return "home";
274
+ if (spelling.startsWith("~\\")) return "windows-home";
275
+ const stripped = stripWindowsPrefix(spelling);
276
+ if (WIN_DRIVE_ABSOLUTE.test(stripped) || WIN_UNC.test(stripped)) return "windows-absolute";
277
+ if (WIN_UNC_FORWARD.test(stripped)) return "windows-absolute";
278
+ if (WIN_DRIVE_RELATIVE.test(stripped)) return "windows-drive-relative";
279
+ if (spelling.startsWith("/")) return "posix-absolute";
280
+ if (WIN_CURRENT_DRIVE.test(stripped)) return "windows-current-drive";
281
+ return "relative";
282
+ }
33
283
  /**
34
- * Lexical path resolution for the settings page's live column. It mirrors the
35
- * host's `expandPath` (a relative entry resolves against the session workspace,
36
- * `~` against the home directory) WITHOUT touching the filesystem, so a
37
- * half-typed row can show where it would land before it is saved.
284
+ * Whether a spelling is a BARE NAME (`.git`, `.env`, `node_modules`): one path
285
+ * component, no separator, no wildcard, not the `.`/`..` relative specials and
286
+ * not a `~` spelling. A bare name is a NAME RULE — it matches that component at
287
+ * any depth under the rule's scope roots rather than naming one literal path.
38
288
  *
39
- * Symbolic links are deliberately not resolved here — the browser cannot
40
- * realpath. The host's own preview is the authoritative answer, and the page
41
- * keeps showing both: this one instantly, the host's on every settled edit.
42
- * @module dsh-extra-paths/client/paths
289
+ * The `./name` spelling is the escape hatch for a literal single-component
290
+ * relative path (it contains a separator, so it stays a normal relative path).
291
+ * @param spelling - the raw configured spelling.
292
+ * @returns true when the spelling is a name rule.
43
293
  */
294
+ function isBareNameSpelling(spelling) {
295
+ if (spelling === "" || spelling === "." || spelling === "..") return false;
296
+ if (spelling.startsWith("~")) return false;
297
+ if (spelling.includes("*")) return false;
298
+ if (/^[A-Za-z]:/.test(spelling)) return false;
299
+ return !spelling.includes("/") && !spelling.includes("\\");
300
+ }
44
301
  /**
45
- * Collapse `.`, `..` and duplicate separators in an absolute POSIX spelling.
46
- * @param path - an absolute spelling (the caller guarantees the leading `/`).
47
- * @returns the collapsed absolute path; `..` above the root is clamped there.
302
+ * Whether a spelling is absolute in its own dialect (a `~` spelling counts:
303
+ * the caller expands home first).
304
+ * @param spelling - the raw configured spelling.
305
+ * @returns true for home, POSIX-absolute and Windows-absolute spellings.
48
306
  */
49
- function collapse(path) {
307
+ function isAbsoluteSpelling(spelling) {
308
+ const kind = classifySpelling(spelling);
309
+ return kind === "home" || kind === "windows-home" || kind === "posix-absolute" || kind === "windows-absolute";
310
+ }
311
+ /** Collapse `.`, `..` and duplicate separators in an absolute POSIX spelling. */
312
+ function collapsePosix(path) {
50
313
  const segments = [];
51
314
  for (const segment of path.split("/")) {
52
315
  if (segment === "" || segment === ".") continue;
@@ -59,36 +322,491 @@ window.__ModuleLoader__.load({
59
322
  return `/${segments.join("/")}`;
60
323
  }
61
324
  /**
62
- * Resolve one configured entry the way the host will, lexically.
63
- * @param entry - the row's raw spelling.
64
- * @param workspaceRoot - the workspace a relative entry resolves against.
65
- * @param home - the host's home directory, once the preview has reported it.
66
- * @returns the absolute path, or undefined when it cannot be resolved yet
67
- * (`~` before the home directory is known, or a relative entry with no usable
68
- * workspace base).
69
- */
70
- function resolveLexically(entry, workspaceRoot, home) {
71
- const trimmed = entry.trim();
72
- if (trimmed === "") return void 0;
73
- if (trimmed === "~" || trimmed.startsWith("~/")) {
74
- if (home === void 0 || home === "") return void 0;
75
- return collapse(trimmed === "~" ? home : `${home}/${trimmed.slice(2)}`);
325
+ * Collapse an absolute Windows spelling (drive or UNC) into its native form.
326
+ * The result uses `\` separators; case is preserved (Windows comparison folds
327
+ * case later, but the host's `realpath`/ACL layers still want the real spelling).
328
+ * @param path - an absolute Windows spelling using either separator.
329
+ * @returns the collapsed spelling, e.g. `C:\Users\me\x` or `\\server\share\x`.
330
+ */
331
+ function collapseWindows(path) {
332
+ const stripped = stripWindowsPrefix(path).replaceAll("/", "\\");
333
+ if (WIN_UNC.test(stripped)) {
334
+ const parts = stripped.slice(2).split("\\");
335
+ const server = parts.shift() ?? "";
336
+ const share = parts.shift() ?? "";
337
+ const rest = collapseWindowsSegments(parts);
338
+ return `\\\\${server}\\${share}${rest === "" ? "" : `\\${rest}`}`;
339
+ }
340
+ return `${stripped.slice(0, 2)}\\${collapseWindowsSegments(stripped.slice(2).split("\\"))}`;
341
+ }
342
+ /** Collapse one segment list, clamping `..` at the start. */
343
+ function collapseWindowsSegments(segments) {
344
+ const out = [];
345
+ for (const segment of segments) {
346
+ if (segment === "" || segment === ".") continue;
347
+ if (segment === "..") {
348
+ out.pop();
349
+ continue;
350
+ }
351
+ out.push(segment);
352
+ }
353
+ return out.join("\\");
354
+ }
355
+ /** Join a home directory and a `~`-relative rest in the host's dialect. */
356
+ function homeJoin(home, rest, dialect) {
357
+ const trimmed = rest.replace(dialect === "windows" ? /^[\\/]+/ : /^\/+/, "");
358
+ if (trimmed === "") return dialect === "windows" ? collapseWindows(home) : collapsePosix(home);
359
+ return dialect === "windows" ? collapseWindows(`${home}\\${trimmed}`) : collapsePosix(`${home}/${trimmed}`);
360
+ }
361
+ /** Resolve a relative spelling against the workspace base in one dialect. */
362
+ function resolveRelative(base, spelling, dialect) {
363
+ if (dialect === "windows") return collapseWindows(`${base}\\${spelling}`);
364
+ return collapsePosix(`${base}/${spelling}`);
365
+ }
366
+ /** Build a `foreign` outcome: the spelling has no meaning on this host. */
367
+ function foreign(reason) {
368
+ return {
369
+ ok: false,
370
+ foreign: reason
371
+ };
372
+ }
373
+ /**
374
+ * Translate a Windows absolute spelling into its WSL spelling.
375
+ * @param spelling - a drive-rooted or UNC spelling (any separator).
376
+ * @param mountRoot - the WSL mount root, normally `/mnt`.
377
+ * @returns the POSIX spelling, or undefined for a share UNC path (no mapping).
378
+ */
379
+ function windowsToWsl(spelling, mountRoot = DEFAULT_WSL_MOUNT_ROOT) {
380
+ const stripped = stripWindowsPrefix(spelling).replaceAll("\\", "/");
381
+ const drive = /^([A-Za-z]):(?:\/|$)/.exec(stripped);
382
+ if (drive === null) return void 0;
383
+ const letter = (drive[1] ?? "").toLowerCase();
384
+ const rest = stripped.slice(drive[0].length);
385
+ const root = mountRoot.replace(/\/+$/, "");
386
+ const tail = rest.replace(/^\/+/, "");
387
+ return tail === "" ? `${root}/${letter}` : `${root}/${letter}/${tail}`;
388
+ }
389
+ /**
390
+ * Translate a POSIX spelling that names a Windows drive into its Windows form.
391
+ * Two conventions are recognized: WSL's `/mnt/<letter>/…` and the MSYS/git-bash
392
+ * `/c/…` form. The caller verifies the result by resolving it (existence is the
393
+ * only proof that the drive really exists on this host).
394
+ * @param spelling - an absolute POSIX spelling.
395
+ * @param mountRoot - the WSL drive mount root, normally `/mnt`.
396
+ * @returns the Windows spelling, or undefined when the spelling is not a drive.
397
+ */
398
+ function posixToWindows(spelling, mountRoot = DEFAULT_WSL_MOUNT_ROOT) {
399
+ const root = mountRoot.replace(/\/+$/, "");
400
+ const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
401
+ const mounted = new RegExp(`^${escape(root)}/([A-Za-z])(?:/(.*))?$`).exec(spelling);
402
+ if (mounted !== null) return windowsFromParts(mounted[1] ?? "", mounted[2]);
403
+ const msys = /^\/([A-Za-z])(?:\/(.*))?$/.exec(spelling);
404
+ if (msys !== null) return windowsFromParts(msys[1] ?? "", msys[2]);
405
+ }
406
+ /** Assemble a Windows drive path from a drive letter and a `/`-separated rest. */
407
+ function windowsFromParts(letter, rest) {
408
+ const drive = letter.toUpperCase();
409
+ return rest === void 0 || rest === "" ? `${drive}:\\` : `${drive}:\\${rest.replaceAll("/", "\\")}`;
410
+ }
411
+ /**
412
+ * Resolve one configured spelling to a HOST-NATIVE absolute path.
413
+ *
414
+ * Translation happens only when the spelling's dialect differs from the host's:
415
+ * a Windows spelling inside WSL becomes `/mnt/<drive>/…`, a `/mnt/<drive>/…`
416
+ * spelling on a native Windows host becomes `<Drive>:\…`. A spelling with no
417
+ * mapping on this host is `foreign`: the caller marks the entry inactive with a
418
+ * warning instead of failing the whole configuration.
419
+ * @param spelling - the configured spelling (already trimmed).
420
+ * @param workspaceRoot - the session workspace a relative spelling resolves against.
421
+ * @param facts - host platform facts.
422
+ * @returns the host-native absolute path, or the reason it is foreign.
423
+ */
424
+ function expandPath(spelling, workspaceRoot, facts) {
425
+ const dialect = hostDialect(facts);
426
+ switch (classifySpelling(spelling)) {
427
+ case "home": return {
428
+ ok: true,
429
+ path: homeJoin(facts.home, spelling.slice(1), dialect),
430
+ dialect,
431
+ translated: false
432
+ };
433
+ case "windows-home":
434
+ if (dialect === "windows") return {
435
+ ok: true,
436
+ path: homeJoin(facts.home, spelling.slice(1), dialect),
437
+ dialect,
438
+ translated: false
439
+ };
440
+ return foreign(`the Windows home spelling ${JSON.stringify(spelling)} is only understood on a Windows host`);
441
+ case "posix-absolute":
442
+ if (dialect === "posix") return {
443
+ ok: true,
444
+ path: collapsePosix(spelling),
445
+ dialect,
446
+ translated: false
447
+ };
448
+ {
449
+ const mapped = posixToWindows(spelling, facts.wslMountRoot);
450
+ if (mapped !== void 0) return {
451
+ ok: true,
452
+ path: collapseWindows(mapped),
453
+ dialect,
454
+ translated: true
455
+ };
456
+ return foreign(`the POSIX path ${JSON.stringify(spelling)} cannot be expressed on a Windows host`);
457
+ }
458
+ case "windows-absolute":
459
+ if (dialect === "windows") return {
460
+ ok: true,
461
+ path: collapseWindows(spelling),
462
+ dialect,
463
+ translated: false
464
+ };
465
+ if (facts.wsl) {
466
+ const mapped = windowsToWsl(spelling, facts.wslMountRoot);
467
+ if (mapped !== void 0) return {
468
+ ok: true,
469
+ path: collapsePosix(mapped),
470
+ dialect,
471
+ translated: true
472
+ };
473
+ return foreign(`the UNC path ${JSON.stringify(spelling)} has no reliable WSL mapping`);
474
+ }
475
+ return foreign(`the Windows path ${JSON.stringify(spelling)} is only understood on a Windows host or inside WSL`);
476
+ case "windows-drive-relative": return foreign(`the drive-relative spelling ${JSON.stringify(spelling)} is ambiguous and refused`);
477
+ case "windows-current-drive":
478
+ if (dialect === "windows") return foreign(`the current-drive spelling ${JSON.stringify(spelling)} is ambiguous and refused`);
479
+ return {
480
+ ok: true,
481
+ path: resolveRelative(workspaceRoot, spelling, dialect),
482
+ dialect,
483
+ translated: false
484
+ };
485
+ default: return {
486
+ ok: true,
487
+ path: resolveRelative(workspaceRoot, spelling, dialect),
488
+ dialect,
489
+ translated: false
490
+ };
76
491
  }
77
- if (trimmed.startsWith("/")) return collapse(trimmed);
78
- if (!workspaceRoot.startsWith("/")) return void 0;
79
- return collapse(`${workspaceRoot}/${trimmed}`);
492
+ }
493
+ //#endregion
494
+ //#region src/client/paths.ts
495
+ /** All access levels, in the order the dropdown offers them (strict → permissive). */
496
+ const ACCESSES = [
497
+ "deny",
498
+ "read",
499
+ "write",
500
+ "always-write"
501
+ ];
502
+ /** All enforcement surfaces. */
503
+ const SURFACES = ["fs", "shell"];
504
+ /** The plugin's default surfaces when a stored entry does not say. */
505
+ const DEFAULT_SURFACES = ["fs", "shell"];
506
+ function accessOf(value) {
507
+ return typeof value === "string" && ACCESSES.includes(value) ? value : void 0;
508
+ }
509
+ function surfacesOf(value) {
510
+ if (!Array.isArray(value)) return void 0;
511
+ const surfaces = [];
512
+ for (const item of value) {
513
+ if (typeof item !== "string" || !SURFACES.includes(item)) continue;
514
+ if (!surfaces.includes(item)) surfaces.push(item);
515
+ }
516
+ return surfaces.length > 0 ? surfaces : void 0;
517
+ }
518
+ /**
519
+ * The defaults a stored section declares, with the legacy `defaultScope` alias
520
+ * and the plugin defaults as fallbacks.
521
+ * @param section - the stored section, when the host has one.
522
+ * @returns access + surfaces to use for entries that omit them.
523
+ */
524
+ function defaultsOf(section) {
525
+ return {
526
+ access: accessOf(section?.defaultAccess) ?? accessOf(section?.defaultScope) ?? "write",
527
+ surfaces: surfacesOf(section?.defaultSurfaces) ?? [...DEFAULT_SURFACES]
528
+ };
529
+ }
530
+ /**
531
+ * Turn a stored section into editable rows. Accepts every shape the host half
532
+ * still accepts: a bare string (the defaults apply), an entry with `access`, and
533
+ * the legacy `scope` (mapped onto the same vocabulary). Unknown vocabulary falls
534
+ * back to the defaults instead of crashing the page — the save-time validator is
535
+ * where an invalid document is reported.
536
+ * @param section - the stored section.
537
+ * @returns the editable rows in stored order.
538
+ */
539
+ function rowsOf(section) {
540
+ const defaults = defaultsOf(section);
541
+ const rows = [];
542
+ for (const item of section?.paths ?? []) {
543
+ if (typeof item === "string") {
544
+ rows.push({
545
+ path: item,
546
+ access: defaults.access,
547
+ surfaces: [...defaults.surfaces]
548
+ });
549
+ continue;
550
+ }
551
+ if (item === null || typeof item !== "object") continue;
552
+ rows.push({
553
+ path: typeof item.path === "string" ? item.path : "",
554
+ access: accessOf(item.access) ?? accessOf(item.scope) ?? defaults.access,
555
+ surfaces: surfacesOf(item.surfaces) ?? [...defaults.surfaces]
556
+ });
557
+ }
558
+ return rows;
559
+ }
560
+ /**
561
+ * Serialise the rows into the structured payload the page saves and previews.
562
+ * Empty paths (a row just added and not typed into yet) are dropped, matching
563
+ * the host's own "path must be a non-empty string" rule.
564
+ * @param rows - the editable rows.
565
+ * @returns `{path, access, surfaces}` objects with trimmed paths.
566
+ */
567
+ function payloadOf(rows) {
568
+ const payload = [];
569
+ for (const row of rows) {
570
+ const path = row.path.trim();
571
+ if (path === "") continue;
572
+ payload.push({
573
+ path,
574
+ access: row.access,
575
+ surfaces: [...row.surfaces]
576
+ });
577
+ }
578
+ return payload;
579
+ }
580
+ /** The canonical `+`-joined surface spelling (`fs+shell`). */
581
+ function surfacesText(surfaces) {
582
+ return SURFACES.filter((surface) => surfaces.includes(surface)).join("+");
583
+ }
584
+ /**
585
+ * Render one rule in the EXPLICIT text form: `path | access | surfaces`.
586
+ *
587
+ * The editor deliberately does not omit values that happen to equal the plugin
588
+ * defaults: the user configured those fields in the list view and expects to
589
+ * see them when switching to text mode (a bare `path` looked like the access
590
+ * and surface settings had been lost). Explicit output also round-trips
591
+ * independent of any future default change. The parser still accepts the short
592
+ * forms (`path`, `path | access`) when hand-typing.
593
+ * @param row - one rule.
594
+ * @returns one text-mode line.
595
+ */
596
+ function formatRule(row) {
597
+ return `${row.path.trim()} | ${row.access} | ${surfacesText(row.surfaces)}`;
598
+ }
599
+ /**
600
+ * Render the current rows for the text-mode editor.
601
+ * @param rows - the current rows.
602
+ * @returns one explicit line per non-empty rule.
603
+ */
604
+ function serializeRules(rows) {
605
+ return rows.filter((row) => row.path.trim() !== "").map(formatRule).join("\n");
606
+ }
607
+ /** Parse the optional `| surfaces` field (`fs`, `shell`, `fs+shell`, also `shell+fs`). */
608
+ function parseSurfacesField(value) {
609
+ const parts = value.split(/[+,\s]+/).filter((part) => part !== "");
610
+ const surfaces = [];
611
+ for (const part of parts) {
612
+ if (!SURFACES.includes(part)) return void 0;
613
+ if (!surfaces.includes(part)) surfaces.push(part);
614
+ }
615
+ const ordered = SURFACES.filter((surface) => surfaces.includes(surface));
616
+ return ordered.length > 0 ? ordered : void 0;
617
+ }
618
+ /**
619
+ * Parse the bulk text editor. Blank lines and lines whose first non-space
620
+ * character is `#` are comments/separators and are skipped. A line is
621
+ * `path`, `path | access`, or `path | access | surfaces`.
622
+ * @param text - the editor content.
623
+ * @param defaults - the defaults a missing access/surfaces field inherits.
624
+ * @returns the parsed rules, or every per-line error (nothing is applied then).
625
+ */
626
+ function parseRules(text, defaults = defaultsOf(void 0)) {
627
+ const rules = [];
628
+ const errors = [];
629
+ text.split(/\r?\n/).forEach((line, index) => {
630
+ const lineNo = index + 1;
631
+ const trimmed = line.trim();
632
+ if (trimmed === "" || trimmed.startsWith("#")) return;
633
+ const fields = trimmed.split("|").map((field) => field.trim());
634
+ if (fields.length > 3) {
635
+ errors.push({
636
+ line: lineNo,
637
+ code: "too-many-fields"
638
+ });
639
+ return;
640
+ }
641
+ const path = fields[0] ?? "";
642
+ if (path === "") {
643
+ errors.push({
644
+ line: lineNo,
645
+ code: "empty-path"
646
+ });
647
+ return;
648
+ }
649
+ let access = defaults.access;
650
+ if (fields.length >= 2) {
651
+ const parsed = accessOf(fields[1]);
652
+ if (parsed === void 0) {
653
+ errors.push({
654
+ line: lineNo,
655
+ code: "unknown-access",
656
+ value: fields[1] ?? ""
657
+ });
658
+ return;
659
+ }
660
+ access = parsed;
661
+ }
662
+ let surfaces = [...defaults.surfaces];
663
+ if (fields.length === 3) {
664
+ const parsed = parseSurfacesField(fields[2] ?? "");
665
+ if (parsed === void 0) {
666
+ errors.push({
667
+ line: lineNo,
668
+ code: "unknown-surfaces",
669
+ value: fields[2] ?? ""
670
+ });
671
+ return;
672
+ }
673
+ surfaces = parsed;
674
+ }
675
+ rules.push({
676
+ path,
677
+ access,
678
+ surfaces
679
+ });
680
+ });
681
+ return errors.length > 0 ? {
682
+ ok: false,
683
+ errors
684
+ } : {
685
+ ok: true,
686
+ rules
687
+ };
688
+ }
689
+ /**
690
+ * Whether a configured spelling is a NAME RULE (`.git`, `.env`, `node_modules`):
691
+ * one component, no separator, matched at ANY depth under the session workspace
692
+ * and every configured writable root. It is not a path, so it has no lexical
693
+ * resolution — the host matches it live per call and reports a match count for
694
+ * the preview.
695
+ *
696
+ * The spelling vocabulary is shared with the host half through `../platform`
697
+ * (pure string functions). The node-only rule engine (`../name-rule`) must never
698
+ * be imported here: this module is bundled into the browser client.
699
+ * @param path - the raw configured spelling.
700
+ * @returns true when the host treats the entry as a name rule.
701
+ */
702
+ function isNameRulePath(path) {
703
+ return isBareNameSpelling(path.trim());
704
+ }
705
+ /** The POSIX-ish fallback used before the host reports its real platform. */
706
+ const FALLBACK_FACTS = Object.freeze({
707
+ platform: "unknown",
708
+ wsl: false,
709
+ wslMountRoot: "/mnt",
710
+ home: ""
711
+ });
712
+ /**
713
+ * Build the path facts from a preview payload. Before the first preview there
714
+ * are no facts: the page then assumes a POSIX host for its instant hint and
715
+ * refuses to claim ANY Windows spelling resolves (it waits for the host's platform facts).
716
+ * @param preview - the preview payload, when one has arrived.
717
+ * @returns the facts plus a flag saying whether they came from the host.
718
+ */
719
+ function hostViewOf(preview) {
720
+ const report = preview?.platform;
721
+ if (report === void 0) return {
722
+ facts: FALLBACK_FACTS,
723
+ known: false
724
+ };
725
+ return {
726
+ known: true,
727
+ facts: {
728
+ platform: report.platform,
729
+ wsl: report.wsl,
730
+ wslMountRoot: report.wslMountRoot ?? "/mnt",
731
+ home: preview?.home ?? ""
732
+ }
733
+ };
734
+ }
735
+ /**
736
+ * Resolve the base-workspace field the way the host will. The field accepts an
737
+ * absolute spelling in the HOST's dialect (`C:\…`, `\\server\share\…`), a `~`
738
+ * spelling, and nothing relative.
739
+ * @param spelling - the raw field value.
740
+ * @param host - the host facts view.
741
+ * @returns the host-native absolute base, or why it cannot be used.
742
+ */
743
+ function resolveBase(spelling, host) {
744
+ const trimmed = spelling.trim();
745
+ if (trimmed === "") return {
746
+ ok: false,
747
+ problem: "empty"
748
+ };
749
+ const kind = classifySpelling(trimmed);
750
+ if (kind === "home" || kind === "windows-home") {
751
+ if (host.facts.home === "") return {
752
+ ok: false,
753
+ problem: "waiting"
754
+ };
755
+ } else if (kind === "windows-absolute") {
756
+ if (!host.known) return {
757
+ ok: false,
758
+ problem: "waiting"
759
+ };
760
+ } else if (!isAbsoluteSpelling(trimmed)) return {
761
+ ok: false,
762
+ problem: "relative"
763
+ };
764
+ const outcome = expandPath(trimmed, "", host.facts);
765
+ if (outcome.ok) return {
766
+ ok: true,
767
+ base: outcome.path
768
+ };
769
+ if (!host.known) return {
770
+ ok: false,
771
+ problem: "waiting"
772
+ };
773
+ return {
774
+ ok: false,
775
+ problem: "foreign",
776
+ reason: outcome.foreign
777
+ };
778
+ }
779
+ /**
780
+ * Which base spelling to send with the preview request.
781
+ *
782
+ * Normally it is the resolved host-native base. While the page still waits for
783
+ * the platform facts it sends the RAW absolute spelling instead: the HOST is the
784
+ * one that knows its dialect, so it accepts `C:\…` on Windows, `/mnt/c/…` in
785
+ * WSL and `~` anywhere (expanding it with the real home directory). Without this
786
+ * a Windows workspace candidate would leave the page waiting for facts forever —
787
+ * it refuses to claim the Windows base resolves, but the host can prove it.
788
+ * Relative/empty spellings are never sent (the host rejects them anyway).
789
+ * @param spelling - the raw base field value.
790
+ * @param base - the lexical base outcome.
791
+ * @returns the query value, or '' when there is nothing usable to ask about.
792
+ */
793
+ function previewBaseOf(spelling, base) {
794
+ if (base.ok) return base.base;
795
+ const trimmed = spelling.trim();
796
+ if (base.problem === "waiting" && isAbsoluteSpelling(trimmed)) return trimmed;
797
+ return "";
80
798
  }
81
799
  //#endregion
82
800
  //#region src/client/preview.ts
83
801
  const ROUTE = "/extra-paths/resolved";
84
802
  /**
85
- * Fetch the effective roots for one workspace.
803
+ * Fetch the host's answer for one workspace.
86
804
  *
87
805
  * The unsaved rows travel with the request so the answer describes the DRAFT:
88
806
  * previously the preview only ever described the stored document, which is what
89
807
  * made configuring a relative path a guess-until-you-save exercise.
90
- * @param cwd - the workspace path to resolve against.
91
- * @param paths - the page's current rows (strings or `{path, scope, surfaces}`).
808
+ * @param cwd - the (host-native, absolute) workspace path to resolve against.
809
+ * @param paths - the page's current rows as `{path, access, surfaces}`.
92
810
  * @param signal - optional abort signal.
93
811
  * @returns the preview, or undefined when the route is unavailable.
94
812
  */
@@ -109,15 +827,6 @@ window.__ModuleLoader__.load({
109
827
  //#endregion
110
828
  //#region src/client/styles.ts
111
829
  const box = { boxSizing: "border-box" };
112
- const card = {
113
- ...box,
114
- display: "flex",
115
- flexDirection: "column",
116
- gap: 8,
117
- padding: "10px 12px",
118
- border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.25))",
119
- borderRadius: 8
120
- };
121
830
  const button = {
122
831
  ...box,
123
832
  padding: "4px 10px",
@@ -128,131 +837,114 @@ window.__ModuleLoader__.load({
128
837
  fontSize: 12,
129
838
  cursor: "pointer"
130
839
  };
840
+ ({ ...box });
131
841
  /** The page's style map. */
132
842
  const styles = {
133
843
  page: {
134
844
  display: "flex",
135
845
  flexDirection: "column",
136
- gap: 12,
846
+ gap: 10,
137
847
  padding: "4px 0",
138
- maxWidth: 760
848
+ maxWidth: 860
849
+ },
850
+ introLine: {
851
+ display: "flex",
852
+ gap: 6,
853
+ alignItems: "baseline",
854
+ flexWrap: "wrap"
139
855
  },
140
856
  intro: {
141
857
  fontSize: 12,
142
858
  lineHeight: 1.6,
143
859
  opacity: .75
144
860
  },
861
+ label: {
862
+ fontSize: 12,
863
+ fontWeight: 600,
864
+ opacity: .8,
865
+ whiteSpace: "nowrap"
866
+ },
145
867
  baseRow: {
146
868
  display: "flex",
147
869
  gap: 8,
148
870
  alignItems: "center",
149
871
  flexWrap: "wrap"
150
872
  },
151
- baseField: { width: 380 },
873
+ baseField: {
874
+ ...box,
875
+ width: 380,
876
+ maxWidth: "100%",
877
+ height: 30
878
+ },
152
879
  toolbar: {
153
880
  display: "flex",
154
881
  gap: 8,
155
882
  alignItems: "center",
156
883
  flexWrap: "wrap"
157
884
  },
158
- card,
159
- cardHead: {
885
+ textEditor: {
160
886
  display: "flex",
161
- alignItems: "center",
162
- justifyContent: "space-between",
887
+ flexDirection: "column",
163
888
  gap: 8
164
889
  },
165
- cardHeadRight: {
166
- display: "flex",
167
- alignItems: "center",
168
- gap: 8
890
+ examples: {
891
+ ...box,
892
+ fontSize: 12
169
893
  },
170
- cardTitle: {
171
- fontSize: 12,
172
- fontWeight: 600,
173
- opacity: .75
894
+ examplesSummary: {
895
+ cursor: "pointer",
896
+ opacity: .75,
897
+ userSelect: "none"
898
+ },
899
+ examplesBody: {
900
+ ...box,
901
+ margin: "6px 0 0",
902
+ padding: "8px 10px",
903
+ maxHeight: 260,
904
+ overflow: "auto",
905
+ border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.25))",
906
+ borderRadius: 8,
907
+ background: "var(--dsh-color-surface-secondary, rgba(128,128,128,0.06))",
908
+ fontFamily: "var(--dsh-font-mono, monospace)",
909
+ fontSize: 11.5,
910
+ lineHeight: 1.55,
911
+ whiteSpace: "pre",
912
+ opacity: .9
174
913
  },
175
- pathInput: {
914
+ textarea: {
176
915
  ...box,
177
916
  width: "100%",
178
- padding: "6px 8px",
179
- borderRadius: 6,
917
+ minHeight: 220,
918
+ padding: "8px 10px",
919
+ borderRadius: 8,
180
920
  border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.35))",
181
921
  background: "transparent",
182
922
  color: "inherit",
183
923
  fontFamily: "var(--dsh-font-mono, monospace)",
184
- fontSize: 13
185
- },
186
- resolvedRow: {
187
- display: "flex",
188
- gap: 6,
189
- alignItems: "baseline",
190
- minHeight: 18,
191
- fontSize: 12,
192
- flexWrap: "wrap"
193
- },
194
- code: {
195
- fontFamily: "var(--dsh-font-mono, monospace)",
196
- fontSize: 12,
197
- wordBreak: "break-all"
198
- },
199
- dim: {
200
- opacity: .6,
201
924
  fontSize: 12,
202
- lineHeight: 1.5
925
+ lineHeight: 1.6,
926
+ resize: "vertical"
203
927
  },
204
- controlsRow: {
928
+ textErrors: {
205
929
  display: "flex",
206
- gap: 16,
207
- alignItems: "center",
208
- flexWrap: "wrap"
930
+ flexDirection: "column",
931
+ gap: 2
209
932
  },
210
- field: {
211
- display: "flex",
212
- gap: 6,
213
- alignItems: "center",
933
+ capability: {
934
+ ...box,
935
+ padding: "8px 10px",
936
+ borderRadius: 8,
937
+ border: "1px solid var(--dsh-color-warning, #b45309)",
938
+ background: "var(--dsh-color-warning-soft, rgba(180,83,9,0.08))",
214
939
  fontSize: 12,
215
- opacity: .85
216
- },
217
- select: {
218
- padding: "3px 6px",
219
- borderRadius: 6,
220
- background: "transparent",
221
- color: "inherit",
222
- fontSize: 12
223
- },
224
- pills: {
225
- display: "flex",
226
- gap: 6,
227
- alignItems: "center"
228
- },
229
- pillOn: {
230
- ...button,
231
- borderColor: "var(--dsh-color-accent, #2f6fd0)",
232
- background: "var(--dsh-color-accent-soft, rgba(47,111,208,0.15))"
233
- },
234
- pillOff: {
235
- ...button,
236
- opacity: .55
237
- },
238
- button,
239
- primary: {
240
- ...button,
241
- borderColor: "var(--dsh-color-accent, #2f6fd0)",
242
- fontWeight: 600
243
- },
244
- linkButton: {
245
- ...button,
246
- border: "none",
247
- opacity: .7,
248
- padding: "2px 4px"
940
+ lineHeight: 1.5
249
941
  },
250
942
  panel: {
251
943
  ...box,
252
944
  display: "flex",
253
945
  flexDirection: "column",
254
- gap: 8,
255
- padding: "10px 12px",
946
+ gap: 6,
947
+ padding: "8px 10px",
256
948
  border: "1px solid var(--dsh-color-border, rgba(128,128,128,0.25))",
257
949
  borderRadius: 8
258
950
  },
@@ -265,6 +957,13 @@ window.__ModuleLoader__.load({
265
957
  fontWeight: 600,
266
958
  opacity: .8
267
959
  },
960
+ panelHeadRight: {
961
+ display: "flex",
962
+ alignItems: "center",
963
+ gap: 8,
964
+ whiteSpace: "nowrap",
965
+ fontWeight: 400
966
+ },
268
967
  entry: {
269
968
  display: "flex",
270
969
  gap: 6,
@@ -272,14 +971,34 @@ window.__ModuleLoader__.load({
272
971
  flexWrap: "wrap",
273
972
  fontSize: 12
274
973
  },
275
- statusOk: { color: "var(--dsh-color-success, #15803d)" },
276
- statusMissing: { color: "var(--dsh-color-warning, #b45309)" },
277
- statusRejected: { color: "var(--dsh-color-danger, #b91c1c)" },
974
+ code: {
975
+ fontFamily: "var(--dsh-font-mono, monospace)",
976
+ fontSize: 12,
977
+ wordBreak: "break-all"
978
+ },
979
+ dim: {
980
+ opacity: .6,
981
+ fontSize: 12,
982
+ lineHeight: 1.5
983
+ },
278
984
  warn: {
279
985
  color: "var(--dsh-color-warning, #b45309)",
280
986
  fontSize: 12,
281
987
  lineHeight: 1.5
282
- }
988
+ },
989
+ danger: {
990
+ color: "var(--dsh-color-danger, #b91c1c)",
991
+ fontSize: 12,
992
+ lineHeight: 1.5
993
+ },
994
+ statusOk: { color: "var(--dsh-color-success, #15803d)" },
995
+ statusMissing: { color: "var(--dsh-color-warning, #b45309)" },
996
+ statusRejected: { color: "var(--dsh-color-danger, #b91c1c)" },
997
+ statusForeign: {
998
+ color: "var(--dsh-color-text-secondary, inherit)",
999
+ opacity: .7
1000
+ },
1001
+ button
283
1002
  };
284
1003
  /**
285
1004
  * Interactive states cannot live in a style OBJECT (there is no `:focus` key),
@@ -299,14 +1018,22 @@ window.__ModuleLoader__.load({
299
1018
  font-size: 13px;
300
1019
  transition: border-color 120ms ease, box-shadow 120ms ease;
301
1020
  }
302
- .xp-input:hover, .xp-select:hover { border-color: var(--dsh-color-border-strong, rgba(128,128,128,0.6)); }
303
- .xp-input:focus, .xp-select:focus { outline: none; }
304
- .xp-input:focus-visible, .xp-select:focus-visible {
1021
+ .xp-input:hover, .xp-select:hover, .xp-textarea:hover { border-color: var(--dsh-color-border-strong, rgba(128,128,128,0.6)); }
1022
+ .xp-input:focus, .xp-select:focus, .xp-textarea:focus { outline: none; }
1023
+ .xp-input:focus-visible, .xp-select:focus-visible, .xp-textarea:focus-visible {
305
1024
  outline: none;
306
1025
  border-color: var(--dsh-color-accent, #2f6fd0);
307
1026
  box-shadow: 0 0 0 2px var(--dsh-color-accent-soft, rgba(47,111,208,0.25));
308
1027
  }
309
- .xp-input::placeholder { color: currentColor; opacity: 0.38; }
1028
+ .xp-input::placeholder, .xp-textarea::placeholder { color: currentColor; opacity: 0.38; }
1029
+ .xp-textarea {
1030
+ box-sizing: border-box;
1031
+ border: 1px solid var(--dsh-color-border, rgba(128,128,128,0.35));
1032
+ border-radius: 8px;
1033
+ background: transparent;
1034
+ color: inherit;
1035
+ transition: border-color 120ms ease, box-shadow 120ms ease;
1036
+ }
310
1037
  .xp-button {
311
1038
  box-sizing: border-box;
312
1039
  padding: 4px 10px;
@@ -322,16 +1049,47 @@ window.__ModuleLoader__.load({
322
1049
  .xp-button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsh-color-accent-soft, rgba(47,111,208,0.25)); }
323
1050
  .xp-button:disabled { opacity: 0.45; cursor: default; }
324
1051
  .xp-button-on { border-color: var(--dsh-color-accent, #2f6fd0); background: var(--dsh-color-accent-soft, rgba(47,111,208,0.15)); }
325
- .xp-button-off { opacity: 0.55; }
326
1052
  .xp-link { border: none; background: none; padding: 2px 4px; opacity: 0.7; font-size: 12px; cursor: pointer; color: inherit; }
327
1053
  .xp-link:hover { opacity: 1; text-decoration: underline; }
1054
+
1055
+ /* One column template for a rule row (the row component is kept for tests and
1056
+ compositions; the page itself edits plain text). */
1057
+ display: grid;
1058
+ grid-template-columns: 10px 150px minmax(0, 1fr) 66px 96px 22px;
1059
+ column-gap: 8px;
1060
+ align-items: center;
1061
+ }
1062
+ /* One control height for every cell; the previous flex row mixed 26px buttons
1063
+ with 31px inputs, so nothing sat on one baseline. */
1064
+ .xp-toolbar .xp-button { height: 28px; display: inline-flex; align-items: center; }
1065
+
1066
+ /* Preview entries share their own template: status / access / spelling → resolution. */
1067
+ .xp-entry {
1068
+ display: grid;
1069
+ grid-template-columns: 62px 116px minmax(0, 1fr);
1070
+ column-gap: 8px;
1071
+ align-items: baseline;
1072
+ font-size: 12px;
1073
+ }
1074
+ .xp-entry-paths { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
328
1075
  `;
329
1076
  //#endregion
330
1077
  //#region src/client/page.tsx
331
1078
  /**
332
- * The Extra paths settings page: one card per configured path, Chinese labels,
333
- * a LIVE lexical resolution per row against a base workspace, quick add
334
- * buttons, and the host's authoritative preview of the DRAFT (unsaved rows).
1079
+ * The Extra paths settings page: ONE plain-text editor for every rule
1080
+ * (`path | access | surfaces` per line, with an always-visible defaults line and
1081
+ * a collapsible examples block), the base-workspace picker used only for the
1082
+ * preview, and the host's authoritative preview of the DRAFT.
1083
+ *
1084
+ * Why the page looks like this: rows and mode switches were removed after the
1085
+ * third round of UI feedback — the text form is the single source of truth, and
1086
+ * Save is the only action. Saving always writes the structured
1087
+ * `{path, access, surfaces}` array; the editor is only a view of it.
1088
+ *
1089
+ * Copy follows the host's own language selection: every string comes from the
1090
+ * dictionaries registered by `./index` through the framework-injected `t` seat,
1091
+ * and the Chinese dictionary is the built-in fallback for a host that supplies
1092
+ * no seat at all (0.1.5 slots, unit tests).
335
1093
  *
336
1094
  * The base workspace comes from the shell's standard `useWorkspaces` hook when
337
1095
  * the slot supplies it — a snapshot read once during activation would be
@@ -341,50 +1099,273 @@ window.__ModuleLoader__.load({
341
1099
  * @module dsh-extra-paths/client/page
342
1100
  */
343
1101
  /**
344
- * Shown when the host refuses a write. The 0.2.x client API returns `false`
345
- * rather than a message, so the page owns this explanation.
1102
+ * Marker carried by a refusal raised in the late-bound scope. The page maps it
1103
+ * to localized copy instead of showing the scope's internal message.
346
1104
  */
347
- const SAVE_REFUSED_MESSAGE = "保存被宿主拒绝:该配置可能被 home patch 或命令行覆盖(设置页只写 profile 的 cordis.patch.yml)。请删掉 ~/.dsh/cordis.patch.yml 里同 id 的覆盖,或直接改 profile patch 后重启。";
1105
+ const SAVE_REFUSED_CODE = "extra-paths/save-refused";
1106
+ /**
1107
+ * Message carried by that marker error (Chinese). The page shows the localized
1108
+ * `saveRefused` copy; this text only reaches logs/tests.
1109
+ */
1110
+ const SAVE_REFUSED_MESSAGE = zh.saveRefused;
1111
+ /** Build the refusal error the page recognizes. */
1112
+ function saveRefusedError() {
1113
+ const error = new Error(SAVE_REFUSED_MESSAGE);
1114
+ error.code = SAVE_REFUSED_CODE;
1115
+ return error;
1116
+ }
1117
+ /** Whether a rejected save is the host refusing the write. */
1118
+ function isSaveRefused(cause) {
1119
+ return cause?.code === SAVE_REFUSED_CODE;
1120
+ }
348
1121
  const NOOP_HOOK = () => void 0;
349
1122
  const IDENTITY = (snapshot) => snapshot;
350
- function itemsOf(value) {
351
- const items = value?.items;
352
- return Array.isArray(items) ? items : [];
353
- }
1123
+ const ACCESS_LABEL = {
1124
+ deny: "accessDeny",
1125
+ read: "accessRead",
1126
+ write: "accessWrite",
1127
+ "always-write": "accessAlways"
1128
+ };
354
1129
  const STATUS_LABEL = {
355
- ok: "生效",
356
- missing: "目录不存在",
357
- rejected: "已拒绝"
1130
+ ok: "statusOk",
1131
+ missing: "statusMissing",
1132
+ rejected: "statusRejected",
1133
+ foreign: "statusForeign"
358
1134
  };
359
1135
  const STATUS_STYLE = {
360
1136
  ok: styles.statusOk,
361
1137
  missing: styles.statusMissing,
362
- rejected: styles.statusRejected
1138
+ rejected: styles.statusRejected,
1139
+ foreign: styles.statusForeign
363
1140
  };
364
- const SCOPE_LABEL = {
365
- write: "随会话模式(read-only 下拒绝)",
366
- "always-write": "始终可写(read-only 下也允许)"
1141
+ const TEXT_ERROR_LABEL = {
1142
+ "empty-path": "textErrorEmptyPath",
1143
+ "unknown-access": "textErrorUnknownAccess",
1144
+ "unknown-surfaces": "textErrorUnknownSurfaces",
1145
+ "too-many-fields": "textErrorTooManyFields"
367
1146
  };
368
- function rowsOf(section) {
369
- const rows = [];
370
- for (const item of section?.paths ?? []) if (typeof item === "string") rows.push({
371
- path: item,
372
- scope: "write",
373
- surfaces: ["fs", "shell"]
1147
+ function itemsOf(value) {
1148
+ const items = value?.items;
1149
+ return Array.isArray(items) ? items : [];
1150
+ }
1151
+ /**
1152
+ * Localized one-line message for a rejected text-mode line.
1153
+ * @param tr - the host's translate seat (or the Chinese fallback).
1154
+ * @param error - one parser error with its 1-based line number.
1155
+ * @returns `第 n 行:…` / `Line n: …`.
1156
+ */
1157
+ function textErrorMessage(tr, error) {
1158
+ const params = error.value === void 0 ? void 0 : { value: error.value };
1159
+ return `${tr("textErrorAtLine", { line: error.line })}${tr(TEXT_ERROR_LABEL[error.code], params)}`;
1160
+ }
1161
+ /**
1162
+ * The tooltip of a NAME RULE row: what the spelling means, plus — once the
1163
+ * host's preview has walked the scope roots — how many paths currently match
1164
+ * (zero is a valid answer: the rule still applies to paths created later).
1165
+ * @param tr - the host's translate seat (or the Chinese fallback).
1166
+ * @param hostEntry - the host's preview entry for this row, when it has arrived.
1167
+ * @returns the localized one-line explanation.
1168
+ */
1169
+ function nameRuleText(tr, hostEntry) {
1170
+ const hint = tr("nameRuleHint");
1171
+ const matches = hostEntry?.matches;
1172
+ if (matches === void 0) return hint;
1173
+ return `${hint} · ${matches > 0 ? tr("nameRuleMatches", { count: matches }) : tr("nameRuleNoMatches")}`;
1174
+ }
1175
+ /**
1176
+ * Whether the shell surface cannot enforce a configured restriction on this host.
1177
+ * Before the host reports capabilities (undefined) nothing is claimed.
1178
+ * @param capabilities - the host's shell capability matrix.
1179
+ * @param rows - the current rules.
1180
+ * @returns true when a deny/read rule targets a shell that cannot honor it.
1181
+ */
1182
+ function needsShellLimitWarning(capabilities, rows) {
1183
+ if (capabilities === void 0) return false;
1184
+ if (!rows.some((row) => (row.access === "deny" || row.access === "read") && row.surfaces.includes("shell"))) return false;
1185
+ return !capabilities.shellReadDeny || !capabilities.shellWriteDeny;
1186
+ }
1187
+ /**
1188
+ * The honesty banner: a deny/read rule that targets `shell` on a dialect that
1189
+ * cannot subtract permissions (landlock, Windows ACL) is still enforced for the
1190
+ * fs tools — but bash will not honor it. The page must say that out loud.
1191
+ * @param props - capability matrix, current rules and the translate seat.
1192
+ */
1193
+ function CapabilityBanner({ capabilities, rows, t }) {
1194
+ const tr = t ?? fallbackTranslate;
1195
+ if (!needsShellLimitWarning(capabilities, rows)) return null;
1196
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1197
+ style: styles.capability,
1198
+ role: "status",
1199
+ children: tr("capabilityShellLimit", { dialect: capabilities?.shellDialect ?? "unknown" })
374
1200
  });
375
- else rows.push({
376
- path: item.path ?? "",
377
- scope: item.scope ?? "write",
378
- surfaces: [...item.surfaces ?? ["fs", "shell"]]
1201
+ }
1202
+ /**
1203
+ * The rule editor: the syntax hint, the live defaults line, the collapsible
1204
+ * examples, a monospace textarea and per-line errors. It owns NO action — Save
1205
+ * lives in the page toolbar and parses the whole draft (all-or-nothing), so the
1206
+ * editor can never disagree with the stored configuration.
1207
+ * @param props - editor content, parser errors, defaults copy and the change hook.
1208
+ */
1209
+ function TextModeEditor({ tr, value, errors, defaultsText, onChange }) {
1210
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1211
+ style: styles.textEditor,
1212
+ children: [
1213
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1214
+ style: styles.dim,
1215
+ children: tr("textModeHint")
1216
+ }),
1217
+ defaultsText === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1218
+ style: styles.dim,
1219
+ children: defaultsText
1220
+ }),
1221
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
1222
+ style: styles.examples,
1223
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", {
1224
+ style: styles.examplesSummary,
1225
+ children: tr("examplesTitle")
1226
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
1227
+ style: styles.examplesBody,
1228
+ children: tr("examplesBody")
1229
+ })]
1230
+ }),
1231
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
1232
+ className: "xp-textarea",
1233
+ style: styles.textarea,
1234
+ rows: 12,
1235
+ spellCheck: false,
1236
+ value,
1237
+ "aria-label": tr("textMode"),
1238
+ onChange: (event) => {
1239
+ onChange?.(event.target.value);
1240
+ }
1241
+ }),
1242
+ errors !== void 0 && errors.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1243
+ style: styles.textErrors,
1244
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1245
+ style: styles.warn,
1246
+ children: tr("textModeInvalid")
1247
+ }), errors.map((error) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1248
+ style: styles.warn,
1249
+ children: textErrorMessage(tr, error)
1250
+ }, `${error.line}-${error.code}`))]
1251
+ }) : null
1252
+ ]
379
1253
  });
380
- return rows;
381
1254
  }
382
- function payloadOf(rows) {
383
- return rows.filter((row) => row.path.trim() !== "").map((row) => ({
384
- path: row.path.trim(),
385
- scope: row.scope,
386
- surfaces: [...row.surfaces]
387
- }));
1255
+ /** Why the base field cannot be used yet, localized (undefined when it is fine). */
1256
+ function baseProblemText(tr, base) {
1257
+ if (base.ok) return void 0;
1258
+ switch (base.problem) {
1259
+ case "empty": return;
1260
+ case "relative": return tr("resolveBaseInvalid");
1261
+ case "waiting": return tr("baseWaiting");
1262
+ case "foreign": return tr("baseForeign");
1263
+ }
1264
+ }
1265
+ /**
1266
+ * The host's resolution report, collapsed by default: the text editor is the
1267
+ * main view, and the preview is the authoritative detail when the user wants it.
1268
+ * @param props - expansion state, the base outcome, the preview payload and dirty flag.
1269
+ */
1270
+ function PreviewPanel({ tr, expanded, onToggle, typedBase, base, preview, dirty }) {
1271
+ const writable = preview?.writable ?? preview?.effective ?? [];
1272
+ const readOnly = preview?.readOnly ?? [];
1273
+ const denied = preview?.denied ?? [];
1274
+ let body;
1275
+ if (typedBase === "") body = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1276
+ style: styles.dim,
1277
+ children: tr("previewNoBase")
1278
+ });
1279
+ else if (!base.ok) body = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1280
+ style: styles.dim,
1281
+ children: base.problem === "relative" ? tr("previewBadBase") : base.problem === "waiting" ? tr("previewExpandingHome") : tr("baseForeign")
1282
+ });
1283
+ else if (preview === void 0) body = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1284
+ style: styles.dim,
1285
+ children: tr("previewUnavailable")
1286
+ });
1287
+ else if (preview.entries.length === 0 && readOnly.length === 0 && denied.length === 0) body = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1288
+ style: styles.dim,
1289
+ children: tr("previewEmpty")
1290
+ });
1291
+ else body = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1292
+ preview.entries.map((entry, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1293
+ className: "xp-entry",
1294
+ children: [
1295
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1296
+ style: STATUS_STYLE[entry.status],
1297
+ children: [
1298
+ "[",
1299
+ tr(STATUS_LABEL[entry.status]),
1300
+ "]"
1301
+ ]
1302
+ }),
1303
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1304
+ style: styles.dim,
1305
+ children: entry.access === void 0 ? "" : tr(ACCESS_LABEL[entry.access])
1306
+ }),
1307
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1308
+ className: "xp-entry-paths",
1309
+ children: [
1310
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1311
+ style: styles.code,
1312
+ children: entry.raw
1313
+ }),
1314
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1315
+ style: styles.dim,
1316
+ children: "→"
1317
+ }),
1318
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1319
+ style: styles.code,
1320
+ children: entry.resolved !== "" ? entry.resolved : isNameRulePath(entry.raw) ? nameRuleText(tr, entry) : tr("unresolved")
1321
+ })
1322
+ ]
1323
+ })
1324
+ ]
1325
+ }, `${index}-${entry.raw}`)),
1326
+ readOnly.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1327
+ style: styles.entry,
1328
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1329
+ style: styles.dim,
1330
+ children: tr("previewReadOnly", { count: readOnly.length })
1331
+ }), readOnly.map((path) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1332
+ style: styles.code,
1333
+ children: path
1334
+ }, path))]
1335
+ }) : null,
1336
+ denied.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1337
+ style: styles.entry,
1338
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1339
+ style: styles.dim,
1340
+ children: tr("previewDenied", { count: denied.length })
1341
+ }), denied.map((path) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1342
+ style: styles.code,
1343
+ children: path
1344
+ }, path))]
1345
+ }) : null,
1346
+ preview.warnings.map((warning) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1347
+ style: styles.warn,
1348
+ children: warning
1349
+ }, warning))
1350
+ ] });
1351
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1352
+ style: styles.panel,
1353
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1354
+ style: styles.panelHead,
1355
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [tr("previewTitle"), dirty ? tr("previewDirty") : ""] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1356
+ style: styles.panelHeadRight,
1357
+ children: [preview === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1358
+ style: styles.dim,
1359
+ children: tr("previewEffective", { count: writable.length })
1360
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1361
+ type: "button",
1362
+ className: "xp-link",
1363
+ onClick: onToggle,
1364
+ children: expanded ? tr("collapse") : tr("expand")
1365
+ })]
1366
+ })]
1367
+ }), expanded ? body : null]
1368
+ });
388
1369
  }
389
1370
  function useSnapshot(scope) {
390
1371
  const [snapshot, setSnapshot] = react.useState(() => scope.getSnapshot());
@@ -400,12 +1381,13 @@ window.__ModuleLoader__.load({
400
1381
  * list, and the full view on the entry's own page. Rendering the editor for both
401
1382
  * is what used to fill the Plugins page with the whole form, so the summary is a
402
1383
  * separate component that can never grow one.
403
- * @param props - the bound settings scope.
1384
+ * @param props - the bound settings scope and the host's translate seat.
404
1385
  */
405
- function ExtraPathsSummary({ scope }) {
1386
+ function ExtraPathsSummary({ scope, t }) {
1387
+ const translate = t ?? fallbackTranslate;
406
1388
  const { status, value } = useSnapshot(scope);
407
1389
  const rows = rowsOf(value).filter((row) => row.path.trim() !== "");
408
- const text = status === "loading" ? "额外可写路径:读取中…" : status === "unavailable" ? "额外可写路径:宿主未提供该设置" : rows.length === 0 ? "额外可写路径:尚未配置" : `额外可写路径:${rows.length} 条 · 保存即生效,写入无需审批`;
1390
+ const text = status === "loading" ? translate("summaryLoading") : status === "unavailable" ? translate("summaryUnavailable") : rows.length === 0 ? translate("summaryEmpty") : translate("summaryCount", { count: rows.length });
409
1391
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
410
1392
  style: styles.dim,
411
1393
  children: text
@@ -413,24 +1395,43 @@ window.__ModuleLoader__.load({
413
1395
  }
414
1396
  /**
415
1397
  * Render the page.
416
- * @param props - the bound settings scope, the standard workspace hook, and the
417
- * lazy fallback used when the composition supplies no standard props.
1398
+ * @param props - the bound settings scope, the host's translate seat, the
1399
+ * standard workspace hook, and the lazy fallback used when the composition
1400
+ * supplies no standard props.
418
1401
  */
419
- function ExtraPathsPage({ scope, getWorkspaces, useWorkspaces }) {
1402
+ function ExtraPathsPage({ scope, t, getWorkspaces, useWorkspaces }) {
1403
+ const tr = t ?? fallbackTranslate;
420
1404
  const snapshot = useSnapshot(scope);
421
1405
  const fromHook = itemsOf((useWorkspaces ?? NOOP_HOOK)(IDENTITY));
422
1406
  const candidates = (fromHook.length > 0 ? fromHook : itemsOf(getWorkspaces?.()?.list?.getSnapshot?.())).map((item) => item.path).filter((path) => typeof path === "string" && path !== "");
1407
+ const defaults = defaultsOf(snapshot.value);
423
1408
  const [rows, setRows] = react.useState(() => rowsOf(snapshot.value));
1409
+ const [text, setText] = react.useState(() => serializeRules(rowsOf(snapshot.value)));
424
1410
  const [dirty, setDirty] = react.useState(false);
425
1411
  const [busy, setBusy] = react.useState(false);
426
1412
  const [error, setError] = react.useState(void 0);
1413
+ const [textErrors, setTextErrors] = react.useState(void 0);
427
1414
  const [preview, setPreview] = react.useState(void 0);
428
1415
  const [cwd, setCwd] = react.useState(() => candidates[0] ?? "");
429
1416
  const [cwdPinned, setCwdPinned] = react.useState(false);
430
1417
  const [manualBase, setManualBase] = react.useState(false);
1418
+ const [introExpanded, setIntroExpanded] = react.useState(false);
1419
+ const [previewExpanded, setPreviewExpanded] = react.useState(false);
431
1420
  react.useEffect(() => {
432
- if (!dirty) setRows(rowsOf(snapshot.value));
433
- }, [snapshot, dirty]);
1421
+ if (dirty) return;
1422
+ const nextRows = rowsOf(snapshot.value);
1423
+ const parsed = parseRules(text, defaultsOf(snapshot.value));
1424
+ const sameAsStored = parsed.ok && JSON.stringify(payloadOf(parsed.rules)) === JSON.stringify(payloadOf(nextRows));
1425
+ setRows(nextRows);
1426
+ if (!sameAsStored) {
1427
+ setText(serializeRules(nextRows));
1428
+ setTextErrors(void 0);
1429
+ }
1430
+ }, [
1431
+ snapshot,
1432
+ dirty,
1433
+ text
1434
+ ]);
434
1435
  const first = candidates[0];
435
1436
  react.useEffect(() => {
436
1437
  if (!cwdPinned && cwd === "" && first !== void 0) setCwd(first);
@@ -439,16 +1440,18 @@ window.__ModuleLoader__.load({
439
1440
  cwd,
440
1441
  first
441
1442
  ]);
442
- const typedBase = cwd.trim();
443
- const usableBase = typedBase.startsWith("/") || typedBase === "~" || typedBase.startsWith("~/");
444
- const base = typedBase.startsWith("~") ? resolveLexically(typedBase, "", preview?.home) ?? "" : typedBase;
1443
+ const base = resolveBase(cwd, hostViewOf(preview));
1444
+ const previewBase = previewBaseOf(cwd, base);
445
1445
  const request = JSON.stringify(payloadOf(rows));
446
1446
  react.useEffect(() => {
447
- if (base === "") return;
1447
+ if (previewBase === "") {
1448
+ setPreview(void 0);
1449
+ return;
1450
+ }
448
1451
  let live = true;
449
1452
  const timer = setTimeout(() => {
450
1453
  const draft = JSON.parse(request);
451
- fetchPreview(base, draft).then((result) => {
1454
+ fetchPreview(previewBase, draft).then((result) => {
452
1455
  if (live) setPreview(result);
453
1456
  });
454
1457
  }, 250);
@@ -457,84 +1460,99 @@ window.__ModuleLoader__.load({
457
1460
  clearTimeout(timer);
458
1461
  };
459
1462
  }, [
460
- base,
1463
+ previewBase,
461
1464
  request,
462
1465
  snapshot
463
1466
  ]);
464
- const update = (index, patch) => {
1467
+ /**
1468
+ * Edit the one text form. A parse failure is reported per line and the last
1469
+ * VALID rows stay in place for the preview; Save refuses until it parses.
1470
+ */
1471
+ const change = (value) => {
465
1472
  setDirty(true);
466
- setRows((current) => current.map((row, i) => i === index ? {
467
- ...row,
468
- ...patch
469
- } : row));
470
- };
471
- const toggleSurface = (index, surface) => {
472
- const row = rows[index];
473
- if (row === void 0) return;
474
- const surfaces = row.surfaces.includes(surface) ? row.surfaces.filter((item) => item !== surface) : [...row.surfaces, surface];
475
- update(index, { surfaces });
476
- };
477
- const append = (path) => {
478
- setDirty(true);
479
- setRows((current) => [...current, {
480
- path,
481
- scope: "write",
482
- surfaces: ["fs", "shell"]
483
- }]);
484
- };
485
- const reset = () => {
486
- setRows(rowsOf(snapshot.value));
487
- setDirty(false);
1473
+ setText(value);
488
1474
  setError(void 0);
1475
+ const parsed = parseRules(value, defaults);
1476
+ if (parsed.ok) {
1477
+ setRows(parsed.rules);
1478
+ setTextErrors(void 0);
1479
+ } else setTextErrors(parsed.errors);
489
1480
  };
1481
+ /**
1482
+ * The page's only action: parse the whole text (all-or-nothing) and write the
1483
+ * structured `paths` array. A host refusal keeps the text intact.
1484
+ */
490
1485
  const save = () => {
1486
+ const parsed = parseRules(text, defaults);
1487
+ if (!parsed.ok) {
1488
+ setTextErrors(parsed.errors);
1489
+ return;
1490
+ }
491
1491
  setBusy(true);
492
1492
  setError(void 0);
493
- scope.set("paths", payloadOf(rows)).then((accepted) => {
494
- if (accepted === false) setError(SAVE_REFUSED_MESSAGE);
495
- else setDirty(false);
1493
+ scope.set("paths", payloadOf(parsed.rules)).then((accepted) => {
1494
+ if (accepted === false) setError(tr("saveRefused"));
1495
+ else {
1496
+ setRows(parsed.rules);
1497
+ setDirty(false);
1498
+ setTextErrors(void 0);
1499
+ }
496
1500
  }).catch((cause) => {
497
- setError(cause instanceof Error ? cause.message : String(cause));
1501
+ setError(isSaveRefused(cause) ? tr("saveRefused") : cause instanceof Error ? cause.message : String(cause));
498
1502
  }).finally(() => {
499
1503
  setBusy(false);
500
1504
  });
501
1505
  };
502
- const hostEntriesOf = (path) => preview?.entries.filter((entry) => entry.raw === path.trim()) ?? [];
503
- const hostEntryOf = (path) => hostEntriesOf(path)[0];
504
1506
  const picker = !manualBase && candidates.length > 0;
505
- const known = candidates.includes(typedBase);
1507
+ const known = candidates.includes(cwd.trim());
1508
+ const baseNotice = baseProblemText(tr, base);
506
1509
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
507
1510
  style: styles.page,
508
1511
  children: [
509
1512
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: css }),
510
1513
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1514
+ style: styles.introLine,
1515
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1516
+ style: styles.intro,
1517
+ children: tr("introCollapsed")
1518
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1519
+ type: "button",
1520
+ className: "xp-link",
1521
+ onClick: () => {
1522
+ setIntroExpanded(!introExpanded);
1523
+ },
1524
+ children: introExpanded ? tr("collapse") : tr("expand")
1525
+ })]
1526
+ }),
1527
+ introExpanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
511
1528
  style: styles.intro,
512
1529
  children: [
513
- "这些路径在会话工作区之外也可以写,",
514
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "不需要审批" }),
515
- ";写工具与终端都按下面的「作用面」生效。 相对路径按「基准工作区」解析——执法时用的是",
516
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "各会话自己的工作区" }),
517
- ",所以同一份配置在不同会话会指向不同目录。"
1530
+ tr("introBefore"),
1531
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: tr("introNoApproval") }),
1532
+ tr("introAfter"),
1533
+ tr("introRuleBefore"),
1534
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: tr("introRuleEmphasis") }),
1535
+ tr("introRuleAfter")
518
1536
  ]
519
- }),
1537
+ }) : null,
520
1538
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
521
1539
  style: styles.baseRow,
522
1540
  children: [
523
1541
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
524
- style: styles.cardTitle,
525
- children: "基准工作区"
1542
+ style: styles.label,
1543
+ children: tr("baseWorkspace")
526
1544
  }),
527
1545
  picker ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
528
1546
  className: "xp-select",
529
1547
  style: styles.baseField,
530
- value: known ? typedBase : "",
1548
+ value: known ? cwd.trim() : "",
531
1549
  onChange: (event) => {
532
1550
  setCwdPinned(true);
533
1551
  setCwd(event.target.value);
534
1552
  },
535
1553
  children: [known ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
536
- value: typedBase,
537
- children: typedBase === "" ? "(未选择)" : typedBase
1554
+ value: cwd.trim(),
1555
+ children: cwd.trim() === "" ? tr("notSelected") : cwd.trim()
538
1556
  }), candidates.map((path) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
539
1557
  value: path,
540
1558
  children: path
@@ -543,7 +1561,7 @@ window.__ModuleLoader__.load({
543
1561
  className: "xp-input",
544
1562
  style: styles.baseField,
545
1563
  value: cwd,
546
- placeholder: "绝对路径,或以 ~/ 开头(例如 ~/projects)",
1564
+ placeholder: tr("basePlaceholder"),
547
1565
  onChange: (event) => {
548
1566
  setCwdPinned(true);
549
1567
  setCwd(event.target.value);
@@ -553,243 +1571,64 @@ window.__ModuleLoader__.load({
553
1571
  type: "button",
554
1572
  className: "xp-link",
555
1573
  onClick: () => {
1574
+ setCwdPinned(true);
556
1575
  setManualBase(!manualBase);
557
1576
  },
558
- children: picker ? "手填" : "从列表选"
1577
+ children: picker ? tr("manualBase") : tr("pickBase")
559
1578
  }) : null,
560
1579
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
561
1580
  style: styles.dim,
562
- children: "仅用于预览与行内解析"
1581
+ children: tr("baseHint")
563
1582
  })
564
1583
  ]
565
1584
  }),
1585
+ baseNotice === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1586
+ style: styles.dim,
1587
+ children: baseNotice
1588
+ }),
566
1589
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1590
+ className: "xp-toolbar",
567
1591
  style: styles.toolbar,
568
- children: [
569
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
570
- type: "button",
571
- className: "xp-button xp-button-on",
572
- disabled: busy || !dirty,
573
- onClick: save,
574
- children: busy ? "保存中…" : "保存"
575
- }),
576
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
577
- type: "button",
578
- className: "xp-button",
579
- onClick: () => {
580
- append("");
581
- },
582
- children: "添加路径"
583
- }),
584
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
585
- type: "button",
586
- className: "xp-button",
587
- onClick: () => {
588
- append("..");
589
- },
590
- children: "添加工作区上一层(..)"
591
- }),
592
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
593
- type: "button",
594
- className: "xp-button",
595
- disabled: !dirty,
596
- onClick: reset,
597
- children: "放弃修改"
598
- }),
599
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
600
- style: styles.dim,
601
- children: dirty ? "有未保存的修改" : "已与配置同步"
602
- })
603
- ]
1592
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1593
+ type: "button",
1594
+ className: "xp-button xp-button-on",
1595
+ disabled: busy || !dirty,
1596
+ onClick: save,
1597
+ children: busy ? tr("saving") : tr("save")
1598
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1599
+ style: styles.dim,
1600
+ children: dirty ? tr("dirty") : tr("synced")
1601
+ })]
604
1602
  }),
605
- rows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
606
- style: styles.dim,
607
- children: "还没有配置路径:用上面的「添加路径」或「添加工作区上一层(..)」开始。"
608
- }) : null,
609
- rows.map((row, index) => {
610
- const patternRow = row.path.includes("*");
611
- const resolved = patternRow ? void 0 : resolveLexically(row.path, base, preview?.home);
612
- const hostMatches = hostEntriesOf(row.path);
613
- const hostEntry = hostEntryOf(row.path);
614
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
615
- style: styles.card,
616
- children: [
617
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
618
- style: styles.cardHead,
619
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
620
- style: styles.cardTitle,
621
- children: ["路径 ", index + 1]
622
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
623
- style: styles.cardHeadRight,
624
- children: [hostEntry !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
625
- style: STATUS_STYLE[hostEntry.status],
626
- children: [
627
- "[",
628
- STATUS_LABEL[hostEntry.status],
629
- hostMatches.length > 1 ? ` ×${hostMatches.length}` : "",
630
- "]"
631
- ]
632
- }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
633
- type: "button",
634
- className: "xp-link",
635
- onClick: () => {
636
- setDirty(true);
637
- setRows((current) => current.filter((_, i) => i !== index));
638
- },
639
- children: "删除"
640
- })]
641
- })]
642
- }),
643
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
644
- className: "xp-input",
645
- style: styles.pathInput,
646
- value: row.path,
647
- placeholder: "~/projects/notes/home、../某仓库、..(上一层)、~/projects/**/.worktrees/..(模式)",
648
- onChange: (event) => {
649
- update(index, { path: event.target.value });
650
- }
651
- }),
652
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
653
- style: styles.resolvedRow,
654
- children: patternRow ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
655
- style: styles.dim,
656
- children: [
657
- "模式:由宿主按目录结构展开",
658
- " ",
659
- hostMatches.length > 0 ? `当前命中 ${hostMatches.length} 个目录(见下方预览)` : "(暂无命中,或被展开上限拦截)"
660
- ]
661
- }) : resolved === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
662
- style: styles.dim,
663
- children: row.path.trim() === "" ? "填入路径后这里会显示解析结果" : typedBase === "" ? "相对路径需要基准工作区:请在上面选择或填写" : !usableBase ? "基准工作区需要绝对路径,或以 ~/ 开头(例如 ~/projects)" : "~ 需要宿主的家目录(第一次预览返回后即可解析)"
664
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
665
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
666
- style: styles.dim,
667
- children: "解析为"
668
- }),
669
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
670
- style: styles.code,
671
- children: resolved
672
- }),
673
- hostEntry !== void 0 && hostEntry.resolved !== resolved ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
674
- style: styles.dim,
675
- children: [
676
- "(宿主解析:",
677
- hostEntry.resolved,
678
- ")"
679
- ]
680
- }) : null
681
- ] })
682
- }),
683
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
684
- style: styles.controlsRow,
685
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
686
- style: styles.field,
687
- children: ["生效模式", /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
688
- className: "xp-select",
689
- value: row.scope,
690
- onChange: (event) => {
691
- update(index, { scope: event.target.value });
692
- },
693
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
694
- value: "write",
695
- children: SCOPE_LABEL.write
696
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
697
- value: "always-write",
698
- children: SCOPE_LABEL["always-write"]
699
- })]
700
- })]
701
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
702
- style: styles.pills,
703
- children: [
704
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
705
- style: styles.dim,
706
- children: "作用面"
707
- }),
708
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
709
- type: "button",
710
- className: row.surfaces.includes("fs") ? "xp-button xp-button-on" : "xp-button xp-button-off",
711
- onClick: () => {
712
- toggleSurface(index, "fs");
713
- },
714
- children: "写工具"
715
- }),
716
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
717
- type: "button",
718
- className: row.surfaces.includes("shell") ? "xp-button xp-button-on" : "xp-button xp-button-off",
719
- onClick: () => {
720
- toggleSurface(index, "shell");
721
- },
722
- children: "终端"
723
- })
724
- ]
725
- })]
726
- })
727
- ]
728
- }, index);
1603
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CapabilityBanner, {
1604
+ capabilities: preview?.capabilities,
1605
+ rows,
1606
+ t: tr
729
1607
  }),
730
- error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
731
- style: styles.warn,
732
- children: error
1608
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextModeEditor, {
1609
+ tr,
1610
+ value: text,
1611
+ errors: textErrors,
1612
+ defaultsText: tr("editorDefaults", {
1613
+ access: defaults.access,
1614
+ surfaces: defaults.surfaces.join("+")
1615
+ }),
1616
+ onChange: change
733
1617
  }),
734
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
735
- style: styles.panel,
736
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
737
- style: styles.panelHead,
738
- children: [
739
- "解析预览",
740
- dirty ? "(含未保存修改)" : "",
741
- preview !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
742
- style: styles.dim,
743
- children: [
744
- "生效根 ",
745
- preview.effective.length,
746
- " 条"
747
- ]
748
- }) : null
749
- ]
750
- }), typedBase === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
751
- style: styles.dim,
752
- children: "先在上面选择或填写「基准工作区」,这里就会显示宿主解析出的生效根。"
753
- }) : !usableBase ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
754
- style: styles.dim,
755
- children: "基准工作区需要绝对路径,或以 ~/ 开头(例如 ~/projects);相对路径不能当基准用。"
756
- }) : base === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
757
- style: styles.dim,
758
- children: "正在展开 ~:宿主的家目录会在第一次预览返回后给出。"
759
- }) : preview === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
760
- style: styles.dim,
761
- children: "预览不可用(宿主没提供该路由、连接还没就绪,或基准工作区被宿主拒绝)。"
762
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [preview.entries.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
763
- style: styles.dim,
764
- children: "还没有可解析的路径。"
765
- }) : preview.entries.map((entry, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
766
- style: styles.entry,
767
- children: [
768
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
769
- style: STATUS_STYLE[entry.status],
770
- children: [
771
- "[",
772
- STATUS_LABEL[entry.status],
773
- "]"
774
- ]
775
- }),
776
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
777
- style: styles.code,
778
- children: entry.raw
779
- }),
780
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
781
- style: styles.dim,
782
- children: "→"
783
- }),
784
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
785
- style: styles.code,
786
- children: entry.resolved === "" ? "(未解析)" : entry.resolved
787
- })
788
- ]
789
- }, `${index}-${entry.raw}`)), preview.warnings.map((warning) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
790
- style: styles.warn,
791
- children: warning
792
- }, warning))] })]
1618
+ error !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1619
+ style: styles.danger,
1620
+ children: error
1621
+ }) : null,
1622
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PreviewPanel, {
1623
+ tr,
1624
+ expanded: previewExpanded,
1625
+ onToggle: () => {
1626
+ setPreviewExpanded(!previewExpanded);
1627
+ },
1628
+ typedBase: cwd.trim(),
1629
+ base,
1630
+ preview,
1631
+ dirty
793
1632
  })
794
1633
  ]
795
1634
  });
@@ -834,6 +1673,15 @@ window.__ModuleLoader__.load({
834
1673
  * nothing declares is inert under `ctx.slots.inject` (the callback never runs),
835
1674
  * which is what lets one build register into both generations.
836
1675
  *
1676
+ * LOCALIZED COPY FOLLOWS THE HOST'S OWN LANGUAGE SELECTION. The client half
1677
+ * registers its `zh`/`en` dictionaries under this plugin's namespace through
1678
+ * `ctx.locale.register`, and every slot registration declares `locale: NAMESPACE`
1679
+ * so the renderer hands each page render the framework `t` seat. Switching
1680
+ * Settings → General → Language therefore switches this page too, without a
1681
+ * reload; languages without a dictionary fall back to English (the host's
1682
+ * documented baseline), and a host without a locale seat (0.1.5 slots, tests)
1683
+ * falls back to the built-in Chinese copy.
1684
+ *
837
1685
  * Every @deepseek-ai/* import here is TYPE-ONLY (erased): the runtime services
838
1686
  * arrive through cordis, and react resolves from the page's module table
839
1687
  * (see dsh.client in package.json).
@@ -842,11 +1690,12 @@ window.__ModuleLoader__.load({
842
1690
  /**
843
1691
  * Client services this half needs.
844
1692
  *
845
- * Only `slots`: the settings scope is fetched late-bound below, because the
1693
+ * `locale` ships in every supported host generation and backs the framework `t`
1694
+ * seat; the settings scope itself is fetched late-bound below, because the
846
1695
  * 0.1.5 (`settingsScope`) and 0.2.x (`configForms`) providers differ and an
847
1696
  * `inject` entry for a service that never appears would block activation.
848
1697
  */
849
- const inject = ["slots"];
1698
+ const inject = ["slots", "locale"];
850
1699
  /** The settings namespace this page edits — the one the host half registers. */
851
1700
  const NAMESPACE = "extra-paths";
852
1701
  /**
@@ -886,7 +1735,7 @@ window.__ModuleLoader__.load({
886
1735
  set: (field, value) => {
887
1736
  if (real === void 0) return Promise.resolve();
888
1737
  return real.set(field, value).then((accepted) => {
889
- if (accepted === false) throw new Error(SAVE_REFUSED_MESSAGE);
1738
+ if (accepted === false) throw saveRefusedError();
890
1739
  return accepted;
891
1740
  });
892
1741
  }
@@ -906,6 +1755,13 @@ window.__ModuleLoader__.load({
906
1755
  */
907
1756
  function apply(ctx) {
908
1757
  const { scope, attach } = lateBoundScope();
1758
+ const registerLocales = () => ctx.locale.register(NAMESPACE, {
1759
+ zh,
1760
+ en
1761
+ });
1762
+ if (typeof ctx.effect === "function") ctx.effect(registerLocales, "extra-paths: locales");
1763
+ else registerLocales();
1764
+ const t = ctx.locale.bind(NAMESPACE);
909
1765
  ctx.inject(["settingsScope"], (child) => {
910
1766
  const { settingsScope } = child;
911
1767
  attach(settingsScope.bind({ namespace: NAMESPACE }));
@@ -926,16 +1782,20 @@ window.__ModuleLoader__.load({
926
1782
  /** The editor, forwarding the shell's workspace hook when the slot carries one. */
927
1783
  const renderPage = (slotProps) => react.createElement(ExtraPathsPage, {
928
1784
  scope,
1785
+ t: typeof slotProps?.t === "function" ? slotProps.t : void 0,
929
1786
  getWorkspaces,
930
1787
  useWorkspaces: typeof slotProps?.useWorkspaces === "function" ? slotProps.useWorkspaces : void 0
931
1788
  });
932
1789
  /** The slot component: one line for `summary`, the editor for every other view. */
933
- const card = (slotProps) => slotProps?.view === "summary" ? react.createElement(ExtraPathsSummary, { scope }) : renderPage(slotProps);
1790
+ const card = (slotProps) => slotProps?.view === "summary" ? react.createElement(ExtraPathsSummary, {
1791
+ scope,
1792
+ t: typeof slotProps.t === "function" ? slotProps.t : void 0
1793
+ }) : renderPage(slotProps);
934
1794
  ctx.slots.inject("settings.section", () => ctx.slots.register({
935
1795
  name: "settings.section",
936
1796
  id: NAMESPACE,
937
1797
  order: 40,
938
- label: () => "额外可写路径",
1798
+ label: () => t("navLabel"),
939
1799
  locale: NAMESPACE,
940
1800
  inject: props
941
1801
  }, card));