ngpt 3.7.0__tar.gz → 3.8.0__tar.gz

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 (59) hide show
  1. {ngpt-3.7.0 → ngpt-3.8.0}/PKG-INFO +27 -10
  2. {ngpt-3.7.0 → ngpt-3.8.0}/README.md +26 -9
  3. {ngpt-3.7.0 → ngpt-3.8.0}/docs/configuration.md +9 -9
  4. {ngpt-3.7.0 → ngpt-3.8.0}/docs/examples/advanced.md +123 -1
  5. {ngpt-3.7.0 → ngpt-3.8.0}/docs/examples/basic.md +59 -1
  6. {ngpt-3.7.0 → ngpt-3.8.0}/docs/overview.md +14 -2
  7. {ngpt-3.7.0 → ngpt-3.8.0}/docs/usage/cli_usage.md +66 -9
  8. {ngpt-3.7.0 → ngpt-3.8.0}/docs/usage/gitcommsg.md +93 -0
  9. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/args.py +7 -3
  10. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/main.py +1 -8
  11. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/chat.py +13 -36
  12. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/code.py +5 -1
  13. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/gitcommsg.py +69 -4
  14. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/rewrite.py +9 -6
  15. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/shell.py +5 -1
  16. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/utils/__init__.py +3 -1
  17. ngpt-3.8.0/ngpt/utils/pipe.py +52 -0
  18. {ngpt-3.7.0 → ngpt-3.8.0}/pyproject.toml +1 -1
  19. {ngpt-3.7.0 → ngpt-3.8.0}/uv.lock +1 -1
  20. {ngpt-3.7.0 → ngpt-3.8.0}/.github/workflows/aur-publish.yml +0 -0
  21. {ngpt-3.7.0 → ngpt-3.8.0}/.github/workflows/python-publish.yml +0 -0
  22. {ngpt-3.7.0 → ngpt-3.8.0}/.gitignore +0 -0
  23. {ngpt-3.7.0 → ngpt-3.8.0}/.python-version +0 -0
  24. {ngpt-3.7.0 → ngpt-3.8.0}/COMMIT_GUIDELINES.md +0 -0
  25. {ngpt-3.7.0 → ngpt-3.8.0}/CONTRIBUTING.md +0 -0
  26. {ngpt-3.7.0 → ngpt-3.8.0}/LICENSE +0 -0
  27. {ngpt-3.7.0 → ngpt-3.8.0}/PKGBUILD +0 -0
  28. {ngpt-3.7.0 → ngpt-3.8.0}/docs/CONTRIBUTING.md +0 -0
  29. {ngpt-3.7.0 → ngpt-3.8.0}/docs/LICENSE.md +0 -0
  30. {ngpt-3.7.0 → ngpt-3.8.0}/docs/_config.yml +0 -0
  31. {ngpt-3.7.0 → ngpt-3.8.0}/docs/_sass/custom/custom.scss +0 -0
  32. {ngpt-3.7.0 → ngpt-3.8.0}/docs/examples.md +0 -0
  33. {ngpt-3.7.0 → ngpt-3.8.0}/docs/index.md +0 -0
  34. {ngpt-3.7.0 → ngpt-3.8.0}/docs/installation.md +0 -0
  35. {ngpt-3.7.0 → ngpt-3.8.0}/docs/usage/cli_config.md +0 -0
  36. {ngpt-3.7.0 → ngpt-3.8.0}/docs/usage/web_search.md +0 -0
  37. {ngpt-3.7.0 → ngpt-3.8.0}/docs/usage.md +0 -0
  38. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/__init__.py +0 -0
  39. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/__main__.py +0 -0
  40. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/__init__.py +0 -0
  41. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/config_manager.py +0 -0
  42. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/formatters.py +0 -0
  43. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/__init__.py +0 -0
  44. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/interactive.py +0 -0
  45. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/modes/text.py +0 -0
  46. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/renderers.py +0 -0
  47. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/cli/ui.py +0 -0
  48. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/client.py +0 -0
  49. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/utils/cli_config.py +0 -0
  50. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/utils/config.py +0 -0
  51. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/utils/log.py +0 -0
  52. {ngpt-3.7.0 → ngpt-3.8.0}/ngpt/utils/web_search.py +0 -0
  53. {ngpt-3.7.0 → ngpt-3.8.0}/previews/ngpt-g.png +0 -0
  54. {ngpt-3.7.0 → ngpt-3.8.0}/previews/ngpt-i.png +0 -0
  55. {ngpt-3.7.0 → ngpt-3.8.0}/previews/ngpt-s-c.png +0 -0
  56. {ngpt-3.7.0 → ngpt-3.8.0}/previews/ngpt-sh-c-a.png +0 -0
  57. {ngpt-3.7.0 → ngpt-3.8.0}/previews/ngpt-w-self.png +0 -0
  58. {ngpt-3.7.0 → ngpt-3.8.0}/previews/ngpt-w.png +0 -0
  59. {ngpt-3.7.0 → ngpt-3.8.0}/wiki.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngpt
3
- Version: 3.7.0
3
+ Version: 3.8.0
4
4
  Summary: Swiss army knife for LLMs: powerful CLI and interactive chatbot in one package. Seamlessly work with OpenAI, Ollama, Groq, Claude, Gemini, or any OpenAI-compatible API to generate code, craft git commits, rewrite text, and execute shell commands.
5
5
  Project-URL: Homepage, https://github.com/nazdridoy/ngpt
6
6
  Project-URL: Repository, https://github.com/nazdridoy/ngpt
@@ -150,7 +150,19 @@ ngpt --code --stream-prettify "function to calculate the Fibonacci sequence"
150
150
  ngpt --shell "list all files in the current directory"
151
151
 
152
152
  # Read from stdin and use the content in your prompt
153
- echo "What is this text about?" | ngpt -p "Analyze the following text: {}"
153
+ echo "What is this text about?" | ngpt --pipe "Analyze the following text: {}"
154
+
155
+ # Using here-string (<<<) for quick single-line input
156
+ ngpt --pipe {} <<< "What is the best way to learn shell redirects?"
157
+
158
+ # Using standard input redirection to process file contents
159
+ ngpt --pipe "summarise {}" < README.md
160
+
161
+ # Using here-document (<<EOF) for multiline input
162
+ ngpt --pipe {} << EOF
163
+ What is the best way to learn Golang?
164
+ Provide simple hello world example.
165
+ EOF
154
166
 
155
167
  # Rewrite text to improve quality while preserving tone and meaning
156
168
  echo "your text" | ngpt -r
@@ -173,6 +185,9 @@ ngpt -g --rec-chunk
173
185
  # Process a diff file instead of staged changes
174
186
  ngpt -g --diff /path/to/changes.diff
175
187
 
188
+ # Use piped diff content for commit message generation
189
+ git diff HEAD~1 | ngpt -g --pipe
190
+
176
191
  # Generate a commit message with logging for debugging
177
192
  ngpt -g --log commit_log.txt
178
193
 
@@ -201,7 +216,7 @@ ngpt --interactive --log conversation.log
201
216
  ngpt --log "Tell me about quantum computing"
202
217
 
203
218
  # Process text from stdin using the {} placeholder
