Skip to content

Commit b48da8c

Browse files
tbitcsoz-agent
andcommitted
docs: complete YAML governance coverage -- arch §28, readthedocs, yaml-governance page
- Add §28 YAML-Native Governance Layer to docs/ARCHITECTURE.md covering authority direction, sync pipeline, strict validation, generate docs, governance-mode flag, domain YAML file table, CI integration, migration script - Add docs/site/yaml-governance.md: full reference (authority model, domain files, YAML schema, CLI reference, migration, CI, Python API, troubleshooting) - Update docs/site/governance.md: add YAML-First Governance (v0.12+) section - Update docs/site/index.md: replace deprecated VS Code Extension section with Kairos recommended-client section; add yaml-governance.md to doc guide table - Stage previously unstaged: root ARCHITECTURE.md AI intel sections, README.md v0.12 YAML governance section, governance_yaml.py yaml_governance group, yaml_governance.yml REQ/TEST YAML files, machine state JSON Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 34c467b commit b48da8c

13 files changed

Lines changed: 929 additions & 22 deletions

File tree

.specsmith/requirements.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,5 +1797,40 @@
17971797
"description": "The Kairos Agents > Providers settings page MUST display bucket scores (reasoning, conversational, longform) retrieved from `GET /api/model-intel/scores/{model}` for each configured provider. Scores MUST be shown as compact numeric badges. A Sync button MUST call `POST /api/model-intel/sync`.",
17981798
"source": "ARCHITECTURE.md §20–21 [KAI-001]",
17991799
"status": "defined"
1800+
},
1801+
{
1802+
"id": "REQ-300",
1803+
"title": "YAML-First Governance Sync Pipeline",
1804+
"description": "When `.specsmith/governance-mode` contains `yaml`, `specsmith sync` MUST read docs/requirements/*.yml and docs/tests/*.yml as canonical sources, write .specsmith/requirements.json + testcases.json as JSON caches, and regenerate docs/REQUIREMENTS.md + docs/TESTS.md as derived artifacts. Legacy Markdown mode (governance-mode absent or `markdown`) MUST still work for backward compatibility.",
1805+
"source": "ARCHITECTURE.md §YAML-Native Governance Layer",
1806+
"status": "implemented"
1807+
},
1808+
{
1809+
"id": "REQ-301",
1810+
"title": "Strict Governance Schema Validation",
1811+
"description": "`specsmith validate --strict` MUST enforce 8 governance schema checks: (1) duplicate REQ IDs, (2) duplicate TEST IDs, (3) missing required REQ fields (id/title/status), (4) missing required TEST fields (id/title/requirement_id), (5) orphaned TESTs (reference non-existent REQ), (6) untested REQs (warning), (7) duplicate REQ titles (warning), (8) machine-state drift between YAML and JSON (warning). Exits 1 on errors; warnings do not block. `--json` flag emits structured output.",
1812+
"source": "ARCHITECTURE.md §YAML-Native Governance Layer",
1813+
"status": "implemented"
1814+
},
1815+
{
1816+
"id": "REQ-302",
1817+
"title": "Generate Docs Command Renders YAML to Markdown",
1818+
"description": "`specsmith generate docs` MUST read docs/requirements/*.yml and docs/tests/*.yml in YAML-first mode, render the canonical Markdown artifacts docs/REQUIREMENTS.md and docs/TESTS.md, and also re-sync the JSON machine state. `--check` flag MUST report what would change without writing. Only available when governance-mode is `yaml`.",
1819+
"source": "ARCHITECTURE.md §YAML-Native Governance Layer",
1820+
"status": "implemented"
1821+
},
1822+
{
1823+
"id": "REQ-303",
1824+
"title": "Governance Mode Flag Controls Authority Direction",
1825+
"description": "`.specsmith/governance-mode` MUST contain `yaml` to activate YAML-first mode. `is_yaml_mode(root)` in `specsmith.governance_yaml` reads this flag. Absence of the file or value `markdown` activates legacy Markdown-primary mode. The flag is written by `scripts/migrate_governance_to_yaml.py`.",
1826+
"source": "ARCHITECTURE.md §YAML-Native Governance Layer",
1827+
"status": "implemented"
1828+
},
1829+
{
1830+
"id": "REQ-304",
1831+
"title": "YAML Governance Migration Script",
1832+
"description": "`scripts/migrate_governance_to_yaml.py` MUST be idempotent and execute the following steps in order: (1) remove duplicate REQs from REQUIREMENTS.md, (2) re-sync .specsmith/ JSON from cleaned MD, (3) export JSON to grouped YAML files under docs/requirements/ and docs/tests/, (4) write .specsmith/governance-mode = yaml. Re-running must not corrupt the governance state.",
1833+
"source": "ARCHITECTURE.md §YAML-Native Governance Layer",
1834+
"status": "implemented"
18001835
}
18011836
]

