dsh-cwtools 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,1305 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-cwtools",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
8
+ let react = require("react");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ // src/contract/toolCatalog.ts
11
+ const CWTOOLS_READ_TOOL_GROUPS = {
12
+ project: [
13
+ "query_project_profile",
14
+ "query_project_knowledge",
15
+ "query_workspace_index",
16
+ "explore_pdx_project",
17
+ "analyze_pdx_flow",
18
+ "query_inline_instantiation",
19
+ "compare_definition_with_vanilla"
20
+ ],
21
+ localisation: ["query_localisation_index"],
22
+ semantic: [
23
+ "query_types",
24
+ "query_rules",
25
+ "query_cwt_schema",
26
+ "search_rule_capabilities",
27
+ "explain_scope",
28
+ "parse_pdx_fragment",
29
+ "query_scope",
30
+ "query_scripted_effects",
31
+ "query_scripted_triggers",
32
+ "query_enums",
33
+ "query_static_modifiers",
34
+ "query_variables",
35
+ "get_entity_info",
36
+ "get_pdx_block",
37
+ "query_targeting_weight"
38
+ ],
39
+ navigation: [
40
+ "get_completion_at",
41
+ "document_symbols",
42
+ "workspace_symbols",
43
+ "go_to_definition",
44
+ "find_references"
45
+ ],
46
+ diagnostics: ["get_diagnostics", "analyze_diagnostic_error"],
47
+ shader: [
48
+ "query_shader_symbol",
49
+ "query_shader_compile_unit",
50
+ "query_shader_platform_variants",
51
+ "query_shader_callers",
52
+ "explain_shader_reachability",
53
+ "validate_shader",
54
+ "compare_shader_with_vanilla"
55
+ ]
56
+ };
57
+ const CWTOOLS_READ_GROUP_ORDER = [
58
+ "project",
59
+ "localisation",
60
+ "semantic",
61
+ "navigation",
62
+ "diagnostics",
63
+ "shader"
64
+ ];
65
+ const CWTOOLS_READ_TOOL_NAMES = Object.freeze(CWTOOLS_READ_GROUP_ORDER.flatMap((group) => [...CWTOOLS_READ_TOOL_GROUPS[group]]));
66
+ const CWTOOLS_WRITE_TOOL_NAMES = ["write_localisation"];
67
+ [...CWTOOLS_READ_TOOL_NAMES, ...CWTOOLS_WRITE_TOOL_NAMES];
68
+ const groupByTool = /* @__PURE__ */ new Map();
69
+ for (const group of CWTOOLS_READ_GROUP_ORDER) for (const name of CWTOOLS_READ_TOOL_GROUPS[group]) groupByTool.set(name, group);
70
+ function cwtoolsReadGroupFor(name) {
71
+ const group = groupByTool.get(name);
72
+ if (group === void 0) throw new Error("Unknown CWTools read tool: " + name);
73
+ return group;
74
+ }
75
+ // src/client/cwtools-controller.ts
76
+ /** Settings namespace of the Host entry this section edits. */
77
+ const CWTOOLS_SETTINGS_NAMESPACE = "cwtools";
78
+ /** Absolute paths and the game identifier of the backend block. */
79
+ const TEXT_FIELDS = [
80
+ {
81
+ field: "backend.serverPath",
82
+ block: "backend"
83
+ },
84
+ {
85
+ field: "backend.gamePath",
86
+ block: "backend"
87
+ },
88
+ {
89
+ field: "backend.rulesPath",
90
+ block: "backend"
91
+ },
92
+ {
93
+ field: "backend.cachePath",
94
+ block: "backend"
95
+ },
96
+ {
97
+ field: "backend.activeManifestPath",
98
+ block: "backend"
99
+ },
100
+ {
101
+ field: "backend.game",
102
+ block: "backend"
103
+ }
104
+ ];
105
+ /**
106
+ * Whole-number fields with the bounds the Host schema enforces.
107
+ *
108
+ * The Host owns these bounds (`src/config.ts`); the copy here only decides
109
+ * whether a draft is worth sending, so a typo fails in the form instead of
110
+ * becoming a refused write. A draft the Host rejects anyway is refused there
111
+ * and keeps its drafts.
112
+ */
113
+ const NUMBER_FIELDS = [
114
+ {
115
+ field: "backend.startupTimeoutMs",
116
+ block: "backend",
117
+ min: 1,
118
+ max: 2147483647
119
+ },
120
+ {
121
+ field: "backend.requestTimeoutMs",
122
+ block: "backend",
123
+ min: 1,
124
+ max: 2147483647
125
+ },
126
+ {
127
+ field: "backend.idleShutdownMs",
128
+ block: "backend",
129
+ min: 1,
130
+ max: 2147483647
131
+ },
132
+ {
133
+ field: "backend.maxWorkspaceRuntimes",
134
+ block: "backend",
135
+ min: 1,
136
+ max: 8
137
+ },
138
+ {
139
+ field: "output.maxResultChars",
140
+ block: "output",
141
+ min: 1e3,
142
+ max: 2e5
143
+ }
144
+ ];
145
+ /** Switches that are off until someone stores them. */
146
+ const DEFAULT_OFF_FIELDS = [
147
+ {
148
+ field: "backend.forceStart",
149
+ block: "backend"
150
+ },
151
+ {
152
+ field: "backend.debug",
153
+ block: "backend"
154
+ },
155
+ {
156
+ field: "writeTools.write_localisation",
157
+ block: "writeTools"
158
+ }
159
+ ];
160
+ /** Switches whose absent value means on: the master switch and every read grant. */
161
+ const DEFAULT_ON_FIELDS = [
162
+ {
163
+ field: "enabled",
164
+ block: "enabled"
165
+ },
166
+ {
167
+ field: "backend.preferActiveBackend",
168
+ block: "backend"
169
+ },
170
+ ...CWTOOLS_READ_GROUP_ORDER.map((group) => ({
171
+ field: `readGroups.${group}`,
172
+ block: "readGroups"
173
+ })),
174
+ ...CWTOOLS_READ_TOOL_NAMES.map((tool) => ({
175
+ field: `readTools.${tool}`,
176
+ block: "readTools"
177
+ }))
178
+ ];
179
+ /** Master switch and backend fields, in the order the page renders them. */
180
+ const topLevel = (block) => [
181
+ ...TEXT_FIELDS,
182
+ ...DEFAULT_OFF_FIELDS,
183
+ ...NUMBER_FIELDS,
184
+ ...DEFAULT_ON_FIELDS
185
+ ].filter((ref) => ref.block === block);
186
+ /** Diagnostic noise controls: two lists and the localisation filter mode. */
187
+ const DIAGNOSTIC_LIST_FIELDS = [{
188
+ field: "diagnostics.ignoreCodes",
189
+ block: "diagnostics"
190
+ }, {
191
+ field: "diagnostics.ignoreFiles",
192
+ block: "diagnostics"
193
+ }];
194
+ /** The three values the Host accepts for the localisation diagnostic filter. */
195
+ const CWTOOLS_LOCALISATION_FILTERS = [
196
+ "off",
197
+ "problems",
198
+ "all"
199
+ ];
200
+ /** Every control on the page, in rendering order. */
201
+ const CWTOOLS_FIELDS = [
202
+ ...topLevel("enabled"),
203
+ ...topLevel("backend"),
204
+ ...DIAGNOSTIC_LIST_FIELDS,
205
+ {
206
+ field: "diagnostics.localisationFilter",
207
+ block: "diagnostics"
208
+ },
209
+ ...topLevel("readGroups"),
210
+ ...topLevel("readTools"),
211
+ ...topLevel("writeTools"),
212
+ ...topLevel("output")
213
+ ];
214
+ /**
215
+ * Expand one level of block nesting into dotted leaf paths.
216
+ * @param section - an accepted section or one of its composition layers.
217
+ * @returns its leaves by dotted path; a nested object is expanded, not kept.
218
+ */
219
+ function flatten(section) {
220
+ const flat = {};
221
+ if (typeof section !== "object" || section === null || Array.isArray(section)) return flat;
222
+ for (const [key, value] of Object.entries(section)) if (typeof value === "object" && value !== null && !Array.isArray(value)) for (const [child, leaf] of Object.entries(value)) flat[`${key}.${child}`] = leaf;
223
+ else flat[key] = value;
224
+ return flat;
225
+ }
226
+ /**
227
+ * The conversion spec of one switch.
228
+ * @param field - dotted path of the switch.
229
+ * @param fallback - the text an absent value renders as.
230
+ * @returns the field's conversion spec.
231
+ */
232
+ function switchField(field, fallback) {
233
+ return {
234
+ field,
235
+ format: (value) => typeof value === "boolean" ? String(value) : fallback,
236
+ parse: (text) => text === "true" ? {
237
+ kind: "set",
238
+ value: true
239
+ } : text === "false" ? {
240
+ kind: "set",
241
+ value: false
242
+ } : void 0
243
+ };
244
+ }
245
+ /**
246
+ * A whole-number field that also refuses drafts outside the Host's bounds.
247
+ * @param ref - the field and its inclusive bounds.
248
+ * @returns the field's conversion spec.
249
+ */
250
+ function boundedNumberField(ref) {
251
+ const numeric = (0, _deepseek_ai_dsh_client_ui_primitives.settingsNumberField)(ref.field);
252
+ return {
253
+ ...numeric,
254
+ parse: (text) => {
255
+ const write = numeric.parse(text);
256
+ if (write?.kind !== "set") return write;
257
+ const value = write.value;
258
+ return Number.isSafeInteger(value) && value >= ref.min && value <= ref.max ? write : void 0;
259
+ }
260
+ };
261
+ }
262
+ /** A comma-separated list field: the Host document stores an array. */
263
+ function listField(field) {
264
+ return {
265
+ field,
266
+ format: (value) => Array.isArray(value) ? value.map((item) => String(item)).join(", ") : "",
267
+ parse: (text) => {
268
+ const items = text.split(/[,\n]/).map((item) => item.trim()).filter((item) => item.length > 0);
269
+ return items.length === 0 ? { kind: "clear" } : {
270
+ kind: "set",
271
+ value: items
272
+ };
273
+ }
274
+ };
275
+ }
276
+ /** The localisation filter enum: only the three Host values are accepted. */
277
+ function localisationFilterField(field) {
278
+ return {
279
+ field,
280
+ format: (value) => typeof value === "string" && CWTOOLS_LOCALISATION_FILTERS.includes(value) ? value : "off",
281
+ parse: (text) => CWTOOLS_LOCALISATION_FILTERS.includes(text) ? {
282
+ kind: "set",
283
+ value: text
284
+ } : void 0
285
+ };
286
+ }
287
+ /** The conversion spec of every control on the page. */
288
+ const SPECS = [
289
+ ...topLevel("enabled").map((ref) => switchField(ref.field, "true")),
290
+ ...DEFAULT_ON_FIELDS.filter((ref) => ref.block === "backend").map((ref) => switchField(ref.field, "true")),
291
+ ...TEXT_FIELDS.map((ref) => (0, _deepseek_ai_dsh_client_ui_primitives.settingsTextField)(ref.field)),
292
+ ...DEFAULT_OFF_FIELDS.filter((ref) => ref.block === "backend").map((ref) => switchField(ref.field, "false")),
293
+ ...NUMBER_FIELDS.filter((ref) => ref.block === "backend").map(boundedNumberField),
294
+ ...DIAGNOSTIC_LIST_FIELDS.map((ref) => listField(ref.field)),
295
+ localisationFilterField("diagnostics.localisationFilter"),
296
+ ...topLevel("readGroups").map((ref) => switchField(ref.field, "true")),
297
+ ...topLevel("readTools").map((ref) => switchField(ref.field, "true")),
298
+ ...DEFAULT_OFF_FIELDS.filter((ref) => ref.block === "writeTools").map((ref) => switchField(ref.field, "false")),
299
+ ...NUMBER_FIELDS.filter((ref) => ref.block === "output").map(boundedNumberField)
300
+ ];
301
+ /** Read the spec of one field. */
302
+ const specOf = (field) => SPECS.find((candidate) => candidate.field === field);
303
+ /**
304
+ * Present one Host entry as a flat section, and translate its single-element
305
+ * write paths back into the nested paths the document stores.
306
+ */
307
+ var FlatSectionScope = class {
308
+ form;
309
+ /** The last write attempted, so the section can tell a refusal from a conflict. */
310
+ lastWrite;
311
+ cache;
312
+ listeners = /* @__PURE__ */ new Set();
313
+ /** @param form - the shared configuration form of this Host entry. */
314
+ constructor(form) {
315
+ this.form = form;
316
+ }
317
+ /** @returns the entry's current snapshot with every block flattened. */
318
+ getSnapshot() {
319
+ const source = this.form.getSnapshot();
320
+ if (this.cache?.source === source) return this.cache.flat;
321
+ const flat = {
322
+ status: source.status,
323
+ value: source.value === void 0 ? void 0 : flatten(source.value),
324
+ base: flatten(source.base),
325
+ user: flatten(source.user),
326
+ writable: source.writable,
327
+ revision: source.revision
328
+ };
329
+ this.cache = {
330
+ source,
331
+ flat
332
+ };
333
+ return flat;
334
+ }
335
+ /**
336
+ * Observe snapshot replacements, keeping this adapter's own listeners so a
337
+ * settled write republishes the refusal bookkeeping.
338
+ * @param listener - invoked after each change.
339
+ * @returns the disposer removing this listener.
340
+ */
341
+ subscribe(listener) {
342
+ const unsubscribe = this.form.subscribe(listener);
343
+ this.listeners.add(listener);
344
+ return () => {
345
+ this.listeners.delete(listener);
346
+ unsubscribe();
347
+ };
348
+ }
349
+ /**
350
+ * Write one save's operations as a single revision-fenced mutation.
351
+ * @param ops - the staged operations, addressed by dotted path.
352
+ * @param expectedRevision - the revision the drafts were staged against.
353
+ * @returns whether the Host accepted the mutation.
354
+ */
355
+ async mutate(ops, expectedRevision) {
356
+ const revision = expectedRevision ?? this.form.getSnapshot().revision;
357
+ this.lastWrite = {
358
+ fields: ops.map((op) => op.path.join(".")),
359
+ revision,
360
+ accepted: false
361
+ };
362
+ const accepted = await this.form.mutate(ops.map(toWireOp), revision);
363
+ this.lastWrite = {
364
+ fields: this.lastWrite.fields,
365
+ revision,
366
+ accepted
367
+ };
368
+ for (const listener of [...this.listeners]) listener();
369
+ return accepted;
370
+ }
371
+ /** Release this view of the shared form. */
372
+ dispose() {
373
+ this.listeners.clear();
374
+ }
375
+ };
376
+ /**
377
+ * Translate one staged operation into the wire shape the Host accepts: the
378
+ * single dotted segment the shared model uses becomes the nested path the
379
+ * Host document stores.
380
+ * @param op - the staged operation.
381
+ * @returns the same operation addressed inside the document.
382
+ */
383
+ function toWireOp(op) {
384
+ const path = [...op.path].flatMap((segment) => segment.split("."));
385
+ return op.op === "set" ? {
386
+ op: "set",
387
+ path,
388
+ value: op.value
389
+ } : {
390
+ op: "unset",
391
+ path
392
+ };
393
+ }
394
+ /**
395
+ * Bind the whole CWTools section to one staged form.
396
+ *
397
+ * Every control is staged; a save writes the staged edits together; leaving the
398
+ * page drops them. A refused save keeps its drafts, reports the values the Host
399
+ * still holds, and says whether the document moved underneath.
400
+ */
401
+ var CwtoolsSettingsController = class {
402
+ scope;
403
+ form;
404
+ store;
405
+ /** @param form - the shared configuration form of the `cwtools` entry. */
406
+ constructor(form) {
407
+ this.scope = new FlatSectionScope(form);
408
+ this.form = new _deepseek_ai_dsh_client_ui_primitives.SettingsFormModel(this.scope, [...SPECS]);
409
+ this.store = this.form.bind(() => this.project());
410
+ }
411
+ /**
412
+ * Bind the section to the slot renderer.
413
+ * @returns the section snapshot and its staged actions.
414
+ */
415
+ inject() {
416
+ return {
417
+ hooks: { cwtoolsSection: this.store },
418
+ ...this.form.actions(),
419
+ toggle: (field, next) => {
420
+ this.form.actions().edit(field, String(next));
421
+ }
422
+ };
423
+ }
424
+ /** Release the accepted-value subscription and the flattened view. */
425
+ dispose() {
426
+ this.form.dispose();
427
+ this.scope.dispose();
428
+ }
429
+ /** Rebuild everything the component renders from the current reads and drafts. */
430
+ project() {
431
+ const shell = this.form.shell();
432
+ const fields = {};
433
+ for (const ref of CWTOOLS_FIELDS) fields[ref.field] = this.form.field(ref.field);
434
+ const stored = (field) => fields[field]?.text === "true";
435
+ const groups = {};
436
+ for (const group of CWTOOLS_READ_GROUP_ORDER) groups[group] = stored(`readGroups.${group}`);
437
+ const tools = {};
438
+ for (const tool of CWTOOLS_READ_TOOL_NAMES) tools[tool] = groups[cwtoolsReadGroupFor(tool)] && stored(`readTools.${tool}`);
439
+ return {
440
+ ...shell,
441
+ fields,
442
+ groups,
443
+ tools,
444
+ conflict: shell.failed && this.conflict(),
445
+ accepted: shell.failed ? this.acceptedValues() : []
446
+ };
447
+ }
448
+ /** Whether the refused write lost a revision race rather than failing validation. */
449
+ conflict() {
450
+ const write = this.scope.lastWrite;
451
+ if (write === void 0 || write.accepted) return false;
452
+ const revision = this.scope.getSnapshot().revision;
453
+ return write.revision !== void 0 && revision !== void 0 && revision !== write.revision;
454
+ }
455
+ /**
456
+ * The values the Host still holds for the fields the refused save tried to
457
+ * write. Read from the accepted section, never from the draft, so the notice
458
+ * shows what a reload would restore.
459
+ */
460
+ acceptedValues() {
461
+ const write = this.scope.lastWrite;
462
+ if (write === void 0) return [];
463
+ const accepted = this.scope.getSnapshot().value ?? {};
464
+ return write.fields.flatMap((field) => {
465
+ const spec = specOf(field);
466
+ if (spec === void 0) return [];
467
+ return [{
468
+ field,
469
+ text: spec.format(accepted[field])
470
+ }];
471
+ });
472
+ }
473
+ };
474
+ // src/client/locales.ts
475
+ /** English copy. */
476
+ const en = {
477
+ nav: "CWTools",
478
+ title: "CWTools",
479
+ intro: "Configure the CWTools language server and which semantic tools this bundle exposes. Every control on this page is saved together.",
480
+ sectionProject: "Project and game",
481
+ sectionBackend: "Backend and runtime",
482
+ tabProject: "Project",
483
+ tabBackend: "Backend",
484
+ tabRead: "Read tools",
485
+ tabOutput: "Write and output",
486
+ sectionReadAccess: "Read tools",
487
+ sectionDiagnostics: "Diagnostic filter",
488
+ ignoreCodes: "Ignored error codes",
489
+ ignoreCodesHint: "Comma-separated codes or message fragments the backend never reports. Vanilla errors are already off.",
490
+ ignoreFiles: "Ignored file names",
491
+ ignoreFilesHint: "Comma-separated file names whose diagnostics are dropped, such as zz_legacy.txt.",
492
+ localisationFilter: "Localisation diagnostics",
493
+ localisationFilterHint: "Filter localisation diagnostics the way the VS Code extension does.",
494
+ localisationFilterOff: "Off",
495
+ localisationFilterProblems: "Problems",
496
+ localisationFilterAll: "All",
497
+ sectionWriteAccess: "Write access",
498
+ sectionOutput: "Output",
499
+ enabled: "Enable CWTools tools",
500
+ enabledHint: "Turning this off withdraws every CWTools tool while keeping the settings below.",
501
+ serverPath: "Server path",
502
+ serverPathHint: "Path to the CWTools language server executable. When empty, the backend is discovered automatically: an installed CWTools extension or a development build. This bundle does not ship one.",
503
+ gamePath: "Game path",
504
+ gamePathHint: "Path to the Paradox game installation. When empty, the install is discovered from the local Steam libraries (registry and libraryfolders.vdf).",
505
+ rulesPath: "Rules path",
506
+ rulesPathHint: "Path to the CWTools rules directory. Empty tries the installed extension, then this workspace's rule checkout, then the server default.",
507
+ cachePath: "Cache path",
508
+ cachePathHint: "Directory for the server cache. Empty reuses the installed extension cache when present, otherwise the workspace default.",
509
+ activeManifestPath: "Active bridge manifest (optional)",
510
+ activeManifestPathHint: "Explicit bridge-manifest.json for active-first reuse. Empty auto-discovers the current workspace host.",
511
+ preferActiveBackend: "Prefer the active backend",
512
+ preferActiveBackendHint: "Reuse a healthy active host for this workspace. If none is reusable, start a standalone backend; an incompatible active host never causes a second one.",
513
+ game: "Game",
514
+ gameHint: "Paradox game identifier such as stellaris or ck3. Empty detects it from the project.",
515
+ forceStart: "Force start",
516
+ forceStartHint: "Start the language server even when the project does not look like a supported game.",
517
+ debug: "Debug logging",
518
+ debugHint: "Keep verbose server diagnostics in the log.",
519
+ startupTimeoutMs: "Startup timeout (ms)",
520
+ startupTimeoutMsHint: "How long to wait for the language server to become ready.",
521
+ requestTimeoutMs: "Request timeout (ms)",
522
+ requestTimeoutMsHint: "How long one tool request may wait for the server.",
523
+ idleShutdownMs: "Idle shutdown (ms)",
524
+ idleShutdownMsHint: "How long an unused project runtime is kept before it stops.",
525
+ maxWorkspaceRuntimes: "Runtime limit",
526
+ maxWorkspaceRuntimesHint: "How many project runtimes may live at once, from 1 to 8.",
527
+ maxResultChars: "Result preview limit",
528
+ maxResultCharsHint: "Characters of each tool result shown to the model; stored values stay complete, from 1000 to 200000.",
529
+ writeLocalisation: "Allow write_localisation",
530
+ writeLocalisationHint: "When off, localisation writes are refused.",
531
+ writePolicyNote: "This page never grants a write on its own: every write still passes the DSH tool policy of the active session.",
532
+ groupProject: "Project queries",
533
+ groupLocalisation: "Localisation",
534
+ groupSemantic: "Semantic queries",
535
+ groupNavigation: "Navigation",
536
+ groupDiagnostics: "Diagnostics",
537
+ groupShader: "Shader",
538
+ groupDisabledNote: "Tool choices inside a disabled group are kept.",
539
+ readAccessIntro: "A group gates its tools. A tool runs only when the group and the tool are both on.",
540
+ overridden: "Overridden",
541
+ reset: "Reset to default",
542
+ invalidNumber: "Enter a whole number in the allowed range.",
543
+ readOnly: "This deployment stores settings read-only.",
544
+ unavailable: "The CWTools plugin is not loaded, so it cannot be configured right now.",
545
+ save: "Save",
546
+ saving: "Saving…",
547
+ saveFailed: "The Host did not accept these values.",
548
+ failedTitle: "The Host kept its own values; your draft is still here.",
549
+ acceptedValue: "Host accepted",
550
+ retryHint: "Correct the draft and save again, or leave the page to discard it.",
551
+ conflictNotice: "Settings changed elsewhere while you were editing, so this save was refused.",
552
+ emptyValue: "Empty",
553
+ on: "On",
554
+ off: "Off"
555
+ };
556
+ /** Simplified Chinese copy, checked against the English keys. */
557
+ const zh = {
558
+ nav: "CWTools",
559
+ title: "CWTools",
560
+ intro: "配置 CWTools 语言服务器,以及本组合包开放哪些语义工具。本页所有控件会一起保存。",
561
+ sectionProject: "项目与游戏",
562
+ sectionBackend: "后端与运行",
563
+ tabProject: "项目",
564
+ tabBackend: "后端",
565
+ tabRead: "只读工具",
566
+ tabOutput: "写入与输出",
567
+ sectionReadAccess: "只读工具",
568
+ sectionDiagnostics: "诊断过滤",
569
+ ignoreCodes: "忽略的错误码",
570
+ ignoreCodesHint: "逗号分隔的错误码或消息片段,后端不再报告。原版错误默认已关闭。",
571
+ ignoreFiles: "忽略的文件名",
572
+ ignoreFilesHint: "逗号分隔的文件名,其诊断会被丢弃,例如 zz_legacy.txt。",
573
+ localisationFilter: "本地化诊断",
574
+ localisationFilterHint: "按与 VS Code 扩展一致的方式过滤本地化诊断。",
575
+ localisationFilterOff: "不过滤",
576
+ localisationFilterProblems: "仅问题",
577
+ localisationFilterAll: "全部",
578
+ sectionWriteAccess: "写入权限",
579
+ sectionOutput: "输出",
580
+ enabled: "启用 CWTools 工具",
581
+ enabledHint: "关闭后不再提供任何 CWTools 工具,下方的设置仍然保留。",
582
+ serverPath: "服务器路径",
583
+ serverPathHint: "CWTools 语言服务器可执行文件路径。留空时自动发现后端:已安装的 CWTools 扩展或开发构建。本组合包不自带后端。",
584
+ gamePath: "游戏路径",
585
+ gamePathHint: "Paradox 游戏安装目录。留空时自动从本机 Steam 库发现(注册表 + libraryfolders.vdf),无需手填。",
586
+ rulesPath: "规则路径",
587
+ rulesPathHint: "CWTools 规则目录。留空时依次尝试已安装扩展的规则、当前工作区的规则检出,最后用服务器默认值。",
588
+ cachePath: "缓存路径",
589
+ cachePathHint: "服务器缓存目录。留空时优先复用已安装扩展的缓存,否则用工作区默认值。",
590
+ activeManifestPath: "活跃桥接清单(可选)",
591
+ activeManifestPathHint: "指定活跃优先复用的 bridge-manifest.json。留空时自动发现当前工作区宿主。",
592
+ preferActiveBackend: "优先复用活跃后端",
593
+ preferActiveBackendHint: "复用当前工作区健康的活跃宿主,没有可复用宿主时才启动独立后端;活跃宿主不兼容时不会再启动第二个实例。",
594
+ game: "游戏",
595
+ gameHint: "Paradox 游戏标识,例如 stellaris 或 ck3。留空时从项目自动识别。",
596
+ forceStart: "强制启动",
597
+ forceStartHint: "即使项目不像受支持的游戏,也启动语言服务器。",
598
+ debug: "调试日志",
599
+ debugHint: "在日志中保留详细的服务端诊断。",
600
+ startupTimeoutMs: "启动超时(毫秒)",
601
+ startupTimeoutMsHint: "等待语言服务器就绪的最长时间。",
602
+ requestTimeoutMs: "请求超时(毫秒)",
603
+ requestTimeoutMsHint: "单次工具请求等待服务器的最长时间。",
604
+ idleShutdownMs: "空闲关闭(毫秒)",
605
+ idleShutdownMsHint: "无人使用的项目运行时保留多久后停止。",
606
+ maxWorkspaceRuntimes: "运行时上限",
607
+ maxWorkspaceRuntimesHint: "同时存活的项目运行时数量,1 到 8。",
608
+ maxResultChars: "结果预览上限",
609
+ maxResultCharsHint: "展示给模型的每份工具结果字符数;存储值始终完整,1000 到 200000。",
610
+ writeLocalisation: "允许 write_localisation",
611
+ writeLocalisationHint: "关闭时拒绝本地化写入。",
612
+ writePolicyNote: "本页不会单方面授予写入:每次写入仍要通过当前会话的 DSH 工具策略。",
613
+ groupProject: "项目查询",
614
+ groupLocalisation: "本地化",
615
+ groupSemantic: "语义查询",
616
+ groupNavigation: "导航",
617
+ groupDiagnostics: "诊断",
618
+ groupShader: "着色器",
619
+ groupDisabledNote: "组关闭时,组内工具的选择仍然保留。",
620
+ readAccessIntro: "组是其工具的开关。只有组和工具同时开启,工具才会运行。",
621
+ overridden: "已覆盖",
622
+ reset: "恢复默认",
623
+ invalidNumber: "请输入允许范围内的整数。",
624
+ readOnly: "本部署的设置为只读。",
625
+ unavailable: "CWTools 插件当前未加载,暂时无法配置。",
626
+ save: "保存",
627
+ saving: "保存中…",
628
+ saveFailed: "本部署没有接受这些值。",
629
+ failedTitle: "本部署保留了它自己的值,你的草稿仍在。",
630
+ acceptedValue: "本部署已接受",
631
+ retryHint: "修改草稿后再次保存,或离开本页放弃草稿。",
632
+ conflictNotice: "编辑期间设置已在别处更新,因此本次保存被拒绝。",
633
+ emptyValue: "空",
634
+ on: "开启",
635
+ off: "关闭"
636
+ };
637
+ /**
638
+ * The shared settings frame's copy, read from this section's dictionary.
639
+ * @param t - the section's locale reader.
640
+ * @returns the labels the shared form frame renders.
641
+ */
642
+ function formLabels(t) {
643
+ return {
644
+ unavailable: t("unavailable"),
645
+ readOnly: t("readOnly"),
646
+ saveFailed: t("saveFailed"),
647
+ save: t("save"),
648
+ saving: t("saving")
649
+ };
650
+ }
651
+ // \0dsh-cwtools-css:C:\Users\A\Documents\cwtools-vscode\submodules\dsh-cwtool\src\client\CwtoolsSection.module.css.mjs
652
+ const css = ".cwtools-PxssPq_section{max-width:720px;color:var(--dsw-alias-label-primary);flex-direction:column;gap:16px;display:flex}.cwtools-PxssPq_header{flex-direction:column;gap:6px;display:flex}.cwtools-PxssPq_title{margin:0;font-size:16px;font-weight:500;line-height:24px}.cwtools-PxssPq_intro{color:var(--dsw-alias-label-tertiary);margin:0;font-size:13px;line-height:20px}.cwtools-PxssPq_stack{flex-direction:column;gap:14px;display:flex}.cwtools-PxssPq_master{flex-direction:column;display:flex}.cwtools-PxssPq_tabs{align-self:stretch}.cwtools-PxssPq_panel{flex-direction:column;gap:12px;display:flex}.cwtools-PxssPq_blockHead{color:var(--dsw-alias-label-primary);margin:0;font-size:13px;font-weight:600;line-height:20px}.cwtools-PxssPq_rows{flex-direction:column;gap:10px;display:flex}.cwtools-PxssPq_row{border:.5px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-settings-card-fill);align-items:flex-start;gap:12px;padding:10px 12px;display:flex}.cwtools-PxssPq_rowText{flex-direction:column;flex:1;gap:1px;min-width:0;display:flex}.cwtools-PxssPq_rowLabel{overflow-wrap:anywhere;font-size:13px;line-height:20px}.cwtools-PxssPq_rowHint{color:var(--dsw-alias-label-tertiary);overflow-wrap:anywhere;font-size:12px;line-height:18px}.cwtools-PxssPq_rowMark{flex-shrink:0;align-items:center;gap:6px;display:flex}.cwtools-PxssPq_rowState{color:var(--dsw-alias-label-tertiary);min-width:24px;font-size:12px;line-height:18px}.cwtools-PxssPq_reset{appearance:none;font:inherit;border-radius:var(--dsw-radius-sm);color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:0;padding:2px 4px;font-size:12px}@media (hover:hover){.cwtools-PxssPq_reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}}.cwtools-PxssPq_reset:disabled{opacity:.5;cursor:default}.cwtools-PxssPq_reset:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}.cwtools-PxssPq_cards{flex-direction:column;gap:10px;display:flex}.cwtools-PxssPq_card{border:.5px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-settings-card-fill);padding:10px 12px}.cwtools-PxssPq_card>*{border-top:0;padding:0}.cwtools-PxssPq_groups{flex-direction:column;gap:10px;display:flex}.cwtools-PxssPq_group{border:.5px solid var(--dsw-alias-settings-card-stroke);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-settings-card-fill);flex-direction:column;gap:8px;padding:10px 12px 12px;display:flex}.cwtools-PxssPq_groupHead{align-items:center;gap:8px;min-height:24px;display:flex}.cwtools-PxssPq_groupTitle{flex:1;margin:0;font-size:13px;font-weight:600;line-height:20px}.cwtools-PxssPq_groupCount{font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);border:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);border-radius:999px;padding:0 6px;font-size:11px;line-height:16px}.cwtools-PxssPq_tools{grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:6px 14px;margin:0;padding:0;list-style:none;display:grid}.cwtools-PxssPq_tool{align-items:center;gap:8px;min-width:0;display:flex}.cwtools-PxssPq_toolName{font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;font-size:12px;line-height:18px}.cwtools-PxssPq_groupOff .cwtools-PxssPq_toolName{color:var(--dsw-alias-label-tertiary)}.cwtools-PxssPq_note{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:18px}.cwtools-PxssPq_failure{border:.5px solid var(--dsw-alias-state-error-primary);border-radius:var(--dsw-radius-lg);flex-direction:column;gap:8px;padding:10px 12px;display:flex}.cwtools-PxssPq_failureTitle{color:var(--dsw-alias-state-error-primary);margin:0;font-size:13px;font-weight:600;line-height:20px}.cwtools-PxssPq_accepted{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:4px 16px;margin:0;font-size:12px;line-height:18px;display:flex}.cwtools-PxssPq_accepted dt{font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);color:var(--dsw-alias-label-tertiary)}.cwtools-PxssPq_accepted dd{overflow-wrap:anywhere;margin:0}@media (width<=560px){.cwtools-PxssPq_tools{grid-template-columns:minmax(0,1fr)}}";
653
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify("dsh-cwtools/CwtoolsSection.module.css") + "]") === null) {
654
+ const tag = document.createElement("style");
655
+ tag.dataset.plugin = "dsh-cwtools";
656
+ tag.dataset.pluginCss = "dsh-cwtools/CwtoolsSection.module.css";
657
+ tag.textContent = css;
658
+ document.head.appendChild(tag);
659
+ }
660
+ var CwtoolsSection_module_css_default = {
661
+ "toolName": "cwtools-PxssPq_toolName",
662
+ "rows": "cwtools-PxssPq_rows",
663
+ "rowHint": "cwtools-PxssPq_rowHint",
664
+ "note": "cwtools-PxssPq_note",
665
+ "panel": "cwtools-PxssPq_panel",
666
+ "failureTitle": "cwtools-PxssPq_failureTitle",
667
+ "section": "cwtools-PxssPq_section",
668
+ "title": "cwtools-PxssPq_title",
669
+ "rowMark": "cwtools-PxssPq_rowMark",
670
+ "groupHead": "cwtools-PxssPq_groupHead",
671
+ "groups": "cwtools-PxssPq_groups",
672
+ "groupTitle": "cwtools-PxssPq_groupTitle",
673
+ "tools": "cwtools-PxssPq_tools",
674
+ "failure": "cwtools-PxssPq_failure",
675
+ "groupOff": "cwtools-PxssPq_groupOff",
676
+ "groupCount": "cwtools-PxssPq_groupCount",
677
+ "rowText": "cwtools-PxssPq_rowText",
678
+ "accepted": "cwtools-PxssPq_accepted",
679
+ "tool": "cwtools-PxssPq_tool",
680
+ "row": "cwtools-PxssPq_row",
681
+ "tabs": "cwtools-PxssPq_tabs",
682
+ "rowLabel": "cwtools-PxssPq_rowLabel",
683
+ "blockHead": "cwtools-PxssPq_blockHead",
684
+ "master": "cwtools-PxssPq_master",
685
+ "stack": "cwtools-PxssPq_stack",
686
+ "card": "cwtools-PxssPq_card",
687
+ "group": "cwtools-PxssPq_group",
688
+ "rowState": "cwtools-PxssPq_rowState",
689
+ "intro": "cwtools-PxssPq_intro",
690
+ "reset": "cwtools-PxssPq_reset",
691
+ "cards": "cwtools-PxssPq_cards",
692
+ "header": "cwtools-PxssPq_header"
693
+ };
694
+ // src/client/CwtoolsSection.tsx
695
+ /**
696
+ * The CWTools settings section.
697
+ *
698
+ * One page over the `cwtools` Host entry, split into four tabs: the project
699
+ * and its game, the backend and its runtime bounds, the six read groups with
700
+ * their 37 tools, and the write allowlist with the result preview bound. The
701
+ * master switch stays above the tabs because it gates every other control.
702
+ *
703
+ * The page stages nothing itself: every control reports what the user typed to
704
+ * the controller, and the shared `SettingsForm` frame is the single place a
705
+ * draft becomes a document mutation. Leaving the page drops the drafts.
706
+ */
707
+ /** Tab order and the locale key naming each one. */
708
+ const TABS = [
709
+ {
710
+ value: "project",
711
+ label: "tabProject"
712
+ },
713
+ {
714
+ value: "backend",
715
+ label: "tabBackend"
716
+ },
717
+ {
718
+ value: "read",
719
+ label: "tabRead"
720
+ },
721
+ {
722
+ value: "output",
723
+ label: "tabOutput"
724
+ }
725
+ ];
726
+ /** Locale keys of every group heading. */
727
+ const GROUP_LABEL = {
728
+ project: "groupProject",
729
+ localisation: "groupLocalisation",
730
+ semantic: "groupSemantic",
731
+ navigation: "groupNavigation",
732
+ diagnostics: "groupDiagnostics",
733
+ shader: "groupShader"
734
+ };
735
+ /** Label and hint of every named field, keyed by dotted path. */
736
+ const FIELD_COPY = {
737
+ "enabled": {
738
+ label: "enabled",
739
+ hint: "enabledHint"
740
+ },
741
+ "backend.serverPath": {
742
+ label: "serverPath",
743
+ hint: "serverPathHint"
744
+ },
745
+ "backend.gamePath": {
746
+ label: "gamePath",
747
+ hint: "gamePathHint"
748
+ },
749
+ "backend.rulesPath": {
750
+ label: "rulesPath",
751
+ hint: "rulesPathHint"
752
+ },
753
+ "backend.cachePath": {
754
+ label: "cachePath",
755
+ hint: "cachePathHint"
756
+ },
757
+ "backend.activeManifestPath": {
758
+ label: "activeManifestPath",
759
+ hint: "activeManifestPathHint"
760
+ },
761
+ "backend.game": {
762
+ label: "game",
763
+ hint: "gameHint"
764
+ },
765
+ "backend.preferActiveBackend": {
766
+ label: "preferActiveBackend",
767
+ hint: "preferActiveBackendHint"
768
+ },
769
+ "backend.forceStart": {
770
+ label: "forceStart",
771
+ hint: "forceStartHint"
772
+ },
773
+ "backend.debug": {
774
+ label: "debug",
775
+ hint: "debugHint"
776
+ },
777
+ "backend.startupTimeoutMs": {
778
+ label: "startupTimeoutMs",
779
+ hint: "startupTimeoutMsHint"
780
+ },
781
+ "backend.requestTimeoutMs": {
782
+ label: "requestTimeoutMs",
783
+ hint: "requestTimeoutMsHint"
784
+ },
785
+ "backend.idleShutdownMs": {
786
+ label: "idleShutdownMs",
787
+ hint: "idleShutdownMsHint"
788
+ },
789
+ "backend.maxWorkspaceRuntimes": {
790
+ label: "maxWorkspaceRuntimes",
791
+ hint: "maxWorkspaceRuntimesHint"
792
+ },
793
+ "diagnostics.ignoreCodes": {
794
+ label: "ignoreCodes",
795
+ hint: "ignoreCodesHint"
796
+ },
797
+ "diagnostics.ignoreFiles": {
798
+ label: "ignoreFiles",
799
+ hint: "ignoreFilesHint"
800
+ },
801
+ "writeTools.write_localisation": {
802
+ label: "writeLocalisation",
803
+ hint: "writeLocalisationHint"
804
+ },
805
+ "output.maxResultChars": {
806
+ label: "maxResultChars",
807
+ hint: "maxResultCharsHint"
808
+ }
809
+ };
810
+ /** Project tab: where the game and its rules live. */
811
+ const PROJECT_FIELDS = [
812
+ "backend.gamePath",
813
+ "backend.rulesPath",
814
+ "backend.cachePath",
815
+ "backend.game"
816
+ ];
817
+ /** Backend tab: how the language server is found. */
818
+ const BACKEND_PATH_FIELDS = ["backend.serverPath", "backend.activeManifestPath"];
819
+ /** Backend tab: the bounds the runtime honours. */
820
+ const BACKEND_NUMBER_FIELDS = [
821
+ "backend.startupTimeoutMs",
822
+ "backend.requestTimeoutMs",
823
+ "backend.idleShutdownMs",
824
+ "backend.maxWorkspaceRuntimes"
825
+ ];
826
+ /** Backend tab: switches that change how the backend is chosen. */
827
+ const BACKEND_SWITCH_FIELDS = [
828
+ "backend.preferActiveBackend",
829
+ "backend.forceStart",
830
+ "backend.debug"
831
+ ];
832
+ /** One switch row: its copy, the reset a stored override offers, and the control. */
833
+ function SwitchRow({ id, checked, overridden, disabled, copy, t, onToggle, onReset }) {
834
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
835
+ className: CwtoolsSection_module_css_default.row,
836
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
837
+ className: CwtoolsSection_module_css_default.rowText,
838
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
839
+ className: CwtoolsSection_module_css_default.rowLabel,
840
+ id: id + "-label",
841
+ children: t(copy.label)
842
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
843
+ className: CwtoolsSection_module_css_default.rowHint,
844
+ children: t(copy.hint)
845
+ })]
846
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
847
+ className: CwtoolsSection_module_css_default.rowMark,
848
+ children: [
849
+ overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
850
+ tone: "neutral",
851
+ children: t("overridden")
852
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
853
+ type: "button",
854
+ className: CwtoolsSection_module_css_default.reset,
855
+ disabled,
856
+ onClick: onReset,
857
+ children: t("reset")
858
+ })] }) : null,
859
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
860
+ checked,
861
+ label: t(copy.label),
862
+ disabled,
863
+ onChange: (next) => {
864
+ onToggle(next);
865
+ }
866
+ }),
867
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
868
+ className: CwtoolsSection_module_css_default.rowState,
869
+ children: checked ? t("on") : t("off")
870
+ })
871
+ ]
872
+ })]
873
+ });
874
+ }
875
+ /** One read group: its switch, and every tool it owns. */
876
+ function GroupBlock({ group, state, disabled, t, onToggle, onReset }) {
877
+ const groupField = "readGroups." + group;
878
+ const active = state.groups[group];
879
+ const tools = CWTOOLS_READ_TOOL_GROUPS[group];
880
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
881
+ className: active ? CwtoolsSection_module_css_default.group : CwtoolsSection_module_css_default.group + " " + CwtoolsSection_module_css_default.groupOff,
882
+ "aria-label": t(GROUP_LABEL[group]),
883
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
884
+ className: CwtoolsSection_module_css_default.groupHead,
885
+ children: [
886
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
887
+ className: CwtoolsSection_module_css_default.groupTitle,
888
+ children: t(GROUP_LABEL[group])
889
+ }),
890
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
891
+ className: CwtoolsSection_module_css_default.groupCount,
892
+ children: tools.length
893
+ }),
894
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
895
+ className: CwtoolsSection_module_css_default.rowMark,
896
+ children: [state.fields[groupField]?.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
897
+ type: "button",
898
+ className: CwtoolsSection_module_css_default.reset,
899
+ disabled,
900
+ onClick: () => {
901
+ onReset(groupField);
902
+ },
903
+ children: t("reset")
904
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
905
+ checked: active,
906
+ label: t(GROUP_LABEL[group]),
907
+ disabled,
908
+ onChange: (next) => {
909
+ onToggle(groupField, next);
910
+ }
911
+ })]
912
+ })
913
+ ]
914
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
915
+ className: CwtoolsSection_module_css_default.tools,
916
+ children: tools.map((tool) => {
917
+ const toolField = "readTools." + tool;
918
+ const granted = state.fields[toolField]?.text === "true";
919
+ const toolDisabled = disabled || !active;
920
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
921
+ className: state.tools[tool] ? CwtoolsSection_module_css_default.tool : CwtoolsSection_module_css_default.tool + " " + CwtoolsSection_module_css_default.toolOff,
922
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
923
+ checked: granted,
924
+ label: tool,
925
+ disabled: toolDisabled,
926
+ title: toolDisabled ? t("groupDisabledNote") : tool,
927
+ onChange: (next) => {
928
+ onToggle(toolField, next);
929
+ }
930
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
931
+ className: CwtoolsSection_module_css_default.toolName,
932
+ children: tool
933
+ })]
934
+ }, tool);
935
+ })
936
+ })]
937
+ });
938
+ }
939
+ /**
940
+ * Render the CWTools settings section.
941
+ * @param props - the section snapshot, its staged actions, and localized copy.
942
+ * @returns the page inside the shared settings form frame.
943
+ */
944
+ function CwtoolsSection(props) {
945
+ const { t } = props;
946
+ const [tab, setTab] = (0, react.useState)("project");
947
+ const state = props.useCwtoolsSection((value) => value);
948
+ const id = (0, react.useId)();
949
+ const locked = !state.writable || state.saving;
950
+ const controlId = (field) => id + "-" + field.replaceAll(".", "-");
951
+ const copyOf = (field) => FIELD_COPY[field];
952
+ const fieldOf = (path) => state.fields[path] ?? {
953
+ text: "",
954
+ overridden: false,
955
+ invalid: false
956
+ };
957
+ const switchRow = (path, disabled) => {
958
+ const copy = copyOf(path);
959
+ /* v8 ignore next 2 -- every rendered switch is declared in FIELD_COPY. */
960
+ if (copy === void 0) return null;
961
+ const current = fieldOf(path);
962
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
963
+ id: controlId(path),
964
+ checked: current.text === "true",
965
+ overridden: current.overridden,
966
+ disabled,
967
+ copy,
968
+ t,
969
+ onToggle: (next) => {
970
+ props.toggle(path, next);
971
+ },
972
+ onReset: () => {
973
+ props.resetField(path);
974
+ }
975
+ }, path);
976
+ };
977
+ const valueRow = (path, numeric) => {
978
+ const copy = copyOf(path);
979
+ /* v8 ignore next 2 -- every rendered value field is declared in FIELD_COPY. */
980
+ if (copy === void 0) return null;
981
+ const current = fieldOf(path);
982
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsValueField, {
983
+ id: controlId(path),
984
+ label: t(copy.label),
985
+ hint: t(copy.hint),
986
+ numeric,
987
+ disabled: locked,
988
+ ...current,
989
+ overriddenLabel: t("overridden"),
990
+ resetLabel: t("reset"),
991
+ invalidLabel: t("invalidNumber"),
992
+ onEdit: (text) => {
993
+ props.edit(path, text);
994
+ },
995
+ onReset: () => {
996
+ props.resetField(path);
997
+ }
998
+ }, path);
999
+ };
1000
+ const cardOf = (path, numeric) => {
1001
+ const field = valueRow(path, numeric);
1002
+ /* v8 ignore next -- an undeclared path yields no field and therefore no card. */
1003
+ return field === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1004
+ className: CwtoolsSection_module_css_default.card,
1005
+ children: field
1006
+ }, path);
1007
+ };
1008
+ const localisationFilter = fieldOf("diagnostics.localisationFilter").text || "off";
1009
+ const tabOf = (entry) => ({
1010
+ value: entry.value,
1011
+ label: t(entry.label),
1012
+ id: id + "-tab-" + entry.value,
1013
+ panelId: id + "-panel-" + entry.value
1014
+ });
1015
+ const tabItems = [
1016
+ tabOf(TABS[0]),
1017
+ tabOf(TABS[1]),
1018
+ tabOf(TABS[2]),
1019
+ tabOf(TABS[3])
1020
+ ];
1021
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
1022
+ className: CwtoolsSection_module_css_default.section,
1023
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
1024
+ className: CwtoolsSection_module_css_default.header,
1025
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1026
+ className: CwtoolsSection_module_css_default.title,
1027
+ children: t("title")
1028
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1029
+ className: CwtoolsSection_module_css_default.intro,
1030
+ children: t("intro")
1031
+ })]
1032
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsForm, {
1033
+ labels: formLabels(t),
1034
+ state,
1035
+ onSave: props.save,
1036
+ onDiscard: props.discard,
1037
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1038
+ className: CwtoolsSection_module_css_default.stack,
1039
+ children: [
1040
+ state.failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1041
+ className: CwtoolsSection_module_css_default.failure,
1042
+ role: "alert",
1043
+ children: [
1044
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1045
+ className: CwtoolsSection_module_css_default.failureTitle,
1046
+ children: t("failedTitle")
1047
+ }),
1048
+ state.conflict ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1049
+ className: CwtoolsSection_module_css_default.note,
1050
+ children: t("conflictNotice")
1051
+ }) : null,
1052
+ state.accepted.length === 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dl", {
1053
+ className: CwtoolsSection_module_css_default.accepted,
1054
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("acceptedValue") }), state.accepted.map((entry) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dd", { children: [
1055
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: entry.field }),
1056
+ " ",
1057
+ entry.text === "" ? t("emptyValue") : entry.text
1058
+ ] }, entry.field))]
1059
+ }),
1060
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1061
+ className: CwtoolsSection_module_css_default.note,
1062
+ children: t("retryHint")
1063
+ })
1064
+ ]
1065
+ }) : null,
1066
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1067
+ className: CwtoolsSection_module_css_default.master,
1068
+ children: switchRow("enabled", locked)
1069
+ }),
1070
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SegmentedTabs, {
1071
+ items: tabItems,
1072
+ value: tab,
1073
+ onChange: setTab,
1074
+ label: t("title"),
1075
+ size: "sm",
1076
+ className: CwtoolsSection_module_css_default.tabs
1077
+ }),
1078
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1079
+ className: CwtoolsSection_module_css_default.panel,
1080
+ role: "tabpanel",
1081
+ id: id + "-panel-" + tab,
1082
+ "aria-labelledby": id + "-tab-" + tab,
1083
+ children: [
1084
+ tab === "project" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1085
+ className: CwtoolsSection_module_css_default.blockHead,
1086
+ children: t("sectionProject")
1087
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1088
+ className: CwtoolsSection_module_css_default.cards,
1089
+ children: PROJECT_FIELDS.map((path) => cardOf(path, false))
1090
+ })] }) : null,
1091
+ tab === "backend" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1092
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1093
+ className: CwtoolsSection_module_css_default.blockHead,
1094
+ children: t("sectionBackend")
1095
+ }),
1096
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1097
+ className: CwtoolsSection_module_css_default.cards,
1098
+ children: BACKEND_PATH_FIELDS.map((path) => cardOf(path, false))
1099
+ }),
1100
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1101
+ className: CwtoolsSection_module_css_default.cards,
1102
+ children: BACKEND_NUMBER_FIELDS.map((path) => cardOf(path, true))
1103
+ }),
1104
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1105
+ className: CwtoolsSection_module_css_default.rows,
1106
+ children: BACKEND_SWITCH_FIELDS.map((path) => switchRow(path, locked))
1107
+ })
1108
+ ] }) : null,
1109
+ tab === "read" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1110
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1111
+ className: CwtoolsSection_module_css_default.blockHead,
1112
+ children: t("sectionReadAccess")
1113
+ }),
1114
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1115
+ className: CwtoolsSection_module_css_default.note,
1116
+ children: t("readAccessIntro")
1117
+ }),
1118
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1119
+ className: CwtoolsSection_module_css_default.blockHead,
1120
+ children: t("sectionDiagnostics")
1121
+ }),
1122
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1123
+ className: CwtoolsSection_module_css_default.cards,
1124
+ children: [
1125
+ cardOf("diagnostics.ignoreCodes", false),
1126
+ cardOf("diagnostics.ignoreFiles", false),
1127
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1128
+ className: CwtoolsSection_module_css_default.card,
1129
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1130
+ className: CwtoolsSection_module_css_default.row,
1131
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1132
+ className: CwtoolsSection_module_css_default.rowText,
1133
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1134
+ className: CwtoolsSection_module_css_default.rowLabel,
1135
+ children: t("localisationFilter")
1136
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1137
+ className: CwtoolsSection_module_css_default.rowHint,
1138
+ children: t("localisationFilterHint")
1139
+ })]
1140
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1141
+ className: CwtoolsSection_module_css_default.rowMark,
1142
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SegmentedControl, {
1143
+ id: id + "-localisation-filter",
1144
+ value: localisationFilter,
1145
+ label: t("localisationFilter"),
1146
+ disabled: locked,
1147
+ options: [
1148
+ {
1149
+ value: "off",
1150
+ label: t("localisationFilterOff")
1151
+ },
1152
+ {
1153
+ value: "problems",
1154
+ label: t("localisationFilterProblems")
1155
+ },
1156
+ {
1157
+ value: "all",
1158
+ label: t("localisationFilterAll")
1159
+ }
1160
+ ],
1161
+ onChange: (next) => {
1162
+ props.edit("diagnostics.localisationFilter", next);
1163
+ }
1164
+ })
1165
+ })]
1166
+ })
1167
+ })
1168
+ ]
1169
+ }),
1170
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1171
+ className: CwtoolsSection_module_css_default.groups,
1172
+ children: CWTOOLS_READ_GROUP_ORDER.map((group) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GroupBlock, {
1173
+ group,
1174
+ state,
1175
+ disabled: locked,
1176
+ t,
1177
+ onToggle: props.toggle,
1178
+ onReset: props.resetField
1179
+ }, group))
1180
+ }),
1181
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1182
+ className: CwtoolsSection_module_css_default.note,
1183
+ children: t("groupDisabledNote")
1184
+ })
1185
+ ] }) : null,
1186
+ tab === "output" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1187
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1188
+ className: CwtoolsSection_module_css_default.blockHead,
1189
+ children: t("sectionWriteAccess")
1190
+ }),
1191
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1192
+ className: CwtoolsSection_module_css_default.rows,
1193
+ children: switchRow("writeTools.write_localisation", locked)
1194
+ }),
1195
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1196
+ className: CwtoolsSection_module_css_default.note,
1197
+ children: t("writePolicyNote")
1198
+ }),
1199
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1200
+ className: CwtoolsSection_module_css_default.blockHead,
1201
+ children: t("sectionOutput")
1202
+ }),
1203
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1204
+ className: CwtoolsSection_module_css_default.cards,
1205
+ children: cardOf("output.maxResultChars", true)
1206
+ })
1207
+ ] }) : null
1208
+ ]
1209
+ })
1210
+ ]
1211
+ })
1212
+ })]
1213
+ });
1214
+ }
1215
+ // src/client/CwtoolsSectionIcon.tsx
1216
+ /**
1217
+ * Render the CWTools navigation icon.
1218
+ * @param props - requested edge in pixels and whether this section is selected.
1219
+ * @returns a decorative SVG in the current text color.
1220
+ */
1221
+ function CwtoolsSectionIcon({ size, active }) {
1222
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1223
+ width: size,
1224
+ height: size,
1225
+ viewBox: "0 0 16 16",
1226
+ fill: "none",
1227
+ "aria-hidden": "true",
1228
+ "data-cwtools-icon": active ? "active" : "idle",
1229
+ children: [
1230
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
1231
+ d: "M11.6 4.2A5.4 5.4 0 1 0 11.6 11.8",
1232
+ stroke: "currentColor",
1233
+ strokeWidth: "1.6",
1234
+ strokeLinecap: "round"
1235
+ }),
1236
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
1237
+ d: "M6.1 6.6 4.7 8l1.4 1.4M9.9 6.6 11.3 8l-1.4 1.4",
1238
+ stroke: "currentColor",
1239
+ strokeWidth: "1.2",
1240
+ strokeLinecap: "round",
1241
+ strokeLinejoin: "round",
1242
+ opacity: "0.75"
1243
+ }),
1244
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
1245
+ cx: "8",
1246
+ cy: "8",
1247
+ r: "0.95",
1248
+ fill: "currentColor"
1249
+ })
1250
+ ]
1251
+ });
1252
+ }
1253
+ // src/client/index.ts
1254
+ /** Dictionary namespace owned by this plugin. */
1255
+ const NS = "settings.cwtools";
1256
+ /** Slot id shared by the section and its navigation icon. */
1257
+ const SECTION_ID = "cwtools";
1258
+ /** Required services (cordis fiber inject). */
1259
+ const inject = [
1260
+ "slots",
1261
+ "locale",
1262
+ "configForms"
1263
+ ];
1264
+ /**
1265
+ * Mount the settings section while the Host serves the `cwtools` entry.
1266
+ * @param ctx - the browser plugin context.
1267
+ */
1268
+ function apply(ctx) {
1269
+ const t = ctx.locale.bind(NS);
1270
+ ctx.effect(() => ctx.locale.register(NS, {
1271
+ en,
1272
+ zh
1273
+ }), "dsh-cwtools: settings dictionaries");
1274
+ const controller = new CwtoolsSettingsController(ctx.configForms.get(CWTOOLS_SETTINGS_NAMESPACE));
1275
+ ctx.effect(() => () => {
1276
+ controller.dispose();
1277
+ }, "dsh-cwtools: settings form subscription");
1278
+ const face = () => controller.inject();
1279
+ ctx.effect(() => ctx.configForms.whileServed([CWTOOLS_SETTINGS_NAMESPACE], () => {
1280
+ const section = ctx.slots.inject("settings.section", () => ctx.slots.register({
1281
+ name: "settings.section",
1282
+ id: SECTION_ID,
1283
+ order: 40,
1284
+ label: () => t("nav"),
1285
+ locale: NS,
1286
+ inject: face
1287
+ }, CwtoolsSection));
1288
+ const icon = ctx.slots.inject("settings.section.icon", () => ctx.slots.register({
1289
+ name: "settings.section.icon",
1290
+ id: SECTION_ID,
1291
+ locale: NS
1292
+ }, CwtoolsSectionIcon));
1293
+ return () => {
1294
+ section();
1295
+ icon();
1296
+ };
1297
+ }), "dsh-cwtools: settings section");
1298
+ }
1299
+ exports.apply = apply;
1300
+ exports.inject = inject;
1301
+ return module.exports;
1302
+ }
1303
+ });
1304
+
1305
+ //# sourceMappingURL=client.js.map