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.
Files changed (49) hide show
  1. ostruct/cli/__init__.py +3 -15
  2. ostruct/cli/attachment_processor.py +455 -0
  3. ostruct/cli/attachment_template_bridge.py +973 -0
  4. ostruct/cli/cli.py +157 -33
  5. ostruct/cli/click_options.py +775 -692
  6. ostruct/cli/code_interpreter.py +195 -12
  7. ostruct/cli/commands/__init__.py +0 -3
  8. ostruct/cli/commands/run.py +289 -62
  9. ostruct/cli/config.py +23 -22
  10. ostruct/cli/constants.py +89 -0
  11. ostruct/cli/errors.py +175 -5
  12. ostruct/cli/explicit_file_processor.py +0 -15
  13. ostruct/cli/file_info.py +97 -15
  14. ostruct/cli/file_list.py +43 -1
  15. ostruct/cli/file_search.py +68 -2
  16. ostruct/cli/help_json.py +235 -0
  17. ostruct/cli/mcp_integration.py +13 -16
  18. ostruct/cli/params.py +217 -0
  19. ostruct/cli/plan_assembly.py +335 -0
  20. ostruct/cli/plan_printing.py +385 -0
  21. ostruct/cli/progress_reporting.py +8 -56
  22. ostruct/cli/quick_ref_help.py +128 -0
  23. ostruct/cli/rich_config.py +299 -0
  24. ostruct/cli/runner.py +397 -190
  25. ostruct/cli/security/__init__.py +2 -0
  26. ostruct/cli/security/allowed_checker.py +41 -0
  27. ostruct/cli/security/normalization.py +13 -9
  28. ostruct/cli/security/security_manager.py +558 -17
  29. ostruct/cli/security/types.py +15 -0
  30. ostruct/cli/template_debug.py +283 -261
  31. ostruct/cli/template_debug_help.py +233 -142
  32. ostruct/cli/template_env.py +46 -5
  33. ostruct/cli/template_filters.py +415 -8
  34. ostruct/cli/template_processor.py +240 -619
  35. ostruct/cli/template_rendering.py +49 -73
  36. ostruct/cli/template_validation.py +2 -1
  37. ostruct/cli/token_validation.py +35 -15
  38. ostruct/cli/types.py +15 -19
  39. ostruct/cli/unicode_compat.py +283 -0
  40. ostruct/cli/upload_manager.py +448 -0
  41. ostruct/cli/validators.py +255 -54
  42. {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/METADATA +230 -127
  43. ostruct_cli-1.0.0.dist-info/RECORD +80 -0
  44. ostruct/cli/commands/quick_ref.py +0 -54
  45. ostruct/cli/template_optimizer.py +0 -478
  46. ostruct_cli-0.8.29.dist-info/RECORD +0 -71
  47. {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/LICENSE +0 -0
  48. {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/WHEEL +0 -0
  49. {ostruct_cli-0.8.29.dist-info → ostruct_cli-1.0.0.dist-info}/entry_points.txt +0 -0
@@ -3,160 +3,251 @@
3
3
  This module provides comprehensive help and examples for template debugging features.
4
4
  """
5
5
 
6
- import click
7
-
8
- TEMPLATE_DEBUG_HELP = """
9
- 🐛 Template Debugging Quick Reference
10
-
11
- BASIC DEBUGGING:
12
- --debug 🐛 Enable all debug output (verbose logging + template expansion)
13
- --show-templates 📝 Show expanded templates only (clean output)
14
- --show-context 📋 Show template variables summary
15
- --show-context-detailed 📋 Show detailed variable context with content preview
16
- --debug-templates 🔍 Enable step-by-step template expansion analysis
17
-
18
- OPTIMIZATION DEBUGGING:
19
- --show-pre-optimization 🔧 Show template before optimization
20
- --show-optimization-diff 🔄 Show optimization changes (before/after comparison)
21
- --show-optimization-steps 🔧 Show detailed optimization step tracking
22
- --optimization-step-detail [summary|detailed] 📊 Control step detail level
23
- --no-optimization ⚡ Skip optimization entirely for debugging
24
-
25
- PERFORMANCE ANALYSIS:
26
- --profile-template ⏱️ Show template performance breakdown (future)
27
- --analyze-optimization 📊 Show optimization impact analysis (future)
28
-
29
- INTERACTIVE DEBUGGING:
30
- ostruct debug template.j2 schema.json --debug-shell 🎯 Interactive debug shell (future)
31
-
32
- EXAMPLES:
33
-
34
- 🔍 Basic Template Debugging:
35
- # Show everything (most verbose)
36
- ostruct run template.j2 schema.json --debug -ft config.yaml
37
-
38
- # Just template content (clean output)
39
- ostruct run template.j2 schema.json --show-templates -ft config.yaml
40
-
41
- # Show template variables and context
42
- ostruct run template.j2 schema.json --show-context -ft config.yaml
43
-
44
- 🔧 Optimization Debugging:
45
- # See template before optimization
46
- ostruct run template.j2 schema.json --show-pre-optimization -ft config.yaml
47
-
48
- # See what optimization changed
49
- ostruct run template.j2 schema.json --show-optimization-diff -ft config.yaml
50
-
51
- # See step-by-step optimization process
52
- ostruct run template.j2 schema.json --show-optimization-steps -ft config.yaml
53
-
54
- # Detailed optimization steps with full diffs
55
- ostruct run template.j2 schema.json --show-optimization-steps --optimization-step-detail detailed -ft config.yaml
56
-
57
- # Skip optimization entirely
58
- ostruct run template.j2 schema.json --no-optimization -ft config.yaml
59
-
60
- 🎯 Combined Debugging:
61
- # Show both optimization diff and steps
62
- ostruct run template.j2 schema.json --show-optimization-diff --show-optimization-steps -ft config.yaml
63
-
64
- # Full debugging with context and optimization
65
- ostruct run template.j2 schema.json --debug --show-context --show-optimization-diff -ft config.yaml
66
-
67
- 🚨 Troubleshooting Common Issues:
68
-
69
- ❌ Undefined Variable Errors:
70
- Problem: UndefinedError: 'variable_name' is undefined
71
- Solution: Use --show-context to see available variables
72
- Example: ostruct run template.j2 schema.json --show-context -ft config.yaml
73
-
74
- ❌ Template Not Expanding:
75
- Problem: Template appears unchanged in output
76
- Solution: Use --show-templates to see expansion
77
- Example: ostruct run template.j2 schema.json --show-templates -ft config.yaml
78
-
79
- ❌ Optimization Breaking Template:
80
- Problem: Template works without optimization but fails with it
81
- Solution: Use --show-optimization-diff to see changes
82
- Example: ostruct run template.j2 schema.json --show-optimization-diff -ft config.yaml
83
-
84
- ❌ Performance Issues:
85
- Problem: Template rendering is slow
86
- Solution: Use --show-optimization-steps to see bottlenecks
87
- Example: ostruct run template.j2 schema.json --show-optimization-steps -ft config.yaml
88
-
89
- 💡 Pro Tips:
90
- • Use --dry-run with debugging flags to avoid API calls
91
- • Combine multiple debug flags for comprehensive analysis
92
- • Start with --show-templates for basic template issues
93
- • Use --debug for full diagnostic information
94
- • Use --show-context when variables are undefined
95
- • Use optimization debugging when templates work but optimization fails
96
-
97
- 📚 For more information, see: docs/template_debugging.md
98
- """
6
+ from rich.console import Console
7
+ from rich.panel import Panel
8
+ from rich.syntax import Syntax
9
+ from rich.text import Text
99
10
 
100
11
 
101
12
  def show_template_debug_help() -> None:
102
- """Display comprehensive template debugging help."""
103
- click.echo(TEMPLATE_DEBUG_HELP, err=True)
13
+ """Display comprehensive template debugging help with rich formatting."""
14
+ console = Console(stderr=True)
15
+
16
+ # Main title
17
+ title = Text(
18
+ "🐛 Template Debugging Quick Reference", style="bold bright_blue"
19
+ )
20
+ console.print(title)
21
+ console.print()
22
+
23
+ # Basic debugging section
24
+ basic_content = """[bold bright_blue]--debug[/bold bright_blue] 🐛 Enable all debug output (verbose logging + template expansion)
25
+ [bold bright_blue]--template-debug[/bold bright_blue] CAPACITIES 📝 Enable specific debugging capacities (see CAPACITIES below)"""
26
+
27
+ basic_panel = Panel(
28
+ basic_content,
29
+ title="[bold]Basic Debugging[/bold]",
30
+ border_style="blue",
31
+ padding=(1, 2),
32
+ )
33
+ console.print(basic_panel)
34
+
35
+ # Capacities section
36
+ capacities_content = """[bold cyan]pre-expand[/bold cyan] 📋 Show template variables before expansion
37
+ [bold cyan]vars[/bold cyan] 📊 Show template variable types and names
38
+ [bold cyan]preview[/bold cyan] 👁️ Show preview of variable content
39
+ [bold cyan]steps[/bold cyan] 🔄 Show step-by-step template expansion
40
+ [bold cyan]post-expand[/bold cyan] 📝 Show expanded templates after processing"""
41
+
42
+ capacities_panel = Panel(
43
+ capacities_content,
44
+ title="[bold]Available Capacities[/bold]",
45
+ border_style="cyan",
46
+ padding=(1, 2),
47
+ )
48
+ console.print(capacities_panel)
49
+
50
+ # Examples section
51
+ console.print(Text("🔍 Examples", style="bold bright_green"))
52
+ console.print()
53
+
54
+ # Basic debugging examples
55
+ basic_examples = [
56
+ (
57
+ "Show everything (most verbose)",
58
+ "ostruct run template.j2 schema.json --debug --file config config.yaml",
59
+ ),
60
+ (
61
+ "Just template content (clean)",
62
+ "ostruct run template.j2 schema.json --template-debug post-expand --file config config.yaml",
63
+ ),
64
+ (
65
+ "Show variables and context",
66
+ "ostruct run template.j2 schema.json --template-debug vars,preview --file config config.yaml",
67
+ ),
68
+ (
69
+ "Step-by-step expansion",
70
+ "ostruct run template.j2 schema.json --template-debug steps --file config config.yaml",
71
+ ),
72
+ ]
73
+
74
+ for desc, cmd in basic_examples:
75
+ console.print(f"[dim]# {desc}[/dim]")
76
+ syntax = Syntax(
77
+ cmd, "bash", theme="monokai", background_color="default"
78
+ )
79
+ console.print(syntax)
80
+ console.print()
81
+
82
+ # Combined debugging example
83
+ console.print("[dim]# Full debugging with context[/dim]")
84
+ combined_cmd = "ostruct run template.j2 schema.json --debug --template-debug vars,preview,post-expand --file config config.yaml"
85
+ syntax = Syntax(
86
+ combined_cmd, "bash", theme="monokai", background_color="default"
87
+ )
88
+ console.print(syntax)
89
+ console.print()
90
+
91
+ # Troubleshooting section
92
+ troubleshooting_title = Text(
93
+ "🚨 Troubleshooting Common Issues", style="bold red"
94
+ )
95
+ console.print(troubleshooting_title)
96
+ console.print()
97
+
98
+ # Create troubleshooting panels
99
+ issues = [
100
+ {
101
+ "title": "❌ Undefined Variable Errors",
102
+ "problem": "UndefinedError: 'variable_name' is undefined",
103
+ "solution": "Use --template-debug vars,preview to see available variables",
104
+ "example": "ostruct run template.j2 schema.json --template-debug vars,preview --file config config.yaml",
105
+ },
106
+ {
107
+ "title": "❌ Template Not Expanding",
108
+ "problem": "Template appears unchanged in output",
109
+ "solution": "Use --template-debug post-expand to see expansion",
110
+ "example": "ostruct run template.j2 schema.json --template-debug post-expand --file config config.yaml",
111
+ },
112
+ {
113
+ "title": "❌ Performance Issues",
114
+ "problem": "Template rendering is slow",
115
+ "solution": "Use --template-debug steps to see processing bottlenecks",
116
+ "example": "ostruct run template.j2 schema.json --template-debug steps --file config config.yaml",
117
+ },
118
+ ]
119
+
120
+ for issue in issues:
121
+ content = f"""[bold red]Problem:[/bold red] {issue["problem"]}
122
+ [bold green]Solution:[/bold green] {issue["solution"]}
123
+ [bold blue]Example:[/bold blue]
124
+ [dim cyan]{issue["example"]}[/dim cyan]"""
125
+
126
+ panel = Panel(
127
+ content,
128
+ title=f"[bold]{issue['title']}[/bold]",
129
+ border_style="red",
130
+ padding=(1, 2),
131
+ )
132
+ console.print(panel)
133
+ console.print()
134
+
135
+ # Pro tips section
136
+ tips_content = """• Use [bold cyan]--dry-run[/bold cyan] with debugging flags to avoid API calls
137
+ • Combine multiple debug capacities: [bold cyan]--template-debug vars,preview,post-expand[/bold cyan]
138
+ • Start with [bold cyan]--template-debug post-expand[/bold cyan] for basic template issues
139
+ • Use [bold cyan]--debug[/bold cyan] for full diagnostic information
140
+ • Use [bold cyan]--template-debug vars,preview[/bold cyan] when variables are undefined"""
141
+
142
+ tips_panel = Panel(
143
+ tips_content,
144
+ title="[bold]💡 Pro Tips[/bold]",
145
+ border_style="yellow",
146
+ padding=(1, 2),
147
+ )
148
+ console.print(tips_panel)
149
+
150
+ # Footer
151
+ console.print()
152
+ footer = Text(
153
+ "📚 For more information, see: docs/template_debugging.md",
154
+ style="dim italic",
155
+ )
156
+ console.print(footer)
104
157
 
105
158
 
106
159
  def show_quick_debug_tips() -> None:
107
- """Show quick debugging tips for common issues."""
108
- quick_tips = """
109
- 🚀 Quick Debug Tips:
160
+ """Show quick debugging tips for common issues with rich formatting."""
161
+ console = Console(stderr=True)
110
162
 
111
- Template not working? Try:
112
- 1. ostruct run template.j2 schema.json --show-templates --dry-run
113
- 2. ostruct run template.j2 schema.json --show-context --dry-run
114
- 3. ostruct run template.j2 schema.json --debug --dry-run
163
+ title = Text("🚀 Quick Debug Tips", style="bold bright_green")
164
+ console.print(title)
165
+ console.print()
115
166
 
116
- Optimization issues? Try:
117
- 1. ostruct run template.j2 schema.json --show-optimization-diff --dry-run
118
- 2. ostruct run template.j2 schema.json --no-optimization --dry-run
167
+ content = """[bold]Template not working? Try:[/bold]
168
+ 1. [cyan]ostruct run template.j2 schema.json --template-debug post-expand --dry-run[/cyan]
169
+ 2. [cyan]ostruct run template.j2 schema.json --template-debug vars,preview --dry-run[/cyan]
170
+ 3. [cyan]ostruct run template.j2 schema.json --debug --dry-run[/cyan]
119
171
 
120
- For full help: ostruct run --help-debug
121
- """
122
- click.echo(quick_tips, err=True)
172
+ [bold]Performance issues? Try:[/bold]
173
+ 1. [cyan]ostruct run template.j2 schema.json --template-debug steps --dry-run[/cyan]
123
174
 
175
+ [dim]For full help: ostruct run --help-debug[/dim]"""
124
176
 
125
- def show_debug_examples() -> None:
126
- """Show practical debugging examples."""
127
- examples = """
128
- 🎯 Template Debugging Examples:
177
+ panel = Panel(content, border_style="green", padding=(1, 2))
178
+ console.print(panel)
129
179
 
130
- 📝 Basic Template Issues:
131
- # Check if template expands correctly
132
- ostruct run my_template.j2 schema.json --show-templates --dry-run -ft config.yaml
133
180
 
134
- # See what variables are available
135
- ostruct run my_template.j2 schema.json --show-context --dry-run -ft config.yaml
136
-
137
- # Full debug output
138
- ostruct run my_template.j2 schema.json --debug --dry-run -ft config.yaml
139
-
140
- 🔧 Optimization Issues:
141
- # See what optimization does to your template
142
- ostruct run my_template.j2 schema.json --show-optimization-diff --dry-run -ft config.yaml
143
-
144
- # Track each optimization step
145
- ostruct run my_template.j2 schema.json --show-optimization-steps --dry-run -ft config.yaml
146
-
147
- # Bypass optimization entirely
148
- ostruct run my_template.j2 schema.json --no-optimization --dry-run -ft config.yaml
149
-
150
- 🔍 Advanced Debugging:
151
- # Combine multiple debug features
152
- ostruct run my_template.j2 schema.json \\
181
+ def show_debug_examples() -> None:
182
+ """Show practical debugging examples with rich formatting."""
183
+ console = Console(stderr=True)
184
+
185
+ title = Text("🎯 Template Debugging Examples", style="bold bright_blue")
186
+ console.print(title)
187
+ console.print()
188
+
189
+ examples = [
190
+ {
191
+ "title": "📝 Basic Template Issues",
192
+ "commands": [
193
+ (
194
+ "Check if template expands correctly",
195
+ "ostruct run my_template.j2 schema.json --template-debug post-expand --dry-run --file config config.yaml",
196
+ ),
197
+ (
198
+ "See what variables are available",
199
+ "ostruct run my_template.j2 schema.json --template-debug vars,preview --dry-run --file config config.yaml",
200
+ ),
201
+ (
202
+ "Full debug output",
203
+ "ostruct run my_template.j2 schema.json --debug --dry-run --file config config.yaml",
204
+ ),
205
+ ],
206
+ },
207
+ {
208
+ "title": "🔧 Performance Issues",
209
+ "commands": [
210
+ (
211
+ "Track template processing steps",
212
+ "ostruct run my_template.j2 schema.json --template-debug steps --dry-run --file config config.yaml",
213
+ )
214
+ ],
215
+ },
216
+ ]
217
+
218
+ for example in examples:
219
+ console.print(Text(str(example["title"]), style="bold bright_blue"))
220
+ console.print()
221
+
222
+ for desc, cmd in example["commands"]:
223
+ console.print(f"[dim]# {desc}[/dim]")
224
+ syntax = Syntax(
225
+ cmd, "bash", theme="monokai", background_color="default"
226
+ )
227
+ console.print(syntax)
228
+ console.print()
229
+
230
+ # Advanced example
231
+ console.print(Text("🔍 Advanced Debugging", style="bold bright_blue"))
232
+ console.print()
233
+ console.print("[dim]# Combine multiple debug features[/dim]")
234
+
235
+ advanced_cmd = """ostruct run my_template.j2 schema.json \\
153
236
  --debug \\
154
- --show-context \\
155
- --show-optimization-diff \\
156
- --show-optimization-steps \\
237
+ --template-debug vars,preview,post-expand,steps \\
157
238
  --dry-run \\
158
- -ft config.yaml
159
-
160
- 💡 Remember: Always use --dry-run when debugging to avoid API calls!
161
- """
162
- click.echo(examples, err=True)
239
+ --file config config.yaml"""
240
+
241
+ syntax = Syntax(
242
+ advanced_cmd, "bash", theme="monokai", background_color="default"
243
+ )
244
+ console.print(syntax)
245
+ console.print()
246
+
247
+ # Reminder
248
+ reminder = Panel(
249
+ "[bold yellow]💡 Remember: Always use --dry-run when debugging to avoid API calls![/bold yellow]",
250
+ border_style="yellow",
251
+ padding=(0, 2),
252
+ )
253
+ console.print(reminder)
@@ -3,14 +3,18 @@
3
3
  This module provides a centralized factory for creating consistently configured Jinja2 environments.
4
4
  """
5
5
 
6
- from typing import List, Optional, Type, Union
6
+ from typing import Any, List, Optional, Tuple, Type, Union
7
7
 
8
8
  import jinja2
9
9
  from jinja2 import Environment
10
10
  from jinja2.ext import Extension
11
11
 
12
12
  from .template_extensions import CommentExtension
13
- from .template_filters import register_template_filters
13
+ from .template_filters import (
14
+ AliasManager,
15
+ register_template_filters,
16
+ register_tses_filters,
17
+ )
14
18
 
15
19
 
16
20
  def create_jinja_env(
@@ -19,7 +23,8 @@ def create_jinja_env(
19
23
  loader: Optional[jinja2.BaseLoader] = None,
20
24
  validation_mode: bool = False,
21
25
  debug_mode: bool = False,
22
- ) -> Environment:
26
+ files: Optional[List[Any]] = None,
27
+ ) -> Tuple[Environment, AliasManager]:
23
28
  """Create a consistently configured Jinja2 environment.
24
29
 
25
30
  Args:
@@ -27,9 +32,10 @@ def create_jinja_env(
27
32
  loader: Template loader to use. Defaults to None.
28
33
  validation_mode: Whether to configure the environment for validation (uses SafeUndefined).
29
34
  debug_mode: Whether to enable debug features like undefined variable detection.
35
+ files: Optional list of FileInfo objects to enable file reference support.
30
36
 
31
37
  Returns:
32
- A configured Jinja2 environment.
38
+ Tuple of (Environment, AliasManager). AliasManager will be empty if no files provided.
33
39
  """
34
40
  if validation_mode:
35
41
  from .template_validation import SafeUndefined
@@ -61,4 +67,39 @@ def create_jinja_env(
61
67
  # Register all template filters
62
68
  register_template_filters(env)
63
69
 
64
- return env
70
+ # Always create an alias manager
71
+ alias_manager = AliasManager()
72
+
73
+ # If files are provided, set up file reference support
74
+ if files is not None:
75
+ # Group files by their parent alias
76
+ alias_groups: dict[str, List[Any]] = {}
77
+ for file_info in files:
78
+ if hasattr(file_info, "parent_alias") and file_info.parent_alias:
79
+ alias = file_info.parent_alias
80
+ if alias not in alias_groups:
81
+ alias_groups[alias] = []
82
+ alias_groups[alias].append(file_info)
83
+
84
+ # Register each alias group
85
+ for alias, file_list in alias_groups.items():
86
+ if file_list:
87
+ # Use the first file to determine the base path and attachment type
88
+ first_file = file_list[0]
89
+ base_path = getattr(first_file, "base_path", first_file.path)
90
+ attachment_type = getattr(
91
+ first_file, "attachment_type", "file"
92
+ )
93
+ is_collection = attachment_type == "collection"
94
+
95
+ alias_manager.register_attachment(
96
+ alias,
97
+ base_path,
98
+ file_list,
99
+ is_collection,
100
+ )
101
+
102
+ # Always register file reference functions in the environment
103
+ register_tses_filters(env, alias_manager)
104
+
105
+ return env, alias_manager