.specsmith/testcases.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,5 +2858,60 @@
28582858
"input": {},
28592859
"expected_behavior": {},
28602860
"confidence": 1.0
2861+
},
2862+
{
2863+
"id": "TEST-300",
2864+
"title": "YAML-First Sync Reads YAML and Writes JSON + MD",
2865+
"description": "When `.specsmith/governance-mode` == `yaml` and docs/requirements/*.yml exist, `specsmith sync` reads from YAML files, writes .specsmith/ requirements.json + testcases.json, and regenerates docs/REQUIREMENTS.md + docs/TESTS.md. `specsmith sync --check` exits 0 after sync. In legacy mode (no governance-mode file), sync reads from REQUIREMENTS.md as before.",
2866+
"requirement_id": "REQ-300",
2867+
"type": "integration",
2868+
"verification_method": "pytest",
2869+
"input": "tmp_path with YAML files + governance-mode=yaml",
2870+
"expected_behavior": "JSON updated; REQUIREMENTS.md regenerated; sync --check exits 0",
2871+
"confidence": 1.0
2872+
},
2873+
{
2874+
"id": "TEST-301",
2875+
"title": "validate --strict Enforces All 8 Schema Checks",
2876+
"description": "`specsmith validate --strict --json` returns `{ok: true, strict_errors: 0}` on a clean project. When a duplicate REQ ID is injected, strict_errors > 0 and exit code is 1. When an untested REQ exists, strict_warnings > 0 but exit code is still 0. The `validate-strict` CI job runs this gate on every push.",
2877+
"requirement_id": "REQ-301",
2878+
"type": "cli",
2879+
"verification_method": "pytest",
2880+
"input": "specsmith validate --strict --json; inject duplicate REQ; inject untested REQ",
2881+
"expected_behavior": "clean project exits 0 strict_errors=0; dup exits 1; untested exits 0 with warning",
2882+
"confidence": 1.0
2883+
},
2884+
{
2885+
"id": "TEST-302",
2886+
"title": "generate docs Renders YAML to REQUIREMENTS.md and TESTS.md",
2887+
"description": "`specsmith generate docs --json` in YAML-first mode exits 0 and returns `{ok: true, reqs: N, tests: M}`. The regenerated docs/REQUIREMENTS.md contains a heading for each REQ in the YAML files. `--check` flag reports changes without writing.",
2888+
"requirement_id": "REQ-302",
2889+
"type": "cli",
2890+
"verification_method": "pytest",
2891+
"input": "specsmith generate docs --json; specsmith generate docs --check --json",
2892+
"expected_behavior": "exits 0; ok=true; REQUIREMENTS.md updated; check exits 0 with dry_run=true",
2893+
"confidence": 1.0
2894+
},
2895+
{
2896+
"id": "TEST-303",
2897+
"title": "governance-mode Flag Controls YAML vs Markdown Authority",
2898+
"description": "`is_yaml_mode(root)` returns True when `.specsmith/governance-mode` == `yaml` and False when the file is absent or contains `markdown`. `specsmith sync` uses YAML sources when yaml_mode=True and Markdown sources when False. The flag is preserved across specsmith upgrades.",
2899+
"requirement_id": "REQ-303",
2900+
"type": "unit",
2901+
"verification_method": "pytest",
2902+
"input": "governance-mode = yaml; governance-mode absent; governance-mode = markdown",
2903+
"expected_behavior": "is_yaml_mode returns True/False/False respectively",
2904+
"confidence": 1.0
2905+
},
2906+
{
2907+
"id": "TEST-304",
2908+
"title": "Migration Script Is Idempotent",
2909+
"description": "Running `scripts/migrate_governance_to_yaml.py` twice produces the same result as running it once. After migration: docs/requirements/ and docs/tests/ contain YAML files, .specsmith/governance-mode == `yaml`, and `specsmith sync --check` exits 0.",
2910+
"requirement_id": "REQ-304",
2911+
"type": "integration",
2912+
"verification_method": "script",
2913+
"input": "scripts/migrate_governance_to_yaml.py run twice on same project",
2914+
"expected_behavior": "second run produces no changes; governance-mode=yaml; sync --check exits 0",
2915+
"confidence": 1.0
28612916
}
28622917
]

