codexa 0.4.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 (189) hide show
  1. codexa-0.4.0.dist-info/METADATA +650 -0
  2. codexa-0.4.0.dist-info/RECORD +189 -0
  3. codexa-0.4.0.dist-info/WHEEL +5 -0
  4. codexa-0.4.0.dist-info/entry_points.txt +2 -0
  5. codexa-0.4.0.dist-info/licenses/LICENSE +21 -0
  6. codexa-0.4.0.dist-info/top_level.txt +1 -0
  7. semantic_code_intelligence/__init__.py +5 -0
  8. semantic_code_intelligence/analysis/__init__.py +21 -0
  9. semantic_code_intelligence/analysis/ai_features.py +351 -0
  10. semantic_code_intelligence/bridge/__init__.py +28 -0
  11. semantic_code_intelligence/bridge/context_provider.py +245 -0
  12. semantic_code_intelligence/bridge/protocol.py +167 -0
  13. semantic_code_intelligence/bridge/server.py +348 -0
  14. semantic_code_intelligence/bridge/vscode.py +271 -0
  15. semantic_code_intelligence/ci/__init__.py +13 -0
  16. semantic_code_intelligence/ci/hooks.py +98 -0
  17. semantic_code_intelligence/ci/hotspots.py +272 -0
  18. semantic_code_intelligence/ci/impact.py +246 -0
  19. semantic_code_intelligence/ci/metrics.py +591 -0
  20. semantic_code_intelligence/ci/pr.py +412 -0
  21. semantic_code_intelligence/ci/quality.py +557 -0
  22. semantic_code_intelligence/ci/templates.py +164 -0
  23. semantic_code_intelligence/ci/trace.py +224 -0
  24. semantic_code_intelligence/cli/__init__.py +0 -0
  25. semantic_code_intelligence/cli/commands/__init__.py +0 -0
  26. semantic_code_intelligence/cli/commands/ask_cmd.py +153 -0
  27. semantic_code_intelligence/cli/commands/benchmark_cmd.py +303 -0
  28. semantic_code_intelligence/cli/commands/chat_cmd.py +252 -0
  29. semantic_code_intelligence/cli/commands/ci_gen_cmd.py +74 -0
  30. semantic_code_intelligence/cli/commands/context_cmd.py +120 -0
  31. semantic_code_intelligence/cli/commands/cross_refactor_cmd.py +113 -0
  32. semantic_code_intelligence/cli/commands/deps_cmd.py +91 -0
  33. semantic_code_intelligence/cli/commands/docs_cmd.py +101 -0
  34. semantic_code_intelligence/cli/commands/doctor_cmd.py +147 -0
  35. semantic_code_intelligence/cli/commands/evolve_cmd.py +171 -0
  36. semantic_code_intelligence/cli/commands/explain_cmd.py +112 -0
  37. semantic_code_intelligence/cli/commands/gate_cmd.py +135 -0
  38. semantic_code_intelligence/cli/commands/grep_cmd.py +234 -0
  39. semantic_code_intelligence/cli/commands/hotspots_cmd.py +119 -0
  40. semantic_code_intelligence/cli/commands/impact_cmd.py +131 -0
  41. semantic_code_intelligence/cli/commands/index_cmd.py +138 -0
  42. semantic_code_intelligence/cli/commands/init_cmd.py +152 -0
  43. semantic_code_intelligence/cli/commands/investigate_cmd.py +163 -0
  44. semantic_code_intelligence/cli/commands/languages_cmd.py +101 -0
  45. semantic_code_intelligence/cli/commands/lsp_cmd.py +49 -0
  46. semantic_code_intelligence/cli/commands/mcp_cmd.py +50 -0
  47. semantic_code_intelligence/cli/commands/metrics_cmd.py +264 -0
  48. semantic_code_intelligence/cli/commands/models_cmd.py +157 -0
  49. semantic_code_intelligence/cli/commands/plugin_cmd.py +275 -0
  50. semantic_code_intelligence/cli/commands/pr_summary_cmd.py +178 -0
  51. semantic_code_intelligence/cli/commands/quality_cmd.py +208 -0
  52. semantic_code_intelligence/cli/commands/refactor_cmd.py +103 -0
  53. semantic_code_intelligence/cli/commands/review_cmd.py +88 -0
  54. semantic_code_intelligence/cli/commands/search_cmd.py +236 -0
  55. semantic_code_intelligence/cli/commands/serve_cmd.py +117 -0
  56. semantic_code_intelligence/cli/commands/suggest_cmd.py +100 -0
  57. semantic_code_intelligence/cli/commands/summary_cmd.py +78 -0
  58. semantic_code_intelligence/cli/commands/tool_cmd.py +282 -0
  59. semantic_code_intelligence/cli/commands/trace_cmd.py +123 -0
  60. semantic_code_intelligence/cli/commands/tui_cmd.py +58 -0
  61. semantic_code_intelligence/cli/commands/viz_cmd.py +127 -0
  62. semantic_code_intelligence/cli/commands/watch_cmd.py +72 -0
  63. semantic_code_intelligence/cli/commands/web_cmd.py +61 -0
  64. semantic_code_intelligence/cli/commands/workspace_cmd.py +250 -0
  65. semantic_code_intelligence/cli/main.py +65 -0
  66. semantic_code_intelligence/cli/router.py +92 -0
  67. semantic_code_intelligence/config/__init__.py +0 -0
  68. semantic_code_intelligence/config/settings.py +260 -0
  69. semantic_code_intelligence/context/__init__.py +19 -0
  70. semantic_code_intelligence/context/engine.py +429 -0
  71. semantic_code_intelligence/context/memory.py +253 -0
  72. semantic_code_intelligence/daemon/__init__.py +1 -0
  73. semantic_code_intelligence/daemon/watcher.py +515 -0
  74. semantic_code_intelligence/docs/__init__.py +1080 -0
  75. semantic_code_intelligence/embeddings/__init__.py +0 -0
  76. semantic_code_intelligence/embeddings/enhanced.py +131 -0
  77. semantic_code_intelligence/embeddings/generator.py +149 -0
  78. semantic_code_intelligence/embeddings/model_registry.py +100 -0
  79. semantic_code_intelligence/evolution/__init__.py +1 -0
  80. semantic_code_intelligence/evolution/budget_guard.py +111 -0
  81. semantic_code_intelligence/evolution/commit_manager.py +88 -0
  82. semantic_code_intelligence/evolution/context_builder.py +131 -0
  83. semantic_code_intelligence/evolution/engine.py +249 -0
  84. semantic_code_intelligence/evolution/patch_generator.py +229 -0
  85. semantic_code_intelligence/evolution/task_selector.py +214 -0
  86. semantic_code_intelligence/evolution/test_runner.py +111 -0
  87. semantic_code_intelligence/indexing/__init__.py +0 -0
  88. semantic_code_intelligence/indexing/chunker.py +174 -0
  89. semantic_code_intelligence/indexing/parallel.py +86 -0
  90. semantic_code_intelligence/indexing/scanner.py +146 -0
  91. semantic_code_intelligence/indexing/semantic_chunker.py +337 -0
  92. semantic_code_intelligence/llm/__init__.py +62 -0
  93. semantic_code_intelligence/llm/cache.py +219 -0
  94. semantic_code_intelligence/llm/cached_provider.py +145 -0
  95. semantic_code_intelligence/llm/conversation.py +190 -0
  96. semantic_code_intelligence/llm/cross_refactor.py +272 -0
  97. semantic_code_intelligence/llm/investigation.py +274 -0
  98. semantic_code_intelligence/llm/mock_provider.py +77 -0
  99. semantic_code_intelligence/llm/ollama_provider.py +122 -0
  100. semantic_code_intelligence/llm/openai_provider.py +100 -0
  101. semantic_code_intelligence/llm/provider.py +92 -0
  102. semantic_code_intelligence/llm/rate_limiter.py +164 -0
  103. semantic_code_intelligence/llm/reasoning.py +438 -0
  104. semantic_code_intelligence/llm/safety.py +110 -0
  105. semantic_code_intelligence/llm/streaming.py +251 -0
  106. semantic_code_intelligence/lsp/__init__.py +609 -0
  107. semantic_code_intelligence/mcp/__init__.py +393 -0
  108. semantic_code_intelligence/parsing/__init__.py +19 -0
  109. semantic_code_intelligence/parsing/parser.py +375 -0
  110. semantic_code_intelligence/plugins/__init__.py +255 -0
  111. semantic_code_intelligence/plugins/examples/__init__.py +1 -0
  112. semantic_code_intelligence/plugins/examples/code_quality.py +73 -0
  113. semantic_code_intelligence/plugins/examples/search_annotator.py +56 -0
  114. semantic_code_intelligence/scalability/__init__.py +205 -0
  115. semantic_code_intelligence/search/__init__.py +0 -0
  116. semantic_code_intelligence/search/formatter.py +123 -0
  117. semantic_code_intelligence/search/grep.py +361 -0
  118. semantic_code_intelligence/search/hybrid_search.py +170 -0
  119. semantic_code_intelligence/search/keyword_search.py +311 -0
  120. semantic_code_intelligence/search/section_expander.py +103 -0
  121. semantic_code_intelligence/services/__init__.py +0 -0
  122. semantic_code_intelligence/services/indexing_service.py +630 -0
  123. semantic_code_intelligence/services/search_service.py +269 -0
  124. semantic_code_intelligence/storage/__init__.py +0 -0
  125. semantic_code_intelligence/storage/chunk_hash_store.py +86 -0
  126. semantic_code_intelligence/storage/hash_store.py +66 -0
  127. semantic_code_intelligence/storage/index_manifest.py +85 -0
  128. semantic_code_intelligence/storage/index_stats.py +138 -0
  129. semantic_code_intelligence/storage/query_history.py +160 -0
  130. semantic_code_intelligence/storage/symbol_registry.py +209 -0
  131. semantic_code_intelligence/storage/vector_store.py +297 -0
  132. semantic_code_intelligence/tests/__init__.py +0 -0
  133. semantic_code_intelligence/tests/test_ai_features.py +351 -0
  134. semantic_code_intelligence/tests/test_chunker.py +119 -0
  135. semantic_code_intelligence/tests/test_cli.py +188 -0
  136. semantic_code_intelligence/tests/test_config.py +154 -0
  137. semantic_code_intelligence/tests/test_context.py +381 -0
  138. semantic_code_intelligence/tests/test_embeddings.py +73 -0
  139. semantic_code_intelligence/tests/test_endtoend.py +1142 -0
  140. semantic_code_intelligence/tests/test_enhanced_embeddings.py +92 -0
  141. semantic_code_intelligence/tests/test_hash_store.py +79 -0
  142. semantic_code_intelligence/tests/test_logging.py +55 -0
  143. semantic_code_intelligence/tests/test_new_cli.py +138 -0
  144. semantic_code_intelligence/tests/test_parser.py +495 -0
  145. semantic_code_intelligence/tests/test_phase10.py +355 -0
  146. semantic_code_intelligence/tests/test_phase11.py +593 -0
  147. semantic_code_intelligence/tests/test_phase12.py +375 -0
  148. semantic_code_intelligence/tests/test_phase13.py +663 -0
  149. semantic_code_intelligence/tests/test_phase14.py +568 -0
  150. semantic_code_intelligence/tests/test_phase15.py +814 -0
  151. semantic_code_intelligence/tests/test_phase16.py +792 -0
  152. semantic_code_intelligence/tests/test_phase17.py +815 -0
  153. semantic_code_intelligence/tests/test_phase18.py +934 -0
  154. semantic_code_intelligence/tests/test_phase19.py +986 -0
  155. semantic_code_intelligence/tests/test_phase20.py +2753 -0
  156. semantic_code_intelligence/tests/test_phase20b.py +2058 -0
  157. semantic_code_intelligence/tests/test_phase20c.py +962 -0
  158. semantic_code_intelligence/tests/test_phase21.py +428 -0
  159. semantic_code_intelligence/tests/test_phase22.py +799 -0
  160. semantic_code_intelligence/tests/test_phase23.py +783 -0
  161. semantic_code_intelligence/tests/test_phase24.py +715 -0
  162. semantic_code_intelligence/tests/test_phase25.py +496 -0
  163. semantic_code_intelligence/tests/test_phase26.py +251 -0
  164. semantic_code_intelligence/tests/test_phase27.py +531 -0
  165. semantic_code_intelligence/tests/test_phase8.py +592 -0
  166. semantic_code_intelligence/tests/test_phase9.py +643 -0
  167. semantic_code_intelligence/tests/test_plugins.py +293 -0
  168. semantic_code_intelligence/tests/test_priority_features.py +727 -0
  169. semantic_code_intelligence/tests/test_router.py +41 -0
  170. semantic_code_intelligence/tests/test_scalability.py +138 -0
  171. semantic_code_intelligence/tests/test_scanner.py +125 -0
  172. semantic_code_intelligence/tests/test_search.py +160 -0
  173. semantic_code_intelligence/tests/test_semantic_chunker.py +255 -0
  174. semantic_code_intelligence/tests/test_tools.py +182 -0
  175. semantic_code_intelligence/tests/test_vector_store.py +151 -0
  176. semantic_code_intelligence/tests/test_watcher.py +211 -0
  177. semantic_code_intelligence/tools/__init__.py +442 -0
  178. semantic_code_intelligence/tools/executor.py +232 -0
  179. semantic_code_intelligence/tools/protocol.py +200 -0
  180. semantic_code_intelligence/tui/__init__.py +454 -0
  181. semantic_code_intelligence/utils/__init__.py +0 -0
  182. semantic_code_intelligence/utils/logging.py +112 -0
  183. semantic_code_intelligence/version.py +3 -0
  184. semantic_code_intelligence/web/__init__.py +11 -0
  185. semantic_code_intelligence/web/api.py +289 -0
  186. semantic_code_intelligence/web/server.py +397 -0
  187. semantic_code_intelligence/web/ui.py +659 -0
  188. semantic_code_intelligence/web/visualize.py +226 -0
  189. semantic_code_intelligence/workspace/__init__.py +427 -0
