dsh-cwtools 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.
package/lib/index.js CHANGED
@@ -1,81 +1,124 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
- import { createToolCallHandler, getMcpToolRegistryMetadata, isMcpToolAvailable, listMcpToolSchemas } from "cwtools-shared";
2
+ import { createToolCallHandler, getMcpToolRegistryMetadata, isMcpToolAvailable, isMcpWriteToolName, listMcpToolSchemas } from "cwtools-shared";
3
3
  import path from "node:path";
4
- import { createNativeBridgeLspHost, createNodeHostServices, detectProjectSupport, discoverNativeBridge } from "cwtools-node";
4
+ import { createNativeBridgeIdeHost, createNativeBridgeLspHost, createNodeHostServices, detectProjectSupport, discoverNativeBridge } from "cwtools-node";
5
5
  // src/contract/toolCatalog.ts
6
- const CWTOOLS_READ_TOOL_GROUPS = {
7
- project: [
8
- "query_project_profile",
9
- "query_project_knowledge",
10
- "query_workspace_index",
11
- "explore_pdx_project",
12
- "analyze_pdx_flow",
13
- "query_inline_instantiation",
14
- "compare_definition_with_vanilla"
15
- ],
16
- localisation: ["query_localisation_index"],
17
- semantic: [
18
- "query_types",
19
- "query_rules",
20
- "query_cwt_schema",
21
- "search_rule_capabilities",
22
- "explain_scope",
23
- "parse_pdx_fragment",
24
- "query_scope",
25
- "query_scripted_effects",
26
- "query_scripted_triggers",
27
- "query_enums",
28
- "query_static_modifiers",
29
- "query_variables",
30
- "get_entity_info",
31
- "get_pdx_block",
32
- "query_targeting_weight"
33
- ],
34
- navigation: [
35
- "get_completion_at",
36
- "document_symbols",
37
- "workspace_symbols",
38
- "go_to_definition",
39
- "find_references"
40
- ],
41
- diagnostics: ["get_diagnostics", "analyze_diagnostic_error"],
42
- shader: [
43
- "query_shader_symbol",
44
- "query_shader_compile_unit",
45
- "query_shader_platform_variants",
46
- "query_shader_callers",
47
- "explain_shader_reachability",
48
- "validate_shader",
49
- "compare_shader_with_vanilla"
50
- ]
51
- };
52
- const CWTOOLS_READ_GROUP_ORDER = [
6
+ /**
7
+ * How the settings page groups the shared tool catalog.
8
+ *
9
+ * The catalog itself is owned by `cwtools-shared`: this module never keeps a
10
+ * copy of tool names. It only records which group a shared tool is presented
11
+ * under, so a tool added upstream appears in the page — and in the Host — on its
12
+ * own, with no edit here.
13
+ */
14
+ const CWTOOLS_READ_GROUPS = [
53
15
  "project",
54
16
  "localisation",
55
17
  "semantic",
56
18
  "navigation",
57
19
  "diagnostics",
58
- "shader"
20
+ "shader",
21
+ "ide"
59
22
  ];
60
- const CWTOOLS_READ_TOOL_NAMES = Object.freeze(CWTOOLS_READ_GROUP_ORDER.flatMap((group) => [...CWTOOLS_READ_TOOL_GROUPS[group]]));
61
- const CWTOOLS_WRITE_TOOL_NAMES = ["write_localisation"];
62
- const CWTOOLS_FIRST_RELEASE_TOOL_NAMES = [...CWTOOLS_READ_TOOL_NAMES, ...CWTOOLS_WRITE_TOOL_NAMES];
63
- const CWTOOLS_STELLARIS_ONLY_TOOLS = /* @__PURE__ */ new Set(["query_targeting_weight"]);
64
- const groupByTool = /* @__PURE__ */ new Map();
65
- for (const group of CWTOOLS_READ_GROUP_ORDER) for (const name of CWTOOLS_READ_TOOL_GROUPS[group]) groupByTool.set(name, group);
23
+ /** Groups in the order the settings page renders them. */
24
+ const CWTOOLS_READ_GROUP_ORDER = CWTOOLS_READ_GROUPS;
25
+ /**
26
+ * Tools that belong to a specific group rather than the group their shared
27
+ * effect implies. Only tools whose purpose the effect cannot express, or whose
28
+ * group assignment is otherwise surprising, need an entry; everything else
29
+ * falls back to {@link cwtoolsReadGroupForEffect}.
30
+ */
31
+ const GROUP_OVERRIDES = {
32
+ query_localisation_index: "localisation",
33
+ get_diagnostics: "diagnostics",
34
+ analyze_diagnostic_error: "diagnostics",
35
+ get_ide_context: "ide",
36
+ open_in_visual_editor: "ide",
37
+ query_shader_symbol: "shader",
38
+ query_shader_compile_unit: "shader",
39
+ query_shader_platform_variants: "shader",
40
+ query_shader_callers: "shader",
41
+ explain_shader_reachability: "shader",
42
+ validate_shader: "shader",
43
+ compare_shader_with_vanilla: "shader"
44
+ };
45
+ /**
46
+ * Tools that only answer inside a workspace with a full game model. Everything
47
+ * else a host cannot run is filtered per call by `isMcpToolAvailable`
48
+ * (CWT-only workspaces, write policy) instead of by name.
49
+ */
50
+ const GAME_MODEL_TOOLS = { query_targeting_weight: "stellaris" };
51
+ function readGroupForEffect(name, effect) {
52
+ const override = GROUP_OVERRIDES[name];
53
+ if (override !== void 0) return override;
54
+ switch (effect) {
55
+ case "workspace_read": return "semantic";
56
+ case "memory":
57
+ case "none": return "project";
58
+ default: return "semantic";
59
+ }
60
+ }
61
+ function buildCatalog() {
62
+ return listMcpToolSchemas({ includeWrites: true }).map((schema) => {
63
+ const metadata = getMcpToolRegistryMetadata(schema.name);
64
+ const isWrite = isMcpWriteToolName(schema.name) || metadata?.isWrite === true;
65
+ return {
66
+ name: schema.name,
67
+ description: schema.description,
68
+ inputSchema: schema.inputSchema,
69
+ isWrite,
70
+ group: readGroupForEffect(schema.name, metadata?.effect)
71
+ };
72
+ });
73
+ }
74
+ /** Every tool the shared catalog publishes, read once at load. */
75
+ const CWTOOLS_CATALOG = Object.freeze(buildCatalog());
76
+ const byName = new Map(CWTOOLS_CATALOG.map((entry) => [entry.name, entry]));
77
+ Object.freeze(CWTOOLS_READ_GROUP_ORDER.flatMap((group) => CWTOOLS_CATALOG.filter((entry) => !entry.isWrite && entry.group === group).map((entry) => entry.name)));
78
+ Object.freeze(CWTOOLS_READ_GROUP_ORDER.reduce((groups, group) => {
79
+ groups[group] = CWTOOLS_CATALOG.filter((entry) => !entry.isWrite && entry.group === group).map((entry) => entry.name);
80
+ return groups;
81
+ }, {}));
82
+ Object.freeze(CWTOOLS_CATALOG.filter((entry) => entry.isWrite).map((entry) => entry.name));
83
+ /** @returns the catalog entry of one tool, or undefined when the shared catalog has no such tool. */
84
+ function cwtoolsCatalogEntry(name) {
85
+ return byName.get(name);
86
+ }
87
+ /** @returns whether the shared catalog publishes this tool as read-only. */
66
88
  function isCwtoolsReadToolName(name) {
67
- return groupByTool.has(name);
89
+ const entry = byName.get(name);
90
+ return entry !== void 0 && !entry.isWrite;
68
91
  }
92
+ /** @returns whether the shared catalog publishes this tool as a write. */
69
93
  function isCwtoolsWriteToolName(name) {
70
- return CWTOOLS_WRITE_TOOL_NAMES.includes(name);
94
+ const entry = byName.get(name);
95
+ return entry === void 0 ? isMcpWriteToolName(name) : entry.isWrite;
71
96
  }
97
+ /**
98
+ * The catalog group a read tool is presented under.
99
+ * @throws when the shared catalog has no such read tool.
100
+ */
72
101
  function cwtoolsReadGroupFor(name) {
73
- const group = groupByTool.get(name);
74
- if (group === void 0) throw new Error("Unknown CWTools read tool: " + name);
75
- return group;
102
+ const entry = byName.get(name);
103
+ if (entry === void 0 || entry.isWrite) throw new Error("Unknown CWTools read tool: " + name);
104
+ return entry.group;
105
+ }
106
+ /**
107
+ * The game model a tool needs, when it only answers against a full game workspace.
108
+ * @returns the game identifier, or undefined when the tool works anywhere.
109
+ */
110
+ function cwtoolsGameModelFor(name) {
111
+ return GAME_MODEL_TOOLS[name];
76
112
  }
77
113
  // src/config.ts
78
114
  const timer = z.number().step(1).min(1).max(2147483647);
115
+ const defaultGroups = (enabled) => Object.fromEntries(CWTOOLS_READ_GROUPS.map((group) => [group, enabled]));
116
+ /**
117
+ * The tool ledger. Keys are not enumerated: the shared catalog publishes the
118
+ * tool set, and this schema only stores the grants someone overrode. A stored
119
+ * key for a tool the catalog no longer publishes is harmless.
120
+ */
121
+ const toolLedger = z.dict(z.boolean(), z.string()).default({});
79
122
  const Config = z.object({
80
123
  enabled: z.boolean().default(true).volatile(),
81
124
  readGroups: z.object({
@@ -84,10 +127,11 @@ const Config = z.object({
84
127
  semantic: z.boolean().default(true),
85
128
  navigation: z.boolean().default(true),
86
129
  diagnostics: z.boolean().default(true),
87
- shader: z.boolean().default(true)
130
+ shader: z.boolean().default(true),
131
+ ide: z.boolean().default(true)
88
132
  }).default({}).volatile(),
89
- readTools: z.dict(z.boolean(), z.string()).default({}).volatile(),
90
- writeTools: z.object({ write_localisation: z.boolean().default(false) }).default({}).volatile(),
133
+ readTools: toolLedger.volatile(),
134
+ writeTools: toolLedger.volatile(),
91
135
  backend: z.object({
92
136
  serverPath: z.string().default(""),
93
137
  gamePath: z.string().default(""),
@@ -121,7 +165,10 @@ const Config = z.object({
121
165
  function snapshotConfig(config) {
122
166
  return {
123
167
  enabled: config.enabled.get(),
124
- readGroups: { ...config.readGroups.get() },
168
+ readGroups: {
169
+ ...defaultGroups(true),
170
+ ...config.readGroups.get()
171
+ },
125
172
  readTools: { ...config.readTools.get() },
126
173
  writeTools: { ...config.writeTools.get() },
127
174
  backend: { ...config.backend.get() },
@@ -133,11 +180,29 @@ function snapshotConfig(config) {
133
180
  output: { ...config.output.get() }
134
181
  };
135
182
  }
183
+ /**
184
+ * Whether a read tool may run. A tool unknown to this build is not granted:
185
+ * the value must come from the shared catalog so a stale name cannot open a
186
+ * gate, and a stored `false` is the only per-tool opt-out.
187
+ * @param config - the snapshot the current operation runs against.
188
+ * @param name - the tool the model called.
189
+ * @returns whether the master switch, its group, and its own entry all allow it.
190
+ */
136
191
  function isReadToolEnabled(config, name) {
137
- return config.enabled && config.readGroups[cwtoolsReadGroupFor(name)] && config.readTools[name] !== false;
192
+ return config.enabled && isCwtoolsReadToolName(name) && config.readGroups[cwtoolsReadGroupFor(name)] === true && config.readTools[name] !== false;
138
193
  }
139
- function isWriteLocalisationEnabled(config) {
140
- return config.enabled && config.writeTools.write_localisation === true;
194
+ /**
195
+ * Whether the write allowlist names this tool.
196
+ * @param config - the snapshot the current operation runs against.
197
+ * @param name - the write tool the model called.
198
+ * @returns whether the operator explicitly allowed it.
199
+ */
200
+ function isWriteToolEnabled(config, name) {
201
+ return config.enabled && config.writeTools[name] === true;
202
+ }
203
+ /** @returns the write tools this configuration allows, in catalog order. */
204
+ function allowedWriteTools(config) {
205
+ return Object.keys(config.writeTools).filter((name) => isWriteToolEnabled(config, name));
141
206
  }
142
207
  // src/host/errors.ts
143
208
  var CwtoolsToolError = class extends Error {
@@ -220,7 +285,9 @@ function normalizeSuccessfulResult(result) {
220
285
  return normalized;
221
286
  }
222
287
  function errorFromSharedResult(result) {
223
- return new CwtoolsToolError(result.error?.code ?? result.status, result.error?.message ?? "CWTools tool call failed with status " + result.status + ".", result.nextSteps ?? []);
288
+ const code = result.error?.code ?? result.status;
289
+ const message = result.error?.message ?? "CWTools tool call failed with status " + result.status + ".";
290
+ return new CwtoolsToolError(code, result.error?.code ? message + " (" + result.error.code + ")" : message, result.nextSteps ?? []);
224
291
  }
225
292
  function renderCwtoolsResult(value, maxResultChars) {
226
293
  const text = JSON.stringify(value, null, 2) ?? "null";
@@ -269,17 +336,23 @@ const SUCCESS_OUTPUT_SCHEMA = {
269
336
  ]
270
337
  };
271
338
  // src/host/nativeTools.ts
339
+ /**
340
+ * Register one native DSH tool per shared-catalog entry.
341
+ *
342
+ * Every published tool is registered; whether it is exposed to a session is
343
+ * decided at call time by `runtime.canExpose`, which applies the configuration
344
+ * gate, the project shape and the host capability check. Registration therefore
345
+ * never encodes the catalog — a tool added upstream is registered by this loop
346
+ * with no change here.
347
+ */
272
348
  function registerNativeCwtoolsTools(ctx, config, runtime) {
273
349
  const disposers = [];
274
- const schemas = listMcpToolSchemas({ includeWrites: true });
275
- for (const schema of schemas) {
276
- if (!CWTOOLS_FIRST_RELEASE_TOOL_NAMES.includes(schema.name)) continue;
277
- if (isCwtoolsReadToolName(schema.name) && !isReadToolEnabled(config, schema.name)) continue;
278
- if (schema.name === "write_localisation" && !isWriteLocalisationEnabled(config)) continue;
279
- const definition = createNativeDefinition(ctx, config, runtime, schema);
350
+ for (const entry of CWTOOLS_CATALOG) {
351
+ if (isCwtoolsWriteToolName(entry.name) ? !isWriteToolEnabled(config, entry.name) : !isReadToolEnabled(config, entry.name)) continue;
352
+ const definition = createNativeDefinition(ctx, config, runtime, entry);
280
353
  disposers.push(ctx.tools.register(definition, { when: async ({ agent, signal }) => {
281
354
  const workspaceRoot = await ctx.workingDirectory.ensure(agent, signal);
282
- return runtime.canExpose(schema.name, workspaceRoot);
355
+ return runtime.canExposeWithHost(entry.name, workspaceRoot, signal);
283
356
  } }));
284
357
  }
285
358
  return () => {
@@ -339,10 +412,16 @@ async function resolveActiveBackend(config, workspaceRoot, signal) {
339
412
  if (discovery.kind === "unavailable") return void 0;
340
413
  return {
341
414
  lspHost: createNativeBridgeLspHost(discovery.manifest, discovery.readyAtMs),
415
+ ideHost: createNativeBridgeIdeHost(discovery.manifest),
342
416
  ...discovery.readyAtMs === void 0 ? {} : { readyAtMs: discovery.readyAtMs }
343
417
  };
344
418
  }
345
419
  // src/host/runtime.ts
420
+ function isActiveBackendLost(result) {
421
+ if (result.ok !== false || result.status !== "unavailable") return false;
422
+ const code = result.error?.code;
423
+ return code === "active_unavailable" || code === "bridge_unavailable";
424
+ }
346
425
  function optional(value) {
347
426
  const trimmed = value.trim();
348
427
  return trimmed === "" ? void 0 : trimmed;
@@ -361,21 +440,48 @@ var CwtoolsRuntimePool = class {
361
440
  canExpose(name, workspaceRoot) {
362
441
  return this.exposureReason(name, workspaceRoot) === void 0;
363
442
  }
443
+ async canExposeWithHost(name, workspaceRoot, signal) {
444
+ if (!this.canExpose(name, workspaceRoot)) return false;
445
+ if (cwtoolsCatalogEntry(name)?.group !== "ide") return true;
446
+ const project = this.resolveProject(workspaceRoot);
447
+ const existing = this.entries.get(project.root);
448
+ if (existing) return isMcpToolAvailable(name, {
449
+ includeWrites: this.config.writeTools[name] === true,
450
+ cwtOnly: project.kind === "cwt-only",
451
+ capabilities: existing.host.capabilities
452
+ });
453
+ if (!this.config.backend.preferActiveBackend) return false;
454
+ try {
455
+ return await resolveActiveBackend(this.config, project.root, signal) !== void 0;
456
+ } catch {
457
+ return false;
458
+ }
459
+ }
460
+ /**
461
+ * Why a tool may not run in this workspace, or undefined when it may.
462
+ *
463
+ * The shared catalog, not this package, owns the tool set: a name the catalog
464
+ * does not publish is refused here, and a published one is filtered by its
465
+ * group grant, the write allowlist and the host capability check instead of by
466
+ * a compiled list of first-release names.
467
+ */
364
468
  exposureReason(name, workspaceRoot) {
365
469
  if (this.disposed || !this.config.enabled) return "CWTools is disabled by configuration.";
366
470
  if (isCwtoolsReadToolName(name)) {
367
471
  if (!isReadToolEnabled(this.config, name)) return "Tool " + name + " is disabled by read-group or per-tool configuration.";
368
472
  } else if (isCwtoolsWriteToolName(name)) {
369
- if (!isWriteLocalisationEnabled(this.config)) return "Tool " + name + " requires an explicit write allowlist entry.";
370
- } else return "Tool " + name + " is outside the first-release CWTools catalog.";
473
+ if (!isWriteToolEnabled(this.config, name)) return "Tool " + name + " requires an explicit write allowlist entry.";
474
+ } else return "Tool " + name + " is not published by the active cwtools-shared catalog.";
371
475
  const project = this.resolveProject(workspaceRoot);
372
476
  if (!project.supported) return project.reason;
373
477
  const cwtOnly = project.kind === "cwt-only";
478
+ const writes = this.config.writeTools[name] === true;
374
479
  if (!isMcpToolAvailable(name, {
375
- includeWrites: isWriteLocalisationEnabled(this.config),
480
+ includeWrites: writes,
376
481
  cwtOnly
377
482
  })) return cwtOnly ? "Tool " + name + " is unavailable in a CWT-only workspace." : "Tool " + name + " is unavailable under the current write policy.";
378
- if (CWTOOLS_STELLARIS_ONLY_TOOLS.has(name) && project.game !== "stellaris") return "Tool " + name + " requires a Stellaris full-mod workspace.";
483
+ const gameModel = cwtoolsGameModelFor(name);
484
+ if (gameModel !== void 0 && project.game !== gameModel) return "Tool " + name + " requires a full " + gameModel + " game workspace.";
379
485
  }
380
486
  async execute(name, args, workspaceRoot, signal) {
381
487
  throwIfAborted(signal);
@@ -383,6 +489,15 @@ var CwtoolsRuntimePool = class {
383
489
  const denied = this.exposureReason(name, workspaceRoot);
384
490
  if (denied !== void 0) throw new CwtoolsToolError("tool_not_available", denied);
385
491
  const entry = await this.entryFor(workspaceRoot, signal);
492
+ const result = await this.invoke(entry, name, args, signal);
493
+ if (this.disposed || !entry.usedActiveBackend || !isActiveBackendLost(result)) return result;
494
+ this.entries.delete(entry.root);
495
+ this.disposeEntry(entry);
496
+ const retried = await this.entryFor(workspaceRoot, signal);
497
+ if (retried === entry) return result;
498
+ return await this.invoke(retried, name, args, signal);
499
+ }
500
+ async invoke(entry, name, args, signal) {
386
501
  if (this.disposed) throw new CwtoolsToolError("runtime_disposed", "The CWTools runtime has been disposed.");
387
502
  const controller = new AbortController();
388
503
  const abort = () => {
@@ -463,7 +578,8 @@ var CwtoolsRuntimePool = class {
463
578
  if (active && "dispose" in active.lspHost && typeof active.lspHost.dispose === "function") active.lspHost.dispose();
464
579
  throw new CwtoolsToolError("runtime_disposed", "The CWTools runtime has been disposed.");
465
580
  }
466
- const writes = isWriteLocalisationEnabled(this.config);
581
+ const allowedTools = allowedWriteTools(this.config);
582
+ const writes = allowedTools.length > 0;
467
583
  const hostOptions = {
468
584
  workspaceRoot: project.root,
469
585
  game: project.game === "paradox" || project.game === "cwt" ? void 0 : project.game,
@@ -475,7 +591,7 @@ var CwtoolsRuntimePool = class {
475
591
  errorIgnoreFiles: this.config.diagnostics.ignoreFiles,
476
592
  localisationDiagnosticFilter: this.config.diagnostics.localisationFilter,
477
593
  enableWrites: writes,
478
- allowedTools: writes ? ["write_localisation"] : [],
594
+ allowedTools,
479
595
  forceStart: this.config.backend.forceStart,
480
596
  startupTimeoutMs: this.config.backend.startupTimeoutMs,
481
597
  requestTimeoutMs: this.config.backend.requestTimeoutMs,
@@ -483,6 +599,7 @@ var CwtoolsRuntimePool = class {
483
599
  honorWorkspaceIgnoreList: true,
484
600
  ...active === void 0 ? {} : {
485
601
  lspHost: active.lspHost,
602
+ ideHost: active.ideHost,
486
603
  readyAtMs: active.readyAtMs
487
604
  }
488
605
  };
@@ -495,7 +612,8 @@ var CwtoolsRuntimePool = class {
495
612
  queue: Promise.resolve(),
496
613
  active: 0,
497
614
  lastUsed: Date.now(),
498
- disposed: false
615
+ disposed: false,
616
+ usedActiveBackend: active !== void 0
499
617
  };
500
618
  this.entries.set(project.root, entry);
501
619
  this.enforceCapacity(entry);
@@ -2,7 +2,7 @@ import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
2
2
  import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
3
3
  import { type SettingsFieldState, type SettingsFormActions, type SettingsFormShell } from '@deepseek-ai/dsh-client-ui-primitives';
4
4
  import type { CwtoolsConfig } from '../contract/configTypes.ts';
5
- import { type CwtoolsReadGroup, type CwtoolsReadToolName } from '../contract/toolCatalog.ts';
5
+ import { type CwtoolsReadGroup } from '../contract/toolCatalog.ts';
6
6
  /** Settings namespace of the Host entry this section edits. */
7
7
  export declare const CWTOOLS_SETTINGS_NAMESPACE = "cwtools";
8
8
  /** Configuration block a leaf belongs to. */
@@ -27,8 +27,8 @@ export interface CwtoolsSectionState extends SettingsFormShell {
27
27
  fields: Record<string, SettingsFieldState>;
28
28
  /** Effective on-state of each read group. */
29
29
  groups: Record<CwtoolsReadGroup, boolean>;
30
- /** Effective on-state of each tool: its own grant AND its group's. */
31
- tools: Record<CwtoolsReadToolName, boolean>;
30
+ /** Effective on-state of each read tool: its own grant AND its group's. */
31
+ tools: Record<string, boolean>;
32
32
  /** Whether the refused save lost a revision race with an edit made elsewhere. */
33
33
  conflict: boolean;
34
34
  /** Values the Host still holds after a refused save; empty otherwise. */
@@ -6,7 +6,7 @@
6
6
  * never translated.
7
7
  */
8
8
  /** Every key this section renders. */
9
- export type CwtoolsLocaleKey = 'nav' | 'title' | 'intro' | 'sectionProject' | 'sectionBackend' | 'sectionReadAccess' | 'sectionDiagnostics' | 'sectionWriteAccess' | 'sectionOutput' | 'tabProject' | 'tabBackend' | 'tabRead' | 'tabOutput' | 'enabled' | 'enabledHint' | 'serverPath' | 'serverPathHint' | 'gamePath' | 'gamePathHint' | 'rulesPath' | 'rulesPathHint' | 'cachePath' | 'cachePathHint' | 'activeManifestPath' | 'activeManifestPathHint' | 'preferActiveBackend' | 'preferActiveBackendHint' | 'game' | 'gameHint' | 'forceStart' | 'forceStartHint' | 'debug' | 'debugHint' | 'startupTimeoutMs' | 'startupTimeoutMsHint' | 'requestTimeoutMs' | 'requestTimeoutMsHint' | 'idleShutdownMs' | 'idleShutdownMsHint' | 'maxWorkspaceRuntimes' | 'maxWorkspaceRuntimesHint' | 'maxResultChars' | 'maxResultCharsHint' | 'writeLocalisation' | 'writeLocalisationHint' | 'writePolicyNote' | 'groupProject' | 'groupLocalisation' | 'groupSemantic' | 'groupNavigation' | 'groupDiagnostics' | 'groupShader' | 'groupDisabledNote' | 'readAccessIntro' | 'ignoreCodes' | 'ignoreCodesHint' | 'ignoreFiles' | 'ignoreFilesHint' | 'localisationFilter' | 'localisationFilterHint' | 'localisationFilterOff' | 'localisationFilterProblems' | 'localisationFilterAll' | 'overridden' | 'reset' | 'invalidNumber' | 'readOnly' | 'unavailable' | 'save' | 'saving' | 'saveFailed' | 'failedTitle' | 'acceptedValue' | 'retryHint' | 'conflictNotice' | 'emptyValue' | 'on' | 'off';
9
+ export type CwtoolsLocaleKey = 'nav' | 'title' | 'intro' | 'sectionProject' | 'sectionBackend' | 'sectionReadAccess' | 'sectionDiagnostics' | 'sectionWriteAccess' | 'sectionOutput' | 'tabProject' | 'tabBackend' | 'tabRead' | 'tabOutput' | 'enabled' | 'enabledHint' | 'serverPath' | 'serverPathHint' | 'gamePath' | 'gamePathHint' | 'rulesPath' | 'rulesPathHint' | 'cachePath' | 'cachePathHint' | 'activeManifestPath' | 'activeManifestPathHint' | 'preferActiveBackend' | 'preferActiveBackendHint' | 'game' | 'gameHint' | 'forceStart' | 'forceStartHint' | 'debug' | 'debugHint' | 'startupTimeoutMs' | 'startupTimeoutMsHint' | 'requestTimeoutMs' | 'requestTimeoutMsHint' | 'idleShutdownMs' | 'idleShutdownMsHint' | 'maxWorkspaceRuntimes' | 'maxWorkspaceRuntimesHint' | 'maxResultChars' | 'maxResultCharsHint' | 'writeLocalisation' | 'writeLocalisationHint' | 'writePolicyNote' | 'groupProject' | 'groupLocalisation' | 'groupSemantic' | 'groupNavigation' | 'groupDiagnostics' | 'groupShader' | 'groupIde' | 'groupDisabledNote' | 'readAccessIntro' | 'ignoreCodes' | 'ignoreCodesHint' | 'ignoreFiles' | 'ignoreFilesHint' | 'localisationFilter' | 'localisationFilterHint' | 'localisationFilterOff' | 'localisationFilterProblems' | 'localisationFilterAll' | 'overridden' | 'reset' | 'invalidNumber' | 'readOnly' | 'unavailable' | 'save' | 'saving' | 'saveFailed' | 'failedTitle' | 'acceptedValue' | 'retryHint' | 'conflictNotice' | 'emptyValue' | 'on' | 'off';
10
10
  /** English copy. */
11
11
  export declare const en: Record<CwtoolsLocaleKey, string>;
12
12
  /** Simplified Chinese copy, checked against the English keys. */
@@ -1,7 +1,7 @@
1
1
  import type { Volatile } from '@deepseek-ai/cordis';
2
2
  import z from '@deepseek-ai/schemastery';
3
3
  import type { CwtoolsBackendConfig, CwtoolsConfig, CwtoolsConfigInput, CwtoolsDiagnosticsConfig } from './contract/configTypes.ts';
4
- import { type CwtoolsReadGroup, type CwtoolsReadToolName, type CwtoolsWriteToolName } from './contract/toolCatalog.ts';
4
+ import { type CwtoolsReadGroup } from './contract/toolCatalog.ts';
5
5
  /** Plain, unwrapped values the runtime consumes. */
6
6
  export type Config = CwtoolsConfig;
7
7
  /**
@@ -13,8 +13,8 @@ export type Config = CwtoolsConfig;
13
13
  export interface CwtoolsLiveConfig {
14
14
  enabled: Volatile<boolean>;
15
15
  readGroups: Volatile<Record<CwtoolsReadGroup, boolean>>;
16
- readTools: Volatile<Partial<Record<CwtoolsReadToolName, boolean>>>;
17
- writeTools: Volatile<Partial<Record<CwtoolsWriteToolName, boolean>>>;
16
+ readTools: Volatile<Record<string, boolean>>;
17
+ writeTools: Volatile<Record<string, boolean>>;
18
18
  backend: Volatile<CwtoolsBackendConfig>;
19
19
  diagnostics: Volatile<CwtoolsDiagnosticsConfig>;
20
20
  output: Volatile<{
@@ -27,5 +27,23 @@ export declare const Config: z<CwtoolsConfigInput, CwtoolsLiveConfig>;
27
27
  * @returns plain values for the runtime, tools and their snapshots.
28
28
  */
29
29
  export declare function snapshotConfig(config: CwtoolsLiveConfig): Config;
30
- export declare function isReadToolEnabled(config: Config, name: CwtoolsReadToolName): boolean;
30
+ /**
31
+ * Whether a read tool may run. A tool unknown to this build is not granted:
32
+ * the value must come from the shared catalog so a stale name cannot open a
33
+ * gate, and a stored `false` is the only per-tool opt-out.
34
+ * @param config - the snapshot the current operation runs against.
35
+ * @param name - the tool the model called.
36
+ * @returns whether the master switch, its group, and its own entry all allow it.
37
+ */
38
+ export declare function isReadToolEnabled(config: Config, name: string): boolean;
39
+ /**
40
+ * Whether the write allowlist names this tool.
41
+ * @param config - the snapshot the current operation runs against.
42
+ * @param name - the write tool the model called.
43
+ * @returns whether the operator explicitly allowed it.
44
+ */
45
+ export declare function isWriteToolEnabled(config: Config, name: string): boolean;
46
+ /** @deprecated Prefer {@link isWriteToolEnabled}; kept for the localisation settings path. */
31
47
  export declare function isWriteLocalisationEnabled(config: Config): boolean;
48
+ /** @returns the write tools this configuration allows, in catalog order. */
49
+ export declare function allowedWriteTools(config: Config): string[];
@@ -1,4 +1,4 @@
1
- import type { CwtoolsReadGroup, CwtoolsReadToolName, CwtoolsWriteToolName } from './toolCatalog.ts';
1
+ import type { CwtoolsReadGroup } from './toolCatalog.ts';
2
2
  export interface CwtoolsBackendConfig {
3
3
  serverPath: string;
4
4
  gamePath: string;
@@ -25,11 +25,16 @@ export interface CwtoolsDiagnosticsConfig {
25
25
  /** Localisation diagnostic filter mode. */
26
26
  localisationFilter: CwtoolsLocalisationFilter;
27
27
  }
28
+ /**
29
+ * Read grants. Tool names are open strings: the shared catalog, not this
30
+ * package, decides which tools exist, so a tool published upstream is granted
31
+ * by its group until someone stores `readTools[name] = false`.
32
+ */
28
33
  export interface CwtoolsConfig {
29
34
  enabled: boolean;
30
35
  readGroups: Record<CwtoolsReadGroup, boolean>;
31
- readTools: Partial<Record<CwtoolsReadToolName, boolean>>;
32
- writeTools: Partial<Record<CwtoolsWriteToolName, boolean>>;
36
+ readTools: Record<string, boolean>;
37
+ writeTools: Record<string, boolean>;
33
38
  backend: CwtoolsBackendConfig;
34
39
  diagnostics: CwtoolsDiagnosticsConfig;
35
40
  output: {
@@ -40,8 +45,8 @@ export interface CwtoolsConfig {
40
45
  export interface CwtoolsConfigInput {
41
46
  enabled?: boolean;
42
47
  readGroups?: Partial<Record<CwtoolsReadGroup, boolean>>;
43
- readTools?: Partial<Record<CwtoolsReadToolName, boolean>>;
44
- writeTools?: Partial<Record<CwtoolsWriteToolName, boolean>>;
48
+ readTools?: Record<string, boolean>;
49
+ writeTools?: Record<string, boolean>;
45
50
  backend?: Partial<CwtoolsBackendConfig>;
46
51
  diagnostics?: Partial<CwtoolsDiagnosticsConfig>;
47
52
  output?: {
@@ -1,19 +1,44 @@
1
- export declare const CWTOOLS_READ_TOOL_GROUPS: {
2
- readonly project: readonly ["query_project_profile", "query_project_knowledge", "query_workspace_index", "explore_pdx_project", "analyze_pdx_flow", "query_inline_instantiation", "compare_definition_with_vanilla"];
3
- readonly localisation: readonly ["query_localisation_index"];
4
- readonly semantic: readonly ["query_types", "query_rules", "query_cwt_schema", "search_rule_capabilities", "explain_scope", "parse_pdx_fragment", "query_scope", "query_scripted_effects", "query_scripted_triggers", "query_enums", "query_static_modifiers", "query_variables", "get_entity_info", "get_pdx_block", "query_targeting_weight"];
5
- readonly navigation: readonly ["get_completion_at", "document_symbols", "workspace_symbols", "go_to_definition", "find_references"];
6
- readonly diagnostics: readonly ["get_diagnostics", "analyze_diagnostic_error"];
7
- readonly shader: readonly ["query_shader_symbol", "query_shader_compile_unit", "query_shader_platform_variants", "query_shader_callers", "explain_shader_reachability", "validate_shader", "compare_shader_with_vanilla"];
8
- };
9
- export type CwtoolsReadGroup = keyof typeof CWTOOLS_READ_TOOL_GROUPS;
10
- export type CwtoolsReadToolName = typeof CWTOOLS_READ_TOOL_GROUPS[CwtoolsReadGroup][number];
1
+ /**
2
+ * How the settings page groups the shared tool catalog.
3
+ *
4
+ * The catalog itself is owned by `cwtools-shared`: this module never keeps a
5
+ * copy of tool names. It only records which group a shared tool is presented
6
+ * under, so a tool added upstream appears in the page — and in the Host — on its
7
+ * own, with no edit here.
8
+ */
9
+ export declare const CWTOOLS_READ_GROUPS: readonly ["project", "localisation", "semantic", "navigation", "diagnostics", "shader", "ide"];
10
+ export type CwtoolsReadGroup = typeof CWTOOLS_READ_GROUPS[number];
11
+ /** Groups in the order the settings page renders them. */
11
12
  export declare const CWTOOLS_READ_GROUP_ORDER: readonly CwtoolsReadGroup[];
12
- export declare const CWTOOLS_READ_TOOL_NAMES: readonly CwtoolsReadToolName[];
13
- export declare const CWTOOLS_WRITE_TOOL_NAMES: readonly ["write_localisation"];
14
- export type CwtoolsWriteToolName = typeof CWTOOLS_WRITE_TOOL_NAMES[number];
15
- export declare const CWTOOLS_FIRST_RELEASE_TOOL_NAMES: readonly string[];
16
- export declare const CWTOOLS_STELLARIS_ONLY_TOOLS: ReadonlySet<string>;
17
- export declare function isCwtoolsReadToolName(name: string): name is CwtoolsReadToolName;
18
- export declare function isCwtoolsWriteToolName(name: string): name is CwtoolsWriteToolName;
19
- export declare function cwtoolsReadGroupFor(name: CwtoolsReadToolName): CwtoolsReadGroup;
13
+ interface CatalogEntry {
14
+ readonly name: string;
15
+ readonly description: string;
16
+ readonly inputSchema: Record<string, unknown>;
17
+ readonly isWrite: boolean;
18
+ readonly group: CwtoolsReadGroup;
19
+ }
20
+ /** Every tool the shared catalog publishes, read once at load. */
21
+ export declare const CWTOOLS_CATALOG: readonly CatalogEntry[];
22
+ /** Read-only tools in rendering order: group order, then shared catalog order. */
23
+ export declare const CWTOOLS_READ_TOOL_NAMES: readonly string[];
24
+ /** Tools per group, in rendering order. */
25
+ export declare const CWTOOLS_READ_TOOL_GROUPS: Readonly<Record<CwtoolsReadGroup, readonly string[]>>;
26
+ /** Write tools the shared catalog publishes. Every one needs an explicit grant. */
27
+ export declare const CWTOOLS_WRITE_TOOL_NAMES: readonly string[];
28
+ /** @returns the catalog entry of one tool, or undefined when the shared catalog has no such tool. */
29
+ export declare function cwtoolsCatalogEntry(name: string): CatalogEntry | undefined;
30
+ /** @returns whether the shared catalog publishes this tool as read-only. */
31
+ export declare function isCwtoolsReadToolName(name: string): boolean;
32
+ /** @returns whether the shared catalog publishes this tool as a write. */
33
+ export declare function isCwtoolsWriteToolName(name: string): boolean;
34
+ /**
35
+ * The catalog group a read tool is presented under.
36
+ * @throws when the shared catalog has no such read tool.
37
+ */
38
+ export declare function cwtoolsReadGroupFor(name: string): CwtoolsReadGroup;
39
+ /**
40
+ * The game model a tool needs, when it only answers against a full game workspace.
41
+ * @returns the game identifier, or undefined when the tool works anywhere.
42
+ */
43
+ export declare function cwtoolsGameModelFor(name: string): string | undefined;
44
+ export {};
@@ -1,7 +1,8 @@
1
- import { type LspHost } from 'cwtools-node';
1
+ import { type IdeHost, type LspHost } from 'cwtools-node';
2
2
  import type { Config } from '../config.ts';
3
3
  export interface ActiveBackend {
4
4
  lspHost: LspHost;
5
+ ideHost: IdeHost;
5
6
  readyAtMs?: number;
6
7
  }
7
8
  /** Resolve a healthy active host only for the exact current mod root. */
@@ -1,4 +1,13 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
- import type { Config } from '../config.ts';
2
+ import { type Config } from '../config.ts';
3
3
  import type { CwtoolsRuntimePool } from './runtime.ts';
4
+ /**
5
+ * Register one native DSH tool per shared-catalog entry.
6
+ *
7
+ * Every published tool is registered; whether it is exposed to a session is
8
+ * decided at call time by `runtime.canExpose`, which applies the configuration
9
+ * gate, the project shape and the host capability check. Registration therefore
10
+ * never encodes the catalog — a tool added upstream is registered by this loop
11
+ * with no change here.
12
+ */
4
13
  export declare function registerNativeCwtoolsTools(ctx: Context, config: Config, runtime: CwtoolsRuntimePool): () => void;
@@ -8,8 +8,18 @@ export declare class CwtoolsRuntimePool {
8
8
  constructor(config: Config);
9
9
  get workspaceCount(): number;
10
10
  canExpose(name: string, workspaceRoot: string): boolean;
11
+ canExposeWithHost(name: string, workspaceRoot: string, signal: AbortSignal): Promise<boolean>;
12
+ /**
13
+ * Why a tool may not run in this workspace, or undefined when it may.
14
+ *
15
+ * The shared catalog, not this package, owns the tool set: a name the catalog
16
+ * does not publish is refused here, and a published one is filtered by its
17
+ * group grant, the write allowlist and the host capability check instead of by
18
+ * a compiled list of first-release names.
19
+ */
11
20
  exposureReason(name: string, workspaceRoot: string): string | undefined;
12
21
  execute(name: string, args: Record<string, unknown>, workspaceRoot: string, signal: AbortSignal): Promise<SharedToolResult>;
22
+ private invoke;
13
23
  dispose(): void;
14
24
  private resolveProject;
15
25
  private entryFor;