ARCHITECTURE.md

Lines changed: 138 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,49 @@ Profiles constrain which providers a session can use (unrestricted,
4848
local-only, budget, performance, air-gapped).
4949
See `specsmith.agent.execution_profiles`.
5050

51-
### Model Intelligence
51+
### Model Intelligence — HF Leaderboard Sync
5252

53-
Role-based scoring engine using HuggingFace benchmark data.
54-
10 roles × benchmark weights. See `specsmith.agent.model_intelligence`.
53+
Syncs benchmark data from the HuggingFace Open LLM Leaderboard and computes
54+
three task-specific bucket scores per model:
55+
- **Reasoning** = 0.35×MATH + 0.30×GPQA + 0.25×BBH + 0.10×IFEval
56+
- **Conversational** = 0.40×IFEval + 0.35×MMLU-PRO + 0.25×BBH
57+
- **Longform** = 0.35×MUSR + 0.35×IFEval + 0.30×MMLU-PRO
58+
59+
Falls back to 40+ built-in static scores when HF is unreachable.
60+
Background sync runs 15 s after startup, then daily. CLI:
61+
`specsmith model-intel sync/scores/recommendations/connection`.
62+
See `specsmith.agent.hf_leaderboard` (REQ-263..REQ-269).
63+
64+
### Model Capability Profiles
65+
66+
40+ pre-built profiles for all major providers (OpenAI, Anthropic, Google,
67+
Mistral, Llama, Qwen, DeepSeek, Ollama variants). Each profile carries:
68+
`max_tokens`, `prompt_style`, `supports_vision`, `supports_tool_calls`,
69+
`reasoning_mode`, `context_window`. Context-aware `trim_history()` preserves
70+
system messages while summarising older turns. See `specsmith.agent.model_profiles`
71+
(REQ-270..REQ-271).
72+
73+
### LLM Client
74+
75+
`LLMClient` wraps multiple providers with automatic fallback on 429/401,
76+
O-series parameter translation (`max_completion_tokens`, temperature=1,
77+
developer role), and vLLM guided-JSON payload injection.
78+
See `specsmith.agent.llm_client` (REQ-275..REQ-277).
79+
80+
### Rate Limit Scheduler
81+
82+
EMA-based adaptive rate limit scheduler with per-model RPM/TPM profiles,
83+
rolling-window tracking, dynamic concurrency backoff on 429, and image
84+
token estimation. See `specsmith.rate_limits` (REQ-272..REQ-274).
85+
86+
### Endpoint Preset Registry
87+
88+
10+ built-in presets for common OpenAI-compatible providers (vllm, lm_studio,
89+
llama_cpp, openrouter, together, groq, fireworks, deepinfra, perplexity,
90+
azure_openai). Each preset has `id`, `label`, `base_url`, `endpoint_kind`,
91+
`needs_key`. `suggest_profiles()` inspects env for API keys and Ollama
92+
availability and returns inert (never-persisted) suggestions.
93+
See `specsmith.agent.provider_registry` (REQ-278..REQ-280).
5594

5695
### USPTO Data Sources
5796

@@ -130,6 +169,102 @@ Routing table (evaluated in order):
130169

131170
Returns `{"reply": "...", "action": "...", "prompt": "..."}`.
132171

