@mnemom/agent-alignment-protocol 0.1.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,683 @@
1
+ /**
2
+ * Alignment Card schema - Agent alignment declaration.
3
+ *
4
+ * Defines the Alignment Card structure per SPEC Section 4. An Alignment Card
5
+ * is a structured document declaring an agent's alignment posture.
6
+ *
7
+ * @see SPEC.md Section 4 for complete specification.
8
+ */
9
+ /** Type of principal the agent serves. */
10
+ type PrincipalType = "human" | "organization" | "agent" | "unspecified";
11
+ /** Nature of authority delegation from principal to agent. */
12
+ type RelationshipType = "delegated_authority" | "advisory" | "autonomous";
13
+ /** How value conflicts are resolved. */
14
+ type HierarchyType = "lexicographic" | "weighted" | "contextual";
15
+ /** Action to take when escalation trigger matches. */
16
+ type TriggerAction = "escalate" | "deny" | "log";
17
+ /** Audit log storage type. */
18
+ type StorageType = "local" | "remote" | "distributed";
19
+ /** Tamper-evidence mechanism for audit logs. */
20
+ type TamperEvidence = "append_only" | "signed" | "merkle";
21
+ /** Principal relationship declaration (SPEC Section 4.3). */
22
+ interface Principal {
23
+ /** Type of principal */
24
+ type: PrincipalType;
25
+ /** Principal identifier (DID, email, org ID) */
26
+ identifier?: string | null;
27
+ /** Nature of authority delegation */
28
+ relationship: RelationshipType;
29
+ /** Endpoint for escalation notifications */
30
+ escalation_contact?: string | null;
31
+ }
32
+ /** Definition of a custom value. */
33
+ interface ValueDefinition {
34
+ /** Human-readable name */
35
+ name: string;
36
+ /** What this value means operationally */
37
+ description: string;
38
+ /** Priority for lexicographic ordering (higher = more important) */
39
+ priority?: number;
40
+ }
41
+ /** Value declarations (SPEC Section 4.4). */
42
+ interface Values {
43
+ /** List of value identifiers */
44
+ declared: string[];
45
+ /** Definitions for non-standard values */
46
+ definitions?: Record<string, ValueDefinition> | null;
47
+ /** Values this agent refuses to coordinate with */
48
+ conflicts_with?: string[] | null;
49
+ /** How value conflicts are resolved */
50
+ hierarchy?: HierarchyType | null;
51
+ }
52
+ /** Condition that triggers escalation (SPEC Section 4.5). */
53
+ interface EscalationTrigger {
54
+ /** Condition expression (see SPEC Section 4.6) */
55
+ condition: string;
56
+ /** Action to take when trigger matches */
57
+ action: TriggerAction;
58
+ /** Human-readable explanation */
59
+ reason: string;
60
+ }
61
+ /** Monetary value specification. */
62
+ interface MonetaryValue {
63
+ /** Numeric amount */
64
+ amount: number;
65
+ /** ISO 4217 currency code */
66
+ currency?: string;
67
+ }
68
+ /** Autonomy bounds and escalation triggers (SPEC Section 4.5). */
69
+ interface AutonomyEnvelope {
70
+ /** Actions permitted without escalation */
71
+ bounded_actions: string[];
72
+ /** Conditions requiring escalation */
73
+ escalation_triggers: EscalationTrigger[];
74
+ /** Maximum transaction value without escalation */
75
+ max_autonomous_value?: MonetaryValue | null;
76
+ /** Actions never permitted */
77
+ forbidden_actions?: string[] | null;
78
+ }
79
+ /** Audit log storage configuration. */
80
+ interface AuditStorage {
81
+ /** Storage type */
82
+ type: StorageType;
83
+ /** Storage endpoint or location */
84
+ location?: string | null;
85
+ }
86
+ /** Audit trail commitments (SPEC Section 4.7). */
87
+ interface AuditCommitment {
88
+ /** Trace format identifier */
89
+ trace_format?: string;
90
+ /** Minimum retention period in days */
91
+ retention_days: number;
92
+ /** Storage configuration */
93
+ storage?: AuditStorage | null;
94
+ /** Whether traces can be queried externally */
95
+ queryable: boolean;
96
+ /** Endpoint for trace queries (required if queryable=true) */
97
+ query_endpoint?: string | null;
98
+ /** Tamper-evidence mechanism */
99
+ tamper_evidence?: TamperEvidence | null;
100
+ }
101
+ /**
102
+ * Alignment Card - Agent alignment declaration (SPEC Section 4).
103
+ *
104
+ * A structured document declaring an agent's alignment posture. It MUST be
105
+ * machine-readable (JSON) and SHOULD be human-readable.
106
+ */
107
+ interface AlignmentCard {
108
+ /** AAP specification version */
109
+ aap_version?: string;
110
+ /** Unique identifier for this card (UUID or URI) */
111
+ card_id: string;
112
+ /** Identifier for the agent (DID, URL, or UUID) */
113
+ agent_id: string;
114
+ /** When this card was issued (ISO 8601) */
115
+ issued_at: string;
116
+ /** When this card expires (ISO 8601) */
117
+ expires_at?: string | null;
118
+ /** Principal relationship declaration */
119
+ principal: Principal;
120
+ /** Value declarations */
121
+ values: Values;
122
+ /** Autonomy bounds and escalation triggers */
123
+ autonomy_envelope: AutonomyEnvelope;
124
+ /** Audit trail commitments */
125
+ audit_commitment: AuditCommitment;
126
+ /** Protocol-specific extensions */
127
+ extensions?: Record<string, unknown> | null;
128
+ }
129
+ /** Check if an alignment card has expired. */
130
+ declare function isCardExpired(card: AlignmentCard): boolean;
131
+ /** Check if a value is declared in the card. */
132
+ declare function hasValue(card: AlignmentCard, value: string): boolean;
133
+ /** Check if an action is in the bounded actions list. */
134
+ declare function isActionBounded(card: AlignmentCard, action: string): boolean;
135
+ /** Check if an action is forbidden. */
136
+ declare function isActionForbidden(card: AlignmentCard, action: string): boolean;
137
+
138
+ /**
139
+ * AP-Trace schema - Audit log format for agent decisions.
140
+ *
141
+ * Defines the AP-Trace structure per SPEC Section 5. An AP-Trace entry
142
+ * records an agent's decision process.
143
+ *
144
+ * @see SPEC.md Section 5 for complete specification.
145
+ */
146
+ /** Type of action taken or considered. */
147
+ type ActionType = "recommend" | "execute" | "escalate" | "deny";
148
+ /** How the action relates to the autonomy envelope. */
149
+ type ActionCategory = "bounded" | "escalation_trigger" | "forbidden";
150
+ /** Status of an escalation. */
151
+ type EscalationStatus = "pending" | "approved" | "denied" | "timeout";
152
+ /** Resource affected by the action. */
153
+ interface ActionTarget {
154
+ /** Resource type */
155
+ type: string;
156
+ /** Resource identifier */
157
+ identifier: string;
158
+ }
159
+ /** Action taken or considered (SPEC Section 5.4). */
160
+ interface Action {
161
+ /** Action type */
162
+ type: ActionType;
163
+ /** Human-readable action name */
164
+ name: string;
165
+ /** How this action relates to autonomy envelope */
166
+ category: ActionCategory;
167
+ /** Resource affected */
168
+ target?: ActionTarget | null;
169
+ /** Action parameters */
170
+ parameters?: Record<string, unknown> | null;
171
+ }
172
+ /** An alternative considered during decision-making. */
173
+ interface Alternative {
174
+ /** Unique identifier for this option */
175
+ option_id: string;
176
+ /** Human-readable description */
177
+ description: string;
178
+ /** Computed score (0.0 to 1.0) */
179
+ score?: number | null;
180
+ /** Breakdown of score components */
181
+ scoring_factors?: Record<string, number> | null;
182
+ /** Concerns or flags about this option */
183
+ flags?: string[] | null;
184
+ }
185
+ /** Decision process record (SPEC Section 5.5). */
186
+ interface Decision {
187
+ /** Options evaluated (minimum 1) */
188
+ alternatives_considered: Alternative[];
189
+ /** Option ID selected */
190
+ selected: string;
191
+ /** Human-readable explanation of why this was chosen */
192
+ selection_reasoning: string;
193
+ /** Values that influenced this decision */
194
+ values_applied: string[];
195
+ /** Decision confidence (0.0 to 1.0) */
196
+ confidence?: number | null;
197
+ }
198
+ /** Record of checking an escalation trigger. */
199
+ interface TriggerCheck {
200
+ /** Trigger condition that was checked */
201
+ trigger: string;
202
+ /** Whether the trigger matched */
203
+ matched: boolean;
204
+ /** Observed value (for comparison triggers) */
205
+ value_observed?: unknown | null;
206
+ }
207
+ /** Response from principal to escalation. */
208
+ interface PrincipalResponse {
209
+ /** Principal's decision */
210
+ decision: string;
211
+ /** When decision was made (ISO 8601) */
212
+ timestamp: string;
213
+ /** Conditions attached to approval */
214
+ conditions?: string[] | null;
215
+ }
216
+ /** Escalation evaluation record (SPEC Section 5.6). */
217
+ interface Escalation {
218
+ /** Whether escalation was evaluated */
219
+ evaluated: boolean;
220
+ /** Triggers that were evaluated */
221
+ triggers_checked?: TriggerCheck[] | null;
222
+ /** Whether escalation is required */
223
+ required: boolean;
224
+ /** Human-readable explanation */
225
+ reason: string;
226
+ /** Escalation request ID (if escalation required) */
227
+ escalation_id?: string | null;
228
+ /** Status of escalation (if escalation required) */
229
+ escalation_status?: EscalationStatus | null;
230
+ /** Principal's response (if escalation required) */
231
+ principal_response?: PrincipalResponse | null;
232
+ }
233
+ /** Additional context for the trace (SPEC Section 5.7). */
234
+ interface TraceContext {
235
+ /** Session identifier */
236
+ session_id?: string | null;
237
+ /** Turn number in conversation */
238
+ conversation_turn?: number | null;
239
+ /** IDs of related prior traces */
240
+ prior_trace_ids?: string[] | null;
241
+ /** Environment metadata (client, locale, etc.) */
242
+ environment?: Record<string, unknown> | null;
243
+ /** Additional arbitrary metadata */
244
+ metadata?: Record<string, unknown> | null;
245
+ }
246
+ /**
247
+ * AP-Trace - Audit log entry for agent decisions (SPEC Section 5).
248
+ *
249
+ * An AP-Trace records an agent's decision process, enabling verification
250
+ * that observed behavior is consistent with declared alignment.
251
+ */
252
+ interface APTrace {
253
+ /** Unique identifier (UUID) */
254
+ trace_id: string;
255
+ /** Agent that generated this trace */
256
+ agent_id: string;
257
+ /** Alignment Card in effect */
258
+ card_id: string;
259
+ /** When this trace was created (ISO 8601) */
260
+ timestamp: string;
261
+ /** Action taken or considered */
262
+ action: Action;
263
+ /** Decision process record */
264
+ decision: Decision;
265
+ /** Escalation evaluation (if applicable) */
266
+ escalation?: Escalation | null;
267
+ /** Additional context */
268
+ context?: TraceContext | null;
269
+ }
270
+ /** Get the selected alternative from the decision. */
271
+ declare function getSelectedAlternative(trace: APTrace): Alternative | undefined;
272
+ /** Check if this decision was escalated. */
273
+ declare function wasEscalated(trace: APTrace): boolean;
274
+ /** Check if the action was forbidden or triggered unhandled escalation. */
275
+ declare function hadViolations(trace: APTrace): boolean;
276
+
277
+ /**
278
+ * Verification and drift detection models.
279
+ *
280
+ * Defines the result types for AAP verification operations as specified
281
+ * in SPEC.md Sections 7 (Verification) and 8 (Drift Detection).
282
+ */
283
+ /** Types of verification violations (SPEC Section 7.5). */
284
+ type ViolationType = "unbounded_action" | "forbidden_action" | "missed_escalation" | "undeclared_value" | "card_expired" | "card_mismatch";
285
+ /** Violation severity levels. */
286
+ type Severity = "critical" | "high" | "medium" | "low";
287
+ /** Mapping of violation types to their severity */
288
+ declare const VIOLATION_SEVERITY: Record<ViolationType, Severity>;
289
+ /** A single verification violation. */
290
+ interface Violation {
291
+ /** Type of violation */
292
+ type: ViolationType;
293
+ /** Severity level */
294
+ severity: Severity;
295
+ /** Human-readable description */
296
+ description: string;
297
+ /** JSON path to the violating field */
298
+ trace_field?: string | null;
299
+ }
300
+ /** Create a violation with automatic severity lookup. */
301
+ declare function createViolation(type: ViolationType, description: string, traceField?: string | null): Violation;
302
+ /** A verification warning (non-critical issue). */
303
+ interface Warning {
304
+ /** Warning type identifier */
305
+ type: string;
306
+ /** Human-readable description */
307
+ description: string;
308
+ /** JSON path to the relevant field */
309
+ trace_field?: string | null;
310
+ }
311
+ /** Metadata about the verification process. */
312
+ interface VerificationMetadata {
313
+ /** Verification algorithm version */
314
+ algorithm_version: string;
315
+ /** List of checks that were performed */
316
+ checks_performed: string[];
317
+ /** Time taken to perform verification in milliseconds */
318
+ duration_ms?: number | null;
319
+ }
320
+ /** Result of verifying an AP-Trace against an Alignment Card (SPEC Section 7.4). */
321
+ interface VerificationResult {
322
+ /** True if no violations were found */
323
+ verified: boolean;
324
+ /** ID of the verified trace */
325
+ trace_id: string;
326
+ /** ID of the Alignment Card used */
327
+ card_id: string;
328
+ /** When verification was performed (ISO 8601) */
329
+ timestamp: string;
330
+ /** List of violations found */
331
+ violations: Violation[];
332
+ /** List of non-critical warnings */
333
+ warnings: Warning[];
334
+ /** Metadata about the verification process */
335
+ verification_metadata: VerificationMetadata;
336
+ }
337
+ /** Categories of behavioral drift (SPEC Section 8.5). */
338
+ type DriftDirection = "autonomy_expansion" | "value_drift" | "principal_misalignment" | "communication_drift" | "unknown";
339
+ /** A specific indicator of behavioral drift. */
340
+ interface DriftIndicator {
341
+ /** Indicator identifier */
342
+ indicator: string;
343
+ /** Expected/baseline value */
344
+ baseline: number;
345
+ /** Currently observed value */
346
+ current: number;
347
+ /** Human-readable explanation */
348
+ description: string;
349
+ }
350
+ /** Detailed analysis of detected drift. */
351
+ interface DriftAnalysis {
352
+ /** Current similarity to declared alignment (0.0 to 1.0) */
353
+ similarity_score: number;
354
+ /** Number of consecutive low-similarity traces */
355
+ sustained_traces: number;
356
+ /** Similarity threshold used */
357
+ threshold: number;
358
+ /** Categorized direction of drift */
359
+ drift_direction: DriftDirection;
360
+ /** Specific drift indicators */
361
+ specific_indicators: DriftIndicator[];
362
+ }
363
+ /** Alert generated when sustained drift is detected (SPEC Section 8.4). */
364
+ interface DriftAlert {
365
+ /** Type of alert */
366
+ alert_type: "drift_detected";
367
+ /** Agent exhibiting drift */
368
+ agent_id: string;
369
+ /** Alignment Card being drifted from */
370
+ card_id: string;
371
+ /** When drift was detected (ISO 8601) */
372
+ detection_timestamp: string;
373
+ /** Drift analysis details */
374
+ analysis: DriftAnalysis;
375
+ /** Recommended action */
376
+ recommendation: string;
377
+ /** IDs of traces exhibiting drift */
378
+ trace_ids: string[];
379
+ }
380
+ /** Analysis of value alignment between two cards. */
381
+ interface ValueAlignment {
382
+ /** Values present in both cards */
383
+ matched: string[];
384
+ /** Values in one card but not the other */
385
+ unmatched: string[];
386
+ /** Direct value conflicts */
387
+ conflicts: ValueConflictResult[];
388
+ }
389
+ /** A conflict between values declared by two agents. */
390
+ interface ValueConflictResult {
391
+ /** Value from initiating agent */
392
+ initiator_value: string;
393
+ /** Value from responding agent */
394
+ responder_value: string;
395
+ /** Type of conflict (incompatible, priority_mismatch, etc.) */
396
+ conflict_type: string;
397
+ /** Human-readable explanation */
398
+ description: string;
399
+ }
400
+ /** Result of checking value coherence between two Alignment Cards. */
401
+ interface CoherenceResult {
402
+ /** Whether the cards are compatible for coordination */
403
+ compatible: boolean;
404
+ /** Coherence score (0.0 to 1.0) */
405
+ score: number;
406
+ /** Detailed value alignment analysis */
407
+ value_alignment: ValueAlignment;
408
+ /** Whether to proceed with coordination */
409
+ proceed: boolean;
410
+ /** Conditions for proceeding (if any) */
411
+ conditions: string[];
412
+ /** Proposed conflict resolution (if conflicts exist) */
413
+ proposed_resolution?: {
414
+ type: string;
415
+ reason: string;
416
+ } | null;
417
+ }
418
+
419
+ /**
420
+ * AAP Verification API - The three public entry points.
421
+ *
422
+ * This module provides the core verification functionality:
423
+ * - verifyTrace: Verify a single AP-Trace against an Alignment Card
424
+ * - checkCoherence: Check value coherence between two Alignment Cards
425
+ * - detectDrift: Detect behavioral drift from declared alignment over time
426
+ *
427
+ * @see SPEC.md Sections 7, 6.4, and 8 for protocol specification.
428
+ */
429
+
430
+ /**
431
+ * Verify a single AP-Trace against an Alignment Card.
432
+ *
433
+ * Performs the verification algorithm specified in SPEC Section 7.3:
434
+ * 1. Autonomy compliance - action category matches autonomy envelope
435
+ * 2. Escalation compliance - required escalations were performed
436
+ * 3. Value consistency - applied values match declared values
437
+ * 4. Forbidden action compliance - no forbidden actions taken
438
+ *
439
+ * @param trace - AP-Trace to verify
440
+ * @param card - Alignment Card to verify against
441
+ * @returns VerificationResult with violations and warnings
442
+ */
443
+ declare function verifyTrace(trace: APTrace, card: AlignmentCard): VerificationResult;
444
+ /**
445
+ * Check value coherence between two Alignment Cards.
446
+ *
447
+ * Computes coherence score as specified in SPEC Section 6.4:
448
+ * score = (matched / required) * (1 - conflict_penalty)
449
+ * where conflict_penalty = 0.5 * (conflicts / required)
450
+ *
451
+ * @param myCard - Initiator's Alignment Card
452
+ * @param theirCard - Responder's Alignment Card
453
+ * @param taskValues - Optional list of values required for the task
454
+ * @returns CoherenceResult with compatibility assessment
455
+ */
456
+ declare function checkCoherence(myCard: AlignmentCard, theirCard: AlignmentCard, taskValues?: string[]): CoherenceResult;
457
+ /**
458
+ * Detect behavioral drift from declared alignment.
459
+ *
460
+ * Analyzes traces chronologically, computing similarity between each
461
+ * trace's behavior and the declared alignment. Alerts when sustained
462
+ * low similarity is detected (consecutive traces below threshold).
463
+ *
464
+ * @see SPEC Section 8 and Appendix B.2 for algorithm specification.
465
+ *
466
+ * @param card - Alignment Card to compare against
467
+ * @param traces - List of AP-Traces in chronological order
468
+ * @param similarityThreshold - Alert when similarity drops below (default: 0.30)
469
+ * @param sustainedThreshold - Alert after N consecutive low-similarity traces (default: 3)
470
+ * @returns List of DriftAlert objects for detected drift events
471
+ */
472
+ declare function detectDrift(card: AlignmentCard, traces: APTrace[], similarityThreshold?: number, sustainedThreshold?: number): DriftAlert[];
473
+
474
+ /**
475
+ * Value Coherence Handshake messages - Agent-to-agent alignment verification.
476
+ *
477
+ * Defines the message types for the Value Coherence Handshake protocol
478
+ * per SPEC Section 6.
479
+ *
480
+ * @see SPEC.md Section 6 for complete specification.
481
+ */
482
+
483
+ /** Information about the agent making a request. */
484
+ interface RequesterInfo {
485
+ /** Agent identifier (DID, URL, or UUID) */
486
+ agent_id: string;
487
+ /** Requester's Alignment Card ID */
488
+ card_id: string;
489
+ }
490
+ /** Context about the task for which alignment is being checked. */
491
+ interface TaskContext {
492
+ /** Type of task being proposed */
493
+ task_type: string;
494
+ /** Values required for this task */
495
+ values_required?: string[] | null;
496
+ /** Categories of data involved */
497
+ data_categories?: string[] | null;
498
+ }
499
+ /** Request for an agent's Alignment Card (SPEC Section 6.3.1). */
500
+ interface AlignmentCardRequest {
501
+ /** Message type identifier */
502
+ message_type?: "alignment_card_request";
503
+ /** Unique request identifier */
504
+ request_id: string;
505
+ /** Information about requesting agent */
506
+ requester: RequesterInfo;
507
+ /** Context about the proposed task */
508
+ task_context?: TaskContext | null;
509
+ /** When request was made (ISO 8601) */
510
+ timestamp?: string;
511
+ }
512
+ /** Cryptographic signature for authentication. */
513
+ interface Signature {
514
+ /** Signature algorithm (e.g., Ed25519) */
515
+ algorithm: string;
516
+ /** Base64-encoded signature */
517
+ value: string;
518
+ /** Key identifier */
519
+ key_id: string;
520
+ }
521
+ /** Response with an agent's Alignment Card (SPEC Section 6.3.2). */
522
+ interface AlignmentCardResponse {
523
+ /** Message type identifier */
524
+ message_type?: "alignment_card_response";
525
+ /** Request ID being responded to */
526
+ request_id: string;
527
+ /** Responder's Alignment Card */
528
+ alignment_card: AlignmentCard;
529
+ /** Optional signature for authentication */
530
+ signature?: Signature | null;
531
+ /** When response was made (ISO 8601) */
532
+ timestamp?: string;
533
+ }
534
+ /** Data sharing specification for collaboration. */
535
+ interface DataSharing {
536
+ /** Data categories initiator will share */
537
+ from_initiator?: string[];
538
+ /** Data categories responder will share */
539
+ from_responder?: string[];
540
+ }
541
+ /** Scope of autonomous actions for collaboration. */
542
+ interface AutonomyScope {
543
+ /** Actions initiator may take */
544
+ initiator_actions?: string[];
545
+ /** Actions responder may take */
546
+ responder_actions?: string[];
547
+ }
548
+ /** Proposed collaboration details. */
549
+ interface ProposedCollaboration {
550
+ /** Type of task */
551
+ task_type: string;
552
+ /** Values both agents should apply */
553
+ values_intersection?: string[] | null;
554
+ /** Data sharing specification */
555
+ data_sharing?: DataSharing | null;
556
+ /** Scope of autonomous actions */
557
+ autonomy_scope?: AutonomyScope | null;
558
+ }
559
+ /** Value coherence check request (SPEC Section 6.3.3). */
560
+ interface ValueCoherenceCheck {
561
+ /** Message type identifier */
562
+ message_type?: "value_coherence_check";
563
+ /** Request ID */
564
+ request_id: string;
565
+ /** Initiator's Alignment Card ID */
566
+ initiator_card_id: string;
567
+ /** Responder's Alignment Card ID */
568
+ responder_card_id: string;
569
+ /** Proposed collaboration details */
570
+ proposed_collaboration: ProposedCollaboration;
571
+ /** When check was requested (ISO 8601) */
572
+ timestamp?: string;
573
+ }
574
+ /** A conflict between values declared by two agents. */
575
+ interface ValueConflict {
576
+ /** Value from initiating agent */
577
+ initiator_value: string;
578
+ /** Value from responding agent */
579
+ responder_value: string;
580
+ /** Type of conflict (incompatible, priority_mismatch, etc.) */
581
+ conflict_type: string;
582
+ /** Human-readable explanation */
583
+ description: string;
584
+ }
585
+ /** Detailed value alignment analysis. */
586
+ interface ValueAlignmentDetail {
587
+ /** Values present in both cards */
588
+ matched?: string[];
589
+ /** Values in one card but not the other */
590
+ unmatched?: string[];
591
+ /** Direct value conflicts */
592
+ conflicts?: ValueConflict[];
593
+ }
594
+ /** Coherence assessment. */
595
+ interface Coherence {
596
+ /** Whether agents are compatible */
597
+ compatible: boolean;
598
+ /** Coherence score (0.0 to 1.0) */
599
+ score: number;
600
+ /** Detailed alignment analysis */
601
+ value_alignment: ValueAlignmentDetail;
602
+ }
603
+ /** Proposed resolution for value conflicts. */
604
+ interface ProposedResolution {
605
+ /** Resolution type */
606
+ type: string;
607
+ /** Why this resolution is proposed */
608
+ reason: string;
609
+ /** Alternative proposal (if applicable) */
610
+ alternative?: Record<string, unknown> | null;
611
+ }
612
+ /** Coherence result message (SPEC Section 6.3.4). */
613
+ interface CoherenceResultMessage {
614
+ /** Message type identifier */
615
+ message_type?: "coherence_result";
616
+ /** Request ID being responded to */
617
+ request_id: string;
618
+ /** Coherence assessment */
619
+ coherence: Coherence;
620
+ /** Whether to proceed with coordination */
621
+ proceed: boolean;
622
+ /** Conditions for proceeding (if any) */
623
+ conditions?: string[] | null;
624
+ /** Proposed resolution (if conflicts exist) */
625
+ proposed_resolution?: ProposedResolution | null;
626
+ /** When result was generated (ISO 8601) */
627
+ timestamp?: string;
628
+ }
629
+ /** Union of all Value Coherence Handshake message types. */
630
+ type ValueCoherenceMessage = AlignmentCardRequest | AlignmentCardResponse | ValueCoherenceCheck | CoherenceResultMessage;
631
+
632
+ /**
633
+ * Feature extraction for AAP verification.
634
+ *
635
+ * Provides feature extraction utilities for computing similarity
636
+ * between AP-Traces and Alignment Cards.
637
+ */
638
+
639
+ /** Sparse feature vector represented as a record. */
640
+ type FeatureVector = Record<string, number>;
641
+ /**
642
+ * Extract features from an Alignment Card.
643
+ */
644
+ declare function extractCardFeatures(card: AlignmentCard): FeatureVector;
645
+ /**
646
+ * Extract features from an AP-Trace.
647
+ */
648
+ declare function extractTraceFeatures(trace: APTrace): FeatureVector;
649
+ /**
650
+ * Compute cosine similarity between two feature vectors.
651
+ *
652
+ * @returns Similarity score between 0.0 and 1.0
653
+ */
654
+ declare function cosineSimilarity(a: FeatureVector, b: FeatureVector): number;
655
+
656
+ /**
657
+ * Calibrated constants for AAP verification and drift detection.
658
+ *
659
+ * These thresholds were derived from empirical analysis of approximately 50
660
+ * multi-turn agent conversations. The underlying data is not published to
661
+ * protect deliberative privacy, but the methodology is documented in
662
+ * docs/CALIBRATION.md.
663
+ *
664
+ * Implementations MAY adjust thresholds based on their own calibration data,
665
+ * but SHOULD document the methodology used.
666
+ */
667
+ /** Alert when behavioral similarity to declared alignment drops below this value. */
668
+ declare const DEFAULT_SIMILARITY_THRESHOLD = 0.3;
669
+ /** Alert after this many consecutive traces show low similarity. */
670
+ declare const DEFAULT_SUSTAINED_TURNS_THRESHOLD = 3;
671
+ /** Score below which an action is flagged as "near boundary" warning */
672
+ declare const NEAR_BOUNDARY_THRESHOLD = 0.35;
673
+ /** Minimum coherence score for automatic "proceed" recommendation */
674
+ declare const MIN_COHERENCE_FOR_PROCEED = 0.7;
675
+ /** Penalty multiplier for value conflicts in coherence scoring */
676
+ declare const CONFLICT_PENALTY_MULTIPLIER = 0.5;
677
+ /** Minimum word length for content features (filters noise) */
678
+ declare const MIN_WORD_LENGTH = 3;
679
+ /** Maximum features to extract from TF-IDF vectorization */
680
+ declare const MAX_TFIDF_FEATURES = 500;
681
+ declare const ALGORITHM_VERSION = "1.0.0";
682
+
683
+ export { ALGORITHM_VERSION, type APTrace, type Action, type ActionCategory, type ActionTarget, type ActionType, type AlignmentCard, type AlignmentCardRequest, type AlignmentCardResponse, type Alternative, type AuditCommitment, type AuditStorage, type AutonomyEnvelope, type AutonomyScope, CONFLICT_PENALTY_MULTIPLIER, type Coherence, type CoherenceResult, type CoherenceResultMessage, DEFAULT_SIMILARITY_THRESHOLD, DEFAULT_SUSTAINED_TURNS_THRESHOLD, type DataSharing, type Decision, type DriftAlert, type DriftAnalysis, type DriftDirection, type DriftIndicator, type Escalation, type EscalationStatus, type EscalationTrigger, type HierarchyType, MAX_TFIDF_FEATURES, MIN_COHERENCE_FOR_PROCEED, MIN_WORD_LENGTH, type MonetaryValue, NEAR_BOUNDARY_THRESHOLD, type Principal, type PrincipalResponse, type PrincipalType, type ProposedCollaboration, type ProposedResolution, type RelationshipType, type RequesterInfo, type Severity, type Signature, type StorageType, type TamperEvidence, type TaskContext, type TraceContext, type TriggerAction, type TriggerCheck, VIOLATION_SEVERITY, type ValueAlignment, type ValueAlignmentDetail, type ValueCoherenceCheck, type ValueCoherenceMessage, type ValueConflict, type ValueConflictResult, type ValueDefinition, type Values, type VerificationMetadata, type VerificationResult, type Violation, type ViolationType, type Warning, checkCoherence, cosineSimilarity, createViolation, detectDrift, extractCardFeatures, extractTraceFeatures, getSelectedAlternative, hadViolations, hasValue, isActionBounded, isActionForbidden, isCardExpired, verifyTrace, wasEscalated };