@morozinc/opencode-tencentdb-plugin 0.0.0-stage → 0.1.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/LICENSE +661 -0
- package/LICENSE-MIT +24 -0
- package/NOTICE.md +14 -0
- package/README.md +207 -2
- package/dist/gui-experimental.cjs +64 -0
- package/dist/integration.mjs +1986 -0
- package/docs/screenshots/code-indexes.png +0 -0
- package/package.json +61 -4
- package/scripts/prepare-runtime.mjs +298 -0
- package/src/binding.ts +33 -0
- package/src/bmad-artifact-preview.tsx +111 -0
- package/src/embedding-settings.tsx +191 -0
- package/src/gui.tsx +388 -0
- package/src/index.ts +484 -0
- package/src/integration.d.ts +75 -0
- package/src/rpc.ts +195 -0
- package/src/rule-document.ts +44 -0
- package/src/rules-contract.ts +77 -0
- package/src/rules.ts +237 -0
- package/src/runtime.ts +436 -0
- package/vendor/TENCENT-LICENSE +27 -0
- package/vendor/integration/native/config.ts +253 -0
- package/vendor/integration/native/embedding.ts +270 -0
- package/vendor/integration/native/index.ts +265 -0
- package/vendor/integration/project/index.ts +151 -0
- package/vendor/integration/project/knowledge.ts +283 -0
- package/vendor/integration/server.ts +154 -0
- package/vendor/integration/tencentChatRules.ts +84 -0
- package/vendor/integration/tencentGenerationContext.ts +4 -0
- package/vendor/integration/tencentKnowledgeClient.ts +512 -0
- package/vendor/integration/tencentMemoryClient.ts +391 -0
- package/vendor/integration/tencentUserQuestion.ts +51 -0
- package/vendor/locks/MemoryCore.json +4776 -0
- package/vendor/locks/MemoryKnowledge.json +3761 -0
- package/vendor/locks/MemoryPanel.json +467 -0
- package/vendor/locks/web.json +6418 -0
- package/vendor/provenance.json +21 -0
- package/vendor/runner.mjs +12 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
/** Optional Tencent Agent Wiki and local code graph tools. Service credentials never reach model inputs. */
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { realpathSync, statSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { binding } from "../../src/binding";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { memoryScope, type MemoryConfig } from "./tencentMemoryClient";
|
|
9
|
+
import { resolveTencentGenerationContext } from "./tencentGenerationContext";
|
|
10
|
+
|
|
11
|
+
export type KnowledgeConfig = {
|
|
12
|
+
nativeKnowledgeProjectsDir?: string;
|
|
13
|
+
knowledgeUrl?: string;
|
|
14
|
+
knowledgeServiceKey?: string;
|
|
15
|
+
knowledgeWorkspaces?: Array<{ hostPath: string; servicePath: string }>;
|
|
16
|
+
};
|
|
17
|
+
export type KnowledgeDetail = {
|
|
18
|
+
wiki_id?: string;
|
|
19
|
+
code_graph_id?: string;
|
|
20
|
+
team_id: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
repo_name?: string;
|
|
23
|
+
repo_url?: string;
|
|
24
|
+
branch?: string;
|
|
25
|
+
status: string;
|
|
26
|
+
sync_error?: string | null;
|
|
27
|
+
page_count?: number | null;
|
|
28
|
+
stats?: { files: number; nodes: number; edges: number } | null;
|
|
29
|
+
last_sync_at?: string | null;
|
|
30
|
+
};
|
|
31
|
+
type KnowledgeList = { items: KnowledgeDetail[]; total: number };
|
|
32
|
+
export type CodeRuntimeAction = "status" | "allocate" | "deallocate";
|
|
33
|
+
export type CodeRuntimeStatus = {
|
|
34
|
+
code_graph_id: string;
|
|
35
|
+
index_status: string;
|
|
36
|
+
loaded: boolean;
|
|
37
|
+
loading: boolean;
|
|
38
|
+
active_queries: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Resolve symlinks before mapping, so a workspace cannot expose files outside an allowed mount. */
|
|
42
|
+
export function knowledgeRepositoryUrl(
|
|
43
|
+
workspace: string,
|
|
44
|
+
mappings: KnowledgeConfig["knowledgeWorkspaces"],
|
|
45
|
+
): string {
|
|
46
|
+
const canonical = realpathSync(workspace);
|
|
47
|
+
if (!statSync(canonical).isDirectory())
|
|
48
|
+
throw new Error("Code index workspace must be a directory");
|
|
49
|
+
for (const mapping of mappings ?? []) {
|
|
50
|
+
let root: string;
|
|
51
|
+
try {
|
|
52
|
+
root = realpathSync(mapping.hostPath);
|
|
53
|
+
} catch {
|
|
54
|
+
continue;
|
|
55
|
+
} // One disconnected project root must not block other mounted repositories.
|
|
56
|
+
const relative = path.relative(root, canonical);
|
|
57
|
+
if (
|
|
58
|
+
relative === ".." ||
|
|
59
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
60
|
+
path.isAbsolute(relative)
|
|
61
|
+
)
|
|
62
|
+
continue;
|
|
63
|
+
if (!path.posix.isAbsolute(mapping.servicePath))
|
|
64
|
+
throw new Error("Knowledge service workspace must be absolute");
|
|
65
|
+
const url = new URL("file:///");
|
|
66
|
+
url.pathname = path.posix.join(
|
|
67
|
+
mapping.servicePath,
|
|
68
|
+
...relative.split(path.sep),
|
|
69
|
+
);
|
|
70
|
+
return url.href;
|
|
71
|
+
}
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Workspace is not mounted for Knowledge indexing; configure knowledgeWorkspaces and a read-only mount",
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export class TencentKnowledgeClient {
|
|
78
|
+
constructor(private readonly config: MemoryConfig & KnowledgeConfig) {}
|
|
79
|
+
|
|
80
|
+
private ownsCode(info: KnowledgeDetail): boolean {
|
|
81
|
+
const current = binding().project;
|
|
82
|
+
if (!current.project_id || !info.repo_url?.startsWith("file:"))
|
|
83
|
+
return false;
|
|
84
|
+
try {
|
|
85
|
+
const repository = realpathSync(fileURLToPath(info.repo_url));
|
|
86
|
+
return current.roots.some((root) => {
|
|
87
|
+
const relative = path.relative(realpathSync(root), repository);
|
|
88
|
+
return (
|
|
89
|
+
relative !== ".." &&
|
|
90
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
91
|
+
!path.isAbsolute(relative)
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private identity() {
|
|
100
|
+
return {
|
|
101
|
+
team_id: this.config.teamId,
|
|
102
|
+
user_id: this.config.userId,
|
|
103
|
+
agent_id: this.config.agentId,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async call<T>(
|
|
108
|
+
route: string,
|
|
109
|
+
body: Record<string, unknown>,
|
|
110
|
+
write = false,
|
|
111
|
+
): Promise<T> {
|
|
112
|
+
if (!this.config.knowledgeUrl)
|
|
113
|
+
throw new Error("Tencent Knowledge is not configured");
|
|
114
|
+
if (write && !this.config.knowledgeServiceKey)
|
|
115
|
+
throw new Error("Tencent Knowledge service key is not configured");
|
|
116
|
+
const response = await fetch(
|
|
117
|
+
`${this.config.knowledgeUrl.replace(/\/$/, "")}/v3/${route}`,
|
|
118
|
+
{
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
"x-tdai-service-id": this.config.serviceId,
|
|
123
|
+
...(this.config.knowledgeServiceKey
|
|
124
|
+
? { Authorization: `Bearer ${this.config.knowledgeServiceKey}` }
|
|
125
|
+
: {}),
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify(body),
|
|
128
|
+
signal: AbortSignal.timeout(20000),
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
const envelope = (await response.json()) as {
|
|
132
|
+
code: number;
|
|
133
|
+
message?: string;
|
|
134
|
+
data?: T & { isError?: boolean; text?: string };
|
|
135
|
+
};
|
|
136
|
+
if (!response.ok || envelope.code !== 0 || envelope.data?.isError)
|
|
137
|
+
throw new Error(
|
|
138
|
+
envelope.data?.text ||
|
|
139
|
+
envelope.message ||
|
|
140
|
+
`Tencent Knowledge returned HTTP ${response.status}`,
|
|
141
|
+
);
|
|
142
|
+
return envelope.data as T;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private async detail(id: string): Promise<KnowledgeDetail> {
|
|
146
|
+
const wiki = id.startsWith("wiki-");
|
|
147
|
+
if (!wiki && !id.startsWith("cg-"))
|
|
148
|
+
throw new Error("Expected a wiki- or cg- knowledge ID");
|
|
149
|
+
const info = await this.call<KnowledgeDetail>(
|
|
150
|
+
wiki ? "wiki/get" : "code-graph/get",
|
|
151
|
+
{
|
|
152
|
+
[wiki ? "wiki_id" : "code_graph_id"]: id,
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
if (info.team_id !== this.config.teamId)
|
|
156
|
+
throw new Error("Knowledge resource belongs to another team");
|
|
157
|
+
if (!wiki && !this.ownsCode(info))
|
|
158
|
+
throw new Error("Code graph is outside the current project");
|
|
159
|
+
return info;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async catalog(id?: string, kind?: "wiki" | "code", offset = 0, limit = 10) {
|
|
163
|
+
if (id) return this.detail(id);
|
|
164
|
+
const routes =
|
|
165
|
+
kind === "wiki"
|
|
166
|
+
? ["wiki"]
|
|
167
|
+
: kind === "code"
|
|
168
|
+
? ["code-graph"]
|
|
169
|
+
: ["wiki", "code-graph"];
|
|
170
|
+
return Promise.all(
|
|
171
|
+
routes.map(async (route) => {
|
|
172
|
+
const data = await this.call<KnowledgeList>(`${route}/list`, {
|
|
173
|
+
...this.identity(),
|
|
174
|
+
offset: route === "code-graph" ? 0 : offset,
|
|
175
|
+
limit,
|
|
176
|
+
});
|
|
177
|
+
// Do not enumerate graph identifiers from other project roots.
|
|
178
|
+
if (route === "code-graph") {
|
|
179
|
+
const all = [...data.items];
|
|
180
|
+
for (
|
|
181
|
+
let cursor = data.items.length;
|
|
182
|
+
cursor < data.total;
|
|
183
|
+
cursor += 100
|
|
184
|
+
) {
|
|
185
|
+
if (cursor > 10000)
|
|
186
|
+
throw new Error("Code catalog exceeds its inventory budget.");
|
|
187
|
+
const page = await this.call<KnowledgeList>(`${route}/list`, {
|
|
188
|
+
...this.identity(),
|
|
189
|
+
offset: cursor,
|
|
190
|
+
limit: 100,
|
|
191
|
+
});
|
|
192
|
+
if (!page.items.length) throw new Error("Incomplete code catalog.");
|
|
193
|
+
all.push(...page.items);
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
kind: route,
|
|
197
|
+
items: all
|
|
198
|
+
.filter((item) => this.ownsCode(item))
|
|
199
|
+
.slice(offset, offset + limit),
|
|
200
|
+
total: all.filter((item) => this.ownsCode(item)).length,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return { kind: route, items: data.items, total: data.total };
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async query(id: string, tool: string, params: Record<string, unknown>) {
|
|
209
|
+
const info = await this.detail(id);
|
|
210
|
+
if (
|
|
211
|
+
info.status !== "ready" &&
|
|
212
|
+
!(id.startsWith("wiki-") && tool === "read_raw")
|
|
213
|
+
)
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Knowledge ${id} is ${info.status}: ${info.sync_error || "indexing is not complete"}`,
|
|
216
|
+
);
|
|
217
|
+
const data = await this.call<Record<string, unknown> & { text?: string }>(
|
|
218
|
+
"tools/call",
|
|
219
|
+
{
|
|
220
|
+
knowledge_id: id,
|
|
221
|
+
tool_name: tool,
|
|
222
|
+
params,
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
if (!id.startsWith("cg-")) return data;
|
|
226
|
+
// Upstream explore reads its service-side snapshot, not the user's live working tree.
|
|
227
|
+
if (typeof data.text === "string")
|
|
228
|
+
data.text = data.text.replace(
|
|
229
|
+
/^> The code below is the \*\*verbatim, current on-disk source\*\*[^\n]*/m,
|
|
230
|
+
"> The code below is from the Knowledge index snapshot. It may differ from the current workspace; refresh the index after source changes.",
|
|
231
|
+
);
|
|
232
|
+
return {
|
|
233
|
+
knowledge_id: id,
|
|
234
|
+
indexed_at: info.last_sync_at ?? null,
|
|
235
|
+
source: "workspace snapshot at last successful sync",
|
|
236
|
+
...data,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async runtime(
|
|
241
|
+
id: string,
|
|
242
|
+
action: CodeRuntimeAction,
|
|
243
|
+
): Promise<CodeRuntimeStatus> {
|
|
244
|
+
if (!id.startsWith("cg-")) throw new Error("Expected a code graph ID");
|
|
245
|
+
await this.detail(id);
|
|
246
|
+
return this.call(
|
|
247
|
+
"code-graph/runtime",
|
|
248
|
+
{ ...this.identity(), code_graph_id: id, action },
|
|
249
|
+
true,
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async ingest(input: {
|
|
254
|
+
wiki_id?: string;
|
|
255
|
+
name?: string;
|
|
256
|
+
files: Array<{ filename: string; content: string }>;
|
|
257
|
+
}) {
|
|
258
|
+
const llmContext = await resolveTencentGenerationContext();
|
|
259
|
+
const wiki = input.wiki_id
|
|
260
|
+
? await this.detail(input.wiki_id)
|
|
261
|
+
: await this.call<KnowledgeDetail>(
|
|
262
|
+
"wiki/create",
|
|
263
|
+
{
|
|
264
|
+
...this.identity(),
|
|
265
|
+
name: input.name || `project-${memoryScope()}`,
|
|
266
|
+
},
|
|
267
|
+
true,
|
|
268
|
+
);
|
|
269
|
+
await this.call(
|
|
270
|
+
"wiki/raw/write",
|
|
271
|
+
{ ...this.identity(), wiki_id: wiki.wiki_id, files: input.files },
|
|
272
|
+
true,
|
|
273
|
+
);
|
|
274
|
+
const job = await this.call(
|
|
275
|
+
"wiki/ingest",
|
|
276
|
+
{
|
|
277
|
+
wiki_id: wiki.wiki_id,
|
|
278
|
+
user_id: this.config.userId,
|
|
279
|
+
llm_context: llmContext,
|
|
280
|
+
},
|
|
281
|
+
true,
|
|
282
|
+
);
|
|
283
|
+
return {
|
|
284
|
+
wiki_id: wiki.wiki_id,
|
|
285
|
+
accepted: true,
|
|
286
|
+
generation_model: llmContext.model,
|
|
287
|
+
job,
|
|
288
|
+
next: "Check tdai_knowledge_catalog with knowledge_id; ingest is asynchronous.",
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async index(workspace = process.env.AIONUI_TDAI_MEMORY_WORKSPACE) {
|
|
293
|
+
if (!workspace) throw new Error("Workspace is missing");
|
|
294
|
+
const repoUrl = knowledgeRepositoryUrl(
|
|
295
|
+
workspace,
|
|
296
|
+
this.config.knowledgeWorkspaces,
|
|
297
|
+
);
|
|
298
|
+
const graph = await this.call<KnowledgeDetail>(
|
|
299
|
+
"code-graph/create",
|
|
300
|
+
{
|
|
301
|
+
...this.identity(),
|
|
302
|
+
repo_url: repoUrl,
|
|
303
|
+
repo_name: memoryScope(workspace),
|
|
304
|
+
branch: "local",
|
|
305
|
+
},
|
|
306
|
+
true,
|
|
307
|
+
);
|
|
308
|
+
const job =
|
|
309
|
+
graph.status === "pending" || graph.status === "processing"
|
|
310
|
+
? {
|
|
311
|
+
code_graph_id: graph.code_graph_id,
|
|
312
|
+
status: graph.status,
|
|
313
|
+
already_processing: true,
|
|
314
|
+
}
|
|
315
|
+
: await this.call(
|
|
316
|
+
"code-graph/sync",
|
|
317
|
+
{
|
|
318
|
+
code_graph_id: graph.code_graph_id,
|
|
319
|
+
user_id: this.config.userId,
|
|
320
|
+
},
|
|
321
|
+
true,
|
|
322
|
+
);
|
|
323
|
+
return {
|
|
324
|
+
code_graph_id: graph.code_graph_id,
|
|
325
|
+
accepted: true,
|
|
326
|
+
job,
|
|
327
|
+
next: "Check tdai_knowledge_catalog with knowledge_id; indexing is asynchronous and includes local uncommitted source.",
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function result(value: unknown) {
|
|
333
|
+
const serialized = JSON.stringify(value);
|
|
334
|
+
const text =
|
|
335
|
+
serialized.length > 20000
|
|
336
|
+
? JSON.stringify({
|
|
337
|
+
truncated: true,
|
|
338
|
+
excerpt: serialized.slice(0, 20000),
|
|
339
|
+
next: "Narrow the query or request fewer page references.",
|
|
340
|
+
})
|
|
341
|
+
: serialized;
|
|
342
|
+
return { content: [{ type: "text" as const, text }] };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function registerTencentKnowledgeTools(
|
|
346
|
+
server: McpServer,
|
|
347
|
+
config: MemoryConfig & KnowledgeConfig,
|
|
348
|
+
): void {
|
|
349
|
+
if (!config.knowledgeUrl) return;
|
|
350
|
+
const client = new TencentKnowledgeClient(config);
|
|
351
|
+
const wikiId = z.string().regex(/^wiki-[a-zA-Z0-9_-]+$/);
|
|
352
|
+
const graphId = z.string().regex(/^cg-[a-zA-Z0-9_-]+$/);
|
|
353
|
+
const querySchema = z.string().min(1).max(2048);
|
|
354
|
+
server.tool(
|
|
355
|
+
"tdai_knowledge_catalog",
|
|
356
|
+
"List Agent Wikis and code indexes, or inspect one resource status/error. Wait for ready before querying; accepted ingest/index is not completion.",
|
|
357
|
+
{
|
|
358
|
+
knowledge_id: z
|
|
359
|
+
.string()
|
|
360
|
+
.regex(/^(wiki|cg)-[a-zA-Z0-9_-]+$/)
|
|
361
|
+
.optional(),
|
|
362
|
+
kind: z.enum(["wiki", "code"]).optional(),
|
|
363
|
+
offset: z.number().int().min(0).optional(),
|
|
364
|
+
limit: z.number().int().min(1).max(20).optional(),
|
|
365
|
+
},
|
|
366
|
+
async ({ knowledge_id, kind, offset, limit }) =>
|
|
367
|
+
result(await client.catalog(knowledge_id, kind, offset, limit)),
|
|
368
|
+
);
|
|
369
|
+
server.tool(
|
|
370
|
+
"tdai_wiki_ingest",
|
|
371
|
+
"Upload verified Markdown/text sources and start Wiki synthesis with this chat’s selected model. To create a Wiki, provide name and omit wiki_id. Use wiki_id only for an existing ID returned by the catalog. Keep BMAD artifacts in tdai_scenario_write; do not upload secrets.",
|
|
372
|
+
{
|
|
373
|
+
wiki_id: wikiId
|
|
374
|
+
.optional()
|
|
375
|
+
.describe(
|
|
376
|
+
"Existing Wiki ID from the catalog. Omit when creating; never invent an ID.",
|
|
377
|
+
),
|
|
378
|
+
name: z.string().min(1).max(200).optional(),
|
|
379
|
+
files: z
|
|
380
|
+
.array(
|
|
381
|
+
z.object({
|
|
382
|
+
filename: z
|
|
383
|
+
.string()
|
|
384
|
+
.min(1)
|
|
385
|
+
.max(200)
|
|
386
|
+
.regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/),
|
|
387
|
+
content: z.string().min(1).max(100000),
|
|
388
|
+
}),
|
|
389
|
+
)
|
|
390
|
+
.min(1)
|
|
391
|
+
.max(5),
|
|
392
|
+
},
|
|
393
|
+
async (input) =>
|
|
394
|
+
result(
|
|
395
|
+
await client.ingest({
|
|
396
|
+
...input,
|
|
397
|
+
files: input.files.map((file) => ({
|
|
398
|
+
filename: file.filename,
|
|
399
|
+
content: file.content,
|
|
400
|
+
})),
|
|
401
|
+
}),
|
|
402
|
+
),
|
|
403
|
+
);
|
|
404
|
+
server.tool(
|
|
405
|
+
"tdai_wiki_search",
|
|
406
|
+
"Search ready Agent Wiki pages. Returns references for tdai_wiki_read.",
|
|
407
|
+
{
|
|
408
|
+
wiki_id: wikiId,
|
|
409
|
+
query: querySchema,
|
|
410
|
+
limit: z.number().int().min(1).max(10).optional(),
|
|
411
|
+
},
|
|
412
|
+
async ({ wiki_id, query, limit }) =>
|
|
413
|
+
result(
|
|
414
|
+
await client.query(wiki_id, "search", { query, limit: limit ?? 5 }),
|
|
415
|
+
),
|
|
416
|
+
);
|
|
417
|
+
server.tool(
|
|
418
|
+
"tdai_wiki_read",
|
|
419
|
+
"Read synthesized Wiki pages by search references, or original uploaded files with source=raw and refs=filenames. Raw sources remain readable if synthesis fails.",
|
|
420
|
+
{
|
|
421
|
+
wiki_id: wikiId,
|
|
422
|
+
refs: z.array(z.string().min(1).max(500)).min(1).max(5),
|
|
423
|
+
source: z.enum(["page", "raw"]).optional(),
|
|
424
|
+
},
|
|
425
|
+
async ({ wiki_id, refs, source }) =>
|
|
426
|
+
result(
|
|
427
|
+
await client.query(
|
|
428
|
+
wiki_id,
|
|
429
|
+
source === "raw" ? "read_raw" : "read_page",
|
|
430
|
+
source === "raw" ? { filenames: refs } : { refs },
|
|
431
|
+
),
|
|
432
|
+
),
|
|
433
|
+
);
|
|
434
|
+
server.tool(
|
|
435
|
+
"tdai_code_index",
|
|
436
|
+
"Create or refresh one Git workspace code index, including uncommitted files. Prefer tdai_project_index for product folders or multiple repositories. Only configured read-only Knowledge mounts are allowed. Returns an asynchronous job; check catalog status.",
|
|
437
|
+
{
|
|
438
|
+
workspace: z.string().min(1).optional(),
|
|
439
|
+
},
|
|
440
|
+
async ({ workspace }) => {
|
|
441
|
+
const { ProjectKnowledge } = await import("./project/knowledge");
|
|
442
|
+
const { resolveProjectContext } = await import("./project");
|
|
443
|
+
const context = await resolveProjectContext();
|
|
444
|
+
if (!context.project_id)
|
|
445
|
+
throw new Error("Code indexing requires a project.");
|
|
446
|
+
return result(
|
|
447
|
+
await new ProjectKnowledge(config).index(context, workspace),
|
|
448
|
+
);
|
|
449
|
+
},
|
|
450
|
+
);
|
|
451
|
+
server.tool(
|
|
452
|
+
"tdai_code_search",
|
|
453
|
+
"Find indexed symbols and their file locations. Index again after source changes to refresh the snapshot.",
|
|
454
|
+
{
|
|
455
|
+
code_graph_id: graphId,
|
|
456
|
+
query: querySchema,
|
|
457
|
+
kind: z
|
|
458
|
+
.enum([
|
|
459
|
+
"function",
|
|
460
|
+
"method",
|
|
461
|
+
"class",
|
|
462
|
+
"interface",
|
|
463
|
+
"type",
|
|
464
|
+
"variable",
|
|
465
|
+
"route",
|
|
466
|
+
"component",
|
|
467
|
+
])
|
|
468
|
+
.optional(),
|
|
469
|
+
limit: z.number().int().min(1).max(20).optional(),
|
|
470
|
+
},
|
|
471
|
+
async ({ code_graph_id, query, kind, limit }) =>
|
|
472
|
+
result(
|
|
473
|
+
await client.query(code_graph_id, "search", {
|
|
474
|
+
query,
|
|
475
|
+
kind,
|
|
476
|
+
limit: limit ?? 8,
|
|
477
|
+
}),
|
|
478
|
+
),
|
|
479
|
+
);
|
|
480
|
+
server.tool(
|
|
481
|
+
"tdai_code_explore",
|
|
482
|
+
"Read indexed source related to symbols/files or a code question. Returned source comes from the last index snapshot.",
|
|
483
|
+
{
|
|
484
|
+
code_graph_id: graphId,
|
|
485
|
+
query: querySchema,
|
|
486
|
+
max_files: z.number().int().min(1).max(5).optional(),
|
|
487
|
+
},
|
|
488
|
+
async ({ code_graph_id, query, max_files }) =>
|
|
489
|
+
result(
|
|
490
|
+
await client.query(code_graph_id, "explore", {
|
|
491
|
+
query,
|
|
492
|
+
maxFiles: max_files ?? 3,
|
|
493
|
+
}),
|
|
494
|
+
),
|
|
495
|
+
);
|
|
496
|
+
server.tool(
|
|
497
|
+
"tdai_code_impact",
|
|
498
|
+
"Inspect indexed dependencies affected by changing a symbol.",
|
|
499
|
+
{
|
|
500
|
+
code_graph_id: graphId,
|
|
501
|
+
symbol: querySchema,
|
|
502
|
+
depth: z.number().int().min(1).max(5).optional(),
|
|
503
|
+
},
|
|
504
|
+
async ({ code_graph_id, symbol, depth }) =>
|
|
505
|
+
result(
|
|
506
|
+
await client.query(code_graph_id, "impact", {
|
|
507
|
+
symbol,
|
|
508
|
+
depth: depth ?? 2,
|
|
509
|
+
}),
|
|
510
|
+
),
|
|
511
|
+
);
|
|
512
|
+
}
|