172+
## Context Window Management
173+
174+
GPU-aware context sizing, live fill tracking, auto-compression, and hard
175+
ceiling enforcement. Implemented in `specsmith.context_window`.
176+
177+
### VRAM Tiers (REQ-244)
178+
179+
`detect_gpu_vram()` reads NVIDIA/AMD VRAM via nvidia-smi/rocm-smi, falls
180+
back to 0.0 on any error. `suggest_context_window(vram_gb)` maps:
181+
<6 GB → 4096, 6–11 GB → 8192, 12–19 GB → 16384, ≥20 GB → 32768 tokens.
182+
183+
### Context Fill Tracker (REQ-245..REQ-247)
184+
185+
`ContextFillTracker(limit=N)` emits `ContextFillEvent` on every `record(used)`
186+
call. At ≥ compression_threshold (default 80%) the event signals that
187+
summarisation should run. At ≥ 85% (hard ceiling), `ContextFullError` is
188+
raised — the caller must trigger emergency compression before proceeding.
189+
190+
## YAML-Native Governance Layer
191+
192+
The most significant architectural change in v0.12: governance files
193+
(REQUIREMENTS.md, TESTS.md) are now **derived artifacts** generated from
194+
canonical YAML sources. This is the authority flip from Markdown-primary
195+
to YAML-primary governance.
196+
197+
### Authority Hierarchy (REQ-300..REQ-304)
198+
199+
```
200+
docs/requirements/*.yml ← CANONICAL (edit here)
201+
docs/tests/*.yml ← CANONICAL (edit here)
202+
203+
▼ specsmith sync (YAML-first mode)
204+
.specsmith/requirements.json ← machine cache
205+
.specsmith/testcases.json ← machine cache
206+
207+
▼ specsmith generate docs
208+
docs/REQUIREMENTS.md ← generated artifact (do not hand-edit)
209+
docs/TESTS.md ← generated artifact (do not hand-edit)
210+
```
211+
212+
### Governance Mode Flag
213+
214+
`.specsmith/governance-mode` contains `yaml` when YAML-first mode is active.
215+
`is_yaml_mode(root)` in `specsmith.governance_yaml` reads this flag.
216+
In legacy Markdown mode (flag absent or `markdown`), the old sync behaviour
217+
is preserved for backward compatibility with projects not yet migrated.
218+
219+
### YAML File Groups
220+
221+
Requirements and tests are grouped into domain files under
222+
`docs/requirements/` and `docs/tests/` (7 files each):
223+
224+
| Stem | REQ Range | Domain |
225+
|---|---|---|
226+
| governance | REQ-001..064 | Core AEE governance |
227+
| agent | REQ-065..129 | Nexus + CI |
228+
| harness | REQ-130..160 | Slash commands + subagents |
229+
| intelligence | REQ-161..220 | Instinct, eval, memory |
230+
| context | REQ-244..247 | Context window management |
231+
| esdb | REQ-248..262 | ESDB + skills + MCP builder |
232+
| ai_intelligence | REQ-263..299 | AI model intelligence |
233+
234+
### Strict Validation (REQ-301)
235+
236+
`specsmith validate --strict` runs 8 schema checks:
237+
1. Duplicate REQ IDs (errors)
238+
2. Duplicate TEST IDs (errors)
239+
3. Missing required REQ fields: `id`, `title`, `status` (errors)
240+
4. Missing required TEST fields: `id`, `title`, `requirement_id` (errors)
241+
5. Orphaned TESTs (TEST references non-existent REQ) (errors)
242+
6. Untested REQs (REQs with no TEST) (warnings)
243+
7. Duplicate REQ titles (warnings)
244+
8. Machine-state drift (YAML ≠ JSON) (warnings)
245+
246+
Gated in CI via the `validate-strict` job in `.github/workflows/ci.yml`.
247+
248+
### Sync Pipeline (REQ-300)
249+
250+
In YAML-first mode, `specsmith sync` executes:
251+
1. `load_yaml_requirements(root)` + `load_yaml_tests(root)` — read YAML
252+
2. Normalise to `{id, title, description, source, status}` schema
253+
3. Compare against existing JSON (detect drift)
254+
4. Write `.specsmith/requirements.json` + `testcases.json` (JSON cache)
255+
5. `generate_requirements_md()` + `generate_tests_md()` — render MD
256+
6. Write `docs/REQUIREMENTS.md` + `docs/TESTS.md` (derived artifacts)
257+
258+
Legacy Markdown mode (steps 1–4 only, MD → JSON).
259+
260+
### Migration
261+
262+
`scripts/migrate_governance_to_yaml.py` is the idempotent migration script:
263+
1. Removes duplicate REQs from REQUIREMENTS.md
264+
2. Re-syncs machine state from cleaned MD
265+
3. Exports JSON → grouped YAML files
266+
4. Writes `.specsmith/governance-mode = yaml`
267+
133268
## Kairos Integration
134269

