MindAttic.Legion/SPEC
MindAttic.Legion — Product specification
The complete product, written down before it is built (owner, 2026-11-30, MAT-T360). Every epic, feature and story the finished product will have is listed here, built or not. The ticket tree mirrors this file one to one: every ID below is a ticket. Nothing gets built unless it is here, and anything taken out of here is closed wont-do in the tree.
docs/RELEASE.mdsays which part of this the current milestone delivers.
1. Product definition
MindAttic.Legion is a portable .NET 10 library plus the legion.exe CLI that turns a panel of LLMs (13 provider connections, a trusted default set of nine) into one trustworthy answer by voting, deciding, scoring and judging, with quorum, failover, personas and psychometric profiles. It is for the MindAttic apps and coding agents that need a decision they cannot afford to get wrong. The finished product is Legion 29: every capability below built, every public surface proven by offline NUnit tests, published on nuget.org and C:\LocalNuGet with legion.exe deployed to R:\MindAttic\Apps\MindAttic.Legion, and docs that describe exactly what ships.
2. Scope boundary
2.1 In the product
- Panel voting, decisions, rubric scoring and grounded judging with exact quorum and voter refill.
- Thirteen providers behind one resilient transport: tiers, live model discovery, retry, fallback, circuit breaker, document input.
- Credentials through MindAttic Vault; an actionable per-provider health report.
- A 1024-persona library, persona and profile panels, five psychometric instruments scored in code.
legion.exewith diagnostics, voting, persona and psychometrics commands, and per-projectlegion.json.- Provider-reported token usage and a host-supplied price table.
- A drop-in package: DI registration, the nuget.org lineage, the brochure page, a run-menu deploy of the CLI.
2.2 Never in the product
- More providers (Cerebras, SambaNova, DeepInfra, Hyperbolic, Novita, AI21, Zhipu, Qwen, Nebius, Reka): thirteen connections are enough; a dead provider is dropped, not replaced (M.LEGN-T28..T37, wont-do).
- Logging to MindAttic.Log from the library: an app dependency breaks LAW-1 portability (M.LEGN-T21).
- Repeat bughunt, run-all-tests and cleanup sweeps as tickets: bugs are filed when found (M.LEGN-T17..T19, T56).
- Key renewal for providers outside the trusted nine (Groq, OpenRouter, Kimi, Perplexity) as Legion work: keys are the owner's Vault housekeeping (M.LEGN-T23..T25, T27).
- Running models locally: Legion calls vendor HTTP APIs and self-hosted OpenAI-compatible URLs (BIBLE §3).
- A long-running service: it stays a library and a CLI (BIBLE §3).
- Upgrading consumer repos to new Legion versions: each consumer does that under its own charter.
3. Users and roles
- Host app (a MindAttic .NET app): wires Legion through DI and calls vote, decide, score and judge.
- Coding agent (Claude Code, Codex): calls
legion.exe askandvotefor decisions without the owner. - Operator (the owner): checks provider health, tiers and keys, and signs off releases.
- Researcher: builds persona panels and psychometric profiles.
- Maintainer: changes Legion and relies on the offline test suite to prove it.
4. Requirements
Status is built (closed ticket, with evidence) or MS-n: the milestone in §7 that delivers it. Every unbuilt story is approved and prioritised in build order; the planner splits a story into tasks when the queue reaches it.
E1. Panel voting and decisions — M.LEGN-T73 — built
F1.1 Consensus voting — M.LEGN-T74 — built
- S1.1.1 Consensus vote — M.LEGN-T75 — built As a host app, I want
VoteAsyncto call every active provider in parallel and return consensus, reasoning and dissent, so that I get a panel answer instead of one model's guess. Acceptance: Given three active providers, when I vote, then I get one consensus with each rationale and the dissent. Evidence:Services/LlmVotingService.cs. - S1.1.2 Exact quorum thresholds — M.LEGN-T76 — built As a caller, I want Plurality, SimpleMajority, TwoThirds and Unanimous computed with integer arithmetic and an empty consensus when quorum fails, so that a tie never passes as agreement. Acceptance: Given a 2-of-4 split under SimpleMajority, then
QuorumReachedis false andConsensusis empty. Evidence:Models/Quorum.cs, LAW-3, LAW-6. - S1.1.3 Failed voter refill — M.LEGN-T77 — built As a caller, I want failed voters replaced round-robin from surviving providers, so that an outage does not drop the panel below quorum. Acceptance: Given one provider fails, when the vote runs, then a different surviving provider takes its seat. Evidence:
LlmVotingService.RefillFailedVotersAsync.
F1.2 Decisions, scoring and judging — M.LEGN-T78 — built
- S1.2.1 Decide among options — M.LEGN-T79 — built As a host app, I want
DecideAsync(question, options)to return one option with reasoning and confidence, so that code can branch on a panel decision. Acceptance: Given options A, B, C, thenChoiceis one of them, or empty when quorum fails. Evidence:LlmVotingService.DecideAsync. - S1.2.2 Rubric scoring — M.LEGN-T80 — built As a host app, I want
ScoreAsyncto score 1-10 per dimension with an aggregate, failing dimensions and improvement directives, so that I can grade and improve generated work. Evidence:LlmVotingService.ScoreAsync. - S1.2.3 Grounded judging — M.LEGN-T50 — built As a host app, I want rubric judging over evidence passages with cited passage ids, per-voter verdicts and agreement, so that a judgement can be checked against its sources. Evidence: 8064beb,
LlmVotingService.Judge.cs.
E2. Providers and transport — M.LEGN-T81 — built
F2.1 Provider catalog and tiers — M.LEGN-T82 — built
- S2.1.1 Live-verified catalog and trusted nine — M.LEGN-T2 — built As a caller, I want a catalog of 13 providers with live-verified model ids and a default trusted set of nine, so that untrusted keys never vote. Evidence:
Services/LlmProviderCatalog.cs, LAW-5. - S2.1.2 Tiered model selection — M.LEGN-T83 — built As a caller, I want to ask for Low..Highest and get the concrete model per provider, climbing down when a tier is missing, so that vendor model churn never breaks me. Evidence:
Models/ModelTier.cs, LAW-4, d51532f, be4cafe. - S2.1.3 Live model discovery — M.LEGN-T84 — built As an operator, I want a provider's live model list fetched, so that I can see which ids are current. Evidence:
Services/LlmModelDiscovery.cs.
F2.2 Resilient transport — M.LEGN-T85 — built
- S2.2.1 Universal transport — M.LEGN-T86 — built As a host app, I want
CallAsync,CallWithFallbackAsyncand multi-turn chat over every provider's wire shape, so that one client reaches every vendor. Evidence:Services/LegionClient.cs,LegionClientWireTests.cs. - S2.2.2 Shared circuit breaker — M.LEGN-T87 — built As a host app, I want transient failures retried with backoff and a process-wide per-provider breaker, so that a dead provider fails fast for everyone. Evidence:
Services/CircuitBreaker.cs, LAW-7. - S2.2.3 Document input — M.LEGN-T88 — built As a caller, I want to send a document with the prompt, so that the panel can answer about a file. Evidence:
LegionClient.CallWithDocumentAsync.
E3. Credentials and health — M.LEGN-T89 — built
F3.1 Vault credentials — M.LEGN-T90 — built
- S3.1.1 Keys from Vault's shared named lists — M.LEGN-T44 — built As the owner, I want Legion's keys and settings in MindAttic Vault.Desktop, so that one app manages every key. Evidence: e918147.
- S3.1.2 Key resolution order — M.LEGN-T91 — built As a host app, I want keys resolved per-voter override, then configuration, then the shared Vault store, so that each host controls its own keys. Evidence:
LlmVotingProvider.cs,MindAtticCredentialStore.cs, LAW-2.
F3.2 Health diagnosis — M.LEGN-T92 — built
- S3.2.1 Actionable health check — M.LEGN-T93 — built As an operator, I want each provider probed and its failure classified (missing key, 401, 429, model gone) with the dashboard or keys URL, so that I know exactly what to fix. Evidence:
LlmHealthCheck.cs,LlmHealthDiagnosis.cs.
E4. Personas and psychometrics — M.LEGN-T94 — built
F4.1 Persona panels — M.LEGN-T95 — built
- S4.1.1 Persona library — M.LEGN-T96 — built As a caller, I want 1024 personas with unique ids and names, so that I can build trait-diverse panels. Evidence:
Services/PersonaLibrary.cs, LAW-9. - S4.1.2 Persona and profile voting — M.LEGN-T97 — built As a caller, I want
VoteWithPersonasAsyncandVoteWithProfilesAsyncto vote as sampled characters spread across providers without repeats, so that the panel holds many worldviews. Evidence:VoterFactory.cs.
F4.2 Psychometric profiles — M.LEGN-T98 — built
- S4.2.1 Five-instrument profiles — M.LEGN-T99 — built As a researcher, I want OCEAN, HEXACO, MBTI-, Enneagram- and DISC-style profiles scored deterministically from in-character answers and saved per persona, so that traits are measured, not asserted. Evidence:
Services/Psychometrics/PsychometricScorer.cs,PersonaStore.cs, LAW-8. - S4.2.2 Psychometric vote analysis — M.LEGN-T100 — built As a researcher, I want votes analysed against voters' profiles, so that I can see how traits shape answers. Evidence:
PsychometricVoteAnalysis.cs.
E5. legion.exe CLI — M.LEGN-T101 — built
F5.1 Command line — M.LEGN-T102 — built
- S5.1.1 Diagnostics commands — M.LEGN-T103 — built As an operator, I want
health,ping,status,providers,modelsandtiers, so that I can see the panel's state from a terminal. Evidence:LegionCli.cs,TiersCommand.cs. - S5.1.2 Voting commands — M.LEGN-T104 — built As a coding agent, I want
vote,ask,pollandgenerate, so that I get a panel decision without writing .NET. Evidence:AskCommand.cs,PollCommand.cs,GenerateCommand.cs. - S5.1.3 Trusted panel by default — M.LEGN-T48 — built As a coding agent, I want
panelandask --must-answerfallbacks to stay within the trusted set or my--providers, so that an untrusted provider never decides for me. Evidence: 9e0f9b1. - S5.1.4 Persona and psychometrics commands — M.LEGN-T105 — built As a researcher, I want
personas,panelandpsychometrics, so that I can build and score panels from a terminal. Evidence:PsychometricsCommand.cs. - S5.1.5 Per-project legion.json — M.LEGN-T106 — built As a coding agent, I want
legion.jsonfound by walking up from the project directory, so that each repo sets its own panel defaults. Evidence:Models/LegionConfig.cs, M.LEGN-T3.
E6. Usage and cost — M.LEGN-T107 — built
F6.1 Usage tracking — M.LEGN-T108 — built
- S6.1.1 Token usage tracking — M.LEGN-T109 — built As a host app, I want provider-reported token usage sent to an
IUsageSinkthroughLegionUsage.Track, so that I can account for every call. Evidence:Usage/LegionUsage.cs, 8064beb. - S6.1.2 Host price table — M.LEGN-T110 — built As a host app, I want to supply an
LlmPriceTable, so that usage turns into cost without hard-coded prices. Evidence:Usage/LlmUsage.cs.
E7. Packaging and distribution — M.LEGN-T111 — built
F7.1 Package and pages — M.LEGN-T112 — built
- S7.1.1 DI registration — M.LEGN-T113 — built As a host app, I want
AddLLMVotingandAddLegionClient, so that one line wires Legion into DI. Evidence:Services/ServiceCollectionExtensions.cs. - S7.1.2 nuget.org lineage — M.LEGN-T41 — built As a consumer, I want the nuget.org lineage current (26.0.0 published), so that the package resolves. Evidence: e4f98b4.
- S7.1.3 Brochure page — M.LEGN-T71 — built As a visitor, I want a one-page brochure at mindattic.github.io/MindAttic.Legion, so that I see what Legion is. Evidence: 8559b7c.
E8. Core voting correctness — M.LEGN-T62 — MS-18 (priority 900)
F8.1 Default panel health — M.LEGN-T65 — MS-18 (990)
- S8.1.1 Health honours the key resolver — M.LEGN-T60 (task) — MS-18 As an operator, I want
legion healthto ask the client whether a provider is configured, so that a host whose keys come only from its keyResolver is not reported as missing a key. Acceptance: Given a key only in the resolver, when health runs, then the provider is probed, not MISSING KEY. - S8.1.2 Mistral answers or leaves the trusted set — M.LEGN-T26 (task) — MS-18 As an operator, I want Mistral's 429 fixed by quota or key, or Mistral dropped from
DefaultIdsand LAW-5, so that every trusted provider answers.
F8.2 Tally, refill and judge tests — M.LEGN-T6 — MS-18 (980)
- S8.2.1 Tally tests — M.LEGN-T52 (task): grouping, dissent, blank consensus on failed quorum, all-failed result.
- S8.2.2 Refill tests — M.LEGN-T53 (task): round-robin replacement, allowed set, persona stripped, error kept.
- S8.2.3 Judge path tests — M.LEGN-T54 (task): agreement clamped 0..N, garbage-reply fallback, judge choice.
F8.3 Decide, breaker and thinking tests — M.LEGN-T64 — MS-18 (970)
- S8.3.1 Decide and panel tests — M.LEGN-T5 (task).
- S8.3.2 Claude thinking helper tests — M.LEGN-T7 (task).
- S8.3.3 Circuit breaker unit tests — M.LEGN-T9 (task). Acceptance for F8.2 and F8.3: the offline suite covers the listed behaviour with
TestSupportfakes, no live keys.
E9. Release and distribution 28 — M.LEGN-T63 — MS-18 (priority 800)
F9.1 NuGet 28 publish — M.LEGN-T66 — MS-18 (890)
- S9.1.1 README pointer — M.LEGN-T72 (task) As a reader, I want README.md to be the standard short pointer to the wiki, with the full text in
docs/overview.md, so that the wiki is the one source. - S9.1.2 Docs describe 28 — M.LEGN-T20 (task, requires T72) As a consumer, I want
docs/overview.mdand the BIBLE to describe 28 as it is, so that docs match the package. - S9.1.3 Publish 28 — M.LEGN-T68 (task) As a consumer, I want MindAttic.Legion 28.x on nuget.org and
C:\LocalNuGet, so that consumers can move to it. Acceptance: the nuget.org page lists 28. Blocked until MindAttic.Vault 7.x is on nuget.org.
F9.2 CLI on shared run menu — M.LEGN-T67 — MS-18 (880)
- S9.2.1 run.ps1 deploy — M.LEGN-T58 (task) As the owner, I want
run.ps1/run.batover the shareddeploy-lib.ps1to publish Debug and Release toR:\MindAttic\Apps\MindAttic.Legion, so thatlegion.exeis installed like every other app.
E10. Full offline coverage — M.LEGN-T114 — MS-133 (priority 700)
Every public surface has offline NUnit coverage with fakes, per the BIBLE quality bar (§8).
F10.1 Library surface tests — M.LEGN-T115 — MS-133 (790)
- S10.1.1 Runtime config resolver tests — M.LEGN-T116 As a maintainer, I want
LlmProviderRuntimeConfigurationResolvercovered offline, so that a config change cannot silently reroute a provider. Supersedes M.LEGN-T4. - S10.1.2 Document input tests — M.LEGN-T117 As a maintainer, I want
CallWithDocumentAsyncandExtractDocumentTextcovered offline, so that document calls keep working. Supersedes M.LEGN-T8. - S10.1.3 DI registration tests — M.LEGN-T118 As a maintainer, I want
AddLLMVotingandAddLegionClientproven to resolve their services, so that a host's one-line wiring never breaks. Supersedes M.LEGN-T13.
F10.2 Psychometrics tests — M.LEGN-T119 — MS-133 (780)
- S10.2.1 Psychometric assessor tests — M.LEGN-T120:
AssessAsyncbehind a fake handler. Supersedes M.LEGN-T10. - S10.2.2 Psychometrics command tests — M.LEGN-T121: against a temp
--store. Supersedes M.LEGN-T11.
F10.3 CLI dispatch tests — M.LEGN-T122 — MS-133 (770)
- S10.3.1 Top-level dispatch tests — M.LEGN-T123 As a maintainer, I want
LegionClidispatch covered (usage on no args, exit 1 on unknown command, exceptions mapped to exit codes), so that every command is reachable. Supersedes M.LEGN-T12. Acceptance for every E10 story: the offline filter covers the surface with fakes; no live keys needed.
E11. Legion 29 polish and release — M.LEGN-T124 — MS-133 (priority 600)
F11.1 Polish and release 29 — M.LEGN-T125 — MS-133 (690)
- S11.1.1 Docs match 29 — M.LEGN-T126 As a consumer, I want
docs/overview.mdand BIBLE §6 to describe 29 exactly, so that what I read is what ships. - S11.1.2 Publish Legion 29 — M.LEGN-T127 (requires T126) As a consumer, I want MindAttic.Legion 29.0.0 on nuget.org and
C:\LocalNuGet, withlegion.exe29 onR:\MindAttic\Apps, so that every repo can move to the finished library. - S11.1.3 Owner sign-off on 29 — M.LEGN-T128 (requires T127; owner-only) As the owner, I want to run
legion healthand alegion askon 29 and see every trusted provider answer, so that the finished product is accepted.
5. Non-functional requirements
- Platform: .NET 10 (
net10.0);legion.exeruns self-contained on Windows. - Portability: depends only on
MindAttic.VaultandMicrosoft.Extensions.*(LAW-1). - Secrets: keys come from MindAttic Vault; none in code, docs or tests (LAW-2).
- Resilience: retry with backoff, a shared per-provider circuit breaker, failed-voter refill (LAW-7).
- Correctness: exact integer quorum and fail-empty on no quorum (LAW-3, LAW-6); deterministic psychometric scoring (LAW-8).
- Testability: every behaviour provable offline with
TestSupportfakes; live tests sit behind categories.
6. Interfaces and dependencies
- Uses: MindAttic.Vault 7.x (credentials and shared key health); 13 vendor HTTP APIs.
- Used by: ThinkTank, Prose, Gadfly, IdeaCms, the Orchestrator, and coding agents through
legion.exe. Each consumer pins its own version under its own charter. - Contract: the public API of
LlmVotingService,LegionClient,LlmProviderCatalog, the DI extensions and thelegion.execommand set; callers ask for tiers, not model ids (LAW-4).
7. Release sequence
- MS-18 — MindAttic.Legion 28 stable release (active,
docs/RELEASE.md): E8 Core voting correctness, E9 Release and distribution 28. - MS-133 — MindAttic.Legion 29: every surface proven, finished library (planned): E10 Full offline coverage, E11 Legion 29 polish and release. When it is reached, the product is finished.
8. Change log
| Date | Change to scope | Ticket |
|---|---|---|
| 2026-11-30 | Specification written from README, BIBLE, RELEASE, code and ticket history. Built record M.LEGN-T73..T113; planned milestone MS-133 (M.LEGN-T114..T128) supersedes the reset's wont-do test tickets T4, T8, T10..T13, because the BIBLE quality bar requires that coverage for a finished feature. | MAT-T378 |