> 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/sessions/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md).

# Implementation Notes

**Session ID**: `phase40-session15-ministry-config-analytics-and-save-ux` **Started**: 2026-07-03 10:05 **Last Updated**: 2026-07-03 10:35

***

## Session Progress

| Metric              | Value     |
| ------------------- | --------- |
| Tasks Completed     | 22 / 22   |
| Estimated Remaining | 0 minutes |
| Blockers            | 0         |

***

## Task Log

### 2026-07-03 - Session Start

**Environment verified**:

* [x] Prerequisites confirmed
* [x] Tools available
* [x] Directory structure ready

***

### Task T001 - Verify Ministry shell and save contracts

**Started**: 2026-07-03 10:04 **Completed**: 2026-07-03 10:05 **Duration**: 1 minute

**Notes**:

* Verified the current Ministry save/copy shell is intentionally disabled and renders draft-only core/expert preview copy.
* Verified `useHermesAdmin` exposes `moa.savePreset`, posts to `/__hermes_moa_save`, prevents duplicate in-flight saves through `runScopedMutation`, and invalidates `HERMES_QUERY_KEYS.models` on success.
* Verified chat model selection already treats refreshed `models.mixtures` as MoA options with provider `moa`.
* Verified demo model intelligence includes bundled pricing provenance and four ranked Ministry rows.
* Confirmed `js-yaml` and `@types/js-yaml` are already declared dependencies.

**Files Changed**:

* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - created session log and T001 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T001 complete.

**Verification**:

* Command/check: `bash .spec_system/scripts/analyze-project.sh --json`
  * Result: PASS - current session resolves to `phase40-session15-ministry-config-analytics-and-save-ux`; session directory exists with `spec.md` and `tasks.md`.
  * Evidence: analyzer reported current phase 40, current session directory present, and no monorepo package scope.
* Command/check: `bash .spec_system/scripts/check-prereqs.sh --json --env`
  * Result: PASS - spec system, jq, and git checks passed.
  * Evidence: checker returned `"overall": "pass"` and no issues.
* Command/check: `sed -n '1,260p' src/components/hermes/ministry/ministry-save-copy-shell.tsx`
  * Result: PASS - current shell state verified before edits.
  * Evidence: copy and save buttons are disabled and component only previews selected lineup rows.
* Command/check: `sed -n '321,1135p' src/hooks/use-hermes-admin.ts`
  * Result: PASS - MoA admin save action and query invalidation verified.
  * Evidence: `moaSaveMutation` posts JSON to `/__hermes_moa_save`, invalidates `HERMES_QUERY_KEYS.models`, and `savePreset` routes through `runScopedMutation`.
* Command/check: `sed -n '620,900p' src/components/hermes/chat/__tests__/hermes-chat-tab.test.tsx`
  * Result: PASS - model selector MoA behavior verified in existing tests.
  * Evidence: tests assert Ministry MoA options render and send `{ model: "ministry", provider: "moa" }`.
* Command/check: `sed -n '130,250p' src/lib/hermes-demo-data.ts`
  * Result: PASS - fixture shape verified.
  * Evidence: `HERMES_DEMO_MODEL_INTELLIGENCE` includes ranked lineup, bundled pricing provenance, and disabled live-pricing summary.
* UI product-surface check: N/A - no user-facing code changed in T001.
* UI craft check: N/A - no user-facing code changed in T001.

***

### Task T002 - Prepare Ministry save/copy and analytics test fixtures

**Started**: 2026-07-03 10:05 **Completed**: 2026-07-03 10:08 **Duration**: 3 minutes

**Notes**:

* Added config fixture rows for endpoint-valid slash/colon model IDs and copy-only quote/whitespace model IDs.
* Added draft fixtures for complete, missing-core, and duplicate-row Ministry configurations.
* Added analytics fixture rows covering live OpenRouter pricing, fallback benchmark/speed/pricing metrics, and partial seat coverage.
* Added builder admin fixtures for ready, admin-disabled, token-gated, offline, success, and safe-error save states.

**Files Changed**:

