thatgfsj-code 0.3.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.
Files changed (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +136 -0
  3. package/ROADMAP.md +61 -0
  4. package/dist/app/agent.d.ts +31 -0
  5. package/dist/app/agent.d.ts.map +1 -0
  6. package/dist/app/agent.js +106 -0
  7. package/dist/app/agent.js.map +1 -0
  8. package/dist/app/index.d.ts +39 -0
  9. package/dist/app/index.d.ts.map +1 -0
  10. package/dist/app/index.js +80 -0
  11. package/dist/app/index.js.map +1 -0
  12. package/dist/cmd/index.d.ts +12 -0
  13. package/dist/cmd/index.d.ts.map +1 -0
  14. package/dist/cmd/index.js +85 -0
  15. package/dist/cmd/index.js.map +1 -0
  16. package/dist/config/index.d.ts +39 -0
  17. package/dist/config/index.d.ts.map +1 -0
  18. package/dist/config/index.js +110 -0
  19. package/dist/config/index.js.map +1 -0
  20. package/dist/config/providers.d.ts +23 -0
  21. package/dist/config/providers.d.ts.map +1 -0
  22. package/dist/config/providers.js +152 -0
  23. package/dist/config/providers.js.map +1 -0
  24. package/dist/config/types.d.ts +33 -0
  25. package/dist/config/types.d.ts.map +1 -0
  26. package/dist/config/types.js +5 -0
  27. package/dist/config/types.js.map +1 -0
  28. package/dist/hooks/index.d.ts +31 -0
  29. package/dist/hooks/index.d.ts.map +1 -0
  30. package/dist/hooks/index.js +71 -0
  31. package/dist/hooks/index.js.map +1 -0
  32. package/dist/llm/anthropic.d.ts +17 -0
  33. package/dist/llm/anthropic.d.ts.map +1 -0
  34. package/dist/llm/anthropic.js +126 -0
  35. package/dist/llm/anthropic.js.map +1 -0
  36. package/dist/llm/gemini.d.ts +16 -0
  37. package/dist/llm/gemini.d.ts.map +1 -0
  38. package/dist/llm/gemini.js +107 -0
  39. package/dist/llm/gemini.js.map +1 -0
  40. package/dist/llm/index.d.ts +48 -0
  41. package/dist/llm/index.d.ts.map +1 -0
  42. package/dist/llm/index.js +174 -0
  43. package/dist/llm/index.js.map +1 -0
  44. package/dist/llm/openai.d.ts +17 -0
  45. package/dist/llm/openai.d.ts.map +1 -0
  46. package/dist/llm/openai.js +113 -0
  47. package/dist/llm/openai.js.map +1 -0
  48. package/dist/llm/provider.d.ts +33 -0
  49. package/dist/llm/provider.d.ts.map +1 -0
  50. package/dist/llm/provider.js +6 -0
  51. package/dist/llm/provider.js.map +1 -0
  52. package/dist/mcp/client.d.ts +83 -0
  53. package/dist/mcp/client.d.ts.map +1 -0
  54. package/dist/mcp/client.js +267 -0
  55. package/dist/mcp/client.js.map +1 -0
  56. package/dist/prompts/index.d.ts +27 -0
  57. package/dist/prompts/index.d.ts.map +1 -0
  58. package/dist/prompts/index.js +102 -0
  59. package/dist/prompts/index.js.map +1 -0
  60. package/dist/session/compactor.d.ts +48 -0
  61. package/dist/session/compactor.d.ts.map +1 -0
  62. package/dist/session/compactor.js +77 -0
  63. package/dist/session/compactor.js.map +1 -0
  64. package/dist/session/index.d.ts +48 -0
  65. package/dist/session/index.d.ts.map +1 -0
  66. package/dist/session/index.js +69 -0
  67. package/dist/session/index.js.map +1 -0
  68. package/dist/session/message.d.ts +26 -0
  69. package/dist/session/message.d.ts.map +1 -0
  70. package/dist/session/message.js +34 -0
  71. package/dist/session/message.js.map +1 -0
  72. package/dist/tools/file.d.ts +46 -0
  73. package/dist/tools/file.d.ts.map +1 -0
  74. package/dist/tools/file.js +100 -0
  75. package/dist/tools/file.js.map +1 -0
  76. package/dist/tools/git.d.ts +52 -0
  77. package/dist/tools/git.d.ts.map +1 -0
  78. package/dist/tools/git.js +112 -0
  79. package/dist/tools/git.js.map +1 -0
  80. package/dist/tools/index.d.ts +42 -0
  81. package/dist/tools/index.d.ts.map +1 -0
  82. package/dist/tools/index.js +92 -0
  83. package/dist/tools/index.js.map +1 -0
  84. package/dist/tools/search.d.ts +36 -0
  85. package/dist/tools/search.d.ts.map +1 -0
  86. package/dist/tools/search.js +223 -0
  87. package/dist/tools/search.js.map +1 -0
  88. package/dist/tools/shell.d.ts +50 -0
  89. package/dist/tools/shell.d.ts.map +1 -0
  90. package/dist/tools/shell.js +117 -0
  91. package/dist/tools/shell.js.map +1 -0
  92. package/dist/tools/types.d.ts +68 -0
  93. package/dist/tools/types.d.ts.map +1 -0
  94. package/dist/tools/types.js +57 -0
  95. package/dist/tools/types.js.map +1 -0
  96. package/dist/tui/index.d.ts +8 -0
  97. package/dist/tui/index.d.ts.map +1 -0
  98. package/dist/tui/index.js +8 -0
  99. package/dist/tui/index.js.map +1 -0
  100. package/dist/tui/input.d.ts +14 -0
  101. package/dist/tui/input.d.ts.map +1 -0
  102. package/dist/tui/input.js +50 -0
  103. package/dist/tui/input.js.map +1 -0
  104. package/dist/tui/output.d.ts +20 -0
  105. package/dist/tui/output.d.ts.map +1 -0
  106. package/dist/tui/output.js +70 -0
  107. package/dist/tui/output.js.map +1 -0
  108. package/dist/tui/repl.d.ts +25 -0
  109. package/dist/tui/repl.d.ts.map +1 -0
  110. package/dist/tui/repl.js +114 -0
  111. package/dist/tui/repl.js.map +1 -0
  112. package/dist/tui/welcome.d.ts +15 -0
  113. package/dist/tui/welcome.d.ts.map +1 -0
  114. package/dist/tui/welcome.js +86 -0
  115. package/dist/tui/welcome.js.map +1 -0
  116. package/dist/types.d.ts +38 -0
  117. package/dist/types.d.ts.map +1 -0
  118. package/dist/types.js +6 -0
  119. package/dist/types.js.map +1 -0
  120. package/dist/utils/diff.d.ts +22 -0
  121. package/dist/utils/diff.d.ts.map +1 -0
  122. package/dist/utils/diff.js +60 -0
  123. package/dist/utils/diff.js.map +1 -0
  124. package/dist/utils/project.d.ts +32 -0
  125. package/dist/utils/project.d.ts.map +1 -0
  126. package/dist/utils/project.js +89 -0
  127. package/dist/utils/project.js.map +1 -0
  128. package/docs/API_KEY_GUIDE.md +236 -0
  129. package/docs/FAQ.md +182 -0
  130. package/install.bat +63 -0
  131. package/install.ps1 +238 -0
  132. package/install.sh +113 -0
  133. package/package.json +36 -0
  134. package/src/app/agent.ts +140 -0
  135. package/src/app/index.ts +101 -0
  136. package/src/cmd/index.ts +96 -0
  137. package/src/config/index.ts +130 -0
  138. package/src/config/providers.ts +160 -0
  139. package/src/config/types.ts +46 -0
  140. package/src/hooks/index.ts +111 -0
  141. package/src/llm/anthropic.ts +146 -0
  142. package/src/llm/gemini.ts +127 -0
  143. package/src/llm/index.ts +209 -0
  144. package/src/llm/openai.ts +132 -0
  145. package/src/llm/provider.ts +38 -0
  146. package/src/mcp/client.ts +330 -0
  147. package/src/prompts/index.ts +123 -0
  148. package/src/session/compactor.ts +103 -0
  149. package/src/session/index.ts +81 -0
  150. package/src/session/message.ts +42 -0
  151. package/src/tools/file.ts +117 -0
  152. package/src/tools/git.ts +132 -0
  153. package/src/tools/index.ts +108 -0
  154. package/src/tools/search.ts +263 -0
  155. package/src/tools/shell.ts +136 -0
  156. package/src/tools/types.ts +122 -0
  157. package/src/tui/index.ts +8 -0
  158. package/src/tui/input.ts +56 -0
  159. package/src/tui/output.ts +83 -0
  160. package/src/tui/repl.ts +131 -0
  161. package/src/tui/welcome.ts +101 -0
  162. package/src/types.ts +42 -0
  163. package/src/utils/diff.ts +71 -0
  164. package/src/utils/project.ts +99 -0
  165. package/tsconfig.json +19 -0
@@ -0,0 +1,236 @@
1
+ # API Key 获取教程
2
+
3
+ Thatgfsj Code 支持多种 AI 提供商,以下是各提供商 API Key 的获取教程。
4
+
5
+ ## 目录
6
+
7
+ 1. [SiliconFlow (推荐)](#1-siliconflow-推荐)
8
+ 2. [MiniMax](#2-minimax)
9
+ 3. [OpenAI](#3-openai)
10
+ 4. [Anthropic (Claude)](#4-anthropic-claude)
11
+ 5. [Google Gemini](#5-google-gemini)
12
+ 6. [Kimi (Moonshot AI)](#6-kimi-moonshot-ai)
13
+ 7. [DeepSeek](#7-deepseek)
14
+ 8. [文心一言 (ERNIE)](#8-文心一言-ernie)
15
+ 9. [Ollama (本地模型)](#9-ollama-本地模型)
16
+
17
+ ---
18
+
19
+ ## 1. SiliconFlow (推荐)
20
+
21
+ **官网**: https://siliconflow.cn
22
+
23
+ ### 步骤
24
+
25
+ 1. 访问 [SiliconFlow](https://siliconflow.cn) 并注册账号
26
+ 2. 完成实名认证(可选,部分模型需要)
27
+ 3. 进入「API 密钥」页面
28
+ 4. 点击「创建新密钥」
29
+ 5. 复制生成的 API Key
30
+
31
+ ### 特点
32
+
33
+ - ✅ 国产模型,性价比高
34
+ - ✅ 支持 Qwen、Kimi、DeepSeek、GLM 等
35
+ - ✅ 免费额度:¥8.8(新用户)
36
+
37
+ ---
38
+
39
+ ## 2. MiniMax
40
+
41
+ **官网**: https://platform.minimax.io
42
+
43
+ ### 步骤
44
+
45
+ 1. 访问 [MiniMax](https://platform.minimax.io) 并注册账号
46
+ 2. 进入「API 密钥」页面
47
+ 3. 点击「创建 API Key」
48
+ 4. 复制生成的密钥
49
+
50
+ ### 特点
51
+
52
+ - ✅ Moonshot Kimi 系列模型
53
+ - ✅ Agent 能力强
54
+
55
+ ---
56
+
57
+ ## 3. OpenAI
58
+
59
+ **官网**: https://platform.openai.com
60
+
61
+ ### 步骤
62
+
63
+ 1. 访问 [OpenAI](https://platform.openai.com) 并注册账号
64
+ 2. 进入「API Keys」页面
65
+ 3. 点击「Create new secret key」
66
+ 4. 复制生成的密钥
67
+
68
+ ### 特点
69
+
70
+ - ⚠️ 需要海外支付方式
71
+ - ✅ GPT-4o 系列最强模型
72
+
73
+ ---
74
+
75
+ ## 4. Anthropic (Claude)
76
+
77
+ **官网**: https://www.anthropic.com
78
+
79
+ ### 步骤
80
+
81
+ 1. 访问 [Anthropic](https://www.anthropic.com) 并注册账号
82
+ 2. 进入「API Keys」页面
83
+ 3. 点击「Create Key」
84
+ 4. 复制生成的密钥
85
+
86
+ ### 特点
87
+
88
+ - ⚠️ 需要海外支付方式
89
+ - ✅ Claude 系列模型能力强
90
+
91
+ ---
92
+
93
+ ## 5. Google Gemini
94
+
95
+ **官网**: https://aistudio.google.com/app/apikey
96
+
97
+ ### 步骤
98
+
99
+ 1. 访问 [Google AI Studio](https://aistudio.google.com/app/apikey)
100
+ 2. 点击「Create API Key」
101
+ 3. 选择已有项目或创建新项目
102
+ 4. 复制生成的密钥
103
+
104
+ ### 特点
105
+
106
+ - ✅ 免费额度充足
107
+ - ✅ Gemini 模型能力强
108
+
109
+ ---
110
+
111
+ ## 6. Kimi (Moonshot AI)
112
+
113
+ **官网**: https://platform.moonshot.cn
114
+
115
+ ### 步骤
116
+
117
+ 1. 访问 [Moonshot AI](https://platform.moonshot.cn) 并注册账号
118
+ 2. 进入「API 密钥管理」页面
119
+ 3. 点击「创建」
120
+ 4. 复制生成的密钥
121
+
122
+ ### 特点
123
+
124
+ - ✅ 国产模型
125
+ - ✅ 长上下文能力强
126
+
127
+ ---
128
+
129
+ ## 7. DeepSeek
130
+
131
+ **官网**: https://platform.deepseek.com
132
+
133
+ ### 步骤
134
+
135
+ 1. 访问 [DeepSeek](https://platform.deepseek.com) 并注册账号
136
+ 2. 进入「API Keys」页面
137
+ 3. 点击「创建 API Key」
138
+ 4. 复制生成的密钥
139
+
140
+ ### 特点
141
+
142
+ - ✅ 性价比高
143
+ - ✅ 编程能力强
144
+
145
+ ---
146
+
147
+ ## 8. 文心一言 (ERNIE)
148
+
149
+ **官网**: https://login.bce.baidu.com
150
+
151
+ ### 步骤
152
+
153
+ 1. 访问 [百度智能云](https://login.bce.baidu.com) 并注册账号
154
+ 2. 进入「文心一言 API」产品页
155
+ 3. 创建应用并获取 API Key 和 Secret Key
156
+ 4. 使用 Secret Key 获取 Access Token
157
+
158
+ ### 特点
159
+
160
+ - ✅ 百度 ERNIE 系列
161
+ - ⚠️ 配置稍复杂
162
+
163
+ ---
164
+
165
+ ## 9. Ollama (本地模型)
166
+
167
+ **官网**: https://ollama.com
168
+
169
+ ### 步骤
170
+
171
+ 1. 下载并安装 [Ollama](https://ollama.com)
172
+ 2. 终端运行 `ollama run llama2`
173
+ 3. 设置环境变量 `OLLAMA_BASE_URL=http://localhost:11434`
174
+
175
+ ### 特点
176
+
177
+ - ✅ 完全免费
178
+ - ✅ 本地运行,保护隐私
179
+ - ⚠️ 需要本地有足够配置
180
+
181
+ ---
182
+
183
+ ## 环境变量设置
184
+
185
+ 获取 API Key 后,设置方式:
186
+
187
+ ```bash
188
+ # SiliconFlow
189
+ export SILICONFLOW_API_KEY=你的密钥
190
+
191
+ # MiniMax
192
+ export MINIMAX_API_KEY=你的密钥
193
+
194
+ # OpenAI
195
+ export OPENAI_API_KEY=你的密钥
196
+
197
+ # Anthropic
198
+ export ANTHROPIC_API_KEY=你的密钥
199
+
200
+ # Google Gemini
201
+ export GEMINI_API_KEY=你的密钥
202
+
203
+ # Kimi
204
+ export KIMI_API_KEY=你的密钥
205
+
206
+ # DeepSeek
207
+ export DEEPSEEK_API_KEY=你的密钥
208
+
209
+ # Ollama
210
+ export OLLAMA_BASE_URL=http://localhost:11434
211
+ ```
212
+
213
+ 或者运行 `gfcode init` 交互式配置。
214
+
215
+ ---
216
+
217
+ ## 常见问题
218
+
219
+ ### Q: 哪个 Provider 最推荐?
220
+
221
+ **A**: SiliconFlow 性价比最高,适合新手入门。
222
+
223
+ ### Q: 为什么我的 API Key 不工作?
224
+
225
+ **A**:
226
+ 1. 检查环境变量是否正确设置
227
+ 2. 确认 API Key 没有过期
228
+ 3. 查看账户是否有足够余额
229
+
230
+ ### Q: 可以同时使用多个 Provider 吗?
231
+
232
+ **A**: 可以,通过配置文件或环境变量切换。
233
+
234
+ ---
235
+
236
+ 如有问题,请提交 Issue: https://github.com/Thatgfsj/thatgfsj-code/issues
package/docs/FAQ.md ADDED
@@ -0,0 +1,182 @@
1
+ # 常见问题 FAQ
2
+
3
+ ## 目录
4
+
5
+ 1. [安装问题](#1-安装问题)
6
+ 2. [配置问题](#2-配置问题)
7
+ 3. [使用问题](#3-使用问题)
8
+ 4. [ Provider 问题](#4-provider-问题)
9
+ 5. [其他问题](#5-其他问题)
10
+
11
+ ---
12
+
13
+ ## 1. 安装问题
14
+
15
+ ### Q: npm install 失败怎么办?
16
+
17
+ **A**:
18
+ - 确保 Node.js 版本 >= 18
19
+ - 尝试清除缓存: `npm cache clean --force`
20
+ - 如果是 Windows 问题,尝试使用 PowerShell 或管理员权限
21
+
22
+ ### Q: npm link 后命令找不到?
23
+
24
+ **A**:
25
+ - 检查 PATH 环境变量是否包含 npm 全局路径
26
+ - Windows 上通常是: `C:\Users\你的用户名\AppData\Roaming\npm`
27
+ - 或者直接使用 `npx gfcode` 运行
28
+
29
+ ---
30
+
31
+ ## 2. 配置问题
32
+
33
+ ### Q: 如何配置 API Key?
34
+
35
+ **A**: 两种方式:
36
+ 1. 交互式配置(推荐):运行 `gfcode init`
37
+ 2. 环境变量:设置对应的环境变量
38
+
39
+ ### Q: 配置文件在哪里?
40
+
41
+ **A**: `~/.thatgfsj/config.json`(用户主目录下的 .thatgfsj 文件夹)
42
+
43
+ ### Q: 配置文件格式?
44
+
45
+ ```json
46
+ {
47
+ "model": "Qwen/Qwen2.5-7B-Instruct",
48
+ "apiKey": "your_api_key",
49
+ "provider": "siliconflow",
50
+ "temperature": 0.7,
51
+ "maxTokens": 4096
52
+ }
53
+ ```
54
+
55
+ ---
56
+
57
+ ## 3. 使用问题
58
+
59
+ ### Q: 交互模式怎么用?
60
+
61
+ **A**:
62
+ ```bash
63
+ # 启动交互模式
64
+ gfcode
65
+
66
+ # 在交互模式中
67
+ > 帮我写一个函数
68
+ > 解释这段代码
69
+ > /help 查看命令
70
+ > /exit 退出
71
+ ```
72
+
73
+ ### Q: 如何解释代码?
74
+
75
+ **A**:
76
+ ```bash
77
+ # 直接解释代码
78
+ gfcode explain "const add = (a, b) => a + b;"
79
+
80
+ # 从文件解释
81
+ gfcode explain -f src/utils.ts
82
+ ```
83
+
84
+ ### Q: 如何调试代码?
85
+
86
+ **A**:
87
+ ```bash
88
+ # 直接调试代码
89
+ gfcode debug "你的代码"
90
+
91
+ # 带错误信息调试
92
+ gfcode debug -f app.js -e "TypeError: undefined"
93
+ ```
94
+
95
+ ### Q: 如何生成代码模板?
96
+
97
+ **A**:
98
+ ```bash
99
+ # React 组件
100
+ gfcode template react -n MyButton
101
+
102
+ # Express API
103
+ gfcode template express -n my-api
104
+
105
+ # Python 脚本
106
+ gfcode template python -n scraper
107
+ ```
108
+
109
+ ---
110
+
111
+ ## 4. Provider 问题
112
+
113
+ ### Q: 哪个 Provider 最推荐?
114
+
115
+ **A**:
116
+ - 新手推荐 **SiliconFlow**,性价比高,支持国产模型
117
+ - 想用 GPT 推荐 **OpenAI**
118
+ - 想用 Claude 推荐 **Anthropic**
119
+ - 想免费用推荐 **Google Gemini**
120
+
121
+ ### Q: API Key 在哪里获取?
122
+
123
+ **A**: 见 [API Key 获取教程](./API_KEY_GUIDE.md)
124
+
125
+ ### Q: Provider 切换需要重新配置吗?
126
+
127
+ **A**:
128
+ - 如果用环境变量,直接改环境变量即可
129
+ - 如果用配置文件,修改配置文件的 `provider` 和 `model` 字段
130
+
131
+ ### Q: 遇到 "API Key 无效" 错误?
132
+
133
+ **A**:
134
+ 1. 检查 API Key 是否正确
135
+ 2. 检查环境变量是否设置正确
136
+ 3. 检查账户是否有足够余额
137
+ 4. 确认 API Key 没有过期
138
+
139
+ ---
140
+
141
+ ## 5. 其他问题
142
+
143
+ ### Q: 如何查看当前版本?
144
+
145
+ ```bash
146
+ gfcode --version
147
+ ```
148
+
149
+ ### Q: 如何更新到最新版本?
150
+
151
+ ```bash
152
+ git pull
153
+ npm install
154
+ npm run build
155
+ ```
156
+
157
+ ### Q: 遇到其他错误怎么办?
158
+
159
+ **A**:
160
+ 1. 查看错误信息
161
+ 2. 尝试 Google 搜索错误
162
+ 3. 提交 Issue: https://github.com/Thatgfsj/thatgfsj-code/issues
163
+
164
+ ### Q: 如何贡献代码?
165
+
166
+ **A**:
167
+ 1. Fork 仓库
168
+ 2. 创建分支: `git checkout -b feature/your-feature`
169
+ 3. 提交修改: `git commit -m 'Add something'`
170
+ 4. 推送分支: `git push origin feature/your-feature`
171
+ 5. 创建 Pull Request
172
+
173
+ ---
174
+
175
+ ## 联系方式
176
+
177
+ - GitHub Issues: https://github.com/Thatgfsj/thatgfsj-code/issues
178
+ - 欢迎提交 Bug 和功能请求!
179
+
180
+ ---
181
+
182
+ 如有更多问题,请提交 Issue。
package/install.bat ADDED
@@ -0,0 +1,63 @@
1
+ @echo off
2
+ chcp 65001 >nul
3
+ title Thatgfsj Code 安装向导
4
+ echo.
5
+ echo Thatgfsj Code 一键安装
6
+ echo =====================
7
+ echo.
8
+
9
+ echo [*] 检查环境...
10
+ echo.
11
+
12
+ :: Check PowerShell
13
+ powershell -Version >nul 2>&1
14
+ if %errorlevel% neq 0 (
15
+ echo [错误] 需要 PowerShell,请升级: https://aka.ms/powershell
16
+ pause
17
+ exit /b 1
18
+ )
19
+ echo [OK] PowerShell 已就绪
20
+
21
+ :: Check Node.js
22
+ for /f "delims=" %%i in ('powershell -Command "node --version 2^>nul"') do set NODE_VERSION=%%i
23
+ if defined NODE_VERSION (
24
+ echo [OK] Node.js %NODE_VERSION% 已安装
25
+ ) else (
26
+ echo.
27
+ echo [!] 未检测到 Node.js,开始自动安装...
28
+ echo.
29
+
30
+ :: Try winget
31
+ where winget >nul 2>&1
32
+ if %errorlevel% equ 0 (
33
+ echo [*] 正在通过 winget 安装 Node.js...
34
+ winget install OpenJS.NodeJS.LTS --source winget --accept-package-agreements --accept-source-agreements
35
+ echo.
36
+ echo [OK] Node.js 安装完成
37
+ echo [!] 请重新打开一个 CMD 然后再次运行此脚本
38
+ pause
39
+ exit /b 0
40
+ )
41
+
42
+ :: Fallback: manual download
43
+ echo [*] 正在下载 Node.js 安装包...
44
+ powershell -Command "Start-Process 'https://nodejs.org/' -Verb Open"
45
+ echo.
46
+ echo [!] 请手动安装 Node.js LTS 版本
47
+ echo [!] 安装完成后,重新运行此脚本
48
+ pause
49
+ exit /b 0
50
+ )
51
+
52
+ :: Download install.ps1
53
+ echo.
54
+ echo [*] 正在下载安装程序...
55
+ powershell -Command "Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/Thatgfsj/thatgfsj-code/main/install.ps1' -OutFile '%TEMP%\thatgfsj_install.ps1'"
56
+
57
+ echo.
58
+ echo [*] 启动安装向导...
59
+ echo.
60
+ powershell -ExecutionPolicy Bypass -File "%TEMP%\thatgfsj_install.ps1"
61
+
62
+ echo.
63
+ pause
package/install.ps1 ADDED
@@ -0,0 +1,238 @@
1
+ # Thatgfsj Code Installer for Windows
2
+ # Usage:
3
+ # powershell -c "irm https://raw.githubusercontent.com/Thatgfsj/thatgfsj-code/main/install.ps1 | iex"
4
+ # powershell -c "& ([scriptblock]::Create((irm https://raw.githubusercontent.com/Thatgfsj/thatgfsj-code/main/install.ps1)))"
5
+
6
+ param(
7
+ [switch]$NoOpen,
8
+ [switch]$DryRun
9
+ )
10
+
11
+ $ErrorActionPreference = "Stop"
12
+
13
+ # Colors
14
+ function Write-Step { param($msg) Write-Host "[*] $msg" -ForegroundColor Yellow }
15
+ function Write-Success { param($msg) Write-Host "[✓] $msg" -ForegroundColor Green }
16
+ function Write-Error { param($msg) Write-Host "[✗] $msg" -ForegroundColor Red }
17
+ function Write-Info { param($msg) Write-Host " $msg" -ForegroundColor Gray }
18
+
19
+ Write-Host ""
20
+ Write-Host " Thatgfsj Code 安装向导" -ForegroundColor Cyan
21
+ Write-Host " =======================" -ForegroundColor Cyan
22
+ Write-Host ""
23
+
24
+ if ($DryRun) {
25
+ Write-Host "[DRY RUN] 仅显示将要执行的操作" -ForegroundColor Yellow
26
+ Write-Host ""
27
+ }
28
+
29
+ # ============== Step 1: Check PowerShell ==============
30
+ Write-Step "检查 PowerShell 版本..."
31
+
32
+ if ($PSVersionTable.PSVersion.Major -lt 5) {
33
+ Write-Error "需要 PowerShell 5.0 或更高版本"
34
+ Write-Host "请升级您的 PowerShell: https://aka.ms/powershell" -ForegroundColor Gray
35
+ exit 1
36
+ }
37
+ Write-Success "PowerShell $($PSVersionTable.PSVersion) 检测正常"
38
+
39
+ # ============== Step 2: Check/Fetch Node.js ==============
40
+ Write-Step "检查 Node.js..."
41
+
42
+ function Test-NodeInstalled {
43
+ try {
44
+ $nodeVersion = node --version 2>$null
45
+ if ($nodeVersion) {
46
+ $version = [int]($nodeVersion -replace 'v(\d+)\..*', '$1')
47
+ return @{ installed = $true; version = $nodeVersion; major = $version }
48
+ }
49
+ } catch {}
50
+ return @{ installed = $false; version = $null; major = 0 }
51
+ }
52
+
53
+ $nodeStatus = Test-NodeInstalled
54
+ if ($nodeStatus.installed -and $nodeStatus.major -ge 18) {
55
+ Write-Success "Node.js $($nodeStatus.version) 已安装"
56
+ } else {
57
+ Write-Host " 未检测到 Node.js 18+,开始安装..." -ForegroundColor Gray
58
+
59
+ # Try winget first
60
+ if (Get-Command winget -ErrorAction SilentlyContinue) {
61
+ Write-Info "使用 winget 安装..."
62
+ winget install OpenJS.NodeJS.LTS --source winget --accept-package-agreements --accept-source-agreements
63
+
64
+ # Refresh PATH
65
+ $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
66
+
67
+ $nodeStatus = Test-NodeInstalled
68
+ if ($nodeStatus.installed) {
69
+ Write-Success "Node.js 安装完成"
70
+ } else {
71
+ Write-Host " 需要重启 PowerShell 后重新运行安装" -ForegroundColor Yellow
72
+ exit 0
73
+ }
74
+ }
75
+ # Try choco
76
+ elseif (Get-Command choco -ErrorAction SilentlyContinue) {
77
+ Write-Info "使用 Chocolatey 安装..."
78
+ choco install nodejs-lts -y
79
+ Write-Success "Node.js 安装完成 (可能需要重启)"
80
+ }
81
+ # Manual fallback
82
+ else {
83
+ Write-Host ""
84
+ Write-Error "未检测到包管理器 (winget/choco/scoop)"
85
+ Write-Host ""
86
+ Write-Host "请手动安装 Node.js:" -ForegroundColor Yellow
87
+ Write-Host " 1. 访问 https://nodejs.org" -ForegroundColor Gray
88
+ Write-Host " 2. 下载 LTS 版本 (推荐 v20 或 v22)" -ForegroundColor Gray
89
+ Write-Host " 3. 运行安装程序" -ForegroundColor Gray
90
+ Write-Host " 4. 重新运行此安装脚本" -ForegroundColor Gray
91
+ Write-Host ""
92
+ exit 1
93
+ }
94
+ }
95
+
96
+ # ============== Step 3: Clone/Update Repository ==============
97
+ Write-Step "准备安装 Thatgfsj Code..."
98
+
99
+ $installDir = Join-Path $env:USERPROFILE "thatgfsj-code"
100
+
101
+ if (Test-Path $installDir) {
102
+ Write-Info "检测到已有安装,正在更新..."
103
+ if (-not $DryRun) {
104
+ Set-Location $installDir
105
+ git pull origin main 2>$null
106
+ if ($LASTEXITCODE -ne 0) {
107
+ # If pull fails, re-clone
108
+ Remove-Item $installDir -Recurse -Force
109
+ }
110
+ }
111
+ } else {
112
+ if (-not $DryRun) {
113
+ Write-Info "正在克隆仓库..."
114
+ git clone https://github.com/Thatgfsj/thatgfsj-code.git $installDir
115
+ Set-Location $installDir
116
+ }
117
+ }
118
+
119
+ if (-not (Test-Path (Join-Path $installDir "package.json"))) {
120
+ Write-Error "安装目录无效: $installDir"
121
+ exit 1
122
+ }
123
+
124
+ Write-Success "代码准备完成: $installDir"
125
+
126
+ # ============== Step 4: Install Dependencies ==============
127
+ Write-Step "安装依赖..."
128
+
129
+ if (-not $DryRun) {
130
+ Set-Location $installDir
131
+ npm install
132
+ if ($LASTEXITCODE -ne 0) {
133
+ Write-Error "npm install 失败"
134
+ exit 1
135
+ }
136
+
137
+ Write-Info "编译 TypeScript..."
138
+ npm run build
139
+ if ($LASTEXITCODE -ne 0) {
140
+ Write-Error "编译失败"
141
+ exit 1
142
+ }
143
+ }
144
+ Write-Success "依赖安装完成"
145
+
146
+ # ============== Step 5: Link Command ==============
147
+ Write-Step "设置命令..."
148
+
149
+ if (-not $DryRun) {
150
+ npm link
151
+ }
152
+ Write-Success "命令 'gfcode' 已可用"
153
+
154
+ # ============== Step 6: Setup API Key ==============
155
+ Write-Host ""
156
+ Write-Step "配置 API Key (可选)..."
157
+
158
+ $apiKeySet = $false
159
+ $providers = @{
160
+ "1" = @{name="SiliconFlow (推荐)"; var="SILICONFLOW_API_KEY"; url="https://siliconflow.cn"}
161
+ "2" = @{name="MiniMax"; var="MINIMAX_API_KEY"; url="https://platform.minimax.io"}
162
+ "3" = @{name="OpenAI"; var="OPENAI_API_KEY"; url="https://platform.openai.com"}
163
+ "4" = @{name="Anthropic"; var="ANTHROPIC_API_KEY"; url="https://www.anthropic.com"}
164
+ "5" = @{name="Google Gemini"; var="GEMINI_API_KEY"; url="https://aistudio.google.com/app/apikey"}
165
+ "6" = @{name="跳过 (稍后配置)"; var=""; url=""}
166
+ }
167
+
168
+ Write-Host ""
169
+ Write-Host " 选择 AI Provider:" -ForegroundColor White
170
+ Write-Host ""
171
+ foreach ($key in $providers.Keys | Sort-Object) {
172
+ $p = $providers[$key]
173
+ Write-Host " $key. $($p.name)" -ForegroundColor Gray
174
+ }
175
+ Write-Host ""
176
+
177
+ if ($NoOpen) {
178
+ Write-Host " 使用 --NoOpen 跳过配置" -ForegroundColor Gray
179
+ } else {
180
+ $choice = Read-Host " 请选择 (1-6, 直接回车跳过)"
181
+
182
+ if ($choice -and $providers.ContainsKey($choice)) {
183
+ $selected = $providers[$choice]
184
+ if ($selected.var) {
185
+ Write-Host ""
186
+ Write-Host " 访问 $($selected.url) 获取 API Key" -ForegroundColor Cyan
187
+ Write-Host " 获取后粘贴到下方" -ForegroundColor Gray
188
+ Write-Host ""
189
+
190
+ $key = Read-Host " 请输入 API Key (输入后回车)"
191
+
192
+ if ($key) {
193
+ # Save to config file
194
+ $configDir = Join-Path $env:USERPROFILE ".thatgfsj"
195
+ if (-not (Test-Path $configDir)) {
196
+ New-Item -ItemType Directory -Path $configDir -Force | Out-Null
197
+ }
198
+
199
+ $configFile = Join-Path $configDir "config.json"
200
+ $config = @{
201
+ model = "Qwen/Qwen2.5-7B-Instruct"
202
+ apiKey = $key
203
+ provider = "siliconflow"
204
+ temperature = 0.7
205
+ maxTokens = 4096
206
+ }
207
+
208
+ # Set provider-specific defaults
209
+ switch ($choice) {
210
+ "1" { $config.provider = "siliconflow"; $config.model = "Qwen/Qwen2.5-7B-Instruct" }
211
+ "2" { $config.provider = "minimax"; $config.model = "MiniMax-M2.5" }
212
+ "3" { $config.provider = "openai"; $config.model = "gpt-4o-mini" }
213
+ "4" { $config.provider = "anthropic"; $config.model = "claude-3-haiku-20240307" }
214
+ "5" { $config.provider = "gemini"; $config.model = "gemini-1.5-flash-8b" }
215
+ }
216
+
217
+ $config | ConvertTo-Json | Set-Content $configFile -Encoding UTF8
218
+ Write-Success "配置已保存到: $configFile"
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ # ============== Done ==============
225
+ Write-Host ""
226
+ Write-Host " ======================================" -ForegroundColor Cyan
227
+ Write-Success " 安装完成!"
228
+ Write-Host " ======================================" -ForegroundColor Cyan
229
+ Write-Host ""
230
+ Write-Host " 使用方法:" -ForegroundColor White
231
+ Write-Host " gfcode init - 重新配置" -ForegroundColor Gray
232
+ Write-Host " gfcode - 启动交互模式" -ForegroundColor Gray
233
+ Write-Host " gfcode '你的问题' - 直接提问" -ForegroundColor Gray
234
+ Write-Host " gfcode explain '代码' - 解释代码" -ForegroundColor Gray
235
+ Write-Host " gfcode debug '代码' - 调试代码" -ForegroundColor Gray
236
+ Write-Host ""
237
+ Write-Host " 文档: https://github.com/Thatgfsj/thatgfsj-code" -ForegroundColor Gray
238
+ Write-Host ""