@techwavedev/agi-agent-kit 1.1.3

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 (196) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +147 -0
  3. package/bin/init.js +471 -0
  4. package/package.json +36 -0
  5. package/templates/.agent/agents/backend-specialist.md +263 -0
  6. package/templates/.agent/agents/code-archaeologist.md +106 -0
  7. package/templates/.agent/agents/database-architect.md +226 -0
  8. package/templates/.agent/agents/debugger.md +225 -0
  9. package/templates/.agent/agents/devops-engineer.md +242 -0
  10. package/templates/.agent/agents/documentation-writer.md +104 -0
  11. package/templates/.agent/agents/explorer-agent.md +73 -0
  12. package/templates/.agent/agents/frontend-specialist.md +556 -0
  13. package/templates/.agent/agents/game-developer.md +162 -0
  14. package/templates/.agent/agents/mobile-developer.md +377 -0
  15. package/templates/.agent/agents/orchestrator.md +416 -0
  16. package/templates/.agent/agents/penetration-tester.md +188 -0
  17. package/templates/.agent/agents/performance-optimizer.md +187 -0
  18. package/templates/.agent/agents/product-manager.md +112 -0
  19. package/templates/.agent/agents/project-planner.md +403 -0
  20. package/templates/.agent/agents/qa-automation-engineer.md +109 -0
  21. package/templates/.agent/agents/security-auditor.md +170 -0
  22. package/templates/.agent/agents/seo-specialist.md +111 -0
  23. package/templates/.agent/agents/test-engineer.md +158 -0
  24. package/templates/.agent/rules/GEMINI.md +253 -0
  25. package/templates/.agent/workflows/brainstorm.md +113 -0
  26. package/templates/.agent/workflows/create.md +59 -0
  27. package/templates/.agent/workflows/debug.md +103 -0
  28. package/templates/.agent/workflows/deploy.md +176 -0
  29. package/templates/.agent/workflows/enhance.md +63 -0
  30. package/templates/.agent/workflows/orchestrate.md +237 -0
  31. package/templates/.agent/workflows/plan.md +89 -0
  32. package/templates/.agent/workflows/preview.md +81 -0
  33. package/templates/.agent/workflows/status.md +86 -0
  34. package/templates/.agent/workflows/test.md +144 -0
  35. package/templates/.agent/workflows/ui-ux-pro-max.md +296 -0
  36. package/templates/base/.env.example +54 -0
  37. package/templates/base/AGENTS.md +463 -0
  38. package/templates/base/requirements.txt +6 -0
  39. package/templates/base/skill-creator/LICENSE.txt +202 -0
  40. package/templates/base/skill-creator/SKILL_skillcreator.md +389 -0
  41. package/templates/base/skill-creator/references/output-patterns.md +82 -0
  42. package/templates/base/skill-creator/references/workflows.md +28 -0
  43. package/templates/base/skill-creator/scripts/init_skill.py +304 -0
  44. package/templates/base/skill-creator/scripts/package_skill.py +110 -0
  45. package/templates/base/skill-creator/scripts/quick_validate.py +95 -0
  46. package/templates/base/skill-creator/scripts/update_catalog.py +371 -0
  47. package/templates/skills/core/README.md +21 -0
  48. package/templates/skills/core/documentation/SKILL.md +351 -0
  49. package/templates/skills/core/documentation/references/best_practices.md +201 -0
  50. package/templates/skills/core/documentation/scripts/analyze_code.py +307 -0
  51. package/templates/skills/core/documentation/scripts/detect_changes.py +460 -0
  52. package/templates/skills/core/documentation/scripts/generate_changelog.py +312 -0
  53. package/templates/skills/core/documentation/scripts/sync_docs.py +272 -0
  54. package/templates/skills/core/documentation/scripts/update_skill_docs.py +366 -0
  55. package/templates/skills/core/pdf-reader/SKILL.md +104 -0
  56. package/templates/skills/core/pdf-reader/references/pdf_libraries.md +83 -0
  57. package/templates/skills/core/pdf-reader/scripts/extract_text.py +295 -0
  58. package/templates/skills/core/qdrant-memory/SKILL.md +435 -0
  59. package/templates/skills/core/qdrant-memory/references/advanced_patterns.md +375 -0
  60. package/templates/skills/core/qdrant-memory/references/collection_schemas.md +229 -0
  61. package/templates/skills/core/qdrant-memory/references/complete_guide.md +724 -0
  62. package/templates/skills/core/qdrant-memory/references/embedding_models.md +325 -0
  63. package/templates/skills/core/qdrant-memory/scripts/benchmark_token_savings.py +640 -0
  64. package/templates/skills/core/qdrant-memory/scripts/embedding_utils.py +323 -0
  65. package/templates/skills/core/qdrant-memory/scripts/hybrid_search.py +214 -0
  66. package/templates/skills/core/qdrant-memory/scripts/init_collection.py +193 -0
  67. package/templates/skills/core/qdrant-memory/scripts/memory_retrieval.py +345 -0
  68. package/templates/skills/core/qdrant-memory/scripts/semantic_cache.py +282 -0
  69. package/templates/skills/core/qdrant-memory/scripts/test_skill.py +655 -0
  70. package/templates/skills/core/webcrawler/SKILL.md +292 -0
  71. package/templates/skills/core/webcrawler/references/advanced_crawling.md +181 -0
  72. package/templates/skills/core/webcrawler/scripts/crawl_docs.py +532 -0
  73. package/templates/skills/core/webcrawler/scripts/extract_page.py +189 -0
  74. package/templates/skills/core/webcrawler/scripts/filter_docs.py +200 -0
  75. package/templates/skills/knowledge/api-patterns/SKILL.md +81 -0
  76. package/templates/skills/knowledge/api-patterns/api-style.md +42 -0
  77. package/templates/skills/knowledge/api-patterns/auth.md +24 -0
  78. package/templates/skills/knowledge/api-patterns/documentation.md +26 -0
  79. package/templates/skills/knowledge/api-patterns/graphql.md +41 -0
  80. package/templates/skills/knowledge/api-patterns/rate-limiting.md +31 -0
  81. package/templates/skills/knowledge/api-patterns/response.md +37 -0
  82. package/templates/skills/knowledge/api-patterns/rest.md +40 -0
  83. package/templates/skills/knowledge/api-patterns/scripts/api_validator.py +211 -0
  84. package/templates/skills/knowledge/api-patterns/security-testing.md +122 -0
  85. package/templates/skills/knowledge/api-patterns/trpc.md +41 -0
  86. package/templates/skills/knowledge/api-patterns/versioning.md +22 -0
  87. package/templates/skills/knowledge/app-builder/SKILL.md +75 -0
  88. package/templates/skills/knowledge/app-builder/agent-coordination.md +71 -0
  89. package/templates/skills/knowledge/app-builder/feature-building.md +53 -0
  90. package/templates/skills/knowledge/app-builder/project-detection.md +34 -0
  91. package/templates/skills/knowledge/app-builder/scaffolding.md +118 -0
  92. package/templates/skills/knowledge/app-builder/tech-stack.md +40 -0
  93. package/templates/skills/knowledge/app-builder/templates/SKILL.md +39 -0
  94. package/templates/skills/knowledge/app-builder/templates/astro-static/TEMPLATE.md +76 -0
  95. package/templates/skills/knowledge/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
  96. package/templates/skills/knowledge/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  97. package/templates/skills/knowledge/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
  98. package/templates/skills/knowledge/app-builder/templates/express-api/TEMPLATE.md +83 -0
  99. package/templates/skills/knowledge/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
  100. package/templates/skills/knowledge/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
  101. package/templates/skills/knowledge/app-builder/templates/nextjs-fullstack/TEMPLATE.md +82 -0
  102. package/templates/skills/knowledge/app-builder/templates/nextjs-saas/TEMPLATE.md +100 -0
  103. package/templates/skills/knowledge/app-builder/templates/nextjs-static/TEMPLATE.md +106 -0
  104. package/templates/skills/knowledge/app-builder/templates/nuxt-app/TEMPLATE.md +101 -0
  105. package/templates/skills/knowledge/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
  106. package/templates/skills/knowledge/app-builder/templates/react-native-app/TEMPLATE.md +93 -0
  107. package/templates/skills/knowledge/architecture/SKILL.md +55 -0
  108. package/templates/skills/knowledge/architecture/context-discovery.md +43 -0
  109. package/templates/skills/knowledge/architecture/examples.md +94 -0
  110. package/templates/skills/knowledge/architecture/pattern-selection.md +68 -0
  111. package/templates/skills/knowledge/architecture/patterns-reference.md +50 -0
  112. package/templates/skills/knowledge/architecture/trade-off-analysis.md +77 -0
  113. package/templates/skills/knowledge/bash-linux/SKILL.md +199 -0
  114. package/templates/skills/knowledge/behavioral-modes/SKILL.md +242 -0
  115. package/templates/skills/knowledge/brainstorming/SKILL.md +163 -0
  116. package/templates/skills/knowledge/brainstorming/dynamic-questioning.md +350 -0
  117. package/templates/skills/knowledge/clean-code/SKILL.md +201 -0
  118. package/templates/skills/knowledge/code-review-checklist/SKILL.md +109 -0
  119. package/templates/skills/knowledge/database-design/SKILL.md +52 -0
  120. package/templates/skills/knowledge/database-design/database-selection.md +43 -0
  121. package/templates/skills/knowledge/database-design/indexing.md +39 -0
  122. package/templates/skills/knowledge/database-design/migrations.md +48 -0
  123. package/templates/skills/knowledge/database-design/optimization.md +36 -0
  124. package/templates/skills/knowledge/database-design/orm-selection.md +30 -0
  125. package/templates/skills/knowledge/database-design/schema-design.md +56 -0
  126. package/templates/skills/knowledge/database-design/scripts/schema_validator.py +172 -0
  127. package/templates/skills/knowledge/deployment-procedures/SKILL.md +241 -0
  128. package/templates/skills/knowledge/doc.md +177 -0
  129. package/templates/skills/knowledge/documentation-templates/SKILL.md +194 -0
  130. package/templates/skills/knowledge/frontend-design/SKILL.md +396 -0
  131. package/templates/skills/knowledge/frontend-design/animation-guide.md +331 -0
  132. package/templates/skills/knowledge/frontend-design/color-system.md +311 -0
  133. package/templates/skills/knowledge/frontend-design/decision-trees.md +418 -0
  134. package/templates/skills/knowledge/frontend-design/motion-graphics.md +306 -0
  135. package/templates/skills/knowledge/frontend-design/scripts/accessibility_checker.py +183 -0
  136. package/templates/skills/knowledge/frontend-design/scripts/ux_audit.py +722 -0
  137. package/templates/skills/knowledge/frontend-design/typography-system.md +345 -0
  138. package/templates/skills/knowledge/frontend-design/ux-psychology.md +541 -0
  139. package/templates/skills/knowledge/frontend-design/visual-effects.md +383 -0
  140. package/templates/skills/knowledge/game-development/2d-games/SKILL.md +119 -0
  141. package/templates/skills/knowledge/game-development/3d-games/SKILL.md +135 -0
  142. package/templates/skills/knowledge/game-development/SKILL.md +167 -0
  143. package/templates/skills/knowledge/game-development/game-art/SKILL.md +185 -0
  144. package/templates/skills/knowledge/game-development/game-audio/SKILL.md +190 -0
  145. package/templates/skills/knowledge/game-development/game-design/SKILL.md +129 -0
  146. package/templates/skills/knowledge/game-development/mobile-games/SKILL.md +108 -0
  147. package/templates/skills/knowledge/game-development/multiplayer/SKILL.md +132 -0
  148. package/templates/skills/knowledge/game-development/pc-games/SKILL.md +144 -0
  149. package/templates/skills/knowledge/game-development/vr-ar/SKILL.md +123 -0
  150. package/templates/skills/knowledge/game-development/web-games/SKILL.md +150 -0
  151. package/templates/skills/knowledge/geo-fundamentals/SKILL.md +156 -0
  152. package/templates/skills/knowledge/geo-fundamentals/scripts/geo_checker.py +289 -0
  153. package/templates/skills/knowledge/i18n-localization/SKILL.md +154 -0
  154. package/templates/skills/knowledge/i18n-localization/scripts/i18n_checker.py +241 -0
  155. package/templates/skills/knowledge/intelligent-routing/SKILL.md +334 -0
  156. package/templates/skills/knowledge/lint-and-validate/SKILL.md +45 -0
  157. package/templates/skills/knowledge/lint-and-validate/scripts/lint_runner.py +172 -0
  158. package/templates/skills/knowledge/lint-and-validate/scripts/type_coverage.py +173 -0
  159. package/templates/skills/knowledge/mcp-builder/SKILL.md +176 -0
  160. package/templates/skills/knowledge/mobile-design/SKILL.md +394 -0
  161. package/templates/skills/knowledge/mobile-design/decision-trees.md +516 -0
  162. package/templates/skills/knowledge/mobile-design/mobile-backend.md +491 -0
  163. package/templates/skills/knowledge/mobile-design/mobile-color-system.md +420 -0
  164. package/templates/skills/knowledge/mobile-design/mobile-debugging.md +122 -0
  165. package/templates/skills/knowledge/mobile-design/mobile-design-thinking.md +357 -0
  166. package/templates/skills/knowledge/mobile-design/mobile-navigation.md +458 -0
  167. package/templates/skills/knowledge/mobile-design/mobile-performance.md +767 -0
  168. package/templates/skills/knowledge/mobile-design/mobile-testing.md +356 -0
  169. package/templates/skills/knowledge/mobile-design/mobile-typography.md +433 -0
  170. package/templates/skills/knowledge/mobile-design/platform-android.md +666 -0
  171. package/templates/skills/knowledge/mobile-design/platform-ios.md +561 -0
  172. package/templates/skills/knowledge/mobile-design/scripts/mobile_audit.py +670 -0
  173. package/templates/skills/knowledge/mobile-design/touch-psychology.md +537 -0
  174. package/templates/skills/knowledge/nextjs-best-practices/SKILL.md +203 -0
  175. package/templates/skills/knowledge/nodejs-best-practices/SKILL.md +333 -0
  176. package/templates/skills/knowledge/parallel-agents/SKILL.md +175 -0
  177. package/templates/skills/knowledge/performance-profiling/SKILL.md +143 -0
  178. package/templates/skills/knowledge/performance-profiling/scripts/lighthouse_audit.py +76 -0
  179. package/templates/skills/knowledge/plan-writing/SKILL.md +152 -0
  180. package/templates/skills/knowledge/powershell-windows/SKILL.md +167 -0
  181. package/templates/skills/knowledge/python-patterns/SKILL.md +441 -0
  182. package/templates/skills/knowledge/react-patterns/SKILL.md +198 -0
  183. package/templates/skills/knowledge/red-team-tactics/SKILL.md +199 -0
  184. package/templates/skills/knowledge/seo-fundamentals/SKILL.md +129 -0
  185. package/templates/skills/knowledge/seo-fundamentals/scripts/seo_checker.py +219 -0
  186. package/templates/skills/knowledge/server-management/SKILL.md +161 -0
  187. package/templates/skills/knowledge/systematic-debugging/SKILL.md +109 -0
  188. package/templates/skills/knowledge/tailwind-patterns/SKILL.md +269 -0
  189. package/templates/skills/knowledge/tdd-workflow/SKILL.md +149 -0
  190. package/templates/skills/knowledge/testing-patterns/SKILL.md +178 -0
  191. package/templates/skills/knowledge/testing-patterns/scripts/test_runner.py +219 -0
  192. package/templates/skills/knowledge/vulnerability-scanner/SKILL.md +276 -0
  193. package/templates/skills/knowledge/vulnerability-scanner/checklists.md +121 -0
  194. package/templates/skills/knowledge/vulnerability-scanner/scripts/security_scan.py +458 -0
  195. package/templates/skills/knowledge/webapp-testing/SKILL.md +187 -0
  196. package/templates/skills/knowledge/webapp-testing/scripts/playwright_runner.py +173 -0
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Script: semantic_cache.py
4
+ Purpose: Semantic caching for LLM responses using Qdrant vector similarity.
5
+
6
+ Supports both Ollama (local/private) and OpenAI (cloud) embeddings.
7
+ Default: Ollama with nomic-embed-text model.
8
+
9
+ Usage:
10
+ # Check cache (uses Ollama by default)
11
+ python3 semantic_cache.py check --query "How do I reset my password?"
12
+
13
+ # Store response
14
+ python3 semantic_cache.py store --query "Password reset" --response "Go to settings..."
15
+
16
+ # Clear cache
17
+ python3 semantic_cache.py clear --older-than 7
18
+
19
+ Environment Variables:
20
+ EMBEDDING_PROVIDER - "ollama" (default) or "openai"
21
+ OLLAMA_URL - Ollama server URL (default: http://localhost:11434)
22
+ OPENAI_API_KEY - Required for OpenAI provider
23
+ QDRANT_URL - Qdrant server URL (default: http://localhost:6333)
24
+ CACHE_COLLECTION - Collection name (default: semantic_cache)
25
+
26
+ Functions:
27
+ check_cache(query, threshold) - Check for semantically similar cached response
28
+ store_response(query, response, metadata) - Store query-response pair
29
+ clear_cache(older_than_days) - Remove old cache entries
30
+
31
+ Exit Codes:
32
+ 0 - Success (cache hit or stored)
33
+ 1 - Cache miss (no similar query found)
34
+ 2 - Connection error
35
+ 3 - Embedding error
36
+ """
37
+
38
+ import argparse
39
+ import json
40
+ import os
41
+ import sys
42
+ import hashlib
43
+ from datetime import datetime, timedelta
44
+ from typing import Optional, Dict, Any
45
+ from urllib.request import Request, urlopen
46
+ from urllib.error import URLError, HTTPError
47
+
48
+ # Import shared embedding utilities (supports Ollama and OpenAI)
49
+ try:
50
+ from embedding_utils import get_embedding
51
+ except ImportError:
52
+ # Fallback if run from different directory
53
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
54
+ from embedding_utils import get_embedding
55
+
56
+ # Configuration
57
+ QDRANT_URL = os.environ.get("QDRANT_URL", "http://localhost:6333")
58
+ COLLECTION = os.environ.get("CACHE_COLLECTION", "semantic_cache")
59
+ DEFAULT_THRESHOLD = 0.92
60
+
61
+
62
+ def check_cache(query: str, threshold: float = DEFAULT_THRESHOLD) -> Optional[Dict[str, Any]]:
63
+ """
64
+ Check if a semantically similar query exists in cache.
65
+
66
+ Args:
67
+ query: The user query to check
68
+ threshold: Minimum similarity score (0.0-1.0)
69
+
70
+ Returns:
71
+ Cached response dict if found, None otherwise
72
+ """
73
+ embedding = get_embedding(query)
74
+
75
+ search_payload = {
76
+ "vector": embedding,
77
+ "limit": 1,
78
+ "score_threshold": threshold,
79
+ "with_payload": True
80
+ }
81
+
82
+ req = Request(
83
+ f"{QDRANT_URL}/collections/{COLLECTION}/points/search",
84
+ data=json.dumps(search_payload).encode(),
85
+ headers={"Content-Type": "application/json"},
86
+ method="POST"
87
+ )
88
+
89
+ try:
90
+ with urlopen(req, timeout=30) as response:
91
+ result = json.loads(response.read().decode())
92
+
93
+ if result.get("result") and len(result["result"]) > 0:
94
+ hit = result["result"][0]
95
+ return {
96
+ "cache_hit": True,
97
+ "score": hit["score"],
98
+ "query": hit["payload"].get("query"),
99
+ "response": hit["payload"].get("response"),
100
+ "timestamp": hit["payload"].get("timestamp"),
101
+ "model": hit["payload"].get("model"),
102
+ "tokens_saved": hit["payload"].get("token_count", 0)
103
+ }
104
+ return None
105
+ except HTTPError as e:
106
+ if e.code == 404:
107
+ return None
108
+ raise
109
+
110
+
111
+ def store_response(
112
+ query: str,
113
+ response: str,
114
+ metadata: Optional[Dict[str, Any]] = None
115
+ ) -> Dict[str, Any]:
116
+ """
117
+ Store a query-response pair in the semantic cache.
118
+
119
+ Args:
120
+ query: The original query
121
+ response: The LLM response
122
+ metadata: Additional metadata (model, project, etc.)
123
+
124
+ Returns:
125
+ Storage confirmation with point ID
126
+ """
127
+ embedding = get_embedding(query)
128
+
129
+ # Generate deterministic ID from query hash
130
+ point_id = int(hashlib.md5(query.encode()).hexdigest()[:16], 16) % (2**63)
131
+
132
+ payload = {
133
+ "query": query,
134
+ "response": response,
135
+ "timestamp": datetime.utcnow().isoformat(),
136
+ "type": "cache",
137
+ "token_count": len(response.split()),
138
+ **(metadata or {})
139
+ }
140
+
141
+ upsert_payload = {
142
+ "points": [
143
+ {
144
+ "id": point_id,
145
+ "vector": embedding,
146
+ "payload": payload
147
+ }
148
+ ]
149
+ }
150
+
151
+ req = Request(
152
+ f"{QDRANT_URL}/collections/{COLLECTION}/points?wait=true",
153
+ data=json.dumps(upsert_payload).encode(),
154
+ headers={"Content-Type": "application/json"},
155
+ method="PUT"
156
+ )
157
+
158
+ with urlopen(req, timeout=30) as response_obj:
159
+ result = json.loads(response_obj.read().decode())
160
+
161
+ return {
162
+ "status": "stored",
163
+ "point_id": point_id,
164
+ "token_count": payload["token_count"],
165
+ "result": result
166
+ }
167
+
168
+
169
+ def clear_cache(older_than_days: int = 7) -> Dict[str, Any]:
170
+ """
171
+ Clear cache entries older than specified days.
172
+
173
+ Args:
174
+ older_than_days: Delete entries older than this
175
+
176
+ Returns:
177
+ Deletion result with count
178
+ """
179
+ cutoff = (datetime.utcnow() - timedelta(days=older_than_days)).isoformat()
180
+
181
+ delete_payload = {
182
+ "filter": {
183
+ "must": [
184
+ {
185
+ "key": "timestamp",
186
+ "range": {
187
+ "lt": cutoff
188
+ }
189
+ },
190
+ {
191
+ "key": "type",
192
+ "match": {
193
+ "value": "cache"
194
+ }
195
+ }
196
+ ]
197
+ }
198
+ }
199
+
200
+ req = Request(
201
+ f"{QDRANT_URL}/collections/{COLLECTION}/points/delete?wait=true",
202
+ data=json.dumps(delete_payload).encode(),
203
+ headers={"Content-Type": "application/json"},
204
+ method="POST"
205
+ )
206
+
207
+ with urlopen(req, timeout=30) as response:
208
+ result = json.loads(response.read().decode())
209
+
210
+ return {
211
+ "status": "cleared",
212
+ "older_than_days": older_than_days,
213
+ "cutoff_date": cutoff,
214
+ "result": result
215
+ }
216
+
217
+
218
+ def main():
219
+ parser = argparse.ArgumentParser(description="Semantic cache operations")
220
+ subparsers = parser.add_subparsers(dest="command", required=True)
221
+
222
+ # Check command
223
+ check_parser = subparsers.add_parser("check", help="Check cache for query")
224
+ check_parser.add_argument("--query", required=True, help="Query to check")
225
+ check_parser.add_argument("--threshold", type=float, default=DEFAULT_THRESHOLD,
226
+ help=f"Similarity threshold (default: {DEFAULT_THRESHOLD})")
227
+
228
+ # Store command
229
+ store_parser = subparsers.add_parser("store", help="Store query-response pair")
230
+ store_parser.add_argument("--query", required=True, help="Original query")
231
+ store_parser.add_argument("--response", required=True, help="LLM response")
232
+ store_parser.add_argument("--model", default="gpt-4", help="Model used")
233
+ store_parser.add_argument("--project", help="Project name")
234
+
235
+ # Clear command
236
+ clear_parser = subparsers.add_parser("clear", help="Clear old cache entries")
237
+ clear_parser.add_argument("--older-than", type=int, default=7,
238
+ help="Delete entries older than N days")
239
+
240
+ args = parser.parse_args()
241
+
242
+ try:
243
+ if args.command == "check":
244
+ result = check_cache(args.query, args.threshold)
245
+ if result:
246
+ print(json.dumps(result, indent=2))
247
+ sys.exit(0)
248
+ else:
249
+ print(json.dumps({"cache_hit": False, "query": args.query}))
250
+ sys.exit(1)
251
+
252
+ elif args.command == "store":
253
+ metadata = {"model": args.model}
254
+ if args.project:
255
+ metadata["project"] = args.project
256
+ result = store_response(args.query, args.response, metadata)
257
+ print(json.dumps(result, indent=2))
258
+ sys.exit(0)
259
+
260
+ elif args.command == "clear":
261
+ result = clear_cache(args.older_than)
262
+ print(json.dumps(result, indent=2))
263
+ sys.exit(0)
264
+
265
+ except URLError as e:
266
+ print(json.dumps({
267
+ "status": "error",
268
+ "type": "connection_error",
269
+ "message": str(e)
270
+ }), file=sys.stderr)
271
+ sys.exit(2)
272
+ except Exception as e:
273
+ print(json.dumps({
274
+ "status": "error",
275
+ "type": type(e).__name__,
276
+ "message": str(e)
277
+ }), file=sys.stderr)
278
+ sys.exit(3)
279
+
280
+
281
+ if __name__ == "__main__":
282
+ main()