* `src/components/hermes/ministry/__tests__/ministry-config.test.ts` - added config fixture helpers and fixture smoke coverage.
* `src/components/hermes/ministry/__tests__/ministry-analytics.test.ts` - added analytics fixture helpers and fixture smoke coverage.
* `src/components/hermes/ministry/__tests__/ministry-builder.test.tsx` - added reusable admin save-state fixtures for later component coverage.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T002 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T002 complete.

**Verification**:

* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-config.test.ts src/components/hermes/ministry/__tests__/ministry-analytics.test.ts src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - 3 test files passed.
  * Evidence: Vitest reported 13 tests passing in 908ms.
* Command/check: `sed -n '700,805p' scripts/lib/hermes-admin-bridge.ts`
  * Result: PASS - fixture inputs aligned with the strict endpoint payload parser.
  * Evidence: parser requires one to three `reference_models`, exact `aggregator`, optional temperatures, `max_tokens`, and `enabled`.
* UI product-surface check: N/A - no user-facing code changed in T002.
* UI craft check: N/A - no user-facing code changed in T002.

***

### Task T003 - Create pure MoA config helpers

**Started**: 2026-07-03 10:08 **Completed**: 2026-07-03 10:12 **Duration**: 4 minutes

**Notes**:

* Added deterministic Ministry config generation that normalizes the draft, validates selected rows, and builds the Hermes v0.17 MoA save request.
* Added endpoint-compatible validation for missing core, missing references, unknown rows, duplicate rows, and invalid provider/model identifiers.
* Added YAML preview generation through the existing `js-yaml` dependency with safe quote options and a copy prompt that avoids raw paths or bridge diagnostics.
* BQC contract alignment applied by mirroring the existing MoA save endpoint parser constraints for provider/model shape, reference count, temperatures, max tokens, and enabled state.

**Files Changed**:

* `src/components/hermes/ministry/ministry-config.ts` - created pure config, validation, YAML, and copy prompt helpers.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T003 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T003 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - TypeScript compiled the new config helper.
  * Evidence: `tsc --noEmit` completed with exit code 0 after narrowing the local `js-yaml` quote option type.
* Command/check: `sed -n '700,805p' scripts/lib/hermes-admin-bridge.ts`
  * Result: PASS - validation rules were checked against the endpoint parser before implementation.
  * Evidence: helper patterns and defaults match parser constraints for provider, model, reference models, temperatures, `max_tokens`, and `enabled`.
* UI product-surface check: N/A - T003 added a pure helper with no rendered UI.
* UI craft check: N/A - T003 added a pure helper with no rendered UI.

**BQC Fixes**:

* Contract alignment: mirrored the endpoint payload contract in `src/components/hermes/ministry/ministry-config.ts` so invalid browser-side requests are blocked before direct save.
* Error information boundaries: validation messages are product-facing and do not include endpoint names, local paths, or raw exception text.

***

### Task T004 - Create pure Ministry analytics helpers

**Started**: 2026-07-03 10:12 **Completed**: 2026-07-03 10:14 **Duration**: 2 minutes

**Notes**:

* Added deterministic analytics summaries for selected Ministry rows, sorted row summaries, seat coverage, role coverage, average benchmark, speed, and cost.
* Added fallback detection for benchmark, speed, and pricing metrics.
* Added provenance copy for generated model intelligence, bundled benchmark rows, bundled/live pricing, and fallback counts without claiming live benchmark data.
* BQC contract alignment applied by keeping analytics pure and typed against existing Hermes model-intelligence contracts.

**Files Changed**:

* `src/components/hermes/ministry/ministry-analytics.ts` - created pure analytics, sorting, coverage, fallback, and provenance helpers.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T004 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T004 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - TypeScript compiled the new analytics helper.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* Command/check: `sed -n '95,155p' src/lib/hermes-types.ts`
  * Result: PASS - analytics helper input and row summaries align with existing Hermes model-intelligence row, metric, pricing, provenance, and live-pricing contracts.
  * Evidence: helper consumes `HermesModelIntelligenceRow`, `HermesModelPricingProvenance`, and `HermesModelLivePricingSummary` shapes without introducing schema drift.
* UI product-surface check: N/A - T004 added a pure helper with no rendered UI.
* UI craft check: N/A - T004 added a pure helper with no rendered UI.

**BQC Fixes**:

* Contract alignment: analytics types consume existing Hermes contracts instead of duplicating or widening runtime data shape.
* Product surface discipline: provenance strings distinguish bundled benchmark data from live OpenRouter pricing and do not claim live benchmark data.

***

### Task T005 - Extend Ministry types

**Started**: 2026-07-03 10:14 **Completed**: 2026-07-03 10:15 **Duration**: 1 minute

**Notes**:

* Extended Ministry prop types for generated config, analytics summaries, save/copy feedback, MoA save view/result types, and optional admin action wiring.
* Kept admin wiring local to the Ministry prop surface without changing unrelated Hermes component contracts in this task.

**Files Changed**:

* `src/components/hermes/ministry/ministry-types.ts` - added config, analytics, save/copy feedback, and admin action prop types.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T005 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T005 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - Ministry type extensions compile.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* UI product-surface check: N/A - T005 changed type definitions only.
* UI craft check: N/A - T005 changed type definitions only.

**BQC Fixes**:

* Contract alignment: save/copy UI props now reference existing `UseHermesAdminResult` and `HermesMoaSaveBody` contracts instead of ad hoc admin shapes.

***

### Task T006 - Export new Ministry helper APIs

**Started**: 2026-07-03 10:15 **Completed**: 2026-07-03 10:16 **Duration**: 1 minute

**Notes**:

* Exported the new config and analytics helper functions and types through the Ministry index.
* Kept helper type exports sourced from their helper modules while save/copy UI prop types remain sourced from `ministry-types.ts`.

**Files Changed**:

* `src/components/hermes/ministry/index.ts` - exported new config and analytics helper APIs for components and colocated tests.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T006 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T006 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - Ministry index exports compile.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* UI product-surface check: N/A - T006 changed export plumbing only.
* UI craft check: N/A - T006 changed export plumbing only.

**BQC Fixes**:

* Contract alignment: helper exports remain colocated under the Ministry boundary rather than broadening unrelated Hermes imports.

***

### Task T007 - Add config and analytics unit coverage

**Started**: 2026-07-03 10:16 **Completed**: 2026-07-03 10:17 **Duration**: 1 minute

**Notes**:

* Added config unit coverage for request shape, defaults, YAML roundtrip for slash/colon/quote/whitespace identifiers, validation failures, duplicate rows, unknown rows, and safe copy boundaries.
* Added analytics unit coverage for benchmark, speed, cost, fallback counts, live-vs-snapshot provenance, deterministic sorting, and partial seat/role coverage.
* Tightened a test boundary assertion after the first run flagged the legitimate `max_tokens` YAML key as if it were a secret token.

**Files Changed**:

* `src/components/hermes/ministry/__tests__/ministry-config.test.ts` - added focused config helper tests.
* `src/components/hermes/ministry/__tests__/ministry-analytics.test.ts` - added focused analytics helper tests.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T007 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T007 complete.

**Verification**:

* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-config.test.ts src/components/hermes/ministry/__tests__/ministry-analytics.test.ts`
  * Result: PASS - 2 test files passed.
  * Evidence: Vitest reported 8 tests passing in 190ms after the safe-copy assertion was narrowed to paths, bearer/secret text, and raw endpoint names.
* UI product-surface check: N/A - T007 changed unit tests only.
* UI craft check: N/A - T007 changed unit tests only.

**BQC Fixes**:

* Contract alignment: tests now lock the generated request to the Hermes v0.17 MoA save shape.
* Error information boundaries: tests assert copy output avoids raw paths, bearer/secret text, and raw endpoint names.

***

### Task T008 - Replace draft-only analytics shell

**Started**: 2026-07-03 10:17 **Completed**: 2026-07-03 10:19 **Duration**: 2 minutes

**Notes**:

* Replaced the draft-only analytics card with completed Ministry analytics cards for seats, benchmark, speed, and cost.
* Added deterministic row summaries, fallback metric labels, role coverage, and static-versus-live provenance copy.
* Kept copy product-facing and avoided endpoint names, local paths, and implementation diagnostics in the visible shell.

**Files Changed**:

* `src/components/hermes/ministry/ministry-analytics-shell.tsx` - replaced draft-only analytics with completed summary and provenance UI.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T008 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T008 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - analytics shell compiles against the new helper and prop types.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - existing Ministry builder render and interaction coverage still passes with the new analytics shell.
  * Evidence: Vitest reported 11 tests passing in 1.05s.
* UI product-surface check: PASS - component render coverage confirms normal Ministry output remains product-facing and existing tests assert debug/source-path copy is absent.
* UI craft check: PASS - shell keeps compact dashboard cards, stable grid tracks, accessible headings, and readable row summaries; full route/mobile smoke remains scheduled in T020/T021.

**BQC Fixes**:

* Product surface discipline: removed draft-disabled analytics copy and replaced it with product-facing cost/speed/benchmark/provenance summaries.
* Failure path completeness: empty selected-seat state now explains that seating a model populates analytics.

***

### Task T009 - Wire builder config and analytics inputs

**Started**: 2026-07-03 10:19 **Completed**: 2026-07-03 10:20 **Duration**: 1 minute

**Notes**:

* Wired `MinistryBuilder` to derive generated MoA config and analytics summaries from the active draft and model-intelligence body.
* Added save/copy feedback state and reset it when model intelligence or draft seat data changes.
* Passed generated config, analytics summary, optional admin result, demo mode, and feedback callbacks into the child shells.

**Files Changed**:

* `src/components/hermes/ministry/ministry-builder.tsx` - derived config/analytics inputs and reset save/copy feedback on draft changes.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T009 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T009 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - builder wiring compiles.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - existing builder interactions still pass with generated config and analytics inputs.
  * Evidence: Vitest reported 11 tests passing in 1.09s.
* UI product-surface check: PASS - component render tests still assert product-facing builder copy and absence of debug/source-path labels.
* UI craft check: PASS - builder still uses the existing dense Pantheon layout and keeps primary controls stable.

**BQC Fixes**:

* State freshness on re-entry: save/copy feedback resets when model intelligence or the active draft changes.
* Contract alignment: generated config and analytics inputs are derived from the same active draft consumed by the visible seats.

***

### Task T010 - Pass Hermes admin result into Ministry builder

**Started**: 2026-07-03 10:20 **Completed**: 2026-07-03 10:21 **Duration**: 1 minute

**Notes**:

* Passed the existing Pantheon `admin` result into `MinistryBuilder`.
* Left persona create/edit/delete/install/sync workflows unchanged.

**Files Changed**:

* `src/components/hermes/hermes-pantheon.tsx` - passed `admin` to the Ministry builder.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T010 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T010 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - Pantheon prop pass compiles.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* Command/check: `bunx vitest run src/components/hermes/__tests__/hermes-sections.test.tsx src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - Pantheon section composition and Ministry builder coverage still pass.
  * Evidence: Vitest reported 101 tests passing across 2 files in 3.82s.
* UI product-surface check: PASS - no visible copy changed in T010.
* UI craft check: PASS - no layout or styling changed in T010.

**BQC Fixes**:

* Contract alignment: Ministry uses the existing `UseHermesAdminResult` owned by the Pantheon route instead of creating a second admin read path.

***

### Task T011 - Enable YAML and prompt copy controls

**Started**: 2026-07-03 10:21 **Completed**: 2026-07-03 10:24 **Duration**: 3 minutes

**Notes**:

* Replaced disabled copy buttons with YAML and prompt copy controls.
* Added clipboard API copy with a textarea fallback and safe failure copy that leaves the preview selectable.
* Rendered the generated YAML preview and validation messages without raw bridge diagnostics.

**Files Changed**:

* `src/components/hermes/ministry/ministry-save-copy-shell.tsx` - enabled YAML/prompt copy controls, fallback copy path, safe copy feedback, and generated preview rendering.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T011 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T011 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - save/copy shell compiles.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - Ministry builder still renders and interacts with the new shell.
  * Evidence: Vitest reported 11 tests passing in 1.12s.
* UI product-surface check: PASS - visible shell copy is product-facing and does not expose raw endpoint names, local paths, or diagnostics.
* UI craft check: PASS - controls use stable icon+text buttons, compact preview layout, and accessible labels.

**BQC Fixes**:

* Failure path completeness: copy failures produce a controlled recovery message instead of exposing raw exception text.
* Accessibility and platform compliance: copy controls use buttons with explicit accessible labels.

***

### Task T012 - Enable admin-gated MoA save

**Started**: 2026-07-03 10:24 **Completed**: 2026-07-03 10:25 **Duration**: 1 minute

**Notes**:

* Wired the save button to the existing `admin.moa.savePreset` action only when a generated request exists and the admin gate is ready.
* Added local duplicate-trigger prevention with an in-flight ref in addition to the hook-level scoped mutation guard.
* Converted save success, null-start, and thrown failures into safe product-facing feedback.

**Files Changed**:

* `src/components/hermes/ministry/ministry-save-copy-shell.tsx` - enabled admin-gated direct save and in-flight duplicate prevention.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T012 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T012 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - save path compiles against `UseHermesAdminResult`.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* Command/check: `sed -n '760,1030p' src/hooks/use-hermes-admin.ts`
  * Result: PASS - direct save uses the existing hook action with hook-level scoped mutation prevention.
  * Evidence: `admin.moa.savePreset` routes through `runScopedMutation`, and the shell adds a local `saveInFlightRef` guard before calling it.
* UI product-surface check: PASS - save success/error feedback avoids raw config paths and raw bridge errors.
* UI craft check: PASS - pending state uses a stable icon button and does not resize the shell.

**BQC Fixes**:

* Duplicate action prevention: save clicks are disabled or ignored while the shell or hook reports an in-flight save.
* Failure path completeness: save null-start and thrown failure paths set controlled recovery feedback.

***

### Task T013 - Render save readiness and safe feedback states

**Started**: 2026-07-03 10:25 **Completed**: 2026-07-03 10:25 **Duration**: 1 minute

**Notes**:

* Added explicit setup-required, admin-disabled, token-gated, offline, demo-disabled, validation-failure, pending, success, and safe error states.
* Kept copy available for read-only/gated states and disabled save when validation, demo, offline, admin, token, or pending gates require it.
* Used safe recovery copy that avoids raw endpoints, local paths, auth JSON, or secret-shaped strings.

**Files Changed**:

* `src/components/hermes/ministry/ministry-save-copy-shell.tsx` - added save gate mapping and state-specific product copy.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T013 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T013 complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - save state mapping compiles.
  * Evidence: `tsc --noEmit` completed with exit code 0.
* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - builder render coverage still passes with the new save state shell.
  * Evidence: Vitest reported 11 tests passing in 1.12s.
* UI product-surface check: PASS - rendered state copy uses product-facing language and avoids raw endpoint/path/auth diagnostics.
* UI craft check: PASS - state banner uses stable compact dimensions and status icons without disrupting the two-column preview.

**BQC Fixes**:

* Failure path completeness: each unavailable save condition now has explicit user-visible recovery copy.
* Error information boundaries: save errors are redacted to stable recovery copy instead of rendering raw hook error text.

***

### Task T014 - Prove model refresh after MoA save

**Started**: 2026-07-03 10:25 **Completed**: 2026-07-03 10:26 **Duration**: 1 minute

**Notes**:

* Strengthened the existing MoA save hook test to assert successful save invalidates `HERMES_QUERY_KEYS.models`.
* No production hook changes were needed because the invalidation already existed.

**Files Changed**:

* `src/hooks/__tests__/use-hermes-admin.test.tsx` - added model-query invalidation assertion to the MoA save test.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T014 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T014 complete.

**Verification**:

* Command/check: `bunx vitest run src/hooks/__tests__/use-hermes-admin.test.tsx`
  * Result: PASS - hook coverage passed with the new invalidation assertion.
  * Evidence: Vitest reported 38 tests passing in 3.09s.
* Command/check: `sed -n '631,642p' src/hooks/use-hermes-admin.ts`
  * Result: PASS - production hook already invalidates model data on MoA save success.
  * Evidence: `moaSaveMutation` `onSuccess` awaits `queryClient.invalidateQueries({ queryKey: HERMES_QUERY_KEYS.models })`.
* UI product-surface check: N/A - T014 changed hook tests only.
* UI craft check: N/A - T014 changed hook tests only.

**BQC Fixes**:

* Contract alignment: hook tests now lock the selector refresh contract required after a saved MoA preset.

***

### Task T015 - Keep chat selector MoA option behavior compatible

**Started**: 2026-07-03 10:26 **Completed**: 2026-07-03 10:27 **Duration**: 1 minute

**Notes**:

* Added chat selector coverage for a newly refreshed MoA mixture beyond the default `ministry` fixture.
* Verified selecting the refreshed mixture sends chat with `{ provider: "moa", model: "saved-council" }`.
* No production selector changes were required because existing `deriveHermesModelOptions` already maps `models.mixtures`.

**Files Changed**:

* `src/components/hermes/chat/__tests__/hermes-chat-tab.test.tsx` - added refreshed MoA mixture selector coverage.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T015 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T015 complete.

**Verification**:

* Command/check: `bunx vitest run src/components/hermes/chat/__tests__/hermes-chat-tab.test.tsx`
  * Result: PASS - chat selector and send behavior passed with the refreshed mixture case.
  * Evidence: Vitest reported 43 tests passing in 2.30s.
* Command/check: `sed -n '425,443p' src/components/hermes/chat/chat-types.ts`
  * Result: PASS - selector options continue to include `body.mixtures.map((mixture) => optionForMixture(mixture, body))`.
  * Evidence: no production change needed for refreshed MoA presets after model-query invalidation.
* UI product-surface check: PASS - selector option remains user-facing MoA preset copy and does not expose save endpoint internals.
* UI craft check: PASS - existing model selector popover layout and stable option rows remain unchanged.

**BQC Fixes**:

* Contract alignment: selector test now covers refreshed `models.mixtures` data produced after MoA save invalidation.

***

### Task T016 - Test save/copy shell gated rendering states

**Started**: 2026-07-03 10:27 **Completed**: 2026-07-03 10:28 **Duration**: 1 minute

**Notes**:

* Added component coverage for admin-disabled, token-gated, offline, demo read-only, and validation-failure save states.
* Verified copy remains available in gated read-only states and save is disabled when the generated config is invalid.

**Files Changed**:

* `src/components/hermes/ministry/__tests__/ministry-builder.test.tsx` - added save/copy state rendering coverage.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T016 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T016 complete.

**Verification**:

* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - save/copy state coverage passed.
  * Evidence: Vitest reported 17 tests passing in 1.36s after resolving one ambiguous validation text lookup.
* UI product-surface check: PASS - tests assert state copy uses product-facing labels and no raw diagnostics.
* UI craft check: PASS - tested states reuse the same stable shell controls and banners.

**BQC Fixes**:

* Failure path completeness: component tests now prove unavailable save paths render explicit recovery copy.

***

### Task T017 - Test copy success, fallback, and safe failure behavior

**Started**: 2026-07-03 10:28 **Completed**: 2026-07-03 10:29 **Duration**: 1 minute

**Notes**:

* Added tests for clipboard YAML copy, textarea fallback prompt copy, and safe copy failure feedback.
* Verified raw exception details are not rendered after a copy failure.

**Files Changed**:

* `src/components/hermes/ministry/__tests__/ministry-builder.test.tsx` - added copy success, fallback, and safe failure tests.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T017 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T017 complete.

**Verification**:

* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - copy behavior coverage passed.
  * Evidence: Vitest reported 17 tests passing in 1.36s.
* UI product-surface check: PASS - copy failure message is safe and omits raw local path/secret exception text.
* UI craft check: PASS - copy feedback renders in the same compact status area without moving core controls.

**BQC Fixes**:

* Failure path completeness: copy has tested success, fallback, and failure paths.
* Error information boundaries: copy failure tests assert local/private exception text is absent.

***

### Task T018 - Test direct save success, duplicate prevention, and safe errors

**Started**: 2026-07-03 10:29 **Completed**: 2026-07-03 10:29 **Duration**: 1 minute

**Notes**:

* Added tests for generated MoA request payload shape passed into `admin.moa.savePreset`.
* Added duplicate-click prevention coverage while a save promise is in flight.
* Added safe save error coverage that rejects raw local path/secret exception text.

**Files Changed**:

* `src/components/hermes/ministry/__tests__/ministry-builder.test.tsx` - added direct save success, duplicate prevention, safe error, and payload shape coverage.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T018 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T018 complete.

**Verification**:

* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-builder.test.tsx`
  * Result: PASS - direct save behavior coverage passed.
  * Evidence: Vitest reported 17 tests passing in 1.36s.
* UI product-surface check: PASS - save success and error messages are safe and product-facing.
* UI craft check: PASS - pending duplicate prevention uses the existing disabled/in-flight control state without layout shift.

**BQC Fixes**:

* Duplicate action prevention: direct save test proves repeated clicks while in flight call `savePreset` only once.
* Error information boundaries: safe error test proves local path/secret exception text is not rendered.

***

### Task T019 - Test model invalidation and refreshed MoA selector rendering

**Started**: 2026-07-03 10:29 **Completed**: 2026-07-03 10:29 **Duration**: 1 minute

**Notes**:

* Ran the hook invalidation and chat selector refreshed-mixture tests together.
* This proves a successful MoA save invalidates model data and refreshed `models.mixtures` render as selectable MoA chat options.

**Files Changed**:

* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T019 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T019 complete.

**Verification**:

* Command/check: `bunx vitest run src/hooks/__tests__/use-hermes-admin.test.tsx src/components/hermes/chat/__tests__/hermes-chat-tab.test.tsx`
  * Result: PASS - model refresh and selector compatibility tests passed together.
  * Evidence: Vitest reported 81 tests passing across 2 files in 3.03s.
* UI product-surface check: PASS - selector test verifies refreshed MoA options use product-facing MoA preset labels.
* UI craft check: PASS - selector behavior remains inside the existing accessible popover control.

**BQC Fixes**:

* Contract alignment: tested the full refresh contract across save invalidation and selector consumption.

***

### Task T020 - Add Hermes Pantheon route smoke for Ministry controls

**Started**: 2026-07-03 10:29 **Completed**: 2026-07-03 10:31 **Duration**: 2 minutes

**Notes**:

* Updated the existing Ministry Pantheon smoke to assert enabled copy controls, disabled save in admin-disabled mode, analytics shell presence, YAML preview, and mobile no-overflow behavior.
* Added demo-mode Pantheon assertions that Ministry copy remains available while save is disabled and demo read-only copy is visible.

**Files Changed**:

* `tests/e2e/hermes-agent.spec.ts` - added Ministry save/copy controls, demo read-only, and mobile layout smoke assertions.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T020 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T020 complete.

**Verification**:

* Command/check: `bunx playwright test tests/e2e/hermes-agent.spec.ts -g "Ministry|populated demo"`
  * Result: PASS - targeted browser smoke passed.
  * Evidence: Playwright reported 2 Chromium tests passing in 17.9s.
* UI product-surface check: PASS - browser assertions confirmed the Pantheon Ministry surface shows product-facing analytics/save/copy states and demo read-only behavior.
* UI craft check: PASS - desktop and 390px mobile smoke confirmed no horizontal overflow with the new controls.

**BQC Fixes**:

* Product surface discipline: route smoke now checks the real Pantheon surface instead of relying only on component tests.
* Accessibility and platform compliance: browser smoke uses accessible button and heading names for the new controls.

***

### Task T021 - Run focused automated checks

**Started**: 2026-07-03 10:31 **Completed**: 2026-07-03 10:32 **Duration**: 1 minute

**Notes**:

* Ran the focused Vitest bundle for Ministry config, analytics, builder, Hermes admin hook, and Hermes chat selector.
* Ran the full Hermes route Playwright smoke file after the targeted Ministry smoke had passed.

**Files Changed**:

* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T021 evidence.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T021 complete.

**Verification**:

* Command/check: `bunx vitest run src/components/hermes/ministry/__tests__/ministry-config.test.ts src/components/hermes/ministry/__tests__/ministry-analytics.test.ts src/components/hermes/ministry/__tests__/ministry-builder.test.tsx src/hooks/__tests__/use-hermes-admin.test.tsx src/components/hermes/chat/__tests__/hermes-chat-tab.test.tsx`
  * Result: PASS - focused unit/component/hook tests passed.
  * Evidence: Vitest reported 106 tests passing across 5 files in 3.06s.
* Command/check: `bunx playwright test tests/e2e/hermes-agent.spec.ts`
  * Result: PASS - full Hermes browser smoke passed.
  * Evidence: Playwright reported 10 Chromium tests passing in 46.6s.
* UI product-surface check: PASS - Playwright covered desktop/mobile Pantheon Ministry controls, demo read-only copy, no horizontal overflow, and existing Hermes tab smoke.
* UI craft check: PASS - full route smoke confirmed the new controls did not regress desktop/mobile layout boundaries.

***

### Task T022 - Run required project checks and ASCII/LF validation

**Started**: 2026-07-03 10:32 **Completed**: 2026-07-03 10:35 **Duration**: 3 minutes

**Notes**:

* Ran required typecheck and lint checks after formatting touched files.
* Ran ASCII/LF validation across the session spec files and touched Ministry/Hermes implementation and test files.
* Left pre-existing `.spec_system/state.json` changes intact; they were present before this implementation turn.

**Files Changed**:

* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md` - recorded T022 evidence and final progress.
* `.spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md` - marked T022 and the completion checklist complete.

