dsh-project-flow-explainer 0.0.0-stage → 0.6.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/README.md +201 -2
- package/client.js +273 -0
- package/cordis.patch.yml +26 -0
- package/index.js +546 -0
- package/lib/command.js +160 -0
- package/lib/core-runner.js +170 -0
- package/lib/paths.js +235 -0
- package/lib/tools.js +1022 -0
- package/lib/validate.js +158 -0
- package/package.json +71 -4
package/lib/tools.js
ADDED
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge tools: index, search, context pack, impact analysis, verify, refresh.
|
|
3
|
+
*
|
|
4
|
+
* Shared rules for every tool in this file:
|
|
5
|
+
* - repository_path must be an absolute path inside allowedRoots (deny-by-default);
|
|
6
|
+
* - the core is reached through `tools/pfe_cli.py`, one JSON object on stdout;
|
|
7
|
+
* - results carry repository-relative paths, symbols and line ranges only —
|
|
8
|
+
* never raw source text, never an absolute workstation path;
|
|
9
|
+
* - a failure is an InputError with the core's stable code, so the runtime
|
|
10
|
+
* keeps the code instead of flattening it into prose.
|
|
11
|
+
*/
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import { runCli } from './core-runner.js'
|
|
14
|
+
import { InputError, resolveRepository } from './paths.js'
|
|
15
|
+
import {
|
|
16
|
+
assertObject, booleanFlag, enumValue, filtersObject, integerInRange,
|
|
17
|
+
optionalString, rejectUnknownKeys, requiredString, stringArray,
|
|
18
|
+
} from './validate.js'
|
|
19
|
+
|
|
20
|
+
const TEXT = (value) => [{ type: 'text', text: value }]
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One description shape for every tool, so the model can choose without
|
|
24
|
+
* reading the source. Keep each line short: the model pays for every token.
|
|
25
|
+
*/
|
|
26
|
+
function describe({ what, use, notUse, prereq, output, next, limits }) {
|
|
27
|
+
// Six lines: what / when (+when not) / prerequisite / output meaning / next
|
|
28
|
+
// action / limits. The model pays for this on every step, so each line stays
|
|
29
|
+
// one clause — but dropping a line costs a wrong tool choice, which is more
|
|
30
|
+
// expensive than the tokens. See README "Chi phí prompt".
|
|
31
|
+
return [
|
|
32
|
+
what,
|
|
33
|
+
`DÙNG KHI: ${use} · KHÔNG DÙNG KHI: ${notUse}`,
|
|
34
|
+
`ĐIỀU KIỆN: ${prereq}`,
|
|
35
|
+
`KẾT QUẢ: ${output}`,
|
|
36
|
+
`TIẾP THEO: ${next}`,
|
|
37
|
+
`GIỚI HẠN: ${limits}`,
|
|
38
|
+
].join('\n')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function abortError(reason) {
|
|
42
|
+
const error = new Error(reason instanceof Error ? reason.message : 'tool call aborted')
|
|
43
|
+
error.name = 'AbortError'
|
|
44
|
+
return error
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function parsePayload(run) {
|
|
48
|
+
const line = run.stdout.trim().split('\n').filter(Boolean).pop() ?? ''
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(line)
|
|
51
|
+
} catch {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Run one CLI subcommand and return the parsed payload.
|
|
58
|
+
* Cancellation keeps its AbortError identity; timeout and core failure keep
|
|
59
|
+
* separate codes so a caller can tell them apart.
|
|
60
|
+
*/
|
|
61
|
+
async function invoke(ctx) {
|
|
62
|
+
const { settings, core, argv, exec, toolName, timeoutMs, inFlight } = ctx
|
|
63
|
+
if (exec?.signal?.aborted) throw abortError(exec.signal.reason)
|
|
64
|
+
if (!core.cli) {
|
|
65
|
+
throw new InputError('core_cli_not_found',
|
|
66
|
+
`${toolName}: bản core này không có tools/pfe_cli.py.`,
|
|
67
|
+
'Cài bundle đã pack (có vendor/core) hoặc đặt config.coreRoot trỏ tới checkout của repo.')
|
|
68
|
+
}
|
|
69
|
+
const controller = new AbortController()
|
|
70
|
+
const forward = () => controller.abort(exec.signal.reason)
|
|
71
|
+
if (exec?.signal) exec.signal.addEventListener('abort', forward, { once: true })
|
|
72
|
+
// Registered with the plugin so dispose() aborts this run too, not only the
|
|
73
|
+
// flow tool's. Without this, unload leaves a child process running.
|
|
74
|
+
inFlight?.add(controller)
|
|
75
|
+
let run
|
|
76
|
+
try {
|
|
77
|
+
run = await runCli({
|
|
78
|
+
pythonPath: settings.pythonPath,
|
|
79
|
+
coreRoot: core.root,
|
|
80
|
+
script: core.cli,
|
|
81
|
+
args: argv,
|
|
82
|
+
signal: controller.signal,
|
|
83
|
+
timeoutMs: timeoutMs ?? settings.timeoutMs,
|
|
84
|
+
maxOutputBytes: settings.maxOutputBytes,
|
|
85
|
+
})
|
|
86
|
+
} finally {
|
|
87
|
+
inFlight?.delete(controller)
|
|
88
|
+
if (exec?.signal) exec.signal.removeEventListener('abort', forward)
|
|
89
|
+
}
|
|
90
|
+
if (run.aborted) throw abortError(exec?.signal?.reason)
|
|
91
|
+
if (run.timedOut) {
|
|
92
|
+
throw new InputError('core_timeout',
|
|
93
|
+
`${toolName}: core vượt quá ${timeoutMs ?? settings.timeoutMs} ms và đã bị dừng.`,
|
|
94
|
+
'Tăng config.timeoutMs hoặc thu hẹp phạm vi phân tích.')
|
|
95
|
+
}
|
|
96
|
+
const payload = parsePayload(run)
|
|
97
|
+
if (payload === null) {
|
|
98
|
+
const tail = run.stderr.trim().split('\n').slice(-2).join(' ').slice(0, 400)
|
|
99
|
+
throw new InputError(run.code === null ? 'core_spawn_failed' : 'core_failed',
|
|
100
|
+
`${toolName}: core không trả JSON hợp lệ. ${tail}`,
|
|
101
|
+
'Chạy lại CLI với --json để xem lỗi gốc.')
|
|
102
|
+
}
|
|
103
|
+
if (payload.status === 'error') {
|
|
104
|
+
throw new InputError(payload.code, payload.message, payload.hint)
|
|
105
|
+
}
|
|
106
|
+
if (run.code !== 0) {
|
|
107
|
+
throw new InputError('core_failed',
|
|
108
|
+
`${toolName}: core exit ${run.code}.`,
|
|
109
|
+
'Xem log của core để biết chi tiết.')
|
|
110
|
+
}
|
|
111
|
+
return payload
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const repoProp = {
|
|
115
|
+
type: 'string',
|
|
116
|
+
description: 'Đường dẫn tuyệt đối tới thư mục repository, phải nằm trong allowedRoots.',
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const refSchema = {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
path: { type: 'string' },
|
|
123
|
+
start_line: { type: 'integer' },
|
|
124
|
+
relation: { type: 'array', items: { type: 'string' } },
|
|
125
|
+
confidence: { type: 'string' },
|
|
126
|
+
},
|
|
127
|
+
required: ['path', 'start_line', 'relation', 'confidence'],
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function knowledgeTools({ settings, core, inFlight }) {
|
|
132
|
+
const repository = (args, toolName) => {
|
|
133
|
+
const value = requiredString(args, 'repository_path', toolName)
|
|
134
|
+
return resolveRepository(value, { allowedRoots: settings.allowedRoots })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return [
|
|
138
|
+
{
|
|
139
|
+
name: 'project_code_index',
|
|
140
|
+
description: describe({
|
|
141
|
+
what: 'Xây/cập nhật index cục bộ tại <repo>/.pfe/index/ (maintenance).',
|
|
142
|
+
use: 'lần đầu vào repo, hoặc sau khi pull/đổi nhiều file.',
|
|
143
|
+
notUse: 'chỉ cần đọc một file đã biết đường dẫn.',
|
|
144
|
+
prereq: 'repository_path tuyệt đối trong allowedRoots.',
|
|
145
|
+
output: 'số file/symbol/route/test đã index; không trả source.',
|
|
146
|
+
next: 'project_context_pack (hoặc project_code_search nếu biết tên).',
|
|
147
|
+
limits: 'phân tích tĩnh, không chạy code; vector mặc định tắt.',
|
|
148
|
+
}),
|
|
149
|
+
parameters: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
properties: {
|
|
152
|
+
repository_path: repoProp,
|
|
153
|
+
mode: { type: 'string', enum: ['full', 'incremental'] },
|
|
154
|
+
include_vectors: { type: 'boolean' },
|
|
155
|
+
},
|
|
156
|
+
required: ['repository_path'],
|
|
157
|
+
additionalProperties: false,
|
|
158
|
+
},
|
|
159
|
+
output: {
|
|
160
|
+
schema: {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
index_id: { type: 'string' },
|
|
164
|
+
index_version: { type: 'integer' },
|
|
165
|
+
source_commit: { type: 'string' },
|
|
166
|
+
mode: { type: 'string' },
|
|
167
|
+
files_indexed: { type: 'integer' },
|
|
168
|
+
files_parsed: { type: 'integer' },
|
|
169
|
+
files_reused: { type: 'integer' },
|
|
170
|
+
symbols_indexed: { type: 'integer' },
|
|
171
|
+
routes_indexed: { type: 'integer' },
|
|
172
|
+
tests_indexed: { type: 'integer' },
|
|
173
|
+
entities: { type: 'integer' },
|
|
174
|
+
facts: { type: 'integer' },
|
|
175
|
+
stale_files: { type: 'integer' },
|
|
176
|
+
embedding: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
enabled: { type: 'boolean' },
|
|
180
|
+
model: { type: 'string' },
|
|
181
|
+
version: { type: 'string' },
|
|
182
|
+
reason: { type: 'string' },
|
|
183
|
+
},
|
|
184
|
+
required: ['enabled'],
|
|
185
|
+
additionalProperties: false,
|
|
186
|
+
},
|
|
187
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
188
|
+
changed: { type: 'array', items: { type: 'string' } },
|
|
189
|
+
added: { type: 'array', items: { type: 'string' } },
|
|
190
|
+
deleted: { type: 'array', items: { type: 'string' } },
|
|
191
|
+
renamed: {
|
|
192
|
+
type: 'array',
|
|
193
|
+
items: {
|
|
194
|
+
type: 'object',
|
|
195
|
+
properties: { from: { type: 'string' }, to: { type: 'string' } },
|
|
196
|
+
required: ['from', 'to'],
|
|
197
|
+
additionalProperties: false,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
required: ['index_id', 'index_version', 'source_commit', 'mode', 'files_indexed',
|
|
202
|
+
'files_parsed', 'files_reused', 'symbols_indexed', 'routes_indexed',
|
|
203
|
+
'tests_indexed', 'entities', 'facts', 'stale_files', 'embedding', 'warnings'],
|
|
204
|
+
additionalProperties: false,
|
|
205
|
+
},
|
|
206
|
+
render(_args, value) {
|
|
207
|
+
const embedding = value.embedding?.enabled
|
|
208
|
+
? `vector: ${value.embedding.model} v${value.embedding.version}`
|
|
209
|
+
: `vector: tắt (${value.embedding?.reason ?? 'không bật'})`
|
|
210
|
+
return TEXT([
|
|
211
|
+
`Index ${value.mode}: ${value.files_indexed} file · ${value.entities} entity · ${value.facts} fact`,
|
|
212
|
+
`Parse lại: ${value.files_parsed} · dùng lại cache: ${value.files_reused}`,
|
|
213
|
+
`Symbol: ${value.symbols_indexed} · route: ${value.routes_indexed} · test: ${value.tests_indexed}`,
|
|
214
|
+
`Commit nguồn: ${value.source_commit || 'không có git'} · stale: ${value.stale_files}`,
|
|
215
|
+
`Tiếp theo: project_context_pack (gom context trước khi sửa).`,
|
|
216
|
+
embedding,
|
|
217
|
+
value.warnings.length > 0 ? `Cảnh báo: ${value.warnings.length}` : 'Không có cảnh báo.',
|
|
218
|
+
].join('\n'))
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
timeoutMs: settings.timeoutMs,
|
|
222
|
+
isConcurrencySafe: () => false,
|
|
223
|
+
async execute(args, exec) {
|
|
224
|
+
assertObject(args, 'project_code_index')
|
|
225
|
+
rejectUnknownKeys(args, ['repository_path', 'mode', 'include_vectors'], 'project_code_index')
|
|
226
|
+
const { root } = repository(args, 'project_code_index')
|
|
227
|
+
const mode = enumValue(args, 'mode', 'project_code_index',
|
|
228
|
+
['full', 'incremental'], 'incremental')
|
|
229
|
+
const includeVectors = booleanFlag(args, 'include_vectors', 'project_code_index', false)
|
|
230
|
+
const argv = ['index', '--repo', root, '--mode', mode]
|
|
231
|
+
if (includeVectors) argv.push('--include-vectors')
|
|
232
|
+
const payload = await invoke({ settings, core, inFlight, argv, exec, toolName: 'project_code_index' })
|
|
233
|
+
return {
|
|
234
|
+
index_id: payload.index_id ?? '',
|
|
235
|
+
index_version: payload.index_version ?? 0,
|
|
236
|
+
source_commit: payload.source_commit ?? '',
|
|
237
|
+
mode: payload.mode ?? mode,
|
|
238
|
+
files_indexed: payload.files_indexed ?? 0,
|
|
239
|
+
files_parsed: payload.files_parsed ?? 0,
|
|
240
|
+
files_reused: payload.files_reused ?? 0,
|
|
241
|
+
symbols_indexed: payload.symbols_indexed ?? 0,
|
|
242
|
+
routes_indexed: payload.routes_indexed ?? 0,
|
|
243
|
+
tests_indexed: payload.tests_indexed ?? 0,
|
|
244
|
+
entities: payload.entities ?? 0,
|
|
245
|
+
facts: payload.facts ?? 0,
|
|
246
|
+
stale_files: payload.stale_files ?? 0,
|
|
247
|
+
embedding: payload.embedding?.enabled
|
|
248
|
+
? {
|
|
249
|
+
enabled: true,
|
|
250
|
+
model: String(payload.embedding.model ?? ''),
|
|
251
|
+
version: String(payload.embedding.version ?? ''),
|
|
252
|
+
}
|
|
253
|
+
: { enabled: false, reason: String(payload.embedding?.reason ?? 'không bật') },
|
|
254
|
+
warnings: payload.warnings ?? [],
|
|
255
|
+
changed: payload.changed ?? [],
|
|
256
|
+
added: payload.added ?? [],
|
|
257
|
+
deleted: payload.deleted ?? [],
|
|
258
|
+
renamed: payload.renamed ?? [],
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
{
|
|
264
|
+
name: 'project_code_search',
|
|
265
|
+
description: describe({
|
|
266
|
+
what: 'Tìm context: exact (FTS5) + graph + vector tùy chọn (maintenance).',
|
|
267
|
+
use: 'biết tên hàm/lớp/route/từ khoá ngắn.',
|
|
268
|
+
notUse: 'câu mô tả nghiệp vụ dài (dùng project_context_pack).',
|
|
269
|
+
prereq: 'đã chạy project_code_index (nếu chưa: mã index_missing).',
|
|
270
|
+
output: 'path, symbol, line range, relation, confidence, lý do khớp; không trả source.',
|
|
271
|
+
next: 'mở đúng path:line, hoặc project_context_pack để gom theo task.',
|
|
272
|
+
limits: 'khớp theo từ khoá; vector (nếu bật) chỉ là candidate lexical, không phải semantic.',
|
|
273
|
+
}),
|
|
274
|
+
parameters: {
|
|
275
|
+
type: 'object',
|
|
276
|
+
properties: {
|
|
277
|
+
repository_path: repoProp,
|
|
278
|
+
query: { type: 'string' },
|
|
279
|
+
top_k: { type: 'integer', minimum: 1, maximum: 50 },
|
|
280
|
+
filters: {
|
|
281
|
+
type: 'object',
|
|
282
|
+
properties: {
|
|
283
|
+
language: { type: 'string' },
|
|
284
|
+
kind: { type: 'string' },
|
|
285
|
+
flow_id: { type: 'string' },
|
|
286
|
+
},
|
|
287
|
+
additionalProperties: false,
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
required: ['repository_path', 'query'],
|
|
291
|
+
additionalProperties: false,
|
|
292
|
+
},
|
|
293
|
+
output: {
|
|
294
|
+
schema: {
|
|
295
|
+
type: 'object',
|
|
296
|
+
properties: {
|
|
297
|
+
query: { type: 'string' },
|
|
298
|
+
intent: { type: 'string' },
|
|
299
|
+
source_commit: { type: 'string' },
|
|
300
|
+
stale: { type: 'boolean' },
|
|
301
|
+
channels: { type: 'array', items: { type: 'string' } },
|
|
302
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
303
|
+
results: {
|
|
304
|
+
type: 'array',
|
|
305
|
+
items: {
|
|
306
|
+
type: 'object',
|
|
307
|
+
properties: {
|
|
308
|
+
entity: { type: 'string' },
|
|
309
|
+
kind: { type: 'string' },
|
|
310
|
+
path: { type: 'string' },
|
|
311
|
+
symbol: { type: 'string' },
|
|
312
|
+
start_line: { type: 'integer' },
|
|
313
|
+
end_line: { type: 'integer' },
|
|
314
|
+
relation: { type: 'array', items: { type: 'string' } },
|
|
315
|
+
confidence: { type: 'string' },
|
|
316
|
+
reason: { type: 'string' },
|
|
317
|
+
score: { type: 'number' },
|
|
318
|
+
why_matched: { type: 'string' },
|
|
319
|
+
evidence_refs: { type: 'array', items: refSchema },
|
|
320
|
+
},
|
|
321
|
+
required: ['entity', 'kind', 'path', 'symbol', 'start_line', 'end_line',
|
|
322
|
+
'relation', 'confidence', 'reason', 'score', 'why_matched', 'evidence_refs'],
|
|
323
|
+
additionalProperties: false,
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
required: ['query', 'intent', 'source_commit', 'stale', 'channels', 'warnings', 'results'],
|
|
328
|
+
additionalProperties: false,
|
|
329
|
+
},
|
|
330
|
+
render(_args, value) {
|
|
331
|
+
const lines = [
|
|
332
|
+
`Truy hồi “${value.query}” · kênh: ${value.channels.join(', ') || 'không có'}`,
|
|
333
|
+
`Kết quả: ${value.results.length}${value.stale ? ' · CẢNH BÁO: index cũ hơn HEAD' : ''}`,
|
|
334
|
+
]
|
|
335
|
+
for (const item of value.results.slice(0, 8)) {
|
|
336
|
+
lines.push(`- [${item.kind}] ${item.symbol || item.entity} — ${item.path}:${item.start_line}`
|
|
337
|
+
+ ` (${item.confidence}) · ${item.why_matched}`)
|
|
338
|
+
}
|
|
339
|
+
if (!value.results.length) lines.push('Không có kết quả: thử project_context_pack với mô tả nghiệp vụ.')
|
|
340
|
+
else lines.push('Tiếp theo: mở path:line ở trên; cần gom theo task thì project_context_pack.')
|
|
341
|
+
if (value.warnings.length > 0) lines.push(`Cảnh báo: ${value.warnings.join('; ')}`)
|
|
342
|
+
return TEXT(lines.join('\n'))
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
timeoutMs: settings.timeoutMs,
|
|
346
|
+
isConcurrencySafe: () => true,
|
|
347
|
+
async execute(args, exec) {
|
|
348
|
+
assertObject(args, 'project_code_search')
|
|
349
|
+
rejectUnknownKeys(args, ['repository_path', 'query', 'top_k', 'filters'], 'project_code_search')
|
|
350
|
+
const { root } = repository(args, 'project_code_search')
|
|
351
|
+
const query = requiredString(args, 'query', 'project_code_search')
|
|
352
|
+
const topK = integerInRange(args, 'top_k', 'project_code_search',
|
|
353
|
+
{ min: 1, max: 50, fallback: 10 })
|
|
354
|
+
const filters = filtersObject(args, 'project_code_search')
|
|
355
|
+
const argv = ['search', '--repo', root, '--query', query, '--top-k', String(topK)]
|
|
356
|
+
if (filters.language) argv.push('--language', filters.language)
|
|
357
|
+
if (filters.kind) argv.push('--kind', filters.kind)
|
|
358
|
+
const payload = await invoke({ settings, core, inFlight, argv, exec, toolName: 'project_code_search' })
|
|
359
|
+
return {
|
|
360
|
+
query: payload.query ?? query,
|
|
361
|
+
intent: payload.intent ?? 'locate',
|
|
362
|
+
source_commit: payload.source_commit ?? '',
|
|
363
|
+
stale: Boolean(payload.stale),
|
|
364
|
+
channels: payload.channels ?? [],
|
|
365
|
+
warnings: payload.warnings ?? [],
|
|
366
|
+
results: (payload.results ?? []).map((item) => ({
|
|
367
|
+
entity: item.entity,
|
|
368
|
+
kind: item.kind,
|
|
369
|
+
path: item.path ?? '',
|
|
370
|
+
symbol: item.symbol ?? '',
|
|
371
|
+
start_line: item.start_line ?? 1,
|
|
372
|
+
end_line: item.end_line ?? item.start_line ?? 1,
|
|
373
|
+
relation: item.relation ?? [],
|
|
374
|
+
confidence: item.confidence ?? 'inferred',
|
|
375
|
+
reason: item.reason ?? item.why_matched ?? '',
|
|
376
|
+
score: Number(item.score ?? 0),
|
|
377
|
+
why_matched: item.why_matched ?? '',
|
|
378
|
+
evidence_refs: (item.evidence_refs ?? []).map((ref) => ({
|
|
379
|
+
path: ref.path ?? '',
|
|
380
|
+
start_line: ref.start_line ?? 1,
|
|
381
|
+
relation: ref.relation ?? [],
|
|
382
|
+
confidence: ref.confidence ?? 'inferred',
|
|
383
|
+
})),
|
|
384
|
+
})),
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
|
|
389
|
+
{
|
|
390
|
+
name: 'project_context_pack',
|
|
391
|
+
description: describe({
|
|
392
|
+
what: 'Gom context trước khi sửa: entry point, file nên đọc, dependency, test.',
|
|
393
|
+
use: 'MẶC ĐỊNH trước khi sửa code — tool đầu tiên nên gọi.',
|
|
394
|
+
notUse: 'chỉ cần kiểm artifact đã sinh (dùng project_verify_flow).',
|
|
395
|
+
prereq: 'đã chạy project_code_index.',
|
|
396
|
+
output: 'entry_points theo loại (http_route/cli_command/gui_event/callback/button_click/'
|
|
397
|
+
+ 'worker/main/public_api), likely_files, dependencies có path+line, related_tests.',
|
|
398
|
+
next: 'sửa file trong likely_files, rồi project_impact_analysis.',
|
|
399
|
+
limits: 'entry point chỉ từ dòng đăng ký thật; chưa chạy test; không trả source.',
|
|
400
|
+
}),
|
|
401
|
+
parameters: {
|
|
402
|
+
type: 'object',
|
|
403
|
+
properties: {
|
|
404
|
+
repository_path: repoProp,
|
|
405
|
+
task: { type: 'string' },
|
|
406
|
+
include_snippets: { type: 'boolean' },
|
|
407
|
+
max_files: { type: 'integer', minimum: 1, maximum: 40 },
|
|
408
|
+
},
|
|
409
|
+
required: ['repository_path', 'task'],
|
|
410
|
+
additionalProperties: false,
|
|
411
|
+
},
|
|
412
|
+
output: {
|
|
413
|
+
schema: {
|
|
414
|
+
type: 'object',
|
|
415
|
+
properties: {
|
|
416
|
+
task: { type: 'string' },
|
|
417
|
+
analysis_kind: { type: 'string' },
|
|
418
|
+
intent: { type: 'string' },
|
|
419
|
+
source_commit: { type: 'string' },
|
|
420
|
+
stale: { type: 'boolean' },
|
|
421
|
+
max_files: { type: 'integer' },
|
|
422
|
+
snippets_included: { type: 'boolean' },
|
|
423
|
+
limitations: { type: 'array', items: { type: 'string' } },
|
|
424
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
425
|
+
not_verified: { type: 'array', items: { type: 'string' } },
|
|
426
|
+
seen: {
|
|
427
|
+
type: 'object',
|
|
428
|
+
properties: {
|
|
429
|
+
paths: { type: 'integer' },
|
|
430
|
+
entities: { type: 'integer' },
|
|
431
|
+
evidence: { type: 'integer' },
|
|
432
|
+
},
|
|
433
|
+
required: ['paths', 'entities', 'evidence'],
|
|
434
|
+
additionalProperties: false,
|
|
435
|
+
},
|
|
436
|
+
relevant_flows: {
|
|
437
|
+
type: 'array',
|
|
438
|
+
items: {
|
|
439
|
+
type: 'object',
|
|
440
|
+
properties: { flow_id: { type: 'string' }, title: { type: 'string' } },
|
|
441
|
+
required: ['flow_id', 'title'],
|
|
442
|
+
additionalProperties: false,
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
entry_points: {
|
|
446
|
+
type: 'array',
|
|
447
|
+
items: {
|
|
448
|
+
type: 'object',
|
|
449
|
+
properties: {
|
|
450
|
+
path: { type: 'string' },
|
|
451
|
+
kind: { type: 'string' },
|
|
452
|
+
label: { type: 'string' },
|
|
453
|
+
route: { type: 'string' },
|
|
454
|
+
start_line: { type: 'integer' },
|
|
455
|
+
confidence: { type: 'string' },
|
|
456
|
+
evidence_kind: { type: 'string' },
|
|
457
|
+
evidence_refs: { type: 'array', items: refSchema },
|
|
458
|
+
},
|
|
459
|
+
required: ['path', 'kind', 'label', 'route', 'start_line', 'confidence',
|
|
460
|
+
'evidence_kind', 'evidence_refs'],
|
|
461
|
+
additionalProperties: false,
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
routes: {
|
|
465
|
+
type: 'array',
|
|
466
|
+
items: {
|
|
467
|
+
type: 'object',
|
|
468
|
+
properties: {
|
|
469
|
+
route: { type: 'string' },
|
|
470
|
+
path: { type: 'string' },
|
|
471
|
+
start_line: { type: 'integer' },
|
|
472
|
+
confidence: { type: 'string' },
|
|
473
|
+
via: { type: 'string' },
|
|
474
|
+
evidence_refs: { type: 'array', items: refSchema },
|
|
475
|
+
},
|
|
476
|
+
required: ['route', 'path', 'start_line', 'confidence', 'via', 'evidence_refs'],
|
|
477
|
+
additionalProperties: false,
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
impacted_symbols: {
|
|
481
|
+
type: 'array',
|
|
482
|
+
items: {
|
|
483
|
+
type: 'object',
|
|
484
|
+
properties: {
|
|
485
|
+
symbol: { type: 'string' },
|
|
486
|
+
path: { type: 'string' },
|
|
487
|
+
start_line: { type: 'integer' },
|
|
488
|
+
kind: { type: 'string' },
|
|
489
|
+
confidence: { type: 'string' },
|
|
490
|
+
},
|
|
491
|
+
required: ['symbol', 'path', 'start_line', 'kind', 'confidence'],
|
|
492
|
+
additionalProperties: false,
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
related_tests: {
|
|
496
|
+
type: 'array',
|
|
497
|
+
items: {
|
|
498
|
+
type: 'object',
|
|
499
|
+
properties: {
|
|
500
|
+
path: { type: 'string' },
|
|
501
|
+
test: { type: 'string' },
|
|
502
|
+
start_line: { type: 'integer' },
|
|
503
|
+
confidence: { type: 'string' },
|
|
504
|
+
why_included: { type: 'string' },
|
|
505
|
+
},
|
|
506
|
+
required: ['path', 'test', 'start_line', 'confidence', 'why_included'],
|
|
507
|
+
additionalProperties: false,
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
likely_files: {
|
|
511
|
+
type: 'array',
|
|
512
|
+
items: {
|
|
513
|
+
type: 'object',
|
|
514
|
+
properties: {
|
|
515
|
+
path: { type: 'string' },
|
|
516
|
+
symbol: { type: 'string' },
|
|
517
|
+
kind: { type: 'string' },
|
|
518
|
+
start_line: { type: 'integer' },
|
|
519
|
+
end_line: { type: 'integer' },
|
|
520
|
+
confidence: { type: 'string' },
|
|
521
|
+
location_confidence: { type: 'string' },
|
|
522
|
+
relevance_confidence: { type: 'string' },
|
|
523
|
+
why_matched: { type: 'string' },
|
|
524
|
+
relevance_why: { type: 'array', items: { type: 'string' } },
|
|
525
|
+
relation: { type: 'array', items: { type: 'string' } },
|
|
526
|
+
evidence_refs: { type: 'array', items: refSchema },
|
|
527
|
+
},
|
|
528
|
+
required: ['path', 'symbol', 'kind', 'start_line', 'end_line', 'confidence',
|
|
529
|
+
'location_confidence', 'relevance_confidence', 'why_matched',
|
|
530
|
+
'relevance_why', 'relation', 'evidence_refs'],
|
|
531
|
+
additionalProperties: false,
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
dependencies: {
|
|
535
|
+
type: 'array',
|
|
536
|
+
items: {
|
|
537
|
+
type: 'object',
|
|
538
|
+
properties: {
|
|
539
|
+
entity: { type: 'string' },
|
|
540
|
+
kind: { type: 'string' },
|
|
541
|
+
path: { type: 'string' },
|
|
542
|
+
symbol: { type: 'string' },
|
|
543
|
+
start_line: { type: 'integer' },
|
|
544
|
+
end_line: { type: 'integer' },
|
|
545
|
+
relation: { type: 'string' },
|
|
546
|
+
confidence: { type: 'string' },
|
|
547
|
+
location_confidence: { type: 'string' },
|
|
548
|
+
relevance_confidence: { type: 'string' },
|
|
549
|
+
why_included: { type: 'string' },
|
|
550
|
+
evidence_refs: { type: 'array', items: refSchema },
|
|
551
|
+
},
|
|
552
|
+
required: ['entity', 'kind', 'path', 'symbol', 'start_line', 'end_line',
|
|
553
|
+
'relation', 'confidence', 'location_confidence', 'relevance_confidence',
|
|
554
|
+
'why_included', 'evidence_refs'],
|
|
555
|
+
additionalProperties: false,
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
external_dependencies: {
|
|
559
|
+
type: 'array',
|
|
560
|
+
items: {
|
|
561
|
+
type: 'object',
|
|
562
|
+
properties: {
|
|
563
|
+
entity: { type: 'string' },
|
|
564
|
+
kind: { type: 'string' },
|
|
565
|
+
symbol: { type: 'string' },
|
|
566
|
+
relation: { type: 'string' },
|
|
567
|
+
confidence: { type: 'string' },
|
|
568
|
+
why_included: { type: 'string' },
|
|
569
|
+
location: { type: 'string' },
|
|
570
|
+
},
|
|
571
|
+
required: ['entity', 'kind', 'symbol', 'relation', 'confidence',
|
|
572
|
+
'why_included', 'location'],
|
|
573
|
+
additionalProperties: false,
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
evidence_refs: { type: 'array', items: refSchema },
|
|
577
|
+
},
|
|
578
|
+
required: ['task', 'analysis_kind', 'intent', 'source_commit', 'stale', 'max_files',
|
|
579
|
+
'snippets_included', 'limitations', 'warnings', 'not_verified', 'seen',
|
|
580
|
+
'relevant_flows', 'entry_points', 'routes', 'impacted_symbols', 'related_tests',
|
|
581
|
+
'likely_files', 'dependencies', 'external_dependencies', 'evidence_refs'],
|
|
582
|
+
additionalProperties: false,
|
|
583
|
+
},
|
|
584
|
+
render(_args, value) {
|
|
585
|
+
const lines = [
|
|
586
|
+
`Context: ${value.task}`,
|
|
587
|
+
`Entry point: ${value.entry_points.length}`
|
|
588
|
+
+ (value.routes.length ? ` · route: ${value.routes[0].route}` : '')
|
|
589
|
+
+ ` · file nên đọc: ${value.likely_files.length}`,
|
|
590
|
+
]
|
|
591
|
+
for (const item of value.likely_files.slice(0, 5)) {
|
|
592
|
+
lines.push(`- ${item.path}:${item.start_line} ${item.symbol} (${item.relevance_confidence})`)
|
|
593
|
+
}
|
|
594
|
+
if (value.related_tests.length) {
|
|
595
|
+
lines.push(`Test liên quan: ${value.related_tests.map((t) => t.path).join(', ')}`)
|
|
596
|
+
}
|
|
597
|
+
if (value.stale) lines.push('CẢNH BÁO: index cũ hơn HEAD — gọi project_knowledge_refresh.')
|
|
598
|
+
for (const limit of value.limitations.slice(0, 2)) lines.push(`Giới hạn: ${limit}`)
|
|
599
|
+
lines.push('Tiếp theo: sửa file trên, rồi project_impact_analysis.')
|
|
600
|
+
return TEXT(lines.join('\n'))
|
|
601
|
+
},
|
|
602
|
+
},
|
|
603
|
+
timeoutMs: settings.timeoutMs,
|
|
604
|
+
isConcurrencySafe: () => true,
|
|
605
|
+
async execute(args, exec) {
|
|
606
|
+
assertObject(args, 'project_context_pack')
|
|
607
|
+
rejectUnknownKeys(args, ['repository_path', 'task', 'max_files', 'include_snippets'], 'project_context_pack')
|
|
608
|
+
const { root } = repository(args, 'project_context_pack')
|
|
609
|
+
const task = requiredString(args, 'task', 'project_context_pack')
|
|
610
|
+
const maxFiles = integerInRange(args, 'max_files', 'project_context_pack',
|
|
611
|
+
{ min: 1, max: 40, fallback: 12 })
|
|
612
|
+
const snippets = booleanFlag(args, 'include_snippets', 'project_context_pack', false)
|
|
613
|
+
const argv = ['context-pack', '--repo', root, '--task', task,
|
|
614
|
+
'--max-files', String(maxFiles)]
|
|
615
|
+
if (snippets) argv.push('--include-snippets')
|
|
616
|
+
const payload = await invoke({ settings, core, inFlight, argv, exec, toolName: 'project_context_pack' })
|
|
617
|
+
return {
|
|
618
|
+
task: payload.task ?? task,
|
|
619
|
+
analysis_kind: payload.analysis_kind ?? 'context_pack',
|
|
620
|
+
intent: payload.intent ?? 'locate',
|
|
621
|
+
source_commit: payload.source_commit ?? '',
|
|
622
|
+
stale: Boolean(payload.stale),
|
|
623
|
+
max_files: payload.max_files ?? maxFiles,
|
|
624
|
+
snippets_included: Boolean(payload.snippets_included),
|
|
625
|
+
limitations: payload.limitations ?? [],
|
|
626
|
+
warnings: payload.warnings ?? [],
|
|
627
|
+
not_verified: payload.not_verified ?? ['runtime', 'ui'],
|
|
628
|
+
seen: payload.seen ?? { paths: 0, entities: 0, evidence: 0 },
|
|
629
|
+
relevant_flows: payload.relevant_flows ?? [],
|
|
630
|
+
entry_points: payload.entry_points ?? [],
|
|
631
|
+
routes: payload.routes ?? [],
|
|
632
|
+
impacted_symbols: payload.impacted_symbols ?? [],
|
|
633
|
+
related_tests: payload.related_tests ?? [],
|
|
634
|
+
likely_files: (payload.likely_files ?? []).map((item) => ({
|
|
635
|
+
path: item.path ?? '',
|
|
636
|
+
symbol: item.symbol ?? '',
|
|
637
|
+
kind: item.kind ?? 'file',
|
|
638
|
+
start_line: item.start_line ?? 1,
|
|
639
|
+
end_line: item.end_line ?? item.start_line ?? 1,
|
|
640
|
+
confidence: item.confidence ?? 'inferred',
|
|
641
|
+
location_confidence: item.location_confidence ?? 'unknown',
|
|
642
|
+
relevance_confidence: item.relevance_confidence ?? 'inferred',
|
|
643
|
+
why_matched: item.why_matched ?? '',
|
|
644
|
+
relevance_why: item.relevance_why ?? [],
|
|
645
|
+
relation: item.relation ?? [],
|
|
646
|
+
evidence_refs: item.evidence_refs ?? [],
|
|
647
|
+
})),
|
|
648
|
+
dependencies: payload.dependencies ?? [],
|
|
649
|
+
external_dependencies: payload.external_dependencies ?? [],
|
|
650
|
+
evidence_refs: payload.evidence_refs ?? [],
|
|
651
|
+
}
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
|
|
655
|
+
{
|
|
656
|
+
name: 'project_impact_analysis',
|
|
657
|
+
description: describe({
|
|
658
|
+
what: 'Phân tích tác động của các file vừa sửa.',
|
|
659
|
+
use: 'SAU KHI sửa, trước khi commit.',
|
|
660
|
+
notUse: 'trước khi sửa (dùng project_context_pack).',
|
|
661
|
+
prereq: 'đã chạy project_code_index; truyền changed_files hoặc diff.',
|
|
662
|
+
output: 'flow/route/symbol bị ảnh hưởng, test liên quan, module phụ thuộc, risk_level.',
|
|
663
|
+
next: 'chạy test trong related_tests, rồi project_verify_flow.',
|
|
664
|
+
limits: 'chỉ thấy quan hệ có trong index; file mới chưa index báo unknown_files.',
|
|
665
|
+
}),
|
|
666
|
+
parameters: {
|
|
667
|
+
type: 'object',
|
|
668
|
+
properties: {
|
|
669
|
+
repository_path: repoProp,
|
|
670
|
+
changed_files: { type: 'array', items: { type: 'string' } },
|
|
671
|
+
diff: { type: 'string' },
|
|
672
|
+
},
|
|
673
|
+
required: ['repository_path'],
|
|
674
|
+
additionalProperties: false,
|
|
675
|
+
},
|
|
676
|
+
output: {
|
|
677
|
+
schema: {
|
|
678
|
+
type: 'object',
|
|
679
|
+
properties: {
|
|
680
|
+
source_commit: { type: 'string' },
|
|
681
|
+
changed_files: { type: 'array', items: { type: 'string' } },
|
|
682
|
+
risk_level: { type: 'string' },
|
|
683
|
+
risk_reasons: { type: 'array', items: { type: 'string' } },
|
|
684
|
+
index_stale: { type: 'boolean' },
|
|
685
|
+
stale_files: { type: 'array', items: { type: 'string' } },
|
|
686
|
+
unknown_files: { type: 'array', items: { type: 'string' } },
|
|
687
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
688
|
+
suggested_verification: { type: 'array', items: { type: 'string' } },
|
|
689
|
+
affected_flows: {
|
|
690
|
+
type: 'array',
|
|
691
|
+
items: {
|
|
692
|
+
type: 'object',
|
|
693
|
+
properties: {
|
|
694
|
+
flow_id: { type: 'string' },
|
|
695
|
+
confidence: { type: 'string' },
|
|
696
|
+
path: { type: 'string' },
|
|
697
|
+
},
|
|
698
|
+
required: ['flow_id', 'confidence', 'path'],
|
|
699
|
+
additionalProperties: false,
|
|
700
|
+
},
|
|
701
|
+
},
|
|
702
|
+
affected_routes: {
|
|
703
|
+
type: 'array',
|
|
704
|
+
items: {
|
|
705
|
+
type: 'object',
|
|
706
|
+
properties: {
|
|
707
|
+
route: { type: 'string' },
|
|
708
|
+
path: { type: 'string' },
|
|
709
|
+
start_line: { type: 'integer' },
|
|
710
|
+
},
|
|
711
|
+
required: ['route', 'path', 'start_line'],
|
|
712
|
+
additionalProperties: false,
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
affected_symbols: {
|
|
716
|
+
type: 'array',
|
|
717
|
+
items: {
|
|
718
|
+
type: 'object',
|
|
719
|
+
properties: {
|
|
720
|
+
symbol: { type: 'string' },
|
|
721
|
+
path: { type: 'string' },
|
|
722
|
+
start_line: { type: 'integer' },
|
|
723
|
+
},
|
|
724
|
+
required: ['symbol', 'path', 'start_line'],
|
|
725
|
+
additionalProperties: false,
|
|
726
|
+
},
|
|
727
|
+
},
|
|
728
|
+
related_tests: {
|
|
729
|
+
type: 'array',
|
|
730
|
+
items: {
|
|
731
|
+
type: 'object',
|
|
732
|
+
properties: { test: { type: 'string' }, path: { type: 'string' } },
|
|
733
|
+
required: ['test', 'path'],
|
|
734
|
+
additionalProperties: false,
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
downstream_modules: {
|
|
738
|
+
type: 'array',
|
|
739
|
+
items: {
|
|
740
|
+
type: 'object',
|
|
741
|
+
properties: {
|
|
742
|
+
file: { type: 'string' },
|
|
743
|
+
relation: { type: 'string' },
|
|
744
|
+
path: { type: 'string' },
|
|
745
|
+
},
|
|
746
|
+
required: ['file', 'relation', 'path'],
|
|
747
|
+
additionalProperties: false,
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
stale_artifacts: {
|
|
751
|
+
type: 'array',
|
|
752
|
+
items: {
|
|
753
|
+
type: 'object',
|
|
754
|
+
properties: {
|
|
755
|
+
flow_id: { type: 'string' },
|
|
756
|
+
generated_at: { type: 'string' },
|
|
757
|
+
artifact_dir: { type: 'string' },
|
|
758
|
+
},
|
|
759
|
+
required: ['flow_id', 'generated_at', 'artifact_dir'],
|
|
760
|
+
additionalProperties: false,
|
|
761
|
+
},
|
|
762
|
+
},
|
|
763
|
+
evidence_refs: { type: 'array', items: refSchema },
|
|
764
|
+
},
|
|
765
|
+
required: ['source_commit', 'changed_files', 'risk_level', 'risk_reasons',
|
|
766
|
+
'index_stale', 'stale_files', 'unknown_files', 'warnings', 'suggested_verification',
|
|
767
|
+
'affected_flows', 'affected_routes', 'affected_symbols', 'related_tests',
|
|
768
|
+
'downstream_modules', 'stale_artifacts', 'evidence_refs'],
|
|
769
|
+
additionalProperties: false,
|
|
770
|
+
},
|
|
771
|
+
render(_args, value) {
|
|
772
|
+
return TEXT([
|
|
773
|
+
`Tác động: ${value.changed_files.length} file · rủi ro ${value.risk_level}`,
|
|
774
|
+
...value.risk_reasons.map((item) => `- ${item}`),
|
|
775
|
+
`Flow: ${value.affected_flows.length} · route: ${value.affected_routes.length} · `
|
|
776
|
+
+ `symbol: ${value.affected_symbols.length} · test: ${value.related_tests.length}`,
|
|
777
|
+
`Kiểm chứng: ${value.suggested_verification.join(' · ')}`,
|
|
778
|
+
'Tiếp theo: chạy test ở trên, rồi project_verify_flow.',
|
|
779
|
+
].join('\n'))
|
|
780
|
+
},
|
|
781
|
+
},
|
|
782
|
+
timeoutMs: settings.timeoutMs,
|
|
783
|
+
isConcurrencySafe: () => true,
|
|
784
|
+
async execute(args, exec) {
|
|
785
|
+
assertObject(args, 'project_impact_analysis')
|
|
786
|
+
rejectUnknownKeys(args, ['repository_path', 'changed_files', 'diff'], 'project_impact_analysis')
|
|
787
|
+
const { root } = repository(args, 'project_impact_analysis')
|
|
788
|
+
const changed = stringArray(args, 'changed_files', 'project_impact_analysis')
|
|
789
|
+
const diff = optionalString(args, 'diff', 'project_impact_analysis')
|
|
790
|
+
if (changed.length === 0 && (diff === undefined || diff.trim() === '')) {
|
|
791
|
+
throw new InputError('no_changed_files',
|
|
792
|
+
'project_impact_analysis: cần changed_files hoặc diff.',
|
|
793
|
+
'Truyền changed_files: ["src/app.py"] hoặc một unified diff.')
|
|
794
|
+
}
|
|
795
|
+
const argv = ['impact', '--repo', root]
|
|
796
|
+
for (const item of changed) argv.push('--changed', item)
|
|
797
|
+
if (diff) argv.push('--diff', diff)
|
|
798
|
+
const payload = await invoke({ settings, core, inFlight, argv, exec, toolName: 'project_impact_analysis' })
|
|
799
|
+
return {
|
|
800
|
+
source_commit: payload.source_commit ?? '',
|
|
801
|
+
changed_files: payload.changed_files ?? changed,
|
|
802
|
+
risk_level: payload.risk_level ?? 'low',
|
|
803
|
+
risk_reasons: payload.risk_reasons ?? [],
|
|
804
|
+
index_stale: Boolean(payload.index_stale),
|
|
805
|
+
stale_files: payload.stale_files ?? [],
|
|
806
|
+
unknown_files: payload.unknown_files ?? [],
|
|
807
|
+
warnings: payload.warnings ?? [],
|
|
808
|
+
suggested_verification: payload.suggested_verification ?? [],
|
|
809
|
+
affected_flows: payload.affected_flows ?? [],
|
|
810
|
+
affected_routes: payload.affected_routes ?? [],
|
|
811
|
+
affected_symbols: payload.affected_symbols ?? [],
|
|
812
|
+
related_tests: payload.related_tests ?? [],
|
|
813
|
+
downstream_modules: payload.downstream_modules ?? [],
|
|
814
|
+
stale_artifacts: payload.stale_artifacts ?? [],
|
|
815
|
+
evidence_refs: payload.evidence_refs ?? [],
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
|
|
820
|
+
{
|
|
821
|
+
name: 'project_verify_flow',
|
|
822
|
+
description: describe({
|
|
823
|
+
what: 'Kiểm artifact/flow: schema, bằng chứng, HTML tĩnh, privacy, test mapping.',
|
|
824
|
+
use: 'bước cuối, sau khi sửa và render lại flow.',
|
|
825
|
+
notUse: 'thay cho việc chạy test hoặc mở trình duyệt.',
|
|
826
|
+
prereq: 'đã có artifact trong <repo>/artifacts/flows/.',
|
|
827
|
+
output: 'static_verdict (đã kiểm tĩnh) tách khỏi overall_verdict (cần cả UI + runtime), '
|
|
828
|
+
+ 'gates, checks, next_action.',
|
|
829
|
+
next: 'overall=partial thì mở flow.html và chạy test liên quan; không đọc là "đã pass".',
|
|
830
|
+
limits: 'quét HTML tĩnh KHÔNG phải kiểm trình duyệt; test mapping KHÔNG phải đã chạy test.',
|
|
831
|
+
}),
|
|
832
|
+
parameters: {
|
|
833
|
+
type: 'object',
|
|
834
|
+
properties: { repository_path: repoProp },
|
|
835
|
+
required: ['repository_path'],
|
|
836
|
+
additionalProperties: false,
|
|
837
|
+
},
|
|
838
|
+
output: {
|
|
839
|
+
schema: {
|
|
840
|
+
type: 'object',
|
|
841
|
+
properties: {
|
|
842
|
+
verdict: { type: 'string' },
|
|
843
|
+
static_verdict: { type: 'string' },
|
|
844
|
+
overall_verdict: { type: 'string' },
|
|
845
|
+
source_commit: { type: 'string' },
|
|
846
|
+
flow_artifacts: { type: 'integer' },
|
|
847
|
+
ui_verified: { type: 'boolean' },
|
|
848
|
+
runtime_verified: { type: 'boolean' },
|
|
849
|
+
notes: { type: 'array', items: { type: 'string' } },
|
|
850
|
+
not_verified: { type: 'array', items: { type: 'string' } },
|
|
851
|
+
next_action: { type: 'string' },
|
|
852
|
+
gates: {
|
|
853
|
+
type: 'object',
|
|
854
|
+
properties: {
|
|
855
|
+
static: { type: 'string' },
|
|
856
|
+
ui: { type: 'string' },
|
|
857
|
+
runtime: { type: 'string' },
|
|
858
|
+
},
|
|
859
|
+
required: ['static', 'ui', 'runtime'],
|
|
860
|
+
additionalProperties: false,
|
|
861
|
+
},
|
|
862
|
+
checks: {
|
|
863
|
+
type: 'array',
|
|
864
|
+
items: {
|
|
865
|
+
type: 'object',
|
|
866
|
+
properties: {
|
|
867
|
+
check: { type: 'string' },
|
|
868
|
+
status: { type: 'string' },
|
|
869
|
+
detail: { type: 'string' },
|
|
870
|
+
evidence: { type: 'array', items: { type: 'string' } },
|
|
871
|
+
},
|
|
872
|
+
required: ['check', 'status', 'detail', 'evidence'],
|
|
873
|
+
additionalProperties: false,
|
|
874
|
+
},
|
|
875
|
+
},
|
|
876
|
+
},
|
|
877
|
+
required: ['verdict', 'static_verdict', 'overall_verdict', 'source_commit',
|
|
878
|
+
'flow_artifacts', 'ui_verified', 'runtime_verified', 'notes', 'not_verified',
|
|
879
|
+
'next_action', 'gates', 'checks'],
|
|
880
|
+
additionalProperties: false,
|
|
881
|
+
},
|
|
882
|
+
render(_args, value) {
|
|
883
|
+
// The two verdicts mean different things and a reader who conflates
|
|
884
|
+
// them thinks the page was rendered and the tests were run. Say which
|
|
885
|
+
// is which, then which checks did run.
|
|
886
|
+
const STATIC_PLAIN = 'chỉ đọc file, chưa mở trang'
|
|
887
|
+
const lines = [
|
|
888
|
+
`Kiểm tĩnh: ${value.static_verdict} (${STATIC_PLAIN})`,
|
|
889
|
+
`Kết luận tổng: ${value.overall_verdict}`
|
|
890
|
+
+ (value.overall_verdict === 'partial'
|
|
891
|
+
? ' — chưa đủ bằng chứng để coi là đã pass' : ''),
|
|
892
|
+
`Artifact: ${value.flow_artifacts} flow · gate chưa chạy: `
|
|
893
|
+
+ `${value.not_verified.join(', ') || 'không có'}`,
|
|
894
|
+
]
|
|
895
|
+
const failed = value.checks.filter((c) => c.status === 'fail')
|
|
896
|
+
for (const check of failed.slice(0, 3)) lines.push(`- FAIL ${check.check}: ${check.detail}`)
|
|
897
|
+
if (!failed.length) {
|
|
898
|
+
const blocked = value.checks.filter((c) => c.status === 'blocked')
|
|
899
|
+
if (blocked.length) lines.push(`Check chưa chạy: ${blocked.map((c) => c.check).join(', ')}`)
|
|
900
|
+
}
|
|
901
|
+
lines.push(`Tiếp theo: ${value.next_action}`)
|
|
902
|
+
return TEXT(lines.join('\n'))
|
|
903
|
+
},
|
|
904
|
+
},
|
|
905
|
+
timeoutMs: settings.timeoutMs,
|
|
906
|
+
isConcurrencySafe: () => true,
|
|
907
|
+
async execute(args, exec) {
|
|
908
|
+
assertObject(args, 'project_verify_flow')
|
|
909
|
+
rejectUnknownKeys(args, ['repository_path'], 'project_verify_flow')
|
|
910
|
+
const { root } = repository(args, 'project_verify_flow')
|
|
911
|
+
const payload = await invoke({
|
|
912
|
+
settings, core, argv: ['verify', '--repo', root], exec,
|
|
913
|
+
toolName: 'project_verify_flow',
|
|
914
|
+
})
|
|
915
|
+
return {
|
|
916
|
+
verdict: payload.overall_verdict ?? payload.verdict ?? 'partial',
|
|
917
|
+
static_verdict: payload.static_verdict ?? 'partial',
|
|
918
|
+
overall_verdict: payload.overall_verdict ?? 'partial',
|
|
919
|
+
source_commit: payload.source_commit ?? '',
|
|
920
|
+
flow_artifacts: payload.flow_artifacts ?? 0,
|
|
921
|
+
ui_verified: Boolean(payload.ui_verified),
|
|
922
|
+
runtime_verified: Boolean(payload.runtime_verified),
|
|
923
|
+
notes: payload.notes ?? [],
|
|
924
|
+
not_verified: payload.not_verified ?? ['ui', 'runtime'],
|
|
925
|
+
next_action: payload.next_action ?? '',
|
|
926
|
+
gates: payload.gates ?? { static: 'partial', ui: 'blocked', runtime: 'blocked' },
|
|
927
|
+
checks: payload.checks ?? [],
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
},
|
|
931
|
+
|
|
932
|
+
{
|
|
933
|
+
name: 'project_knowledge_refresh',
|
|
934
|
+
description: describe({
|
|
935
|
+
what: 'Refresh index tăng dần sau khi sửa code (maintenance).',
|
|
936
|
+
use: 'sau khi sửa file, trước khi search/impact lần nữa.',
|
|
937
|
+
notUse: 'khi index chưa tồn tại (dùng project_code_index mode=full).',
|
|
938
|
+
prereq: 'index đã tồn tại.',
|
|
939
|
+
output: 'file parse lại/dùng lại, changed/added/deleted/renamed, stale.',
|
|
940
|
+
next: 'project_code_search hoặc project_impact_analysis.',
|
|
941
|
+
limits: 'rename nhận qua content hash; không rebuild toàn bộ nếu không cần.',
|
|
942
|
+
}),
|
|
943
|
+
parameters: {
|
|
944
|
+
type: 'object',
|
|
945
|
+
properties: {
|
|
946
|
+
repository_path: repoProp,
|
|
947
|
+
mode: { type: 'string', enum: ['full', 'incremental'] },
|
|
948
|
+
include_vectors: { type: 'boolean' },
|
|
949
|
+
},
|
|
950
|
+
required: ['repository_path'],
|
|
951
|
+
additionalProperties: false,
|
|
952
|
+
},
|
|
953
|
+
output: {
|
|
954
|
+
schema: {
|
|
955
|
+
type: 'object',
|
|
956
|
+
properties: {
|
|
957
|
+
mode: { type: 'string' },
|
|
958
|
+
files_parsed: { type: 'integer' },
|
|
959
|
+
files_reused: { type: 'integer' },
|
|
960
|
+
stale_files: { type: 'integer' },
|
|
961
|
+
no_full_rebuild: { type: 'boolean' },
|
|
962
|
+
changed: { type: 'array', items: { type: 'string' } },
|
|
963
|
+
added: { type: 'array', items: { type: 'string' } },
|
|
964
|
+
deleted: { type: 'array', items: { type: 'string' } },
|
|
965
|
+
renamed: {
|
|
966
|
+
type: 'array',
|
|
967
|
+
items: {
|
|
968
|
+
type: 'object',
|
|
969
|
+
properties: { from: { type: 'string' }, to: { type: 'string' } },
|
|
970
|
+
required: ['from', 'to'],
|
|
971
|
+
additionalProperties: false,
|
|
972
|
+
},
|
|
973
|
+
},
|
|
974
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
975
|
+
},
|
|
976
|
+
required: ['mode', 'files_parsed', 'files_reused', 'stale_files',
|
|
977
|
+
'no_full_rebuild', 'changed', 'added', 'deleted', 'renamed', 'warnings'],
|
|
978
|
+
additionalProperties: false,
|
|
979
|
+
},
|
|
980
|
+
render(_args, value) {
|
|
981
|
+
return TEXT([
|
|
982
|
+
`Refresh ${value.mode}: parse lại ${value.files_parsed} · dùng lại ${value.files_reused}`,
|
|
983
|
+
`changed ${value.changed.length} · added ${value.added.length} · `
|
|
984
|
+
+ `deleted ${value.deleted.length} · renamed ${value.renamed.length}`,
|
|
985
|
+
`Rebuild toàn bộ: ${value.no_full_rebuild ? 'không' : 'có'}`,
|
|
986
|
+
'Tiếp theo: project_code_search hoặc project_impact_analysis.',
|
|
987
|
+
].join('\n'))
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
timeoutMs: settings.timeoutMs,
|
|
991
|
+
isConcurrencySafe: () => false,
|
|
992
|
+
async execute(args, exec) {
|
|
993
|
+
assertObject(args, 'project_knowledge_refresh')
|
|
994
|
+
rejectUnknownKeys(args, ['repository_path', 'mode', 'include_vectors'], 'project_knowledge_refresh')
|
|
995
|
+
const { root } = repository(args, 'project_knowledge_refresh')
|
|
996
|
+
const mode = enumValue(args, 'mode', 'project_knowledge_refresh',
|
|
997
|
+
['full', 'incremental'], 'incremental')
|
|
998
|
+
const includeVectors = booleanFlag(args, 'include_vectors',
|
|
999
|
+
'project_knowledge_refresh', false)
|
|
1000
|
+
const argv = ['refresh', '--repo', root, '--mode', mode]
|
|
1001
|
+
if (includeVectors) argv.push('--include-vectors')
|
|
1002
|
+
const payload = await invoke({
|
|
1003
|
+
settings, core, inFlight, argv, exec, toolName: 'project_knowledge_refresh',
|
|
1004
|
+
})
|
|
1005
|
+
return {
|
|
1006
|
+
mode: payload.mode ?? mode,
|
|
1007
|
+
files_parsed: payload.files_parsed ?? 0,
|
|
1008
|
+
files_reused: payload.files_reused ?? 0,
|
|
1009
|
+
stale_files: payload.stale_files ?? 0,
|
|
1010
|
+
no_full_rebuild: Boolean(payload.no_full_rebuild),
|
|
1011
|
+
changed: payload.changed ?? [],
|
|
1012
|
+
added: payload.added ?? [],
|
|
1013
|
+
deleted: payload.deleted ?? [],
|
|
1014
|
+
renamed: payload.renamed ?? [],
|
|
1015
|
+
warnings: payload.warnings ?? [],
|
|
1016
|
+
}
|
|
1017
|
+
},
|
|
1018
|
+
},
|
|
1019
|
+
]
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
export { InputError, path }
|