feat(wizard): 添加交互式向导和 AI 补全功能#79
Merged
h3zh1 merged 52 commits intoJan 23, 2026
Merged
Conversation
为 Wizard 交互式表单功能添加 huh 库支持 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- wizard.go: 定义 Wizard 结构和 Builder 模式方法 - result.go: 实现 WizardResult 结果存储和类型转换 - runner.go: 集成 huh 库实现表单执行逻辑 支持的字段类型: Input, Text, Select, MultiSelect, Confirm, Number, FilePath 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
预置常用配置向导模板: - listener_setup: 监听器配置向导 - tcp_pipeline: TCP 管道配置向导 - http_pipeline: HTTP 管道配置向导 - profile_create: Profile 创建向导 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
实现 Wizard 的 Lua 接口,支持在 MAL 脚本中构建交互式向导: - wizard(id, title): 创建新向导 - wizard_template(name): 加载预定义模板 - wizard_templates(): 列出所有模板 支持链式调用: wiz:input():select():confirm():run() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
实现 wizard 命令行接口: - wizard list: 列出所有可用向导模板 - wizard run <name>: 运行指定向导 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
在 NewLuaVM 中注册 wizard metatable 和全局函数, 使所有 MAL 脚本都能使用 wizard 功能 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
测试覆盖: - Wizard Builder 模式 - WizardResult 类型转换 - 模板注册和获取 - Wizard 克隆功能 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
移除未使用的 wizardfw 导入和 Initialize 调用, wizard 功能已通过 vm.go 中的 Lua VM 初始化集成 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- ai.go: 实现 AI API 客户端,支持 OpenAI 和 Claude - 支持流式响应 - 支持多种模型配置 - ai_cache.go: 实现 AI 补全缓存机制 - LRU 缓存策略 - 减少重复 API 调用 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
实现 AI 相关命令: - ai config: 配置 AI 设置 (API Key, 模型等) - ai ask: 向 AI 提问 - ai analyze: 分析命令输出或会话数据 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
实现命令有效性验证,用于 AI 补全功能: - 验证命令是否存在 - 验证命令参数格式 - 支持子命令验证 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
实现基于 AI 的智能命令补全: - 根据上下文生成补全建议 - 支持自然语言描述转命令 - 集成到 readline 补全系统 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- ai_complete.go: 实现控制台 AI 补全接口 - console.go: 添加 AI 补全支持和配置 - go.mod: 更新依赖 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
修改 readline 组件以支持 AI 补全功能: - completion.go: 集成 AI 补全回调 - inputrc/bind.go: 添加 AI 补全快捷键绑定 - internal/display/engine.go: 优化显示引擎 - shell.go: 添加 AI 补全配置接口 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
在设置中添加 AI 相关配置: - API Key 配置 - 模型选择 - 超时设置 - 补全开关 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
在 Console 结构中添加 AI 相关组件: - AICompletionEngine: AI 补全引擎 - AICache: 补全缓存 - CommandValidator: 命令验证器 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 Field() 方法返回当前字段以便链式设置属性 - 添加 SetRequired() 和 SetValidate() 方法支持字段验证 - 添加常用验证器: ValidateHost, ValidatePort, ValidateRange, ValidateFloat - 完善测试用例 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 WizardSpec 和 FieldSpec 结构体用于序列化定义 - 支持从 YAML/JSON 文件加载 wizard 定义 - 支持从嵌入资源 (embed://) 加载 spec - 支持从 Lua map 转换为 WizardSpec - 添加 RegisterTemplateFromSpec 方便注册 spec 定义的模板 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 Lua wizard builder API - 支持在 Lua 中定义和运行 wizard - 支持从 Lua table 注册 wizard 模板 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 WizardCategory 和 WizardEntry 类型定义 wizard 分组 - 定义四个分类: build, pipeline, cert, config - 定义三个独立命令: listener, profile, infra - 添加 RunSelect() 函数实现交互式选择菜单 - 为 Select 字段添加默认选中第一项的逻辑 - 重构 commands.go 支持分组子命令 - 改进 wizard list 以分组方式展示 用法示例: wizard build # 交互式选择构建类型 wizard build beacon # 直接运行 build_beacon wizard pipeline tcp # 直接运行 tcp_pipeline wizard listener # 运行 listener_setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 WizardExecutor 类型和注册机制 - wizard 完成后可自动调用对应执行器执行实际操作 - 添加 executors.go 存放各 wizard 的具体执行逻辑 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 插件可通过 Lua API 注册自定义 wizard 模板 - 添加 wizard_templates.go 管理插件注册的模板 - 支持从插件 resources/wizards 目录加载 spec 文件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 AI 补全快捷键支持 - 改进补全引擎逻辑 - 添加新的快捷键绑定 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 build_beacon 执行器 - 添加 build_pulse 执行器 - 添加 build_prelude 执行器 - 添加 build_module 执行器 - 添加 getFloat64 和 getStringSlice 辅助函数 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 WizardForm 组件实现两层选择器界面 - 新增 HorizontalSelect 和 HorizontalMultiSelect 组件 - 添加 RunCompact() 和 RunTwoPhase() 运行模式 - 重构 executors.go 辅助函数,统一类型处理 - 重构 wizard_templates.go 使用 specWalker 简化逻辑 - 添加 executors_test.go 测试用例 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加菜单作用域缓存 (GetScoped/SetScoped/GetPrefixScoped) - 改进补全逻辑,只显示补全部分而非完整命令 - 添加 GetCommandsForMenu/IsCommandAllowedInMenu 方法实现菜单感知验证 - 添加 NewCommandValidatorWithMenu 和 AddCommandsFromCobra 支持按菜单注册命令 - 过滤与用户输入完全相同的建议 - 增加建议数量上限到 10 个 - 跳过 shell 转义语法 (! 前缀) - 添加 command_validator_test.go 测试用例 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 智能处理补全前缀:当用户输入以空格结尾时剥离命令前缀 - 跳过与用户输入完全相同的建议 - 避免显示空候选项 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 OptionsProvider 接口支持运行时动态填充选项 - 添加 PrepareOptions() 方法在运行前调用所有提供者 - 水平选择器添加编辑模式 (按 e 键进入) - 将模板中的静态 Input 改为 Select 以支持动态选项 - 改进空值显示为 "(空)" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 wizard run 命令的模板名称补全 - 添加分类命令的子命令补全 - 新增 providers.go 实现动态选项提供者: - ProfileOptionsProvider: 从服务器获取配置文件列表 - ListenerOptionsProvider: 从服务器获取监听器列表 - PipelineOptionsProvider: 从服务器获取管道列表 - ArtifactOptionsProvider: 从服务器获取构件列表 - AddressOptionsProvider: 从管道中提取 C2 地址 - 添加 setupDynamicProviders 自动为已知字段设置提供者 - executors.go 添加 checkPortAvailable 端口可用性检查 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- explorer: 改进 reg_explorer 命令用法说明和示例 - privilege: 修正 runas 命令参数名 (--program -> --path),添加路径补全 - reg: 为 reg add 命令的 --type 参数添加值补全 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
主要改动: - 用 grouped_form 替换 horizontal_select/multiselect 组件 - 添加 AskPrediction 方法支持低延迟 AI 预测 - 改进 readline 补全引擎和显示逻辑 - 优化 build/cert 命令和 flagset 处理 - 改进 cryptography 和 certutils 模块 - 更新 intl/community 子模块 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- WizardGroup 新增 Optional 和 Expanded 属性 - 可选分组默认折叠,用户可按 Enter/Space 展开 - 按 c 键可折叠已展开的可选分组 - 支持在 YAML/JSON spec 中通过 optional 字段定义可选分组 - 添加 AsOptional() 和 SetExpanded() 链式方法 - 修复 lipgloss OSC 终端查询与 readline 冲突问题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 CobraToWizard() 将 cobra.Command 的 flags 自动转换为 Wizard - 支持 ui:group 注解按组分类字段 - 支持 ui:order 注解控制字段排序 - 支持 ui:options 注解将字段转为 Select 类型 - 支持 ui:required/ui:widget 等注解 - 新增 ApplyWizardResultToFlags() 将结果写回 flags - 支持编辑模式:读取当前 flag 值作为默认值 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 新增 RegisterWizardFlag() 注册全局 --wizard 标志 - 新增 WrapWithWizardSupport() 包装 PreRunE 支持 wizard 模式 - 任意命令添加 --wizard 即可启动交互式向导填写参数 - 在 root.go 和 client.go 中集成 wizard 支持 - 添加 carapace 补全使子命令继承 PersistentFlags 用法: iom <command> --wizard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 添加 TestGroupedWizardForm_OptionalGroups 测试可选分组功能 - 添加 cobra_test.go 测试 CobraToWizard 转换逻辑 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 将 wizard 相关的中文注释和消息改为英文 - 添加 minInt 辅助函数以兼容旧版 Go(不依赖内置 min) - 调整依赖版本以提高兼容性 - 移除 RunSelect 的 Inline 选项 - 更新配置文件模板 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 恢复 go.mod 到原版(使用新版 charmbracelet) - 完成剩余文件的中文注释英文化 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
f028fbd to
11536ce
Compare
- Go 版本升级到 1.23.0(miekg/dns 依赖要求) - 添加 charmbracelet/huh 依赖 - 使用 chainreactors/tui 原版 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
11536ce to
fccd136
Compare
M09Ic
reviewed
Jan 20, 2026
| vm.PreloadModule(global.Name, mals.GlobalLoader(global.Name, global.Path, global.Content)) | ||
| } | ||
|
|
||
| // 注册所有内置函数 |
Contributor
There was a problem hiding this comment.
参考其他的command如何注册到lua, 不应该在全局的入口处添加wizard的注册
- 移除 AI 自动补全引擎 (ai_cache, command_validator, ai_completer) - 从 console.go 移除 AI 补全相关初始化代码 - 简化 ai.go,移除 AskPrediction 和 AICompletionEngine - 重构 wizard 命令结构,统一使用 createCategoryCommand - 导出 ExecuteBuild 和 ValidateLibFlag 供 wizard 使用 - 更新 go.mod 依赖版本 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 重构 cobra.go,合并 wizard 运行逻辑到单一文件 - 移除复杂的 spec/template/lua 集成系统 - 移除 executor 框架和 providers - 简化 wizard_flag.go,移除 WrapWithWizardSupport - 新增 client/command/common/wizard.go 统一 wizard 辅助函数 - 更新各模块 commands.go 适配新的 wizard 接口 - 清理 plugin 中的 wizard 模板相关代码 - 增强 console completer 功能 - 更新 go.mod 依赖 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
移除 toolchain 指令以提高兼容性 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
保持最小改动,内联建议功能将单独提 PR 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Lua 插件通过 command() 函数创建的命令现在自动支持 --wizard 标志, 用户可以在任意 Lua 命令上使用交互式向导模式。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- 将 wizard 启用逻辑从 common 包移至 wizard 包 (enable.go) - 优化 AI 配置命令,支持更多选项 - 改进 grouped_form UI 交互体验 - 简化 cobra.go 的 wizard 转换逻辑 - 更新 go.mod 依赖版本
- 删除 client/command/wizard_flag.go - 功能已整合到 client/wizard/enable.go - 简化 build/commands.go 的 wizard 调用
- pipeline/commands.go 添加 wizard 支持 - service/commands.go 添加 wizard 支持 - website/commands.go 添加 wizard 支持 - 新增 wizard_test.go 单元测试
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
本 PR 添加 Wizard 交互式向导 和 AI 命令补全引擎。
1. Wizard 交互式向导
核心功能
client/wizard/包,实现交互式表单向导Cobra 命令转 Wizard
RunWizard(cmd)自动将 cobra.Command flags 转为交互式表单ui:group、ui:order、ui:options等 flag 注解--wizard标志,任意命令可启动向导模式用法示例
# 任意命令添加 --wizard 启动向导 build beacon --wizard pipeline tcp --wizard2. AI 命令补全引擎
核心功能
client/core/ai.go,AI 驱动的智能命令补全AI 子命令
ai ask <问题>- 询问 AI 关于命令的问题ai analyze <命令>- 分析命令语法和参数ai config- 配置 AI 提供商和模型?- 快捷命令,等价于ai ask用法示例
3. Lua 插件 Wizard 支持
Lua 插件通过
command()创建的命令自动支持--wizard标志。Lua 插件示例
使用方式
主要文件
client/wizard/cobra.goclient/wizard/grouped_form.goclient/core/ai.goclient/command/ai/client/command/wizard_flag.goclient/command/common/wizard.goclient/plugin/lua.goclient/assets/settings.goTest plan
build beacon --wizard启动交互式向导ai config配置 AI 提供商? 如何构建 beacon测试 AI 问答--wizard测试