ai-cli-log 1.0.3 → 1.0.5

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 (49) hide show
  1. package/.ai-cli-log/0001.txt +360 -0
  2. package/.ai-cli-log/0002.txt +1791 -0
  3. package/.ai-cli-log/0003.txt +338 -0
  4. package/.ai-cli-log/0004.txt +116 -0
  5. package/.ai-cli-log/0005.txt +105 -0
  6. package/.ai-cli-log/config.json +32 -0
  7. package/.ai-cli-log/gemini-2025-07-13T13-33-13-a-quick-gemini-test.txt +174 -0
  8. package/.ai-cli-log/gemini-2025-07-13T13-37-00-typescript-check-pass.txt +105 -0
  9. package/.ai-cli-log/gemini-2025-07-13T13-44-15-rename-ai-cli-logs-to-log.txt +164 -0
  10. package/.ai-cli-log/gemini-20250705-154601.txt +1320 -0
  11. package/.ai-cli-log/gemini-20250705-155547.txt +726 -0
  12. package/.ai-cli-log/gemini-20250705-165038.txt +66 -0
  13. package/.ai-cli-log/gemini-20250705-171429.txt +216 -0
  14. package/.ai-cli-log/gemini-20250705-191202.txt +448 -0
  15. package/.ai-cli-log/gemini-20250705-193741.txt +901 -0
  16. package/.ai-cli-log/gemini-20250705-194435.txt +110 -0
  17. package/.ai-cli-log/gemini-20250705-195926.txt +415 -0
  18. package/.ai-cli-log/gemini-20250705-201738.txt +246 -0
  19. package/.ai-cli-log/gemini-20250713-204921.txt +3036 -0
  20. package/.ai-cli-log/gemini-20250713-215941-update-ai-cli-log-documentation.txt +400 -0
  21. package/.ai-cli-log/gemini-20250713-220544-removed-debug-logs-successfully.txt +258 -0
  22. package/.ai-cli-log/gemini-20250713-221128-sessionsummarytxt.txt +112 -0
  23. package/.ai-cli-log/gemini-20250714-084659.txt +86 -0
  24. package/.ai-cli-log/gemini-20250714-085847-update-prompt-configuration.txt +189 -0
  25. package/.ai-cli-log/gemini-20250714-090905-add-sgpt-custom-summarizer.txt +284 -0
  26. package/.ai-cli-log/gemini-20250714-092329.txt +110 -0
  27. package/.ai-cli-log/gemini-20250714-092935.txt +183 -0
  28. package/.ai-cli-log/gemini-20250714-093205-heres-a-concise-summary-of-the-terminal-session-fix-sgpt-option-error-this-captures-1-the-action-fix-2-the-tool-involved-sgpt-3-the-issue-option-error-4-follows-the-requested-lowercase-hyphenated-format.txt +140 -0
  29. package/.ai-cli-log/gemini-20250714-094141-heres-the-concise-summary-build-check-clean-this-captures-1.txt +111 -0
  30. package/.ai-cli-log/gemini-20250714-094405-heres-the-concise-summary-clean-build-check-this-captures-1.txt +111 -0
  31. package/.ai-cli-log/gemini-20250714-094816-json-summary-format.txt +132 -0
  32. package/.ai-cli-log/gemini-20250714-094833-optimize-summary-logic.txt +342 -0
  33. package/.ai-cli-log/gemini-20250714-133202-refactor-config-initialization.txt +1729 -0
  34. package/.ai-cli-log/gemini-20250714-134138-update-summary-logic.txt +153 -0
  35. package/.ai-cli-log/gemini-20250714-134749-json-summary-format.txt +214 -0
  36. package/.ai-cli-log/gemini-20250714-140527.txt +715 -0
  37. package/.ai-cli-log/gemini-20250714-142018.txt +86 -0
  38. package/.ai-cli-log/gemini-20250714-142027-update-summary-format.txt +86 -0
  39. package/.ai-cli-log/gemini-20250714-142100-session-complete.txt +86 -0
  40. package/.ai-cli-log/gemini-20250714-142129-refactor-readme-structure.txt +584 -0
  41. package/.ai-cli-log/gemini-20250714-213153.txt +1195 -0
  42. package/.ai-cli-log/session-20250705-150655.txt +174 -0
  43. package/.ai-cli-log/session-20250705-151726.txt +313 -0
  44. package/.github/workflows/node.js.yml +30 -0
  45. package/GEMINI.md +5 -4
  46. package/README.md +230 -45
  47. package/dist/index.js +368 -71
  48. package/package.json +1 -1
  49. package/src/index.ts +419 -89
