cliops 4.0.0__tar.gz → 4.2.2__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.
- {cliops-4.0.0/cliops.egg-info → cliops-4.2.2}/PKG-INFO +6 -9
- {cliops-4.0.0 → cliops-4.2.2}/README.md +1 -1
- {cliops-4.0.0 → cliops-4.2.2/cliops.egg-info}/PKG-INFO +6 -9
- {cliops-4.0.0 → cliops-4.2.2}/cliops.egg-info/SOURCES.txt +2 -8
- {cliops-4.0.0 → cliops-4.2.2}/cliops.egg-info/requires.txt +0 -3
- cliops-4.2.2/core/intelligence.py +199 -0
- cliops-4.2.2/core/optimizer.py +202 -0
- {cliops-4.0.0 → cliops-4.2.2}/core/patterns.py +58 -85
- {cliops-4.0.0 → cliops-4.2.2}/core/state.py +1 -1
- {cliops-4.0.0 → cliops-4.2.2}/main.py +9 -18
- cliops-4.2.2/requirements.txt +1 -0
- {cliops-4.0.0 → cliops-4.2.2}/setup.py +5 -5
- cliops-4.2.2/tests/test_integration.py +52 -0
- {cliops-4.0.0 → cliops-4.2.2}/tests/test_optimizer.py +14 -27
- cliops-4.0.0/core/branding.py +0 -34
- cliops-4.0.0/core/cache.py +0 -51
- cliops-4.0.0/core/optimizer.py +0 -181
- cliops-4.0.0/core/setup.py +0 -77
- cliops-4.0.0/core/validation.py +0 -49
- cliops-4.0.0/requirements.txt +0 -4
- cliops-4.0.0/tests/test_cache.py +0 -50
- cliops-4.0.0/tests/test_cli_integration.py +0 -65
- cliops-4.0.0/tests/test_integration.py +0 -74
- cliops-4.0.0/tests/test_validation.py +0 -56
- {cliops-4.0.0 → cliops-4.2.2}/LICENSE +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/MANIFEST.in +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/cliops.egg-info/dependency_links.txt +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/cliops.egg-info/entry_points.txt +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/cliops.egg-info/not-zip-safe +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/cliops.egg-info/top_level.txt +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/core/__init__.py +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/core/analyzer.py +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/core/config.py +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/post_install.py +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/presets.py +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/setup.cfg +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/tests/__init__.py +0 -0
- {cliops-4.0.0 → cliops-4.2.2}/tests/test_patterns.py +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cliops
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.2.2
|
|
4
4
|
Summary: Advanced CLI tool for structured, pattern-based prompt optimization and state management
|
|
5
|
-
Home-page: https://github.com/
|
|
5
|
+
Home-page: https://github.com/cliops/cliops
|
|
6
6
|
Author: cliops by mabd
|
|
7
7
|
Author-email: iammabd@substack.com
|
|
8
|
-
Project-URL: Bug Reports, https://github.com/
|
|
9
|
-
Project-URL: Source, https://github.com/
|
|
10
|
-
Project-URL: Documentation, https://cliops.
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/cliops/cliops/issues
|
|
9
|
+
Project-URL: Source, https://github.com/cliops/cliops
|
|
10
|
+
Project-URL: Documentation, https://cliops.readthedocs.io
|
|
11
11
|
Keywords: cli prompt optimization ai llm prompt-engineering patterns state-management
|
|
12
12
|
Classifier: Development Status :: 5 - Production/Stable
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -29,9 +29,6 @@ Requires-Python: >=3.8
|
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
30
30
|
License-File: LICENSE
|
|
31
31
|
Requires-Dist: rich>=13.0.0
|
|
32
|
-
Requires-Dist: jinja2>=3.0.0
|
|
33
|
-
Requires-Dist: pydantic>=2.0.0
|
|
34
|
-
Requires-Dist: typing-extensions>=4.0.0
|
|
35
32
|
Provides-Extra: dev
|
|
36
33
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
37
34
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
@@ -54,7 +51,7 @@ Dynamic: requires-dist
|
|
|
54
51
|
Dynamic: requires-python
|
|
55
52
|
Dynamic: summary
|
|
56
53
|
|
|
57
|
-
#
|
|
54
|
+
# CliOps - Command Line Interface for Prompt Optimization
|
|
58
55
|
|
|
59
56
|
A powerful CLI tool for structured, pattern-based prompt optimization and state management.
|
|
60
57
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cliops
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.2.2
|
|
4
4
|
Summary: Advanced CLI tool for structured, pattern-based prompt optimization and state management
|
|
5
|
-
Home-page: https://github.com/
|
|
5
|
+
Home-page: https://github.com/cliops/cliops
|
|
6
6
|
Author: cliops by mabd
|
|
7
7
|
Author-email: iammabd@substack.com
|
|
8
|
-
Project-URL: Bug Reports, https://github.com/
|
|
9
|
-
Project-URL: Source, https://github.com/
|
|
10
|
-
Project-URL: Documentation, https://cliops.
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/cliops/cliops/issues
|
|
9
|
+
Project-URL: Source, https://github.com/cliops/cliops
|
|
10
|
+
Project-URL: Documentation, https://cliops.readthedocs.io
|
|
11
11
|
Keywords: cli prompt optimization ai llm prompt-engineering patterns state-management
|
|
12
12
|
Classifier: Development Status :: 5 - Production/Stable
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -29,9 +29,6 @@ Requires-Python: >=3.8
|
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
30
30
|
License-File: LICENSE
|
|
31
31
|
Requires-Dist: rich>=13.0.0
|
|
32
|
-
Requires-Dist: jinja2>=3.0.0
|
|
33
|
-
Requires-Dist: pydantic>=2.0.0
|
|
34
|
-
Requires-Dist: typing-extensions>=4.0.0
|
|
35
32
|
Provides-Extra: dev
|
|
36
33
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
37
34
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
@@ -54,7 +51,7 @@ Dynamic: requires-dist
|
|
|
54
51
|
Dynamic: requires-python
|
|
55
52
|
Dynamic: summary
|
|
56
53
|
|
|
57
|
-
#
|
|
54
|
+
# CliOps - Command Line Interface for Prompt Optimization
|
|
58
55
|
|
|
59
56
|
A powerful CLI tool for structured, pattern-based prompt optimization and state management.
|
|
60
57
|
|
|
@@ -15,18 +15,12 @@ cliops.egg-info/requires.txt
|
|
|
15
15
|
cliops.egg-info/top_level.txt
|
|
16
16
|
core/__init__.py
|
|
17
17
|
core/analyzer.py
|
|
18
|
-
core/branding.py
|
|
19
|
-
core/cache.py
|
|
20
18
|
core/config.py
|
|
19
|
+
core/intelligence.py
|
|
21
20
|
core/optimizer.py
|
|
22
21
|
core/patterns.py
|
|
23
|
-
core/setup.py
|
|
24
22
|
core/state.py
|
|
25
|
-
core/validation.py
|
|
26
23
|
tests/__init__.py
|
|
27
|
-
tests/test_cache.py
|
|
28
|
-
tests/test_cli_integration.py
|
|
29
24
|
tests/test_integration.py
|
|
30
25
|
tests/test_optimizer.py
|
|
31
|
-
tests/test_patterns.py
|
|
32
|
-
tests/test_validation.py
|
|
26
|
+
tests/test_patterns.py
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Dict, List, Tuple
|
|
3
|
+
|
|
4
|
+
class PromptIntelligence:
|
|
5
|
+
"""Analyzes prompts to determine optimal patterns and generate contextual content."""
|
|
6
|
+
|
|
7
|
+
DOMAIN_PATTERNS = {
|
|
8
|
+
'web_frontend': [
|
|
9
|
+
r'\b(react|vue|angular|svelte|next|nuxt|gatsby|html|css|sass|scss|less|tailwind)\b',
|
|
10
|
+
r'\b(component|hook|state|props|dom|browser|webpack|vite|rollup)\b',
|
|
11
|
+
r'\b(ui|ux|responsive|mobile|desktop|layout|design|frontend|landing|page|website|saas)\b'
|
|
12
|
+
],
|
|
13
|
+
'web_backend': [
|
|
14
|
+
r'\b(api|endpoint|server|database|sql|rest|graphql|grpc)\b',
|
|
15
|
+
r'\b(express|django|flask|fastapi|spring|node|laravel|rails|asp\.net)\b',
|
|
16
|
+
r'\b(auth|middleware|route|controller|service|backend|microservice)\b'
|
|
17
|
+
],
|
|
18
|
+
'mobile': [
|
|
19
|
+
r'\b(ios|android|flutter|react native|ionic|xamarin|swift|kotlin|dart)\b',
|
|
20
|
+
r'\b(app|mobile|device|platform|store|xcode|android studio)\b',
|
|
21
|
+
r'\b(native|hybrid|cross-platform|pwa)\b'
|
|
22
|
+
],
|
|
23
|
+
'data_science': [
|
|
24
|
+
r'\b(pandas|numpy|matplotlib|seaborn|plotly|sklearn|tensorflow|pytorch|keras)\b',
|
|
25
|
+
r'\b(data|analysis|model|ml|ai|algorithm|dataset|jupyter|notebook)\b',
|
|
26
|
+
r'\b(statistics|regression|classification|clustering|deep learning)\b'
|
|
27
|
+
],
|
|
28
|
+
'devops': [
|
|
29
|
+
r'\b(docker|kubernetes|aws|azure|gcp|terraform|ansible|jenkins)\b',
|
|
30
|
+
r'\b(deploy|ci/cd|pipeline|infrastructure|monitoring|helm|istio)\b',
|
|
31
|
+
r'\b(cloud|serverless|container|orchestration|automation)\b'
|
|
32
|
+
],
|
|
33
|
+
'game_development': [
|
|
34
|
+
r'\b(unity|unreal|godot|pygame|phaser|three\.js|webgl)\b',
|
|
35
|
+
r'\b(game|gaming|2d|3d|sprite|animation|physics|collision)\b',
|
|
36
|
+
r'\b(c#|c\+\+|lua|gdscript|shader|texture|mesh)\b'
|
|
37
|
+
],
|
|
38
|
+
'blockchain': [
|
|
39
|
+
r'\b(solidity|ethereum|bitcoin|web3|smart contract|dapp|nft)\b',
|
|
40
|
+
r'\b(blockchain|crypto|defi|dao|token|wallet|metamask)\b',
|
|
41
|
+
r'\b(truffle|hardhat|ganache|remix|openzeppelin)\b'
|
|
42
|
+
],
|
|
43
|
+
'desktop': [
|
|
44
|
+
r'\b(electron|tauri|qt|gtk|wpf|winforms|javafx|swing)\b',
|
|
45
|
+
r'\b(desktop|gui|window|native|cross-platform)\b',
|
|
46
|
+
r'\b(c#|java|c\+\+|python|rust|go)\b'
|
|
47
|
+
],
|
|
48
|
+
'embedded': [
|
|
49
|
+
r'\b(arduino|raspberry pi|esp32|microcontroller|firmware|rtos)\b',
|
|
50
|
+
r'\b(embedded|iot|sensor|actuator|gpio|i2c|spi|uart)\b',
|
|
51
|
+
r'\b(c|c\+\+|assembly|micropython|circuitpython)\b'
|
|
52
|
+
],
|
|
53
|
+
'security': [
|
|
54
|
+
r'\b(security|vulnerability|penetration|exploit|malware|encryption)\b',
|
|
55
|
+
r'\b(auth|oauth|jwt|ssl|tls|https|firewall|vpn)\b',
|
|
56
|
+
r'\b(cybersecurity|infosec|pentest|owasp|cve)\b'
|
|
57
|
+
],
|
|
58
|
+
'testing': [
|
|
59
|
+
r'\b(test|testing|unit|integration|e2e|selenium|cypress|jest)\b',
|
|
60
|
+
r'\b(mock|stub|fixture|assertion|coverage|tdd|bdd)\b',
|
|
61
|
+
r'\b(pytest|junit|mocha|jasmine|karma|playwright)\b'
|
|
62
|
+
],
|
|
63
|
+
'database': [
|
|
64
|
+
r'\b(mysql|postgresql|mongodb|redis|elasticsearch|cassandra|sqlite)\b',
|
|
65
|
+
r'\b(database|db|sql|nosql|query|schema|migration|orm)\b',
|
|
66
|
+
r'\b(prisma|sequelize|mongoose|sqlalchemy|hibernate)\b'
|
|
67
|
+
],
|
|
68
|
+
'system_programming': [
|
|
69
|
+
r'\b(rust|c|c\+\+|go|zig|assembly|kernel|driver|compiler)\b',
|
|
70
|
+
r'\b(system|low-level|memory|performance|optimization|concurrency)\b',
|
|
71
|
+
r'\b(linux|unix|windows|macos|operating system)\b'
|
|
72
|
+
],
|
|
73
|
+
'ai_ml': [
|
|
74
|
+
r'\b(machine learning|deep learning|neural network|ai|artificial intelligence)\b',
|
|
75
|
+
r'\b(tensorflow|pytorch|scikit-learn|huggingface|openai|llm|gpt)\b',
|
|
76
|
+
r'\b(model|training|inference|dataset|feature|algorithm)\b'
|
|
77
|
+
],
|
|
78
|
+
'api_integration': [
|
|
79
|
+
r'\b(api|rest|graphql|webhook|integration|third-party|sdk)\b',
|
|
80
|
+
r'\b(postman|curl|axios|fetch|http|json|xml)\b',
|
|
81
|
+
r'\b(oauth|authentication|rate limit|pagination)\b'
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
COMPLEXITY_INDICATORS = [
|
|
86
|
+
r'\b(implement|create|build|develop|design)\b',
|
|
87
|
+
r'\b(optimize|refactor|improve|enhance)\b',
|
|
88
|
+
r'\b(integrate|connect|sync|merge)\b',
|
|
89
|
+
r'\b(test|debug|fix|solve)\b'
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
@classmethod
|
|
93
|
+
def detect_domain(cls, prompt: str) -> str:
|
|
94
|
+
"""Detects the primary domain of the prompt."""
|
|
95
|
+
prompt_lower = prompt.lower()
|
|
96
|
+
domain_scores = {}
|
|
97
|
+
|
|
98
|
+
for domain, patterns in cls.DOMAIN_PATTERNS.items():
|
|
99
|
+
score = 0
|
|
100
|
+
for pattern in patterns:
|
|
101
|
+
matches = len(re.findall(pattern, prompt_lower))
|
|
102
|
+
score += matches
|
|
103
|
+
domain_scores[domain] = score
|
|
104
|
+
|
|
105
|
+
if not any(domain_scores.values()):
|
|
106
|
+
return 'general'
|
|
107
|
+
|
|
108
|
+
return max(domain_scores, key=domain_scores.get)
|
|
109
|
+
|
|
110
|
+
@classmethod
|
|
111
|
+
def assess_complexity(cls, prompt: str) -> str:
|
|
112
|
+
"""Assesses prompt complexity level."""
|
|
113
|
+
if len(prompt) < 50:
|
|
114
|
+
return 'simple'
|
|
115
|
+
|
|
116
|
+
complexity_matches = 0
|
|
117
|
+
for pattern in cls.COMPLEXITY_INDICATORS:
|
|
118
|
+
complexity_matches += len(re.findall(pattern, prompt.lower()))
|
|
119
|
+
|
|
120
|
+
if complexity_matches >= 3 or len(prompt) > 200:
|
|
121
|
+
return 'complex'
|
|
122
|
+
elif complexity_matches >= 1 or len(prompt) > 100:
|
|
123
|
+
return 'moderate'
|
|
124
|
+
|
|
125
|
+
return 'simple'
|
|
126
|
+
|
|
127
|
+
@classmethod
|
|
128
|
+
def suggest_pattern(cls, prompt: str) -> str:
|
|
129
|
+
"""Suggests the best pattern based on prompt analysis."""
|
|
130
|
+
domain = cls.detect_domain(prompt)
|
|
131
|
+
complexity = cls.assess_complexity(prompt)
|
|
132
|
+
|
|
133
|
+
# Pattern selection logic
|
|
134
|
+
if complexity == 'complex' or domain != 'general':
|
|
135
|
+
return 'adaptive_generation'
|
|
136
|
+
elif any(word in prompt.lower() for word in ['fix', 'bug', 'error', 'debug']):
|
|
137
|
+
return 'precision_engineering'
|
|
138
|
+
elif complexity == 'moderate':
|
|
139
|
+
return 'adaptive_generation'
|
|
140
|
+
|
|
141
|
+
return 'adaptive_generation'
|
|
142
|
+
|
|
143
|
+
@classmethod
|
|
144
|
+
def generate_contextual_constraints(cls, prompt: str, domain: str) -> str:
|
|
145
|
+
"""Generates domain-specific constraints."""
|
|
146
|
+
constraints_map = {
|
|
147
|
+
'web_frontend': 'Ensure responsive design, accessibility compliance, SEO optimization, and modern web standards.',
|
|
148
|
+
'web_backend': 'Follow REST/GraphQL principles, implement proper error handling, security, and scalability.',
|
|
149
|
+
'mobile': 'Optimize for performance, battery life, follow platform guidelines, and ensure intuitive UX.',
|
|
150
|
+
'data_science': 'Validate data integrity, document assumptions, ensure reproducibility, and statistical rigor.',
|
|
151
|
+
'devops': 'Prioritize reliability, implement monitoring, follow IaC principles, and ensure security.',
|
|
152
|
+
'game_development': 'Optimize for performance, frame rate, memory usage, and engaging gameplay mechanics.',
|
|
153
|
+
'blockchain': 'Ensure security, gas optimization, audit readiness, and decentralization principles.',
|
|
154
|
+
'desktop': 'Follow platform UI guidelines, ensure cross-platform compatibility, and optimize resource usage.',
|
|
155
|
+
'embedded': 'Minimize memory footprint, optimize power consumption, ensure real-time constraints.',
|
|
156
|
+
'security': 'Follow OWASP guidelines, implement defense in depth, and ensure compliance standards.',
|
|
157
|
+
'testing': 'Ensure comprehensive coverage, maintainable tests, and fast execution times.',
|
|
158
|
+
'database': 'Optimize queries, ensure ACID properties, implement proper indexing, and data integrity.',
|
|
159
|
+
'system_programming': 'Ensure memory safety, optimize performance, handle concurrency, and system compatibility.',
|
|
160
|
+
'ai_ml': 'Validate model performance, ensure data privacy, implement proper evaluation metrics.',
|
|
161
|
+
'api_integration': 'Handle rate limits, implement proper error handling, ensure data validation.',
|
|
162
|
+
'general': 'Follow clean code principles, ensure maintainability, and include comprehensive documentation.'
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
base_constraint = constraints_map.get(domain, constraints_map['general'])
|
|
166
|
+
|
|
167
|
+
# Add specific constraints based on prompt content
|
|
168
|
+
if 'performance' in prompt.lower():
|
|
169
|
+
base_constraint += ' Focus on optimization and performance.'
|
|
170
|
+
if 'security' in prompt.lower():
|
|
171
|
+
base_constraint += ' Implement security best practices.'
|
|
172
|
+
if 'test' in prompt.lower():
|
|
173
|
+
base_constraint += ' Include comprehensive testing.'
|
|
174
|
+
|
|
175
|
+
return base_constraint
|
|
176
|
+
|
|
177
|
+
@classmethod
|
|
178
|
+
def generate_success_criteria(cls, prompt: str, domain: str) -> str:
|
|
179
|
+
"""Generates contextual success criteria."""
|
|
180
|
+
criteria_map = {
|
|
181
|
+
'web_frontend': 'UI renders correctly across devices, accessibility standards met, performance optimized.',
|
|
182
|
+
'web_backend': 'API endpoints respond correctly, security implemented, scalability considered.',
|
|
183
|
+
'mobile': 'App functions on target platforms, smooth performance, intuitive user experience.',
|
|
184
|
+
'data_science': 'Analysis produces accurate results, code is reproducible, insights are actionable.',
|
|
185
|
+
'devops': 'Infrastructure deploys successfully, monitoring implemented, system is reliable and secure.',
|
|
186
|
+
'game_development': 'Game runs smoothly, engaging mechanics implemented, performance targets met.',
|
|
187
|
+
'blockchain': 'Smart contracts are secure, gas-optimized, and thoroughly tested.',
|
|
188
|
+
'desktop': 'Application runs on target platforms, UI follows guidelines, performance is optimal.',
|
|
189
|
+
'embedded': 'System meets real-time constraints, power consumption optimized, hardware compatibility ensured.',
|
|
190
|
+
'security': 'Vulnerabilities identified and mitigated, compliance requirements met, security tested.',
|
|
191
|
+
'testing': 'Comprehensive test coverage achieved, tests are maintainable, CI/CD integration works.',
|
|
192
|
+
'database': 'Queries perform efficiently, data integrity maintained, backup/recovery implemented.',
|
|
193
|
+
'system_programming': 'Code is memory-safe, performance optimized, system compatibility verified.',
|
|
194
|
+
'ai_ml': 'Model meets accuracy targets, training is reproducible, deployment is scalable.',
|
|
195
|
+
'api_integration': 'Integration works reliably, error handling robust, rate limits respected.',
|
|
196
|
+
'general': 'Code works as intended, follows best practices, is well-documented and maintainable.'
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return criteria_map.get(domain, criteria_map['general'])
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from rich.console import Console
|
|
3
|
+
from rich.panel import Panel
|
|
4
|
+
from rich.table import Table
|
|
5
|
+
from rich.syntax import Syntax
|
|
6
|
+
from rich.text import Text
|
|
7
|
+
from rich import box
|
|
8
|
+
from .intelligence import PromptIntelligence
|
|
9
|
+
|
|
10
|
+
console = Console()
|
|
11
|
+
|
|
12
|
+
class PromptOptimizer:
|
|
13
|
+
"""Optimizes raw prompts using predefined patterns."""
|
|
14
|
+
def __init__(self, pattern_registry, cli_state, verbose: bool = False):
|
|
15
|
+
self.pattern_registry = pattern_registry
|
|
16
|
+
self.cli_state = cli_state
|
|
17
|
+
self.verbose = verbose
|
|
18
|
+
|
|
19
|
+
def _parse_prompt_into_sections(self, raw_prompt: str) -> dict:
|
|
20
|
+
"""Parses a raw prompt into a dictionary of sections based on '## SECTION:' headers and <TAG>...</TAG> blocks."""
|
|
21
|
+
sections = {}
|
|
22
|
+
main_body_content = raw_prompt
|
|
23
|
+
extracted_sections = {}
|
|
24
|
+
|
|
25
|
+
# Extract tagged blocks (e.g., <CODE>, <CONTEXT>)
|
|
26
|
+
tag_block_pattern = re.compile(r"<(\w+)>(.*?)</\1>", re.DOTALL | re.IGNORECASE)
|
|
27
|
+
|
|
28
|
+
matches_to_remove = []
|
|
29
|
+
for match in tag_block_pattern.finditer(main_body_content):
|
|
30
|
+
tag_name = match.group(1).upper()
|
|
31
|
+
content = match.group(2).strip()
|
|
32
|
+
extracted_sections[tag_name] = content
|
|
33
|
+
matches_to_remove.append(match.span())
|
|
34
|
+
|
|
35
|
+
# Remove extracted tag blocks from the main body content
|
|
36
|
+
for start, end in sorted(matches_to_remove, key=lambda x: x[0], reverse=True):
|
|
37
|
+
main_body_content = main_body_content[:start] + main_body_content[end:]
|
|
38
|
+
|
|
39
|
+
# Extract ## sections from the remaining text
|
|
40
|
+
parts = re.split(r'(?m)^(##\s*[\w\s\/]+?:)', main_body_content)
|
|
41
|
+
|
|
42
|
+
current_key = "MAIN_BODY"
|
|
43
|
+
if parts and parts[0].strip():
|
|
44
|
+
extracted_sections[current_key] = parts[0].strip()
|
|
45
|
+
|
|
46
|
+
for i in range(1, len(parts), 2):
|
|
47
|
+
header = parts[i].strip()
|
|
48
|
+
key = header.replace('##', '').replace(':', '').strip().replace(' ', '_').upper()
|
|
49
|
+
content = parts[i+1].strip() if i+1 < len(parts) else ""
|
|
50
|
+
extracted_sections[key] = content
|
|
51
|
+
|
|
52
|
+
# Handle 'code_here' specifically if it's the main body or implied
|
|
53
|
+
if "CODE" in extracted_sections:
|
|
54
|
+
extracted_sections["CODE_HERE"] = extracted_sections.pop("CODE")
|
|
55
|
+
|
|
56
|
+
return extracted_sections
|
|
57
|
+
|
|
58
|
+
def _extract_components(self, raw_prompt: str, pattern) -> dict:
|
|
59
|
+
"""Extracts common and pattern-specific components from a raw prompt."""
|
|
60
|
+
parsed_sections = self._parse_prompt_into_sections(raw_prompt)
|
|
61
|
+
extracted_fields = {}
|
|
62
|
+
|
|
63
|
+
# Map common section names to expected template field names
|
|
64
|
+
common_mappings = {
|
|
65
|
+
'DIRECTIVE': 'directive',
|
|
66
|
+
'SCOPE': 'scope',
|
|
67
|
+
'CONSTRAINTS': 'constraints',
|
|
68
|
+
'OUTPUT_FORMAT': 'output_format',
|
|
69
|
+
'SUCCESS_CRITERIA': 'success_criteria',
|
|
70
|
+
'CODE_HERE': 'code_here',
|
|
71
|
+
'CODE': 'code_here',
|
|
72
|
+
'CONTEXT': 'context',
|
|
73
|
+
'CURRENT_FOCUS': 'current_focus',
|
|
74
|
+
'MINDSET': 'mindset',
|
|
75
|
+
'MAIN_BODY': 'code_here'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for section_key, template_field in common_mappings.items():
|
|
79
|
+
if section_key in parsed_sections and parsed_sections[section_key] != "":
|
|
80
|
+
extracted_fields[template_field] = parsed_sections[section_key]
|
|
81
|
+
|
|
82
|
+
# Apply pattern-specific extraction logic
|
|
83
|
+
if pattern.specific_extract_func:
|
|
84
|
+
specific_extracted = pattern.specific_extract_func(raw_prompt)
|
|
85
|
+
for k,v in specific_extracted.items():
|
|
86
|
+
if v is not None and v != '':
|
|
87
|
+
extracted_fields[k.lower()] = v
|
|
88
|
+
|
|
89
|
+
return {k: v for k, v in extracted_fields.items() if v is not None}
|
|
90
|
+
|
|
91
|
+
def _generate_intelligent_content(self, field_name: str, raw_prompt: str, domain: str, extracted_fields: dict) -> str:
|
|
92
|
+
"""Generates clean, actionable content sections."""
|
|
93
|
+
arch = self.cli_state.get('ARCHITECTURE') or 'modern tech stack'
|
|
94
|
+
focus = self.cli_state.get('FOCUS') or 'core functionality'
|
|
95
|
+
|
|
96
|
+
# Remove test values
|
|
97
|
+
if arch == 'Test Architecture':
|
|
98
|
+
arch = 'modern tech stack'
|
|
99
|
+
if focus == 'Test Focus':
|
|
100
|
+
focus = 'core functionality'
|
|
101
|
+
|
|
102
|
+
generators = {
|
|
103
|
+
'requirements_section': f"- {domain.replace('_', ' ')} solution using {arch}\n- clean, maintainable code\n- best practices implementation\n- focus on {focus}",
|
|
104
|
+
|
|
105
|
+
'tech_specs_section': {
|
|
106
|
+
'web_frontend': "- mobile-first responsive design\n- WCAG accessibility\n- SEO optimization\n- semantic HTML",
|
|
107
|
+
'web_backend': "- RESTful API design\n- JWT authentication\n- database integration\n- scalable architecture",
|
|
108
|
+
'mobile': "- native performance\n- platform UI guidelines\n- state management\n- cross-platform compatibility",
|
|
109
|
+
'blockchain': "- gas-optimized contracts\n- security auditing\n- Web3 integration\n- decentralized architecture",
|
|
110
|
+
'data_science': "- data validation\n- statistical analysis\n- model deployment\n- reproducible workflows",
|
|
111
|
+
'general': "- clean architecture\n- error handling\n- performance optimization\n- maintainable design"
|
|
112
|
+
}.get(domain, "- best practices\n- clean code\n- comprehensive testing\n- documentation"),
|
|
113
|
+
|
|
114
|
+
'implementation_section': {
|
|
115
|
+
'web_frontend': "- component structure\n- responsive layout\n- accessibility features\n- performance optimization",
|
|
116
|
+
'web_backend': "- API endpoints\n- authentication middleware\n- validation\n- database setup",
|
|
117
|
+
'mobile': "- app structure\n- UI components\n- state management\n- platform features",
|
|
118
|
+
'general': "- architecture planning\n- core functionality\n- error handling\n- testing"
|
|
119
|
+
}.get(domain, "- structure planning\n- best practices implementation\n- testing\n- documentation"),
|
|
120
|
+
|
|
121
|
+
'deliverables_section': {
|
|
122
|
+
'web_frontend': "- responsive web application\n- cross-browser compatibility\n- accessibility compliance\n- performance metrics",
|
|
123
|
+
'web_backend': "- production API endpoints\n- database schema\n- API documentation\n- security implementation",
|
|
124
|
+
'mobile': "- native mobile app\n- platform builds\n- app store guidelines\n- performance benchmarks",
|
|
125
|
+
'general': "- working solution\n- clean code\n- documentation\n- test coverage"
|
|
126
|
+
}.get(domain, "- complete solution\n- documented code\n- testing coverage\n- usage instructions"),
|
|
127
|
+
|
|
128
|
+
'code_section': raw_prompt
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return generators.get(field_name, '')
|
|
132
|
+
|
|
133
|
+
def optimize_prompt(self, raw_prompt: str, pattern_name: str, overrides: dict, dry_run: bool = False) -> str:
|
|
134
|
+
"""Creates highly personalized, non-repetitive optimized prompts."""
|
|
135
|
+
pattern = self.pattern_registry.get_pattern(pattern_name)
|
|
136
|
+
if not pattern:
|
|
137
|
+
raise ValueError(f"Pattern '{pattern_name}' not found.")
|
|
138
|
+
|
|
139
|
+
# Intelligent analysis and pattern selection
|
|
140
|
+
domain = PromptIntelligence.detect_domain(raw_prompt)
|
|
141
|
+
complexity = PromptIntelligence.assess_complexity(raw_prompt)
|
|
142
|
+
|
|
143
|
+
# Auto-upgrade pattern based on intelligence
|
|
144
|
+
if pattern_name == "context_aware_generation":
|
|
145
|
+
suggested_pattern = PromptIntelligence.suggest_pattern(raw_prompt)
|
|
146
|
+
better_pattern = self.pattern_registry.get_pattern(suggested_pattern)
|
|
147
|
+
if better_pattern:
|
|
148
|
+
pattern = better_pattern
|
|
149
|
+
|
|
150
|
+
# Extract components with domain awareness
|
|
151
|
+
extracted_fields = self._extract_components(raw_prompt, pattern)
|
|
152
|
+
extracted_fields['detected_domain'] = domain
|
|
153
|
+
extracted_fields['complexity'] = complexity
|
|
154
|
+
|
|
155
|
+
# Build dynamic template fields
|
|
156
|
+
template_fields = dict(extracted_fields)
|
|
157
|
+
|
|
158
|
+
# Inject CLI state
|
|
159
|
+
class StateObject:
|
|
160
|
+
def __init__(self, state_dict):
|
|
161
|
+
for key, value in state_dict.items():
|
|
162
|
+
setattr(self, key, value)
|
|
163
|
+
def __getattr__(self, name):
|
|
164
|
+
return 'Not set'
|
|
165
|
+
|
|
166
|
+
cli_state_values = {key: self.cli_state.get(key) for key in self.cli_state.state.keys()}
|
|
167
|
+
template_fields['STATE'] = StateObject(cli_state_values)
|
|
168
|
+
|
|
169
|
+
# Apply overrides
|
|
170
|
+
template_fields.update(overrides)
|
|
171
|
+
|
|
172
|
+
# Generate intelligent content for both patterns
|
|
173
|
+
if pattern.name in ["adaptive_generation", "precision_engineering"]:
|
|
174
|
+
for field in ['requirements_section', 'tech_specs_section', 'implementation_section', 'deliverables_section', 'code_section']:
|
|
175
|
+
if field not in template_fields:
|
|
176
|
+
template_fields[field] = self._generate_intelligent_content(field, raw_prompt, domain, extracted_fields)
|
|
177
|
+
|
|
178
|
+
# Clean directive based on user input
|
|
179
|
+
smart_defaults = {
|
|
180
|
+
'directive': extracted_fields.get('directive') or raw_prompt.capitalize(),
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
# Apply smart defaults only for missing fields
|
|
184
|
+
for field, default_value in smart_defaults.items():
|
|
185
|
+
if field not in template_fields or not template_fields[field]:
|
|
186
|
+
template_fields[field] = default_value
|
|
187
|
+
|
|
188
|
+
if dry_run:
|
|
189
|
+
console.print(Panel("[bold blue]Dry Run: Intelligent Prompt Analysis[/bold blue]", expand=False, border_style="blue"))
|
|
190
|
+
console.print(f"Detected Domain: {domain}")
|
|
191
|
+
console.print(f"Complexity Level: {complexity}")
|
|
192
|
+
console.print(f"Selected Pattern: {pattern.name}")
|
|
193
|
+
console.print(f"Intelligence Score: {len(raw_prompt)} chars, {len(raw_prompt.split())} words")
|
|
194
|
+
return "Dry run complete. No prompt generated."
|
|
195
|
+
|
|
196
|
+
try:
|
|
197
|
+
optimized_prompt = pattern.template.format(**template_fields)
|
|
198
|
+
return optimized_prompt
|
|
199
|
+
except KeyError as e:
|
|
200
|
+
# Fallback with missing field filled
|
|
201
|
+
template_fields[str(e).strip("'")] = f"[{e} not specified]"
|
|
202
|
+
return pattern.template.format(**template_fields)
|