nexus-agents 2.151.0 → 2.152.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,841 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * nexus-agents/config - Model Capabilities Type Definitions
5
+ *
6
+ * Zod schemas and TypeScript interfaces for the model capabilities matrix.
7
+ * Defines output/input modalities, tool support, and special features
8
+ * for each supported AI model.
9
+ *
10
+ * @module config/model-capabilities-types
11
+ * (Source: Issue #683, Epic #682)
12
+ */
13
+
14
+ /** Output modalities a model can produce. */
15
+ declare const OUTPUT_MODALITIES: readonly ["text", "image_png", "image_jpeg", "audio_pcm", "audio_wav", "audio_mp3", "video_mp4", "svg", "structured_json", "code"];
16
+ type OutputModality = (typeof OUTPUT_MODALITIES)[number];
17
+ /** Input modalities a model can accept. */
18
+ declare const INPUT_MODALITIES: readonly ["text", "image", "audio", "video", "pdf", "code"];
19
+ type InputModality = (typeof INPUT_MODALITIES)[number];
20
+ /** Tool capabilities a model supports. */
21
+ declare const TOOL_CAPABILITIES: readonly ["mcp", "function_calling", "computer_use", "code_execution_sandbox", "web_search", "file_operations", "structured_output", "apply_patch"];
22
+ type ToolCapability = (typeof TOOL_CAPABILITIES)[number];
23
+ /** Special features beyond standard text generation. */
24
+ declare const SPECIAL_FEATURES: readonly ["extended_thinking", "deep_research", "streaming", "grounding", "citations", "image_editing", "voice_cloning", "live_api", "context_caching"];
25
+ type SpecialFeature = (typeof SPECIAL_FEATURES)[number];
26
+ /** CLI tool names supported by the routing system. */
27
+ declare const CLI_NAMES: readonly ["claude", "gemini", "codex", "opencode"];
28
+ type CliNameLiteral = (typeof CLI_NAMES)[number];
29
+ /**
30
+ * Canonical model id enum used for narrow `ModelId` typing and as the
31
+ * argument to `z.enum(MODEL_IDS)` in `ModelCapabilitySchema`.
32
+ *
33
+ * This is a hand-maintained narrow tuple rather than a derived view
34
+ * from `ModelRegistry` because the literal-union type is load-bearing:
35
+ * — Zod schemas (`ModelCapabilitySchema.id`, `replacedBy`) need a
36
+ * closed enum at compile time.
37
+ * — Many function signatures across `src/` accept `ModelId` and rely
38
+ * on the narrowed type for exhaustiveness.
39
+ *
40
+ * The runtime invariant — `MODEL_IDS` matches the in-tree registry
41
+ * entries — is asserted by `model-ids-invariant.test.ts`. If you add
42
+ * or remove a model in `DEFAULT_MODEL_CAPABILITIES.models`, you must
43
+ * also update this list (and the test will tell you when they drift).
44
+ *
45
+ * Slice E of #2546 will collapse `model-capabilities.ts` itself; at
46
+ * that point `MODEL_IDS` either moves to `model-config-helpers.ts` or
47
+ * its consumers are loosened to `string`. This narrow type stays
48
+ * until then.
49
+ */
50
+ declare const MODEL_IDS: readonly ["claude-opus", "claude-sonnet", "claude-haiku", "gemini-3-pro", "gemini-pro", "gemini-3-flash", "gemini-flash", "codex-5.3", "codex-5.2", "codex-5.1-mini", "opencode-default", "opencode-custom-opus", "opencode-custom-sonnet", "openrouter-nemotron-super", "openrouter-qwen-coder"];
51
+ type ModelId = (typeof MODEL_IDS)[number];
52
+ /** Quality scores for model capability routing (0-10 scale). */
53
+ declare const QualityScoresSchema: z.ZodObject<{
54
+ reasoning: z.ZodNumber;
55
+ codeGeneration: z.ZodNumber;
56
+ speed: z.ZodNumber;
57
+ cost: z.ZodNumber;
58
+ }, z.core.$strip>;
59
+ type QualityScores = z.infer<typeof QualityScoresSchema>;
60
+ /** Pricing information (USD per 1M tokens). */
61
+ declare const PricingSchema: z.ZodObject<{
62
+ inputPer1M: z.ZodNumber;
63
+ outputPer1M: z.ZodNumber;
64
+ }, z.core.$strip>;
65
+ type Pricing = z.infer<typeof PricingSchema>;
66
+
67
+ /**
68
+ * decision-cost — per-DECISION cost aggregation over a governed panel's voters.
69
+ *
70
+ * Source: Issue #3855 (epic #3854 child, M4).
71
+ *
72
+ * A governed decision — a `consensus_vote` or `pr_review` run — fans out to N
73
+ * voter calls; each voter is one LLM call. Per-CALL usage telemetry already
74
+ * exists ({@link module:learning/usage-log} — token + cost per model call,
75
+ * PR #2479/#2480 era). This module is the AGGREGATION layer that rolls those
76
+ * per-call numbers UP into a single per-decision answer: "what did this
77
+ * governed decision cost?".
78
+ *
79
+ * It is a PURE rollup (no I/O, no clock, no env reads at the math layer):
80
+ * {@link rollupDecisionCost} takes the per-voter cost inputs + the billing mode
81
+ * and returns a {@link DecisionCostSummary} — total tokens, total USD, a
82
+ * per-voter breakdown, and a per-model breakdown. Persistence + the live
83
+ * `process.env` billing-mode read live in the callers (the store + the tools),
84
+ * mirroring the usage-log split between `computeCostUSD` (pure) and
85
+ * `recordUsageEvent` (I/O).
86
+ *
87
+ * Design decisions that the fixture tests pin (#3855 acceptance criteria):
88
+ *
89
+ * - **Missing cost is UNMEASURED, not zero.** A voter with no token counts
90
+ * (e.g. a CLI-subscription adapter that doesn't report usage, or an error
91
+ * vote that never reached the model) is counted in `unmeasuredVoters` and
92
+ * contributes 0 to the totals — but the summary records that the total is a
93
+ * floor, not an exact figure (`measured` < `voterCount`). Treating unmeasured
94
+ * as a true $0 would silently understate spend; this keeps the honesty.
95
+ * - **Plan mode records 0-cost but keeps tokens.** Under `NEXUS_BILLING_MODE=plan`
96
+ * the spend is pre-covered by a subscription, so cost is recorded as $0 while
97
+ * token counts are preserved (so the operator can still see consumption and
98
+ * a later `api`-mode reprice is possible). This mirrors how plan mode zeroes
99
+ * cost in routing/scoring without dropping the token signal.
100
+ *
101
+ * @module observability/decision-cost
102
+ */
103
+
104
+ /** Billing mode in effect for a decision. Mirrors `NEXUS_BILLING_MODE`. */
105
+ type DecisionBillingMode = 'plan' | 'api';
106
+ /** Per-voter line in the decision rollup. */
107
+ interface VoterCostBreakdown {
108
+ readonly role: string;
109
+ readonly model: string;
110
+ readonly inputTokens: number;
111
+ readonly outputTokens: number;
112
+ readonly totalTokens: number;
113
+ /** Effective cost after billing-mode application (0 in plan mode). */
114
+ readonly costUsd: number;
115
+ /**
116
+ * True when this voter reported NO usage at all (no tokens, no cost). Its
117
+ * zeros are placeholders, not a measured $0 / 0-token call.
118
+ */
119
+ readonly unmeasured: boolean;
120
+ }
121
+ /** Per-model rollup line within a single decision. */
122
+ interface ModelCostBreakdown {
123
+ readonly model: string;
124
+ readonly voterCount: number;
125
+ readonly inputTokens: number;
126
+ readonly outputTokens: number;
127
+ readonly totalTokens: number;
128
+ readonly costUsd: number;
129
+ }
130
+ /**
131
+ * The per-decision cost rollup. Totals are a FLOOR when `unmeasuredVoters > 0`
132
+ * — read alongside `measuredVoters` / `voterCount` for the confidence.
133
+ */
134
+ interface DecisionCostSummary {
135
+ /** Billing mode applied to produce `totalCostUsd` (and per-line `costUsd`). */
136
+ readonly billingMode: DecisionBillingMode;
137
+ /** Total voters folded into this decision. */
138
+ readonly voterCount: number;
139
+ /** Voters that reported usage (tokens and/or cost). */
140
+ readonly measuredVoters: number;
141
+ /** Voters that reported no usage at all (counted, not zeroed-as-fact). */
142
+ readonly unmeasuredVoters: number;
143
+ readonly totalInputTokens: number;
144
+ readonly totalOutputTokens: number;
145
+ readonly totalTokens: number;
146
+ /**
147
+ * Total cost in USD. 0 under `plan` mode by construction. A FLOOR when
148
+ * `unmeasuredVoters > 0` (unmeasured voters contribute 0, not their unknown
149
+ * real cost).
150
+ */
151
+ readonly totalCostUsd: number;
152
+ /** Per-voter breakdown, in input order. */
153
+ readonly perVoter: readonly VoterCostBreakdown[];
154
+ /** Per-model breakdown, sorted by total cost desc then total tokens desc. */
155
+ readonly perModel: readonly ModelCostBreakdown[];
156
+ }
157
+
158
+ /**
159
+ * nexus-agents/consensus - Core Type Definitions
160
+ *
161
+ * Core type definitions and Zod schemas for the consensus engine.
162
+ * Supports multiple voting strategies for multi-agent decisions.
163
+ */
164
+
165
+ /**
166
+ * Consensus algorithm types.
167
+ * - simple_majority: >50% of votes required
168
+ * - supermajority: >=67% of votes required
169
+ * - unanimous: 100% approval required
170
+ * - proof_of_learning: weighted voting based on agent performance
171
+ * - opinion_wise: higher-order voting with correlation awareness (Issue #333)
172
+ * - higher_order: alias for opinion_wise (Issue #514)
173
+ */
174
+ declare const ConsensusAlgorithmSchema: z.ZodEnum<{
175
+ simple_majority: "simple_majority";
176
+ supermajority: "supermajority";
177
+ unanimous: "unanimous";
178
+ proof_of_learning: "proof_of_learning";
179
+ opinion_wise: "opinion_wise";
180
+ higher_order: "higher_order";
181
+ }>;
182
+ type ConsensusAlgorithm = z.infer<typeof ConsensusAlgorithmSchema>;
183
+ /**
184
+ * Vote decision options.
185
+ */
186
+ declare const VoteDecisionSchema: z.ZodEnum<{
187
+ approve: "approve";
188
+ reject: "reject";
189
+ abstain: "abstain";
190
+ }>;
191
+ type VoteDecision = z.infer<typeof VoteDecisionSchema>;
192
+ /**
193
+ * Proposal status in the lifecycle.
194
+ */
195
+ declare const ProposalStatusSchema: z.ZodEnum<{
196
+ timeout: "timeout";
197
+ closed: "closed";
198
+ rejected: "rejected";
199
+ pending: "pending";
200
+ voting: "voting";
201
+ approved: "approved";
202
+ }>;
203
+ type ProposalStatus = z.infer<typeof ProposalStatusSchema>;
204
+ /**
205
+ * Structured rejection feedback categories (Issue #1213).
206
+ * Enables reject→refine→re-vote feedback loops by classifying rejection reasons.
207
+ */
208
+ declare const RejectionCategorySchema: z.ZodEnum<{
209
+ YAGNI: "YAGNI";
210
+ DRY_VIOLATION: "DRY_VIOLATION";
211
+ OVER_ENGINEERING: "OVER_ENGINEERING";
212
+ SCOPE_CREEP: "SCOPE_CREEP";
213
+ SECURITY_RISK: "SECURITY_RISK";
214
+ MISALIGNED: "MISALIGNED";
215
+ INSUFFICIENT_EVIDENCE: "INSUFFICIENT_EVIDENCE";
216
+ }>;
217
+ type RejectionCategory = z.infer<typeof RejectionCategorySchema>;
218
+ /**
219
+ * All valid rejection category values, for runtime reference.
220
+ */
221
+ declare const REJECTION_CATEGORIES: ("YAGNI" | "DRY_VIOLATION" | "OVER_ENGINEERING" | "SCOPE_CREEP" | "SECURITY_RISK" | "MISALIGNED" | "INSUFFICIENT_EVIDENCE")[];
222
+ /**
223
+ * A vote cast by an agent.
224
+ */
225
+ declare const VoteSchema: z.ZodObject<{
226
+ decision: z.ZodEnum<{
227
+ approve: "approve";
228
+ reject: "reject";
229
+ abstain: "abstain";
230
+ }>;
231
+ reasoning: z.ZodString;
232
+ confidence: z.ZodNumber;
233
+ conditions: z.ZodOptional<z.ZodArray<z.ZodString>>;
234
+ rejectionCategories: z.ZodOptional<z.ZodArray<z.ZodEnum<{
235
+ YAGNI: "YAGNI";
236
+ DRY_VIOLATION: "DRY_VIOLATION";
237
+ OVER_ENGINEERING: "OVER_ENGINEERING";
238
+ SCOPE_CREEP: "SCOPE_CREEP";
239
+ SECURITY_RISK: "SECURITY_RISK";
240
+ MISALIGNED: "MISALIGNED";
241
+ INSUFFICIENT_EVIDENCE: "INSUFFICIENT_EVIDENCE";
242
+ }>>>;
243
+ findings: z.ZodOptional<z.ZodArray<z.ZodObject<{
244
+ summary: z.ZodString;
245
+ location: z.ZodString;
246
+ severity: z.ZodDefault<z.ZodEnum<{
247
+ critical: "critical";
248
+ high: "high";
249
+ low: "low";
250
+ medium: "medium";
251
+ }>>;
252
+ gate: z.ZodObject<{
253
+ reread_cited_line: z.ZodDefault<z.ZodEnum<{
254
+ failed: "failed";
255
+ skipped: "skipped";
256
+ passed: "passed";
257
+ }>>;
258
+ traced_call_path: z.ZodDefault<z.ZodEnum<{
259
+ failed: "failed";
260
+ skipped: "skipped";
261
+ passed: "passed";
262
+ }>>;
263
+ named_assertion: z.ZodDefault<z.ZodString>;
264
+ ruled_out_language_non_issue: z.ZodDefault<z.ZodEnum<{
265
+ failed: "failed";
266
+ skipped: "skipped";
267
+ passed: "passed";
268
+ }>>;
269
+ }, z.core.$strip>;
270
+ claim: z.ZodString;
271
+ }, z.core.$strip>>>;
272
+ timestamp: z.ZodOptional<z.ZodISODateTime>;
273
+ }, z.core.$strip>;
274
+ type Vote = z.infer<typeof VoteSchema>;
275
+ /**
276
+ * A proposal submitted for consensus.
277
+ */
278
+ declare const ProposalSchema: z.ZodObject<{
279
+ id: z.ZodOptional<z.ZodString>;
280
+ title: z.ZodString;
281
+ description: z.ZodString;
282
+ algorithm: z.ZodEnum<{
283
+ simple_majority: "simple_majority";
284
+ supermajority: "supermajority";
285
+ unanimous: "unanimous";
286
+ proof_of_learning: "proof_of_learning";
287
+ opinion_wise: "opinion_wise";
288
+ higher_order: "higher_order";
289
+ }>;
290
+ timeout: z.ZodOptional<z.ZodNumber>;
291
+ requiredVoters: z.ZodOptional<z.ZodArray<z.ZodString>>;
292
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
293
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
294
+ }, z.core.$strip>;
295
+ type Proposal = z.infer<typeof ProposalSchema>;
296
+ /**
297
+ * Unique identifier for a proposal.
298
+ */
299
+ type ProposalId = string;
300
+ /**
301
+ * Vote counts summary.
302
+ */
303
+ interface VoteCounts {
304
+ approve: number;
305
+ reject: number;
306
+ abstain: number;
307
+ total: number;
308
+ }
309
+ /**
310
+ * Weighted vote counts for proof-of-learning.
311
+ */
312
+ interface WeightedVoteCounts {
313
+ approve: number;
314
+ reject: number;
315
+ abstain: number;
316
+ totalWeight: number;
317
+ }
318
+ /**
319
+ * Result of a consensus decision.
320
+ */
321
+ interface ConsensusResult {
322
+ proposalId: ProposalId;
323
+ proposal: Proposal;
324
+ outcome: ProposalStatus;
325
+ votes: Map<string, Vote>;
326
+ voteCounts: VoteCounts;
327
+ weightedCounts?: WeightedVoteCounts | undefined;
328
+ approvalPercentage: number;
329
+ quorumReached: boolean;
330
+ startedAt: string;
331
+ closedAt: string;
332
+ durationMs: number;
333
+ }
334
+ /**
335
+ * Consensus result schema for validation.
336
+ */
337
+ declare const ConsensusResultSchema: z.ZodObject<{
338
+ proposalId: z.ZodString;
339
+ proposal: z.ZodObject<{
340
+ id: z.ZodOptional<z.ZodString>;
341
+ title: z.ZodString;
342
+ description: z.ZodString;
343
+ algorithm: z.ZodEnum<{
344
+ simple_majority: "simple_majority";
345
+ supermajority: "supermajority";
346
+ unanimous: "unanimous";
347
+ proof_of_learning: "proof_of_learning";
348
+ opinion_wise: "opinion_wise";
349
+ higher_order: "higher_order";
350
+ }>;
351
+ timeout: z.ZodOptional<z.ZodNumber>;
352
+ requiredVoters: z.ZodOptional<z.ZodArray<z.ZodString>>;
353
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
354
+ createdAt: z.ZodOptional<z.ZodISODateTime>;
355
+ }, z.core.$strip>;
356
+ outcome: z.ZodEnum<{
357
+ timeout: "timeout";
358
+ closed: "closed";
359
+ rejected: "rejected";
360
+ pending: "pending";
361
+ voting: "voting";
362
+ approved: "approved";
363
+ }>;
364
+ votes: z.ZodMap<z.ZodString, z.ZodObject<{
365
+ decision: z.ZodEnum<{
366
+ approve: "approve";
367
+ reject: "reject";
368
+ abstain: "abstain";
369
+ }>;
370
+ reasoning: z.ZodString;
371
+ confidence: z.ZodNumber;
372
+ conditions: z.ZodOptional<z.ZodArray<z.ZodString>>;
373
+ rejectionCategories: z.ZodOptional<z.ZodArray<z.ZodEnum<{
374
+ YAGNI: "YAGNI";
375
+ DRY_VIOLATION: "DRY_VIOLATION";
376
+ OVER_ENGINEERING: "OVER_ENGINEERING";
377
+ SCOPE_CREEP: "SCOPE_CREEP";
378
+ SECURITY_RISK: "SECURITY_RISK";
379
+ MISALIGNED: "MISALIGNED";
380
+ INSUFFICIENT_EVIDENCE: "INSUFFICIENT_EVIDENCE";
381
+ }>>>;
382
+ findings: z.ZodOptional<z.ZodArray<z.ZodObject<{
383
+ summary: z.ZodString;
384
+ location: z.ZodString;
385
+ severity: z.ZodDefault<z.ZodEnum<{
386
+ critical: "critical";
387
+ high: "high";
388
+ low: "low";
389
+ medium: "medium";
390
+ }>>;
391
+ gate: z.ZodObject<{
392
+ reread_cited_line: z.ZodDefault<z.ZodEnum<{
393
+ failed: "failed";
394
+ skipped: "skipped";
395
+ passed: "passed";
396
+ }>>;
397
+ traced_call_path: z.ZodDefault<z.ZodEnum<{
398
+ failed: "failed";
399
+ skipped: "skipped";
400
+ passed: "passed";
401
+ }>>;
402
+ named_assertion: z.ZodDefault<z.ZodString>;
403
+ ruled_out_language_non_issue: z.ZodDefault<z.ZodEnum<{
404
+ failed: "failed";
405
+ skipped: "skipped";
406
+ passed: "passed";
407
+ }>>;
408
+ }, z.core.$strip>;
409
+ claim: z.ZodString;
410
+ }, z.core.$strip>>>;
411
+ timestamp: z.ZodOptional<z.ZodISODateTime>;
412
+ }, z.core.$strip>>;
413
+ voteCounts: z.ZodObject<{
414
+ approve: z.ZodNumber;
415
+ reject: z.ZodNumber;
416
+ abstain: z.ZodNumber;
417
+ total: z.ZodNumber;
418
+ }, z.core.$strip>;
419
+ weightedCounts: z.ZodOptional<z.ZodObject<{
420
+ approve: z.ZodNumber;
421
+ reject: z.ZodNumber;
422
+ abstain: z.ZodNumber;
423
+ totalWeight: z.ZodNumber;
424
+ }, z.core.$strip>>;
425
+ approvalPercentage: z.ZodNumber;
426
+ quorumReached: z.ZodBoolean;
427
+ startedAt: z.ZodISODateTime;
428
+ closedAt: z.ZodISODateTime;
429
+ durationMs: z.ZodNumber;
430
+ }, z.core.$strip>;
431
+ /**
432
+ * Agent performance record for proof-of-learning.
433
+ */
434
+ interface AgentPerformance {
435
+ agentId: string;
436
+ totalVotes: number;
437
+ correctVotes: number;
438
+ successRate: number;
439
+ lastUpdated: string;
440
+ }
441
+ /**
442
+ * Agent performance schema.
443
+ */
444
+ declare const AgentPerformanceSchema: z.ZodObject<{
445
+ agentId: z.ZodString;
446
+ totalVotes: z.ZodNumber;
447
+ correctVotes: z.ZodNumber;
448
+ successRate: z.ZodNumber;
449
+ lastUpdated: z.ZodISODateTime;
450
+ }, z.core.$strip>;
451
+ /**
452
+ * Proposal content caching configuration for determinism. (Issue #589)
453
+ */
454
+ interface ProposalCacheConfig {
455
+ /** Enable content-based caching for repeated proposals */
456
+ enabled: boolean;
457
+ /** TTL in milliseconds (default: 1 hour) */
458
+ ttlMs: number;
459
+ /** Maximum cached entries (default: 500) */
460
+ maxEntries: number;
461
+ }
462
+ /**
463
+ * Incremental quorum configuration (Issue #1408).
464
+ * When enabled, ambiguous votes trigger voter pool expansion.
465
+ */
466
+ interface IncrementalQuorumConfig {
467
+ /** Enable incremental quorum expansion. Default: false */
468
+ enabled: boolean;
469
+ /** Maximum expansion rounds (5→7→9). Default: 2 */
470
+ maxExpansionRounds: number;
471
+ /** Voters to add per expansion round. Default: 2 */
472
+ votersPerExpansion: number;
473
+ /** Minimum average confidence to avoid expansion. Default: 0.6 */
474
+ confidenceThreshold: number;
475
+ /** Ambiguity band: if approval rate is within this of threshold, expand. Default: 0.15 */
476
+ ambiguityBand: number;
477
+ }
478
+ /**
479
+ * Callback to request additional voters for incremental quorum.
480
+ * Returns the IDs of newly added voters.
481
+ */
482
+ type VoterExpansionCallback = (proposalId: ProposalId, currentVoterCount: number, requestedCount: number) => Promise<readonly string[]>;
483
+ /**
484
+ * Consensus engine configuration.
485
+ */
486
+ interface ConsensusEngineConfig {
487
+ defaultTimeout: number;
488
+ minVotersForQuorum: number;
489
+ maxActiveProposals: number;
490
+ enablePerformanceTracking: boolean;
491
+ /** Maximum number of closed proposals to retain. Oldest are evicted when exceeded. (Issue #549) */
492
+ maxClosedProposals: number;
493
+ /** Content-based proposal caching for determinism (Issue #589) */
494
+ proposalCache?: ProposalCacheConfig;
495
+ /** Incremental quorum configuration (Issue #1408) */
496
+ incrementalQuorum?: IncrementalQuorumConfig;
497
+ }
498
+ /**
499
+ * Consensus engine configuration schema.
500
+ */
501
+ declare const ConsensusEngineConfigSchema: z.ZodObject<{
502
+ defaultTimeout: z.ZodDefault<z.ZodNumber>;
503
+ minVotersForQuorum: z.ZodDefault<z.ZodNumber>;
504
+ maxActiveProposals: z.ZodDefault<z.ZodNumber>;
505
+ enablePerformanceTracking: z.ZodDefault<z.ZodBoolean>;
506
+ maxClosedProposals: z.ZodDefault<z.ZodNumber>;
507
+ proposalCache: z.ZodOptional<z.ZodObject<{
508
+ enabled: z.ZodDefault<z.ZodBoolean>;
509
+ ttlMs: z.ZodDefault<z.ZodNumber>;
510
+ maxEntries: z.ZodDefault<z.ZodNumber>;
511
+ }, z.core.$strip>>;
512
+ }, z.core.$strip>;
513
+ /**
514
+ * Default configuration values.
515
+ */
516
+ declare const DEFAULT_CONSENSUS_CONFIG: ConsensusEngineConfig;
517
+ /**
518
+ * Voting thresholds for each algorithm.
519
+ */
520
+ declare const VOTING_THRESHOLDS: Record<ConsensusAlgorithm, number>;
521
+ /**
522
+ * Internal proposal state managed by the engine.
523
+ */
524
+ interface ProposalState {
525
+ proposal: Proposal;
526
+ status: ProposalStatus;
527
+ votes: Map<string, Vote>;
528
+ voteWeights: Map<string, number>;
529
+ startedAt: Date;
530
+ timeoutId?: ReturnType<typeof setTimeout>;
531
+ /** Number of incremental quorum expansions applied (Issue #1408). */
532
+ expansionRounds?: number;
533
+ /**
534
+ * True while a quorum expansion is awaiting its callback for this
535
+ * proposal. Concurrent `vote()` calls check this to avoid double-
536
+ * expanding across the `await` gap (Issue #2861). Per-proposal so
537
+ * independent proposals never block each other.
538
+ */
539
+ expansionInFlight?: boolean;
540
+ }
541
+ /**
542
+ * Consensus metrics for monitoring.
543
+ */
544
+ interface ConsensusMetrics {
545
+ totalProposals: number;
546
+ approvedProposals: number;
547
+ rejectedProposals: number;
548
+ timedOutProposals: number;
549
+ averageDurationMs: number;
550
+ averageVotesPerProposal: number;
551
+ algorithmUsage: Record<ConsensusAlgorithm, number>;
552
+ }
553
+ /**
554
+ * Consensus metrics schema.
555
+ */
556
+ declare const ConsensusMetricsSchema: z.ZodObject<{
557
+ totalProposals: z.ZodNumber;
558
+ approvedProposals: z.ZodNumber;
559
+ rejectedProposals: z.ZodNumber;
560
+ timedOutProposals: z.ZodNumber;
561
+ averageDurationMs: z.ZodNumber;
562
+ averageVotesPerProposal: z.ZodNumber;
563
+ algorithmUsage: z.ZodRecord<z.ZodEnum<{
564
+ simple_majority: "simple_majority";
565
+ supermajority: "supermajority";
566
+ unanimous: "unanimous";
567
+ proof_of_learning: "proof_of_learning";
568
+ opinion_wise: "opinion_wise";
569
+ higher_order: "higher_order";
570
+ }>, z.ZodNumber>;
571
+ }, z.core.$strip>;
572
+
573
+ /**
574
+ * nexus-agents vote command types
575
+ *
576
+ * Type definitions for the consensus voting CLI command.
577
+ *
578
+ * (Source: Issue #212, Process Automation Epic #209)
579
+ */
580
+
581
+ /**
582
+ * #4135: how the `vote` command maps a `no_quorum` decision — a quorum void
583
+ * (a missing/errored voice under the opt-in `absolute_quorum` error policy, or an
584
+ * error-policy short-circuit), which is DISTINCT from a genuine rejection.
585
+ *
586
+ * - `fail` (default): exit 1, exactly as a rejection would — back-compat.
587
+ * - `exit2`: exit with a distinct code 2 so scripts can tell a quorum void apart
588
+ * from an approval (0) or a rejection (1).
589
+ * - `retry`: re-run the vote ONCE (the plan is fine, a voice was missing); if it
590
+ * still cannot reach quorum, fall back to `fail` (exit 1).
591
+ */
592
+ type NoQuorumPolicy = 'fail' | 'exit2' | 'retry';
593
+ /**
594
+ * Voter agent role definitions.
595
+ *
596
+ * `scope_steward` (#2185) was added 2026-04-25 to address a build-vs-buy
597
+ * blind spot in the original 6-role panel: the panel approved a proposal
598
+ * to build a USB-flasher CLI without flagging that Rufus already solves
599
+ * the problem. The scope-steward role explicitly checks for existing tools
600
+ * + biases toward "don't build."
601
+ */
602
+ type VoterRole = 'architect' | 'security' | 'devex' | 'ai_ml' | 'pm' | 'catfish' | 'scope_steward';
603
+ /**
604
+ * Individual agent vote with metadata.
605
+ */
606
+ interface AgentVoteResult {
607
+ readonly role: VoterRole;
608
+ readonly vote: Vote;
609
+ readonly processingTimeMs: number;
610
+ /**
611
+ * Source of the vote:
612
+ * - 'llm': Real LLM execution
613
+ * - 'simulation': Fallback simulation (opt-in only)
614
+ * - 'error': Error during execution (Issue #523)
615
+ */
616
+ readonly source: 'llm' | 'simulation' | 'error';
617
+ /** CLI that executed this vote (for adaptive routing feedback). */
618
+ readonly cli?: string | undefined;
619
+ /**
620
+ * Model id that executed this vote, when known (e.g. 'claude-sonnet'). Carried
621
+ * so per-decision cost aggregation can attribute spend per model (#3855). Absent
622
+ * for error/simulation votes that never reached a model.
623
+ */
624
+ readonly model?: string | undefined;
625
+ /**
626
+ * Input tokens the adapter reported for this voter's LLM call, when known
627
+ * (#3910). Propagated from `CompletionResponse.usage` so per-decision cost
628
+ * aggregation resolves from `unmeasured` to MEASURED. Absent for
629
+ * error/simulation votes that never reached a model, or for adapters that do
630
+ * not report usage (CLI subscriptions) — those stay honestly `unmeasured`.
631
+ */
632
+ readonly inputTokens?: number | undefined;
633
+ /**
634
+ * Output tokens the adapter reported for this voter's LLM call, when known
635
+ * (#3910). See {@link AgentVoteResult.inputTokens}.
636
+ */
637
+ readonly outputTokens?: number | undefined;
638
+ /** Error message if vote fell back to simulation or encountered an error */
639
+ readonly error?: string;
640
+ }
641
+
642
+ /**
643
+ * Types, schemas, and response helpers for the consensus_vote MCP tool.
644
+ * Extracted from consensus-vote.ts for file size compliance (Issue #708).
645
+ *
646
+ * @module mcp/tools/consensus-vote-types
647
+ */
648
+
649
+ /**
650
+ * Available consensus voting strategies.
651
+ *
652
+ * - `simple_majority`: Standard majority voting (>50%)
653
+ * - `supermajority`: Requires >=67% approval
654
+ * - `unanimous`: Requires 100% approval
655
+ * - `proof_of_learning`: Weighted by agent performance (Issue #103)
656
+ * - `higher_order`: Bayesian-optimal with correlation awareness (Issue #514)
657
+ * - `opinion_wise`: Alias for higher_order (Issue #333)
658
+ */
659
+ type VotingStrategy = 'simple_majority' | 'supermajority' | 'unanimous' | 'proof_of_learning' | 'higher_order' | 'opinion_wise';
660
+ /**
661
+ * How error-source votes (timed-out or crashed voters) are counted toward
662
+ * the threshold (#2630).
663
+ *
664
+ * - `reduce_denominator` (default for non-strict strategies): errors are
665
+ * filtered out before the engine sees votes — denominator = non-error
666
+ * votes. Best for operational decisions where you trust the responding
667
+ * voters and infrastructure flake should not block the vote.
668
+ * - `count_as_abstain`: error votes reach the engine as abstain. Behaves
669
+ * conservatively — a timed-out voter effectively withholds approval
670
+ * relative to the threshold. Use when you can't tell what the error
671
+ * voter would have decided and want the math to reflect uncertainty.
672
+ * - `fail_closed` (default for unanimous / higher_order): any error voids
673
+ * the vote. Threshold math is not run. Use for security-critical or
674
+ * breaking-change decisions where every voter must be heard.
675
+ * - `absolute_quorum` (opt-in, #4132): an errored voter DEGRADES the panel
676
+ * verdict to `no_quorum` instead of being silently dropped from the
677
+ * denominator. Unlike `fail_closed` (which reports a rejection-flavored void),
678
+ * `absolute_quorum` reports `no_quorum` — a recoverable "re-run the missing
679
+ * voice" state that never manufactures `approved` NOR `rejected` from an
680
+ * induced error. An approval requires ZERO errors, the contrarian (catfish)
681
+ * present and non-error (unless quick-mode drops it), and an ABSOLUTE approval
682
+ * count (`ceil(fraction * panelSize)` over the full requested panel — not just
683
+ * a majority of the responders). A genuine reject (zero errors) still blocks.
684
+ * The anti-DoS point: a voter you can knock offline can only ever force a
685
+ * re-run, never flip the verdict.
686
+ *
687
+ * Regardless of policy, a hard floor applies: when errors exceed 50% of
688
+ * total voters, the vote always fails. Catches "all CLIs are down" — a
689
+ * 2-voter consensus is not a real consensus.
690
+ */
691
+ declare const ErrorPolicySchema: z.ZodEnum<{
692
+ reduce_denominator: "reduce_denominator";
693
+ count_as_abstain: "count_as_abstain";
694
+ fail_closed: "fail_closed";
695
+ absolute_quorum: "absolute_quorum";
696
+ }>;
697
+ type ErrorPolicy = z.infer<typeof ErrorPolicySchema>;
698
+ /**
699
+ * Threshold values accepted by the `--threshold` CLI flag and the
700
+ * \`threshold\` MCP input field (#2638 — single source of truth).
701
+ *
702
+ * Maps to consensus algorithms via:
703
+ * `majority → simple_majority`, `supermajority → supermajority`, `unanimous → unanimous`.
704
+ *
705
+ * Used as the canonical Zod schema for CLI parsing
706
+ * (`cli.ts:parseThreshold`), validation (`cli-commands-validators.ts:isValidThreshold`),
707
+ * and the `ConsensusVoteInputSchema.threshold` field.
708
+ */
709
+ declare const VoteThresholdSchema: z.ZodEnum<{
710
+ supermajority: "supermajority";
711
+ unanimous: "unanimous";
712
+ majority: "majority";
713
+ }>;
714
+ type VoteThreshold = z.infer<typeof VoteThresholdSchema>;
715
+ declare const ConsensusVoteInputSchema: z.ZodObject<{
716
+ proposal: z.ZodString;
717
+ threshold: z.ZodOptional<z.ZodEnum<{
718
+ supermajority: "supermajority";
719
+ unanimous: "unanimous";
720
+ majority: "majority";
721
+ }>>;
722
+ strategy: z.ZodOptional<z.ZodEnum<{
723
+ simple_majority: "simple_majority";
724
+ supermajority: "supermajority";
725
+ unanimous: "unanimous";
726
+ proof_of_learning: "proof_of_learning";
727
+ opinion_wise: "opinion_wise";
728
+ higher_order: "higher_order";
729
+ }>>;
730
+ errorPolicy: z.ZodOptional<z.ZodEnum<{
731
+ reduce_denominator: "reduce_denominator";
732
+ count_as_abstain: "count_as_abstain";
733
+ fail_closed: "fail_closed";
734
+ absolute_quorum: "absolute_quorum";
735
+ }>>;
736
+ quickMode: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
737
+ simulateVotes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
738
+ mode: z.ZodOptional<z.ZodEnum<{
739
+ async: "async";
740
+ sync: "sync";
741
+ }>>;
742
+ idempotencyKey: z.ZodOptional<z.ZodString>;
743
+ ratifies: z.ZodOptional<z.ZodString>;
744
+ }, z.core.$strip>;
745
+ type ConsensusVoteInput = z.infer<typeof ConsensusVoteInputSchema>;
746
+ interface AgentVoteSummary {
747
+ role: string;
748
+ decision: 'approve' | 'reject' | 'abstain';
749
+ confidence: number;
750
+ reasoning: string;
751
+ simulated: boolean;
752
+ /** True when this vote was generated from an error (Issue #815). */
753
+ error: boolean;
754
+ /** Model used for this agent's vote (Issue #817). */
755
+ modelUsed?: string;
756
+ /** Structured rejection categories for reject→refine→re-vote loops (Issue #1213). */
757
+ rejectionCategories?: readonly string[];
758
+ }
759
+ /**
760
+ * Canonical set of decision statuses a vote response can carry. Single source
761
+ * of truth: the `consensus_vote` MCP `outputSchema` reuses
762
+ * {@link VoteDecisionStatusSchema} so the advertised enum can never be narrower
763
+ * than what {@link buildResponse} emits (all five are reachable —
764
+ * `no_quorum` on an all-error/no-quorum panel, the rest via
765
+ * {@link mapOutcomeToDecision}). A narrower schema made strict MCP clients
766
+ * reject `timeout`/`pending` votes with a `-32602`-class error (#4032).
767
+ */
768
+ declare const VoteDecisionStatusSchema: z.ZodEnum<{
769
+ timeout: "timeout";
770
+ rejected: "rejected";
771
+ pending: "pending";
772
+ approved: "approved";
773
+ no_quorum: "no_quorum";
774
+ }>;
775
+ type VoteDecisionStatus = z.infer<typeof VoteDecisionStatusSchema>;
776
+ /** Higher-Order Voting metadata (Issue #514). */
777
+ interface HigherOrderMetadata {
778
+ posteriorApproval: number;
779
+ posteriorRejection: number;
780
+ effectiveVoteCount: number;
781
+ method: 'ow' | 'isp' | 'simple';
782
+ usedCorrelationData: boolean;
783
+ improvementOverBaseline: number;
784
+ downweightedAgents: readonly string[];
785
+ reasoning: string;
786
+ }
787
+ interface ConsensusVoteResponse {
788
+ proposal: string;
789
+ threshold?: VoteThreshold;
790
+ strategy: VotingStrategy;
791
+ decision: VoteDecisionStatus;
792
+ approvalPercentage: number;
793
+ voteCounts: {
794
+ approve: number;
795
+ reject: number;
796
+ abstain: number;
797
+ error: number;
798
+ };
799
+ votes: AgentVoteSummary[];
800
+ durationMs: number;
801
+ simulateVotes: boolean;
802
+ higherOrderMetadata?: HigherOrderMetadata;
803
+ /**
804
+ * Set when an error policy short-circuited the vote (#2630/#3124). Explains a
805
+ * `rejected` decision that may coexist with a high `approvalPercentage` — e.g.
806
+ * `fail_closed: 1 voter(s) errored`. Absent on normally-tallied votes.
807
+ */
808
+ policyReason?: string;
809
+ /**
810
+ * Set when the panel was DEGRADED (#3587): some voters errored, so the
811
+ * decision rests on fewer than the requested number of voters. Surfaces a
812
+ * silently-shrunk panel so the result isn't read as a full-strength consensus.
813
+ * Absent when every requested voter returned a real vote.
814
+ */
815
+ panelWarning?: string;
816
+ /**
817
+ * Per-decision cost rollup (#3855): per-voter / per-model token + USD totals
818
+ * for this governed decision. Rides the existing response — no new MCP tool.
819
+ * Totals are a floor when `costSummary.unmeasuredVoters > 0` (voters whose
820
+ * adapter reported no usage are counted as unmeasured, not a measured $0).
821
+ */
822
+ costSummary?: DecisionCostSummary;
823
+ /**
824
+ * #3991: whether the authentic vote record (#3897) was persisted at vote time.
825
+ * Post-#3991 the runtime ledger routes through `nexusDataPath` under
826
+ * `governance/`, so a writable `.nexus-agents/governance/` location almost
827
+ * always exists and `true` is the normal case. `false` means the persist was
828
+ * skipped (all votes simulated) or the write failed (data dir unwritable) —
829
+ * see {@link voteRecordNote}. Surfaces to the MCP caller what was previously
830
+ * only a server-side WARN.
831
+ */
832
+ voteRecordPersisted: boolean;
833
+ /**
834
+ * #3991: present only when {@link voteRecordPersisted} is `false` — the
835
+ * actionable reason the record was not written (e.g. the data dir is unwritable
836
+ * → fix permissions or set `NEXUS_VOTE_RECORDS_PATH` to a writable path).
837
+ */
838
+ voteRecordNote?: string;
839
+ }
840
+
841
+ export { type AgentPerformance as A, type RejectionCategory as B, type CliNameLiteral as C, type DecisionCostSummary as D, RejectionCategorySchema as E, VOTING_THRESHOLDS as F, type VoteDecisionStatus as G, VoteSchema as H, type InputModality as I, type VoteThreshold as J, type ErrorPolicy as K, type ModelId as M, type NoQuorumPolicy as N, type OutputModality as O, type Pricing as P, type QualityScores as Q, REJECTION_CATEGORIES as R, type SpecialFeature as S, type ToolCapability as T, type Vote as V, type WeightedVoteCounts as W, type VoteDecision as a, type VoterRole as b, type ConsensusAlgorithm as c, type VoteCounts as d, type ProposalState as e, type ProposalId as f, type ConsensusEngineConfig as g, type ConsensusResult as h, type ProposalStatus as i, type Proposal as j, type ConsensusMetrics as k, type VoterExpansionCallback as l, type AgentVoteResult as m, type VotingStrategy as n, AgentPerformanceSchema as o, type AgentVoteSummary as p, ConsensusAlgorithmSchema as q, ConsensusEngineConfigSchema as r, ConsensusMetricsSchema as s, ConsensusResultSchema as t, type ConsensusVoteInput as u, ConsensusVoteInputSchema as v, type ConsensusVoteResponse as w, DEFAULT_CONSENSUS_CONFIG as x, ProposalSchema as y, ProposalStatusSchema as z };