solidx-ai-agent 0.1.0__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.
Files changed (170) hide show
  1. solidx_ai_agent-0.1.0/PKG-INFO +658 -0
  2. solidx_ai_agent-0.1.0/README.md +621 -0
  3. solidx_ai_agent-0.1.0/agents/__init__.py +0 -0
  4. solidx_ai_agent-0.1.0/agents/solidx_agent.py +311 -0
  5. solidx_ai_agent-0.1.0/auth/__init__.py +2 -0
  6. solidx_ai_agent-0.1.0/auth/context.py +53 -0
  7. solidx_ai_agent-0.1.0/auth/token_helpers.py +304 -0
  8. solidx_ai_agent-0.1.0/config/__init__.py +0 -0
  9. solidx_ai_agent-0.1.0/config/loader.py +104 -0
  10. solidx_ai_agent-0.1.0/config/solidx.yaml +84 -0
  11. solidx_ai_agent-0.1.0/console.py +129 -0
  12. solidx_ai_agent-0.1.0/db/__init__.py +10 -0
  13. solidx_ai_agent-0.1.0/db/base.py +69 -0
  14. solidx_ai_agent-0.1.0/db/models/__init__.py +12 -0
  15. solidx_ai_agent-0.1.0/db/models/agent_event.py +49 -0
  16. solidx_ai_agent-0.1.0/db/models/agent_session.py +28 -0
  17. solidx_ai_agent-0.1.0/db/models/mcp_audit.py +75 -0
  18. solidx_ai_agent-0.1.0/db/models/solid_core_auth.py +128 -0
  19. solidx_ai_agent-0.1.0/db/repository.py +139 -0
  20. solidx_ai_agent-0.1.0/db/session.py +108 -0
  21. solidx_ai_agent-0.1.0/environments/__init__.py +0 -0
  22. solidx_ai_agent-0.1.0/environments/solidx_environment.py +192 -0
  23. solidx_ai_agent-0.1.0/events/__init__.py +31 -0
  24. solidx_ai_agent-0.1.0/events/emitter.py +93 -0
  25. solidx_ai_agent-0.1.0/events/events.py +192 -0
  26. solidx_ai_agent-0.1.0/exceptions.py +23 -0
  27. solidx_ai_agent-0.1.0/mcp_layer/__init__.py +11 -0
  28. solidx_ai_agent-0.1.0/mcp_layer/app.py +271 -0
  29. solidx_ai_agent-0.1.0/mcp_layer/audit.py +151 -0
  30. solidx_ai_agent-0.1.0/mcp_layer/auth/__init__.py +49 -0
  31. solidx_ai_agent-0.1.0/mcp_layer/auth/api_key_service.py +297 -0
  32. solidx_ai_agent-0.1.0/mcp_layer/auth/middleware.py +517 -0
  33. solidx_ai_agent-0.1.0/mcp_layer/prompts.py +132 -0
  34. solidx_ai_agent-0.1.0/mcp_layer/resources.py +143 -0
  35. solidx_ai_agent-0.1.0/mcp_layer/tools.py +712 -0
  36. solidx_ai_agent-0.1.0/models/__init__.py +0 -0
  37. solidx_ai_agent-0.1.0/models/fast_llm.py +126 -0
  38. solidx_ai_agent-0.1.0/models/solidx_model.py +701 -0
  39. solidx_ai_agent-0.1.0/prompts/__init__.py +1 -0
  40. solidx_ai_agent-0.1.0/prompts/instance_prompt.md +54 -0
  41. solidx_ai_agent-0.1.0/prompts/system_prompt.md +188 -0
  42. solidx_ai_agent-0.1.0/pyproject.toml +67 -0
  43. solidx_ai_agent-0.1.0/run.py +631 -0
  44. solidx_ai_agent-0.1.0/server/__init__.py +0 -0
  45. solidx_ai_agent-0.1.0/server/app.py +822 -0
  46. solidx_ai_agent-0.1.0/server/db_listener.py +273 -0
  47. solidx_ai_agent-0.1.0/server/sessions.py +445 -0
  48. solidx_ai_agent-0.1.0/setup.cfg +4 -0
  49. solidx_ai_agent-0.1.0/skills/__init__.py +26 -0
  50. solidx_ai_agent-0.1.0/skills/injector.py +330 -0
  51. solidx_ai_agent-0.1.0/skills/intent.py +284 -0
  52. solidx_ai_agent-0.1.0/skills/loader.py +128 -0
  53. solidx_ai_agent-0.1.0/skills/registry.py +150 -0
  54. solidx_ai_agent-0.1.0/solidx_ai_agent.egg-info/PKG-INFO +658 -0
  55. solidx_ai_agent-0.1.0/solidx_ai_agent.egg-info/SOURCES.txt +168 -0
  56. solidx_ai_agent-0.1.0/solidx_ai_agent.egg-info/dependency_links.txt +1 -0
  57. solidx_ai_agent-0.1.0/solidx_ai_agent.egg-info/entry_points.txt +2 -0
  58. solidx_ai_agent-0.1.0/solidx_ai_agent.egg-info/requires.txt +32 -0
  59. solidx_ai_agent-0.1.0/solidx_ai_agent.egg-info/top_level.txt +16 -0
  60. solidx_ai_agent-0.1.0/solidx_platform/__init__.py +10 -0
  61. solidx_ai_agent-0.1.0/solidx_platform/helpers/__init__.py +0 -0
  62. solidx_ai_agent-0.1.0/solidx_platform/helpers/backend_step_engine.py +281 -0
  63. solidx_ai_agent-0.1.0/solidx_platform/helpers/code_edit_operations_helper.py +640 -0
  64. solidx_ai_agent-0.1.0/solidx_platform/helpers/constants.py +319 -0
  65. solidx_ai_agent-0.1.0/solidx_platform/helpers/doc_index_helper.py +371 -0
  66. solidx_ai_agent-0.1.0/solidx_platform/helpers/field_helper.py +169 -0
  67. solidx_ai_agent-0.1.0/solidx_platform/helpers/frontend_fs_common.py +65 -0
  68. solidx_ai_agent-0.1.0/solidx_platform/helpers/json_patch_helper.py +687 -0
  69. solidx_ai_agent-0.1.0/solidx_platform/helpers/metadata_generic.py +90 -0
  70. solidx_ai_agent-0.1.0/solidx_platform/helpers/module_metadata_json_helper.py +780 -0
  71. solidx_ai_agent-0.1.0/solidx_platform/helpers/rag_context_helper.py +36 -0
  72. solidx_ai_agent-0.1.0/solidx_platform/helpers/response_context.py +204 -0
  73. solidx_ai_agent-0.1.0/solidx_platform/helpers/solid_cli_helper.py +512 -0
  74. solidx_ai_agent-0.1.0/solidx_platform/helpers/solid_fs_registry.py +225 -0
  75. solidx_ai_agent-0.1.0/solidx_platform/helpers/solid_ts_morph.py +303 -0
  76. solidx_ai_agent-0.1.0/solidx_platform/helpers/syntax_check.py +129 -0
  77. solidx_ai_agent-0.1.0/solidx_platform/orm/__init__.py +1 -0
  78. solidx_ai_agent-0.1.0/solidx_platform/orm/models/__init__.py +50 -0
  79. solidx_ai_agent-0.1.0/solidx_platform/orm/models/action_metadata.py +31 -0
  80. solidx_ai_agent-0.1.0/solidx_platform/orm/models/common_entity.py +3 -0
  81. solidx_ai_agent-0.1.0/solidx_platform/orm/models/dashboard.py +26 -0
  82. solidx_ai_agent-0.1.0/solidx_platform/orm/models/dashboard_question.py +28 -0
  83. solidx_ai_agent-0.1.0/solidx_platform/orm/models/dashboard_question_sql_dataset_config.py +25 -0
  84. solidx_ai_agent-0.1.0/solidx_platform/orm/models/dashboard_variable.py +24 -0
  85. solidx_ai_agent-0.1.0/solidx_platform/orm/models/field_metadata.py +74 -0
  86. solidx_ai_agent-0.1.0/solidx_platform/orm/models/list_of_values.py +20 -0
  87. solidx_ai_agent-0.1.0/solidx_platform/orm/models/media.py +24 -0
  88. solidx_ai_agent-0.1.0/solidx_platform/orm/models/media_storage_provider_metadata.py +18 -0
  89. solidx_ai_agent-0.1.0/solidx_platform/orm/models/menu_item_metadata.py +33 -0
  90. solidx_ai_agent-0.1.0/solidx_platform/orm/models/model_metadata.py +45 -0
  91. solidx_ai_agent-0.1.0/solidx_platform/orm/models/model_sequence.py +24 -0
  92. solidx_ai_agent-0.1.0/solidx_platform/orm/models/module_metadata.py +23 -0
  93. solidx_ai_agent-0.1.0/solidx_platform/orm/models/permission_metadata.py +19 -0
  94. solidx_ai_agent-0.1.0/solidx_platform/orm/models/role_metadata.py +50 -0
  95. solidx_ai_agent-0.1.0/solidx_platform/orm/models/saved_filters.py +25 -0
  96. solidx_ai_agent-0.1.0/solidx_platform/orm/models/scheduled_job.py +29 -0
  97. solidx_ai_agent-0.1.0/solidx_platform/orm/models/security_rule.py +20 -0
  98. solidx_ai_agent-0.1.0/solidx_platform/orm/models/setting.py +21 -0
  99. solidx_ai_agent-0.1.0/solidx_platform/orm/models/sms_template.py +18 -0
  100. solidx_ai_agent-0.1.0/solidx_platform/orm/models/user.py +71 -0
  101. solidx_ai_agent-0.1.0/solidx_platform/orm/models/user_view_metadata.py +17 -0
  102. solidx_ai_agent-0.1.0/solidx_platform/orm/models/view_metadata.py +26 -0
  103. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/__init__.py +34 -0
  104. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/action_metadata_repository.py +34 -0
  105. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/base.py +24 -0
  106. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/common_repository.py +13 -0
  107. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/dashboard_repository.py +37 -0
  108. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/dashboard_variable_repository.py +18 -0
  109. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/ddl_info_repository.py +149 -0
  110. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/field_metadata_repository.py +102 -0
  111. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/media_repository.py +33 -0
  112. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/media_storage_provider_metadata_repository.py +22 -0
  113. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/menu_item_metadata_repository.py +55 -0
  114. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/model_metadata_repository.py +85 -0
  115. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/module_metadata_repository.py +68 -0
  116. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/role_metadata_repository.py +12 -0
  117. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/setting_repository.py +18 -0
  118. solidx_ai_agent-0.1.0/solidx_platform/orm/repositories/view_metadata_repository.py +58 -0
  119. solidx_ai_agent-0.1.0/solidx_platform/services/__init__.py +0 -0
  120. solidx_ai_agent-0.1.0/solidx_platform/tools/__init__.py +1 -0
  121. solidx_ai_agent-0.1.0/solidx_platform/tools/content_crud.py +193 -0
  122. solidx_ai_agent-0.1.0/solidx_platform/tools/edit.py +316 -0
  123. solidx_ai_agent-0.1.0/solidx_platform/tools/executors/__init__.py +18 -0
  124. solidx_ai_agent-0.1.0/solidx_platform/tools/executors/base.py +9 -0
  125. solidx_ai_agent-0.1.0/solidx_platform/tools/executors/registry.py +83 -0
  126. solidx_ai_agent-0.1.0/solidx_platform/tools/executors/solid_add_fields_to_model_handler.py +139 -0
  127. solidx_ai_agent-0.1.0/solidx_platform/tools/executors/solid_create_model_with_fields_handler.py +288 -0
  128. solidx_ai_agent-0.1.0/solidx_platform/tools/executors/solid_create_module_handler.py +174 -0
  129. solidx_ai_agent-0.1.0/solidx_platform/tools/executors/solid_remove_module_handler.py +136 -0
  130. solidx_ai_agent-0.1.0/solidx_platform/tools/filesystem_tool.py +130 -0
  131. solidx_ai_agent-0.1.0/solidx_platform/tools/get_backend_context.py +197 -0
  132. solidx_ai_agent-0.1.0/solidx_platform/tools/get_metadata.py +479 -0
  133. solidx_ai_agent-0.1.0/solidx_platform/tools/introspect_database.py +100 -0
  134. solidx_ai_agent-0.1.0/solidx_platform/tools/manage_data_model.py +266 -0
  135. solidx_ai_agent-0.1.0/solidx_platform/tools/manage_metadata.py +151 -0
  136. solidx_ai_agent-0.1.0/solidx_platform/tools/metadata_json_patch.py +240 -0
  137. solidx_ai_agent-0.1.0/solidx_platform/tools/read.py +104 -0
  138. solidx_ai_agent-0.1.0/solidx_platform/tools/run_solidctl.py +251 -0
  139. solidx_ai_agent-0.1.0/solidx_platform/tools/search.py +366 -0
  140. solidx_ai_agent-0.1.0/solidx_platform/tools/write.py +145 -0
  141. solidx_ai_agent-0.1.0/tests/test_agent_multiturn.py +182 -0
  142. solidx_ai_agent-0.1.0/tests/test_backend_step_engine.py +186 -0
  143. solidx_ai_agent-0.1.0/tests/test_bash_executor.py +60 -0
  144. solidx_ai_agent-0.1.0/tests/test_config.py +48 -0
  145. solidx_ai_agent-0.1.0/tests/test_db_listener.py +98 -0
  146. solidx_ai_agent-0.1.0/tests/test_db_models.py +129 -0
  147. solidx_ai_agent-0.1.0/tests/test_emit_sync_thread_safety.py +72 -0
  148. solidx_ai_agent-0.1.0/tests/test_environment.py +118 -0
  149. solidx_ai_agent-0.1.0/tests/test_events.py +92 -0
  150. solidx_ai_agent-0.1.0/tests/test_frontend_filesystem_tools.py +796 -0
  151. solidx_ai_agent-0.1.0/tests/test_get_backend_context.py +177 -0
  152. solidx_ai_agent-0.1.0/tests/test_get_metadata.py +252 -0
  153. solidx_ai_agent-0.1.0/tests/test_llm_intent_classification.py +275 -0
  154. solidx_ai_agent-0.1.0/tests/test_mcp_audit.py +290 -0
  155. solidx_ai_agent-0.1.0/tests/test_mcp_auth.py +347 -0
  156. solidx_ai_agent-0.1.0/tests/test_mcp_prompts.py +109 -0
  157. solidx_ai_agent-0.1.0/tests/test_mcp_resources.py +104 -0
  158. solidx_ai_agent-0.1.0/tests/test_mcp_tools.py +87 -0
  159. solidx_ai_agent-0.1.0/tests/test_rag_index_retrieval.py +346 -0
  160. solidx_ai_agent-0.1.0/tests/test_response_context.py +48 -0
  161. solidx_ai_agent-0.1.0/tests/test_sessions.py +119 -0
  162. solidx_ai_agent-0.1.0/tests/test_skills.py +867 -0
  163. solidx_ai_agent-0.1.0/tests/test_solid_ts_morph_client.py +57 -0
  164. solidx_ai_agent-0.1.0/tests/test_tool_registry.py +226 -0
  165. solidx_ai_agent-0.1.0/tests/test_turn_complete.py +41 -0
  166. solidx_ai_agent-0.1.0/tools/__init__.py +0 -0
  167. solidx_ai_agent-0.1.0/tools/adapter.py +433 -0
  168. solidx_ai_agent-0.1.0/tools/bash_executor.py +126 -0
  169. solidx_ai_agent-0.1.0/tools/composite.py +106 -0
  170. solidx_ai_agent-0.1.0/tools/registry.py +137 -0
