feat: enhance AI commands and logging system
- Update @kevisual/query to 0.0.32 and @kevisual/router to 0.0.37 - Restructure AI command interface with run and deploy subcommands - Add comprehensive logging throughout cmd-execution flow - Improve sync module with better configuration handling - Add clickable link functionality in logger - Enhance error handling and debugging capabilities 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { App } from '@kevisual/app/src/app.ts';
|
||||
import { storage } from '../module/query.ts';
|
||||
|
||||
export const app = new App({ token: storage.getItem('token') || '' });
|
||||
export const app = new App({ token: storage.getItem('token') || '', storage });
|
||||
@@ -1,11 +1,12 @@
|
||||
import { app } from '../ai.ts';
|
||||
import { execSync } from 'node:child_process'
|
||||
import { logger } from '@/module/logger.ts';
|
||||
const promptTemplate = `# CMD 结果判断器
|
||||
|
||||
分析上一条 CMD 命令的执行结果,判断是否需要执行下一条命令。
|
||||
|
||||
- 若结果中隐含或明确指示需继续执行 → 返回:\`{"cmd": "推断出的下一条命令", "type": "cmd"}\`
|
||||
- 若无后续操作 → 返回:\`{"type": "none"}\`
|
||||
- 若无后续操作,甚至上一次执行的返回为空或者成功 → 返回:\`{"type": "none"}\`
|
||||
|
||||
1. 仅输出合法 JSON,无任何额外文本。
|
||||
2. \`cmd\` 必须从执行结果中合理推断得出,非预设或猜测。
|
||||
@@ -23,8 +24,10 @@ app.router.route({
|
||||
ctx.state.steps = ctx.state?.steps || [];
|
||||
|
||||
try {
|
||||
logger.info('执行命令:', cmd);
|
||||
result = execSync(cmd, { encoding: 'utf-8' });
|
||||
ctx.state.steps.push({ cmd, result });
|
||||
logger.info(result);
|
||||
} catch (error: any) {
|
||||
result = error.message || '';
|
||||
ctx.state.steps.push({ cmd, result, error: true });
|
||||
@@ -33,19 +36,24 @@ app.router.route({
|
||||
}
|
||||
return;
|
||||
}
|
||||
await app.loadAI()
|
||||
const prompt = `${promptTemplate}\n上一条命令:\n${cmd}\n执行结果:\n${result}\n`;
|
||||
const response = await app.ai.question(prompt);
|
||||
|
||||
const msg = app.ai.utils.extractJsonFromMarkdown(app.ai.responseText);
|
||||
try {
|
||||
logger.debug('AI Prompt', prompt);
|
||||
logger.debug('AI 分析结果:', msg);
|
||||
const { cmd, type } = msg;
|
||||
if (type === 'cmd' && cmd) {
|
||||
await app.router.call({ path: 'cmd-run', payload: { cmd } }, { state: ctx.state });
|
||||
} else {
|
||||
logger.info('无后续命令,结束执行');
|
||||
ctx.state.steps.push({ type: 'none' });
|
||||
}
|
||||
} catch (error) {
|
||||
result = '执行错误,无法解析返回结果为合法 JSON' + app.ai.responseText
|
||||
logger.error(result);
|
||||
ctx.state.steps.push({ cmd, result, parseError: true });
|
||||
}
|
||||
ctx.body = {
|
||||
|
||||
Reference in New Issue
Block a user