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
Place in the ecosystem: Legion is the platform owner of LLM calls (docs/ECOSYSTEM.md §2.1): every chat, vote, judgement and embedding call in every repo goes through it, with every credential from MindAttic.Vault.
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. Legion is trustworthy — M.LEGN-T62 — MS-18 (priority 900)
Its votes, refills, judgements, decisions and circuit breaker are proven correct offline, its health report tells the truth, and it gets every credential from Vault.
F8.1 Panel health reported truthfully — M.LEGN-T65 — MS-18 (990)
- S8.1.2 Mistral answers or leaves the panel — M.LEGN-T26 (task) — MS-18 As an operator, I want a real Mistral call to answer (its key validated again on 2026-11-30), or Mistral dropped from
DefaultIdsand LAW-5, so that every trusted provider answers. - (S8.1.1 "Health honours the key resolver", M.LEGN-T60, is superseded by S8.4.2: health resolves keys through Vault.)
F8.4 Credentials only from Vault — M.LEGN-T129 — MS-18 (900)
- S8.4.1 Vault-only key lookup — M.LEGN-T130 (task; requires Vault M.VALT-T213) As a host app, I want Legion to resolve every provider key through Vault only (no caller-supplied lookup, no env or config fallback), and Kimi to use
api.moonshot.ailike Vault, so that one key store serves every call. - S8.4.2 Health check via Vault — M.LEGN-T131 (task; requires Vault M.VALT-T208) As an operator, I want
legion healthto use Vault's catalog-driven probe and plain-words verdicts, so that Legion and the LLM Health Dashboard never disagree about a key.
F8.2 Voting arithmetic proven — 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 Decisions and breaker proven — 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. Legion 28 released — M.LEGN-T63 — MS-18 (priority 800; the milestone's closing epic)
F9.1 Published to nuget.org — 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. Requires Vault's nuget.org release (M.VALT-T197).
F9.2 legion.exe on the 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. Legion 29: every surface proven — M.LEGN-T114 — MS-133 (priority 700)
The finished library: every public surface proven offline with fakes (BIBLE quality bar §8), then polished, published and signed off.
F10.1 Library surface proven — M.LEGN-T115 — MS-133 (790)
- S10.1.1 Runtime config resolver tests — M.LEGN-T116 (requires S9.1.3, the end of MS-18) 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 proven — 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 proven — 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.
F10.4 Polish and release 29 — M.LEGN-T125 — MS-133 (690)
(E11 "Legion 29 polish and release", M.LEGN-T124, was a single-feature epic: closed by MAT-T462, its feature moved here.)
- 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 and F10.1-F10.3) 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.
Added by MAT-T477 (owner stories and cross-repo links)
- F M.LEGN-T132 Fails over across a provider's keys (epic M.LEGN-T62, MS-18)
- S M.LEGN-T133 Calls survive a dead key: Tutor's TUT-T301 requires it. Given two Vault keys for a provider, the first revoked, when an app calls Legion, then the call succeeds on the second key and the first is reported to Vault's health record.
- F M.LEGN-T134 Fake provider for spend-free tests (epic M.LEGN-T114, MS-133)
- S M.LEGN-T135 Apps test against a fake provider: ThinkTank's TT-T162 requires it.
- E M.LEGN-T136 Every model call goes through Legion (MS-167 Legion 30: every model call, any client; priority 600)
- F M.LEGN-T137 Speech, image and video generation / S M.LEGN-T138 Generated media through Legion (Prose PRS-T1410 requires it)
- F M.LEGN-T139 Callable from any client / S M.LEGN-T140 Devices call Legion (Hardware.Claudia HC-T14, HC-T34, HC-T35 require it)
- F M.LEGN-T141 Polish and release 30 / S M.LEGN-T142 Legion 30 released (requires T138 and T140; T138 and T140 require the Legion 29 polish M.LEGN-T125)
- F M.LEGN-T144 Batched structured calls / S M.LEGN-T145 Products batch through Legion (proposed, for the owner: Brevity's RTB-T294 requires it; a batch of prompts with one system prompt and an output JSON schema, keys from Vault, the provider's batch API where it has one)
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
- Platform concerns it uses (ECOSYSTEM §2.1): credentials and key health: MindAttic.Vault (only; M.LEGN-T129); shipping:
run.ps1over Agency's deploy-lib; the plan: MindAttic.Tickets. Outside: 13 vendor HTTP APIs. - Concern it owns: LLM calls. No other repo keeps its own provider client (Prose's move onto Legion: PRS-T1405).
- 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 Legion is trustworthy, E9 Legion 28 released. - MS-133 — MindAttic.Legion 29: every surface proven, finished library (planned): E10 Legion 29: every surface proven (ending with its polish-and-release feature F10.4). 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 |
| 2026-11-30 | MAT-T462 single-source pass: 12 renamed (test-suite features named for the capability they prove; E8 "Legion is trustworthy", E9 "Legion 28 released", E10 "Legion 29: every surface proven"); single-feature epic M.LEGN-T124 closed into E10; M.LEGN-T60 superseded by M.LEGN-T131; F8.4 Credentials only from Vault (M.LEGN-T129..T131) added to the spec; 8 requires added (3 cross-repo to Vault) | MAT-T463 |
| 2026-11-30 | MAT-T477 owner story for Tutor, ThinkTank, Prose, Hardware.Claudia | MAT-T477 |