package/README.md CHANGED
@@ -10,41 +10,116 @@ npm install -g ai-cli-log
10
10
 
11
11
  ## Usage
12
12
 
13
- Wrap any command with `ai-cli-log` to start a logging session. The session will be saved to a plain text file in the `.ai-cli-logs` directory.
14
-
15
- For example, to log a session with Google's Gemini CLI (`gemini`):
13
+ Wrap any command with `ai-cli-log` to start a logging session.
16
14
 
17
15
  ```bash
18
- ai-cli-log gemini
16
+ ai-cli-log <command> [args...]
19
17
  ```
20
18
 
21
- Or to log a session with another tool, like `claude`:`
22
-
23
- ```bash
24
- ai-cli-log claude
25
- ```
26
-
27
- The recorded session will be saved to a file like `.ai-cli-logs/session-YYYYMMDD-HH:mm:ss.txt`.
19
+ **Examples:**
20
+
21
+ - **Basic Logging:** Record a session with Google's Gemini CLI.
22
+ ```bash
23
+ ai-cli-log gemini
24
+ ```
25
+ *Logs are saved to the `.ai-cli-log/` directory.*
26
+
27
+ - **AI-Powered Filenames:** Use an AI summary for the log's filename.
28
+ ```bash
29
+ ai-cli-log -s <command> [args...]
30
+ # or
31
+ ai-cli-log --with-summary <command> [args...]
32
+ ```
33
+ This will use your default summarizer to generate a descriptive filename like `gemini-20250713-153000-fix-database-connection-error.md`. You can also specify a summarizer: `ai-cli-log -s=my-ollama-summarizer ...`.
34
+
35
+ ## Configuration
36
+
37
+ `ai-cli-log` loads configuration from `config.json` files. It prioritizes a local (project-specific) configuration over the global one.
38
+
39
+ **Loading Order:**
40
+ 1. **Local Configuration**: Looks for `.ai-cli-log/config.json` in the current directory first.
41
+ 2. **Global Configuration**: If no local configuration is found, it falls back to `~/.config/ai-cli-log/config.json`.
42
+
43
+ You can create these files manually or by using the interactive setup command.
44
+
45
+ ### Interactive Setup (`--init`)
46
+
47
+ The `--init` command helps you create a configuration file.
48
+
49
+ * **To create a global configuration:**
50
+ ```bash
51
+ ai-cli-log --init
52
+ ```
53
+ This saves the configuration to `~/.config/ai-cli-log/config.json`.
54
+
55
+ * **To create a local (project-specific) configuration:**
56
+ ```bash
57
+ ai-cli-log --init --local
58
+ ```
59
+ This saves the configuration to `.ai-cli-log/config.json` in the current directory.
60
+
61
+ ### Manual Configuration
62
+
63
+ Here is an example of a manual `config.json`:
64
+
65
+ ```json
66
+ {
67
+ "summarizer": {
68
+ "default": "gemini-pro",
69
+ "summarizers": [
70
+ {
71
+ "name": "gemini-pro",
72
+ "tool": "gemini",
73
+ "prompt": "You are a log summarizer. Your response MUST be a valid JSON object with one key: \"summary\" (a 3-5 word, lowercase, filename-friendly phrase). Example: {\"summary\": \"refactor-database-schema\"}. The session content is:",
74
+ "maxLines": 100
75
+ },
76
+ {
77
+ "name": "ollama",
78
+ "tool": "ollama",
79
+ "model": "llama3",
80
+ "prompt": "You are a log summarizer. Your response MUST be a valid JSON object with one key: \"summary\" (a 3-5 word, lowercase, filename-friendly phrase). Example: {\"summary\": \"refactor-database-schema\"}. The session content is:",
81
+ "maxLines": 50
82
+ },
83
+ {
84
+ "name": "sgpt",
85
+ "tool": "custom",
86
+ "command": ["sgpt", "--chat", "session-summary", "\"{{prompt}}\""]
87
+ },
88
+
89
+ * **To create a global configuration file (at `~/.config/ai-cli-log/config.json`):**
90
+ ```bash
91
+ ai-cli-log --init
92
+ ```
93
+
94
+ * **To create a local, project-specific configuration file (at `.ai-cli-log/config.json`):**
95
+ ```bash
96
+ ai-cli-log --init --local
97
+ ```
98
+
99
+ This command will:
100
+ 1. Scan for available AI tools on your system (like `gemini`, `sgpt`, or `ollama`).
101
+ 2. Guide you through creating summarizer profiles for them.
102
+ 3. Set a default summarizer.
28
103
 
29
104
  ## Features
30
105
 
31
- * **Interactive Session Capture:** Acts as a wrapper for other CLI tools, capturing full interactive sessions, including user input and the "rendered" output (what you actually see on the terminal after backspaces, cursor movements, etc.).
32
- * **Accurate Logging:** Utilizes `node-pty` for pseudo-terminal emulation and `@xterm/headless` to parse ANSI escape codes, ensuring the captured log accurately reflects the final state of the terminal screen.
33
- * **Plain Text Output:** Saves recorded sessions as clean plain text files for easy readability and documentation.
34
- * **TypeScript Implementation:** Built with Node.js and TypeScript, leveraging a robust ecosystem for CLI development and type safety.
106
+ * **Interactive Session Capture:** Faithfully records complex interactive CLI sessions.
107
+ * **AI-Powered Summaries:** Automatically generates descriptive filenames from session content, making logs easy to find and identify.
108
+ * **Accurate Rendering:** Uses `@xterm/headless` to interpret ANSI escape codes, ensuring the log accurately reflects the final terminal state (spinners, progress bars, etc.).
109
+ * **Configurable:** Supports different AI backends (`gemini`, `sgpt`, `ollama`, etc.) for generating summaries.
110
+ * **Performance-Aware:** When summarizing long sessions, it intelligently samples the beginning and end of the output to ensure fast and cost-effective summary generation.
111
+ * **Markdown Output:** Saves sessions as clean Markdown files.
35
112
 
36
113
  ## Development Notes
37
114
 
38
- This project was generated with the assistance of Google Gemini. You can review the detailed development process and interactions in the `.ai-cli-logs` directory, specifically starting with `0001.md` and subsequent log files.
115
+ This project was generated with the assistance of Google Gemini. You can review the detailed development process and interactions in the `.ai-cli-log` directory, specifically starting with `0001.txt` and subsequent log files.
39
116
 
40
117
  Special thanks to Gemini for its invaluable help in the development of this tool!
41
118
 
42
119
  ## TODO
43
120
 
44
- * **Content Handling:**
45
- * Empty log files are now prevented from being saved when the session output is blank or contains only whitespace.
46
- * Trailing whitespace and blank lines are now trimmed from the output to address issues where insufficient content led to large blank areas.
47
- * **Filename Convention:** The current timestamp-based filenames are functional but can be monotonous. Evaluate alternatives for more descriptive filenames, while carefully considering potential information leakage if AI summarization were to be used for naming.
121
+ * **Argument Parsing:** Refactor the manual argument parsing to use a robust library like `yargs` or `commander` to improve maintainability and provide standard features like `--help`.
122
+ * **Markdown Support:** Investigate and potentially implement saving logs in Markdown format, which could include session metadata (e.g., command, timestamp, summary) in a frontmatter block.
48
123
 
49
124
  ---
50
125
 
@@ -60,47 +135,156 @@ npm install -g ai-cli-log
60
135
 
61
136
  ## 使用方法
62
137
 
63
- 使用 `ai-cli-log` 命令来包装任何您想记录的命令。会话日志将被保存到当前目录下的 `.ai-cli-logs` 文件夹中。
64
-
65
- 例如,记录与 Google Gemini CLI (`gemini`) 的会话:
138
+ 使用 `ai-cli-log` 命令来包装任何您想记录的命令。
66
139
 
67
140
  ```bash
68
- ai-cli-log gemini
141
+ ai-cli-log <command> [args...]
69
142
  ```
70
143
 
71
- 或者记录与其他工具(如 `claude`)的会话:
144
+ **示例:**
145
+
146
+ - **基本日志记录:** 记录与 Google Gemini CLI 的会话。
147
+ ```bash
148
+ ai-cli-log gemini
149
+ ```
150
+ *日志将保存到 `.ai-cli-log/` 目录中。*
151
+
152
+ - **AI 驱动的文件名:** 使用 AI 摘要作为日志文件名。
153
+ ```bash
154
+ ai-cli-log -s <命令> [参数...]
155
+ # 或
156
+ ai-cli-log --with-summary <命令> [参数...]
157
+ ```
158
+ 这将使用您的默认摘要器生成一个描述性的文件名,例如 `gemini-20250713-153000-fix-database-connection-error.md`。您也可以指定一个摘要器:`ai-cli-log -s=my-ollama-summarizer ...`。
159
+
160
+ ## 配置
161
+
162
+ `ai-cli-log` 从 `config.json` 文件中加载配置。它会优先使用本地(项目特定)的配置,其次是全局配置。
163
+
164
+ **加载顺序:**
165
+ 1. **本地配置**: 首先在当前目录中查找 `.ai-cli-log/config.json`。
166
+ 2. **全局配置**: 如果未找到本地配置,则会使用 `~/.config/ai-cli-log/config.json`。
167
+
168
+ 您可以通过手动或使用交互式设置命令来创建这些文件。
169
+
170
+ ### 交互式设置 (`--init`)
171
+
172
+ `--init` 命令可以帮助您创建配置文件。
173
+
174
+ * **创建全局配置文件:**
175
+ ```bash
176
+ ai-cli-log --init
177
+ ```
178
+ 这会将配置保存到 `~/.config/ai-cli-log/config.json`。
179
+
180
+ * **创建本地(项目特定)配置文件:**
181
+ ```bash
182
+ ai-cli-log --init --local
183
+ ```
184
+ 这会将配置保存到当前目录的 `.ai-cli-log/config.json` 中。
185
+
186
+ ### 手动配置
187
+
188
+ 这是一个手动创建 `config.json` 的示例:
189
+
190
+ ```json
191
+ {
192
+ "summarizer": {
193
+ "default": "gemini-pro",
194
+ "summarizers": [
195
+ {
196
+ "name": "gemini-pro",
197
+ "tool": "gemini",
198
+ "prompt": "你是一个日志摘要器。你的响应必须是一个有效的 JSON 对象,其中包含一个键:"summary"(一个 3-5 个单词的、小写的、文件名友好的短语)。示例:{"summary": "refactor-database-schema"}。会话内容是:",
199
+ "maxLines": 100
200
+ },
201
+ {
202
+ "name": "ollama",
203
+ "tool": "ollama",
204
+ "model": "llama3",
205
+ "prompt": "你是一个日志摘要器。你的响应必须是一个有效的 JSON 对象,其中包含一个键:"summary"(一个 3-5 个单词的、小写的、文件名友好的短语)。示例:{"summary": "refactor-database-schema"}。会话内容是:",
206
+ "maxLines": 50
207
+ },
208
+ {
209
+ "name": "sgpt",
210
+ "tool": "custom",
211
+ "command": ["sgpt", "--chat", "session-summary", ""{{prompt}}""],
212
+ "prompt": "你是一个日志摘要器。你的响应必须是一个有效的 JSON 对象,其中包含一个键:"summary"(一个 3-5 个单词的、小写的、文件名友好的短语)。示例:{"summary": "refactor-database-schema"}。会话内容是:",
213
+ "maxLines": 100
214
+ },
215
+ {
216
+ "name": "my-custom-summarizer",
217
+ "tool": "custom",
218
+ "command": ["my-summarizer-script", "--prompt", "{{prompt}}"],
219
+ "prompt": "You are a log summarizer. Your response MUST be a valid JSON object with one key: \"summary\" (a 3-5 word, lowercase, filename-friendly phrase). Example: {\"summary\": \"refactor-database-schema\"}. The session content is:",
220
+ "maxLines": 200
221
+ }
222
+ ]
223
+ }
224
+ }
225
+ ```
72
226
 
73
- ```bash
74
- ai-cli-log claude
227
+ **字段说明:**
228
+
229
+ * `summarizer.default` (可选): 默认使用的摘要器配置名称。
230
+ * `summarizer.summarizers`: 包含不同摘要器配置的数组。
231
+ * **`name`**: 您为摘要器配置指定的唯一名称 (例如, `gemini-pro`, `ollama`, `claude-opus`, `my-custom-summarizer`)。
232
+ * **`tool`**: 指定摘要器使用的工具类型。
233
+ * `gemini`: 使用 `gemini` CLI 工具。
234
+ * `ollama`: 使用 `ollama` CLI 工具。
235
+ * `claude`: 使用 `claude` CLI 工具。
236
+ * `custom`: 使用自定义命令。
237
+ * **`model`** (可选): 对于 `ollama` 工具,指定要使用的模型名称 (例如, `llama3`)。
238
+ * **`prompt`**: 传递给摘要器命令的提示。会话内容将作为标准输入传递。
239
+ * **`maxLines`** (可选): 限制传递给摘要器的会话内容行数。如果会话内容超过此限制,将只采样开头和结尾的行。
240
+ * **`command`** (可选): 对于 `custom` 工具,指定要执行的命令数组。会话内容会通过管道传递给该命令的 `stdin`。`{{prompt}}` 占位符将被实际的提示字符串替换。例如: `["my-summarizer-script", "--prompt", "{{prompt}}"]`。
241
+ * **重要**: 摘要器的输出**必须**是一个有效的 JSON 对象,其中包含一个名为 `summary` 的键(例如,`{"summary": "你的摘要短语"}`)。
75
242
  ```
76
243
 
77
- 记录的会话将保存为类似 `.ai-cli-logs/session-YYYYMMDD-HH:mm:ss.txt` 的文件。
244
+ **Field Descriptions:**
78
245
 
79
- ## 快捷提示:使用别名
246
+ * `summarizer.default` (optional): The name of the default summarizer configuration to use.
247
+ * `summarizer.summarizers`: An array of different summarizer configurations.
248
+ * **`name`**: A unique name you give to the summarizer configuration (e.g., `gemini-pro`, `ollama`, `claude-opus`, `my-custom-summarizer`).
249
+ * **`tool`**: The type of tool the summarizer uses.
250
+ * `gemini`: Uses the `gemini` CLI tool.
251
+ * `ollama`: Uses the `ollama` CLI tool.
252
+ * `claude`: Uses the `claude` CLI tool.
253
+ * `custom`: Uses a custom command.
254
+ * **`model`** (optional): For the `ollama` tool, specifies the model name to use (e.g., `llama3`).
255
+ * **`prompt`**: The prompt passed to the summarizer command. The session content will be passed as standard input.
256
+ * **`maxLines`** (optional): Limits the number of session content lines passed to the summarizer. If the session exceeds this limit, only the beginning and end lines will be sampled.
257
+ * **`command`** (optional): For the `custom` tool, specifies the command array to execute. The session content is piped to this command's `stdin`. The `{{prompt}}` placeholder will be replaced with the actual prompt string. Example: `["my-summarizer-script", "--prompt", "{{prompt}}"]`.
258
+ * **Important**: The output from the summarizer **MUST** be a valid JSON object containing a key named `summary` (e.g., `{"summary": "your-summary-phrase"}`).
80
259
 
81
- 为了简化您的工作流程,您可以为常用命令创建 shell 别名。例如,快速记录您的 Gemini CLI 会话:
260
+ ### 交互式设置 (`--init`)
82
261
 
83
- ```bash
84
- alias gemini-log='ai-cli-log gemini'
85
- # 将此行添加到您的 shell 配置文件中(例如 ~/.bashrc, ~/.zshrc)
86
- ```
262
+ 运行交互式设置来创建配置文件。
87
263
 
88
- 然后,您只需运行:
264
+ * **创建全局配置文件 (位于 `~/.config/ai-cli-log/config.json`):**
265
+ ```bash
266
+ ai-cli-log --init
267
+ ```
89
268
 
90
- ```bash
91
- gemini-log
92
- ```
269
+ * **创建本地、项目特定的配置文件 (位于 `.ai-cli-log/config.json`):**
270
+ ```bash
271
+ ai-cli-log --init --local
272
+ ```
273
+
274
+ 该命令将引导您完成配置过程,包括扫描可用的 AI 工具、创建摘要器配置和设置默认摘要器。
93
275
 
94
276
  ## 功能特性
95
277
 
96
- * **交互式会话捕获:** 作为其他 CLI 工具的包装器,能够捕获完整的交互式会话,包括用户输入和最终“渲染”在屏幕上的输出(即处理了退格、光标移动等控制字符后的真实显示内容)。
97
- * **精确日志记录:** 利用 `node-pty` 进行伪终端模拟,并结合 `@xterm/headless` 解析 ANSI 转义码,确保日志精确还原终端的最终显示状态。
98
- * **纯文本输出:** 将会话保存为干净、易读的纯文本文件,方便查阅和整理。
99
- * **TypeScript 实现:** 基于 Node.js 和 TypeScript 构建,确保了代码的健壮性和类型安全。
278
+ * **交互式会话捕获:** 忠实地记录复杂的交互式 CLI 会话。
279
+ * **AI 驱动的摘要:** 从会话内容中自动生成描述性文件名,使日志易于查找和识别。
280
+ * **精确渲染:** 使用 `@xterm/headless` 解释 ANSI 转义码,确保日志准确反映最终的终端状态(如加载动画、进度条等)。
281
+ * **可配置:** 支持不同的 AI 后端(`gemini`、`sgpt`、`ollama` 等)用于生成摘要。
282
+ * **性能感知:** 在总结长会话时,它会智能地抽样输出的开头和结尾,以确保快速且经济高效地生成摘要。
283
+ * **纯文本输出:** 将会话保存为清晰的纯文本文档。
100
284
 
101
285
  ## 开发说明
102
286
 
103
- 本项目是在 Google Gemini 的协助下生成的。您可以在 `.ai-cli-logs` 目录中查看详细的开发过程和交互记录,特别是从 `0001.md` 开始的日志文件。
287
+ 本项目是在 Google Gemini 的协助下生成的。您可以在 `.ai-cli-log` 目录中查看详细的开发过程和交互记录,特别是从 `0001.txt` 开始的日志文件。
104
288
 
105
289
  特别感谢 Gemini 在本项目开发过程中提供的宝贵帮助!
106
290
 
@@ -108,5 +292,6 @@ gemini-log
108
292
 
109
293
  * **内容处理:**
110
294
  * 当会话输出为空时,避免保存空的日志文件。
111
- * 解决内容不足导致输出中出现大片空白的问题。
112
- * **文件名约定:** 当前基于时间戳的文件名虽然功能上可行,但可能过于单调。评估其他更具描述性的文件名方案,同时仔细考虑如果使用 AI 摘要进行命名可能导致的信息泄露问题。
295
+ * 尾随空格和空行现在已从输出中删除,以解决内容不足导致大片空白区域的问题。
296
+ * **文件名约定:** 当前基于时间戳的文件名虽然功能上可行,但可能过于单调。评估其他更具描述性的文件名方案,同时仔细考虑如果使用 AI 摘要进行命名可能导致的信息泄露问题。
297
+