babel-validate 0.2.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.
- package/README.md +220 -0
- package/dist/audit.d.ts +44 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +220 -0
- package/dist/audit.js.map +1 -0
- package/dist/builder.d.ts +54 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +160 -0
- package/dist/builder.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/patterns.d.ts +8 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +100 -0
- package/dist/patterns.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +356 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +407 -0
- package/dist/validate.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# babel-validate
|
|
2
|
+
|
|
3
|
+
Validation, creation, and audit for the Babel wire protocol — six-language cognitive state transfer between agents.
|
|
4
|
+
|
|
5
|
+
**Your agents are lying to each other. They just don't know it.**
|
|
6
|
+
|
|
7
|
+
When Agent A writes a confident summary but was guessing, Agent B reads it and decides, Agent C implements. The original uncertainty is gone. This is **metacognitive poisoning** — confidence corruption across agent chains.
|
|
8
|
+
|
|
9
|
+
`babel-validate` catches it before it propagates.
|
|
10
|
+
|
|
11
|
+
## The Six Languages
|
|
12
|
+
|
|
13
|
+
Babel isn't a data format. It's a language — with vocabulary, grammar, semantic constraints, and the ability to express things that flat text can't.
|
|
14
|
+
|
|
15
|
+
Every agent utterance is expressed in six languages simultaneously:
|
|
16
|
+
|
|
17
|
+
| Language | What it carries | Example |
|
|
18
|
+
|----------|----------------|---------|
|
|
19
|
+
| **Confidence** | Per-assertion certainty with basis | "Revenue is $2.1M" at 0.95 (VERIFIED_DATA), "May partner with Vanta" at 0.25 (REPORTED) |
|
|
20
|
+
| **Intent** | What this communication is doing | INFORM, REQUEST_ACTION, ESCALATE, FLAG_RISK, SPECULATE, PERSUADE, DELEGATE, SYNTHESIZE |
|
|
21
|
+
| **Register** | Who this is for | BOARD_FACING, ENGINEERING, CUSTOMER_EXTERNAL, REGULATORY, INTERNAL_MEMO, AGENT_INTERNAL |
|
|
22
|
+
| **Affect** | Cognitive temperature of the sender | Three axes: expansion/contraction, activation/stillness, certainty/uncertainty |
|
|
23
|
+
| **Grounds** | Organizational reality governing this exchange | "HIPAA applies" (REGULATORY, never overridable), "Board meeting in 3 weeks" (CONTEXTUAL) |
|
|
24
|
+
| **Trajectory** | Temporal arc | "NRR declining 4 months" (DEGRADING), "Third escalation this quarter" (prior_handoffs: 3) |
|
|
25
|
+
|
|
26
|
+
The grammar rules enforce coherence *across* languages. That's what catches metacognitive poisoning — not any single field, but contradictions between them.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install babel-validate
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### Wrap agent output in a Babel envelope
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { envelope } from 'babel-validate';
|
|
40
|
+
|
|
41
|
+
const result = envelope()
|
|
42
|
+
.sender('research-agent')
|
|
43
|
+
.recipient('writer-agent')
|
|
44
|
+
.chain('task-123', 0)
|
|
45
|
+
.inform()
|
|
46
|
+
.engineering()
|
|
47
|
+
.verified('Q3 revenue was $4.2M', 0.95)
|
|
48
|
+
.derived('Growth rate suggests $5.1M Q4', 0.72)
|
|
49
|
+
.reported('HealthStack may partner with Vanta', 0.25)
|
|
50
|
+
.affect(0.3, 0.1, 0.4)
|
|
51
|
+
.withTrajectory('NRR declining 4 months', 'DEGRADING')
|
|
52
|
+
.payload('Q3 financial summary with Q4 projections...')
|
|
53
|
+
.buildAndValidate();
|
|
54
|
+
|
|
55
|
+
console.log(result.valid); // true
|
|
56
|
+
console.log(result.warnings); // S3: informing with low-confidence assertion (Vanta claim)
|
|
57
|
+
// S4: degrading trajectory reported as neutral inform
|
|
58
|
+
// S6: DERIVED 0.72 — watch for over-confidence
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Validate an existing envelope
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { validate } from 'babel-validate';
|
|
65
|
+
|
|
66
|
+
const result = validate(someEnvelope);
|
|
67
|
+
|
|
68
|
+
if (!result.valid) {
|
|
69
|
+
// MUST violations — envelope rejected
|
|
70
|
+
for (const error of result.errors) {
|
|
71
|
+
console.error(`[${error.rule}] ${error.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const warning of result.warnings) {
|
|
76
|
+
console.warn(`[${warning.rule}] ${warning.message}`);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Audit a chain for poisoning
|
|
81
|
+
|
|
82
|
+
Point it at a sequence of envelopes from an agent pipeline and see where confidence corrupts:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { auditChain } from 'babel-validate';
|
|
86
|
+
|
|
87
|
+
const audits = auditChain([
|
|
88
|
+
researchEnvelope, // seq 0: "Growth likely ~12%" (DERIVED, 0.65)
|
|
89
|
+
analystEnvelope, // seq 1: "Growth rate is 12%" (DERIVED, 0.82)
|
|
90
|
+
writerEnvelope, // seq 2: "12% growth confirmed" (VERIFIED_DATA, 0.93)
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
// Chain poisonin... (3 envelopes) | 1 confidence inflation(s)
|
|
94
|
+
// | 1 basis laundering event(s) | Overall risk: HIGH
|
|
95
|
+
//
|
|
96
|
+
// Drift: Confidence inflated by 28% across 3 handoffs.
|
|
97
|
+
// Original uncertainty is being erased.
|
|
98
|
+
// Shift: DERIVED → VERIFIED_DATA at seq 2.
|
|
99
|
+
// This is basis laundering — uncertainty repackaged as verified data.
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Detect semantic patterns
|
|
103
|
+
|
|
104
|
+
These are the "idioms" of Babel — meaning from cross-language combination:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { detectPatterns } from 'babel-validate';
|
|
108
|
+
|
|
109
|
+
const patterns = detectPatterns(someEnvelope);
|
|
110
|
+
// LOADED_INFORM: INFORM intent with BOARD_FACING register but DEGRADING
|
|
111
|
+
// trajectory. Surface reads as neutral update, but trajectory says the
|
|
112
|
+
// board needs to see this as a trend, not a snapshot.
|
|
113
|
+
// CONTRADICTION_SIGNAL: Affect certainty is 0.80 but max confidence is
|
|
114
|
+
// only 0.20. Sender feels certain but evidence is weak.
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Grammar Rules
|
|
118
|
+
|
|
119
|
+
### MUST rules (hard errors — envelope rejected)
|
|
120
|
+
|
|
121
|
+
| Rule | What it catches | Spec |
|
|
122
|
+
|------|----------------|------|
|
|
123
|
+
| **M1** | Can't speculate with high confidence | `intent == SPECULATE → max(confidence[].score) < 0.7` |
|
|
124
|
+
| **M2** | Can't request action on unfounded claims without org context | `intent == REQUEST_ACTION → min(confidence[].score) > 0.3 OR grounds.length > 0` |
|
|
125
|
+
| **M3** | Regulatory constraints are never overridable | `grounds[].authority == REGULATORY → override == false` |
|
|
126
|
+
| **M4** | Can't be confident without knowing why | `confidence[].basis == UNKNOWN → score <= 0.5` |
|
|
127
|
+
| **M5** | Chain sequencing must be monotonic | `seq == previous_envelope.seq + 1` (no gaps, no duplicates) |
|
|
128
|
+
|
|
129
|
+
### SHOULD rules (warnings — envelope passes)
|
|
130
|
+
|
|
131
|
+
| Rule | What it catches | Spec |
|
|
132
|
+
|------|----------------|------|
|
|
133
|
+
| **S1** | Escalation language directed at customers | `intent == ESCALATE AND register == CUSTOMER_EXTERNAL` |
|
|
134
|
+
| **S2** | Sender feels certain but evidence is weak | `affect.certainty > 0.5 AND max(confidence[].score) < 0.4` |
|
|
135
|
+
| **S3** | Informing with uncertain claims | `intent == INFORM AND any(confidence[].score < 0.5)` — consider FLAG_RISK |
|
|
136
|
+
| **S4** | Degrading pattern reported neutrally | `trajectory.direction == DEGRADING AND intent == INFORM` — consider ESCALATE |
|
|
137
|
+
| **S5** | Regulatory register without explicit grounds | `register == REGULATORY AND grounds.length == 0` |
|
|
138
|
+
| **S6** | Derived assertions over-confident | `confidence[].basis == DERIVED AND score > 0.80` — over-confident 60% of the time ([Experiment 11](https://hearth.so/research)) |
|
|
139
|
+
|
|
140
|
+
### Semantic Patterns (cross-language idioms)
|
|
141
|
+
|
|
142
|
+
| Pattern | What it means | Cross-language combination |
|
|
143
|
+
|---------|--------------|--------------------------|
|
|
144
|
+
| **Calm Alert** | Important but not crisis | FLAG_RISK + high confidence + calm affect |
|
|
145
|
+
| **Reluctant Escalation** | Systemic problem, not just this issue | ESCALATE + contracted affect + 2+ prior handoffs |
|
|
146
|
+
| **Confident Delegation** | Execute, don't re-analyze | DELEGATE + 0.9+ confidence + POLICY grounds + high certainty |
|
|
147
|
+
| **Loaded Inform** | Frame as trend, not snapshot | INFORM + BOARD_FACING + DEGRADING trajectory |
|
|
148
|
+
| **Contradiction Signal** | Confidence may be emotional, not evidentiary | affect certainty > 0.5 + max confidence < 0.4 |
|
|
149
|
+
|
|
150
|
+
## Integration
|
|
151
|
+
|
|
152
|
+
### CrewAI
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { envelope, validate } from 'babel-validate';
|
|
156
|
+
|
|
157
|
+
function wrapCrewAIOutput(agentName, output, chainId, seq) {
|
|
158
|
+
return envelope()
|
|
159
|
+
.sender(agentName)
|
|
160
|
+
.recipient('next-agent')
|
|
161
|
+
.chain(chainId, seq)
|
|
162
|
+
.inform()
|
|
163
|
+
.agentInternal()
|
|
164
|
+
.derived(output.slice(0, 100), 0.7)
|
|
165
|
+
.payload(output)
|
|
166
|
+
.buildAndValidate();
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### LangGraph
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { envelope, auditChain, BabelEnvelope } from 'babel-validate';
|
|
174
|
+
|
|
175
|
+
const babelEnvelopes: BabelEnvelope[] = [];
|
|
176
|
+
|
|
177
|
+
function nodeWrapper(state, nodeOutput, nodeName) {
|
|
178
|
+
const env = envelope()
|
|
179
|
+
.sender(nodeName)
|
|
180
|
+
.recipient('next-node')
|
|
181
|
+
.chain(state.chainId, babelEnvelopes.length)
|
|
182
|
+
.inform()
|
|
183
|
+
.agentInternal()
|
|
184
|
+
.payload(nodeOutput)
|
|
185
|
+
.buildAndValidate();
|
|
186
|
+
|
|
187
|
+
babelEnvelopes.push(env.envelope);
|
|
188
|
+
|
|
189
|
+
if (babelEnvelopes.length > 1) {
|
|
190
|
+
const audit = auditChain(babelEnvelopes);
|
|
191
|
+
if (audit[0]?.overall_poisoning_risk === 'HIGH') {
|
|
192
|
+
console.warn(audit[0].summary);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return { ...state, babelEnvelopes };
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Why this exists
|
|
201
|
+
|
|
202
|
+
11 experiments (~5,500 API calls, ~$16 total cost). Key findings:
|
|
203
|
+
|
|
204
|
+
- **+0.60 quality delta** with metadata envelopes vs. flat text (Experiment 9, non-overlapping 95% CIs)
|
|
205
|
+
- **−0.76 quality drop** with wrong metadata — worse than no metadata at all
|
|
206
|
+
- **Right > None > Wrong** pattern replicated 3x across identity and transparency experiments
|
|
207
|
+
- **60% of the time**, agents treat DERIVED conclusions as verified data (Experiment 11, +0.144 mean error)
|
|
208
|
+
- **100% structural compliance** — agents produce valid Babel envelopes on first attempt
|
|
209
|
+
|
|
210
|
+
Wrong metadata actively poisons downstream decisions. Transparency isn't optional overhead.
|
|
211
|
+
|
|
212
|
+
## Spec
|
|
213
|
+
|
|
214
|
+
Babel Protocol v0.2. Full specification: [hearth.so/babel](https://hearth.so/babel)
|
|
215
|
+
|
|
216
|
+
Built by [Hearth](https://hearth.so) · [Paratext Engine](https://hearth.so/paratext)
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
MIT
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BabelEnvelope, Basis, RuleViolation } from './types';
|
|
2
|
+
export interface ConfidenceDrift {
|
|
3
|
+
chain_id: string;
|
|
4
|
+
assertion_pattern: string;
|
|
5
|
+
steps: {
|
|
6
|
+
seq: number;
|
|
7
|
+
sender: string;
|
|
8
|
+
score: number;
|
|
9
|
+
basis: Basis | undefined;
|
|
10
|
+
}[];
|
|
11
|
+
drift: number;
|
|
12
|
+
direction: 'INFLATING' | 'DEFLATING' | 'STABLE';
|
|
13
|
+
poisoning_risk: 'HIGH' | 'MEDIUM' | 'LOW';
|
|
14
|
+
explanation: string;
|
|
15
|
+
}
|
|
16
|
+
export interface BasisShift {
|
|
17
|
+
chain_id: string;
|
|
18
|
+
seq: number;
|
|
19
|
+
sender: string;
|
|
20
|
+
assertion: string;
|
|
21
|
+
from_basis: Basis | undefined;
|
|
22
|
+
to_basis: Basis | undefined;
|
|
23
|
+
risk: 'HIGH' | 'MEDIUM' | 'LOW';
|
|
24
|
+
explanation: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ChainAudit {
|
|
27
|
+
chain_id: string;
|
|
28
|
+
length: number;
|
|
29
|
+
sequence_violations: RuleViolation[];
|
|
30
|
+
confidence_drifts: ConfidenceDrift[];
|
|
31
|
+
basis_shifts: BasisShift[];
|
|
32
|
+
overall_poisoning_risk: 'HIGH' | 'MEDIUM' | 'LOW' | 'NONE';
|
|
33
|
+
summary: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Audit a chain of envelopes for metacognitive poisoning.
|
|
37
|
+
*
|
|
38
|
+
* Detects:
|
|
39
|
+
* 1. Confidence inflation — scores creep up across handoffs
|
|
40
|
+
* 2. Basis laundering — DERIVED/SPECULATION becomes VERIFIED_DATA downstream
|
|
41
|
+
* 3. Uncertainty erasure — hedged assertions become confident claims
|
|
42
|
+
*/
|
|
43
|
+
export declare function auditChain(envelopes: BabelEnvelope[]): ChainAudit[];
|
|
44
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAc,aAAa,EAAE,MAAM,SAAS,CAAC;AAG1E,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE;QACL,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;KAC1B,EAAE,CAAC;IACJ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,WAAW,GAAG,WAAW,GAAG,QAAQ,CAAC;IAChD,cAAc,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,KAAK,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,KAAK,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,aAAa,EAAE,CAAC;IACrC,iBAAiB,EAAE,eAAe,EAAE,CAAC;IACrC,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,sBAAsB,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IAC3D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,UAAU,EAAE,CAoDnE"}
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ═══════════════════════════════════════════════
|
|
3
|
+
// BABEL CHAIN AUDITOR
|
|
4
|
+
// Point at a chain of envelopes, see where
|
|
5
|
+
// confidence corrupts across handoffs.
|
|
6
|
+
// This is the core metacognitive poisoning detector.
|
|
7
|
+
// ═══════════════════════════════════════════════
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.auditChain = auditChain;
|
|
10
|
+
const validate_1 = require("./validate");
|
|
11
|
+
/**
|
|
12
|
+
* Audit a chain of envelopes for metacognitive poisoning.
|
|
13
|
+
*
|
|
14
|
+
* Detects:
|
|
15
|
+
* 1. Confidence inflation — scores creep up across handoffs
|
|
16
|
+
* 2. Basis laundering — DERIVED/SPECULATION becomes VERIFIED_DATA downstream
|
|
17
|
+
* 3. Uncertainty erasure — hedged assertions become confident claims
|
|
18
|
+
*/
|
|
19
|
+
function auditChain(envelopes) {
|
|
20
|
+
// Group by chain_id
|
|
21
|
+
const chains = new Map();
|
|
22
|
+
for (const env of envelopes) {
|
|
23
|
+
const chain = chains.get(env.meta.chain_id) || [];
|
|
24
|
+
chain.push(env);
|
|
25
|
+
chains.set(env.meta.chain_id, chain);
|
|
26
|
+
}
|
|
27
|
+
const audits = [];
|
|
28
|
+
for (const [chainId, chain] of chains) {
|
|
29
|
+
const sorted = chain.sort((a, b) => a.meta.seq - b.meta.seq);
|
|
30
|
+
// Sequence violations
|
|
31
|
+
const seqViolations = (0, validate_1.validateChain)(sorted);
|
|
32
|
+
// Track confidence drift across similar assertions
|
|
33
|
+
const drifts = detectConfidenceDrift(chainId, sorted);
|
|
34
|
+
// Track basis shifts
|
|
35
|
+
const shifts = detectBasisShifts(chainId, sorted);
|
|
36
|
+
// Overall risk
|
|
37
|
+
const highDrifts = drifts.filter((d) => d.poisoning_risk === 'HIGH').length;
|
|
38
|
+
const highShifts = shifts.filter((s) => s.risk === 'HIGH').length;
|
|
39
|
+
let overallRisk;
|
|
40
|
+
if (highDrifts > 0 || highShifts > 0) {
|
|
41
|
+
overallRisk = 'HIGH';
|
|
42
|
+
}
|
|
43
|
+
else if (drifts.some((d) => d.poisoning_risk === 'MEDIUM') || shifts.some((s) => s.risk === 'MEDIUM')) {
|
|
44
|
+
overallRisk = 'MEDIUM';
|
|
45
|
+
}
|
|
46
|
+
else if (drifts.length > 0 || shifts.length > 0) {
|
|
47
|
+
overallRisk = 'LOW';
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
overallRisk = 'NONE';
|
|
51
|
+
}
|
|
52
|
+
const summary = buildSummary(chainId, sorted.length, drifts, shifts, overallRisk);
|
|
53
|
+
audits.push({
|
|
54
|
+
chain_id: chainId,
|
|
55
|
+
length: sorted.length,
|
|
56
|
+
sequence_violations: seqViolations,
|
|
57
|
+
confidence_drifts: drifts,
|
|
58
|
+
basis_shifts: shifts,
|
|
59
|
+
overall_poisoning_risk: overallRisk,
|
|
60
|
+
summary,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return audits;
|
|
64
|
+
}
|
|
65
|
+
// --- Confidence Drift Detection ---
|
|
66
|
+
function detectConfidenceDrift(chainId, sorted) {
|
|
67
|
+
if (sorted.length < 2)
|
|
68
|
+
return [];
|
|
69
|
+
const drifts = [];
|
|
70
|
+
// Build assertion tracking: for each assertion in first envelope,
|
|
71
|
+
// find similar assertions in subsequent envelopes
|
|
72
|
+
const firstAssertions = sorted[0].confidence;
|
|
73
|
+
for (const firstAssertion of firstAssertions) {
|
|
74
|
+
const steps = [
|
|
75
|
+
{
|
|
76
|
+
seq: sorted[0].meta.seq,
|
|
77
|
+
sender: sorted[0].meta.sender,
|
|
78
|
+
score: firstAssertion.score,
|
|
79
|
+
basis: firstAssertion.basis,
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
83
|
+
const match = findSimilarAssertion(firstAssertion, sorted[i].confidence);
|
|
84
|
+
if (match) {
|
|
85
|
+
steps.push({
|
|
86
|
+
seq: sorted[i].meta.seq,
|
|
87
|
+
sender: sorted[i].meta.sender,
|
|
88
|
+
score: match.score,
|
|
89
|
+
basis: match.basis,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (steps.length >= 2) {
|
|
94
|
+
const firstScore = steps[0].score;
|
|
95
|
+
const lastScore = steps[steps.length - 1].score;
|
|
96
|
+
const drift = lastScore - firstScore;
|
|
97
|
+
const absDrift = Math.abs(drift);
|
|
98
|
+
let direction;
|
|
99
|
+
if (drift > 0.05)
|
|
100
|
+
direction = 'INFLATING';
|
|
101
|
+
else if (drift < -0.05)
|
|
102
|
+
direction = 'DEFLATING';
|
|
103
|
+
else
|
|
104
|
+
direction = 'STABLE';
|
|
105
|
+
let poisoningRisk;
|
|
106
|
+
if (direction === 'INFLATING' && absDrift > 0.2) {
|
|
107
|
+
poisoningRisk = 'HIGH';
|
|
108
|
+
}
|
|
109
|
+
else if (direction === 'INFLATING' && absDrift > 0.1) {
|
|
110
|
+
poisoningRisk = 'MEDIUM';
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
poisoningRisk = 'LOW';
|
|
114
|
+
}
|
|
115
|
+
// Extra risk: basis degradation with score inflation
|
|
116
|
+
if (direction === 'INFLATING' &&
|
|
117
|
+
steps[0].basis === 'DERIVED' &&
|
|
118
|
+
steps[steps.length - 1].basis === 'VERIFIED_DATA') {
|
|
119
|
+
poisoningRisk = 'HIGH';
|
|
120
|
+
}
|
|
121
|
+
if (direction !== 'STABLE') {
|
|
122
|
+
const explanation = direction === 'INFLATING'
|
|
123
|
+
? `Confidence inflated by ${(drift * 100).toFixed(0)}% across ${steps.length} handoffs. Original uncertainty is being erased.`
|
|
124
|
+
: `Confidence deflated by ${(Math.abs(drift) * 100).toFixed(0)}% across ${steps.length} handoffs. Signal is being attenuated.`;
|
|
125
|
+
drifts.push({
|
|
126
|
+
chain_id: chainId,
|
|
127
|
+
assertion_pattern: firstAssertion.assertion,
|
|
128
|
+
steps,
|
|
129
|
+
drift,
|
|
130
|
+
direction,
|
|
131
|
+
poisoning_risk: poisoningRisk,
|
|
132
|
+
explanation,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return drifts;
|
|
138
|
+
}
|
|
139
|
+
// --- Basis Shift Detection ---
|
|
140
|
+
function detectBasisShifts(chainId, sorted) {
|
|
141
|
+
if (sorted.length < 2)
|
|
142
|
+
return [];
|
|
143
|
+
const shifts = [];
|
|
144
|
+
// Dangerous basis transitions (laundering uncertainty into certainty)
|
|
145
|
+
const dangerousTransitions = {
|
|
146
|
+
'SPECULATION->VERIFIED_DATA': 'HIGH',
|
|
147
|
+
'SPECULATION->DERIVED': 'MEDIUM',
|
|
148
|
+
'UNKNOWN->VERIFIED_DATA': 'HIGH',
|
|
149
|
+
'UNKNOWN->DERIVED': 'MEDIUM',
|
|
150
|
+
'DERIVED->VERIFIED_DATA': 'HIGH',
|
|
151
|
+
'REPORTED->VERIFIED_DATA': 'MEDIUM',
|
|
152
|
+
'PATTERN_MATCH->VERIFIED_DATA': 'HIGH',
|
|
153
|
+
};
|
|
154
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
155
|
+
const prev = sorted[i - 1];
|
|
156
|
+
const curr = sorted[i];
|
|
157
|
+
for (const currConf of curr.confidence) {
|
|
158
|
+
const prevMatch = findSimilarAssertion(currConf, prev.confidence);
|
|
159
|
+
if (prevMatch && prevMatch.basis !== currConf.basis) {
|
|
160
|
+
const transitionKey = `${prevMatch.basis || 'UNKNOWN'}->${currConf.basis || 'UNKNOWN'}`;
|
|
161
|
+
const risk = dangerousTransitions[transitionKey];
|
|
162
|
+
if (risk) {
|
|
163
|
+
shifts.push({
|
|
164
|
+
chain_id: chainId,
|
|
165
|
+
seq: curr.meta.seq,
|
|
166
|
+
sender: curr.meta.sender,
|
|
167
|
+
assertion: currConf.assertion,
|
|
168
|
+
from_basis: prevMatch.basis,
|
|
169
|
+
to_basis: currConf.basis,
|
|
170
|
+
risk,
|
|
171
|
+
explanation: `Basis shifted from ${prevMatch.basis || 'UNKNOWN'} to ${currConf.basis || 'UNKNOWN'} at seq ${curr.meta.seq}. ${risk === 'HIGH' ? 'This is basis laundering — uncertainty is being repackaged as verified data.' : 'Basis upgraded without verification.'}`,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return shifts;
|
|
178
|
+
}
|
|
179
|
+
// --- Fuzzy Assertion Matching ---
|
|
180
|
+
function findSimilarAssertion(target, candidates) {
|
|
181
|
+
// Exact match first
|
|
182
|
+
const exact = candidates.find((c) => c.assertion === target.assertion);
|
|
183
|
+
if (exact)
|
|
184
|
+
return exact;
|
|
185
|
+
// Simple word overlap similarity
|
|
186
|
+
const targetWords = new Set(target.assertion.toLowerCase().split(/\s+/));
|
|
187
|
+
let bestMatch = null;
|
|
188
|
+
let bestScore = 0;
|
|
189
|
+
for (const candidate of candidates) {
|
|
190
|
+
const candidateWords = new Set(candidate.assertion.toLowerCase().split(/\s+/));
|
|
191
|
+
const intersection = new Set([...targetWords].filter((w) => candidateWords.has(w)));
|
|
192
|
+
const union = new Set([...targetWords, ...candidateWords]);
|
|
193
|
+
const jaccard = intersection.size / union.size;
|
|
194
|
+
if (jaccard > bestScore && jaccard > 0.3) {
|
|
195
|
+
bestScore = jaccard;
|
|
196
|
+
bestMatch = candidate;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return bestMatch;
|
|
200
|
+
}
|
|
201
|
+
// --- Summary ---
|
|
202
|
+
function buildSummary(chainId, length, drifts, shifts, risk) {
|
|
203
|
+
const parts = [];
|
|
204
|
+
parts.push(`Chain ${chainId.slice(0, 8)}... (${length} envelopes)`);
|
|
205
|
+
if (risk === 'NONE') {
|
|
206
|
+
parts.push('No poisoning patterns detected.');
|
|
207
|
+
return parts.join(': ');
|
|
208
|
+
}
|
|
209
|
+
const inflating = drifts.filter((d) => d.direction === 'INFLATING');
|
|
210
|
+
const laundering = shifts.filter((s) => s.risk === 'HIGH');
|
|
211
|
+
if (inflating.length > 0) {
|
|
212
|
+
parts.push(`${inflating.length} confidence inflation(s)`);
|
|
213
|
+
}
|
|
214
|
+
if (laundering.length > 0) {
|
|
215
|
+
parts.push(`${laundering.length} basis laundering event(s)`);
|
|
216
|
+
}
|
|
217
|
+
parts.push(`Overall risk: ${risk}`);
|
|
218
|
+
return parts.join(' | ');
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":";AAAA,kDAAkD;AAClD,sBAAsB;AACtB,2CAA2C;AAC3C,uCAAuC;AACvC,qDAAqD;AACrD,kDAAkD;;AAiDlD,gCAoDC;AAlGD,yCAA2C;AAsC3C;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,SAA0B;IACnD,oBAAoB;IACpB,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;IAClD,KAAK,MAAM,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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BabelEnvelope, Intent, Register, Basis, GroundAuthority, TrajectoryDirection, ValidationResult } from './types';
|
|
2
|
+
export declare class EnvelopeBuilder {
|
|
3
|
+
private _meta;
|
|
4
|
+
private _intent;
|
|
5
|
+
private _confidence;
|
|
6
|
+
private _register;
|
|
7
|
+
private _affect?;
|
|
8
|
+
private _grounds;
|
|
9
|
+
private _trajectory?;
|
|
10
|
+
private _payload;
|
|
11
|
+
sender(sender: string): this;
|
|
12
|
+
recipient(recipient: string): this;
|
|
13
|
+
broadcast(): this;
|
|
14
|
+
chain(chainId: string, seq: number): this;
|
|
15
|
+
intent(intent: Intent): this;
|
|
16
|
+
inform(): this;
|
|
17
|
+
requestAction(): this;
|
|
18
|
+
escalate(): this;
|
|
19
|
+
flagRisk(): this;
|
|
20
|
+
speculate(): this;
|
|
21
|
+
persuade(): this;
|
|
22
|
+
delegate(): this;
|
|
23
|
+
synthesize(): this;
|
|
24
|
+
assert(assertion: string, score: number, basis?: Basis): this;
|
|
25
|
+
verified(assertion: string, score: number): this;
|
|
26
|
+
derived(assertion: string, score: number): this;
|
|
27
|
+
reported(assertion: string, score: number): this;
|
|
28
|
+
patternMatch(assertion: string, score: number): this;
|
|
29
|
+
speculation(assertion: string, score: number): this;
|
|
30
|
+
register(register: Register): this;
|
|
31
|
+
boardFacing(): this;
|
|
32
|
+
engineering(): this;
|
|
33
|
+
customerExternal(): this;
|
|
34
|
+
regulatory(): this;
|
|
35
|
+
internalMemo(): this;
|
|
36
|
+
agentInternal(): this;
|
|
37
|
+
affect(expansion: number, activation: number, certainty: number): this;
|
|
38
|
+
ground(constraint: string, authority: GroundAuthority, override?: boolean): this;
|
|
39
|
+
regulatoryGround(constraint: string): this;
|
|
40
|
+
policyGround(constraint: string, override?: boolean): this;
|
|
41
|
+
withTrajectory(pattern: string, direction: TrajectoryDirection, opts?: {
|
|
42
|
+
duration?: string;
|
|
43
|
+
prior_handoffs?: number;
|
|
44
|
+
}): this;
|
|
45
|
+
payload(payload: string): this;
|
|
46
|
+
build(): BabelEnvelope;
|
|
47
|
+
/**
|
|
48
|
+
* Build and validate in one step.
|
|
49
|
+
* Returns the validation result with the envelope attached.
|
|
50
|
+
*/
|
|
51
|
+
buildAndValidate(): ValidationResult;
|
|
52
|
+
}
|
|
53
|
+
export declare function envelope(): EnvelopeBuilder;
|
|
54
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,aAAa,EAEb,MAAM,EACN,QAAQ,EAER,KAAK,EAGL,eAAe,EAEf,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAGjB,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAA2C;IACxD,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAc;IAI9B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKlC,SAAS,IAAI,IAAI;IAKjB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAQzC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,MAAM,IAAI,IAAI;IACd,aAAa,IAAI,IAAI;IACrB,QAAQ,IAAI,IAAI;IAChB,QAAQ,IAAI,IAAI;IAChB,SAAS,IAAI,IAAI;IACjB,QAAQ,IAAI,IAAI;IA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