135270
Kairos (layer1labs/kairos) is the Rust terminal that consumes

README.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ per-session and per-project.
2424

2525
```bash
2626
specsmith governance-serve --port 7700 # Kairos governance REST API
27-
specsmith sync # sync .specsmith/ from docs/ markdown
27+
specsmith sync # sync YAML → JSON → MD (YAML-first mode)
28+
specsmith generate docs # regenerate REQUIREMENTS.md + TESTS.md from YAML
29+
specsmith validate --strict # YAML schema checks: dup IDs, orphans, coverage
2830
specsmith agent permissions-check git_push # check tool permission (REQ-012)
2931
specsmith ollama gpu # detect GPU VRAM, recommend context size
3032
specsmith export # generate full compliance report
@@ -164,16 +166,44 @@ specsmith phase --project-dir ./my-project
164166

165167
---
166168

167-
## Machine State Sync
169+
## Machine State Sync + YAML Governance
168170

169-
`.specsmith/` always mirrors the human-readable `docs/` governance files.
170-
Run `specsmith sync` after any change to `docs/REQUIREMENTS.md` or `docs/TESTS.md`:
171+
As of v0.12, specsmith uses **YAML-first governance**: `docs/requirements/*.yml`
172+
and `docs/tests/*.yml` are the canonical sources. `REQUIREMENTS.md` and `TESTS.md`
173+
are **generated artifacts** — do not hand-edit them.
171174

172175
```bash
173-
specsmith sync # regenerate .specsmith/requirements.json + testcases.json
174-
specsmith sync --check # CI mode: exits 1 if out of sync without writing
175-
specsmith sync --json # emit sync result as JSON
176-
```
176+
# YAML-first pipeline (v0.12+)
177+
specsmith sync # YAML → .specsmith/*.json → docs/*.md (all in one)
178+
specsmith generate docs # regenerate only the Markdown artifacts from YAML
179+
specsmith generate docs --check # dry-run: report what would change
180+
specsmith validate --strict # enforce schema: dup IDs, orphans, missing fields
181+
specsmith validate --strict --json # machine-readable validation result
182+
183+
# CI guard (already in .github/workflows/ci.yml)
184+
specsmith sync --check # exits 1 if JSON cache is out of sync with YAML
185+
```
186+
187+
**To add a new requirement**, edit the appropriate `docs/requirements/<domain>.yml`
188+
file and run `specsmith sync`. **Never** hand-edit `docs/REQUIREMENTS.md` — it will
189+
be overwritten by the next sync.
190+
191+
**Domain files:**
192+
193+
| File | REQ range | Domain |
194+
|---|---|---|
195+
| `docs/requirements/governance.yml` | REQ-001..064 | Core AEE governance |
196+
| `docs/requirements/agent.yml` | REQ-065..129 | Nexus + CI |
197+
| `docs/requirements/harness.yml` | REQ-130..160 | Slash commands + subagents |
198+
| `docs/requirements/intelligence.yml` | REQ-161..220 | Instinct, eval, memory |
199+
| `docs/requirements/context.yml` | REQ-244..247 | Context window |
200+
| `docs/requirements/esdb.yml` | REQ-248..262 | ESDB + skills + MCP |
201+
| `docs/requirements/ai_intelligence.yml` | REQ-263..299 | AI model intelligence |
202+
| `docs/requirements/yaml_governance.yml` | REQ-300..399 | YAML governance layer |
203+
204+
**Migration from Markdown-primary:** Run
205+
`scripts/migrate_governance_to_yaml.py` once to convert an existing project.
206+
Idempotent — safe to re-run.
177207

178208
## Least-Privilege Agent Permissions (REG-012)
179209

0 commit comments

Comments
 (0)