-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_config_docs.py
More file actions
428 lines (376 loc) Β· 13.3 KB
/
generate_config_docs.py
File metadata and controls
428 lines (376 loc) Β· 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/usr/bin/env python3
"""Generate real configuration documentation for all config/ stub files.
Replaces MANUAL_DOC_REVIEW_REQUIRED stubs with accurate config docs
based on source module __init__.py docstrings and os.getenv() calls.
"""
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
CONFIG_DIR = REPO_ROOT / "config"
SRC_DIR = REPO_ROOT / "src" / "codomyrmex"
# MODULE_META extracted to _config_module_meta.py for LOC budget compliance
from _config_module_meta import MODULE_META
def title_case(module_name: str) -> str:
"""Convert module_name to Title Case."""
words = module_name.replace("_", " ").split()
# Special cases
special = {
"ai": "AI",
"ci": "CI",
"cd": "CD",
"cli": "CLI",
"api": "API",
"ide": "IDE",
"io": "IO",
"ml": "ML",
"llm": "LLM",
"mcp": "MCP",
"ui": "UI",
"iot": "IoT",
"pdf": "PDF",
"rbac": "RBAC",
"rag": "RAG",
"fpf": "FPF",
"os": "OS",
"sql": "SQL",
"tts": "TTS",
"stt": "STT",
"ros2": "ROS2",
"oauth": "OAuth",
"yaml": "YAML",
"json": "JSON",
"csv": "CSV",
"xml": "XML",
"html": "HTML",
"http": "HTTP",
"s3": "S3",
"gcp": "GCP",
"aws": "AWS",
}
return " ".join(special.get(w.lower(), w.capitalize()) for w in words)
def generate_readme(module: str, meta: dict) -> str:
title = title_case(module)
desc = meta["desc"]
env_vars = meta["env_vars"]
mcp_tools = meta["mcp_tools"]
config_notes = meta["config_notes"]
lines = [
f"# {title} Configuration",
"",
"**Version**: v1.0.8 | **Status**: Active | **Last Updated**: March 2026",
"",
"## Overview",
"",
desc,
"",
]
# Quick Configuration
if env_vars:
lines.append("## Quick Configuration")
lines.append("")
lines.append("```bash")
for name, default, description in env_vars:
if default:
lines.append(f'export {name}="{default}" # {description}')
else:
lines.append(f'export {name}="" # {description} (required)')
lines.append("```")
lines.append("")
# Configuration Options table
lines.append("## Configuration Options")
lines.append("")
if env_vars:
lines.append("| Option | Type | Default | Description |")
lines.append("|--------|------|---------|-------------|")
for name, default, description in env_vars:
default_display = f"`{default}`" if default else "None"
lines.append(f"| `{name}` | str | {default_display} | {description} |")
else:
lines.append(
f"The {module} module operates with sensible defaults and does not require environment variable configuration. {config_notes}"
)
lines.append("")
# MCP Tools
if mcp_tools:
lines.append("## MCP Tools")
lines.append("")
lines.append(f"This module exposes {len(mcp_tools)} MCP tool(s):")
lines.append("")
for tool in mcp_tools:
lines.append(f"- `{tool}`")
lines.append("")
# PAI Integration
lines.append("## PAI Integration")
lines.append("")
if mcp_tools:
lines.append(
f"PAI agents invoke {module} tools through the MCP bridge. {config_notes}"
)
else:
lines.append(
f"PAI agents interact with {module} through direct Python imports. {config_notes}"
)
lines.append("")
# Validation
lines.append("## Validation")
lines.append("")
lines.append("```bash")
lines.append("# Verify module is available")
lines.append("codomyrmex modules | grep " + module)
lines.append("")
lines.append("# Run module health check")
lines.append("codomyrmex status")
lines.append("```")
lines.append("")
# Navigation
lines.append("## Navigation")
lines.append("")
lines.append(
f"- [Source Module](../../src/codomyrmex/{module}/README.md) | [AGENTS.md](AGENTS.md) | [SPEC.md](SPEC.md)"
)
lines.append("")
return "\n".join(lines)
def generate_agents(module: str, meta: dict) -> str:
title = title_case(module)
desc = meta["desc"]
env_vars = meta["env_vars"]
mcp_tools = meta["mcp_tools"]
config_notes = meta["config_notes"]
lines = [
f"# {title} -- Configuration Agent Coordination",
"",
"**Version**: v1.0.8 | **Status**: Active | **Last Updated**: March 2026",
"",
"## Overview",
"",
f"Agent coordination guide for configuring and using the {module} module. {desc.split('.')[0]}.",
"",
"## Configuration Requirements",
"",
f"Before using {module} in any PAI workflow, ensure:",
"",
]
if env_vars:
for i, (name, default, description) in enumerate(env_vars, 1):
if default:
lines.append(
f"{i}. `{name}` is set (default: `{default}`) -- {description}"
)
else:
lines.append(f"{i}. `{name}` is set -- {description}")
else:
lines.append(
f"1. The module is importable via `from codomyrmex.{module} import *`"
)
lines.append(
"2. Any optional dependencies are installed (check with `codomyrmex check`)"
)
lines.append("")
lines.append("## Agent Instructions")
lines.append("")
if env_vars:
lines.append(
f"1. Verify required environment variables are set before invoking {module} tools"
)
lines.append(
f'2. Use `get_config("{module}.<key>")` from config_management to read module settings'
)
else:
lines.append(
f"1. Import the module directly: `from codomyrmex.{module} import ...`"
)
lines.append(
"2. Check module availability with `list_modules()` from system_discovery"
)
if mcp_tools:
lines.append(
f"3. Available MCP tools: {', '.join(f'`{t}`' for t in mcp_tools)}"
)
else:
lines.append(
"3. This module has no auto-discovered MCP tools; use direct Python imports"
)
lines.append(f"4. {config_notes}")
lines.append("")
lines.append("## Operating Contracts")
lines.append("")
lines.append(
"- **Import Safety**: Module import does not trigger side effects or network calls"
)
lines.append(
"- **Error Handling**: All errors raise specific exceptions (never returns None silently)"
)
lines.append(
"- **Thread Safety**: Configuration reads are thread-safe after initialization"
)
lines.append("")
lines.append("## Configuration Patterns")
lines.append("")
lines.append("```python")
lines.append(
"from codomyrmex.config_management.mcp_tools import get_config, set_config"
)
lines.append("")
lines.append("# Read current configuration")
lines.append(f'value = get_config("{module}.setting")')
lines.append("")
lines.append("# Update configuration")
lines.append(f'set_config("{module}.setting", "new_value")')
lines.append("```")
lines.append("")
lines.append("## PAI Agent Role Access Matrix")
lines.append("")
lines.append("| PAI Agent | Config Access | Notes |")
lines.append("|-----------|--------------|-------|")
lines.append("| Engineer | Read/Write | Can update configuration during setup |")
lines.append("| Architect | Read | Reviews configuration for compliance |")
lines.append("| QATester | Read | Validates configuration before test runs |")
lines.append("| Researcher | Read | No configuration changes |")
lines.append("")
lines.append("## Navigation")
lines.append("")
lines.append(
f"- [README.md](README.md) | [SPEC.md](SPEC.md) | [Source Module](../../src/codomyrmex/{module}/AGENTS.md)"
)
lines.append("")
return "\n".join(lines)
def generate_spec(module: str, meta: dict) -> str:
title = title_case(module)
desc = meta["desc"]
env_vars = meta["env_vars"]
config_notes = meta["config_notes"]
lines = [
f"# {title} Configuration Specification",
"",
"**Version**: v1.0.8 | **Status**: Active | **Last Updated**: March 2026",
"",
"## Overview",
"",
f"{desc} This specification documents the configuration schema and constraints.",
"",
"## Configuration Schema",
"",
]
if env_vars:
lines.append("| Key | Type | Required | Default | Description |")
lines.append("|-----|------|----------|---------|-------------|")
for name, default, description in env_vars:
required = "Yes" if not default else "No"
default_display = f"`{default}`" if default else "None"
lines.append(
f"| `{name}` | string | {required} | {default_display} | {description} |"
)
lines.append("")
lines.append("## Environment Variables")
lines.append("")
lines.append("```bash")
required = [(n, d, desc) for n, d, desc in env_vars if not d]
optional = [(n, d, desc) for n, d, desc in env_vars if d]
if required:
lines.append("# Required")
for name, default, description in required:
lines.append(f'export {name}="" # {description}')
if optional:
if required:
lines.append("")
lines.append("# Optional (defaults shown)")
for name, default, description in optional:
lines.append(f'export {name}="{default}" # {description}')
lines.append("```")
else:
lines.append(
f"The {module} module does not require external configuration via environment variables. All settings are managed programmatically through constructor parameters and method arguments."
)
lines.append("")
lines.append("| Key | Type | Required | Default | Description |")
lines.append("|-----|------|----------|---------|-------------|")
lines.append(
f"| (programmatic) | varies | No | module defaults | {config_notes} |"
)
lines.append("")
lines.append("## Design Principles")
lines.append("")
lines.append(
"- **Centralized Config**: All settings accessible via config_management module"
)
lines.append(
"- **Env-First**: Environment variables take precedence over config file values"
)
lines.append(
"- **Explicit Defaults**: All optional settings have documented defaults"
)
lines.append(
"- **Zero-Mock**: No placeholder or fake configuration values in production"
)
lines.append("")
lines.append("## Constraints")
lines.append("")
if env_vars:
required_vars = [n for n, d, _ in env_vars if not d]
if required_vars:
for v in required_vars:
lines.append(f"- `{v}` must be set before module initialization")
else:
lines.append("- All configuration options have sensible defaults")
else:
lines.append(f"- {config_notes}")
lines.append(
"- Configuration is validated on first use; invalid values raise explicit errors"
)
lines.append("- No silent fallback to placeholder values")
lines.append("")
lines.append("## Dependencies")
lines.append("")
lines.append("**Depends on**: `config_management`, `environment_setup`")
lines.append("")
lines.append("## Navigation")
lines.append("")
lines.append(
f"- [README.md](README.md) | [AGENTS.md](AGENTS.md) | [Source Module](../../src/codomyrmex/{module}/SPEC.md)"
)
lines.append("")
return "\n".join(lines)
def has_stub(filepath: Path) -> bool:
"""Check if file contains the stub marker."""
if not filepath.exists():
return False
text = filepath.read_text()
return "MANUAL_DOC_REVIEW_REQUIRED" in text
def main():
total_written = 0
total_skipped = 0
errors = []
for module, meta in sorted(MODULE_META.items()):
config_module_dir = CONFIG_DIR / module
if not config_module_dir.exists():
errors.append(f"SKIP: config/{module}/ directory does not exist")
total_skipped += 1
continue
# README.md
readme_path = config_module_dir / "README.md"
if has_stub(readme_path):
readme_path.write_text(generate_readme(module, meta))
total_written += 1
else:
total_skipped += 1
# AGENTS.md
agents_path = config_module_dir / "AGENTS.md"
if has_stub(agents_path):
agents_path.write_text(generate_agents(module, meta))
total_written += 1
else:
total_skipped += 1
# SPEC.md
spec_path = config_module_dir / "SPEC.md"
if has_stub(spec_path):
spec_path.write_text(generate_spec(module, meta))
total_written += 1
else:
total_skipped += 1
print(f"Written: {total_written} files")
print(f"Skipped: {total_skipped} files (no stub marker or missing dir)")
if errors:
print(f"Errors: {len(errors)}")
for e in errors:
print(f" {e}")
if __name__ == "__main__":
main()