codicent-cli 0.4.3__py3-none-any.whl

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.
app.py ADDED
@@ -0,0 +1,216 @@
1
+ import sys
2
+ import os
3
+ import logging
4
+ from codicentpy import Codicent
5
+ from rich.console import Console
6
+ from rich.markdown import Markdown
7
+
8
+ # Configure logging
9
+ logging.basicConfig(level=logging.WARNING, format='%(levelname)s: %(message)s')
10
+ logger = logging.getLogger(__name__)
11
+
12
+ def show_help():
13
+ """Display help information."""
14
+ help_text = """
15
+ Codicent CLI - Command-line interface for the Codicent API
16
+
17
+ USAGE:
18
+ codicent [OPTIONS] [QUESTION]
19
+ codicent [OPTIONS] < file.txt
20
+ echo "question" | codicent [OPTIONS]
21
+
22
+ OPTIONS:
23
+ -t, --interactive Start interactive chat mode
24
+ -h, --help Show this help message
25
+ -v, --version Show version information
26
+ --verbose Enable verbose logging
27
+ --quiet Suppress non-essential output
28
+
29
+ EXAMPLES:
30
+ codicent "What is Python?"
31
+ codicent -t
32
+ codicent "@mention Hello there"
33
+ echo "Help me debug this" | codicent
34
+
35
+ ENVIRONMENT:
36
+ CODICENT_TOKEN Your Codicent API token (required)
37
+
38
+ For more information, visit: https://github.com/izaxon/codicent-cli
39
+ """
40
+ print(help_text.strip())
41
+
42
+ def show_version():
43
+ """Display version information."""
44
+ print("Codicent CLI v0.4.3")
45
+
46
+ def validate_input(question):
47
+ """Validate user input."""
48
+ if not question or not question.strip():
49
+ return False, "Empty question provided"
50
+
51
+ if len(question) > 10000: # Reasonable limit
52
+ return False, "Question too long (max 10,000 characters)"
53
+
54
+ return True, None
55
+
56
+ def main():
57
+ # Parse command line arguments
58
+ if "-h" in sys.argv or "--help" in sys.argv:
59
+ show_help()
60
+ return 0
61
+
62
+ if "-v" in sys.argv or "--version" in sys.argv:
63
+ show_version()
64
+ return 0
65
+
66
+ # Set logging level based on flags
67
+ if "--verbose" in sys.argv:
68
+ logging.getLogger().setLevel(logging.INFO)
69
+ sys.argv.remove("--verbose")
70
+ logger.info("Verbose logging enabled")
71
+
72
+ if "--quiet" in sys.argv:
73
+ logging.getLogger().setLevel(logging.ERROR)
74
+ sys.argv.remove("--quiet")
75
+
76
+ # Validate environment
77
+ token = os.getenv("CODICENT_TOKEN")
78
+ if not token:
79
+ print("Error: CODICENT_TOKEN environment variable is not set.")
80
+ print("Please set it with your Codicent API token:")
81
+ print(" export CODICENT_TOKEN='your_token_here'")
82
+ print("Or visit the Codicent documentation for setup instructions.")
83
+ return 1
84
+
85
+ # Initialize API client with error handling
86
+ try:
87
+ codicent = Codicent(token)
88
+ logger.info("Codicent API client initialized successfully")
89
+ except Exception as e:
90
+ print(f"Error: Failed to initialize Codicent API client: {e}")
91
+ logger.error(f"API client initialization failed: {e}")
92
+ return 1
93
+
94
+ conversationId = None
95
+
96
+ # Parse interactive mode flags
97
+ interactive = False
98
+ if "-t" in sys.argv or "--interactive" in sys.argv:
99
+ interactive = True
100
+ if "-t" in sys.argv:
101
+ sys.argv.remove("-t")
102
+ if "--interactive" in sys.argv:
103
+ sys.argv.remove("--interactive")
104
+ elif len(sys.argv) == 1:
105
+ interactive = True
106
+
107
+ # Get input based on mode
108
+ if not interactive:
109
+ if len(sys.argv) < 2:
110
+ if sys.stdin.isatty():
111
+ print("Usage: codicent <question> or codicent < chat.txt or cat chat.txt | codicent or codicent (equal to codicent -t)")
112
+ print("Use 'codicent --help' for more information.")
113
+ return 1
114
+ try:
115
+ question = sys.stdin.read().strip()
116
+ except (KeyboardInterrupt, EOFError):
117
+ return 1
118
+ else:
119
+ question = " ".join(sys.argv[1:])
120
+ else:
121
+ if len(sys.argv) > 1:
122
+ question = " ".join(sys.argv[1:])
123
+ elif not sys.stdin.isatty():
124
+ try:
125
+ question = sys.stdin.read().strip()
126
+ except (KeyboardInterrupt, EOFError):
127
+ return 1
128
+ else:
129
+ question = ""
130
+
131
+ def handle_question(question):
132
+ nonlocal conversationId
133
+
134
+ # Validate input
135
+ is_valid, error_msg = validate_input(question)
136
+ if not is_valid:
137
+ print(f"Error: {error_msg}")
138
+ logger.warning(f"Invalid input: {error_msg}")
139
+ return False
140
+
141
+ console = Console()
142
+
143
+ # Show user message in cyan color for interactive mode
144
+ if interactive:
145
+ console.print(f"[cyan]{question}[/cyan]")
146
+
147
+ try:
148
+ if question.strip().startswith("@"):
149
+ logger.info("Sending message to Codicent API")
150
+ with console.status("[dim]Sending message...[/dim]", spinner="dots"):
151
+ response = codicent.post_message(question, type="info")
152
+ console.print("[green]โœ… Message posted successfully.[/green]")
153
+ else:
154
+ logger.info("Sending chat reply to Codicent API")
155
+ with console.status("[dim]๐Ÿค” Thinking...[/dim]", spinner="dots"):
156
+ response = codicent.post_chat_reply(question, conversationId)
157
+ conversationId = response["id"]
158
+ logger.info(f"Updated conversation ID: {conversationId}")
159
+
160
+ # Show bot response with markdown formatting in green
161
+ if interactive:
162
+ console.print()
163
+
164
+ # Create markdown with green styling
165
+ from rich.text import Text
166
+ markdown_content = Markdown(response["content"])
167
+ console.print(markdown_content, style="green")
168
+ console.print()
169
+
170
+ return True
171
+
172
+ except KeyboardInterrupt:
173
+ console.print("\n[yellow]Operation cancelled by user[/yellow]")
174
+ return False
175
+ except ConnectionError as e:
176
+ console.print(f"[red]Network error: Unable to connect to Codicent API[/red]")
177
+ logger.error(f"Connection error: {e}")
178
+ return False
179
+ except Exception as e:
180
+ console.print(f"[red]API error: {e}[/red]")
181
+ logger.error(f"API call failed: {e}")
182
+ return False
183
+
184
+ # Handle initial question if provided
185
+ if question != "":
186
+ success = handle_question(question)
187
+ if not success and not interactive:
188
+ return 1
189
+
190
+ # Interactive mode loop
191
+ if interactive:
192
+ console = Console()
193
+ console.print("\n[bold green]๐Ÿค– Codicent CLI Interactive Mode[/bold green]")
194
+ console.print("[dim]Type your questions or use Ctrl+C to exit.[/dim]")
195
+ console.print("[dim]Prefix with @ for info messages.[/dim]")
196
+ console.print("โ”€" * 50)
197
+
198
+ while True:
199
+ try:
200
+ question = input("ยค ")
201
+ except KeyboardInterrupt:
202
+ console.print("\n[yellow]๐Ÿ‘‹ Goodbye![/yellow]")
203
+ break
204
+ except EOFError:
205
+ break
206
+
207
+ if question.strip() != "":
208
+ handle_question(question)
209
+ # Add a separator line after each interaction
210
+ if question.strip() != "" and not question.strip().startswith("@"):
211
+ console.print("[dim]" + "โ”€" * 50 + "[/dim]")
212
+
213
+ return 0
214
+
215
+ if __name__ == "__main__":
216
+ sys.exit(main())
@@ -0,0 +1,267 @@
1
+ Metadata-Version: 2.4
2
+ Name: codicent-cli
3
+ Version: 0.4.3
4
+ Summary: Command-line interface for the Codicent API
5
+ Home-page: https://github.com/izaxon/codicent-cli
6
+ Author: Johan Isaksson
7
+ Author-email: johan@izaxon.com
8
+ Project-URL: Bug Reports, https://github.com/izaxon/codicent-cli/issues
9
+ Project-URL: Source, https://github.com/izaxon/codicent-cli
10
+ Keywords: codicent cli api chat ai
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.6
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Requires-Python: >=3.6
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: rich
27
+ Dynamic: author
28
+ Dynamic: author-email
29
+ Dynamic: classifier
30
+ Dynamic: description
31
+ Dynamic: description-content-type
32
+ Dynamic: home-page
33
+ Dynamic: keywords
34
+ Dynamic: license-file
35
+ Dynamic: project-url
36
+ Dynamic: requires-dist
37
+ Dynamic: requires-python
38
+ Dynamic: summary
39
+
40
+ # Codicent CLI
41
+
42
+ Codicent CLI is a command-line interface for interacting with the Codicent API. It provides both one-shot command execution and interactive chat sessions with comprehensive error handling and user-friendly features.
43
+
44
+ ## Features
45
+
46
+ - **One-shot mode**: Execute single commands and get responses
47
+ - **Interactive mode**: Continuous chat sessions with conversation tracking
48
+ - **Message types**: Support for regular chat and @-prefixed info messages
49
+ - **Input flexibility**: Command arguments, stdin pipes, or interactive prompts
50
+ - **Rich output**: Markdown-formatted responses with beautiful terminal UI
51
+ - **Error handling**: Comprehensive error messages and graceful failure handling
52
+ - **Logging**: Configurable logging levels for debugging
53
+
54
+ ## Installation
55
+
56
+ ### Prerequisites
57
+
58
+ - Python 3.6 or higher
59
+ - `pip` (Python package installer)
60
+
61
+ ### Quick Installation
62
+
63
+ ```bash
64
+ # Install both dependencies with one command
65
+ pip install git+https://github.com/izaxon/codicent-py.git git+https://github.com/izaxon/codicent-cli.git@v0.4.3
66
+ ```
67
+
68
+ ### Development Installation
69
+
70
+ #### Steps
71
+
72
+ 1. Clone the repository:
73
+ ```bash
74
+ git clone https://github.com/izaxon/codicent-cli.git
75
+ cd codicent-cli
76
+ ```
77
+
78
+ 2. Install the Git dependency:
79
+ ```bash
80
+ pip install git+https://github.com/izaxon/codicent-py.git
81
+ ```
82
+
83
+ 3. Install the CLI application:
84
+ ```bash
85
+ pip install .
86
+ ```
87
+
88
+ For development mode:
89
+ ```bash
90
+ pip install -e .
91
+ ```
92
+
93
+ ### Direct Installation from GitHub
94
+
95
+ You can also install directly from GitHub without cloning:
96
+
97
+ ```bash
98
+ # Install the latest release
99
+ pip install git+https://github.com/izaxon/codicent-py.git
100
+ pip install git+https://github.com/izaxon/codicent-cli.git
101
+
102
+ # Install a specific version
103
+ pip install git+https://github.com/izaxon/codicent-cli.git@v0.4.3
104
+ ```
105
+
106
+ ## Usage
107
+
108
+ ### Basic Setup
109
+
110
+ 1. Set the `CODICENT_TOKEN` environment variable with your Codicent API token:
111
+ ```bash
112
+ export CODICENT_TOKEN="YOUR_API_TOKEN"
113
+ ```
114
+
115
+ ### Command Options
116
+
117
+ ```
118
+ codicent [OPTIONS] [QUESTION]
119
+
120
+ OPTIONS:
121
+ -t, --interactive Start interactive chat mode
122
+ -h, --help Show help message
123
+ -v, --version Show version information
124
+ --verbose Enable verbose logging
125
+ --quiet Suppress non-essential output
126
+ ```
127
+
128
+ ### Examples
129
+
130
+ **One-shot questions:**
131
+ ```bash
132
+ codicent "What can you help me with?"
133
+ codicent "Explain Python decorators"
134
+ ```
135
+
136
+ **Interactive mode:**
137
+ ```bash
138
+ codicent -t
139
+ # or
140
+ codicent --interactive
141
+ ```
142
+
143
+ **Piped input:**
144
+ ```bash
145
+ echo "What is machine learning?" | codicent
146
+ codicent < questions.txt
147
+ cat code.py | codicent "Review this code"
148
+ ```
149
+
150
+ **Info messages (@ prefix):**
151
+ ```bash
152
+ codicent "@mention This is an info message"
153
+ ```
154
+
155
+ **With logging:**
156
+ ```bash
157
+ codicent --verbose "Debug this issue"
158
+ codicent --quiet "Silent operation"
159
+ ```
160
+
161
+ ## Interactive Mode
162
+
163
+ In interactive mode, you can have ongoing conversations with enhanced visual clarity:
164
+
165
+ ```
166
+ $ codicent -t
167
+ ๐Ÿค– Codicent CLI Interactive Mode
168
+ Type your questions or use Ctrl+C to exit.
169
+ Prefix with @ for info messages.
170
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
171
+ ยค What is Python?
172
+
173
+ Python is a high-level, interpreted programming language known for its
174
+ simplicity and readability. It was created by Guido van Rossum and first
175
+ released in 1991.
176
+
177
+ Key features:
178
+ โ€ข Easy to learn and use
179
+ โ€ข Extensive standard library
180
+ โ€ข Cross-platform compatibility
181
+ โ€ข Strong community support
182
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
183
+ ยค Can you give me an example?
184
+
185
+ Here's a simple Python example:
186
+
187
+ # Hello World in Python
188
+ print("Hello, World!")
189
+
190
+ # Working with variables
191
+ name = "Alice"
192
+ age = 25
193
+ print(f"My name is {name} and I am {age} years old.")
194
+
195
+ Python's syntax is clean and intuitive!
196
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
197
+ ยค @mention Save this conversation
198
+ โœ… Message posted successfully.
199
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
200
+ ยค ^C
201
+ ๐Ÿ‘‹ Goodbye!
202
+ ```
203
+
204
+ **Visual Features:**
205
+ - **Colored messages**: User input appears in cyan, bot responses in green
206
+ - **Clean prompting**: Original `ยค` prompt character maintained
207
+ - **Visual separators**: Clear lines between conversations
208
+ - **Rich formatting**: Markdown responses with syntax highlighting
209
+ - **Status indicators**: Animated thinking indicators and success messages
210
+ - **Emojis**: Friendly visual cues throughout the interface
211
+
212
+ ## Error Handling
213
+
214
+ The CLI provides helpful error messages for common issues:
215
+
216
+ - **Missing token**: Clear instructions on setting up `CODICENT_TOKEN`
217
+ - **Network errors**: Graceful handling of connection issues
218
+ - **API errors**: Detailed error messages from the Codicent API
219
+ - **Input validation**: Prevents empty or overly long inputs
220
+ - **Keyboard interrupts**: Clean exit handling
221
+
222
+ ## Development
223
+
224
+ ### Running Tests
225
+
226
+ ```bash
227
+ python -m pytest test_app.py -v
228
+ ```
229
+
230
+ ### Project Structure
231
+
232
+ - `app.py` - Main application logic (single-file architecture)
233
+ - `test_app.py` - Comprehensive test suite
234
+ - `setup.py` - Package configuration
235
+ - `requirements.txt` - Dependencies including git packages
236
+
237
+ ### Dependencies
238
+
239
+ - **codicentpy**: Core API client for Codicent services
240
+ - **rich**: Terminal formatting, markdown rendering, and animations
241
+
242
+ ## Troubleshooting
243
+
244
+ ### Common Issues
245
+
246
+ 1. **"CODICENT_TOKEN environment variable is not set"**
247
+ - Set the token: `export CODICENT_TOKEN="your_token"`
248
+ - Verify it's set: `echo $CODICENT_TOKEN`
249
+
250
+ 2. **"Network error: Unable to connect to Codicent API"**
251
+ - Check your internet connection
252
+ - Verify the Codicent API is accessible
253
+ - Try again with `--verbose` for more details
254
+
255
+ 3. **"Failed to initialize Codicent API client"**
256
+ - Verify your token is valid
257
+ - Check if the codicentpy package is properly installed
258
+
259
+ ### Getting Help
260
+
261
+ - Use `codicent --help` for usage information
262
+ - Use `codicent --verbose` for detailed logging
263
+ - Check the [Codicent documentation](https://github.com/izaxon/codicent-py) for API details
264
+
265
+ ## License
266
+
267
+ This project is licensed under the MIT License.
@@ -0,0 +1,7 @@
1
+ app.py,sha256=GNWRPv8sdPHTQX1U0lZuw5pw7a4prtSR83dBZu2flOQ,7619
2
+ codicent_cli-0.4.3.dist-info/licenses/LICENSE,sha256=wXFYmzbk9nJjly1LSguyMXo2m4WYIgrCxwcg2H9Ri5E,1092
3
+ codicent_cli-0.4.3.dist-info/METADATA,sha256=0S9aym_jrit0rlwxOH5CRkqmTYi7Dy0BvT1XxIhCvpc,7985
4
+ codicent_cli-0.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ codicent_cli-0.4.3.dist-info/entry_points.txt,sha256=EbUSUE5QNZkK5E5-HjYAcvLsKh4b-BjMeHgvDck3wlU,38
6
+ codicent_cli-0.4.3.dist-info/top_level.txt,sha256=io9g7LCbfmTG1SFKgEOGXmCFB9uMP2H5lerm0HiHWQE,4
7
+ codicent_cli-0.4.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ codicent = app:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Johan Isaksson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ app