Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Covenant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Covenant.Governance", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Covenant.Host", "src\Covenant.Host\Covenant.Host.csproj", "{13CD101B-CB05-4632-966E-8DAAD7DB34DD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Covenant.Ui", "src\Covenant.Ui\Covenant.Ui.csproj", "{4F1C2B7E-9D3A-4B86-A2E5-6C0D8F7B1E42}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Covenant.Tests", "tests\Covenant.Tests\Covenant.Tests.csproj", "{8C7AC33C-9BF8-413E-9227-D179A0245892}"
EndProject
Global
Expand All @@ -38,6 +40,10 @@ Global
{13CD101B-CB05-4632-966E-8DAAD7DB34DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13CD101B-CB05-4632-966E-8DAAD7DB34DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13CD101B-CB05-4632-966E-8DAAD7DB34DD}.Release|Any CPU.Build.0 = Release|Any CPU
{4F1C2B7E-9D3A-4B86-A2E5-6C0D8F7B1E42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F1C2B7E-9D3A-4B86-A2E5-6C0D8F7B1E42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F1C2B7E-9D3A-4B86-A2E5-6C0D8F7B1E42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F1C2B7E-9D3A-4B86-A2E5-6C0D8F7B1E42}.Release|Any CPU.Build.0 = Release|Any CPU
{8C7AC33C-9BF8-413E-9227-D179A0245892}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C7AC33C-9BF8-413E-9227-D179A0245892}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C7AC33C-9BF8-413E-9227-D179A0245892}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -51,6 +57,7 @@ Global
{E28BD9F8-FBB1-4D29-BC1D-97F6E3AA59DF} = {7DBFEF37-7328-4DE7-B219-1B311679A9F1}
{A83FBCC1-65D4-4604-BA54-46DEF55E3B0C} = {7DBFEF37-7328-4DE7-B219-1B311679A9F1}
{13CD101B-CB05-4632-966E-8DAAD7DB34DD} = {7DBFEF37-7328-4DE7-B219-1B311679A9F1}
{4F1C2B7E-9D3A-4B86-A2E5-6C0D8F7B1E42} = {7DBFEF37-7328-4DE7-B219-1B311679A9F1}
{8C7AC33C-9BF8-413E-9227-D179A0245892} = {1AFC3317-7EBB-410A-9065-0CE302297F63}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
4 changes: 4 additions & 0 deletions docs/PROVENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ No third-party source code has been copied into this repository. Everything belo
- `OpenTelemetry.Extensions.Hosting` / `OpenTelemetry.Exporter.OpenTelemetryProtocol` 1.17.0 — Apache-2.0. Host-only, activated only when `Otel:Endpoint` is configured (ADR-0003). Core instruments via BCL `ActivitySource` and takes no OTel dependency.
- `Neo4j.Driver` 6.2.1 — Apache-2.0, official Bolt driver. Host-only, activated only when `Neo4j:Uri` is configured (ADR-0006 evidence graph projection).
- `Anthropic` 12.8.0 — MIT, official Anthropic SDK (IChatClient integration). Host-only, activated only when `Anthropic:ApiKey` is configured (ADR-0001 provider start set).
- Console (`src/Covenant.Ui`, ADR-0004 standalone Blazor WebAssembly; compiled to static assets and embedded in the Host — never loaded into the Host process): `Microsoft.AspNetCore.Components.WebAssembly` 10.0.11 — MIT; `Microsoft.AspNetCore.Components.WebAssembly.DevServer` 10.0.11 — MIT, build/dev-time only (`PrivateAssets=all`), not in the published bundle. Pinned against nuget.org 2026-10-16.

## Bundled assets (not code)
- **IBM Plex Sans** (400/500/600, latin subset) and **IBM Plex Mono** (400/500, latin subset) — Copyright 2018 IBM Corp., **SIL Open Font License 1.1**. Copied from `covenant-prototype/fonts/` into `src/Covenant.Ui/wwwroot/fonts/` as `.woff2` together with both licence texts (`LICENSE-ibm-plex-sans.txt`, `LICENSE-ibm-plex-mono.txt`) and the `@font-face` declarations in `fonts/fonts.css`. Served only from the appliance (`/ui/fonts/*`); nothing is fetched from a CDN. The OFL permits bundling and redistribution with the licence; the fonts are not sold on their own and are not renamed (Reserved Font Name "Plex" is kept).

_Update this file in the same change as any code that introduces a new influence or dependency._
305 changes: 305 additions & 0 deletions docs/UI-implementation-tasks.txt

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions docs/UI-redesign-brief.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# ADR-0009 — Request correlation, audit record v2, and honest usage accounting

**Status:** Accepted
**Date:** 2026-10-16

## Context
The console must open the *exact* evidence record for a request it just sent, show what actually
happened (which stage stopped it, whether classification ran, which model was selected / attempted /
served), and never present unknown usage as a real $0. Before this ADR: the audit stage minted its own
id unrelated to any response id; the provider adapter replaced missing token counts with 0; a cancelled
request could lose its audit record (the sink write used the cancelled token); and the audit record
had no structured outcome beyond Effect + a reason string.

## Decision
1. **One correlation id.** Host middleware creates `req_<32 hex>` for every `/v1/*` request *before*
body binding, sets `X-Covenant-Request-Id`, and passes it into the canonical request. It is the
buffered OpenAI `id`, the Anthropic message `id`, the SSE chunk id, `request_id` on error bodies, and
the audit record `Id` (duplicated in `CorrelationId` for explicitness). Caller-supplied ids are never
used. Requests rejected by the JSON binder never reach the pipeline: they carry the header but have no
audit record — the console states this instead of searching.
2. **Audit record v2 — additive, hash-compatible.** New nullable fields appended to `AuditEntry`:
`SchemaVersion=2, CorrelationId, ClassificationEvaluated, DenialKind, StoppedAtStage, SelectedModel,
AttemptedModel, Stream, UsageReported, CostBasis`. The chain hashes the *stored* line bytes and the
verifier re-hashes stored content, so legacy lines verify unchanged and are never rewritten; on
deserialize missing fields are null and the console renders **Not recorded**. Facts are observed, not
inferred: the pipeline sets `CurrentStage` on entry to each stage and `Deny` captures it (the budget
stage names the finer "pause" for the kill switch); `AttemptedModel` is set immediately before a
provider call starts; `ClassificationEvaluated` only by the classify stage. The restrictive default
classification is unchanged for enforcement. No measured per-stage timings yet.
3. **Cancellation is evidence.** The audit stage records a cancelled request as `DenialKind=Cancelled`
and writes with `CancellationToken.None`, so the client going away can never suppress the record.
HTTP 499 if anything is still listening.
4. **Usage honesty.** `InferenceResponse.UsageReported` is false when the provider omitted either token
count. `CostBasis` ∈ `reported | zero_priced | estimated_from_text | estimated_failed_call |
unknown_failed_call | unpriced | no_call`.
5. **Fail-closed accounting.** (a) Startup refuses any routable model without a price (0 is an explicit,
valid price for in-perimeter compute — "provider charge $0", infrastructure excluded). (b) A served
call on a priced model with no reported usage is charged from a chars/4 estimate of prompt + output
(`estimated_from_text`); token counts stay "not reported". (c) A call that was *started* but produced no
response (upstream failure, mid-stream failure, cancellation) is charged an estimate of input + any
streamed output (`estimated_failed_call`) — never a silent zero. (d) Savings aggregates exclude
estimated/unknown records and expose their counts. The budget remains a **pre-call threshold** check:
concurrent requests admitted under the cap can overshoot it by their own cost; it is not an invoice
ceiling.

## Consequences
- (+) Exact evidence lookup by id (`GET /admin/requests/{id}`), robust to identical prompts, equal
timestamps and concurrency; no timestamp joins anywhere.
- (+) Unknown cost cannot become a false $0 or a false saving; ledger replay reproduces estimated charges
because they are recorded in `Usage.CostUsd` of the audit line.
- (−) Lookups re-read the current segment (bounded to it; archived segments are out of scope).
- (−) Estimates can over- or under-charge relative to the provider invoice; they are labelled estimates.

## Alternatives considered
- Rewrite legacy lines into v2 — rejected: rewriting history is exactly what the chain forbids.
- Nullable token fields inside `Usage` — rejected: changes the nested shape every consumer and the
ledger replay read; an entry-level flag is additive.
- Charge nothing for failed calls — rejected: providers bill input tokens on many failures; fail-closed.
35 changes: 35 additions & 0 deletions docs/adr/ADR-0010-local-only-provider-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ADR-0010 — Local-only provider mode and the governed local route

**Status:** Accepted
**Date:** 2026-10-16

## Context
The demo and many regulated deployments run a single in-perimeter model (Ollama serving one exact Qwen
tag) with no cloud credential. Startup required `OpenAI:ApiKey`; the local model id defaulted to a
hard-coded `llama-3.1-8b-instruct`; and the console needs to probe/discover an Ollama endpoint without
becoming an arbitrary server-side URL fetcher.

## Decision
- `Providers:Mode` = `cloud` (default, unchanged behaviour: cloud key required; Public/Internal on cloud
routes; PII/PHI on the local route) or `local-only`.
- **local-only** requires `Local:Endpoint` (absolute http/https) and `Local:ModelId` (exact tag); it
registers **no** cloud provider and **refuses to start** if `OpenAI:ApiKey` or `Anthropic:ApiKey` is
configured — no silent fallback, no quiet rerouting. Every classification routes to `local:<tag>`: an
explicit mode choice recorded in status/catalog, not a model dropdown.
- In both modes the local model id is never guessed: `Local:Endpoint` without `Local:ModelId` refuses to
start; with no local config the route reads `local-model-not-configured` and fails closed at the
provider stage.
- Probing (`POST /admin/providers/probe`, admin-only): destinations must be on
`Providers:ProbeAllowList` (host:port list) or be the applied `Local:Endpoint` authority; http/https;
no userinfo/query/fragment; redirects not followed; connection only to the validated host; 5 s
timeout; 64 KiB response cap; no Covenant credential forwarded. `localhost` means Covenant's host.
- Applying configuration remains manual (config + restart). The console reads back the applied
configuration (`GET /admin/catalog`); draft probe results never alter applied state. Observed health
comes from real pipeline calls and probes of the applied endpoint; a later failure supersedes an
earlier success while preserving the last-success time. A paused (refused) request records no health.

## Consequences
- (+) A no-cloud appliance starts and serves the local model through the full governed pipeline.
- (+) The probe cannot be aimed at arbitrary hosts by a console user.
- (−) One local model only; multiple local models need a registry extension (later ADR).
- (−) Runtime apply is deferred; the wizard ends with configuration guidance and a restart.
Loading
Loading