**Verification**:

* Command/check: `bun run typecheck`
  * Result: PASS - project TypeScript check passed.
  * Evidence: `tsc --noEmit` completed with exit code 0 after formatting.
* Command/check: `bun run lint`
  * Result: PASS - project lint passed.
  * Evidence: `eslint .` completed with exit code 0 after Prettier normalized touched files.
* Command/check: `perl -ne 'exit 1 if /\r|[^\x00-\x7F]/' .spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/spec.md .spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/tasks.md .spec_system/specs/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.md src/components/hermes/ministry/ministry-config.ts src/components/hermes/ministry/ministry-analytics.ts src/components/hermes/ministry/ministry-analytics-shell.tsx src/components/hermes/ministry/ministry-save-copy-shell.tsx src/components/hermes/ministry/ministry-builder.tsx src/components/hermes/ministry/ministry-types.ts src/components/hermes/ministry/index.ts src/components/hermes/ministry/__tests__/ministry-config.test.ts src/components/hermes/ministry/__tests__/ministry-analytics.test.ts src/components/hermes/ministry/__tests__/ministry-builder.test.tsx src/components/hermes/hermes-pantheon.tsx src/hooks/__tests__/use-hermes-admin.test.tsx src/components/hermes/chat/__tests__/hermes-chat-tab.test.tsx tests/e2e/hermes-agent.spec.ts`
  * Result: PASS - ASCII and LF validation passed for session and touched implementation/test files.
  * Evidence: Perl scan completed with exit code 0.
* UI product-surface check: PASS - final checks include prior full Hermes Playwright smoke from T021.
* UI craft check: PASS - final checks include prior desktop/mobile no-overflow route smoke from T021.

***


---

# 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/sessions/phase40-session15-ministry-config-analytics-and-save-ux/implementation-notes.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.
