cwtools-shared 0.2.8 → 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.
@@ -35,12 +35,14 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.defaultSharedToolDispatcher = void 0;
37
37
  const path = __importStar(require("path"));
38
+ const lsp_1 = require("../host/lsp");
38
39
  const diagnosticRouting_1 = require("../knowledge/diagnosticRouting");
39
40
  const rules_1 = require("../knowledge/rules");
40
41
  const profile_1 = require("../project/profile");
41
42
  const knowledge_1 = require("../project/knowledge");
42
43
  const localisation_1 = require("../safety/localisation");
43
44
  const pdxBlock_1 = require("./pdxBlock");
45
+ const targetingWeights_1 = require("./targetingWeights");
44
46
  const schema_1 = require("./schema");
45
47
  const symbols_1 = require("./symbols");
46
48
  function asRecord(value) {
@@ -48,8 +50,11 @@ function asRecord(value) {
48
50
  ? value
49
51
  : {};
50
52
  }
51
- async function executeLspTool(host, command, args, unavailableNextStep) {
52
- const result = await host.lsp.executeCommand(command, args);
53
+ async function executeLspTool(host, command, args, unavailableNextStep, signal) {
54
+ // Cancellation must not be laundered into `unavailable`: the caller asked to
55
+ // stop, so the abort error propagates untouched.
56
+ (0, lsp_1.throwIfAborted)(signal);
57
+ const result = await host.lsp.executeCommand(command, args, signal ? { signal } : undefined);
53
58
  const record = asRecord(result);
54
59
  const errorRecord = asRecord(record.error);
55
60
  const unavailable = record.status === 'unavailable' || errorRecord.code === 'lsp_unavailable';
@@ -67,8 +72,11 @@ async function executeLspTool(host, command, args, unavailableNextStep) {
67
72
  nextSteps: unavailable ? [unavailableNextStep] : undefined,
68
73
  };
69
74
  }
70
- const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
75
+ const defaultSharedToolDispatcher = async (host, name, rawArgs, context) => {
71
76
  const args = asRecord(rawArgs);
77
+ const signal = context?.signal;
78
+ const lspTool = (command, args, unavailableNextStep) => executeLspTool(host, command, args, unavailableNextStep, signal);
79
+ (0, lsp_1.throwIfAborted)(signal);
72
80
  switch (name) {
73
81
  case 'query_project_profile':
74
82
  return (0, profile_1.queryProjectProfileWithHost)(host, args);
@@ -98,7 +106,7 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
98
106
  };
99
107
  }
100
108
  case 'explore_pdx_project':
101
- return executeLspTool(host, 'cwtools.ai.exploreProject', [
109
+ return lspTool('cwtools.ai.exploreProject', [
102
110
  typeof args.query === 'string' ? args.query : '',
103
111
  typeof args.file === 'string' && args.file ? toFileUri(args.file, host.workspaceRoot) : '',
104
112
  typeof args.typeName === 'string' ? args.typeName : '',
@@ -122,7 +130,7 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
122
130
  },
123
131
  };
124
132
  }
125
- return executeLspTool(host, 'cwtools.ai.analyzePdxFlow', [{
133
+ return lspTool('cwtools.ai.analyzePdxFlow', [{
126
134
  ...(file ? { file } : {}),
127
135
  ...(definitionId ? { definitionId } : {}),
128
136
  ...(typeof args.entityType === 'string' && args.entityType.trim() ? { entityType: args.entityType.trim() } : {}),
@@ -141,7 +149,7 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
141
149
  },
142
150
  };
143
151
  }
144
- return executeLspTool(host, 'cwtools.ai.compareDefinitionWithVanilla', [args.entityType.trim(), args.symbolId.trim()], 'Start the CWTools LSP process and wait for the game model to load before comparing the definition with vanilla.');
152
+ return lspTool('cwtools.ai.compareDefinitionWithVanilla', [args.entityType.trim(), args.symbolId.trim()], 'Start the CWTools LSP process and wait for the game model to load before comparing the definition with vanilla.');
145
153
  }
146
154
  case 'query_inline_instantiation': {
147
155
  const template = typeof args.template === 'string' ? args.template.trim() : '';
@@ -157,13 +165,28 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
157
165
  },
158
166
  };
159
167
  }
160
- return executeLspTool(host, 'cwtools.ai.exploreInlineGraph', [{
168
+ return lspTool('cwtools.ai.exploreInlineGraph', [{
161
169
  ...(template ? { template } : {}),
162
170
  ...(file ? { file } : {}),
163
171
  ...(Number.isInteger(args.line) ? { line: Number(args.line) } : {}),
164
172
  limit: Math.max(1, Math.min(Number(args.limit ?? 50) || 50, 200)),
165
173
  }], 'Start the CWTools LSP process and wait for the game model to load before resolving the inline template instantiation.');
166
174
  }
175
+ case 'query_targeting_weight': {
176
+ // Pure computation: no host, no I/O, and no backend to wait for. The shared
177
+ // implementation is the single source of truth for the formula, so the MCP
178
+ // surface, the in-extension agent and the panel produce identical numbers
179
+ // for the same inputs.
180
+ const data = (0, targetingWeights_1.executeTargetingWeightQuery)(args);
181
+ const failure = typeof data.error === 'string' ? data.error : undefined;
182
+ return {
183
+ ok: failure === undefined,
184
+ status: failure === undefined ? 'ready' : 'error',
185
+ source: 'cwtools-shared',
186
+ data,
187
+ error: failure === undefined ? undefined : { code: 'invalid_arguments', message: failure },
188
+ };
189
+ }
167
190
  case 'query_localisation_index': {
168
191
  if (!host.indexing) {
169
192
  return (0, schema_1.toolUnavailable)(name, 'Localisation index is not available in this host.', [
@@ -172,7 +195,7 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
172
195
  }
173
196
  const data = await host.indexing.queryLocalisation(args);
174
197
  const semanticAudit = args.auditMode === true
175
- ? await executeLspTool(host, 'cwtools.ai.queryLocalisationAudit', [{
198
+ ? await lspTool('cwtools.ai.queryLocalisationAudit', [{
176
199
  ...(typeof args.key === 'string' ? { key: args.key } : {}),
177
200
  prefix: args.prefix === true,
178
201
  contains: args.contains === true,
@@ -189,7 +212,7 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
189
212
  }
190
213
  case 'get_diagnostics':
191
214
  {
192
- const diagnostics = await host.diagnostics.getDiagnostics(args);
215
+ const diagnostics = await host.diagnostics.getDiagnostics(args, signal ? { signal } : undefined);
193
216
  return {
194
217
  ok: diagnostics.ok,
195
218
  status: diagnostics.status === 'unavailable' ? 'unavailable' : diagnostics.status === 'stale' ? 'stale' : diagnostics.status === 'pending' ? 'loading' : 'ready',
@@ -247,9 +270,9 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
247
270
  limit: typeof args.limit === 'number' ? args.limit : undefined,
248
271
  });
249
272
  case 'query_scope':
250
- return executeLspTool(host, 'cwtools.ai.getScopeAtPosition', [toFileUri(String(args.file ?? ''), host.workspaceRoot), args.line, args.column], 'Start the CWTools LSP process or connect this host to an existing language server.');
273
+ return lspTool('cwtools.ai.getScopeAtPosition', [toFileUri(String(args.file ?? ''), host.workspaceRoot), args.line, args.column], 'Start the CWTools LSP process or connect this host to an existing language server.');
251
274
  case 'query_types':
252
- return executeLspTool(host, 'cwtools.ai.queryTypes', [args.typeName, args.filter ?? '', args.limit ?? 30, args.vanilla === true], 'Start the CWTools LSP process or connect this host to an existing language server.');
275
+ return lspTool('cwtools.ai.queryTypes', [args.typeName, args.filter ?? '', args.limit ?? 30, args.vanilla === true], 'Start the CWTools LSP process or connect this host to an existing language server.');
253
276
  case 'query_rules':
254
277
  return (0, rules_1.queryRulesWithHost)(host, {
255
278
  category: String(args.category ?? 'trigger'),
@@ -278,19 +301,19 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
278
301
  scope: String(args.scope ?? ''),
279
302
  });
280
303
  case 'parse_pdx_fragment':
281
- return executeLspTool(host, 'cwtools.ai.parseFragment', [String(args.code ?? '')], 'Start the CWTools LSP process or connect this host to an existing language server.');
304
+ return lspTool('cwtools.ai.parseFragment', [String(args.code ?? '')], 'Start the CWTools LSP process or connect this host to an existing language server.');
282
305
  case 'query_scripted_effects':
283
- return executeLspTool(host, 'cwtools.ai.queryScriptedEffects', [args.filter ?? '', args.limit ?? 50], 'Start the CWTools LSP process or connect this host to an existing language server.');
306
+ return lspTool('cwtools.ai.queryScriptedEffects', [args.filter ?? '', args.limit ?? 50], 'Start the CWTools LSP process or connect this host to an existing language server.');
284
307
  case 'query_scripted_triggers':
285
- return executeLspTool(host, 'cwtools.ai.queryScriptedTriggers', [args.filter ?? '', args.limit ?? 50], 'Start the CWTools LSP process or connect this host to an existing language server.');
308
+ return lspTool('cwtools.ai.queryScriptedTriggers', [args.filter ?? '', args.limit ?? 50], 'Start the CWTools LSP process or connect this host to an existing language server.');
286
309
  case 'query_enums':
287
- return executeLspTool(host, 'cwtools.ai.queryEnums', [args.enumName ?? '', args.limit ?? 500], 'Start the CWTools LSP process or connect this host to an existing language server.');
310
+ return lspTool('cwtools.ai.queryEnums', [args.enumName ?? '', args.limit ?? 500], 'Start the CWTools LSP process or connect this host to an existing language server.');
288
311
  case 'query_static_modifiers':
289
- return executeLspTool(host, 'cwtools.ai.queryStaticModifiers', [args.filter ?? '', args.limit ?? 300], 'Start the CWTools LSP process or connect this host to an existing language server.');
312
+ return lspTool('cwtools.ai.queryStaticModifiers', [args.filter ?? '', args.limit ?? 300], 'Start the CWTools LSP process or connect this host to an existing language server.');
290
313
  case 'query_variables':
291
- return executeLspTool(host, 'cwtools.ai.queryVariables', [args.filter ?? ''], 'Start the CWTools LSP process or connect this host to an existing language server.');
314
+ return lspTool('cwtools.ai.queryVariables', [args.filter ?? ''], 'Start the CWTools LSP process or connect this host to an existing language server.');
292
315
  case 'get_entity_info':
293
- return executeLspTool(host, 'cwtools.ai.getEntityInfo', [toFileUri(String(args.file ?? ''), host.workspaceRoot)], 'Start the CWTools LSP process or connect this host to an existing language server.');
316
+ return lspTool('cwtools.ai.getEntityInfo', [toFileUri(String(args.file ?? ''), host.workspaceRoot)], 'Start the CWTools LSP process or connect this host to an existing language server.');
294
317
  case 'get_pdx_block':
295
318
  return (0, pdxBlock_1.getPdxBlockWithHost)(host, {
296
319
  file: String(args.file ?? ''),
@@ -299,23 +322,23 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
299
322
  // Shader knowledge tools: each LSP command takes a single JSON record
300
323
  // argument and returns { ok, ... } / { ok: false, status: 'error', ... }.
301
324
  case 'query_shader_symbol':
302
- return executeLspTool(host, 'cwtools.ai.shader.symbols', [shaderRecord({
325
+ return lspTool('cwtools.ai.shader.symbols', [shaderRecord({
303
326
  filter: typeof args.filter === 'string' ? args.filter : undefined,
304
327
  kind: typeof args.kind === 'string' ? args.kind : undefined,
305
328
  limit: typeof args.limit === 'number' ? args.limit : undefined,
306
329
  cursor: typeof args.cursor === 'number' ? args.cursor : undefined,
307
330
  })], 'Start the CWTools LSP process and wait for the shader model to load before querying shader symbols.');
308
331
  case 'query_shader_compile_unit':
309
- return executeLspTool(host, 'cwtools.ai.shader.compileUnit', [{ uri: toFileUri(String(args.file ?? ''), host.workspaceRoot) }], 'Start the CWTools LSP process and wait for the shader model to load before resolving compile units.');
332
+ return lspTool('cwtools.ai.shader.compileUnit', [{ uri: toFileUri(String(args.file ?? ''), host.workspaceRoot) }], 'Start the CWTools LSP process and wait for the shader model to load before resolving compile units.');
310
333
  case 'query_shader_platform_variants':
311
- return executeLspTool(host, 'cwtools.ai.shader.variants', [{ uri: toFileUri(String(args.file ?? ''), host.workspaceRoot) }], 'Start the CWTools LSP process and wait for the shader model to load before comparing shader platform variants.');
334
+ return lspTool('cwtools.ai.shader.variants', [{ uri: toFileUri(String(args.file ?? ''), host.workspaceRoot) }], 'Start the CWTools LSP process and wait for the shader model to load before comparing shader platform variants.');
312
335
  case 'query_shader_callers':
313
- return executeLspTool(host, 'cwtools.ai.shader.callers', [shaderRecord({
336
+ return lspTool('cwtools.ai.shader.callers', [shaderRecord({
314
337
  effectName: String(args.effectName ?? ''),
315
338
  limit: typeof args.limit === 'number' ? args.limit : undefined,
316
339
  })], 'Start the CWTools LSP process and wait for the shader model to load before querying Effect callers.');
317
340
  case 'explain_shader_reachability':
318
- return executeLspTool(host, 'cwtools.ai.shader.reachability', [typeof args.effectName === 'string' && args.effectName
341
+ return lspTool('cwtools.ai.shader.reachability', [typeof args.effectName === 'string' && args.effectName
319
342
  ? { effectName: args.effectName }
320
343
  : shaderRecord({
321
344
  uri: toFileUri(String(args.file ?? ''), host.workspaceRoot),
@@ -323,11 +346,20 @@ const defaultSharedToolDispatcher = async (host, name, rawArgs) => {
323
346
  cursor: typeof args.cursor === 'number' ? args.cursor : undefined,
324
347
  })], 'Start the CWTools LSP process and wait for the shader model to load before explaining Effect reachability.');
325
348
  case 'validate_shader':
326
- return executeLspTool(host, 'cwtools.ai.shader.validate', [{ uri: toFileUri(String(args.file ?? ''), host.workspaceRoot) }], 'Start the CWTools LSP process and wait for the shader model to load before validating shader files.');
349
+ return lspTool('cwtools.ai.shader.validate', [{ uri: toFileUri(String(args.file ?? ''), host.workspaceRoot) }], 'Start the CWTools LSP process and wait for the shader model to load before validating shader files.');
327
350
  case 'compare_shader_with_vanilla':
328
- return executeLspTool(host, 'cwtools.ai.shader.compareVanilla', [typeof args.effectName === 'string' && args.effectName
351
+ return lspTool('cwtools.ai.shader.compareVanilla', [typeof args.effectName === 'string' && args.effectName
329
352
  ? { effectName: args.effectName }
330
353
  : { uri: toFileUri(String(args.file ?? ''), host.workspaceRoot) }], 'Start the CWTools LSP process and wait for the shader model to load before comparing with vanilla.');
354
+ case 'get_ide_context':
355
+ case 'open_in_visual_editor':
356
+ return (0, schema_1.toolUnavailable)(name, `${name} requires the active VS Code extension bridge (default mode without --standalone).`, ['Open the project in VS Code / Cursor / Antigravity with the CWTools extension active and connect via bridge mode.']);
357
+ case 'typed_pdx_write':
358
+ case 'candidate_transaction':
359
+ case 'convert_image_to_dds':
360
+ case 'convert_audio':
361
+ case 'deploy_mod_asset':
362
+ return (0, schema_1.toolUnavailable)(name, `${name} requires the active VS Code extension bridge started with --allow-domain-writes (or --enable-writes).`, ['Connect to the active VS Code extension bridge with --allow-domain-writes enabled.']);
331
363
  default:
332
364
  return {
333
365
  ok: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cwtools-shared",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Shared protocol and tool contracts for the CWTools MCP server",
5
5
  "license": "MIT",
6
6
  "repository": {