204
- cat README.md | ngpt -p "Summarize this document: {}"
219
+ cat README.md | ngpt --pipe "Summarize this document: {}"
205
220
 
206
221
  # Use different model providers by specifying the provider name
207
222
  ngpt --provider Groq "Explain quantum computing"
@@ -249,13 +264,14 @@ For more examples and detailed usage, visit the [CLI Usage Guide](https://nazdri
249
264
 
250
265
  ```console
251
266
  ❯ ngpt -h
267
+
252
268
  usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index CONFIG_INDEX] [--provider PROVIDER]
253
269
  [--remove] [--show-config] [--all] [--list-models] [--list-renderers] [--cli-config [COMMAND ...]]
254
- [--api-key API_KEY] [--base-url BASE_URL] [--model MODEL] [--web-search] [--temperature TEMPERATURE]
255
- [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT] [--no-stream | --prettify |
256
- --stream-prettify] [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]] [--chunk-size CHUNK_SIZE]
257
- [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
258
- [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t | -p | -r | -g]
270
+ [--api-key API_KEY] [--base-url BASE_URL] [--model MODEL] [--web-search] [--pipe]
271
+ [--temperature TEMPERATURE] [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT]
272
+ [--no-stream | --prettify | --stream-prettify] [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]]
273
+ [--chunk-size CHUNK_SIZE] [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
274
+ [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t | -r | -g]
259
275
  [prompt]
260
276
 
261
277
  nGPT - Interact with AI language models via OpenAI-compatible APIs
@@ -288,6 +304,7 @@ Global Options::
288
304
  --base-url BASE_URL Base URL for the API
289
305
  --model MODEL Model to use
290
306
  --web-search Enable web search capability using DuckDuckGo to enhance prompts with relevant information
307
+ --pipe Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content. Can be used with any mode option except --text and --interactive
291
308
  --temperature TEMPERATURE Set temperature (controls randomness, default: 0.7)
292
309
  --top_p TOP_P Set top_p (controls diversity, default: 1.0)
293
310
  --max_tokens MAX_TOKENS Set max response length in tokens
@@ -308,7 +325,7 @@ Git Commit Message Options::
308
325
  --chunk-size CHUNK_SIZE Number of lines per chunk when chunking is enabled (default: 200)
309
326
  --analyses-chunk-size ANALYSES_CHUNK_SIZE Number of lines per chunk when recursively chunking analyses (default: 200)
310
327
  --max-msg-lines MAX_MSG_LINES Maximum number of lines in commit message before condensing (default: 20)
311
- --max-recursion-depth MAX_RECURSION_DEPTH Maximum recursion depth for commit message condensing (default: 3)
328
+ --max-recursion-depth MAX_RECURSION_DEPTH Maximum recursion depth for commit message condensing (default: 3)
312
329
 
313
330
  Modes (mutually exclusive)::
314
331
 
@@ -316,9 +333,9 @@ Modes (mutually exclusive)::
316
333
  -s, --shell Generate and execute shell commands
317
334
  -c, --code Generate code
318
335
  -t, --text Enter multi-line text input (submit with Ctrl+D)
319
- -p, --pipe Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content
320
336
  -r, --rewrite Rewrite text from stdin to be more natural while preserving tone and meaning
321
337
  -g, --gitcommsg Generate AI-powered git commit messages from staged changes or diff file
338
+
322
339
  ```
323
340
 
324
341
  > **Note**: For better visualization of conventional commit messages on GitHub, you can use the [GitHub Commit Labels](https://greasyfork.org/en/scripts/526153-github-commit-labels) userscript, which adds colorful labels to your commits.
@@ -113,7 +113,19 @@ ngpt --code --stream-prettify "function to calculate the Fibonacci sequence"
113
113
  ngpt --shell "list all files in the current directory"
114
114
 
115
115
  # Read from stdin and use the content in your prompt
116
- echo "What is this text about?" | ngpt -p "Analyze the following text: {}"
116
+ echo "What is this text about?" | ngpt --pipe "Analyze the following text: {}"
117
+
118
+ # Using here-string (<<<) for quick single-line input
119
+ ngpt --pipe {} <<< "What is the best way to learn shell redirects?"
120
+
121
+ # Using standard input redirection to process file contents
122
+ ngpt --pipe "summarise {}" < README.md
123
+
124
+ # Using here-document (<<EOF) for multiline input
125
+ ngpt --pipe {} << EOF
126
+ What is the best way to learn Golang?
127
+ Provide simple hello world example.
128
+ EOF
117
129
 
118
130
  # Rewrite text to improve quality while preserving tone and meaning
119
131
  echo "your text" | ngpt -r
@@ -136,6 +148,9 @@ ngpt -g --rec-chunk
136
148
  # Process a diff file instead of staged changes
137
149
  ngpt -g --diff /path/to/changes.diff
138
150
 
151
+ # Use piped diff content for commit message generation
152
+ git diff HEAD~1 | ngpt -g --pipe
153
+
139
154
  # Generate a commit message with logging for debugging
140
155
  ngpt -g --log commit_log.txt
141
156
 
@@ -164,7 +179,7 @@ ngpt --interactive --log conversation.log
164
179
  ngpt --log "Tell me about quantum computing"
165
180
 
166
181
  # Process text from stdin using the {} placeholder
167
- cat README.md | ngpt -p "Summarize this document: {}"
182
+ cat README.md | ngpt --pipe "Summarize this document: {}"
168
183
 
169
184
  # Use different model providers by specifying the provider name
170
185
  ngpt --provider Groq "Explain quantum computing"
@@ -212,13 +227,14 @@ For more examples and detailed usage, visit the [CLI Usage Guide](https://nazdri
212
227
 
213
228
  ```console
214
229
  ❯ ngpt -h
230
+
215
231
  usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index CONFIG_INDEX] [--provider PROVIDER]
216
232
  [--remove] [--show-config] [--all] [--list-models] [--list-renderers] [--cli-config [COMMAND ...]]
217
- [--api-key API_KEY] [--base-url BASE_URL] [--model MODEL] [--web-search] [--temperature TEMPERATURE]
218
- [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT] [--no-stream | --prettify |
219
- --stream-prettify] [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]] [--chunk-size CHUNK_SIZE]
220
- [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
221
- [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t | -p | -r | -g]
233
+ [--api-key API_KEY] [--base-url BASE_URL] [--model MODEL] [--web-search] [--pipe]
234
+ [--temperature TEMPERATURE] [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT]
235
+ [--no-stream | --prettify | --stream-prettify] [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]]
236
+ [--chunk-size CHUNK_SIZE] [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
237
+ [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t | -r | -g]
222
238
  [prompt]
223
239
 
224
240
  nGPT - Interact with AI language models via OpenAI-compatible APIs
@@ -251,6 +267,7 @@ Global Options::
251
267
  --base-url BASE_URL Base URL for the API
252
268
  --model MODEL Model to use
253
269
  --web-search Enable web search capability using DuckDuckGo to enhance prompts with relevant information
270
+ --pipe Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content. Can be used with any mode option except --text and --interactive
254
271
  --temperature TEMPERATURE Set temperature (controls randomness, default: 0.7)
255
272
  --top_p TOP_P Set top_p (controls diversity, default: 1.0)
256
273
  --max_tokens MAX_TOKENS Set max response length in tokens
@@ -271,7 +288,7 @@ Git Commit Message Options::
271
288
  --chunk-size CHUNK_SIZE Number of lines per chunk when chunking is enabled (default: 200)
272
289
  --analyses-chunk-size ANALYSES_CHUNK_SIZE Number of lines per chunk when recursively chunking analyses (default: 200)
273
290
  --max-msg-lines MAX_MSG_LINES Maximum number of lines in commit message before condensing (default: 20)
274
- --max-recursion-depth MAX_RECURSION_DEPTH Maximum recursion depth for commit message condensing (default: 3)
291
+ --max-recursion-depth MAX_RECURSION_DEPTH Maximum recursion depth for commit message condensing (default: 3)
275
292
 
276
293
  Modes (mutually exclusive)::
277
294
 
@@ -279,9 +296,9 @@ Modes (mutually exclusive)::
279
296
  -s, --shell Generate and execute shell commands
280
297
  -c, --code Generate code
281
298
  -t, --text Enter multi-line text input (submit with Ctrl+D)
282
- -p, --pipe Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content
283
299
  -r, --rewrite Rewrite text from stdin to be more natural while preserving tone and meaning
284
300
  -g, --gitcommsg Generate AI-powered git commit messages from staged changes or diff file
301
+
285
302
  ```
286
303
 
287
304
  > **Note**: For better visualization of conventional commit messages on GitHub, you can use the [GitHub Commit Labels](https://greasyfork.org/en/scripts/526153-github-commit-labels) userscript, which adds colorful labels to your commits.
@@ -145,13 +145,13 @@ The interactive configuration will prompt you for values and guide you through t
145
145
  You can set configuration options directly via command-line arguments:
146
146
 
147
147
  ```
148
- usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index CONFIG_INDEX] [--provider PROVIDER] [--remove]
149
- [--show-config] [--all] [--list-models] [--list-renderers] [--cli-config [COMMAND ...]] [--api-key API_KEY]
150
- [--base-url BASE_URL] [--model MODEL] [--web-search] [--temperature TEMPERATURE] [--top_p TOP_P]
151
- [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT] [--no-stream | --prettify | --stream-prettify]
152
- [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]] [--chunk-size CHUNK_SIZE]
153
- [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
154
- [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t |-p | -r | -g]
148
+ usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index CONFIG_INDEX] [--provider PROVIDER]
149
+ [--remove] [--show-config] [--all] [--list-models] [--list-renderers] [--cli-config [COMMAND ...]]
150
+ [--api-key API_KEY] [--base-url BASE_URL] [--model MODEL] [--web-search] [--pipe]
151
+ [--temperature TEMPERATURE] [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT]
152
+ [--no-stream | --prettify | --stream-prettify] [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]]
153
+ [--chunk-size CHUNK_SIZE] [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
154
+ [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t | -r | -g]
155
155
  [prompt]
156
156
  ```
157
157
 
@@ -211,7 +211,7 @@ usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index
211
211
  - `-s, --shell`: Generate and execute shell commands
212
212
  - `-c, --code`: Generate code
213
213
  - `-t, --text`: Enter multi-line text input (submit with Ctrl+D)
214
- - `-p, --pipe`: Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content
214
+ - `--pipe`: Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content. Can be used with any mode option except --text and --interactive.
215
215
  - `-r, --rewrite`: Rewrite text from stdin to be more natural while preserving tone and meaning
216
216
  - `-g, --gitcommsg`: Generate AI-powered git commit messages from staged changes or diff file
217
217
 
@@ -240,7 +240,7 @@ ngpt --interactive --log conversation.log
240
240
  ngpt --log "Tell me about quantum computing"
241
241
 
242
242
  # Process text from stdin using the {} placeholder
243
- echo "What is this text about?" | ngpt -p "Analyze the following text: {}"
243
+ echo "What is this text about?" | ngpt --pipe "Analyze the following text: {}"
244
244
 
245
245
  # Generate git commit message from staged changes
246
246
  ngpt -g
@@ -45,7 +45,7 @@ Use detailed, structured system prompts to create specific behaviors:
45
45
 
46
46
  ```bash
47
47
  # Create a detailed prompt from a file
48
- cat structured_prompt.txt | ngpt -i --pipe "--preprompt {}"
48
+ cat structured_prompt.txt | ngpt --pipe "--preprompt {}"
49
49
 
50
50
  # Technical review prompt
51
51
  ngpt --preprompt "Act as a senior software engineer reviewing my code.
@@ -192,6 +192,128 @@ cat api_docs.txt | ngpt --pipe "Enhance this API documentation with better expla
192
192
  cat product_descriptions.txt | ngpt --pipe "Improve these product descriptions by adding more vivid language, highlighting unique features, and addressing common customer pain points: {}"
193
193
  ```
194
194
 
195
+ ## Advanced Pipe Processing Workflows
196
+
197
+ The `--pipe` flag enables sophisticated data processing pipelines when combined with other tools and modes. Here are advanced workflows that leverage piped content:
198
+
199
+ ### Shell Redirection with Pipe
200
+
201
+ nGPT works seamlessly with various shell redirection techniques for flexible input handling:
202
+
203
+ ```bash
204
+ # Using here-string (<<<) for quick single-line input
205
+ ngpt --pipe {} <<< "What is the best way to learn shell redirects?"
206
+
207
+ # Using standard input redirection to process file contents
208
+ ngpt --pipe "summarise {}" < README.md
209
+
210
+ # Using here-document (<<EOF) for multiline input
211
+ ngpt --pipe {} << EOF
212
+ What is the best way to learn Golang?
213
+ Provide simple hello world example.
214
+ EOF
215
+ ```
216
+
217
+ ### Multi-Stage Processing Pipelines
218
+
219
+ Create complex processing chains that transform data through multiple steps:
220
+
221
+ ```bash
222
+ # Multi-stage code transformation
223
+ # Extract functions, optimize them, then add tests
224
+ grep -r "function" src/ |
225
+ ngpt --pipe "Extract all JavaScript function definitions from this code: {}" |
226
+ ngpt --code --pipe "Optimize these functions for performance: {}" |
227
+ ngpt --code --pipe "Write comprehensive unit tests for these optimized functions: {}" > test_suite.js
228
+
229
+ # Log analysis workflow
230
+ # Extract errors, analyze patterns, then generate fix suggestions
231
+ grep -i "error" system.log |
232
+ ngpt --pipe "Extract and categorize all errors by type: {}" |
233
+ ngpt --pipe "Analyze these error categories and identify common patterns: {}" |
234
+ ngpt --pipe "Recommend fixes for the most common error patterns: {}" > error_remediation.md
235
+ ```
236
+
237
+ ### Mode-Specific Advanced Techniques
238
+
239
+ #### Advanced Code Mode with Pipe
240
+
241
+ ```bash
242
+ # API Integration
243
+ # Generate wrapper code for a REST API described in documentation
244
+ curl -s https://api.example.com/docs |
245
+ ngpt --pipe "Extract all API endpoints, parameters and response formats from this documentation: {}" |
246
+ ngpt --code --language typescript --pipe "Create TypeScript interface definitions for these API resources: {}" > api-types.ts
247
+
248
+ # Code transformation with context
249
+ # Refactor legacy code to modern standards with context
250
+ cat legacy-component.js |
251
+ ngpt --code --language javascript --preprompt "You are refactoring legacy React class components to modern functional components with hooks" --pipe "Refactor this legacy component, preserving all functionality: {}" > modern-component.js
252
+ ```
253
+
254
+ #### Advanced Shell Mode with Pipe
255
+
256
+ ```bash
257
+ # Complex data processing command generation
258
+ # Generate a command to process a complex data structure
259
+ jq -r '.items[] | .metadata' complex_data.json |
260
+ ngpt --shell --pipe "Generate a command to extract all unique values of the 'region' field, count occurrences of each, sort by count in descending order, and save to regions.csv with headers 'Region,Count': {}"
261
+
262
+ # Dynamic script generation
263
+ # Generate a data cleanup script based on analysis
264
+ cat messy_data.csv |
265
+ ngpt --pipe "Analyze this CSV data and identify all data quality issues: {}" |
266
+ ngpt --shell --pipe "Create a bash script that cleans up all these data quality issues: {}" > cleanup_data.sh
267
+ ```
268
+
269
+ #### Advanced Rewrite Mode with Pipe
270
+
271
+ ```bash
272
+ # Targeted content update
273
+ # Extract, update, and replace specific sections of a document
274
+ grep -A20 "## Installation" README.md |
275
+ ngpt --rewrite --pipe "Update this installation guide to include Docker setup instructions while maintaining the existing style: {}" |
276
+ sed -i '/## Installation/,+20c\' README.md
277
+
278
+ # Feedback-based improvement
279
+ # Incorporate reviewer feedback into documentation
280
+ cat reviewer_comments.txt |
281
+ ngpt --pipe "Extract all actionable feedback points: {}" |
282
+ cat docs.md - |
283
+ ngpt --rewrite --pipe "Update this documentation to address all the feedback points listed at the end: {}" > improved_docs.md
284
+ ```
285
+
286
+ ### Working with Structured Data
287
+
288
+ Process and transform structured data through pipe workflows:
289
+
290
+ ```bash
291
+ # JSON transformation and enhancement
292
+ cat data.json |
293
+ jq '.items' |
294
+ ngpt --pipe "Convert this JSON data to a markdown table with headers from the field names: {}" > data_table.md
295
+
296
+ # Log data extraction and analysis
297
+ cat server_logs.txt |
298
+ grep -i "error" |
299
+ ngpt --pipe "Extract timestamp, error code, and message from each line and format as a CSV: {}" |
300
+ ngpt --pipe "Analyze this error data and identify trends by time of day and error type: {}" > error_analysis.md
301
+ ```
302
+
303
+ ### Git-Specific Pipe Workflows
304
+
305
+ Leverage git command output with pipe processing:
306
+
307
+ ```bash
308
+ # Commit history analysis
309
+ git log --author="username" --since="1 month ago" --pretty=format:"%h %s" |
310
+ ngpt --pipe "Analyze this commit history and summarize this developer's work focus and productivity patterns: {}" > developer_report.md
311
+
312
+ # PR summary generation
313
+ git diff origin/main..HEAD |
314
+ ngpt --pipe "Summarize the key changes in this PR, focusing on functional changes rather than styling: {}" > pr_summary.md
315
+ ```
316
+
195
317
  ## Advanced Git Commit Message Generation
196
318
 
197
319
  ### Working with Large Codebases
@@ -165,6 +165,22 @@ cat script.py | ngpt --pipe "Explain what this code does and suggest improvement
165
165
  cat emails.txt | ngpt --pipe "Extract all company domains from these email addresses: {}"
166
166
  ```
167
167
 
168
+ ### Shell Redirection Examples
169
+
170
+ ```bash
171
+ # Using here-string (<<<) for quick single-line input
172
+ ngpt --pipe {} <<< "What is the best way to learn shell redirects?"
173
+
174
+ # Using standard input redirection to process file contents
175
+ ngpt --pipe "summarise {}" < README.md
176
+
177
+ # Using here-document (<<EOF) for multiline input
178
+ ngpt --pipe {} << EOF
179
+ What is the best way to learn Golang?
180
+ Provide simple hello world example.
181
+ EOF
182
+ ```
183
+
168
184
  ### Content Transformation
169
185
 
170
186
  ```bash
@@ -178,6 +194,48 @@ cat spanish.txt | ngpt --pipe "Translate this Spanish text to English: {}"
178
194
  cat technical.txt | ngpt --pipe "Rewrite this technical content for a non-technical audience: {}"
179
195
  ```
180
196
 
197
+ ## Pipe Usage With Different Modes
198
+
199
+ The pipe flag can be used with several different modes for powerful combinations:
200
+
201
+ ### With Standard Mode (Default)
202
+
203
+ ```bash
204
+ # Summarize document content
205
+ cat README.md | ngpt --pipe "Summarize this document: {}"
206
+ ```
207
+
208
+ ### With Code Mode
209
+
210
+ ```bash
211
+ # Generate optimized version of code
212
+ cat slow_function.py | ngpt --code --pipe "Optimize this function for performance: {}"
213
+
214
+ # Add tests to existing code
215
+ cat module.js | ngpt --code --language javascript --pipe "Write unit tests for this code: {}"
216
+ ```
217
+
218
+ ### With Shell Mode
219
+
220
+ ```bash
221
+ # Generate command to process file content
222
+ cat error_logs.txt | ngpt --shell --pipe "Generate a command to count occurrences of each error type in these logs: {}"
223
+ ```
224
+
225
+ ### With Rewrite Mode
226
+
227
+ ```bash
228
+ # Improve email drafts
229
+ cat draft_email.txt | ngpt --rewrite --pipe "Make this email more professional while maintaining the core message: {}"
230
+ ```
231
+
232
+ ### With Git Commit Message Mode
233
+
234
+ ```bash
235
+ # Generate message from specific diff
236
+ git diff HEAD~1 | ngpt --gitcommsg --pipe
237
+ ```
238
+
181
239
  ## Git Commit Message Examples
182
240
 
183
241
  ### Basic Usage
@@ -321,4 +379,4 @@ For more advanced examples and detailed explanations of specific features, see:
321
379
  - [Advanced Examples](advanced.md)
322
380
  - [CLI Usage Guide](../usage/cli_usage.md)
323
381
  - [CLI Configuration Guide](../usage/cli_config.md)
324
- - [Git Commit Message Guide](../usage/gitcommsg.md)
382
+ - [Git Commit Message Guide](../usage/gitcommsg.md)
@@ -89,10 +89,22 @@ ngpt -t
89
89
  ```
90
90
 
91
91
  ### Stdin Processing Mode
92
- Process piped content using a placeholder:
92
+ Process piped content using a placeholder (compatible with standard, code, shell, rewrite, and gitcommsg modes):
93
93
  ```bash
94
+ # Standard mode
94
95
  cat README.md | ngpt --pipe "Summarize this document: {}"
95
- cat README.md | ngpt -p "Summarize this document: {}"
96
+
97
+ # Code mode
98
+ cat algorithm.py | ngpt --code --pipe "Optimize this algorithm: {}"
99
+
100
+ # Shell mode
101
+ cat logs.txt | ngpt --shell --pipe "Generate a command to analyze these logs: {}"
102
+
103
+ # Rewrite mode
104
+ cat email.txt | ngpt --rewrite --pipe "Make this more professional: {}"
105
+
106
+ # Git commit message mode
107
+ git diff HEAD~1 | ngpt --gitcommsg --pipe
96
108
  ```
97
109
 
98
110
  ## Architecture
@@ -37,13 +37,13 @@ Where:
37
37
  You can set configuration options directly via command-line arguments:
38
38
 
39
39
  ```
40
- usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index CONFIG_INDEX] [--provider PROVIDER] [--remove]
41
- [--show-config] [--all] [--list-models] [--list-renderers] [--cli-config [COMMAND ...]] [--api-key API_KEY]
42
- [--base-url BASE_URL] [--model MODEL] [--web-search] [--temperature TEMPERATURE] [--top_p TOP_P]
43
- [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT] [--no-stream | --prettify | --stream-prettify]
44
- [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]] [--chunk-size CHUNK_SIZE]
45
- [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
46
- [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t |-p | -r | -g]
40
+ usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index CONFIG_INDEX] [--provider PROVIDER]
41
+ [--remove] [--show-config] [--all] [--list-models] [--list-renderers] [--cli-config [COMMAND ...]]
42
+ [--api-key API_KEY] [--base-url BASE_URL] [--model MODEL] [--web-search] [--pipe]
43
+ [--temperature TEMPERATURE] [--top_p TOP_P] [--max_tokens MAX_TOKENS] [--log [FILE]] [--preprompt PREPROMPT]
44
+ [--no-stream | --prettify | --stream-prettify] [--renderer {auto,rich,glow}] [--rec-chunk] [--diff [FILE]]
45
+ [--chunk-size CHUNK_SIZE] [--analyses-chunk-size ANALYSES_CHUNK_SIZE] [--max-msg-lines MAX_MSG_LINES]
46
+ [--max-recursion-depth MAX_RECURSION_DEPTH] [-i | -s | -c | -t | -r | -g]
47
47
  [prompt]
48
48
  ```
49
49
 
@@ -103,7 +103,7 @@ usage: ngpt [-h] [-v] [--language LANGUAGE] [--config [CONFIG]] [--config-index
103
103
  - `-s, --shell`: Generate and execute shell commands
104
104
  - `-c, --code`: Generate code
105
105
  - `-t, --text`: Enter multi-line text input (submit with Ctrl+D)
106
- - `-p, --pipe`: Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content
106
+ - `--pipe`: Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content. Can be used with any mode option except --text and --interactive.
107
107
  - `-r, --rewrite`: Rewrite text from stdin to be more natural while preserving tone and meaning
108
108
  - `-g, --gitcommsg`: Generate AI-powered git commit messages from staged changes or diff file
109
109
 
@@ -282,6 +282,9 @@ ngpt --gitcommsg --rec-chunk
282
282
  # Use a diff file instead of staged changes
283
283
  ngpt --gitcommsg --diff path/to/diff_file
284
284
 
285
+ # Use piped diff content from stdin
286
+ git diff HEAD~1 | ngpt --gitcommsg --pipe
287
+
285
288
  # With custom context
286
289
  ngpt --gitcommsg --preprompt "type:feat"
287
290
  ```
@@ -323,10 +326,52 @@ cat script.py | ngpt --pipe "Explain what this code does and suggest improvement
323
326
 
324
327
  # Review text
325
328
  cat essay.txt | ngpt --pipe "Provide feedback on this essay: {}"
329
+
330
+ # Using here-string (<<<) for quick single-line input
331
+ ngpt --pipe {} <<< "What is the best way to learn shell redirects?"
332
+
333
+ # Using standard input redirection to process file contents
334
+ ngpt --pipe "summarise {}" < README.md
335
+
336
+ # Using here-document (<<EOF) for multiline input
337
+ ngpt --pipe {} << EOF
338
+ What is the best way to learn Golang?
339
+ Provide simple hello world example.
340
+ EOF
326
341
  ```
327
342
 
328
343
  This is powerful for integrating nGPT into shell scripts and automation workflows.
329
344
 
345
+ ### Pipe Usage With Different Modes
346
+
347
+ The `--pipe` flag can be combined with several modes (except `--text` and `--interactive`) for powerful workflows:
348
+
349
+ ```bash
350
+ # Standard chat mode with pipe
351
+ cat README.md | ngpt --pipe "Summarize this document in bullet points: {}"
352
+
353
+ # Code generation mode with pipe
354
+ cat algorithm.py | ngpt --code --pipe "Optimize this algorithm and add comments: {}"
355
+
356
+ # Shell command generation with pipe
357
+ cat server_logs.txt | ngpt --shell --pipe "Generate a command to extract all error messages from these logs: {}"
358
+
359
+ # Rewrite mode with pipe (explicit placeholder)
360
+ cat draft_email.txt | ngpt --rewrite --pipe "Make this email more professional while keeping key points: {}"
361
+
362
+ # Rewrite mode with pipe (implicit - will use entire content)
363
+ cat draft_email.txt | ngpt --rewrite
364
+
365
+ # Git commit message generation from piped diff
366
+ git diff HEAD~1 | ngpt --gitcommsg --pipe
367
+ ```
368
+
369
+ Each mode handles piped content appropriately for that context:
370
+ - In code mode: Uses piped code as a starting point for modification
371
+ - In shell mode: Generates commands that process the piped content
372
+ - In rewrite mode: Treats the piped content as the text to be rewritten
373
+ - In gitcommsg mode: Uses piped content as the diff to analyze
374
+
330
375
  ## Formatting Options
331
376
 
332
377
  ### No Streaming
@@ -507,7 +552,19 @@ nGPT works well with Unix pipes and redirection:
507
552
  ngpt "Write a short story about AI" > story.txt
508
553
 
509
554
  # Process file content
510
- cat data.csv | ngpt -p "Analyze this CSV data and provide insights: {}" > analysis.txt
555
+ cat data.csv | ngpt --pipe "Analyze this CSV data and provide insights: {}" > analysis.txt
556
+
557
+ # Using here-string (<<<) for quick single-line input
558
+ ngpt --pipe {} <<< "What is the best way to learn shell redirects?"
559
+
560
+ # Using standard input redirection to process file contents
561
+ ngpt --pipe "summarise {}" < README.md
562
+
563
+ # Using here-document (<<EOF) for multiline input
564
+ ngpt --pipe {} << EOF
565
+ What is the best way to learn Golang?
566
+ Provide simple hello world example.
567
+ EOF
511
568
 
512
569
  # Chain commands
513
570
  ngpt --code "function to parse CSV" | grep -v "#" > parse_csv.py
@@ -114,6 +114,99 @@ This is useful for:
114
114
  - Sharing change analysis across machines
115
115
  - Creating template-based workflows
116
116
 
117
+ ## Using Piped Diff Content
118
+
119
+ You can also pipe git diff output directly to nGPT for immediate commit message generation:
120
+
121
+ ```bash
122
+ # Generate message from current unstaged changes
123
+ git diff | ngpt --gitcommsg --pipe
124
+
125
+ # Generate message from staged changes
126
+ git diff --staged | ngpt --gitcommsg --pipe
127
+
128
+ # Generate message from specific commit
129
+ git diff HEAD~1 HEAD | ngpt --gitcommsg --pipe
130
+
131
+ # Generate message from branch comparison
132
+ git diff main..feature-branch | ngpt --gitcommsg --pipe
133
+
134
+ # Generate message from specific files
135
+ git diff -- src/components/ | ngpt --gitcommsg --pipe
136
+ ```
137
+
138
+ This approach offers several advantages:
139
+
140
+ 1. **Flexibility**: Generate messages for any diff without creating temporary files
141
+ 2. **Workflow Integration**: Easily incorporate into shell scripts and CI/CD pipelines
142
+ 3. **Quick Previews**: Preview commit messages before staging changes
143
+ 4. **Selective Analysis**: Focus on specific files or directories
144
+ 5. **Branch Comparisons**: Generate messages based on differences between branches
145
+
146
+ ### Advanced Piped Diff Examples
147
+
148
+ You can apply additional git options to customize the diff content:
149
+
150
+ ```bash
151
+ # Ignore whitespace changes
152
+ git diff -w | ngpt --gitcommsg --pipe
153
+
154
+ # Include function context
155
+ git diff -W | ngpt --gitcommsg --pipe
156
+
157
+ # Compare with specific revision
158
+ git diff v1.0.0..HEAD | ngpt --gitcommsg --pipe
159
+
160
+ # Filter by file type
161
+ git diff -- "*.js" "*.jsx" | ngpt --gitcommsg --pipe
162
+ ```
163
+
164
+ ### Combining with Other Tools
165
+
166
+ You can combine piped diff content with other Unix tools:
167
+
168
+ ```bash
169
+ # Filter the diff first with grep
170
+ git diff | grep -v "package-lock.json" | ngpt --gitcommsg --pipe
171
+
172
+ # Process large diffs with head/tail
173
+ git diff | head -n 1000 | ngpt --gitcommsg --pipe
174
+
175
+ # Save the diff and the message
176
+ git diff | tee changes.diff | ngpt --gitcommsg --pipe | tee commit_msg.txt
177
+ ```
178
+
179
+ ### Using with Preprompt
180
+
181
+ You can combine piped diff content with preprompt directives:
182
+
183
+ ```bash
184
+ # Provide type and scope
185
+ git diff | ngpt --gitcommsg --pipe --preprompt "type:feat scope:auth"
186
+
187
+ # Add context about the changes
188
+ git diff | ngpt --gitcommsg --pipe --preprompt "This implements the user authentication flow using OAuth2"
189
+ ```
190
+
191
+ ### Pipe Processing in Automated Workflows
192
+
193
+ You can use piped diff content in scripts and automated workflows:
194
+
195
+ ```bash
196
+ #!/bin/bash
197
+ # Example script that analyzes all pending changes
198
+ # and suggests commit messages for each file
199
+
200
+ # Get list of changed files
201
+ changed_files=$(git status -s | awk '{print $2}')
202
+
203
+ for file in $changed_files; do
204
+ echo "Analyzing changes in $file..."
205
+ git diff -- "$file" | ngpt --gitcommsg --pipe > "$file.commit_msg"
206
+ echo "Suggested commit message saved to $file.commit_msg"
207
+ done
208
+ ```
209
+
117
210
  ## Guiding Message Generation
118
211
 
119
212
  You can use the `--preprompt` option to provide context or directives for the message generation:
@@ -69,6 +69,8 @@ def setup_argument_parser():
69
69
  help='Model to use')
70
70
  global_group.add_argument('--web-search', action='store_true',
71
71
  help='Enable web search capability using DuckDuckGo to enhance prompts with relevant information')
72
+ global_group.add_argument('--pipe', action='store_true',
73
+ help='Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content. Can be used with any mode option except --text and --interactive')
72
74
  global_group.add_argument('--temperature', type=float, default=0.7,
73
75
  help='Set temperature (controls randomness, default: 0.7)')
74
76
  global_group.add_argument('--top_p', type=float, default=1.0,
@@ -119,8 +121,6 @@ def setup_argument_parser():
119
121
  help='Generate code')
120
122
  mode_exclusive_group.add_argument('-t', '--text', action='store_true',
121
123
  help='Enter multi-line text input (submit with Ctrl+D)')
122
- mode_exclusive_group.add_argument('-p', '--pipe', action='store_true',
123
- help='Read from stdin and use content with prompt. Use {} in prompt as placeholder for stdin content')
124
124
  mode_exclusive_group.add_argument('-r', '--rewrite', action='store_true',
125
125
  help='Rewrite text from stdin to be more natural while preserving tone and meaning')
126
126
  mode_exclusive_group.add_argument('-g', '--gitcommsg', action='store_true',
@@ -167,7 +167,11 @@ def validate_args(args):
167
167
  if args.stream_prettify and not has_markdown_renderer('rich'):
168
168
  raise ValueError("--stream-prettify requires Rich to be installed. Install with: pip install \"ngpt[full]\" or pip install rich")
169
169
 
170
- # If stdin mode is used, check if input is available
170
+ # Check for incompatible --pipe flag with certain modes
171
+ if args.pipe and (args.text or args.interactive):
172
+ raise ValueError("--pipe flag cannot be used with --text or --interactive modes. These modes already handle input directly.")
173
+
174
+ # If pipe flag is used, check if input is available
171
175
  if args.pipe and sys.stdin.isatty():
172
176
  raise ValueError("--pipe was specified but no input is piped. Use echo 'content' | ngpt --pipe 'prompt with {}'")
173
177
 
@@ -550,13 +550,6 @@ def main():
550
550
  # Text mode (multiline input)
551
551
  text_mode(client, args, logger=logger)
552
552
 
553
- elif args.pipe:
554
- # Apply CLI config for pipe mode (similar to chat mode)
555
- args = apply_cli_config(args, "all")
556
-
557
- # Pipe mode (using the chat mode with stdin input)
558
- chat_mode(client, args, logger=logger)
559
-
560
553
  elif args.rewrite:
561
554
  # Apply CLI config for rewrite mode
562
555
  args = apply_cli_config(args, "all")
@@ -571,8 +564,8 @@ def main():
571
564
  # Git commit message generation mode
572
565
  gitcommsg_mode(client, args, logger=logger)
573
566
 
567
+ # Choose chat mode by default if no other specific mode is selected
574
568
  else:
575
- # Default to chat mode
576
569
  # Apply CLI config for default chat mode
577
570
  args = apply_cli_config(args, "all")
578
571
 
@@ -1,7 +1,7 @@
1
1
  from ..formatters import COLORS
2
2
  from ..renderers import prettify_markdown, prettify_streaming_markdown
3
3
  from ..ui import spinner
4
- from ...utils import enhance_prompt_with_web_search
4
+ from ...utils import enhance_prompt_with_web_search, process_piped_input
5
5
  import sys
6
6
  import threading
7
7
 
@@ -13,43 +13,20 @@ def chat_mode(client, args, logger=None):
13
13
  args: The parsed command-line arguments
14
14
  logger: Optional logger instance
15
15
  """
16
+ # Get the prompt
17
+ if args.prompt is None:
18
+ try:
19
+ print("Enter your prompt: ", end='')
20
+ prompt = input()
21
+ except KeyboardInterrupt:
22
+ print("\nInput cancelled by user. Exiting gracefully.")
23
+ sys.exit(130)
24
+ else:
25
+ prompt = args.prompt
26
+
16
27
  # Handle pipe mode
17
28
  if args.pipe:
18
- # Read input from stdin
19
- stdin_content = sys.stdin.read().strip()
20
-
21
- # Get the prompt - either use provided one or ask user
22
- if args.prompt is None:
23
- try:
24
- print("Enter your prompt (use {} as placeholder for stdin): ", end='')
25
- prompt = input()
26
- except KeyboardInterrupt:
27
- print("\nInput cancelled by user. Exiting gracefully.")
28
- sys.exit(130)
29
- else:
30
- prompt = args.prompt
31
-
32
- # Replace the placeholder in the prompt with stdin content
33
- placeholder = "{}"
34
-
35
- # Check if the placeholder exists in the prompt
36
- if placeholder not in prompt:
37
- print(f"{COLORS['yellow']}Warning: Placeholder '{placeholder}' not found in prompt. Appending stdin content to the end.{COLORS['reset']}")
38
- prompt = f"{prompt} {stdin_content}"
39
- else:
40
- prompt = prompt.replace(placeholder, stdin_content)
41
- # Handle regular chat mode
42
- else:
43
- # Get the prompt
44
- if args.prompt is None:
45
- try:
46
- print("Enter your prompt: ", end='')
47
- prompt = input()
48
- except KeyboardInterrupt:
49
- print("\nInput cancelled by user. Exiting gracefully.")
50
- sys.exit(130)
51
- else:
52
- prompt = args.prompt
29
+ prompt = process_piped_input(prompt, logger=logger)
53
30
 
54
31
  # Log the user message if logging is enabled
55
32
  if logger:
@@ -1,7 +1,7 @@
1
1
  from ..formatters import COLORS
2
2
  from ..renderers import prettify_markdown, prettify_streaming_markdown, has_markdown_renderer, show_available_renderers
3
3
  from ..ui import spinner, copy_to_clipboard
4
- from ...utils import enhance_prompt_with_web_search
4
+ from ...utils import enhance_prompt_with_web_search, process_piped_input
5
5
  import sys
6
6
  import threading
7
7
 
@@ -97,6 +97,10 @@ def code_mode(client, args, logger=None):
97
97
  else:
98
98
  prompt = args.prompt
99
99
 
100
+ # Apply piped input if --pipe is enabled
101
+ if args.pipe:
102
+ prompt = process_piped_input(prompt, logger=logger)
103
+
100
104
  # Log the user prompt if logging is enabled
101
105
  if logger:
102
106
  logger.log("user", prompt)
@@ -11,6 +11,7 @@ from ..formatters import COLORS
11
11
  from ..ui import spinner, copy_to_clipboard
12
12
  from ...utils.log import create_gitcommsg_logger
13
13
  from ...utils.cli_config import get_cli_config_option
14
+ from ...utils import process_piped_input
14
15
 
15
16
  def get_diff_content(diff_file=None):
16
17
  """Get git diff content from file or git staged changes.
@@ -964,6 +965,39 @@ REMINDER:
964
965
 
965
966
  DO NOT ask for the original diff or add explanations outside the commit message format."""
966
967
 
968
+ def is_git_diff(content):
969
+ """Check if the content looks like a git diff.
970
+
971
+ Args:
972
+ content: The content to check
973
+
974
+ Returns:
975
+ bool: True if the content looks like a git diff, False otherwise
976
+ """
977
+ # Check for common git diff patterns
978
+ diff_patterns = [
979
+ r'diff --git a/.*? b/.*?', # diff --git a/file b/file
980
+ r'index [a-f0-9]+\.\.[a-f0-9]+', # index hash..hash
981
+ r'--- a/.*?', # --- a/file
982
+ r'\+\+\+ b/.*?', # +++ b/file
983
+ r'@@ -\d+,\d+ \+\d+,\d+ @@' # @@ -line,count +line,count @@
984
+ ]
985
+
986
+ # Check if the content contains at least one of these patterns
987
+ for pattern in diff_patterns:
988
+ if re.search(pattern, content):
989
+ return True
990
+
991
+ # Check if the content contains lines starting with + or - (changes)
992
+ lines = content.splitlines()
993
+ plus_minus_lines = [line for line in lines if line.startswith('+') or line.startswith('-')]
994
+
995
+ # If there are many +/- lines, it's likely a diff
996
+ if len(plus_minus_lines) > 5 and len(plus_minus_lines) / len(lines) > 0.1:
997
+ return True
998
+
999
+ return False
1000
+
967
1001
  def gitcommsg_mode(client, args, logger=None):
968
1002
  """Handle the Git commit message generation mode.
969
1003
 
@@ -987,16 +1021,47 @@ def gitcommsg_mode(client, args, logger=None):
987
1021
  active_logger.debug(f"Args: {args}")
988
1022
 
989
1023
  try:
1024
+ # Process piped input as diff content when --pipe flag is set
1025
+ piped_diff_content = None
1026
+ if args.pipe:
1027
+ if active_logger:
1028
+ active_logger.info("Processing piped input as diff content")
1029
+
1030
+ if not sys.stdin.isatty():
1031
+ piped_diff_content = sys.stdin.read().strip()
1032
+ if not piped_diff_content:
1033
+ print(f"{COLORS['yellow']}Warning: No diff content received from stdin.{COLORS['reset']}")
1034
+ else:
1035
+ # Validate that the piped content looks like a git diff
1036
+ if not is_git_diff(piped_diff_content):
1037
+ print(f"{COLORS['red']}Error: The piped content doesn't appear to be a git diff. Exiting.{COLORS['reset']}")
1038
+ if active_logger:
1039
+ active_logger.error("Piped content doesn't appear to be a git diff. Aborting.")
1040
+ return
1041
+ elif active_logger:
1042
+ active_logger.info(f"Received {len(piped_diff_content.splitlines())} lines of diff content from stdin")
1043
+ else:
1044
+ print(f"{COLORS['yellow']}Error: --pipe was specified but no input is piped.{COLORS['reset']}")
1045
+ return
1046
+
990
1047
  # Check if --diff was explicitly passed on the command line
991
1048
  diff_option_provided = '--diff' in sys.argv
992
1049
  diff_path_provided = diff_option_provided and args.diff is not None and args.diff is not True
993
1050
 
1051
+ # If piped diff content is available, use it directly
1052
+ if piped_diff_content:
1053
+ diff_content = piped_diff_content
1054
+ if active_logger:
1055
+ active_logger.info("Using diff content from stdin")
994
1056
  # If --diff wasn't explicitly provided on the command line, don't use the config value
995
- if not diff_option_provided:
1057
+ elif not diff_option_provided:
996
1058
  # Even if diff is in CLI config, don't use it unless --diff flag is provided
997
1059
  diff_file = None
998
1060
  if active_logger:
999
1061
  active_logger.info("Not using diff file from CLI config because --diff flag was not provided")
1062
+
1063
+ # Get diff content from git staged changes
1064
+ diff_content = get_diff_content(diff_file)
1000
1065
  else:
1001
1066
  # --diff flag was provided on command line
1002
1067
  if args.diff is True:
@@ -1013,9 +1078,9 @@ def gitcommsg_mode(client, args, logger=None):
1013
1078
  diff_file = args.diff
1014
1079
  if active_logger:
1015
1080
  active_logger.info(f"Using explicitly provided diff file: {diff_file}")
1016
-
1017
- # Get diff content
1018
- diff_content = get_diff_content(diff_file)
1081
+
1082
+ # Get diff content from file
1083
+ diff_content = get_diff_content(diff_file)
1019
1084
 
1020
1085
  if not diff_content:
1021
1086
  print(f"{COLORS['red']}No diff content available. Exiting.{COLORS['reset']}")
@@ -4,7 +4,7 @@ import time
4
4
  from ..formatters import COLORS
5
5
  from ..renderers import prettify_markdown, prettify_streaming_markdown
6
6
  from ..ui import get_multiline_input, spinner, copy_to_clipboard
7
- from ...utils import enhance_prompt_with_web_search
7
+ from ...utils import enhance_prompt_with_web_search, process_piped_input
8
8
 
9
9
  # System prompt for rewriting text
10
10
  REWRITE_SYSTEM_PROMPT = """You are an expert text editor and rewriter. Your task is to rewrite the user's text to improve readability and flow while carefully preserving the original meaning, tone, and style.
@@ -78,14 +78,17 @@ def rewrite_mode(client, args, logger=None):
78
78
  args: The parsed command-line arguments
79
79
  logger: Optional logger instance
80
80
  """
81
- # Determine the input source (stdin pipe, command-line argument, or multiline input)
82
- if not sys.stdin.isatty():
81
+ # Check if using --pipe flag with a specific placeholder
82
+ if args.pipe and args.prompt:
83
+ input_text = process_piped_input(args.prompt, logger=logger)
84
+ # Normal rewrite mode functionality (direct stdin piping without --pipe flag)
85
+ elif not sys.stdin.isatty():
83
86
  # Read from stdin if data is piped
84
87
  input_text = sys.stdin.read().strip()
85
88
 
86
- # If stdin is empty but prompt is provided, use the prompt
87
- if not input_text and args.prompt:
88
- input_text = args.prompt
89
+ # If prompt is also provided, append it to the piped input
90
+ if args.prompt:
91
+ input_text = f"{input_text}\n\n{args.prompt}"
89
92
  elif args.prompt:
90
93
  # Use the command-line argument if provided
91
94
  input_text = args.prompt
@@ -1,7 +1,7 @@
1
1
  from ..formatters import COLORS
2
2
  from ..ui import spinner, copy_to_clipboard
3
3
  from ..renderers import prettify_markdown, has_markdown_renderer, prettify_streaming_markdown, show_available_renderers
4
- from ...utils import enhance_prompt_with_web_search
4
+ from ...utils import enhance_prompt_with_web_search, process_piped_input
5
5
  import subprocess
6
6
  import sys
7
7
  import threading
@@ -396,6 +396,10 @@ def shell_mode(client, args, logger=None):
396
396
  else:
397
397
  prompt = args.prompt
398
398
 
399
+ # Process piped input if --pipe flag is set
400
+ if args.pipe:
401
+ prompt = process_piped_input(prompt, logger=logger)
402
+
399
403
  # Log the user prompt if logging is enabled
400
404
  if logger:
401
405
  logger.log("user", prompt)
@@ -27,6 +27,7 @@ from .web_search import (
27
27
  get_web_search_results,
28
28
  format_web_search_results_for_prompt
29
29
  )
30
+ from .pipe import process_piped_input
30
31
 
31
32
  __all__ = [
32
33
  "create_logger", "Logger",
@@ -35,5 +36,6 @@ __all__ = [
35
36
  "load_cli_config", "set_cli_config_option", "get_cli_config_option",
36
37
  "unset_cli_config_option", "apply_cli_config", "list_cli_config_options",
37
38
  "CLI_CONFIG_OPTIONS", "get_cli_config_dir", "get_cli_config_path",
38
- "enhance_prompt_with_web_search", "get_web_search_results", "format_web_search_results_for_prompt"
39
+ "enhance_prompt_with_web_search", "get_web_search_results", "format_web_search_results_for_prompt",
40
+ "process_piped_input"
39
41
  ]
@@ -0,0 +1,52 @@
1
+ import sys
2
+
3
+ def process_piped_input(prompt, logger=None):
4
+ """Process piped input to be used with a prompt.
5
+
6
+ Args:
7
+ prompt: The prompt string which may contain a {} placeholder
8
+ logger: Optional logger instance
9
+
10
+ Returns:
11
+ str: The processed prompt with piped input inserted at placeholder, or appended
12
+ """
13
+ # Import COLORS here to avoid circular imports
14
+ from ..cli.formatters import COLORS
15
+
16
+ # Only process if stdin is not a TTY (i.e., if we're receiving piped input)
17
+ if not sys.stdin.isatty():
18
+ # Read input from stdin
19
+ stdin_content = sys.stdin.read().strip()
20
+
21
+ # If we have stdin content and prompt is provided
22
+ if stdin_content and prompt:
23
+ placeholder = "{}"
24
+
25
+ # Check if the placeholder exists in the prompt
26
+ if placeholder not in prompt:
27
+ print(f"{COLORS['yellow']}Warning: Placeholder '{placeholder}' not found in prompt. Appending stdin content to the end.{COLORS['reset']}")
28
+ processed_prompt = f"{prompt}\n\n{stdin_content}"
29
+ else:
30
+ # Replace the placeholder in the prompt with stdin content
31
+ processed_prompt = prompt.replace(placeholder, stdin_content)
32
+
33
+ # Log if a logger is provided
34
+ if logger:
35
+ logger.log("info", f"Processed piped input: Combined prompt with stdin content")
36
+
37
+ return processed_prompt
38
+
39
+ # If we have stdin content but no prompt, just use the stdin content
40
+ elif stdin_content:
41
+ return stdin_content
42
+ elif prompt:
43
+ # We have prompt but stdin is empty
44
+ print(f"{COLORS['yellow']}Warning: No stdin content received. Using only the provided prompt.{COLORS['reset']}")
45
+ return prompt
46
+ else:
47
+ # No stdin content and no prompt
48
+ print(f"{COLORS['yellow']}Error: No stdin content and no prompt provided.{COLORS['reset']}")
49
+ return ""
50
+
51
+ # If no stdin or no content in stdin, just return the original prompt
52
+ return prompt
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ngpt"
3
- version = "3.7.0"
3
+ version = "3.8.0"
4
4
  description = "Swiss army knife for LLMs: powerful CLI and interactive chatbot in one package. Seamlessly work with OpenAI, Ollama, Groq, Claude, Gemini, or any OpenAI-compatible API to generate code, craft git commits, rewrite text, and execute shell commands."
5
5
  authors = [
6
6
  {name = "nazDridoy", email = "nazdridoy399@gmail.com"},
@@ -148,7 +148,7 @@ wheels = [
148
148
 
149
149
  [[package]]
150
150
  name = "ngpt"
151
- version = "3.7.0"
151
+ version = "3.8.0"
152
152
  source = { editable = "." }
153
153
  dependencies = [
154
154
  { name = "beautifulsoup4" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes