ostruct-cli 0.8.29__py3-none-any.whl → 1.0.0__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.
- ostruct/cli/__init__.py +3 -15
- ostruct/cli/attachment_processor.py +455 -0
- ostruct/cli/attachment_template_bridge.py +973 -0
- ostruct/cli/cli.py +157 -33
- ostruct/cli/click_options.py +775 -692
- ostruct/cli/code_interpreter.py +195 -12
- ostruct/cli/commands/__init__.py +0 -3
- ostruct/cli/commands/run.py +289 -62
- ostruct/cli/config.py +23 -22
- ostruct/cli/constants.py +89 -0
- ostruct/cli/errors.py +175 -5
- ostruct/cli/explicit_file_processor.py +0 -15
- ostruct/cli/file_info.py +97 -15
- ostruct/cli/file_list.py +43 -1
- ostruct/cli/file_search.py +68 -2
- ostruct/cli/help_json.py +235 -0
- ostruct/cli/mcp_integration.py +13 -16
- ostruct/cli/params.py +217 -0
- ostruct/cli/plan_assembly.py +335 -0
- ostruct/cli/plan_printing.py +385 -0
- ostruct/cli/progress_reporting.py +8 -56
- ostruct/cli/quick_ref_help.py +128 -0
- ostruct/cli/rich_config.py +299 -0
- ostruct/cli/runner.py +397 -190
- ostruct/cli/security/__init__.py +2 -0
- ostruct/cli/security/allowed_checker.py +41 -0
- ostruct/cli/security/normalization.py +13 -9
- ostruct/cli/security/security_manager.py +558 -17
- ostruct/cli/security/types.py +15 -0
- ostruct/cli/template_debug.py +283 -261
- ostruct/cli/template_debug_help.py +233 -142
- ostruct/cli/template_env.py +46 -5
- ostruct/cli/template_filters.py +415 -8
- ostruct/cli/template_processor.py +240 -619
- ostruct/cli/template_rendering.py +49 -73
- ostruct/cli/template_validation.py +2 -1
- ostruct/cli/token_validation.py +35 -15
- ostruct/cli/types.py +15 -19
- ostruct/cli/unicode_compat.py +283 -0
- ostruct/cli/upload_manager.py +448 -0
- ostruct/cli/validators.py +255 -54
- {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/METADATA +230 -127
- ostruct_cli-1.0.0.dist-info/RECORD +80 -0
- ostruct/cli/commands/quick_ref.py +0 -54
- ostruct/cli/template_optimizer.py +0 -478
- ostruct_cli-0.8.29.dist-info/RECORD +0 -71
- {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/LICENSE +0 -0
- {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/WHEEL +0 -0
- {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/entry_points.txt +0 -0
ostruct/cli/cli.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""Main CLI module for ostruct."""
|
2
3
|
|
4
|
+
import os
|
3
5
|
import sys
|
4
6
|
from typing import Optional
|
5
7
|
|
6
|
-
import click
|
8
|
+
import rich_click as click
|
7
9
|
from dotenv import load_dotenv
|
8
10
|
|
9
11
|
from .. import __version__
|
@@ -17,9 +19,40 @@ from .errors import (
|
|
17
19
|
handle_error,
|
18
20
|
)
|
19
21
|
from .exit_codes import ExitCode
|
22
|
+
from .help_json import print_full_cli_help_json as print_full_help_json
|
20
23
|
from .registry_updates import get_update_notification
|
24
|
+
|
25
|
+
# Import rich-click configuration
|
26
|
+
from .rich_config import * # noqa: F401,F403
|
27
|
+
from .unicode_compat import safe_emoji
|
21
28
|
from .utils import fix_surrogate_escapes
|
22
29
|
|
30
|
+
# Load environment variables from .env file
|
31
|
+
load_dotenv()
|
32
|
+
|
33
|
+
|
34
|
+
def _handle_quick_ref(
|
35
|
+
ctx: click.Context, param: click.Parameter, value: bool
|
36
|
+
) -> None:
|
37
|
+
"""Handle --quick-ref flag by showing quick reference help and exiting."""
|
38
|
+
if not value or ctx.resilient_parsing:
|
39
|
+
return
|
40
|
+
|
41
|
+
from .quick_ref_help import show_quick_ref_help
|
42
|
+
|
43
|
+
show_quick_ref_help()
|
44
|
+
ctx.exit()
|
45
|
+
|
46
|
+
|
47
|
+
def _handle_version(
|
48
|
+
ctx: click.Context, param: click.Parameter, value: bool
|
49
|
+
) -> None:
|
50
|
+
"""Handle --version flag by showing version and exiting."""
|
51
|
+
if not value or ctx.resilient_parsing:
|
52
|
+
return
|
53
|
+
click.echo(f"ostruct, version {__version__}")
|
54
|
+
ctx.exit()
|
55
|
+
|
23
56
|
|
24
57
|
def fix_argv_encoding() -> None:
|
25
58
|
"""Fix UTF-8 encoding issues in sys.argv.
|
@@ -50,44 +83,55 @@ def fix_argv_encoding() -> None:
|
|
50
83
|
def create_cli_group() -> click.Group:
|
51
84
|
"""Create the main CLI group with all commands."""
|
52
85
|
|
53
|
-
@click.group()
|
54
|
-
@click.
|
86
|
+
@click.group(cls=click.RichGroup)
|
87
|
+
@click.option(
|
88
|
+
"--version",
|
89
|
+
"-V",
|
90
|
+
is_flag=True,
|
91
|
+
expose_value=False,
|
92
|
+
is_eager=True,
|
93
|
+
callback=_handle_version,
|
94
|
+
help="Show the version and exit.",
|
95
|
+
)
|
55
96
|
@click.option(
|
56
97
|
"--config",
|
57
98
|
type=click.Path(exists=True),
|
58
99
|
help="Configuration file path (default: ostruct.yaml)",
|
59
100
|
)
|
101
|
+
@click.option(
|
102
|
+
"--quick-ref",
|
103
|
+
is_flag=True,
|
104
|
+
callback=_handle_quick_ref,
|
105
|
+
expose_value=False,
|
106
|
+
is_eager=True,
|
107
|
+
help=f"{safe_emoji('📖')} Show concise usage examples and patterns",
|
108
|
+
)
|
109
|
+
@click.option(
|
110
|
+
"--help-json",
|
111
|
+
is_flag=True,
|
112
|
+
callback=print_full_help_json,
|
113
|
+
expose_value=False,
|
114
|
+
is_eager=True,
|
115
|
+
hidden=True, # Hide from help output - feature not ready for release
|
116
|
+
help=f"{safe_emoji('📖')} Output comprehensive help for all commands in JSON format",
|
117
|
+
)
|
118
|
+
@click.option(
|
119
|
+
"--unicode/--no-unicode",
|
120
|
+
default=None,
|
121
|
+
help="Force enable/disable Unicode emoji display (overrides auto-detection)",
|
122
|
+
envvar="OSTRUCT_UNICODE",
|
123
|
+
)
|
60
124
|
@click.pass_context
|
61
|
-
def cli_group(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
📁 FILE ROUTING (explicit tool assignment):
|
72
|
-
-ft/--file-for-template Template access only
|
73
|
-
-fc/--file-for-code-interpreter Code execution & analysis
|
74
|
-
-fs/--file-for-file-search Document search & retrieval
|
75
|
-
|
76
|
-
⚡ EXAMPLES:
|
77
|
-
# Basic usage (unchanged)
|
78
|
-
ostruct run template.j2 schema.json -f config.yaml
|
125
|
+
def cli_group(
|
126
|
+
ctx: click.Context,
|
127
|
+
config: Optional[str] = None,
|
128
|
+
unicode: Optional[bool] = None,
|
129
|
+
) -> None:
|
130
|
+
"""ostruct - AI-powered structured output with multi-tool integration."""
|
131
|
+
# Handle Unicode preference
|
132
|
+
if unicode is not None:
|
133
|
+
os.environ["OSTRUCT_UNICODE"] = "1" if unicode else "0"
|
79
134
|
|
80
|
-
# Multi-tool explicit routing
|
81
|
-
ostruct run analysis.j2 schema.json -fc data.csv -fs docs.pdf -ft config.yaml
|
82
|
-
|
83
|
-
# Advanced routing with --file-for
|
84
|
-
ostruct run task.j2 schema.json --file-for code-interpreter shared.json --file-for file-search shared.json
|
85
|
-
|
86
|
-
# MCP server integration
|
87
|
-
ostruct run template.j2 schema.json --mcp-server deepwiki@https://mcp.deepwiki.com/sse
|
88
|
-
|
89
|
-
📖 For detailed documentation: https://ostruct.readthedocs.io
|
90
|
-
"""
|
91
135
|
# Load configuration
|
92
136
|
try:
|
93
137
|
app_config = OstructConfig.load(config)
|
@@ -112,6 +156,86 @@ def create_cli_group() -> click.Group:
|
|
112
156
|
# Ensure any errors don't affect normal operation
|
113
157
|
pass
|
114
158
|
|
159
|
+
# Set the docstring dynamically with emoji compatibility
|
160
|
+
rocket = safe_emoji("🚀")
|
161
|
+
folder = safe_emoji("📁")
|
162
|
+
target = safe_emoji("🎯")
|
163
|
+
book = safe_emoji("📖")
|
164
|
+
lightning = safe_emoji("⚡")
|
165
|
+
wrench = safe_emoji("🔧")
|
166
|
+
|
167
|
+
cli_group.__doc__ = f"""ostruct - AI-powered structured output with multi-tool integration.
|
168
|
+
|
169
|
+
Transform unstructured inputs into structured JSON using OpenAI APIs, Jinja2 templates, and powerful tool integrations.
|
170
|
+
|
171
|
+
{rocket} **QUICK START**
|
172
|
+
|
173
|
+
ostruct run template.j2 schema.json --var name=value
|
174
|
+
|
175
|
+
{folder} **FILE ATTACHMENT SYSTEM**
|
176
|
+
|
177
|
+
--file [targets:]alias path Attach file with optional target routing
|
178
|
+
|
179
|
+
--dir [targets:]alias path Attach directory with optional target routing
|
180
|
+
|
181
|
+
{target} **TARGETS**
|
182
|
+
|
183
|
+
prompt (default) Template access only
|
184
|
+
|
185
|
+
code-interpreter, ci Code execution & analysis
|
186
|
+
|
187
|
+
file-search, fs Document search & retrieval
|
188
|
+
|
189
|
+
{book} **GETTING HELP**
|
190
|
+
|
191
|
+
ostruct --help Command overview
|
192
|
+
|
193
|
+
ostruct --quick-ref Usage examples and patterns
|
194
|
+
|
195
|
+
ostruct run --help Detailed options reference
|
196
|
+
|
197
|
+
ostruct run --help-debug Troubleshooting guide
|
198
|
+
|
199
|
+
{book} Documentation: https://ostruct.readthedocs.io
|
200
|
+
|
201
|
+
{lightning} **EXAMPLES**
|
202
|
+
|
203
|
+
# Basic usage
|
204
|
+
ostruct run template.j2 schema.json --file data file.txt
|
205
|
+
|
206
|
+
# Multi-tool routing
|
207
|
+
ostruct run analysis.j2 schema.json --file ci:data data.csv --file fs:docs manual.pdf
|
208
|
+
|
209
|
+
# Combined targets
|
210
|
+
ostruct run task.j2 schema.json --file ci,fs:shared data.json
|
211
|
+
|
212
|
+
# MCP server integration
|
213
|
+
ostruct run template.j2 schema.json --mcp-server deepwiki@https://mcp.deepwiki.com/sse
|
214
|
+
|
215
|
+
{wrench} **ENVIRONMENT VARIABLES**
|
216
|
+
|
217
|
+
```text
|
218
|
+
Core API Configuration:
|
219
|
+
OPENAI_API_KEY OpenAI API authentication key
|
220
|
+
OPENAI_API_BASE Custom OpenAI API base URL
|
221
|
+
|
222
|
+
Template Processing Limits:
|
223
|
+
OSTRUCT_TEMPLATE_FILE_LIMIT Max individual file size (default: 64KB)
|
224
|
+
OSTRUCT_TEMPLATE_TOTAL_LIMIT Max total files size (default: 1MB)
|
225
|
+
OSTRUCT_TEMPLATE_PREVIEW_LIMIT Template preview size limit (default: 4096)
|
226
|
+
|
227
|
+
System Behavior:
|
228
|
+
OSTRUCT_DISABLE_REGISTRY_UPDATE_CHECKS Disable model registry updates
|
229
|
+
OSTRUCT_MCP_URL_<name> Custom MCP server URLs
|
230
|
+
|
231
|
+
Unicode Display Control:
|
232
|
+
OSTRUCT_UNICODE=auto Auto-detect terminal capabilities (default)
|
233
|
+
OSTRUCT_UNICODE=1/true/yes Force emoji display (override detection)
|
234
|
+
OSTRUCT_UNICODE=0/false/no Force plain text (override detection)
|
235
|
+
OSTRUCT_UNICODE=debug Show detection details and auto-detect
|
236
|
+
```
|
237
|
+
"""
|
238
|
+
|
115
239
|
# Add all commands from the command module
|
116
240
|
command_group = create_command_group()
|
117
241
|
for command in command_group.commands.values():
|