@@ -0,0 +1,658 @@
1
+ Metadata-Version: 2.4
2
+ Name: solidx-ai-agent
3
+ Version: 0.1.0
4
+ Summary: AI agent harness for the SolidX platform — build full-stack apps via natural language
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: litellm
8
+ Requires-Dist: mini-swe-agent>=2.2.8
9
+ Requires-Dist: pydantic>=2
10
+ Requires-Dist: pydantic-settings
11
+ Requires-Dist: python-dotenv
12
+ Requires-Dist: rich
13
+ Requires-Dist: typer
14
+ Requires-Dist: pyyaml
15
+ Requires-Dist: jinja2
16
+ Requires-Dist: fastapi
17
+ Requires-Dist: uvicorn[standard]
18
+ Requires-Dist: websockets
19
+ Requires-Dist: sqlalchemy>=2.0
20
+ Requires-Dist: psycopg2-binary
21
+ Requires-Dist: openai>=1.0
22
+ Requires-Dist: anthropic
23
+ Requires-Dist: httpx
24
+ Requires-Dist: aiohttp
25
+ Requires-Dist: tqdm
26
+ Requires-Dist: starlette
27
+ Requires-Dist: mcp>=1.0
28
+ Provides-Extra: full
29
+ Requires-Dist: llama-index-core; extra == "full"
30
+ Requires-Dist: llama-index-embeddings-huggingface; extra == "full"
31
+ Requires-Dist: sentence-transformers; extra == "full"
32
+ Requires-Dist: PyMuPDF; extra == "full"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest; extra == "dev"
35
+ Requires-Dist: pytest-asyncio; extra == "dev"
36
+ Requires-Dist: ruff; extra == "dev"
37
+
38
+ # SolidX AI Agent
39
+
40
+ Build full-stack applications on the SolidX platform using natural language.
41
+
42
+ The SolidX AI Agent is an LLM-powered harness that wraps the SolidX platform tools — module creation, model/field management, layout editing, code generation, and more — so an LLM can orchestrate multi-step application building through a CLI, a persistent **server** (WebSocket + REST for the Chat UI), or `solidctl`.
43
+
44
+ ```
45
+ You: "Create a CRM module with Lead and Contact models,
46
+ add name/email/phone fields, set up list views and menus"
47
+
48
+ Agent: 1. Checks existing modules (solid_get_module_metadata)
49
+ 2. Creates CRM module (solid_create_module)
50
+ 3. Creates Lead model with fields (solid_create_model_with_fields)
51
+ 4. Creates Contact model with fields (solid_create_model_with_fields)
52
+ 5. Configures list/form layouts (solid_update_layout)
53
+ 6. Adds sidebar menu entries (solid_add_or_update_menu)
54
+ → Done. DB + APIs + UI generated.
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Key Features
60
+
61
+ - **10 SolidX platform tools** exposed to the LLM alongside a `bash` shell tool — including `filesystem_tool` for unified frontend operations and `get_metadata` for read-only metadata inspection
62
+ - **Persistent server process** — FastAPI with WebSocket + REST endpoints for multi-turn conversations
63
+ - **Multi-turn sessions** — agent maintains conversation context across messages
64
+ - **Interaction logging** — all events persisted to PostgreSQL via agent-owned DB layer
65
+ - **solidctl integration** — `solidctl agent start` / `solidctl agent run <task>` commands
66
+ - **Event-driven architecture** — every agent action emits typed events for real-time streaming to CLI or Chat UI
67
+ - **Rich CLI output** — colored panels, step boundaries, tool call previews, cost tracking
68
+ - **Interactive mode** — REPL-style prompt for iterative building
69
+ - **Built on mini-SWE-agent** — lightweight, extensible observe-act loop with LiteLLM (supports Anthropic, OpenAI, and 100+ providers); uses **FastLLM for auxiliary tasks** (intent classification, session titles)
70
+
71
+ ---
72
+
73
+ ## Prerequisites
74
+
75
+ - **Python 3.11+** (recommended)
76
+ - **An LLM API key** — Anthropic (recommended) or OpenAI
77
+ - **PostgreSQL** with the SolidX database (`DATABASE_URL`)
78
+ - **For server interaction logging** (optional): `DATABASE_URL` so the agent can create its logging tables in PostgreSQL
79
+
80
+ ---
81
+
82
+ ## Quick Start
83
+
84
+ ### 1. Install
85
+
86
+ ```bash
87
+ cd /path/to/SolidXCode/solidx-ai-agent
88
+ pip install -e "./vendor/mini-swe-agent" -e ".[dev]"
89
+
90
+ # After taking pull
91
+ pip install -e ".[full]"
92
+
93
+ ```
94
+
95
+ ### 2. Configure environment
96
+
97
+ ```bash
98
+ cp .env.example .env
99
+ ```
100
+
101
+ Edit `.env` with your settings:
102
+
103
+ ```bash
104
+ # Required: LLM API key (pick one)
105
+ ANTHROPIC_API_KEY=sk-ant-...
106
+ # OPENAI_API_KEY=sk-...
107
+
108
+ # Required for native mode: database connection
109
+ DATABASE_URL=postgresql://user:password@localhost:5432/solidx_db
110
+
111
+ # Optional: which LLM model to use (default: anthropic/claude-sonnet-4-20250514)
112
+ # MSWEA_MODEL_NAME=anthropic/claude-sonnet-4-20250514
113
+
114
+ # Optional: RAG support uses LlamaIndex
115
+ ```
116
+
117
+ ### 3. Run the agent
118
+
119
+ **Start the agent server (for Chat UI):**
120
+
121
+ ```bash
122
+ solidx-agent serve --port 8765
123
+ ```
124
+
125
+ **Single task (CLI):**
126
+
127
+ ```bash
128
+ solidx-agent "Create a Library Management module with Book and Author models"
129
+ ```
130
+
131
+ **Interactive mode:**
132
+
133
+ ```bash
134
+ solidx-agent -i
135
+ ```
136
+
137
+ ```
138
+ SolidX AI Agent — Interactive Mode
139
+
140
+ Type your task and press Enter. Type quit or exit to stop.
141
+
142
+ solidx> List all existing modules
143
+ solidx> Create a Book model with title, author, isbn, and published_date fields
144
+ solidx> Add a Publisher model to the Library module
145
+ solidx> quit
146
+ ```
147
+
148
+ **As a Python module:**
149
+
150
+ ```bash
151
+ python -m solidx_agent "Show me the field metadata for the Book model"
152
+ ```
153
+
154
+ ### 4. Verify the installation (no external services needed)
155
+
156
+ ```bash
157
+ MSWEA_SILENT_STARTUP=1 python -m pytest tests/ -v
158
+ ```
159
+
160
+ All 166+ tests across 24 test files pass using mock adapters — no database or LLM API required.
161
+
162
+ ---
163
+
164
+ ## CLI Reference
165
+
166
+ ```
167
+ Usage: solidx-agent [OPTIONS] [TASK] COMMAND [ARGS]...
168
+
169
+ Commands:
170
+ serve Start the agent server (FastAPI + WebSocket + REST + /mcp mount)
171
+ mcp Run as a local MCP server over stdio (for Claude Desktop)
172
+ mcp-remote Run as a remote MCP server over Streamable HTTP
173
+
174
+ Arguments:
175
+ [TASK] Task description for the agent
176
+
177
+ Options:
178
+ -c, --config TEXT Path to custom YAML config file
179
+ -m, --mode TEXT Tool mode (default: native)
180
+ -l, --log-level TEXT Logging level (default: INFO)
181
+ -i, --interactive Interactive prompt mode
182
+ --help Show this message and exit.
183
+ ```
184
+
185
+ **`serve` subcommand:**
186
+
187
+ ```
188
+ Usage: solidx-agent serve [OPTIONS]
189
+
190
+ Options:
191
+ -p, --port INTEGER Port to bind the server (default: 8765)
192
+ -H, --host TEXT Host to bind the server (default: 0.0.0.0)
193
+ -l, --log-level TEXT Logging level (default: INFO)
194
+ ```
195
+
196
+ **`mcp` subcommand (local STDIO MCP):**
197
+
198
+ ```
199
+ Usage: solidx-agent mcp [OPTIONS]
200
+
201
+ Options:
202
+ -l, --log-level TEXT Logging level (default: INFO)
203
+ --file-logs/--no-file-logs Write logs to Claude Desktop logs directory
204
+ ```
205
+
206
+ Requires `SOLIDX_API_KEY` (a solid-core user API key, format `sldx_…`)
207
+ in the environment. The user's role must include the `mcp:invoke`
208
+ permission.
209
+
210
+ **`mcp-remote` subcommand (remote Streamable-HTTP MCP):**
211
+
212
+ ```
213
+ Usage: solidx-agent mcp-remote [OPTIONS]
214
+
215
+ Options:
216
+ --host TEXT Bind address (default: 0.0.0.0)
217
+ -p, --port INTEGER Listen port (default: 9000)
218
+ --mount-path TEXT Path to mount the MCP app at (default: /mcp)
219
+ -l, --log-level TEXT Logging level (default: INFO)
220
+ ```
221
+
222
+ Requires `DATABASE_URL` (the same Postgres as solid-core). Clients
223
+ authenticate by sending the `solidx-api-key: sldx_…` header on every
224
+ request. `GET /health` is exempt from auth for liveness probes.
225
+
226
+ **Examples:**
227
+
228
+ ```bash
229
+ # One-shot task
230
+ solidx-agent "Add an email field to the Contact model in the CRM module"
231
+
232
+ # Persistent server (Chat UI)
233
+ solidx-agent serve --port 8765
234
+
235
+ # Use a different LLM model
236
+ MSWEA_MODEL_NAME=openai/gpt-4o solidx-agent "Create a Task model"
237
+
238
+ # Custom config file
239
+ solidx-agent --config my_config.yaml "Build a dashboard"
240
+
241
+ # Debug logging
242
+ solidx-agent -l DEBUG "Inspect the Library module"
243
+ ```
244
+
245
+ ---
246
+
247
+ ## Running the MCP server (authenticated)
248
+
249
+ The MCP layer is exposed three ways:
250
+
251
+ | Entry point | Auth | Audit log | Notes |
252
+ |---|---|---|---|
253
+ | `solidx-agent serve` (`/mcp` mount) | **none** — agent mode | none (uses `ss_agent_events`) | Convenience for the bundled agent server. |
254
+ | `solidx-agent mcp` (STDIO) | **required** — `SOLIDX_API_KEY` env var | `ss_mcp_audit_log` | Local Claude Desktop, Cursor stdio, etc. |
255
+ | `solidx-agent mcp-remote` (HTTP) | **required** — `solidx-api-key` header | `ss_mcp_audit_log` | Cloud desktop, Codex CLI, remote clients. |
256
+
257
+ Both dedicated MCP commands authenticate against **solid-core user API
258
+ keys** (the keys minted via `POST /iam/api-keys`). Validation is
259
+ performed against the shared Postgres directly — no HTTP call to
260
+ solid-core per request, with a short in-process cache. The user's role
261
+ must include the `mcp:invoke` permission (configurable under
262
+ `mcp.remote.required_permission`).
263
+
264
+ ### Local Claude Desktop (`mcp` STDIO)
265
+
266
+ 1. Mint an API key for your user in solid-core (admin UI or `POST /iam/api-keys`).
267
+ 2. Configure Claude Desktop's `claude_desktop_config.json`:
268
+
269
+ ```json
270
+ {
271
+ "mcpServers": {
272
+ "solidx": {
273
+ "command": "solidx-agent",
274
+ "args": ["mcp"],
275
+ "env": {
276
+ "SOLIDX_API_KEY": "sldx_...",
277
+ "DATABASE_URL": "postgresql://user:pw@host:5432/db"
278
+ }
279
+ }
280
+ }
281
+ }
282
+ ```
283
+
284
+ 3. Restart Claude Desktop. If the key is invalid or the user lacks the
285
+ `mcp:invoke` permission, the server fails to start and the error is
286
+ surfaced in Claude Desktop's "developer tools" log.
287
+
288
+ The STDIO server re-validates the key periodically (default every 5
289
+ minutes, see `mcp.remote.stdio_revalidate_seconds`) and exits if the
290
+ key is revoked or loses its permission, so revocations propagate
291
+ without restarting Claude.
292
+
293
+ ### Remote (`mcp-remote` Streamable HTTP)
294
+
295
+ ```bash
296
+ export DATABASE_URL=postgresql://user:pw@host:5432/db # same DB as solid-core
297
+ solidx-agent mcp-remote --host 0.0.0.0 --port 9000
298
+ ```
299
+
300
+ Test from the command line:
301
+
302
+ ```bash
303
+ # Liveness — no auth required
304
+ curl http://localhost:9000/health
305
+
306
+ # Without the header → 401
307
+ curl -X POST http://localhost:9000/mcp/ \
308
+ -H 'content-type: application/json' \
309
+ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
310
+
311
+ # With a valid, permitted key → 200
312
+ curl -X POST http://localhost:9000/mcp/ \
313
+ -H 'content-type: application/json' \
314
+ -H 'solidx-api-key: sldx_...' \
315
+ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
316
+ ```
317
+
318
+ Configure your remote MCP client (Cursor, Codex CLI, etc.) to use
319
+ `http://<host>:9000/mcp/` with header `solidx-api-key: sldx_…`.
320
+
321
+ ### Audit log (`ss_mcp_audit_log`)
322
+
323
+ Every dedicated-MCP request is persisted to `ss_mcp_audit_log` —
324
+ auth events (`auth.startup`, `auth.denied`, `auth.revalidate`),
325
+ non-tool JSON-RPC method calls (`tools/list`, `initialize`, etc.),
326
+ and tool invocations (`tools/call`) with their inputs and outputs.
327
+
328
+ Useful queries:
329
+
330
+ ```sql
331
+ -- Recent activity per user
332
+ SELECT username, method, tool_name, status, duration_ms, created_at
333
+ FROM ss_mcp_audit_log
334
+ ORDER BY created_at DESC
335
+ LIMIT 50;
336
+
337
+ -- Failed auth attempts in the last hour
338
+ SELECT created_at, transport, client_addr, error_message
339
+ FROM ss_mcp_audit_log
340
+ WHERE method = 'auth.denied' AND created_at > NOW() - INTERVAL '1 hour';
341
+
342
+ -- Most-used tools per user this week
343
+ SELECT username, tool_name, COUNT(*) AS calls,
344
+ AVG(duration_ms) AS avg_ms
345
+ FROM ss_mcp_audit_log
346
+ WHERE method = 'tools/call' AND created_at > NOW() - INTERVAL '7 days'
347
+ GROUP BY username, tool_name
348
+ ORDER BY calls DESC;
349
+ ```
350
+
351
+ Large request/response payloads are JSON-encoded and truncated to
352
+ `mcp.audit.max_payload_chars` (default 100 KB). Set
353
+ `mcp.audit.log_response_results: false` to skip response bodies (only
354
+ inputs are logged). Set `mcp.audit.enabled: false` to disable audit
355
+ logging entirely.
356
+
357
+ > **Limitation:** STDIO mode logs auth events and every tool call, but
358
+ > not non-tool JSON-RPC methods (e.g. `tools/list`, `initialize`).
359
+ > Those are only visible in the audit log when going through `mcp-remote`.
360
+
361
+ ---
362
+
363
+ ## solidctl Commands
364
+
365
+ When using the SolidX CLI (`solidctl`), you can start the agent server or run a single task without invoking `solidx-agent` directly:
366
+
367
+ ```bash
368
+ solidctl agent start --port 8765 # start agent server
369
+ solidctl agent run "Create a CRM" # single-shot task
370
+ ```
371
+
372
+ ---
373
+
374
+ ## Tool Execution
375
+
376
+ The agent imports tool functions directly and calls them as async Python functions (native mode). Only native mode is supported.
377
+
378
+ ```
379
+ Agent process → Python import → manage_data_model() → PostgreSQL
380
+ ```
381
+
382
+ **Requirements:**
383
+ - `DATABASE_URL` pointing to the SolidX PostgreSQL database
384
+ - (Optional) LlamaIndex RAG index for documentation-aware tools
385
+
386
+ **Best for:** Local development, single-user workflows, fastest execution.
387
+
388
+ ---
389
+
390
+ ## Available Tools
391
+
392
+ The agent exposes 11 tools (10 SolidX + bash):
393
+
394
+ | Tool | Category | Purpose |
395
+ |------|----------|---------|
396
+ | `bash` | Shell | Execute any shell command |
397
+ | `manage_data_model` | Backend | CRUD for modules, models, and fields |
398
+ | `get_backend_context` | Backend | Read-only backend inspection (code context, datasources, controllers, services, providers) |
399
+ | `filesystem_tool` | Frontend | Unified frontend filesystem operations (search, read, patch) |
400
+ | `get_metadata` | Backend | Read-only metadata inspection (modules, models, fields, roles, security rules, menus, layouts, dashboards, etc.) |
401
+ | `manage_metadata` | Backend | CRUD for menus, roles, security rules, layouts, templates, etc. |
402
+ | `edit_backend_code` | Backend | Backend code editing (controllers, services, providers, etc.) |
403
+ | `run_solidctl` | Deployment | Execute solidctl CLI commands |
404
+ | `introspect_database` | Backend | Introspect existing database schemas |
405
+ | `content_crud` | Backend | CRUD operations on model records via REST API |
406
+
407
+ > **Note:** `edit_frontend_code` and `get_frontend_context` still exist in the codebase but are NOT in the active tool list — they were replaced by `filesystem_tool`.
408
+
409
+ ---
410
+
411
+ ## Configuration
412
+
413
+ ### Config file (`config/solidx.yaml`)
414
+
415
+ The default config is bundled with the package. Override it with `--config`:
416
+
417
+ ```yaml
418
+ agent:
419
+ step_limit: 30 # max LLM query cycles
420
+ cost_limit: 5.0 # max USD spend per run
421
+ mode: confirm # confirm / yolo / human
422
+
423
+ tools:
424
+ mode: native # only native mode is supported
425
+
426
+ environment:
427
+ timeout: 120 # shell command timeout (seconds)
428
+ cwd: "" # working directory (default: current)
429
+
430
+ server:
431
+ port: 8765
432
+ host: "0.0.0.0"
433
+ session_timeout: 1800
434
+ max_sessions: 10
435
+
436
+ model:
437
+ model_name: anthropic/claude-sonnet-4-20250514
438
+ cost_tracking: ignore_errors
439
+ ```
440
+
441
+ ### Environment variable overrides
442
+
443
+ Any config value can be overridden via environment variables:
444
+
445
+ | Environment Variable | Config Path | Example |
446
+ |---------------------|-------------|---------|
447
+ | `MSWEA_MODEL_NAME` | `model.model_name` | `openai/gpt-4o` |
448
+ | `SOLIDX_PROJECT_ROOT` | `environment.cwd` | `/path/to/project` |
449
+ | `SOLIDX_AGENT_STEP_LIMIT` | `agent.step_limit` | `50` |
450
+ | `SOLIDX_AGENT_COST_LIMIT` | `agent.cost_limit` | `10.0` |
451
+ | `SOLIDX_SERVER_PORT` | `server.port` | `8765` |
452
+ | `SOLIDX_SERVER_HOST` | `server.host` | `0.0.0.0` |
453
+ | `SOLIDX_SESSION_TIMEOUT` | `server.session_timeout` | `1800` |
454
+ | `SOLIDX_MAX_SESSIONS` | `server.max_sessions` | `10` |
455
+
456
+ ---
457
+
458
+ ## Project Structure
459
+
460
+ ```
461
+ solidx-ai-agent/
462
+ ├── vendor/mini-swe-agent/ # Agent framework (editable install, not modified)
463
+ ├── pyproject.toml # Package config and dependencies
464
+ ├── .env.example # Environment variable template
465
+ ├── README.md # This file
466
+ ├── ARCHITECTURE.md # Detailed technical architecture reference
467
+ ├── run.py # CLI entry point (Typer)
468
+ ├── console.py # Rich terminal event listeners
469
+ ├── exceptions.py # Agent exceptions (e.g. TurnComplete)
470
+ ├── agent-ui/ # Bundled React/Vite Chat UI
471
+ ├── agents/
472
+ │ └── solidx_agent.py # Agent with lifecycle events
473
+ ├── config/
474
+ │ ├── loader.py # YAML + env var config loading
475
+ │ └── solidx.yaml # Default configuration
476
+ ├── db/
477
+ │ ├── base.py # SQLAlchemy declarative base
478
+ │ ├── session.py # Engine / session factory for agent DB
479
+ │ ├── repository.py # Persistence helpers
480
+ │ └── models/ # ORM models (sessions, events)
481
+ ├── environments/
482
+ │ └── solidx_environment.py # Hybrid bash + SolidX tool executor
483
+ ├── events/
484
+ │ ├── emitter.py # Async EventEmitter
485
+ │ └── events.py # Typed event dataclasses
486
+ ├── models/
487
+ │ ├── solidx_model.py # Multi-tool LLM model
488
+ │ └── fast_llm.py # FastLLM for auxiliary tasks (intent classification, session titles)
489
+ ├── prompts/
490
+ │ ├── system_prompt.md # SolidX builder system prompt
491
+ │ └── instance_prompt.md # Per-task prompt template
492
+ ├── server/
493
+ │ ├── app.py # FastAPI app: WebSocket + REST
494
+ │ ├── sessions.py # Multi-turn session manager
495
+ │ └── db_listener.py # Persists events to PostgreSQL
496
+ ├── skills/ # Skill library
497
+ │ ├── backend-studio/ # 40 backend skills
498
+ │ ├── frontend-studio/ # 4 frontend skills
499
+ │ ├── deployment-studio/ # 1 deployment skill
500
+ │ ├── platform/ # 2 platform-level skills
501
+ │ ├── tools/ # (reserved)
502
+ │ └── workflows/ # (reserved)
503
+ ├── solidx_platform/
504
+ │ ├── tools/ # Tool implementations (includes deprecated edit_frontend_code, get_frontend_context)
505
+ │ └── helpers/ # Helpers: backend_step_engine.py, code_context_selector.py, json_patch_helper.py, …
506
+ ├── tools/
507
+ │ ├── adapter.py # Native tool adapter
508
+ │ ├── registry.py # OpenAI function schema builder
509
+ │ └── composite.py # Multi-step orchestration helpers
510
+ └── tests/ # 166+ tests across 24 test files (all pass without external services)
511
+ ```
512
+
513
+ **Dependency graph:**
514
+
515
+ ```
516
+ solidx-ai-agent
517
+ ├── sqlalchemy>=2.0, psycopg2-binary, fastapi, uvicorn, websockets, …
518
+ └── mini-swe-agent (pip install -e ./vendor/mini-swe-agent)
519
+ └── litellm, pydantic, jinja2, …
520
+ ```
521
+
522
+ ---
523
+
524
+ ## How It Works
525
+
526
+ ### CLI and interactive mode
527
+
528
+ 1. **User provides a task** via CLI argument or interactive prompt
529
+ 2. **Config loads** from `solidx.yaml`, merged with environment variable overrides
530
+ 3. **Tool adapter initializes** — discovers tool functions from the installed platform tools (native mode)
531
+ 4. **Tool registry builds** OpenAI function-calling schemas from all discovered tools
532
+ 5. **Agent loop starts** — LLM receives the system prompt (SolidX platform context + tool descriptions) and the user's task; **FastLLM classifies user intent** (e.g. backend vs frontend task) to select the right skill/workflow
533
+ 6. **LLM reasons and calls tools** — can call `bash` for shell commands or any of the 10 SolidX tools
534
+ 7. **Environment dispatches** — routes bash to subprocess, SolidX tools to the adapter
535
+ 8. **Events stream** — every action emits typed events to the console (or WebSocket clients in server mode)
536
+ 9. **Loop repeats** until the LLM signals completion or limits are reached
537
+ 10. **Results displayed** with total steps and cost
538
+
539
+ ### Server mode (Chat UI)
540
+
541
+ 1. **Process starts** with `solidx-agent serve` (or `solidctl agent start`); FastAPI binds to `host`/`port` from config or flags
542
+ 2. **Lifespan hook** loads config, initializes the tool adapter and registry, optionally creates SQLAlchemy engine/session factory for the **agent** database (same `DATABASE_URL` as native tools when logging is enabled)
543
+ 3. **SessionManager** tracks WebSocket-backed sessions with idle timeout and max concurrent sessions
544
+ 4. **Client connects** to `/ws/agent`, sends `start_session` → server returns `session_id` and streams lifecycle events for that connection
545
+ 5. **Each user message** runs one **turn** — conversation history is kept in the session so the LLM sees prior turns (`UserMessage` / `TurnCompleteEvent` participate in the event stream and optional DB logging)
546
+ 6. **DatabaseEventListener** (when DB is configured) writes interaction events to PostgreSQL for auditing and analytics
547
+ 7. **REST** — `POST /api/agent/run` runs a single task in a temporary session; `GET`/`DELETE /api/agent/sessions` manage server-side sessions
548
+
549
+ ---
550
+
551
+ ## Streaming & Events
552
+
553
+ The agent emits typed events at every lifecycle point. This powers the CLI and the Chat UI over WebSocket.
554
+
555
+ **Events emitted during a run (representative flow):**
556
+
557
+ ```
558
+ AgentStarted → UserMessage → StepStarted → LlmComplete → ToolCalling → ToolResult → StepComplete → … → TurnCompleteEvent → AgentComplete
559
+ ```
560
+
561
+ (`UserMessage` records inbound user text in multi-turn flows; `TurnCompleteEvent` marks the end of one assistant turn.)
562
+
563
+ **CLI output example:**
564
+
565
+ ```
566
+ ╭──────────── SolidX Agent Started ─────────────╮
567
+ │ Create a Library module with Book model │
568
+ ╰────────────────────────────────────────────────╯
569
+ ──────────── Step 1 (cost so far: $0.0000) ─────────────
570
+ Assistant (step 1, $0.0023):
571
+ Let me check what modules already exist first.
572
+ > solid_get_module_metadata: {"module_matches": "Library"}
573
+
574
+ Calling tool: solid_get_module_metadata
575
+ Result: OK 234ms
576
+
577
+ ──────────── Step 2 (cost so far: $0.0023) ─────────────
578
+ ...
579
+ ──────────────────────────────────────────────────────────
580
+ ╭──────────── Agent Complete ────────────────────╮
581
+ │ Status: Submitted │
582
+ │ Steps: 4 | Cost: $0.0089 │
583
+ ╰────────────────────────────────────────────────╯
584
+ ```
585
+
586
+ **Chat UI — WebSocket** (`/ws/agent`): clients and server exchange JSON messages. **Client → server** (multi-turn protocol):
587
+
588
+ ```json
589
+ {"action": "start_session"}
590
+ {"action": "message", "session_id": "<uuid>", "content": "Create a CRM module"}
591
+ {"action": "end_session", "session_id": "<uuid>"}
592
+ ```
593
+
594
+ **Server → client:** after `start_session`, the server sends `session_started`, then streams typed events (same shape as below) for each turn, and ends the turn with `turn_complete`.
595
+
596
+ ```json
597
+ {"type": "session_started", "session_id": "<uuid>"}
598
+ {"type": "UserMessage", "data": {"content": "Create a CRM module", "session_id": "<uuid>", "turn_number": 1}}
599
+ {"type": "StepStarted", "data": {"step": 1, "cost_so_far": 0.0}}
600
+ {"type": "ToolCalling", "data": {"tool_name": "solid_create_module", "arguments": {"prompt": "..."}}}
601
+ {"type": "ToolResult", "data": {"tool_name": "solid_create_module", "output": "...", "returncode": 0}}
602
+ {"type": "TurnCompleteEvent", "data": {"content": "...", "turn_number": 1, "total_cost": 0.01, "total_steps": 3}}
603
+ {"type": "turn_complete", "data": {"content": "...", "session_id": "<uuid>", "turn_count": 1}}
604
+ {"type": "session_ended", "session_id": "<uuid>"}
605
+ ```
606
+
607
+ See **[docs/CHAT_UI_DEVELOPER_GUIDE.md](docs/CHAT_UI_DEVELOPER_GUIDE.md)** for full protocol details, REST endpoints, and integration notes.
608
+
609
+ ---
610
+
611
+ ## Example Tasks to Try
612
+
613
+ Once set up with a database and API key:
614
+
615
+ ```bash
616
+ # Inspect existing state
617
+ solidx-agent "List all existing modules and their models"
618
+
619
+ # Explore metadata
620
+ solidx-agent "What modules exist in this project? Show me all models and their field counts."
621
+
622
+ # Create from scratch
623
+ solidx-agent "Create a Blog module with Post and Comment models. Posts should have title, content, published_date, and status fields. Comments should have body, author_name, and a relation to Post."
624
+
625
+ # Modify existing structures
626
+ solidx-agent "Add an email and phone_number field to the Author model in the Library module"
627
+
628
+ # Layout changes
629
+ solidx-agent "Update the list view for Books to show title, author, isbn, and published_date columns"
630
+
631
+ # Code changes
632
+ solidx-agent "Add a custom endpoint to the Book controller that returns books published in the last 30 days"
633
+
634
+ # Multi-step workflows
635
+ solidx-agent "Create a complete Task Management module with Project, Task, and Comment models. Projects have name and description. Tasks have title, description, status (todo/in-progress/done), priority, and due_date. Comments belong to Tasks. Set up menus for all models."
636
+ ```
637
+
638
+ ---
639
+
640
+ ## Troubleshooting
641
+
642
+ **"DATABASE_URL environment variable is not set"**
643
+ Set `DATABASE_URL` in `.env` pointing to your SolidX PostgreSQL database.
644
+
645
+ **"No default model set"**
646
+ Set `MSWEA_MODEL_NAME` in `.env` (e.g., `anthropic/claude-sonnet-4-20250514`) or `ANTHROPIC_API_KEY` / `OPENAI_API_KEY`.
647
+
648
+ **Tests fail on import**
649
+ Run `pip install -e "./vendor/mini-swe-agent" -e ".[dev]"` to ensure both packages are installed as editable.
650
+
651
+ ---
652
+
653
+ ## Further Reading
654
+
655
+ - **[ARCHITECTURE.md](ARCHITECTURE.md)** — Detailed technical architecture, component deep dives, data flow diagrams, and extension points
656
+ - **[docs/CHAT_UI_DEVELOPER_GUIDE.md](docs/CHAT_UI_DEVELOPER_GUIDE.md)** — Chat UI integration: WebSocket protocol, REST API, and session flow
657
+ - **[mini-swe-agent docs](https://mini-swe-agent.com)** — Framework documentation for the underlying agent loop
658
+ - **[LiteLLM docs](https://docs.litellm.ai)** — Supported LLM providers and model names