diff --git a/README.md b/README.md index a333a1a724d0891e62ee7d1492cc39041dfab182..112e128253ebacb511125e7a3fbf8cb2ef017135 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,351 @@ -# euler-copilot-shell +# openEuler Intelligence Smart Shell -#### 介绍 -CLI and desktop client applications that enables developers to interact with the operating system using natural language. +一个基于 Python Textual 构建的智能终端应用程序,提供 AI 驱动的命令行交互体验。支持多种 LLM 后端,集成 MCP 协议,提供现代化的 TUI 界面。 -#### 软件架构 -软件架构说明 +## 核心特性 +- **多后端支持**: 支持 OpenAI API 大模型和 openEuler Intelligence 后端 +- **智能终端界面**: 基于 Textual 的现代化 TUI 界面 +- **流式响应**: 实时显示 AI 回复内容 +- **部署助手**: 内置 openEuler Intelligence 自动部署功能 -#### 安装教程 +## 安装说明 -1. xxxx -2. xxxx -3. xxxx +### 方式一:从源码安装(推荐开发者) -#### 使用说明 +1. 克隆仓库: -1. xxxx -2. xxxx -3. xxxx + ```sh + git clone https://gitee.com/openeuler/euler-copilot-shell.git -b dev + cd euler-copilot-shell + ``` -#### 参与贡献 +2. 安装依赖(建议使用 Python 虚拟环境): -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request + ```sh + pip install -r requirements.txt + ``` +### 方式二:通过 RPM 包安装 -#### 特技 +注意:*仅适用于 openEuler 24.03 LTS SP2* -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +```sh +sudo dnf install openeuler-intelligence-cli +``` + +安装完成后,可以使用 `oi` 命令启动应用程序。 + +## 使用方法 + +安装 RPM 包后: + +```sh +oi +``` + +查看最新的日志内容: + +```sh +oi --logs +``` + +设置日志级别并验证: + +```sh +oi --log-level INFO +``` + +初始化 openEuler Intelligence 后端(仅支持 openEuler 操作系统): + +```sh +oi --init +``` + +选择和设置默认智能体(仅适用于 openEuler Intelligence 后端): + +```sh +oi --agent +``` + +应用启动后,您可以直接在输入框中输入命令。如果命令无效或无法执行,应用程序将基于您的输入提供智能建议。 + +### 界面操作快捷键 + +- **Ctrl+S**: 打开设置界面 +- **Ctrl+R**: 重置对话历史 +- **Ctrl+T**: 选择智能体 +- **Tab**: 在命令输入框和输出区域之间切换焦点 +- **Esc**: 退出应用程序 + +### MCP 工具交互 + +当使用支持 MCP (Model Context Protocol) 的后端时,应用程序会在需要工具确认或参数输入时: + +1. **工具执行确认**: 显示工具名称、风险级别和执行原因,用户可选择确认或取消 +2. **参数补全**: 动态生成参数输入表单,用户填写必要信息后提交 + +应用程序使用内联交互模式,不会打开模态对话框,确保流畅的用户体验。 + +### --init 命令说明 + +`--init` 命令用于在 openEuler 操作系统上自动安装和配置 openEuler Intelligence 后端,它将执行以下步骤: + +1. **系统检测**: 检测当前操作系统是否为 openEuler +2. **环境检查**: 验证 dnf 包管理器和管理员权限 +3. **包安装**: 通过 dnf 安装 `openeuler-intelligence-installer` RPM 包 +4. **服务部署**: 运行部署脚本完成系统初始化 + +**使用要求**: + +- 仅支持 openEuler 操作系统 +- 需要管理员权限(sudo) +- 需要网络连接以下载 RPM 包 + +**注意**: 此命令会自动安装系统服务,请在生产环境使用前仔细评估。 + +### --agent 命令说明 + +`--agent` 命令用于在命令行中选择和设置默认智能体,它提供了一个 TUI 界面来管理智能体配置: + +1. **智能体列表**: 自动获取并显示所有可用的智能体 +2. **可视化选择**: 通过图形化界面选择要设置为默认的智能体 +3. **配置保存**: 自动将选择保存到配置文件中的 `eulerintelli.default_app` 字段 +4. **即时反馈**: 设置完成后显示确认信息 + +**使用要求**: + +- 必须配置为 openEuler Intelligence 后端 +- 需要有效的服务器连接来获取智能体列表 +- 如果后端不是 openEuler Intelligence,会显示错误提示并引导切换 + +**功能特点**: + +- 包含"智能问答"选项(无智能体)作为默认选择 +- 支持取消操作,不会更改现有配置 +- 自动处理网络错误和异常情况 + +## 配置说明 + +应用程序支持两种后端配置,配置文件会自动保存在 `~/.config/eulerintelli/smart-shell.json`: + +### 后端类型 + +1. **OpenAI 兼容 API** (包括 LM Studio、vLLM、Ollama 等) +2. **openEuler Intelligence** + +### 配置示例 + +首次运行时,可通过设置界面 (Ctrl+S) 配置以下参数: + +**OpenAI 兼容 API 配置:** + +- Base URL: 如 `http://localhost:1234/v1` +- Model: 如 `qwen/qwen3-30b-a3b` +- API Key: 如 `sk-xxxxxx` + +**openEuler Intelligence 配置:** + +- Base URL: 如 `http://your-server:8002` +- API Key: 您的认证令牌 + +### 智能体管理 + +对于 openEuler Intelligence 后端,应用程序支持多智能体切换: + +1. **默认智能问答**: 通用 AI 助手 +2. **专业智能体**: 针对特定领域的专门助手 + +使用 `Ctrl+T` 可以在运行时切换不同的智能体。 + +#### 默认智能体配置 + +应用程序支持配置默认启动的智能体: + +- **默认智能体配置**: 决定应用启动时激活哪个智能体,持久保存 +- **运行时智能体切换**: 在当前会话中临时切换智能体,不影响默认配置 + +##### 方式一:命令行(修改默认配置) + +```sh +oi --agent +``` + +通过图形化界面选择默认智能体,选择会自动保存到配置文件。 + +##### 方式二:手动修改配置文件(不推荐) + +直接编辑配置文件 `~/.config/eulerintelli/smart-shell.json`,修改 `eulerintelli.default_app` 字段的值: + +- 设置为空字符串 `""` 或删除该字段:使用"智能问答"(没有调用工具的能力) +- 设置为有效的智能体ID:使用指定的智能体作为默认 +- 设置为无效的智能体ID:应用启动时会自动清理并回退到"智能问答" + +##### 配置详情 + +- **配置位置**: `~/.config/eulerintelli/smart-shell.json` 中的 `eulerintelli.default_app` 字段 +- **默认行为**: 如果未设置或为空,将默认使用"智能问答"(通用助手) +- **自动应用**: 应用启动时会自动加载配置的默认智能体 +- **自动清理**: 如果配置的智能体ID不存在(如服务器数据更改),会自动清理配置并回退到"智能问答" + +**配置示例**: + +```json +{ + "backend": "eulerintelli", + "eulerintelli": { + "base_url": "http://your-server:8002", + "api_key": "your-api-key", + "default_app": "your-preferred-agent-id" + } +} +``` + +### 日志配置 + +应用程序提供多级日志记录: + +- **DEBUG**: 详细调试信息(默认) +- **INFO**: 基本信息 +- **WARNING**: 警告信息 +- **ERROR**: 仅错误信息 + +## 日志功能 + +应用程序提供完整的日志记录功能: + +- **日志位置**: `~/.cache/openEuler Intelligence/logs/` +- **日志格式**: `smart-shell-YYYYMMDD-HHMMSS.log`(使用本地时区时间) +- **自动清理**: 每次启动时自动删除7天前的旧日志和空日志文件 +- **命令行查看**: 使用 `python src/main.py --logs` 查看最新日志内容 +- **记录内容**: + - 程序启动和退出 + - API请求详情(URL、状态码、耗时等) + - 异常和错误信息 + - 模块级别的操作日志 + +## 系统要求 + +### 基本要求 + +- **Python**: 3.11 或更高版本 +- **操作系统**: openEuler 24.03 LTS 或更高版本 +- **网络**: 访问配置的 LLM API 服务 + +### 依赖包 + +核心依赖: + +- **textual**: 5.3.0 - TUI 界面框架 +- **rich**: 14.1.0 - 富文本渲染 +- **httpx**: 0.28.1 - HTTP 客户端 +- **openai**: 1.99.6 - OpenAI API 客户端 + +开发依赖: + +- **ruff**: *Latest* - 代码检查器 + +### 特殊功能要求 + +**自动部署功能(`--init` 命令)**: + +- 仅支持 openEuler 操作系统 +- 需要管理员权限(sudo) +- 需要 dnf 包管理器 +- 需要网络连接 + +## 在 openEuler 系统下的 RPM 打包 + +以下步骤演示如何在 openEuler 24.03 LTS 或更高版本上,使用自带脚本打包生成 RPM 包。 + +前提条件: + +- 操作系统:openEuler 24.03 LTS 或更高版本 +- 工具依赖:rpmdevtools、git、bash +- 具有管理员权限(sudo) + +构建步骤: + +1. 克隆仓库并切换到对应分支: + + ```sh + git clone https://gitee.com/openeuler/euler-copilot-shell.git -b dev + cd euler-copilot-shell + ``` + +2. 为构建脚本添加可执行权限: + + ```sh + chmod +x scripts/build/create_tarball.sh scripts/build/build_rpm.sh + ``` + +3. 运行 RPM 构建脚本: + + ```sh + ./scripts/build/build_rpm.sh + ``` + + 脚本执行完成后,会在临时构建目录下的 `RPMS` 和 `SRPMS` 子目录中生成相应的二进制包和源码包,并在终端输出具体路径。 + +## 项目结构 + +```text +smart-shell/ +├── README.md # 项目说明文档 +├── requirements.txt # Python 依赖包列表 +├── setup.py # 包安装配置文件 +├── LICENSE # 开源许可证 +├── distribution/ # 发布相关文件 +├── docs/ # 项目文档目录 +│ └── development/ # 开发设计文档 +│ └── server-side/ # 服务端相关文档 +├── scripts/ # 部署脚本目录 +│ └── build/ # RPM 包构建脚本 +│ └── deploy/ # 自动化部署脚本 +├── tests/ # 测试文件目录 +└── src/ # 源代码目录 + ├── main.py # 应用程序入口点 + ├── app/ # TUI 应用模块 + │ ├── tui.py # 主界面应用类 + │ ├── mcp_widgets.py # MCP 交互组件 + │ ├── tui_mcp_handler.py # MCP 事件处理器 + │ ├── settings.py # 设置界面 + │ ├── css/ + │ │ └── styles.tcss # TUI 样式文件 + │ ├── deployment/ # 部署助手模块 + │ │ ├── models.py # 部署配置模型 + │ │ ├── service.py # 部署服务逻辑 + │ │ ├── ui.py # 部署界面组件 + │ │ └── validators.py # 配置验证器 + │ └── dialogs/ # 对话框组件 + │ ├── agent.py # 智能体选择对话框 + │ └── common.py # 通用对话框组件 + ├── backend/ # 后端适配模块 + │ ├── base.py # 后端客户端基类 + │ ├── factory.py # 后端工厂类 + │ ├── mcp_handler.py # MCP 事件处理接口 + │ ├── openai.py # OpenAI 兼容客户端 + │ └── hermes/ # openEuler Intelligence 客户端 + │ ├── client.py # Hermes API 客户端 + │ ├── constants.py # 常量定义 + │ ├── exceptions.py # 异常类定义 + │ ├── models.py # 数据模型 + │ ├── stream.py # 流式响应处理 + │ └── services/ # 服务层组件 + ├── config/ # 配置管理模块 + │ ├── manager.py # 配置管理器 + │ └── model.py # 配置数据模型 + ├── log/ # 日志管理模块 + │ └── manager.py # 日志管理器 + └── tool/ # 工具模块 + ├── command_processor.py # 命令处理器 + └── oi_backend_init.py # 后端初始化工具 +``` + +## 贡献 + +欢迎贡献代码!请随时提交 PR 或开启问题讨论任何功能增强或错误修复建议。 + +## 开源许可 + +本项目采用 MulanPSL-2.0 许可证。详细信息请参见 [LICENSE](LICENSE) 文件。 diff --git a/euler-copilot-shell-0.10.0.tar.gz b/euler-copilot-shell-0.10.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..4a4e027618a1fbab572449091483c881f02f7897 Binary files /dev/null and b/euler-copilot-shell-0.10.0.tar.gz differ diff --git a/euler-copilot-shell-0.9.2.tar.gz b/euler-copilot-shell-0.9.2.tar.gz deleted file mode 100644 index 8df2cc21e7cca72a389dab16e0b669aeb33a735e..0000000000000000000000000000000000000000 Binary files a/euler-copilot-shell-0.9.2.tar.gz and /dev/null differ diff --git a/euler-copilot-shell.spec b/euler-copilot-shell.spec index 3e3c6e2b34b4e604d8fcf2d3deeab11c149ad81d..82859f10725932dffa07b21c3bf895bb087a30b6 100644 --- a/euler-copilot-shell.spec +++ b/euler-copilot-shell.spec @@ -1,50 +1,124 @@ +%global pypi_name oi-cli +%global shortcut_name oi %global debug_package %{nil} Name: euler-copilot-shell -Version: 0.9.2 -Release: 11%{?dist} -Summary: EulerCopilot 命令行助手 +Version: 0.10.0 +Release: 4%{?dist} +Summary: openEuler Intelligence 智能命令行工具集 License: MulanPSL-2.0 -URL: https://www.openeuler.org/zh/ -Group: Applications/Utilities +URL: https://gitee.com/openeuler/euler-copilot-shell Source0: %{name}-%{version}.tar.gz -BuildArch: aarch64 x86_64 riscv64 -BuildRequires: python3-devel python3-setuptools + +ExclusiveArch: x86_64 aarch64 riscv64 loongarch64 + +BuildRequires: python3-devel +BuildRequires: python3-virtualenv BuildRequires: python3-pip -BuildRequires: python3-Cython gcc -Requires: python3 jq hostname %description -EulerCopilot 提供了命令行助手,旨在为 openEuler 提供智能辅助工具。 +openEuler Intelligence 智能命令行工具集,包含智能 Shell 命令行程序和部署安装工具。 + +# 智能命令行工具子包 +%package -n openeuler-intelligence-cli +Summary: openEuler Intelligence 智能 Shell 命令行工具 +Requires: glibc +# 替换原来的 euler-copilot-shell 包 +Obsoletes: euler-copilot-shell < %{version}-%{release} +Provides: euler-copilot-shell = %{version}-%{release} + +%description -n openeuler-intelligence-cli +openEuler Intelligence 智能 Shell 是一个智能命令行程序。 +它允许用户输入命令,通过集成大语言模型提供命令建议,帮助用户更高效地使用命令行。 + +# 部署安装工具子包 +%package -n openeuler-intelligence-installer +Summary: openEuler Intelligence 部署安装脚本 +Requires: python3-aiohttp +Requires: python3-requests +BuildArch: noarch + +%description -n openeuler-intelligence-installer +openEuler Intelligence 部署安装工具包,包含部署脚本和相关资源文件。 %prep -%setup -q -python3 -m venv .venv -.venv/bin/python3 -m pip install -U -i https://mirrors.huaweicloud.com/repository/pypi/simple pip setuptools -.venv/bin/python3 -m pip install -U -i https://mirrors.huaweicloud.com/repository/pypi/simple Cython pyinstaller -.venv/bin/python3 -m pip install -U -i https://mirrors.huaweicloud.com/repository/pypi/simple websockets requests -.venv/bin/python3 -m pip install -U -i https://mirrors.huaweicloud.com/repository/pypi/simple rich typer questionary +%autosetup -n %{name}-%{version} %build -.venv/bin/python3 setup.py build_ext -.venv/bin/pyinstaller --onefile --clean \ - --distpath=%{_builddir}/%{name}-%{version}/dist \ - --workpath=%{_builddir}/%{name}-%{version}/build \ - copilot.py +# 创建虚拟环境 +python3 -m venv %{_builddir}/venv +source %{_builddir}/venv/bin/activate + +# 升级 pip 和 setuptools +pip install -i https://mirrors.huaweicloud.com/repository/pypi/simple --upgrade pip setuptools wheel + +# 安装项目依赖 +pip install -i https://mirrors.huaweicloud.com/repository/pypi/simple -r requirements.txt + +# 安装 PyInstaller +pip install -i https://mirrors.huaweicloud.com/repository/pypi/simple pyinstaller + +# 使用虚拟环境中的 PyInstaller 创建单一可执行文件 +pyinstaller --noconfirm \ + --distpath dist \ + oi-cli.spec + +# 退出虚拟环境 +deactivate %install -%define _unpackaged_files_terminate_build 0 -install -d %{buildroot}/%{_bindir} -install -c -m 0755 %{_builddir}/%{name}-%{version}/dist/copilot %{buildroot}/%{_bindir} -install -d %{buildroot}/etc/profile.d -install -c -m 0755 %{_builddir}/%{name}-%{version}/eulercopilot.sh %{buildroot}/etc/profile.d +# 安装智能命令行工具 +mkdir -p %{buildroot}%{_bindir} +install -m 0755 dist/%{pypi_name} %{buildroot}%{_bindir}/%{pypi_name} -%files -%defattr(-,root,root,-) -/usr/bin/copilot -/etc/profile.d/eulercopilot.sh +# 创建快捷链接 +ln -sf %{pypi_name} %{buildroot}%{_bindir}/%{shortcut_name} + +# 安装部署脚本和资源 +mkdir -p %{buildroot}/usr/lib/openeuler-intelligence/{scripts,resources} +mkdir -p %{buildroot}%{_bindir} + +# 复制部署脚本和资源 +install -m 755 scripts/deploy/deploy.sh %{buildroot}/usr/lib/openeuler-intelligence/scripts/deploy +cp -r scripts/deploy/0-one-click-deploy scripts/deploy/1-check-env scripts/deploy/2-install-dependency scripts/deploy/3-install-server scripts/deploy/4-other-script scripts/deploy/5-resource %{buildroot}/usr/lib/openeuler-intelligence/scripts/ +chmod -R +x %{buildroot}/usr/lib/openeuler-intelligence/scripts/ + +# 创建可执行文件的符号链接 +ln -sf /usr/lib/openeuler-intelligence/scripts/deploy %{buildroot}%{_bindir}/openeuler-intelligence-installer + +%files -n openeuler-intelligence-cli +%license LICENSE +%doc README.md +%{_bindir}/%{pypi_name} +%{_bindir}/%{shortcut_name} + +%files -n openeuler-intelligence-installer +%license LICENSE +%doc scripts/deploy/安装部署手册.md +/usr/lib/openeuler-intelligence +%{_bindir}/openeuler-intelligence-installer %changelog +* Tue Sep 09 2025 openEuler - 0.10.0-4 +- 优化安装脚本:添加内核版本检查和架构支持,优化 MongoDB 和 MinIO 安装逻辑 +- 优化 MCP 交互相关 TUI 样式 + +* Thu Sep 04 2025 openEuler - 0.10.0-3 +- 部署功能新增支持全量部署(含 RAG、Web) +- 允许构建 riscv64 loongarch64 版本 + +* Thu Aug 28 2025 openEuler - 0.10.0-2 +- 新增 openEuler Intelligence 部署功能 TUI +- 新增选择默认 Agent 功能 + +* Wed Aug 13 2025 openEuler - 0.10.0-1 +- 重构为子包形式:openeuler-intelligence-cli 和 openeuler-intelligence-installer +- openeuler-intelligence-cli 替换原 euler-copilot-shell 包 +- 新增 openeuler-intelligence-installer 子包,包含部署安装脚本 + +* Thu Jun 26 2025 Wenlong Zhang - 0.9.2-12 +- enable loongarch64 build + * Fri Jun 20 2025 misaka00251 - 0.9.2-11 - Enable riscv64 build