@@ -0,0 +1,1080 @@
1
+ """Auto-documentation generator for CodexA.
2
+
3
+ Generates Markdown documentation for:
4
+ - CLI commands (from Click command tree)
5
+ - Plugin hooks (from PluginHook enum)
6
+ - Bridge protocol (from RequestKind and data classes)
7
+ - Tool registry (from ToolRegistry definitions)
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import inspect
13
+ import textwrap
14
+ from pathlib import Path
15
+ from typing import Any
16
+
17
+ import click
18
+
19
+ from semantic_code_intelligence.utils.logging import get_logger
20
+
21
+ logger = get_logger("docs")
22
+
23
+
24
+ def generate_cli_reference(cli_group: click.Group) -> str:
25
+ """Generate Markdown documentation for all CLI commands.
26
+
27
+ Walks the Click command tree and produces a reference with
28
+ usage, options, and help text for every registered command.
29
+ """
30
+ lines: list[str] = [
31
+ "# CLI Reference",
32
+ "",
33
+ "Auto-generated from the registered Click command tree.",
34
+ "",
35
+ ]
36
+
37
+ commands = _collect_commands(cli_group, prefix="codexa")
38
+ for cmd_path, cmd in commands:
39
+ lines.append(f"## `{cmd_path}`")
40
+ lines.append("")
41
+
42
+ # Help text
43
+ help_text = (cmd.help or "").strip()
44
+ if help_text:
45
+ lines.append(help_text)
46
+ lines.append("")
47
+
48
+ # Arguments
49
+ params_args = [p for p in cmd.params if isinstance(p, click.Argument)]
50
+ if params_args:
51
+ lines.append("**Arguments:**")
52
+ lines.append("")
53
+ for arg in params_args:
54
+ lines.append(f"- `{arg.name}` — {arg.type.name}")
55
+ lines.append("")
56
+
57
+ # Options
58
+ params_opts = [p for p in cmd.params if isinstance(p, click.Option)]
59
+ if params_opts:
60
+ lines.append("**Options:**")
61
+ lines.append("")
62
+ lines.append("| Flag | Type | Default | Description |")
63
+ lines.append("|------|------|---------|-------------|")
64
+ for opt in params_opts:
65
+ flags = ", ".join(opt.opts + opt.secondary_opts)
66
+ type_name = opt.type.name if opt.type else ""
67
+ default = opt.default if opt.default is not None else ""
68
+ if isinstance(default, bool):
69
+ default = str(default).lower()
70
+ help_str = (opt.help or "").replace("|", "\\|")
71
+ lines.append(f"| `{flags}` | {type_name} | {default} | {help_str} |")
72
+ lines.append("")
73
+
74
+ lines.append("---")
75
+ lines.append("")
76
+
77
+ return "\n".join(lines)
78
+
79
+
80
+ def _collect_commands(
81
+ group: click.Group | click.Command,
82
+ prefix: str,
83
+ ) -> list[tuple[str, click.Command]]:
84
+ """Recursively collect all commands from a Click group."""
85
+ results: list[tuple[str, click.Command]] = []
86
+
87
+ if isinstance(group, click.Group):
88
+ for name in sorted(group.commands):
89
+ cmd = group.commands[name]
90
+ full = f"{prefix} {name}"
91
+ if isinstance(cmd, click.Group):
92
+ # Add the group itself
93
+ results.append((full, cmd))
94
+ results.extend(_collect_commands(cmd, full))
95
+ else:
96
+ results.append((full, cmd))
97
+ return results
98
+
99
+
100
+ def generate_plugin_reference() -> str:
101
+ """Generate Markdown documentation for the Plugin SDK."""
102
+ from semantic_code_intelligence.plugins import (
103
+ PluginBase,
104
+ PluginHook,
105
+ PluginMetadata,
106
+ )
107
+
108
+ lines: list[str] = [
109
+ "# Plugin SDK Reference",
110
+ "",
111
+ "Auto-generated from the CodexA plugin architecture.",
112
+ "",
113
+ "## Hook Points",
114
+ "",
115
+ f"CodexA provides **{len(PluginHook)}** hook points in the processing pipeline:",
116
+ "",
117
+ "| Hook | Value | Category |",
118
+ "|------|-------|----------|",
119
+ ]
120
+
121
+ categories = {
122
+ "PRE_INDEX": "Indexing",
123
+ "POST_INDEX": "Indexing",
124
+ "ON_CHUNK": "Indexing",
125
+ "PRE_SEARCH": "Search",
126
+ "POST_SEARCH": "Search",
127
+ "PRE_ANALYSIS": "Analysis",
128
+ "POST_ANALYSIS": "Analysis",
129
+ "PRE_AI": "AI",
130
+ "POST_AI": "AI",
131
+ "ON_FILE_CHANGE": "File Events",
132
+ "ON_STREAM": "Streaming",
133
+ "CUSTOM_VALIDATION": "Validation",
134
+ "CUSTOM": "Custom",
135
+ }
136
+
137
+ for hook in PluginHook:
138
+ cat = categories.get(hook.name, "Other")
139
+ lines.append(f"| `{hook.name}` | `{hook.value}` | {cat} |")
140
+
141
+ lines.extend([
142
+ "",
143
+ "## Plugin Base Class",
144
+ "",
145
+ "All plugins extend `PluginBase` and implement the following interface:",
146
+ "",
147
+ "```python",
148
+ "class PluginBase(ABC):",
149
+ " @abstractmethod",
150
+ " def metadata(self) -> PluginMetadata:",
151
+ ' """Return plugin name, version, description, and registered hooks."""',
152
+ "",
153
+ " def activate(self, context: dict) -> None:",
154
+ ' """Called when the plugin is activated."""',
155
+ "",
156
+ " def deactivate(self) -> None:",
157
+ ' """Called when the plugin is deactivated."""',
158
+ "",
159
+ " def on_hook(self, hook: PluginHook, data: dict) -> dict:",
160
+ ' """Called when a registered hook fires. Modify and return data."""',
161
+ "```",
162
+ "",
163
+ "## PluginMetadata",
164
+ "",
165
+ "| Field | Type | Description |",
166
+ "|-------|------|-------------|",
167
+ "| `name` | `str` | Unique plugin name |",
168
+ "| `version` | `str` | Semantic version (default: `0.1.0`) |",
169
+ "| `description` | `str` | Human-readable description |",
170
+ "| `author` | `str` | Author name |",
171
+ "| `hooks` | `list[PluginHook]` | Hooks this plugin subscribes to |",
172
+ "",
173
+ "## Discovery",
174
+ "",
175
+ "Plugins are discovered from `.codexa/plugins/` directories. Each plugin file",
176
+ "must define a `create_plugin()` factory function that returns a `PluginBase` instance.",
177
+ "",
178
+ "## Lifecycle",
179
+ "",
180
+ "1. **Register** — `PluginManager.register(plugin)` adds the plugin",
181
+ "2. **Activate** — `PluginManager.activate(name, context)` calls `plugin.activate()`",
182
+ "3. **Dispatch** — `PluginManager.dispatch(hook, data)` chains through active plugins",
183
+ "4. **Deactivate** — `PluginManager.deactivate(name)` calls `plugin.deactivate()`",
184
+ "",
185
+ ])
186
+
187
+ return "\n".join(lines)
188
+
189
+
190
+ def generate_bridge_reference() -> str:
191
+ """Generate Markdown documentation for the bridge protocol."""
192
+ from semantic_code_intelligence.bridge.protocol import (
193
+ AgentRequest,
194
+ AgentResponse,
195
+ BridgeCapabilities,
196
+ RequestKind,
197
+ )
198
+
199
+ lines: list[str] = [
200
+ "# Bridge Protocol Reference",
201
+ "",
202
+ "Auto-generated from the CodexA agent cooperation protocol.",
203
+ "",
204
+ "## Overview",
205
+ "",
206
+ "CodexA exposes a stateless JSON/HTTP bridge (`codexa serve`) that any",
207
+ "IDE extension or AI assistant can use to request context.",
208
+ "",
209
+ "## Endpoints",
210
+ "",
211
+ "| Method | Path | Description |",
212
+ "|--------|------|-------------|",
213
+ "| GET | `/` | Capabilities manifest |",
214
+ "| GET | `/health` | Health check |",
215
+ "| POST | `/request` | Handle an AgentRequest |",
216
+ "| OPTIONS | `*` | CORS preflight |",
217
+ "",
218
+ "## Request Kinds",
219
+ "",
220
+ f"The bridge supports **{len(RequestKind)}** request types:",
221
+ "",
222
+ "| Kind | Value |",
223
+ "|------|-------|",
224
+ ]
225
+
226
+ for kind in RequestKind:
227
+ lines.append(f"| `{kind.name}` | `{kind.value}` |")
228
+
229
+ lines.extend([
230
+ "",
231
+ "## AgentRequest",
232
+ "",
233
+ "```json",
234
+ "{",
235
+ ' "kind": "semantic_search",',
236
+ ' "params": {"query": "authentication", "top_k": 5},',
237
+ ' "request_id": "req-001",',
238
+ ' "source": "copilot"',
239
+ "}",
240
+ "```",
241
+ "",
242
+ "| Field | Type | Description |",
243
+ "|-------|------|-------------|",
244
+ "| `kind` | `string` | One of the RequestKind values |",
245
+ "| `params` | `object` | Operation-specific parameters |",
246
+ "| `request_id` | `string` | Caller-assigned correlation ID |",
247
+ "| `source` | `string` | Identifier of calling agent |",
248
+ "",
249
+ "## AgentResponse",
250
+ "",
251
+ "```json",
252
+ "{",
253
+ ' "success": true,',
254
+ ' "data": {"snippets": [...]},',
255
+ ' "error": "",',
256
+ ' "request_id": "req-001",',
257
+ ' "elapsed_ms": 42.5',
258
+ "}",
259
+ "```",
260
+ "",
261
+ "| Field | Type | Description |",
262
+ "|-------|------|-------------|",
263
+ "| `success` | `boolean` | Whether the request succeeded |",
264
+ "| `data` | `object` | Structured response payload |",
265
+ "| `error` | `string` | Error message if success is false |",
266
+ "| `request_id` | `string` | Echoed correlation ID |",
267
+ "| `elapsed_ms` | `number` | Processing time in milliseconds |",
268
+ "",
269
+ ])
270
+
271
+ return "\n".join(lines)
272
+
273
+
274
+ def generate_tool_reference() -> str:
275
+ """Generate Markdown documentation for the tool registry."""
276
+ from semantic_code_intelligence.tools import TOOL_DEFINITIONS
277
+
278
+ tools = TOOL_DEFINITIONS
279
+
280
+ lines: list[str] = [
281
+ "# Tool Registry Reference",
282
+ "",
283
+ "Auto-generated from the CodexA tool-calling interface.",
284
+ "",
285
+ "These tools provide a structured JSON interface for LLM agents.",
286
+ "",
287
+ f"**{len(tools)} tools available:**",
288
+ "",
289
+ "| Tool | Description |",
290
+ "|------|-------------|",
291
+ ]
292
+
293
+ for tool in tools:
294
+ desc = tool.get("description", "")
295
+ lines.append(f"| `{tool['name']}` | {desc} |")
296
+
297
+ lines.extend([
298
+ "",
299
+ "## Usage",
300
+ "",
301
+ "```python",
302
+ "from semantic_code_intelligence.tools import ToolRegistry",
303
+ "",
304
+ 'registry = ToolRegistry(project_root="/path/to/repo")',
305
+ 'result = registry.call("search", {"query": "auth"})',
306
+ "print(result.to_json())",
307
+ "```",
308
+ "",
309
+ ])
310
+
311
+ return "\n".join(lines)
312
+
313
+
314
+ def generate_web_reference() -> str:
315
+ """Generate Markdown documentation for the Web API and visualization layer."""
316
+ lines: list[str] = [
317
+ "# Web Interface Reference",
318
+ "",
319
+ "Auto-generated from the CodexA web module.",
320
+ "",
321
+ "## Overview",
322
+ "",
323
+ "CodexA ships an **optional** lightweight web interface (`codexa web`) that",
324
+ "bundles a REST API and a browser UI on a single port (default 8080).",
325
+ "No external frameworks are required — the server uses Python's `http.server`.",
326
+ "",
327
+ "## REST API Endpoints",
328
+ "",
329
+ "| Method | Path | Description |",
330
+ "|--------|------|-------------|",
331
+ "| GET | `/health` | Server health / project metadata |",
332
+ "| GET | `/api/search?q=&top_k=&threshold=` | Semantic code search |",
333
+ "| GET | `/api/symbols?file=&kind=` | Symbol table browser |",
334
+ "| GET | `/api/deps?file=` | File dependency graph |",
335
+ "| GET | `/api/callgraph?symbol=` | Call graph edges |",
336
+ "| GET | `/api/summary` | Project summary |",
337
+ "| POST | `/api/ask` | Ask a natural-language question |",
338
+ "| POST | `/api/analyze` | Validate or explain a code snippet |",
339
+ "",
340
+ "### POST `/api/ask` body",
341
+ "",
342
+ "```json",
343
+ "{",
344
+ ' "question": "How does authentication work?",',
345
+ ' "top_k": 5',
346
+ "}",
347
+ "```",
348
+ "",
349
+ "### POST `/api/analyze` body",
350
+ "",
351
+ "```json",
352
+ "{",
353
+ ' "code": "def hello(): ...",',
354
+ ' "mode": "validate"',
355
+ "}",
356
+ "```",
357
+ "",
358
+ "## Visualization (Mermaid)",
359
+ "",
360
+ "The `codexa viz` command and `/api/viz/{kind}` endpoint produce",
361
+ "Mermaid-compatible diagram source text.",
362
+ "",
363
+ "| Kind | Description |",
364
+ "|------|-------------|",
365
+ "| `callgraph` | Caller → callee flowchart |",
366
+ "| `deps` | File dependency flowchart |",
367
+ "| `symbols` | Class diagram of symbols |",
368
+ "| `workspace` | Hub-and-spoke project map |",
369
+ "",
370
+ "### Example output",
371
+ "",
372
+ "````mermaid",
373
+ "flowchart LR",
374
+ ' main["main"] --> auth["auth"]',
375
+ ' auth["auth"] --> db["db"]',
376
+ "````",
377
+ "",
378
+ "## Web UI Pages",
379
+ "",
380
+ "| Path | Page |",
381
+ "|------|------|",
382
+ "| `/` | Search interface |",
383
+ "| `/symbols` | Symbol browser |",
384
+ "| `/workspace` | Project overview |",
385
+ "| `/viz` | Visualization viewer |",
386
+ "",
387
+ "The UI is server-rendered HTML with inline CSS (dark theme) and",
388
+ "vanilla JavaScript — no build step or npm required.",
389
+ "",
390
+ "## CLI Commands",
391
+ "",
392
+ "- `codexa web [--host HOST] [--port PORT] [--path PATH]` — start the web server",
393
+ "- `codexa viz KIND [--target T] [--output FILE] [--json] [--path PATH]` — generate a diagram",
394
+ "",
395
+ ]
396
+
397
+ return "\n".join(lines)
398
+
399
+
400
+ def generate_ci_reference() -> str:
401
+ """Generate Markdown documentation for the CI/CD integration layer."""
402
+ lines: list[str] = [
403
+ "# CI/CD Integration Reference",
404
+ "",
405
+ "Auto-generated from the CodexA CI module.",
406
+ "",
407
+ "## Overview",
408
+ "",
409
+ "CodexA provides optional CI/CD integration for contribution safety and",
410
+ "quality assurance. All outputs are **advisory** — CodexA never modifies",
411
+ "repository code automatically.",
412
+ "",
413
+ "## Quality Analyzers",
414
+ "",
415
+ "| Analyzer | Description |",
416
+ "|----------|-------------|",
417
+ "| Cyclomatic complexity | Counts decision points per function/method |",
418
+ "| Dead code detection | Identifies unreferenced symbols via call graph |",
419
+ "| Duplicate logic | Trigram Jaccard similarity between function bodies |",
420
+ "| Safety validation | 17 dangerous-pattern checks (existing validator) |",
421
+ "",
422
+ "### Quality Report Format (JSON)",
423
+ "",
424
+ "```json",
425
+ "{",
426
+ ' "files_analyzed": 42,',
427
+ ' "symbol_count": 180,',
428
+ ' "issue_count": 3,',
429
+ ' "complexity_issues": [{"symbol_name": "...", "complexity": 15, "rating": "high"}],',
430
+ ' "dead_code": [{"symbol_name": "...", "kind": "function", "file_path": "..."}],',
431
+ ' "duplicates": [{"symbol_a": "...", "symbol_b": "...", "similarity": 0.82}],',
432
+ ' "safety": {"safe": true, "issues": []}',
433
+ "}",
434
+ "```",
435
+ "",
436
+ "## PR Intelligence",
437
+ "",
438
+ "| Feature | Description |",
439
+ "|---------|-------------|",
440
+ "| Change summary | File-level and symbol-level diff analysis |",
441
+ "| Impact analysis | Blast radius via call graph traversal |",
442
+ "| Suggested reviewers | Domain-based reviewer assignment |",
443
+ "| Risk scoring | 0-100 composite risk with level (low/medium/high/critical) |",
444
+ "",
445
+ "### Risk Factors",
446
+ "",
447
+ "- Changeset size (file count)",
448
+ "- Symbol removals and modifications",
449
+ "- Safety issues in changed code",
450
+ "- Blast radius (affected downstream symbols)",
451
+ "",
452
+ "## CI Workflow Templates",
453
+ "",
454
+ "Generate with `codexa ci-gen <template>`:",
455
+ "",
456
+ "| Template | Description |",
457
+ "|----------|-------------|",
458
+ "| `analysis` | Full analysis workflow (quality + PR summary) |",
459
+ "| `safety` | Lightweight safety-only workflow |",
460
+ "| `precommit` | Pre-commit hook configuration |",
461
+ "",
462
+ "## Pre-Commit Hooks",
463
+ "",
464
+ "CodexA supports optional pre-commit validation:",
465
+ "",
466
+ "1. Safety validation — scans for dangerous patterns",
467
+ "2. Plugin hooks — dispatches `CUSTOM_VALIDATION` for user-defined rules",
468
+ "",
469
+ "## CLI Commands",
470
+ "",
471
+ "- `codexa quality [--json] [--safety-only] [--complexity-threshold N] [--pipe]`",
472
+ "- `codexa metrics [--json] [--snapshot] [--history N] [--trend] [--pipe]`",
473
+ "- `codexa gate [--json] [--strict] [--min-maintainability F] [--max-complexity N] [--pipe]`",
474
+ "- `codexa pr-summary [--json] [-f FILE ...] [--pipe]`",
475
+ "- `codexa ci-gen {analysis|safety|precommit} [-o FILE] [--python-version VER]`",
476
+ "",
477
+ ]
478
+
479
+ return "\n".join(lines)
480
+
481
+
482
+ def generate_quality_metrics_reference() -> str:
483
+ """Generate Markdown documentation for Phase 17 quality metrics features."""
484
+ lines: list[str] = [
485
+ "# Quality Metrics & Trends Reference",
486
+ "",
487
+ "Auto-generated documentation for CodexA's quality metrics, trend tracking,",
488
+ "and quality gate enforcement features.",
489
+ "",
490
+ "## Maintainability Index",
491
+ "",
492
+ "CodexA computes a per-file and project-wide maintainability index (0-100)",
493
+ "based on a simplified Software Engineering Institute (SEI) formula:",
494
+ "",
495
+ "- **Lines of code** — penalises overly large files",
496
+ "- **Cyclomatic complexity** — penalises deeply nested logic",
497
+ "- **Comment ratio** — rewards well-documented code",
498
+ "",
499
+ "| MI Range | Rating |",
500
+ "|----------|--------|",
501
+ "| 65-100 | Good (easy to maintain) |",
502
+ "| 40-64 | Moderate |",
503
+ "| 0-39 | Poor (difficult to maintain) |",
504
+ "",
505
+ "## Quality Snapshots",
506
+ "",
507
+ "Save point-in-time quality metrics via `codexa metrics --snapshot`.",
508
+ "Snapshots are stored in `.codexa/memory.json` and include:",
509
+ "",
510
+ "- Maintainability index",
511
+ "- Lines of code",
512
+ "- Symbol count",
513
+ "- Issue count",
514
+ "- Avg complexity",
515
+ "- Comment ratio",
516
+ "- Timestamp and metadata",
517
+ "",
518
+ "## Trend Analysis",
519
+ "",
520
+ "Use `codexa metrics --trend` to compute directional trends from snapshots:",
521
+ "",
522
+ "| Metric Tracked | Higher is Better |",
523
+ "|---------------|-----------------|",
524
+ "| `maintainability_index` | Yes |",
525
+ "| `avg_complexity` | No |",
526
+ "| `issue_count` | No |",
527
+ "| `total_loc` | Yes |",
528
+ "",
529
+ "Trend direction: **improving**, **stable**, or **degrading**.",
530
+ "",
531
+ "## Quality Gates",
532
+ "",
533
+ "Enforce quality policies in CI pipelines with `codexa gate`.",
534
+ "",
535
+ "| Policy | Default | Description |",
536
+ "|--------|---------|-------------|",
537
+ "| `min_maintainability` | 40.0 | Minimum MI score |",
538
+ "| `max_complexity` | 25 | Maximum cyclomatic complexity |",
539
+ "| `max_issues` | 20 | Maximum total quality issues |",
540
+ "| `max_dead_code` | 15 | Maximum dead code symbols |",
541
+ "| `max_duplicates` | 10 | Maximum duplicate code pairs |",
542
+ "| `require_safety_pass` | true | Safety check must pass |",
543
+ "",
544
+ "Use `--strict` to exit with code 1 on failure (for CI).",
545
+ "",
546
+ "## CLI Commands",
547
+ "",
548
+ "```",
549
+ "codexa metrics # Current metrics",
550
+ "codexa metrics --snapshot --json # Save snapshot, JSON output",
551
+ "codexa metrics --history 10 # Last 10 snapshots",
552
+ "codexa metrics --trend # Trend analysis",
553
+ "codexa gate --strict # CI quality gate",
554
+ "codexa gate --min-maintainability 60 # Custom threshold",
555
+ "```",
556
+ "",
557
+ "## Configuration",
558
+ "",
559
+ "Quality settings in `.codexa/config.json`:",
560
+ "",
561
+ "```json",
562
+ '{',
563
+ ' "quality": {',
564
+ ' "complexity_threshold": 10,',
565
+ ' "min_maintainability": 40.0,',
566
+ ' "max_issues": 20,',
567
+ ' "snapshot_on_index": false,',
568
+ ' "history_limit": 50',
569
+ ' }',
570
+ '}',
571
+ "```",
572
+ "",
573
+ ]
574
+ return "\n".join(lines)
575
+
576
+
577
+ def generate_ai_workflows_reference() -> str:
578
+ """Generate Markdown documentation for Phase 16 AI workflow features."""
579
+ lines: list[str] = [
580
+ "# AI Workflows Reference",
581
+ "",
582
+ "Auto-generated documentation for CodexA's advanced AI workflow features.",
583
+ "",
584
+ "## Multi-Turn Conversations",
585
+ "",
586
+ "Use `codexa chat` for persistent multi-turn conversations about your codebase.",
587
+ "",
588
+ "| Option | Description |",
589
+ "|--------|-------------|",
590
+ "| `--session <id>` | Resume an existing conversation |",
591
+ "| `--list-sessions` | Show all stored sessions |",
592
+ "| `--max-turns <n>` | Context window limit (default: 20) |",
593
+ "| `--json` | JSON output |",
594
+ "| `--pipe` | Machine-readable output |",
595
+ "",
596
+ "### Session Persistence",
597
+ "",
598
+ "Sessions are stored in `.codexa/sessions/<id>.json` with full message history.",
599
+ "Each session tracks: session_id, title, messages, created_at, updated_at.",
600
+ "",
601
+ "### API",
602
+ "",
603
+ "| Class | Method | Description |",
604
+ "|-------|--------|-------------|",
605
+ "| `ConversationSession` | `add_user(content)` | Add user message |",
606
+ "| `ConversationSession` | `add_assistant(content)` | Add assistant response |",
607
+ "| `ConversationSession` | `get_messages_for_llm(max_turns)` | Get context-windowed messages |",
608
+ "| `SessionStore` | `save(session)` | Persist to disk |",
609
+ "| `SessionStore` | `load(session_id)` | Load from disk |",
610
+ "| `SessionStore` | `list_sessions()` | List all sessions |",
611
+ "| `SessionStore` | `delete(session_id)` | Remove a session |",
612
+ "| `SessionStore` | `get_or_create(session_id)` | Resume or create |",
613
+ "",
614
+ "---",
615
+ "",
616
+ "## Autonomous Investigation Chains",
617
+ "",
618
+ "Use `codexa investigate` for multi-step autonomous code exploration.",
619
+ "",
620
+ "| Option | Description |",
621
+ "|--------|-------------|",
622
+ "| `--max-steps <n>` | Step limit (default: 6) |",
623
+ "| `--json` | JSON output |",
624
+ "| `--pipe` | Machine-readable output |",
625
+ "",
626
+ "### How It Works",
627
+ "",
628
+ "1. The LLM planner receives the user's question",
629
+ "2. It decides an action: `search`, `analyze`, `deps`, or `conclude`",
630
+ "3. The action is executed and results fed back to the planner",
631
+ "4. Loop continues until `conclude` or step limit is reached",
632
+ "",
633
+ "### Investigation Actions",
634
+ "",
635
+ "| Action | Description |",
636
+ "|--------|-------------|",
637
+ "| `search` | Semantic search over the codebase |",
638
+ "| `analyze` | Symbol lookup and context analysis |",
639
+ "| `deps` | Dependency analysis for a file |",
640
+ "| `conclude` | Final answer delivery |",
641
+ "",
642
+ "---",
643
+ "",
644
+ "## Cross-Repo Refactoring",
645
+ "",
646
+ "Use `codexa cross-refactor` to find duplicate logic across workspace repos.",
647
+ "",
648
+ "| Option | Description |",
649
+ "|--------|-------------|",
650
+ "| `--threshold <f>` | Similarity threshold (default: 0.70) |",
651
+ "| `--json` | JSON output |",
652
+ "| `--pipe` | Machine-readable output |",
653
+ "",
654
+ "### Analysis Pipeline",
655
+ "",
656
+ "1. Collect symbols from all registered workspace repositories",
657
+ "2. Compare function/method bodies using trigram Jaccard similarity",
658
+ "3. Only cross-repo matches are reported (not intra-repo)",
659
+ "4. If LLM is configured, generates actionable refactoring suggestions",
660
+ "",
661
+ "---",
662
+ "",
663
+ "## Streaming LLM Responses",
664
+ "",
665
+ "The `stream_chat()` function delivers tokens incrementally from any provider.",
666
+ "",
667
+ "### Supported Providers",
668
+ "",
669
+ "| Provider | Streaming Method |",
670
+ "|----------|-----------------|",
671
+ "| Ollama | Native HTTP streaming (`stream: true`) |",
672
+ "| OpenAI | Native streaming API (`stream=True`) |",
673
+ "| Mock | Word-by-word simulation |",
674
+ "| Other | Fallback single-token emit |",
675
+ "",
676
+ "### Plugin Integration",
677
+ "",
678
+ "The `PluginHook.ON_STREAM` hook is dispatched for each token event,",
679
+ "allowing plugins to monitor, transform, or log streaming output.",
680
+ "",
681
+ "### StreamEvent Types",
682
+ "",
683
+ "| Kind | Description |",
684
+ "|------|-------------|",
685
+ "| `start` | Stream initialization with provider metadata |",
686
+ "| `token` | A token of generated text |",
687
+ "| `done` | Stream completed successfully |",
688
+ "| `error` | An error occurred during streaming |",
689
+ "",
690
+ ]
691
+ return "\n".join(lines)
692
+
693
+
694
+ def generate_workflow_intelligence_reference() -> str:
695
+ """Generate the Workflow Intelligence reference document."""
696
+ lines = [
697
+ "# Workflow Intelligence Reference",
698
+ "",
699
+ "CodexA provides three developer workflow intelligence tools that combine",
700
+ "static analysis, call-graph traversal, dependency mapping, and optional",
701
+ "git history to surface actionable insights about your codebase.",
702
+ "",
703
+ "---",
704
+ "",
705
+ "## Hotspot Detection (`codexa hotspots`)",
706
+ "",
707
+ "Identifies high-risk code areas using a weighted multi-factor heuristic.",
708
+ "",
709
+ "### Factors",
710
+ "",
711
+ "| Factor | Default Weight | Description |",
712
+ "|--------|---------------|-------------|",
713
+ "| Complexity | 0.30 | Cyclomatic complexity of the symbol body |",
714
+ "| Duplication | 0.20 | Duplicate line density in the containing file |",
715
+ "| Fan-in | 0.15 | Number of callers (call graph in-degree) |",
716
+ "| Fan-out | 0.15 | Number of callees (call graph out-degree) |",
717
+ "| Churn | 0.20 | Git change frequency (commits touching the file) |",
718
+ "",
719
+ "When git data is unavailable the churn weight is redistributed equally",
720
+ "across the remaining four factors.",
721
+ "",
722
+ "### CLI Options",
723
+ "",
724
+ "| Option | Description |",
725
+ "|--------|-------------|",
726
+ "| `--path / -p` | Project root (default: `.`) |",
727
+ "| `--top-n / -n` | Number of hotspots to report (default: 20) |",
728
+ "| `--include-git / --no-git` | Toggle git churn analysis |",
729
+ "| `--json` | JSON output |",
730
+ "| `--pipe` | Machine-readable plain text |",
731
+ "",
732
+ "### API",
733
+ "",
734
+ "| Function | Description |",
735
+ "|----------|-------------|",
736
+ "| `analyze_hotspots(symbols, call_graph, dep_map, root, *, top_n, include_git, weights)` | Run full hotspot analysis |",
737
+ "",
738
+ "### Plugin Hooks",
739
+ "",
740
+ "| Hook | When |",
741
+ "|------|------|",
742
+ "| `PRE_HOTSPOT_ANALYSIS` | Before hotspot scoring begins |",
743
+ "| `POST_HOTSPOT_ANALYSIS` | After the hotspot report is built |",
744
+ "",
745
+ "---",
746
+ "",
747
+ "## Impact Analysis (`codexa impact <target>`)",
748
+ "",
749
+ "Predicts the blast radius of modifying a symbol or file using BFS over",
750
+ "the call graph and dependency map.",
751
+ "",
752
+ "### How It Works",
753
+ "",
754
+ "1. Resolve the target to symbols or a file path",
755
+ "2. Seed the BFS queue with the target's names and files",
756
+ "3. Walk callers in the call graph (direct → transitive)",
757
+ "4. Walk importers in the dependency map",
758
+ "5. Build dependency chains tracing paths back to the target",
759
+ "",
760
+ "### CLI Options",
761
+ "",
762
+ "| Option | Description |",
763
+ "|--------|-------------|",
764
+ "| `TARGET` | Symbol name or relative file path |",
765
+ "| `--path / -p` | Project root (default: `.`) |",
766
+ "| `--max-depth / -d` | BFS depth limit (default: 5) |",
767
+ "| `--json` | JSON output |",
768
+ "| `--pipe` | Machine-readable plain text |",
769
+ "",
770
+ "### API",
771
+ "",
772
+ "| Function | Description |",
773
+ "|----------|-------------|",
774
+ "| `analyze_impact(target, symbols, call_graph, dep_map, root, *, max_depth)` | Run impact analysis |",
775
+ "",
776
+ "### Plugin Hooks",
777
+ "",
778
+ "| Hook | When |",
779
+ "|------|------|",
780
+ "| `PRE_IMPACT_ANALYSIS` | Before impact BFS begins |",
781
+ "| `POST_IMPACT_ANALYSIS` | After the impact report is built |",
782
+ "",
783
+ "---",
784
+ "",
785
+ "## Symbol Trace (`codexa trace <symbol>`)",
786
+ "",
787
+ "Traces execution relationships upstream (callers) and downstream (callees)",
788
+ "to visualise call flow through the codebase.",
789
+ "",
790
+ "### How It Works",
791
+ "",
792
+ "1. Resolve the target symbol",
793
+ "2. BFS upstream: walk `callers_of` edges to find all transitive callers",
794
+ "3. BFS downstream: walk `callees_of` edges to find all transitive callees",
795
+ "4. Collect trace edges connecting the nodes",
796
+ "",
797
+ "### CLI Options",
798
+ "",
799
+ "| Option | Description |",
800
+ "|--------|-------------|",
801
+ "| `SYMBOL` | Symbol name to trace |",
802
+ "| `--path / -p` | Project root (default: `.`) |",
803
+ "| `--max-depth / -d` | BFS depth limit (default: 5) |",
804
+ "| `--json` | JSON output |",
805
+ "| `--pipe` | Machine-readable plain text |",
806
+ "",
807
+ "### API",
808
+ "",
809
+ "| Function | Description |",
810
+ "|----------|-------------|",
811
+ "| `trace_symbol(target, symbols, call_graph, *, max_depth)` | Run symbol trace |",
812
+ "",
813
+ "### Plugin Hooks",
814
+ "",
815
+ "| Hook | When |",
816
+ "|------|------|",
817
+ "| `PRE_TRACE` | Before trace BFS begins |",
818
+ "| `POST_TRACE` | After the trace result is built |",
819
+ "",
820
+ "---",
821
+ "",
822
+ "## Output Formats",
823
+ "",
824
+ "All three commands support three output modes:",
825
+ "",
826
+ "| Flag | Format | Use Case |",
827
+ "|------|--------|----------|",
828
+ "| *(none)* | Rich terminal | Interactive development |",
829
+ "| `--json` | Pretty JSON | Programmatic consumption |",
830
+ "| `--pipe` | Tab-separated text | Shell pipelines and CI |",
831
+ "",
832
+ "---",
833
+ "",
834
+ "## Data Classes",
835
+ "",
836
+ "### Hotspots",
837
+ "",
838
+ "| Class | Fields |",
839
+ "|-------|--------|",
840
+ "| `HotspotFactor` | `name`, `raw_value`, `normalized`, `weight` |",
841
+ "| `Hotspot` | `name`, `file_path`, `kind`, `risk_score`, `factors` |",
842
+ "| `HotspotReport` | `files_analyzed`, `symbols_analyzed`, `hotspots` |",
843
+ "",
844
+ "### Impact",
845
+ "",
846
+ "| Class | Fields |",
847
+ "|-------|--------|",
848
+ "| `AffectedSymbol` | `name`, `file_path`, `kind`, `relationship`, `depth` |",
849
+ "| `AffectedModule` | `file_path`, `relationship`, `depth` |",
850
+ "| `DependencyChain` | `path` (list of strings) |",
851
+ "| `ImpactReport` | `target`, `target_kind`, `direct_symbols`, `transitive_symbols`, `affected_modules`, `chains` |",
852
+ "",
853
+ "### Trace",
854
+ "",
855
+ "| Class | Fields |",
856
+ "|-------|--------|",
857
+ "| `TraceNode` | `name`, `file_path`, `kind`, `depth` |",
858
+ "| `TraceEdge` | `caller`, `callee`, `file_path` |",
859
+ "| `TraceResult` | `target`, `target_file`, `upstream`, `downstream`, `edges` |",
860
+ "",
861
+ ]
862
+ return "\n".join(lines)
863
+
864
+
865
+ # ---------------------------------------------------------------------------
866
+ # AI Tool Protocol Reference (Phase 19)
867
+ # ---------------------------------------------------------------------------
868
+
869
+
870
+ def generate_ai_tool_protocol_reference() -> str:
871
+ """Generate AI_TOOL_PROTOCOL.md documentation."""
872
+ from semantic_code_intelligence.tools import TOOL_DEFINITIONS
873
+ from semantic_code_intelligence.tools.protocol import (
874
+ ToolErrorCode,
875
+ ToolExecutionResult,
876
+ ToolInvocation,
877
+ ToolError,
878
+ )
879
+
880
+ lines = [
881
+ "# AI Tool Protocol Reference",
882
+ "",
883
+ "This document describes the AI Agent Tooling Protocol introduced in",
884
+ "**Phase 19** of CodexA. It enables AI coding agents to invoke CodexA",
885
+ "tools via structured JSON requests and receive typed results.",
886
+ "",
887
+ "## Overview",
888
+ "",
889
+ "The protocol provides three layers:",
890
+ "",
891
+ "1. **Tool Invocation Protocol** — typed request/response dataclasses",
892
+ "2. **Tool Execution Engine** — validates, routes, and executes tools",
893
+ "3. **Bridge HTTP Endpoints** — REST + SSE for external agents",
894
+ "",
895
+ "## Protocol Dataclasses",
896
+ "",
897
+ "### ToolInvocation",
898
+ "",
899
+ "| Field | Type | Description |",
900
+ "|-------|------|-------------|",
901
+ "| `tool_name` | `str` | Name of the tool to invoke |",
902
+ "| `arguments` | `dict` | Key-value arguments |",
903
+ "| `request_id` | `str` | Correlation ID (auto-generated) |",
904
+ "| `timestamp` | `float` | Unix timestamp |",
905
+ "",
906
+ "### ToolExecutionResult",
907
+ "",
908
+ "| Field | Type | Description |",
909
+ "|-------|------|-------------|",
910
+ "| `tool_name` | `str` | Tool that was executed |",
911
+ "| `request_id` | `str` | Correlation ID |",
912
+ "| `success` | `bool` | Whether execution succeeded |",
913
+ "| `result_payload` | `dict` | Output data (success only) |",
914
+ "| `error` | `ToolError` | Error details (failure only) |",
915
+ "| `execution_time_ms` | `float` | Execution time |",
916
+ "",
917
+ "### ToolError",
918
+ "",
919
+ "| Field | Type | Description |",
920
+ "|-------|------|-------------|",
921
+ "| `tool_name` | `str` | Tool that failed |",
922
+ "| `error_code` | `str` | Machine-readable code |",
923
+ "| `error_message` | `str` | Human-readable message |",
924
+ "| `request_id` | `str` | Correlation ID |",
925
+ "",
926
+ "### Error Codes",
927
+ "",
928
+ "| Code | Meaning |",
929
+ "|------|---------|",
930
+ ]
931
+ for code in ToolErrorCode:
932
+ lines.append(f"| `{code.value}` | {code.name.replace('_', ' ').title()} |")
933
+
934
+ lines.extend([
935
+ "",
936
+ "## Available Tools",
937
+ "",
938
+ "| Tool | Description |",
939
+ "|------|-------------|",
940
+ ])
941
+ for t in TOOL_DEFINITIONS:
942
+ lines.append(f"| `{t['name']}` | {t['description'][:80]} |")
943
+
944
+ lines.extend([
945
+ "",
946
+ "## HTTP Endpoints",
947
+ "",
948
+ "| Method | Path | Description |",
949
+ "|--------|------|-------------|",
950
+ "| `POST` | `/tools/invoke` | Execute a tool invocation |",
951
+ "| `GET` | `/tools/list` | List available tools |",
952
+ "| `GET` | `/tools/stream` | SSE stream of tool events |",
953
+ "| `POST` | `/request` | Legacy bridge request (supports `invoke_tool`, `list_tools` kinds) |",
954
+ "",
955
+ "## CLI Usage",
956
+ "",
957
+ "```",
958
+ "codexa tool list # list all tools",
959
+ "codexa tool run <name> --arg key=value",
960
+ "codexa tool schema <name> # show tool schema",
961
+ "```",
962
+ "",
963
+ "## Plugin Tool Registration",
964
+ "",
965
+ "Plugins can register custom tools via the `REGISTER_TOOL` hook:",
966
+ "",
967
+ "```python",
968
+ 'def on_hook(self, hook, data):',
969
+ ' if hook == PluginHook.REGISTER_TOOL:',
970
+ ' data["tools"].append({',
971
+ ' "name": "my_tool",',
972
+ ' "description": "My custom tool",',
973
+ ' "parameters": {"input": {"type": "string", "required": True}},',
974
+ ' "handler": my_handler_function,',
975
+ ' })',
976
+ ' return data',
977
+ "```",
978
+ "",
979
+ "## Safety Guardrails",
980
+ "",
981
+ "- Tools are deterministic and read-only (no code execution)",
982
+ "- All arguments are validated against declared schemas",
983
+ "- Plugin tools cannot overwrite built-in tool names",
984
+ "- Error codes are typed for reliable machine parsing",
985
+ "",
986
+ ])
987
+ return "\n".join(lines)
988
+
989
+
990
+ def generate_all_docs(output_dir: Path) -> list[str]:
991
+ """Generate all documentation files into the output directory.
992
+
993
+ Returns:
994
+ List of generated file paths (relative to output_dir).
995
+ """
996
+ output_dir.mkdir(parents=True, exist_ok=True)
997
+ generated: list[str] = []
998
+
999
+ # CLI reference needs the actual CLI group
1000
+ try:
1001
+ from semantic_code_intelligence.cli.main import cli
1002
+ cli_md = generate_cli_reference(cli)
1003
+ (output_dir / "CLI.md").write_text(cli_md, encoding="utf-8")
1004
+ generated.append("CLI.md")
1005
+ except Exception:
1006
+ logger.debug("Failed to generate CLI.md")
1007
+
1008
+ # Plugin reference
1009
+ try:
1010
+ plugin_md = generate_plugin_reference()
1011
+ (output_dir / "PLUGINS.md").write_text(plugin_md, encoding="utf-8")
1012
+ generated.append("PLUGINS.md")
1013
+ except Exception:
1014
+ logger.debug("Failed to generate PLUGINS.md")
1015
+
1016
+ # Bridge reference
1017
+ try:
1018
+ bridge_md = generate_bridge_reference()
1019
+ (output_dir / "BRIDGE.md").write_text(bridge_md, encoding="utf-8")
1020
+ generated.append("BRIDGE.md")
1021
+ except Exception:
1022
+ logger.debug("Failed to generate BRIDGE.md")
1023
+
1024
+ # Tool reference
1025
+ try:
1026
+ tool_md = generate_tool_reference()
1027
+ (output_dir / "TOOLS.md").write_text(tool_md, encoding="utf-8")
1028
+ generated.append("TOOLS.md")
1029
+ except Exception:
1030
+ logger.debug("Failed to generate TOOLS.md")
1031
+
1032
+ # Web / API reference
1033
+ try:
1034
+ web_md = generate_web_reference()
1035
+ (output_dir / "WEB.md").write_text(web_md, encoding="utf-8")
1036
+ generated.append("WEB.md")
1037
+ except Exception:
1038
+ logger.debug("Failed to generate WEB.md")
1039
+
1040
+ # CI/CD reference
1041
+ try:
1042
+ ci_md = generate_ci_reference()
1043
+ (output_dir / "CI.md").write_text(ci_md, encoding="utf-8")
1044
+ generated.append("CI.md")
1045
+ except Exception:
1046
+ logger.debug("Failed to generate CI.md")
1047
+
1048
+ # AI Workflows reference
1049
+ try:
1050
+ ai_md = generate_ai_workflows_reference()
1051
+ (output_dir / "AI_WORKFLOWS.md").write_text(ai_md, encoding="utf-8")
1052
+ generated.append("AI_WORKFLOWS.md")
1053
+ except Exception:
1054
+ logger.debug("Failed to generate AI_WORKFLOWS.md")
1055
+
1056
+ # Quality Metrics reference
1057
+ try:
1058
+ qm_md = generate_quality_metrics_reference()
1059
+ (output_dir / "QUALITY_METRICS.md").write_text(qm_md, encoding="utf-8")
1060
+ generated.append("QUALITY_METRICS.md")
1061
+ except Exception:
1062
+ logger.debug("Failed to generate QUALITY_METRICS.md")
1063
+
1064
+ # Workflow Intelligence reference
1065
+ try:
1066
+ wi_md = generate_workflow_intelligence_reference()
1067
+ (output_dir / "WORKFLOW_INTELLIGENCE.md").write_text(wi_md, encoding="utf-8")
1068
+ generated.append("WORKFLOW_INTELLIGENCE.md")
1069
+ except Exception:
1070
+ logger.debug("Failed to generate WORKFLOW_INTELLIGENCE.md")
1071
+
1072
+ # AI Tool Protocol reference (Phase 19)
1073
+ try:
1074
+ atp_md = generate_ai_tool_protocol_reference()
1075
+ (output_dir / "AI_TOOL_PROTOCOL.md").write_text(atp_md, encoding="utf-8")
1076
+ generated.append("AI_TOOL_PROTOCOL.md")
1077
+ except Exception:
1078
+ logger.debug("Failed to generate AI_TOOL_PROTOCOL.md")
1079
+
1080
+ return generated