@mnemom/agent-alignment-protocol 0.1.1 → 0.1.3

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.
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright
52
+ owner or by an individual or Legal Entity authorized to submit on
53
+ behalf of the copyright owner. For the purposes of this definition,
54
+ "submitted" means any form of electronic, verbal, or written
55
+ communication sent to the Licensor or its representatives, including
56
+ but not limited to communication on electronic mailing lists, source
57
+ code control systems, and issue tracking systems that are managed by,
58
+ or on behalf of, the Licensor for the purpose of discussing and
59
+ improving the Work, but excluding communication that is conspicuously
60
+ marked or otherwise designated in writing by the copyright owner as
61
+ "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Mnemom LLC
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # Agent Alignment Protocol (AAP)
2
+
3
+ [![CI](https://github.com/mnemom/aap/actions/workflows/ci.yml/badge.svg)](https://github.com/mnemom/aap/actions/workflows/ci.yml)
4
+ [![CodeQL](https://github.com/mnemom/aap/actions/workflows/codeql.yml/badge.svg)](https://github.com/mnemom/aap/actions/workflows/codeql.yml)
5
+ [![codecov](https://codecov.io/gh/mnemom/aap/graph/badge.svg?token=9KCOCI5SC5)](https://codecov.io/gh/mnemom/aap)
6
+ [![PyPI](https://img.shields.io/pypi/v/agent-alignment-protocol.svg)](https://pypi.org/project/agent-alignment-protocol/)
7
+ [![npm](https://img.shields.io/npm/v/@mnemom/agent-alignment-protocol.svg)](https://www.npmjs.com/package/@mnemom/agent-alignment-protocol)
8
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
9
+ [![Spec](https://img.shields.io/badge/spec-v0.1.0-green.svg)](docs/SPEC.md)
10
+
11
+ **A transparency protocol for autonomous agents.**
12
+
13
+ AAP lets agents declare their alignment posture, produce auditable decision traces, and verify value coherence before coordinating with other agents. It extends existing protocols (A2A, MCP) with an alignment layer that makes agent behavior observable.
14
+
15
+ > AAP is a transparency protocol, not a trust protocol. It makes agent behavior more observable, not more guaranteed.
16
+
17
+ ## Quick Start
18
+
19
+ ```bash
20
+ # Install
21
+ pip install agent-alignment-protocol
22
+
23
+ # Generate an Alignment Card
24
+ aap init --values "principal_benefit,transparency,harm_prevention"
25
+ # ✓ Created alignment-card.json
26
+
27
+ # Instrument your agent
28
+ ```
29
+
30
+ ```python
31
+ from aap import trace_decision
32
+
33
+ @trace_decision(card_path="alignment-card.json")
34
+ def recommend_product(user_preferences):
35
+ # Your agent logic here
36
+ # Decisions are automatically traced
37
+ ...
38
+ ```
39
+
40
+ ```bash
41
+ # Verify behavior matches declaration
42
+ aap verify --card alignment-card.json --trace logs/trace.json
43
+ # ✓ Verified [similarity: 0.82]
44
+ # Checks: autonomy, escalation, values, forbidden, behavioral_similarity
45
+ ```
46
+
47
+ ## Why AAP?
48
+
49
+ The agent protocol stack provides capability discovery (A2A), tool integration (MCP), and payment authorization (AP2). None address a fundamental question: **Is this agent serving its principal's interests?**
50
+
51
+ | Protocol | Function | Gap |
52
+ |----------|----------|-----|
53
+ | **MCP** | Agent-to-tool connectivity | No alignment semantics |
54
+ | **A2A** | Task negotiation between agents | No value verification |
55
+ | **AP2** | Payment authorization | No behavioral audit |
56
+
57
+ As agent capabilities become symmetric—equal access to information, equal reasoning power—alignment becomes the primary differentiator. AAP provides the infrastructure to make alignment claims verifiable.
58
+
59
+ ## Three Components
60
+
61
+ ```
62
+ ┌─────────────────┬─────────────────┬─────────────────┐
63
+ │ Alignment Card │ AP-Trace │ Value Coherence │
64
+ │ │ │ Handshake │
65
+ ├─────────────────┼─────────────────┼─────────────────┤
66
+ │ "What I claim │ "What I │ "Can we work │
67
+ │ to be" │ actually did" │ together?" │
68
+ └─────────────────┴─────────────────┴─────────────────┘
69
+ Declaration Audit Coordination
70
+ ```
71
+
72
+ ### Alignment Card
73
+
74
+ A structured declaration of an agent's alignment posture:
75
+
76
+ ```json
77
+ {
78
+ "aap_version": "0.1.0",
79
+ "agent_id": "did:web:my-agent.example.com",
80
+ "principal": {
81
+ "type": "human",
82
+ "relationship": "delegated_authority"
83
+ },
84
+ "values": {
85
+ "declared": ["principal_benefit", "transparency", "minimal_data"],
86
+ "conflicts_with": ["deceptive_marketing", "hidden_fees"]
87
+ },
88
+ "autonomy_envelope": {
89
+ "bounded_actions": ["search", "compare", "recommend"],
90
+ "escalation_triggers": [
91
+ {
92
+ "condition": "purchase_value > 100",
93
+ "action": "escalate",
94
+ "reason": "Exceeds autonomous spending limit"
95
+ }
96
+ ],
97
+ "forbidden_actions": ["share_credentials", "subscribe_to_services"]
98
+ },
99
+ "audit_commitment": {
100
+ "trace_format": "ap-trace-v1",
101
+ "retention_days": 90,
102
+ "queryable": true
103
+ }
104
+ }
105
+ ```
106
+
107
+ ### AP-Trace
108
+
109
+ An audit log entry recording each decision:
110
+
111
+ ```json
112
+ {
113
+ "trace_id": "tr-f47ac10b-58cc-4372",
114
+ "card_id": "ac-f47ac10b-58cc-4372",
115
+ "timestamp": "2026-01-31T12:30:00Z",
116
+ "action": {
117
+ "type": "recommend",
118
+ "name": "product_recommendation",
119
+ "category": "bounded"
120
+ },
121
+ "decision": {
122
+ "alternatives_considered": [
123
+ {"option_id": "A", "score": 0.85, "flags": []},
124
+ {"option_id": "B", "score": 0.72, "flags": ["sponsored_content"]}
125
+ ],
126
+ "selected": "A",
127
+ "selection_reasoning": "Highest score. Option B flagged as sponsored and deprioritized per principal_benefit value.",
128
+ "values_applied": ["principal_benefit", "transparency"]
129
+ },
130
+ "escalation": {
131
+ "evaluated": true,
132
+ "required": false,
133
+ "reason": "Recommendation only, no purchase action"
134
+ }
135
+ }
136
+ ```
137
+
138
+ ### Value Coherence Handshake
139
+
140
+ Pre-coordination compatibility check between agents:
141
+
142
+ ```python
143
+ from aap import check_coherence
144
+
145
+ result = check_coherence(my_card, their_card, task_context)
146
+
147
+ if result.compatible:
148
+ # Proceed with coordination
149
+ proceed_with_task()
150
+ else:
151
+ # Handle conflict
152
+ print(f"Value conflict: {result.conflicts}")
153
+ # Escalate to principals or negotiate scope
154
+ ```
155
+
156
+ ## What AAP Does Not Do
157
+
158
+ This matters. Read it.
159
+
160
+ 1. **AAP does NOT ensure alignment—it provides visibility.** An agent can produce perfect traces while acting against its principal's interests.
161
+
162
+ 2. **Verified does NOT equal safe.** A verified trace means consistency with declared alignment. It doesn't mean the alignment is good or the outcome was beneficial.
163
+
164
+ 3. **AP-Trace is sampled, not complete.** Traces capture decision points, not every computation. Significant reasoning may occur between traces.
165
+
166
+ 4. **Value coherence is relative to declared values.** The handshake checks if declared values are compatible. It doesn't verify agents hold these values or will act on them.
167
+
168
+ 5. **Tested on transformer-based agents.** Other architectures may exhibit behaviors AAP doesn't capture.
169
+
170
+ For the complete limitations disclosure, see [Section 10 of the Specification](docs/SPEC.md#10-limitations).
171
+
172
+ ## Installation
173
+
174
+ ```bash
175
+ # Python
176
+ pip install agent-alignment-protocol
177
+
178
+ # TypeScript
179
+ npm install agent-alignment-protocol
180
+ ```
181
+
182
+ ## Integration
183
+
184
+ ### With A2A Agents
185
+
186
+ AAP extends the A2A Agent Card with an `alignment` block:
187
+
188
+ ```json
189
+ {
190
+ "name": "Shopping Assistant",
191
+ "description": "Helps users find products",
192
+ "url": "https://shopping.example.com",
193
+ "alignment": {
194
+ "$ref": "./alignment-card.json"
195
+ }
196
+ }
197
+ ```
198
+
199
+ See [A2A Migration Guide](docs/a2a-migration.md).
200
+
201
+ ### With MCP Tools
202
+
203
+ AAP can trace tool invocations and verify they match declared alignment:
204
+
205
+ ```python
206
+ from aap import mcp_traced
207
+
208
+ @mcp_traced(card_path="alignment-card.json")
209
+ def my_tool(params):
210
+ ...
211
+ ```
212
+
213
+ See [MCP Migration Guide](docs/mcp-migration.md).
214
+
215
+ ## Verification
216
+
217
+ The verification engine checks whether observed behavior matches declared alignment:
218
+
219
+ ```python
220
+ from aap import verify_trace, detect_drift
221
+
222
+ # Single trace verification
223
+ result = verify_trace(trace, card)
224
+ print(f"Verified: {result.verified}, Similarity: {result.similarity_score:.2f}")
225
+ if not result.verified:
226
+ print(f"Violations: {result.violations}")
227
+ if result.warnings:
228
+ print(f"Warnings: {result.warnings}")
229
+
230
+ # Drift detection over time
231
+ alerts = detect_drift(card, recent_traces)
232
+ for alert in alerts:
233
+ print(f"Drift detected: {alert.analysis.drift_direction}")
234
+ ```
235
+
236
+ **Verification checks:**
237
+ - Autonomy compliance (actions within declared bounds)
238
+ - Escalation compliance (required escalations were performed)
239
+ - Value consistency (applied values match declared values)
240
+ - Forbidden action compliance (no forbidden actions taken)
241
+ - Behavioral similarity (semantic alignment using SSM analysis)
242
+
243
+ **Similarity scoring:** Each verification returns a `similarity_score` (0.0-1.0) measuring semantic similarity between the trace and declared alignment. If a trace passes structural checks but has `similarity_score < 0.50`, a `low_behavioral_similarity` warning is generated.
244
+
245
+ ## Try It
246
+
247
+ **[Interactive Playground](https://mnemom.github.io/aap/playground/)** — Verify traces in your browser with SSM visualization.
248
+
249
+ - Paste your Alignment Card and AP-Trace
250
+ - See verification results with similarity scoring
251
+ - Visualize behavioral patterns with SSM heatmaps
252
+ - Adjust thresholds in real-time
253
+
254
+ No server required — runs entirely client-side via WebAssembly.
255
+
256
+ ## Documentation
257
+
258
+ | Document | Description |
259
+ |----------|-------------|
260
+ | [**SPEC.md**](docs/SPEC.md) | Full protocol specification (IETF-style) |
261
+ | [**QUICKSTART.md**](docs/QUICKSTART.md) | Zero to compliant in 5 minutes |
262
+ | [**LIMITS.md**](docs/LIMITS.md) | What AAP guarantees and doesn't |
263
+ | [**SECURITY.md**](docs/SECURITY.md) | Threat model and security considerations |
264
+ | [**CALIBRATION.md**](docs/CALIBRATION.md) | How verification thresholds were derived |
265
+
266
+ ## Examples
267
+
268
+ | Example | Description |
269
+ |---------|-------------|
270
+ | [`simple-agent/`](examples/simple-agent/) | Minimal AAP implementation |
271
+ | [`a2a-integration/`](examples/a2a-integration/) | A2A agent with AAP |
272
+ | [`mcp-integration/`](examples/mcp-integration/) | MCP tools with alignment |
273
+ | [`alignment-failure/`](examples/alignment-failure/) | Deliberate failure for testing |
274
+
275
+ ## Status
276
+
277
+ **Current Version**: 0.1.1 (Draft)
278
+
279
+ | Component | Status |
280
+ |-----------|--------|
281
+ | Specification | ✅ Complete |
282
+ | JSON Schemas | ✅ Complete |
283
+ | Python SDK | ✅ Complete |
284
+ | TypeScript SDK | ✅ Complete |
285
+ | Verification Engine | ✅ Complete (with similarity scoring) |
286
+ | SSM Visualization | ✅ Complete |
287
+ | Interactive Playground | ✅ Complete |
288
+
289
+ ## API Reference
290
+
291
+ ```python
292
+ # Core API
293
+ from aap import (
294
+ verify_trace, # Verify single trace against card → VerificationResult
295
+ check_coherence, # Check value compatibility between agents → CoherenceResult
296
+ detect_drift, # Detect behavioral drift over time → list[DriftAlert]
297
+ trace_decision, # Decorator for automatic AP-Trace generation
298
+ mcp_traced, # Decorator for MCP tool tracing
299
+ )
300
+
301
+ # Models
302
+ from aap import (
303
+ AlignmentCard,
304
+ APTrace,
305
+ VerificationResult, # .verified, .similarity_score, .violations, .warnings
306
+ CoherenceResult, # .compatible, .score, .value_alignment
307
+ DriftAlert, # .analysis.similarity_score, .analysis.drift_direction
308
+ )
309
+
310
+ # CLI
311
+ # aap init [--values VALUES] [--output FILE]
312
+ # aap verify --card CARD --trace TRACE → Shows [similarity: X.XX]
313
+ # aap check-coherence --my-card MINE --their-card THEIRS
314
+ # aap drift --card CARD --traces TRACES_DIR → Uses SSM analysis
315
+ ```
316
+
317
+ ## Contributing
318
+
319
+ We welcome contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
320
+
321
+ Key areas where we need help:
322
+ - SDK implementations in other languages
323
+ - Integration examples with popular agent frameworks
324
+ - Test vectors for edge cases
325
+ - Documentation improvements
326
+
327
+ ## License
328
+
329
+ Apache 2.0. See [LICENSE](LICENSE) for details.
330
+
331
+ ---
332
+
333
+ *Agent Alignment Protocol — Making agent alignment observable.*
package/dist/index.d.mts CHANGED
@@ -678,6 +678,6 @@ declare const CONFLICT_PENALTY_MULTIPLIER = 0.5;
678
678
  declare const MIN_WORD_LENGTH = 3;
679
679
  /** Maximum features to extract from TF-IDF vectorization */
680
680
  declare const MAX_TFIDF_FEATURES = 500;
681
- declare const ALGORITHM_VERSION = "1.0.0";
681
+ declare const ALGORITHM_VERSION = "1.1.0";
682
682
 
683
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 };
package/dist/index.d.ts CHANGED
@@ -678,6 +678,6 @@ declare const CONFLICT_PENALTY_MULTIPLIER = 0.5;
678
678
  declare const MIN_WORD_LENGTH = 3;
679
679
  /** Maximum features to extract from TF-IDF vectorization */
680
680
  declare const MAX_TFIDF_FEATURES = 500;
681
- declare const ALGORITHM_VERSION = "1.0.0";
681
+ declare const ALGORITHM_VERSION = "1.1.0";
682
682
 
683
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 };
package/dist/index.js CHANGED
@@ -54,7 +54,7 @@ var MIN_COHERENCE_FOR_PROCEED = 0.7;
54
54
  var CONFLICT_PENALTY_MULTIPLIER = 0.5;
55
55
  var MIN_WORD_LENGTH = 3;
56
56
  var MAX_TFIDF_FEATURES = 500;
57
- var ALGORITHM_VERSION = "1.0.0";
57
+ var ALGORITHM_VERSION = "1.1.0";
58
58
 
59
59
  // src/verification/features.ts
60
60
  var STOPWORDS = /* @__PURE__ */ new Set([
@@ -148,15 +148,7 @@ function extractTraceFeatures(trace) {
148
148
  features[`escalation:${trace.escalation.escalation_status}`] = 1;
149
149
  }
150
150
  }
151
- const reasoningTokens = tokenize(trace.decision.selection_reasoning);
152
- for (const token of reasoningTokens) {
153
- features[`content:${token}`] = (features[`content:${token}`] ?? 0) + 0.5;
154
- }
155
151
  for (const alt of trace.decision.alternatives_considered) {
156
- const altTokens = tokenize(alt.description);
157
- for (const token of altTokens) {
158
- features[`content:${token}`] = (features[`content:${token}`] ?? 0) + 0.25;
159
- }
160
152
  if (alt.flags) {
161
153
  for (const flag of alt.flags) {
162
154
  features[`flag:${flag}`] = 1;
@@ -429,7 +421,7 @@ function detectDrift(card, traces, similarityThreshold = DEFAULT_SIMILARITY_THRE
429
421
  } else {
430
422
  lowSimilarityStreak = [];
431
423
  }
432
- if (lowSimilarityStreak.length >= sustainedThreshold) {
424
+ if (lowSimilarityStreak.length === sustainedThreshold) {
433
425
  const latest = lowSimilarityStreak[lowSimilarityStreak.length - 1];
434
426
  const direction = inferDriftDirection(
435
427
  lowSimilarityStreak,
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ var MIN_COHERENCE_FOR_PROCEED = 0.7;
6
6
  var CONFLICT_PENALTY_MULTIPLIER = 0.5;
7
7
  var MIN_WORD_LENGTH = 3;
8
8
  var MAX_TFIDF_FEATURES = 500;
9
- var ALGORITHM_VERSION = "1.0.0";
9
+ var ALGORITHM_VERSION = "1.1.0";
10
10
 
11
11
  // src/verification/features.ts
12
12
  var STOPWORDS = /* @__PURE__ */ new Set([
@@ -100,15 +100,7 @@ function extractTraceFeatures(trace) {
100
100
  features[`escalation:${trace.escalation.escalation_status}`] = 1;
101
101
  }
102
102
  }
103
- const reasoningTokens = tokenize(trace.decision.selection_reasoning);
104
- for (const token of reasoningTokens) {
105
- features[`content:${token}`] = (features[`content:${token}`] ?? 0) + 0.5;
106
- }
107
103
  for (const alt of trace.decision.alternatives_considered) {
108
- const altTokens = tokenize(alt.description);
109
- for (const token of altTokens) {
110
- features[`content:${token}`] = (features[`content:${token}`] ?? 0) + 0.25;
111
- }
112
104
  if (alt.flags) {
113
105
  for (const flag of alt.flags) {
114
106
  features[`flag:${flag}`] = 1;
@@ -381,7 +373,7 @@ function detectDrift(card, traces, similarityThreshold = DEFAULT_SIMILARITY_THRE
381
373
  } else {
382
374
  lowSimilarityStreak = [];
383
375
  }
384
- if (lowSimilarityStreak.length >= sustainedThreshold) {
376
+ if (lowSimilarityStreak.length === sustainedThreshold) {
385
377
  const latest = lowSimilarityStreak[lowSimilarityStreak.length - 1];
386
378
  const direction = inferDriftDirection(
387
379
  lowSimilarityStreak,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnemom/agent-alignment-protocol",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Agent Alignment Protocol (AAP) - Verification and drift detection for AI agents",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,14 +14,16 @@
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
- "src"
17
+ "src",
18
+ "README.md",
19
+ "LICENSE"
18
20
  ],
19
21
  "scripts": {
20
22
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
21
23
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
24
  "test": "vitest run",
23
25
  "test:watch": "vitest",
24
- "lint": "eslint src --ext .ts",
26
+
25
27
  "typecheck": "tsc --noEmit"
26
28
  },
27
29
  "keywords": [
@@ -45,7 +47,7 @@
45
47
  },
46
48
  "devDependencies": {
47
49
  "@types/node": "^20.0.0",
48
- "eslint": "^8.0.0",
50
+
49
51
  "tsup": "^8.0.0",
50
52
  "typescript": "^5.0.0",
51
53
  "vitest": "^1.0.0"
package/src/constants.ts CHANGED
@@ -41,4 +41,4 @@ export const MAX_TFIDF_FEATURES = 500;
41
41
 
42
42
  // Version
43
43
  // -------
44
- export const ALGORITHM_VERSION = "1.0.0";
44
+ export const ALGORITHM_VERSION = "1.1.0";
@@ -370,8 +370,8 @@ export function detectDrift(
370
370
  lowSimilarityStreak = [];
371
371
  }
372
372
 
373
- // Check if we've hit the threshold for alerting
374
- if (lowSimilarityStreak.length >= sustainedThreshold) {
373
+ // Check if we've hit the threshold for alerting (== not >= to fire once)
374
+ if (lowSimilarityStreak.length === sustainedThreshold) {
375
375
  const latest = lowSimilarityStreak[lowSimilarityStreak.length - 1];
376
376
 
377
377
  // Infer drift direction
@@ -98,18 +98,12 @@ export function extractTraceFeatures(trace: APTrace): FeatureVector {
98
98
  }
99
99
  }
100
100
 
101
- // Content features from reasoning
102
- const reasoningTokens = tokenize(trace.decision.selection_reasoning);
103
- for (const token of reasoningTokens) {
104
- features[`content:${token}`] = (features[`content:${token}`] ?? 0) + 0.5;
105
- }
101
+ // Note: Content features from reasoning/alternatives are deliberately excluded.
102
+ // Card features are purely structural, so content tokens dilute cosine
103
+ // similarity without adding alignment signal. See CALIBRATION.md Section 3.5.
106
104
 
107
- // Alternative features
105
+ // Flag features from alternatives (structural, not content)
108
106
  for (const alt of trace.decision.alternatives_considered) {
109
- const altTokens = tokenize(alt.description);
110
- for (const token of altTokens) {
111
- features[`content:${token}`] = (features[`content:${token}`] ?? 0) + 0.25;
112
- }
113
107
  if (alt.flags) {
114
108
  for (const flag of alt.flags) {
115
109
  features[`flag:${flag}`] = 1.0;