> For the complete documentation index, see [llms.txt](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/phases/phase_40/session_06_moa_save_endpoint.md).

# Session 06: MoA Save Endpoint

**Session ID**: `phase40-session06-moa-save-endpoint` **Status**: Not Started **Estimated Tasks**: \~12-25 **Estimated Duration**: 2-4 hours

***

## Objective

Add safe local persistence for Ministry MoA presets without clobbering existing Hermes config or leaking local paths.

***

## Scope

### In Scope (MVP)

* Add POST `/__hermes_moa_save` or the chosen namespaced admin equivalent in the Hermes admin bridge.
* Require loopback, same-run token, and explicit admin mode because the endpoint writes `~/.hermes/config.yaml`.
* Validate preset name, aggregator provider/model, one to three reference models, bounded temperatures, bounded `max_tokens`, and absence of unknown or oversized payload fields.
* Return setup-required state when config is missing without exposing raw private paths.
* Backup the existing config, merge only `cfg.moa.presets[name]` and `cfg.moa.default_preset`, preserve unrelated config, and return a safe backup label.
* Add admin types and hook surface for Ministry save UX.

### Out of Scope

* Ministry builder UI.
* Frontend YAML generation.
* Writing any config key outside the MoA preset/default fields.

***

## Prerequisites

* [ ] Session 03 shared redaction helper is available.

***

## Deliverables

1. Admin MoA save endpoint with structured YAML merge/dump behavior.
2. Safe response shapes for success, missing config, validation failure, token failure, and admin-disabled failure.
3. Tests for merge, existing preset preservation, backup creation, invalid payloads, missing config, gates, and no raw path leakage.

***

## Success Criteria

* [ ] Saving a preset updates only the intended MoA config fields.
* [ ] Existing Hermes config keys and unrelated presets remain intact.
* [ ] Browser-visible responses name the preset and safe backup label only.
* [ ] Invalid or oversized payloads are rejected before file writes.

***

## Folded Source Session Split

The section below preserves the original Phase 40 session split detail for this session, including dependencies, decisions, outputs, and acceptance checks.

### Session 06: MoA Save Endpoint

**Objective**: Add safe local persistence for Ministry MoA presets without clobbering existing Hermes config or leaking local paths.

**Scope**:

* Add POST `/__hermes_moa_save` or the chosen namespaced admin equivalent in the Hermes admin bridge and register it with current control-plane guards.
* Require loopback, same-run token, and explicit admin mode because the endpoint writes `~/.hermes/config.yaml`.
* Validate preset name, aggregator provider/model, one to three reference models, bounded temperatures, bounded `max_tokens`, and absence of unknown or oversized payload fields.
* Return setup-required state when config is missing without exposing raw paths.
* Backup the existing config, merge only `cfg.moa.presets[name]` and `cfg.moa.default_preset`, preserve unrelated config, and return a safe backup label.
* Add admin types and hook surface for Ministry save UX.

**Outputs**:

* Admin MoA save endpoint with structured YAML merge/dump behavior.
* Safe response shape for success, missing config, validation failure, token failure, and admin-disabled failure.
* Tests for merge, existing preset preservation, backup creation, invalid payloads, missing config, gates, and no raw path leakage.

**Dependencies / Notes**:

* Depends on Session 03.
* Session 15 depends on this endpoint for direct save UX.
* Assumption: the existing `js-yaml` dependency is sufficient for admin-side config writes.

**Acceptance Checks**:

* Saving a preset updates only the intended MoA config fields.
* Existing Hermes config keys and unrelated presets remain intact.
* Browser-visible responses name the preset and safe backup label only.
* Invalid or oversized payloads are rejected before file writes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/phases/phase_40/session_06_moa_save_endpoint.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
