feat: 重构为 Monorepo 架构并实现 HTTP Server
架构变更: - 采用 pnpm workspaces 实现 Monorepo 结构 - 将现有代码迁移到 packages/core - 新增 packages/server HTTP 服务层 Server 功能: - REST API: 会话管理、工具管理、配置管理 - WebSocket: 实时双向通信支持 - SSE: 服务端事件推送 - Hono + Bun 作为运行时 API 端点: - GET/POST /api/sessions - 会话 CRUD - GET/POST /api/sessions/:id/messages - 消息管理 - GET /api/sessions/:id/events - SSE 事件流 - WS /api/ws/:sessionId - WebSocket 连接 - GET/POST /api/tools - 工具管理 - GET/PUT /api/config - 配置管理
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import * as readline from 'readline';
|
||||
import chalk from 'chalk';
|
||||
import type { PermissionContext, PermissionDecision } from './types.js';
|
||||
|
||||
/**
|
||||
* 在终端中提示用户确认权限
|
||||
*/
|
||||
export async function promptPermission(ctx: PermissionContext): Promise<PermissionDecision> {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
console.log('');
|
||||
console.log(chalk.yellow('⚠️ 权限确认'));
|
||||
console.log(chalk.cyan('命令: ') + chalk.white(ctx.command));
|
||||
console.log(chalk.cyan('目录: ') + chalk.gray(ctx.workdir));
|
||||
|
||||
if (ctx.externalPaths && ctx.externalPaths.length > 0) {
|
||||
console.log(chalk.red('⚠️ 此命令访问项目目录外的路径:'));
|
||||
ctx.externalPaths.forEach(p => {
|
||||
console.log(chalk.red(' • ') + chalk.gray(p));
|
||||
});
|
||||
}
|
||||
|
||||
if (ctx.patterns && ctx.patterns.length > 0) {
|
||||
console.log(chalk.gray('匹配模式: ') + ctx.patterns.join(', '));
|
||||
}
|
||||
|
||||
console.log('');
|
||||
console.log(chalk.white('选择操作:'));
|
||||
console.log(chalk.green(' [y] ') + '允许执行');
|
||||
console.log(chalk.green(' [Y] ') + '允许执行,并记住此类命令(本次会话)');
|
||||
console.log(chalk.red(' [n] ') + '拒绝执行');
|
||||
console.log(chalk.red(' [N] ') + '拒绝执行,并记住此类命令(本次会话)');
|
||||
console.log('');
|
||||
|
||||
rl.question(chalk.yellow('请选择 [y/Y/n/N]: '), (answer) => {
|
||||
rl.close();
|
||||
|
||||
const choice = answer.trim();
|
||||
|
||||
switch (choice) {
|
||||
case 'y':
|
||||
resolve({ allow: true, remember: false });
|
||||
break;
|
||||
case 'Y':
|
||||
resolve({ allow: true, remember: true });
|
||||
break;
|
||||
case 'N':
|
||||
resolve({ allow: false, remember: true });
|
||||
break;
|
||||
case 'n':
|
||||
default:
|
||||
resolve({ allow: false, remember: false });
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示权限被拒绝的消息
|
||||
*/
|
||||
export function showPermissionDenied(command: string, reason: string): void {
|
||||
console.log('');
|
||||
console.log(chalk.red('🚫 权限被拒绝'));
|
||||
console.log(chalk.cyan('命令: ') + chalk.white(command));
|
||||
console.log(chalk.cyan('原因: ') + chalk.gray(reason));
|
||||
console.log('');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示权限允许的消息
|
||||
*/
|
||||
export function showPermissionAllowed(command: string): void {
|
||||
console.log(chalk.green('✓ ') + chalk.gray(`执行: ${command}`));
|
||||
}
|
||||
Reference in New Issue
Block a user