@openora/mcp 0.4.1-canary.49 → 0.4.1-canary.494
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/README.md +33 -15
- package/dist/.tsbuildinfo +1 -1
- package/dist/dep-graph-cli.d.ts +3 -0
- package/dist/dep-graph-cli.d.ts.map +1 -0
- package/dist/dep-graph-cli.js +10 -0
- package/dist/dep-graph-cli.js.map +1 -0
- package/dist/dep-graph.d.ts +16 -0
- package/dist/dep-graph.d.ts.map +1 -0
- package/dist/dep-graph.js +121 -0
- package/dist/dep-graph.js.map +1 -0
- package/dist/intent.d.ts +3 -0
- package/dist/intent.d.ts.map +1 -0
- package/dist/intent.js +18 -0
- package/dist/intent.js.map +1 -0
- package/dist/main.js +357 -105
- package/dist/main.js.map +1 -1
- package/dist/source.d.ts +26 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +125 -0
- package/dist/source.js.map +1 -0
- package/docs/catalog.json +6518 -287
- package/docs/dep-graph.json +1 -0
- package/package.json +13 -10
package/dist/main.js
CHANGED
|
@@ -5,7 +5,54 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
6
|
import { dirname, join, parse } from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { buildDepGraph, impactOf } from './dep-graph.js';
|
|
9
|
+
import { classifyIntent } from './intent.js';
|
|
10
|
+
import { findCoreSourceRoot, findSymbol, findUsages, outline, readSourceTree, LINE_WIDTH, } from './source.js';
|
|
8
11
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const ownPackage = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8'));
|
|
13
|
+
const formatMethods = (a) => a.methods?.length ? ` { ${a.methods.join(', ')} }` : '';
|
|
14
|
+
const formatIam = (iam) => iam ? `${iam.resource}:${iam.action}` : '(non-literal)';
|
|
15
|
+
function formatAgentTool(t) {
|
|
16
|
+
return [
|
|
17
|
+
`- ${t.id} [${t.class ?? '?'}, v${t.schemaVersion ?? '?'}, iam ${formatIam(t.iam)}, module ${t.module}]`,
|
|
18
|
+
...(t.title || t.description
|
|
19
|
+
? [` ${[t.title, t.description].filter(Boolean).join(' - ')}`]
|
|
20
|
+
: []),
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
function formatAgentAction(a) {
|
|
24
|
+
const reversibility = a.reversible === null ? 'reversible ?' : a.reversible ? 'reversible' : 'irreversible';
|
|
25
|
+
const benefit = a.benefitsPlayer === null
|
|
26
|
+
? ', benefits player ?'
|
|
27
|
+
: a.benefitsPlayer
|
|
28
|
+
? ', benefits player'
|
|
29
|
+
: a.benefitsPlayerWhen
|
|
30
|
+
? `, benefits player when ${a.benefitsPlayerWhen.field} is ${a.benefitsPlayerWhen.values.join(' or ')}`
|
|
31
|
+
: '';
|
|
32
|
+
const distinct = a.distinctBy ? `, distinct by ${a.distinctBy}` : '';
|
|
33
|
+
return [
|
|
34
|
+
`- ${a.id} [${reversibility}${benefit}${distinct}, v${a.schemaVersion ?? '?'}, iam ${formatIam(a.iam)}, module ${a.module}]`,
|
|
35
|
+
...(a.title || a.description
|
|
36
|
+
? [` ${[a.title, a.description].filter(Boolean).join(' - ')}`]
|
|
37
|
+
: []),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
const containsIgnoreCase = (query, ...fields) => fields.some((f) => f.toLowerCase().includes(query.toLowerCase()));
|
|
41
|
+
function bindingPlugins(a) {
|
|
42
|
+
return a.boundIn
|
|
43
|
+
.filter((p) => p.endsWith('/plugin.ts'))
|
|
44
|
+
.map((p) => p.replace(/^packages\/core\/src\//, '').replace(/\/plugin\.ts$/, ''));
|
|
45
|
+
}
|
|
46
|
+
function formatAdapter(a) {
|
|
47
|
+
const plugins = bindingPlugins(a);
|
|
48
|
+
const bound = plugins.length > 0
|
|
49
|
+
? `bound in ${plugins.join(', ')}`
|
|
50
|
+
: a.status === 'wired'
|
|
51
|
+
? 'bound in the core runtime'
|
|
52
|
+
: 'stub - bind your implementation';
|
|
53
|
+
return `- ${a.category}: ${a.interface}${formatMethods(a)} -> ${a.token} [${a.status}; ${bound}]`;
|
|
54
|
+
}
|
|
55
|
+
const SCHEMA_MATCH_LIMIT = 30;
|
|
9
56
|
const NOT_FOUND_MESSAGE = 'catalog.json not found - run `pnpm regen` in the platform repo, or set OSS_CATALOG to its path.';
|
|
10
57
|
function catalogCandidates() {
|
|
11
58
|
const candidates = [];
|
|
@@ -38,7 +85,7 @@ function loadCatalog() {
|
|
|
38
85
|
return { catalog, path: candidate };
|
|
39
86
|
}
|
|
40
87
|
catch {
|
|
41
|
-
|
|
88
|
+
continue;
|
|
42
89
|
}
|
|
43
90
|
}
|
|
44
91
|
return null;
|
|
@@ -54,54 +101,56 @@ function withCatalog(fn) {
|
|
|
54
101
|
}
|
|
55
102
|
const server = new McpServer({
|
|
56
103
|
name: 'oss',
|
|
57
|
-
version:
|
|
104
|
+
version: ownPackage.version,
|
|
58
105
|
});
|
|
59
106
|
server.registerTool('catalog-overview', {
|
|
60
|
-
description: 'START HERE. A concise "what can I extend" summary of the OSS igaming platform you are consuming: counts of modules/events/
|
|
107
|
+
description: 'START HERE. A concise "what can I extend" summary of the OSS igaming platform you are consuming: counts of modules/events/schemas, the adapter swap-seam table (category/interface/token/status), and the igaming-config fields. Read this first to orient before drilling into the other tools.',
|
|
61
108
|
inputSchema: {},
|
|
62
109
|
}, withCatalog((c) => {
|
|
63
110
|
const lines = ['=== OSS igaming platform catalog ==='];
|
|
64
111
|
lines.push(`modules: ${c.modules.length} adapters: ${c.adapters.length} events: ${c.events.length} ` +
|
|
65
|
-
`
|
|
66
|
-
`
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
112
|
+
`schemas: ${c.schemas.length} agent tools: ${c.agentTools?.length ?? 0} ` +
|
|
113
|
+
`action types: ${c.agentActions?.length ?? 0}`);
|
|
114
|
+
const stubs = c.adapters.filter((a) => a.status !== 'wired').map((a) => a.category);
|
|
115
|
+
lines.push('\n--- Adapter seams (details: list-adapters <query>) ---');
|
|
116
|
+
lines.push(c.adapters.map((a) => a.category).join(', '));
|
|
117
|
+
lines.push(`stubs awaiting an implementation: ${stubs.join(', ') || '(none)'}`);
|
|
118
|
+
lines.push(`\n--- Modules (details: describe-module <id>) ---`);
|
|
119
|
+
lines.push(c.modules.map((m) => m.id).join(', '));
|
|
71
120
|
lines.push(`\n--- Config (${c.config.token}) ---`);
|
|
72
121
|
for (const f of c.config.fields) {
|
|
73
122
|
lines.push(`- ${f.key}${f.note ? `: ${f.note}` : ''}`);
|
|
74
123
|
}
|
|
75
|
-
lines.push('\nNext: list-adapters | list-routes | list-events | list-
|
|
124
|
+
lines.push('\nNext: list-adapters | list-routes | list-events | list-agent-tools | describe-module <name> | schema-get <name> | get-config-schema');
|
|
76
125
|
return lines.join('\n');
|
|
77
126
|
}));
|
|
78
127
|
server.registerTool('list-adapters', {
|
|
79
|
-
description: 'List the vendor adapter swap-seams (PSP/KYC/game/aggregator/geo-ip/notification). For each: the interface to implement, the DI token to bind it to, whether it is already wired or a stub awaiting an implementation, and
|
|
80
|
-
inputSchema: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (a.boundIn.length > 0) {
|
|
91
|
-
lines.push(` boundIn: ${a.boundIn.join(', ')}`);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
lines.push(' boundIn: (none - stub; bind your implementation to the token)');
|
|
95
|
-
}
|
|
128
|
+
description: 'List the vendor adapter swap-seams (PSP/KYC/game/aggregator/geo-ip/notification). For each: the interface to implement, the DI token to bind it to, whether it is already wired or a stub awaiting an implementation, and which module plugins bind it. Use this to find the integration point for a third-party vendor. Pass `query` (e.g. "withdrawal", "kyc") to keep the output short.',
|
|
129
|
+
inputSchema: {
|
|
130
|
+
query: z
|
|
131
|
+
.string()
|
|
132
|
+
.optional()
|
|
133
|
+
.describe('Case-insensitive filter on category, interface, token or binding module'),
|
|
134
|
+
},
|
|
135
|
+
}, async ({ query }) => {
|
|
136
|
+
const loaded = loadCatalog();
|
|
137
|
+
if (!loaded) {
|
|
138
|
+
return { content: [{ type: 'text', text: NOT_FOUND_MESSAGE }] };
|
|
96
139
|
}
|
|
97
|
-
|
|
98
|
-
|
|
140
|
+
const adapters = loaded.catalog.adapters.filter((a) => !query ||
|
|
141
|
+
containsIgnoreCase(query, a.category, a.interface, a.token, ...(a.methods ?? []), ...bindingPlugins(a)));
|
|
142
|
+
const text = adapters.length > 0
|
|
143
|
+
? `=== Adapter seams (${adapters.length}) ===\n${adapters.map(formatAdapter).join('\n')}`
|
|
144
|
+
: `No adapter seam matches "${query}".`;
|
|
145
|
+
return { content: [{ type: 'text', text }] };
|
|
146
|
+
});
|
|
99
147
|
server.registerTool('list-routes', {
|
|
100
|
-
description: 'List oRPC route namespaces exposed by the platform modules. Pass `module` to scope to a single module.
|
|
148
|
+
description: 'List oRPC route namespaces exposed by the platform modules. Pass `module` to scope to a single module and `query` (e.g. "withdraw") to keep only matching routes.',
|
|
101
149
|
inputSchema: {
|
|
102
150
|
module: z.string().optional().describe('Module id to filter by (e.g. "wallet")'),
|
|
151
|
+
query: z.string().optional().describe('Case-insensitive substring of the route'),
|
|
103
152
|
},
|
|
104
|
-
}, async ({ module: mod }) => {
|
|
153
|
+
}, async ({ module: mod, query }) => {
|
|
105
154
|
const loaded = loadCatalog();
|
|
106
155
|
if (!loaded) {
|
|
107
156
|
return { content: [{ type: 'text', text: NOT_FOUND_MESSAGE }] };
|
|
@@ -120,38 +169,56 @@ server.registerTool('list-routes', {
|
|
|
120
169
|
}
|
|
121
170
|
const lines = [];
|
|
122
171
|
for (const m of modules) {
|
|
123
|
-
|
|
124
|
-
|
|
172
|
+
const routes = m.routes.filter((r) => !query || containsIgnoreCase(query, r));
|
|
173
|
+
if (routes.length > 0) {
|
|
174
|
+
lines.push(`${m.id}:\n${routes.map((r) => ` ${r}`).join('\n')}`);
|
|
125
175
|
}
|
|
126
176
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
const text = lines.join('\n\n') || 'No routes defined in the catalog yet.';
|
|
177
|
+
const text = lines.join('\n\n') ||
|
|
178
|
+
(query ? `No route matches "${query}".` : 'No routes defined in the catalog yet.');
|
|
131
179
|
return { content: [{ type: 'text', text }] };
|
|
132
180
|
});
|
|
133
181
|
server.registerTool('list-events', {
|
|
134
|
-
description: 'List the cross-module domain events you can subscribe to (via ctx.events.on in a plugin) or that signal platform activity. Use this to find the event to hook into for side effects.',
|
|
135
|
-
inputSchema: {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
server.registerTool('list-slots', {
|
|
143
|
-
description: 'List the named UI slots you can fill from a client-side UI plugin (ctx.<slot>.add(...)) to extend the backoffice without forking: nav items, table columns, dashboard tiles, detail sections. Includes each slot description and subject type.',
|
|
144
|
-
inputSchema: {},
|
|
145
|
-
}, withCatalog((c) => {
|
|
146
|
-
if (c.uiSlots.length === 0) {
|
|
147
|
-
return 'No UI slots in the catalog.';
|
|
182
|
+
description: 'List the cross-module domain events you can subscribe to (via ctx.events.on in a plugin) or that signal platform activity. Use this to find the event to hook into for side effects. Pass `query` (e.g. "withdrawal", "promo.bonus") to keep the output short.',
|
|
183
|
+
inputSchema: {
|
|
184
|
+
query: z.string().optional().describe('Case-insensitive substring of the event name'),
|
|
185
|
+
},
|
|
186
|
+
}, async ({ query }) => {
|
|
187
|
+
const loaded = loadCatalog();
|
|
188
|
+
if (!loaded) {
|
|
189
|
+
return { content: [{ type: 'text', text: NOT_FOUND_MESSAGE }] };
|
|
148
190
|
}
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
191
|
+
const events = loaded.catalog.events.filter((e) => !query || containsIgnoreCase(query, e));
|
|
192
|
+
const text = events.length > 0
|
|
193
|
+
? `=== Domain events (${events.length}) ===\n${events.map((e) => `- ${e}`).join('\n')}`
|
|
194
|
+
: `No event matches "${query}".`;
|
|
195
|
+
return { content: [{ type: 'text', text }] };
|
|
196
|
+
});
|
|
197
|
+
server.registerTool('list-agent-tools', {
|
|
198
|
+
description: 'List the agent surface: MCP tools (read calls a model may make during a run) and action types (state changes a model may only propose; an idempotent executor runs them after approval). Each entry shows its IAM resource:action, schema version and owning module. Modules register them in plugin.ts with ctx.mcp.tool(defineMcpTool({...}), factory) and ctx.actions.register(defineActionType({...}), factory); consumers reach them only through the MCP_KERNEL token, which validates input, checks IAM, applies the output allow-list and audits every call. Pass `module` to scope to one module and `query` to match ids, titles and descriptions.',
|
|
199
|
+
inputSchema: {
|
|
200
|
+
module: z.string().optional().describe('Module id to filter by (e.g. "wallet")'),
|
|
201
|
+
query: z
|
|
202
|
+
.string()
|
|
203
|
+
.optional()
|
|
204
|
+
.describe('Case-insensitive substring of the id, title or description'),
|
|
205
|
+
},
|
|
206
|
+
}, async ({ module: mod, query }) => {
|
|
207
|
+
const loaded = loadCatalog();
|
|
208
|
+
if (!loaded) {
|
|
209
|
+
return { content: [{ type: 'text', text: NOT_FOUND_MESSAGE }] };
|
|
152
210
|
}
|
|
153
|
-
|
|
154
|
-
|
|
211
|
+
const c = loaded.catalog;
|
|
212
|
+
const matches = (e) => (!mod || e.module === mod) &&
|
|
213
|
+
(!query || containsIgnoreCase(query, e.id, e.title ?? '', e.description ?? ''));
|
|
214
|
+
const tools = (c.agentTools ?? []).filter(matches);
|
|
215
|
+
const actions = (c.agentActions ?? []).filter(matches);
|
|
216
|
+
const lines = [`=== Agent tools (${tools.length}) ===`];
|
|
217
|
+
lines.push(...(tools.length > 0 ? tools.flatMap(formatAgentTool) : ['(none)']));
|
|
218
|
+
lines.push(`\n=== Agent action types (${actions.length}) ===`);
|
|
219
|
+
lines.push(...(actions.length > 0 ? actions.flatMap(formatAgentAction) : ['(none)']));
|
|
220
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
221
|
+
});
|
|
155
222
|
server.registerTool('describe-module', {
|
|
156
223
|
description: "Describe one platform module from the catalog: its group (player/backoffice/platform), Drizzle tables, and oRPC routes. Use this to understand a module's surface before extending or integrating with it.",
|
|
157
224
|
inputSchema: { name: z.string().describe('Module id (e.g. "wallet", "gaming")') },
|
|
@@ -176,12 +243,31 @@ server.registerTool('describe-module', {
|
|
|
176
243
|
const lines = [`=== Module: ${m.id} (${m.group}) ===`];
|
|
177
244
|
lines.push(`\n--- Tables ---\n${m.tables.length > 0 ? m.tables.map((t) => `- ${t}`).join('\n') : '(none)'}`);
|
|
178
245
|
lines.push(`\n--- Routes ---\n${m.routes.length > 0 ? m.routes.map((r) => `- ${r}`).join('\n') : '(none)'}`);
|
|
246
|
+
const eventSegments = [m.id, m.id.replaceAll('-', '_')];
|
|
247
|
+
const events = c.events.filter((e) => e.split('.').some((s) => eventSegments.includes(s)));
|
|
248
|
+
lines.push(`\n--- Events named after this module ---\n${events.length > 0 ? events.map((e) => `- ${e}`).join('\n') : '(none - try list-events query=<word>)'}`);
|
|
249
|
+
const seams = c.adapters.filter((a) => bindingPlugins(a).some((p) => p === m.id || p.endsWith(`/${m.id}`)));
|
|
250
|
+
if (seams.length > 0) {
|
|
251
|
+
const seamLines = seams.map((a) => `- ${a.category} -> ${a.token}`).join('\n');
|
|
252
|
+
lines.push(`\n--- Adapter seams this module binds or reads (methods: list-adapters query=<category>) ---\n${seamLines}`);
|
|
253
|
+
}
|
|
254
|
+
const tools = (c.agentTools ?? []).filter((t) => t.module === m.id);
|
|
255
|
+
const actions = (c.agentActions ?? []).filter((a) => a.module === m.id);
|
|
256
|
+
if (tools.length > 0) {
|
|
257
|
+
lines.push(`\n--- Agent tools ---\n${tools.flatMap(formatAgentTool).join('\n')}`);
|
|
258
|
+
}
|
|
259
|
+
if (actions.length > 0) {
|
|
260
|
+
lines.push(`\n--- Agent action types ---\n${actions.flatMap(formatAgentAction).join('\n')}`);
|
|
261
|
+
}
|
|
179
262
|
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
180
263
|
});
|
|
181
264
|
server.registerTool('schema-get', {
|
|
182
265
|
description: 'Locate a Zod contract schema by name and return the file that defines it. The actual shape is read from the package types you have installed; this tells you WHERE the schema lives so you can import it.',
|
|
183
266
|
inputSchema: {
|
|
184
|
-
name: z
|
|
267
|
+
name: z
|
|
268
|
+
.string()
|
|
269
|
+
.min(1)
|
|
270
|
+
.describe('Schema name, e.g. "WalletBalance" or "WalletBalanceSchema"'),
|
|
185
271
|
},
|
|
186
272
|
}, async ({ name }) => {
|
|
187
273
|
const loaded = loadCatalog();
|
|
@@ -194,18 +280,132 @@ server.registerTool('schema-get', {
|
|
|
194
280
|
if (hit) {
|
|
195
281
|
return { content: [{ type: 'text', text: `${hit.name}\n${hit.file}` }] };
|
|
196
282
|
}
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
.
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
283
|
+
const close = c.schemas.filter((s) => containsIgnoreCase(name, s.name));
|
|
284
|
+
const shown = close
|
|
285
|
+
.slice(0, SCHEMA_MATCH_LIMIT)
|
|
286
|
+
.map((s) => `- ${s.name} ${s.file}`)
|
|
287
|
+
.join('\n');
|
|
288
|
+
const more = close.length > SCHEMA_MATCH_LIMIT
|
|
289
|
+
? `\n(${close.length - SCHEMA_MATCH_LIMIT} more - narrow the name)`
|
|
290
|
+
: '';
|
|
291
|
+
const text = close.length > 0
|
|
292
|
+
? `No schema named "${name}". Names containing it:\n${shown}${more}`
|
|
293
|
+
: `No schema name contains "${name}". Try a shorter word (e.g. "Withdraw").`;
|
|
294
|
+
return { content: [{ type: 'text', text }] };
|
|
295
|
+
});
|
|
296
|
+
const USAGE_LIMIT = 40;
|
|
297
|
+
const SYMBOL_LOCATION_LIMIT = 5;
|
|
298
|
+
function loadSource() {
|
|
299
|
+
const loaded = loadCatalog();
|
|
300
|
+
const root = process.env['OSS_SOURCE'] ?? (loaded ? findCoreSourceRoot(loaded.path) : null);
|
|
301
|
+
if (!root || !existsSync(root)) {
|
|
302
|
+
return 'Platform source not found - it is read from a linked platform checkout (packages/core/src). Set OSS_SOURCE to that folder.';
|
|
303
|
+
}
|
|
304
|
+
return { root, files: readSourceTree(root) };
|
|
305
|
+
}
|
|
306
|
+
const textReply = (text) => ({ content: [{ type: 'text', text }] });
|
|
307
|
+
const namesInput = (example) => z
|
|
308
|
+
.array(z.string().min(2))
|
|
309
|
+
.min(1)
|
|
310
|
+
.max(10)
|
|
311
|
+
.describe(`One or more names, looked up together in one call, e.g. ${example}`);
|
|
312
|
+
function usagesOf(source, name, mod, includeTests) {
|
|
313
|
+
const usages = findUsages(source.files, name, { module: mod, includeTests });
|
|
314
|
+
if (usages.length === 0) {
|
|
315
|
+
return `No usage of "${name}"${mod ? ` under ${mod}/` : ''}.`;
|
|
316
|
+
}
|
|
317
|
+
const shown = usages.slice(0, USAGE_LIMIT).map((u) => `${u.path}:${u.line} ${u.text}`);
|
|
318
|
+
const more = usages.length > USAGE_LIMIT
|
|
319
|
+
? `\n(${usages.length - USAGE_LIMIT} more - pass module=<folder> to narrow)`
|
|
320
|
+
: '';
|
|
321
|
+
return `=== ${usages.length} usages of ${name} ===\n${shown.join('\n')}${more}`;
|
|
322
|
+
}
|
|
323
|
+
server.registerTool('find-usages', {
|
|
324
|
+
description: 'Find where identifiers are used: a DI token (WALLET_COMMANDS), a function, a type, an event or route id. Whole-word match over packages/core/src, comment lines and tests skipped. Returns `file:line code`, capped. Pass every name you need in one call. Use it instead of grepping the platform source.',
|
|
325
|
+
inputSchema: {
|
|
326
|
+
names: namesInput('["WALLET_COMMANDS", "withdraw"]'),
|
|
327
|
+
module: z
|
|
328
|
+
.string()
|
|
329
|
+
.optional()
|
|
330
|
+
.describe('Only files under this folder, for every name, e.g. "wallet" or "promo/bonus"'),
|
|
331
|
+
includeTests: z.boolean().optional().describe('Also search test files (default false)'),
|
|
332
|
+
},
|
|
333
|
+
}, async ({ names, module: mod, includeTests }) => {
|
|
334
|
+
const source = loadSource();
|
|
335
|
+
if (typeof source === 'string') {
|
|
336
|
+
return textReply(source);
|
|
337
|
+
}
|
|
338
|
+
const sections = [...new Set(names)].map((name) => usagesOf(source, name, mod, includeTests));
|
|
339
|
+
return textReply([`(paths under ${source.root})`, ...sections].join('\n\n'));
|
|
340
|
+
});
|
|
341
|
+
function symbolOf(source, name, file, maxLines) {
|
|
342
|
+
const hits = findSymbol(source.files, name, { file });
|
|
343
|
+
if (hits.length === 0) {
|
|
344
|
+
return `No declaration of "${name}"${file ? ` in files matching ${file}` : ''}. Try find-usages names=["${name.split('.').pop()}"].`;
|
|
345
|
+
}
|
|
346
|
+
if (hits.length > SYMBOL_LOCATION_LIMIT) {
|
|
347
|
+
const where = hits
|
|
348
|
+
.slice(0, USAGE_LIMIT)
|
|
349
|
+
.map((h) => `${h.path}:${h.line} ${(h.body[0] ?? '').trim().slice(0, LINE_WIDTH)}`);
|
|
350
|
+
if (hits.length > USAGE_LIMIT) {
|
|
351
|
+
where.push(`(${hits.length - USAGE_LIMIT} more)`);
|
|
352
|
+
}
|
|
353
|
+
return `${hits.length} declarations of "${name}" - pass file=<path part>${name.includes('.') ? '' : ` or Owner.${name}`}:\n${where.join('\n')}`;
|
|
354
|
+
}
|
|
355
|
+
return hits
|
|
356
|
+
.map((h) => {
|
|
357
|
+
const path = `${source.root}/${h.path}`;
|
|
358
|
+
const head = `--- ${path}:${h.line}-${h.line + h.body.length - 1} ---`;
|
|
359
|
+
if (h.body.length <= maxLines) {
|
|
360
|
+
return `${head}\n${h.body.map((l) => l.slice(0, LINE_WIDTH)).join('\n')}`;
|
|
361
|
+
}
|
|
362
|
+
const shape = outline(h);
|
|
363
|
+
const shown = shape.slice(0, maxLines).map((l) => l.slice(0, LINE_WIDTH));
|
|
364
|
+
const nextLine = shape[maxLines]?.split(':')[0];
|
|
365
|
+
const rest = nextLine
|
|
366
|
+
? `${shape.length - maxLines} more outline lines; Read ${path} offset=${nextLine} limit=${h.line + h.body.length - Number(nextLine)} for the rest`
|
|
367
|
+
: `Read ${path} offset=<line> limit=<n> for a part`;
|
|
368
|
+
return [
|
|
369
|
+
`${head} (outline: ${h.body.length} lines is over maxLines=${maxLines})`,
|
|
370
|
+
...shown,
|
|
371
|
+
`... (${rest}, or raise maxLines for the whole body)`,
|
|
372
|
+
].join('\n');
|
|
373
|
+
})
|
|
374
|
+
.join('\n\n');
|
|
375
|
+
}
|
|
376
|
+
server.registerTool('get-symbol', {
|
|
377
|
+
description: 'Print the source of platform declarations: a function, const, schema, type, interface, class or one method with `Owner.method` (e.g. "WalletService.withdraw", "WithdrawInputSchema"). A body over maxLines comes back as a numbered outline (members, or statements and their if/throw/await lines). Pass every name you need in one call. Use it instead of grepping for the definition and reading the file around it.',
|
|
378
|
+
inputSchema: {
|
|
379
|
+
names: namesInput('["WalletService.withdraw", "WithdrawInputSchema"]'),
|
|
380
|
+
file: z
|
|
381
|
+
.string()
|
|
382
|
+
.optional()
|
|
383
|
+
.describe('Path substring to pick one definition, for every name, e.g. "wallet/service"'),
|
|
384
|
+
maxLines: z
|
|
385
|
+
.number()
|
|
386
|
+
.int()
|
|
387
|
+
.min(5)
|
|
388
|
+
.max(400)
|
|
389
|
+
.optional()
|
|
390
|
+
.describe('Longest body printed whole, per declaration (default 80); longer ones come back as an outline'),
|
|
391
|
+
},
|
|
392
|
+
}, async ({ names, file, maxLines = 80 }) => {
|
|
393
|
+
const source = loadSource();
|
|
394
|
+
if (typeof source === 'string') {
|
|
395
|
+
return textReply(source);
|
|
396
|
+
}
|
|
397
|
+
const budget = SYMBOL_LOCATION_LIMIT * maxLines;
|
|
398
|
+
let used = 0;
|
|
399
|
+
const sections = [...new Set(names)].map((name) => {
|
|
400
|
+
const section = symbolOf(source, name, file, maxLines);
|
|
401
|
+
const size = section.split('\n').length;
|
|
402
|
+
if (used > 0 && used + size > budget) {
|
|
403
|
+
return `(${name}: skipped, it would take this reply over ${budget} lines - ask for it in another call)`;
|
|
404
|
+
}
|
|
405
|
+
used += size;
|
|
406
|
+
return section;
|
|
407
|
+
});
|
|
408
|
+
return textReply(sections.join('\n\n'));
|
|
209
409
|
});
|
|
210
410
|
server.registerTool('get-config-schema', {
|
|
211
411
|
description: 'Return the igaming-config surface: the DI token, the source file that defines it, and each configurable field with its note. Use this to learn what a consumer can configure (branding, currencies, jurisdictions, enabled modules, limits, ...).',
|
|
@@ -220,23 +420,6 @@ server.registerTool('get-config-schema', {
|
|
|
220
420
|
}
|
|
221
421
|
return lines.join('\n');
|
|
222
422
|
}));
|
|
223
|
-
function classifyIntent(ask) {
|
|
224
|
-
const a = ` ${ask.toLowerCase()} `;
|
|
225
|
-
const has = (re) => re.test(a);
|
|
226
|
-
if (has(/\b(payment|psp|stripe|adyen|kyc|onfido|sms|email|notification|vendor|adapter|gateway)\b/)) {
|
|
227
|
-
return 'adapter';
|
|
228
|
-
}
|
|
229
|
-
if (has(/\b(page|screen|dashboard|view|frontend|admin panel|backoffice page|player page)\b/)) {
|
|
230
|
-
return 'ui-page';
|
|
231
|
-
}
|
|
232
|
-
if (has(/\b(endpoint|route|procedure|api method|rpc)\b/)) {
|
|
233
|
-
return 'route';
|
|
234
|
-
}
|
|
235
|
-
if (has(/\b(feature|module|tournament|leaderboard|jackpot|loyalty|bonus|cashback|mission|reward)\b/)) {
|
|
236
|
-
return 'feature';
|
|
237
|
-
}
|
|
238
|
-
return 'unsure';
|
|
239
|
-
}
|
|
240
423
|
function buildConsumerPlaybook(kind, ctx) {
|
|
241
424
|
const moduleList = ctx.modules.length
|
|
242
425
|
? ctx.modules.map((m) => `- ${m}`).join('\n')
|
|
@@ -245,7 +428,7 @@ function buildConsumerPlaybook(kind, ctx) {
|
|
|
245
428
|
case 'feature':
|
|
246
429
|
return [
|
|
247
430
|
'## Where it goes',
|
|
248
|
-
'New behavior in a consumer repo -> an overlay plugin (`pnpm gen plugin`). It can add routes, subscribe to events, rebind adapters
|
|
431
|
+
'New behavior in a consumer repo -> an overlay plugin (`pnpm gen plugin`). It can add routes, subscribe to events, and rebind adapters without touching OSS core.',
|
|
249
432
|
'If this is a new business domain that should be in the OSS platform itself, open an issue on the OSS repo instead.',
|
|
250
433
|
'',
|
|
251
434
|
'## Existing platform modules you can hook into',
|
|
@@ -253,15 +436,15 @@ function buildConsumerPlaybook(kind, ctx) {
|
|
|
253
436
|
'',
|
|
254
437
|
'## Playbook',
|
|
255
438
|
'1. Spawn the `expert` agent (Task tool) to turn this ask into requirements + acceptance criteria (player journey, jurisdiction rules, edge cases). Skip only for a trivial change.',
|
|
256
|
-
'2. Spawn the `builder` agent to implement: `pnpm gen plugin`, then in `register(ctx)` add routes (`ctx.routers.add`)
|
|
439
|
+
'2. Spawn the `builder` agent to implement: `pnpm gen plugin`, then in `register(ctx)` add routes (`ctx.routers.add`) and subscribe to events (`ctx.events.on`).',
|
|
257
440
|
'3. Register the plugin in `extensions.config.ts` at the repo root.',
|
|
258
|
-
'4. Spawn the `
|
|
441
|
+
'4. Spawn the `tester` agent to write/run a Playwright E2E test for the acceptance criteria.',
|
|
259
442
|
'5. Run `pnpm check:types && pnpm check:lint`.',
|
|
260
443
|
'',
|
|
261
444
|
'## Agents',
|
|
262
445
|
'- `expert` - requirements + AC (advisory, no code)',
|
|
263
446
|
'- `builder` - implements the overlay',
|
|
264
|
-
'- `
|
|
447
|
+
'- `tester` - E2E test + bug triage (OSS-core vs overlay)',
|
|
265
448
|
].join('\n');
|
|
266
449
|
case 'adapter':
|
|
267
450
|
return [
|
|
@@ -286,21 +469,16 @@ function buildConsumerPlaybook(kind, ctx) {
|
|
|
286
469
|
case 'ui-page':
|
|
287
470
|
return [
|
|
288
471
|
'## Where it goes',
|
|
289
|
-
'The platform is headless - pages live in your own frontend repo and consume the api via `@openora/core/react`.
|
|
290
|
-
'',
|
|
291
|
-
'## Named UI slots you can fill (via defineUIPlugin)',
|
|
292
|
-
ctx.slots.length
|
|
293
|
-
? ctx.slots.map((s) => `- ${s}`).join('\n')
|
|
294
|
-
: '- (run list-slots for details)',
|
|
472
|
+
'The platform is headless - pages live in your own frontend repo and consume the api via `@openora/core/react`.',
|
|
295
473
|
'',
|
|
296
474
|
'## Playbook',
|
|
297
|
-
'1. Spawn the `builder` agent to implement the page in your frontend repo
|
|
298
|
-
'2. Spawn the `
|
|
475
|
+
'1. Spawn the `builder` agent to implement the page in your frontend repo.',
|
|
476
|
+
'2. Spawn the `tester` agent to verify the page renders and behaves in a browser.',
|
|
299
477
|
'3. Run `pnpm check:types`.',
|
|
300
478
|
'',
|
|
301
479
|
'## Agents',
|
|
302
480
|
'- `builder` - mounts/extends the page',
|
|
303
|
-
'- `
|
|
481
|
+
'- `tester` - browser verification',
|
|
304
482
|
].join('\n');
|
|
305
483
|
case 'route':
|
|
306
484
|
return [
|
|
@@ -329,7 +507,7 @@ function buildConsumerPlaybook(kind, ctx) {
|
|
|
329
507
|
'## Agents available in this repo',
|
|
330
508
|
'- `expert` - domain/product requirements (advisory)',
|
|
331
509
|
'- `builder` - fullstack implementation',
|
|
332
|
-
'- `
|
|
510
|
+
'- `tester` - E2E testing',
|
|
333
511
|
].join('\n');
|
|
334
512
|
}
|
|
335
513
|
}
|
|
@@ -365,7 +543,7 @@ const REQUIREMENTS_INTERVIEW = [
|
|
|
365
543
|
'Then summarize the requirements back to the user as a short structured list and get an explicit yes before any building starts.',
|
|
366
544
|
].join('\n');
|
|
367
545
|
server.registerTool('enhance-intent', {
|
|
368
|
-
description: 'Turn a fuzzy "I want to build X" ask into a grounded, consumer-context brief. Uses the platform catalog (live module
|
|
546
|
+
description: 'Turn a fuzzy "I want to build X" ask into a grounded, consumer-context brief. Uses the platform catalog (live module and adapter list) to return a classified intent, a requirements checklist to collect from the user, a step-by-step playbook using the consumer pnpm gen commands, and an acceptance-criteria stub.',
|
|
369
547
|
inputSchema: {
|
|
370
548
|
ask: z
|
|
371
549
|
.string()
|
|
@@ -382,7 +560,6 @@ server.registerTool('enhance-intent', {
|
|
|
382
560
|
const ctx = {
|
|
383
561
|
modules: catalog?.modules.map((m) => `${m.group}/${m.id}`) ?? [],
|
|
384
562
|
tokens: catalog?.adapters.map((a) => a.token) ?? [],
|
|
385
|
-
slots: catalog?.uiSlots.map((s) => s.name) ?? [],
|
|
386
563
|
};
|
|
387
564
|
const detected = kind && kind !== 'unsure' ? '' : ' (auto-detected)';
|
|
388
565
|
const text = [
|
|
@@ -422,14 +599,13 @@ server.registerTool('start', {
|
|
|
422
599
|
const tokens = catalog?.adapters.map((a) => a.token) ?? [];
|
|
423
600
|
const role = [
|
|
424
601
|
'## Your role',
|
|
425
|
-
'You are a requirements interviewer and orchestrator, NOT the implementer. Your one human-facing job is to collect thorough requirements from the user. Everything after that - scaffolding, code, tests - you delegate to the agents (`expert`, `builder`, `
|
|
602
|
+
'You are a requirements interviewer and orchestrator, NOT the implementer. Your one human-facing job is to collect thorough requirements from the user. Everything after that - scaffolding, code, tests - you delegate to the agents (`expert`, `builder`, `tester`) via the Task tool. Keep the user out of the loop after requirements are confirmed, except to resolve genuine decisions only they can make.',
|
|
426
603
|
].join('\n');
|
|
427
604
|
if (ask) {
|
|
428
605
|
const resolved = classifyIntent(ask);
|
|
429
606
|
const playbook = buildConsumerPlaybook(resolved, {
|
|
430
607
|
modules,
|
|
431
608
|
tokens,
|
|
432
|
-
slots: catalog?.uiSlots.map((s) => s.name) ?? [],
|
|
433
609
|
});
|
|
434
610
|
return {
|
|
435
611
|
content: [
|
|
@@ -480,7 +656,7 @@ server.registerTool('start', {
|
|
|
480
656
|
'Call `enhance-intent` (ask = the confirmed requirements summary, kind = step 1). Then follow its playbook, which delegates to the agents:',
|
|
481
657
|
'- `expert` formalizes requirements + acceptance criteria (and may surface gaps - if so, ask the user those, then continue).',
|
|
482
658
|
'- `builder` implements (`pnpm gen ...`, code).',
|
|
483
|
-
'- `
|
|
659
|
+
'- `tester` writes/runs the E2E test.',
|
|
484
660
|
'You orchestrate; you do not write feature code yourself.',
|
|
485
661
|
'',
|
|
486
662
|
`Platform modules: ${modules.join(', ') || '(catalog not loaded)'}`,
|
|
@@ -489,6 +665,82 @@ server.registerTool('start', {
|
|
|
489
665
|
],
|
|
490
666
|
};
|
|
491
667
|
});
|
|
668
|
+
let builtGraph = null;
|
|
669
|
+
function localGraph(rebuild) {
|
|
670
|
+
const prebuilt = join(process.cwd(), 'dep-graph.json');
|
|
671
|
+
if (!rebuild && existsSync(prebuilt)) {
|
|
672
|
+
return JSON.parse(readFileSync(prebuilt, 'utf8'));
|
|
673
|
+
}
|
|
674
|
+
if (rebuild || !builtGraph) {
|
|
675
|
+
builtGraph = buildDepGraph(process.cwd());
|
|
676
|
+
}
|
|
677
|
+
return builtGraph;
|
|
678
|
+
}
|
|
679
|
+
function platformGraph() {
|
|
680
|
+
const shipped = join(here, '..', 'docs', 'dep-graph.json');
|
|
681
|
+
return existsSync(shipped) ? JSON.parse(readFileSync(shipped, 'utf8')) : null;
|
|
682
|
+
}
|
|
683
|
+
server.registerTool('impact', {
|
|
684
|
+
description: 'Blast radius of a change: for each repo-relative file, the files that import it (transitively), and for a platform file (packages/core/src/...) the public @openora/* entry points it reaches plus the consumer files importing them. Use before editing a shared file, or to decide what to re-test after a change.',
|
|
685
|
+
inputSchema: {
|
|
686
|
+
files: z
|
|
687
|
+
.array(z.string())
|
|
688
|
+
.min(1)
|
|
689
|
+
.describe('Repo-relative paths, e.g. "apps/web/src/lib/x.ts"'),
|
|
690
|
+
depth: z
|
|
691
|
+
.number()
|
|
692
|
+
.int()
|
|
693
|
+
.min(1)
|
|
694
|
+
.max(10)
|
|
695
|
+
.optional()
|
|
696
|
+
.describe('Import hops to follow (default 4)'),
|
|
697
|
+
rebuild: z
|
|
698
|
+
.boolean()
|
|
699
|
+
.optional()
|
|
700
|
+
.describe('Re-cruise the repo instead of using a cached graph'),
|
|
701
|
+
},
|
|
702
|
+
}, async ({ files, depth = 4, rebuild = false }) => {
|
|
703
|
+
let local;
|
|
704
|
+
try {
|
|
705
|
+
local = localGraph(rebuild);
|
|
706
|
+
}
|
|
707
|
+
catch (error) {
|
|
708
|
+
return {
|
|
709
|
+
content: [{ type: 'text', text: `Could not build the graph: ${String(error)}` }],
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
const platform = platformGraph();
|
|
713
|
+
const list = (items, max = 40) => items.length === 0
|
|
714
|
+
? ' (none)'
|
|
715
|
+
: items
|
|
716
|
+
.slice(0, max)
|
|
717
|
+
.map((i) => ` - ${i}`)
|
|
718
|
+
.join('\n') + (items.length > max ? `\n (+${items.length - max} more)` : '');
|
|
719
|
+
const sections = files.map((file) => {
|
|
720
|
+
const known = (g) => file in g.dependents || file in g.entryPoints || file in g.platform;
|
|
721
|
+
const onPlatform = platform && !known(local) && known(platform);
|
|
722
|
+
const impact = onPlatform
|
|
723
|
+
? impactOf(platform, file, depth, local)
|
|
724
|
+
: impactOf(local, file, depth);
|
|
725
|
+
const lines = [
|
|
726
|
+
`=== ${file} ===`,
|
|
727
|
+
`Importers (${impact.importers.length}):`,
|
|
728
|
+
list(impact.importers),
|
|
729
|
+
];
|
|
730
|
+
if (impact.specifiers.length > 0) {
|
|
731
|
+
lines.push(`Public entry points reached:`, list(impact.specifiers));
|
|
732
|
+
}
|
|
733
|
+
if (onPlatform) {
|
|
734
|
+
lines.push(`Files in this repo importing them:`, list(impact.consumerFiles));
|
|
735
|
+
}
|
|
736
|
+
const imports = local.platform[file];
|
|
737
|
+
if (imports?.length) {
|
|
738
|
+
lines.push(`Platform imports of this file:`, list(imports));
|
|
739
|
+
}
|
|
740
|
+
return lines.join('\n');
|
|
741
|
+
});
|
|
742
|
+
return { content: [{ type: 'text', text: sections.join('\n\n') }] };
|
|
743
|
+
});
|
|
492
744
|
server.registerTool('dev:infra', {
|
|
493
745
|
description: 'Start / stop / status local dev infrastructure via docker compose (postgres on :5432). Call before pnpm db:migrate or pnpm dev when the database is not reachable.',
|
|
494
746
|
inputSchema: {
|