@satelliteoflove/godot-mcp 3.21.0 → 3.21.1
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/addon/plugin.cfg +1 -1
- package/dist/__tests__/core/doc-examples.test.d.ts +2 -0
- package/dist/__tests__/core/doc-examples.test.d.ts.map +1 -0
- package/dist/__tests__/core/doc-examples.test.js +102 -0
- package/dist/__tests__/core/doc-examples.test.js.map +1 -0
- package/dist/core/doc-examples.d.ts +12 -0
- package/dist/core/doc-examples.d.ts.map +1 -0
- package/dist/core/doc-examples.js +116 -0
- package/dist/core/doc-examples.js.map +1 -0
- package/package.json +1 -1
package/addon/plugin.cfg
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-examples.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/core/doc-examples.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { getActionVariants, buildVariantExample, rawJsonSchema, exampleForProp, } from '../../core/doc-examples.js';
|
|
3
|
+
import { sceneTools, nodeTools, editorTools, projectTools, animationTools, tilemapTools, resourceTools, scene3dTools, docsTools, inputTools, profilerTools, runtimeStateTools, gameTimeTools, execTools, } from '../../tools/index.js';
|
|
4
|
+
const ALL_TOOLS = [
|
|
5
|
+
...sceneTools,
|
|
6
|
+
...nodeTools,
|
|
7
|
+
...editorTools,
|
|
8
|
+
...projectTools,
|
|
9
|
+
...animationTools,
|
|
10
|
+
...tilemapTools,
|
|
11
|
+
...resourceTools,
|
|
12
|
+
...scene3dTools,
|
|
13
|
+
...docsTools,
|
|
14
|
+
...inputTools,
|
|
15
|
+
...profilerTools,
|
|
16
|
+
...runtimeStateTools,
|
|
17
|
+
...gameTimeTools,
|
|
18
|
+
...execTools,
|
|
19
|
+
];
|
|
20
|
+
// Tool + each of its action variants, as the doc generator sees them.
|
|
21
|
+
const ACTION_CASES = ALL_TOOLS.flatMap((tool) => {
|
|
22
|
+
const variants = getActionVariants(rawJsonSchema(tool));
|
|
23
|
+
return variants ? variants.map((variant) => ({ tool, variant })) : [];
|
|
24
|
+
});
|
|
25
|
+
function variantOf(toolName, action) {
|
|
26
|
+
const tool = ALL_TOOLS.find((t) => t.name === toolName);
|
|
27
|
+
const variant = getActionVariants(rawJsonSchema(tool)).find((v) => v.action === action);
|
|
28
|
+
return { tool, variant };
|
|
29
|
+
}
|
|
30
|
+
describe('generated doc examples (#287)', () => {
|
|
31
|
+
it('discovers action variants across the tool surface', () => {
|
|
32
|
+
// Guards the whole premise: if union detection regresses, every per-action
|
|
33
|
+
// doc would silently fall back to the flat path again.
|
|
34
|
+
const toolsWithActions = new Set(ACTION_CASES.map((c) => c.tool.name));
|
|
35
|
+
expect(toolsWithActions.size).toBeGreaterThanOrEqual(14);
|
|
36
|
+
expect(ACTION_CASES.length).toBeGreaterThan(50);
|
|
37
|
+
});
|
|
38
|
+
// Defect 1: every generated example must satisfy the REAL Zod schema —
|
|
39
|
+
// including discriminator-only actions, schema-required fields, and refines.
|
|
40
|
+
it.each(ACTION_CASES.map((c) => [`${c.tool.name}:${c.variant.action}`, c]))('emits a schema-valid example for %s', (_label, { tool, variant }) => {
|
|
41
|
+
const example = buildVariantExample(variant, tool.schema);
|
|
42
|
+
const result = tool.schema.safeParse(example);
|
|
43
|
+
expect(result.success, JSON.stringify(example)).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
// Defect 2: each action literal's .describe() must be available to render
|
|
46
|
+
// under the action heading (no more empty Actions sections).
|
|
47
|
+
it.each(ACTION_CASES.map((c) => [`${c.tool.name}:${c.variant.action}`, c]))('carries an action description for %s', (_label, { variant }) => {
|
|
48
|
+
const desc = String(variant.properties.action?.description ?? '').trim();
|
|
49
|
+
expect(desc.length).toBeGreaterThan(0);
|
|
50
|
+
});
|
|
51
|
+
it('includes schema-required fields beyond the discriminator (exec run -> source, remove -> name)', () => {
|
|
52
|
+
const run = variantOf('godot_exec', 'run');
|
|
53
|
+
expect(buildVariantExample(run.variant, run.tool.schema)).toMatchObject({
|
|
54
|
+
action: 'run',
|
|
55
|
+
source: expect.any(String),
|
|
56
|
+
});
|
|
57
|
+
const remove = variantOf('godot_exec', 'remove');
|
|
58
|
+
expect(buildVariantExample(remove.variant, remove.tool.schema)).toMatchObject({
|
|
59
|
+
action: 'remove',
|
|
60
|
+
name: expect.any(String),
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it('satisfies a refine that JSON Schema cannot express (watch_start needs specs or signals)', () => {
|
|
64
|
+
const { tool, variant } = variantOf('godot_runtime_state', 'watch_start');
|
|
65
|
+
const example = buildVariantExample(variant, tool.schema);
|
|
66
|
+
// Required-only would be {action} and fail the refine; augmentation must add one.
|
|
67
|
+
const hasSpecs = Array.isArray(example.specs) && example.specs.length > 0;
|
|
68
|
+
const hasSignals = Array.isArray(example.signals) && example.signals.length > 0;
|
|
69
|
+
expect(hasSpecs || hasSignals).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
it('does not over-specify actions that need only the discriminator (watch_collect)', () => {
|
|
72
|
+
const { tool, variant } = variantOf('godot_runtime_state', 'watch_collect');
|
|
73
|
+
const example = buildVariantExample(variant, tool.schema);
|
|
74
|
+
expect(example).toEqual({ action: 'watch_collect' });
|
|
75
|
+
});
|
|
76
|
+
describe('exampleForProp', () => {
|
|
77
|
+
it('builds a non-empty array from its items schema', () => {
|
|
78
|
+
const val = exampleForProp('paths', { type: 'array', items: { type: 'string' } });
|
|
79
|
+
expect(val).toEqual(['example']);
|
|
80
|
+
});
|
|
81
|
+
it('builds a union-typed array entry from the first branch (input sequence entries)', () => {
|
|
82
|
+
const { tool } = variantOf('godot_input', 'sequence');
|
|
83
|
+
const example = buildVariantExample(getActionVariants(rawJsonSchema(tool)).find((v) => v.action === 'sequence'), tool.schema);
|
|
84
|
+
const inputs = example.inputs;
|
|
85
|
+
expect(Array.isArray(inputs)).toBe(true);
|
|
86
|
+
expect(inputs.length).toBeGreaterThan(0);
|
|
87
|
+
expect(inputs[0]).not.toBeNull();
|
|
88
|
+
});
|
|
89
|
+
it('respects a numeric lower bound', () => {
|
|
90
|
+
expect(exampleForProp('hz', { type: 'integer', minimum: 1 })).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
it('only populates required object fields', () => {
|
|
93
|
+
const val = exampleForProp('spec', {
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: { path: { type: 'string' }, fields: { type: 'array', items: { type: 'string' } } },
|
|
96
|
+
required: ['path'],
|
|
97
|
+
});
|
|
98
|
+
expect(val).toEqual({ path: '/root/Main/Player' });
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=doc-examples.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-examples.test.js","sourceRoot":"","sources":["../../../src/__tests__/core/doc-examples.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,SAAS,EACT,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,SAAS,GACV,MAAM,sBAAsB,CAAC;AAG9B,MAAM,SAAS,GAAwB;IACrC,GAAG,UAAU;IACb,GAAG,SAAS;IACZ,GAAG,WAAW;IACd,GAAG,YAAY;IACf,GAAG,cAAc;IACjB,GAAG,YAAY;IACf,GAAG,aAAa;IAChB,GAAG,YAAY;IACf,GAAG,SAAS;IACZ,GAAG,UAAU;IACb,GAAG,aAAa;IAChB,GAAG,iBAAiB;IACpB,GAAG,aAAa;IAChB,GAAG,SAAS;CACb,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E,GAAG,EAAE;YACxC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;YAC/C,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE;gBACjC,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;gBAC9F,QAAQ,EAAE,CAAC,MAAM,CAAC;aACnB,CAA4B,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { AnyToolDefinition } from './types.js';
|
|
3
|
+
export interface ActionVariant {
|
|
4
|
+
action: string;
|
|
5
|
+
properties: Record<string, Record<string, unknown>>;
|
|
6
|
+
required: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function rawJsonSchema(tool: AnyToolDefinition): Record<string, unknown>;
|
|
9
|
+
export declare function getActionVariants(schema: Record<string, unknown>): ActionVariant[] | null;
|
|
10
|
+
export declare function exampleForProp(name: string, prop: Record<string, unknown>): unknown;
|
|
11
|
+
export declare function buildVariantExample(variant: ActionVariant, toolSchema: z.ZodType): Record<string, unknown>;
|
|
12
|
+
//# sourceMappingURL=doc-examples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-examples.d.ts","sourceRoot":"","sources":["../../src/core/doc-examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAOpD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAOD,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG9E;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,GAAG,IAAI,CAezF;AAwBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAuCnF;AAOD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,CAAC,CAAC,OAAO,GACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// The Anthropic-shaped input schema flattens discriminated unions into a single
|
|
3
|
+
// object (see core/schema.ts), which discards per-action structure. For docs we
|
|
4
|
+
// want that structure back, so read the raw (un-flattened) JSON Schema, where a
|
|
5
|
+
// discriminatedUnion serializes to a top-level `oneOf` of per-action branches —
|
|
6
|
+
// each carrying its own `required` list and the action literal's `.describe()`.
|
|
7
|
+
export function rawJsonSchema(tool) {
|
|
8
|
+
const { $schema, ...rest } = z.toJSONSchema(tool.schema, { target: 'draft-07' });
|
|
9
|
+
return rest;
|
|
10
|
+
}
|
|
11
|
+
// Discriminated-union schemas serialize to oneOf (one object variant per
|
|
12
|
+
// action). Pull each variant's action literal, properties, and required list.
|
|
13
|
+
export function getActionVariants(schema) {
|
|
14
|
+
const branches = (schema.oneOf || schema.anyOf);
|
|
15
|
+
if (!Array.isArray(branches))
|
|
16
|
+
return null;
|
|
17
|
+
const variants = [];
|
|
18
|
+
for (const branch of branches) {
|
|
19
|
+
const properties = branch.properties || {};
|
|
20
|
+
const actionProp = properties.action;
|
|
21
|
+
const action = actionProp?.const ??
|
|
22
|
+
(Array.isArray(actionProp?.enum) ? actionProp.enum[0] : undefined);
|
|
23
|
+
if (action === undefined)
|
|
24
|
+
continue;
|
|
25
|
+
variants.push({ action, properties, required: branch.required || [] });
|
|
26
|
+
}
|
|
27
|
+
return variants.length > 0 ? variants : null;
|
|
28
|
+
}
|
|
29
|
+
// Representative values for well-known parameter names, so generated examples
|
|
30
|
+
// read like real calls rather than `"example"` placeholders.
|
|
31
|
+
const NAMED_EXAMPLES = {
|
|
32
|
+
node_path: '/root/Main/Player',
|
|
33
|
+
parent_path: '/root/Main',
|
|
34
|
+
new_parent_path: '/root/UI',
|
|
35
|
+
scene_path: 'res://scenes/enemy.tscn',
|
|
36
|
+
script_path: 'res://scripts/player.gd',
|
|
37
|
+
resource_path: 'res://resources/spriteframes.tres',
|
|
38
|
+
animation_name: 'idle',
|
|
39
|
+
node_name: 'NewNode',
|
|
40
|
+
node_type: 'Sprite2D',
|
|
41
|
+
name_pattern: '*Enemy*',
|
|
42
|
+
type: 'CharacterBody2D',
|
|
43
|
+
root_path: '/root/Main',
|
|
44
|
+
path: '/root/Main/Player',
|
|
45
|
+
signal: 'body_entered',
|
|
46
|
+
};
|
|
47
|
+
// Build a representative, schema-VALID value for one JSON-Schema property.
|
|
48
|
+
// Recurses through arrays/objects/unions and produces NON-EMPTY arrays +
|
|
49
|
+
// populated required object fields, so min-length / nested-required constraints hold.
|
|
50
|
+
export function exampleForProp(name, prop) {
|
|
51
|
+
if (prop.const !== undefined)
|
|
52
|
+
return prop.const;
|
|
53
|
+
if (Array.isArray(prop.enum))
|
|
54
|
+
return prop.enum[0];
|
|
55
|
+
if (name in NAMED_EXAMPLES)
|
|
56
|
+
return NAMED_EXAMPLES[name];
|
|
57
|
+
// A prop that is itself a union (z.union / z.discriminatedUnion serialize to
|
|
58
|
+
// anyOf / oneOf — e.g. the input `sequence` entry shapes): build the first branch.
|
|
59
|
+
const branches = (prop.oneOf ?? prop.anyOf ?? prop.allOf);
|
|
60
|
+
if (Array.isArray(branches) && branches.length > 0) {
|
|
61
|
+
return exampleForProp(name, branches[0]);
|
|
62
|
+
}
|
|
63
|
+
switch (prop.type) {
|
|
64
|
+
case 'string':
|
|
65
|
+
return 'example';
|
|
66
|
+
case 'integer':
|
|
67
|
+
case 'number':
|
|
68
|
+
// Respect a lower bound so .min(n) constraints aren't violated.
|
|
69
|
+
return typeof prop.minimum === 'number' ? prop.minimum : 0;
|
|
70
|
+
case 'boolean':
|
|
71
|
+
return false;
|
|
72
|
+
case 'array': {
|
|
73
|
+
const items = prop.items;
|
|
74
|
+
// One representative element: keeps arrays non-empty so a length-based
|
|
75
|
+
// refine (e.g. watch_start's specs/signals) is satisfied.
|
|
76
|
+
return items ? [exampleForProp(name, items)] : [];
|
|
77
|
+
}
|
|
78
|
+
case 'object': {
|
|
79
|
+
const props = prop.properties || {};
|
|
80
|
+
const req = prop.required || [];
|
|
81
|
+
const obj = {};
|
|
82
|
+
for (const key of Object.keys(props)) {
|
|
83
|
+
if (req.includes(key))
|
|
84
|
+
obj[key] = exampleForProp(key, props[key]);
|
|
85
|
+
}
|
|
86
|
+
return obj;
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// A copy-pasteable example for one action: the discriminator plus every
|
|
93
|
+
// schema-required field. JSON Schema can't express cross-field refinements
|
|
94
|
+
// (e.g. watch_start requires specs OR signals), so if the required-only example
|
|
95
|
+
// fails the REAL Zod schema, add optional fields one at a time until it
|
|
96
|
+
// validates — keeping the minimal field that unblocks it (#287).
|
|
97
|
+
export function buildVariantExample(variant, toolSchema) {
|
|
98
|
+
const example = { action: variant.action };
|
|
99
|
+
for (const name of variant.required) {
|
|
100
|
+
if (name === 'action')
|
|
101
|
+
continue;
|
|
102
|
+
example[name] = exampleForProp(name, variant.properties[name]);
|
|
103
|
+
}
|
|
104
|
+
if (!toolSchema.safeParse(example).success) {
|
|
105
|
+
for (const [name, prop] of Object.entries(variant.properties)) {
|
|
106
|
+
if (name === 'action' || name in example)
|
|
107
|
+
continue;
|
|
108
|
+
example[name] = exampleForProp(name, prop);
|
|
109
|
+
if (toolSchema.safeParse(example).success)
|
|
110
|
+
break;
|
|
111
|
+
delete example[name]; // this field didn't unblock it — don't over-specify
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return example;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=doc-examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-examples.js","sourceRoot":"","sources":["../../src/core/doc-examples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAA4B,CAAC;IAC5G,OAAO,IAAI,CAAC;AACd,CAAC;AAED,yEAAyE;AACzE,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,MAA+B;IAC/D,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAA+C,CAAC;IAC9F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,C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