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.
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ // ═══════════════════════════════════════════════
3
+ // BABEL ENVELOPE BUILDER
4
+ // Fluent API for creating valid envelopes
5
+ // ═══════════════════════════════════════════════
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.EnvelopeBuilder = void 0;
8
+ exports.envelope = envelope;
9
+ const validate_1 = require("./validate");
10
+ class EnvelopeBuilder {
11
+ constructor() {
12
+ this._meta = { version: 'babel/0.2' };
13
+ this._intent = 'INFORM';
14
+ this._confidence = [];
15
+ this._register = 'AGENT_INTERNAL';
16
+ this._grounds = [];
17
+ this._payload = '';
18
+ }
19
+ // --- Meta ---
20
+ sender(sender) {
21
+ this._meta.sender = sender;
22
+ return this;
23
+ }
24
+ recipient(recipient) {
25
+ this._meta.recipient = recipient;
26
+ return this;
27
+ }
28
+ broadcast() {
29
+ this._meta.recipient = 'broadcast';
30
+ return this;
31
+ }
32
+ chain(chainId, seq) {
33
+ this._meta.chain_id = chainId;
34
+ this._meta.seq = seq;
35
+ return this;
36
+ }
37
+ // --- Intent ---
38
+ intent(intent) {
39
+ this._intent = intent;
40
+ return this;
41
+ }
42
+ inform() { return this.intent('INFORM'); }
43
+ requestAction() { return this.intent('REQUEST_ACTION'); }
44
+ escalate() { return this.intent('ESCALATE'); }
45
+ flagRisk() { return this.intent('FLAG_RISK'); }
46
+ speculate() { return this.intent('SPECULATE'); }
47
+ persuade() { return this.intent('PERSUADE'); }
48
+ delegate() { return this.intent('DELEGATE'); }
49
+ synthesize() { return this.intent('SYNTHESIZE'); }
50
+ // --- Confidence ---
51
+ assert(assertion, score, basis) {
52
+ this._confidence.push({ assertion, score, basis });
53
+ return this;
54
+ }
55
+ verified(assertion, score) {
56
+ return this.assert(assertion, score, 'VERIFIED_DATA');
57
+ }
58
+ derived(assertion, score) {
59
+ return this.assert(assertion, score, 'DERIVED');
60
+ }
61
+ reported(assertion, score) {
62
+ return this.assert(assertion, score, 'REPORTED');
63
+ }
64
+ patternMatch(assertion, score) {
65
+ return this.assert(assertion, score, 'PATTERN_MATCH');
66
+ }
67
+ speculation(assertion, score) {
68
+ return this.assert(assertion, score, 'SPECULATION');
69
+ }
70
+ // --- Register ---
71
+ register(register) {
72
+ this._register = register;
73
+ return this;
74
+ }
75
+ boardFacing() { return this.register('BOARD_FACING'); }
76
+ engineering() { return this.register('ENGINEERING'); }
77
+ customerExternal() { return this.register('CUSTOMER_EXTERNAL'); }
78
+ regulatory() { return this.register('REGULATORY'); }
79
+ internalMemo() { return this.register('INTERNAL_MEMO'); }
80
+ agentInternal() { return this.register('AGENT_INTERNAL'); }
81
+ // --- Affect ---
82
+ affect(expansion, activation, certainty) {
83
+ this._affect = { expansion, activation, certainty };
84
+ return this;
85
+ }
86
+ // --- Grounds ---
87
+ ground(constraint, authority, override = false) {
88
+ // Auto-enforce M3: REGULATORY grounds are never overridable
89
+ if (authority === 'REGULATORY') {
90
+ override = false;
91
+ }
92
+ this._grounds.push({ constraint, authority, override });
93
+ return this;
94
+ }
95
+ regulatoryGround(constraint) {
96
+ return this.ground(constraint, 'REGULATORY', false);
97
+ }
98
+ policyGround(constraint, override = false) {
99
+ return this.ground(constraint, 'POLICY', override);
100
+ }
101
+ // --- Trajectory ---
102
+ withTrajectory(pattern, direction, opts) {
103
+ this._trajectory = {
104
+ pattern,
105
+ direction,
106
+ duration: opts?.duration,
107
+ prior_handoffs: opts?.prior_handoffs,
108
+ };
109
+ return this;
110
+ }
111
+ // --- Payload ---
112
+ payload(payload) {
113
+ this._payload = payload;
114
+ return this;
115
+ }
116
+ // --- Build ---
117
+ build() {
118
+ const now = new Date().toISOString();
119
+ return {
120
+ meta: {
121
+ version: this._meta.version || 'babel/0.2',
122
+ timestamp: this._meta.timestamp || now,
123
+ sender: this._meta.sender || 'unknown',
124
+ recipient: this._meta.recipient || 'broadcast',
125
+ chain_id: this._meta.chain_id || generateUUID(),
126
+ seq: this._meta.seq ?? 0,
127
+ },
128
+ intent: this._intent,
129
+ confidence: this._confidence,
130
+ register: this._register,
131
+ affect: this._affect,
132
+ grounds: this._grounds.length > 0 ? this._grounds : undefined,
133
+ trajectory: this._trajectory,
134
+ payload: this._payload,
135
+ };
136
+ }
137
+ /**
138
+ * Build and validate in one step.
139
+ * Returns the validation result with the envelope attached.
140
+ */
141
+ buildAndValidate() {
142
+ const envelope = this.build();
143
+ return (0, validate_1.validate)(envelope);
144
+ }
145
+ }
146
+ exports.EnvelopeBuilder = EnvelopeBuilder;
147
+ // --- Factory ---
148
+ function envelope() {
149
+ return new EnvelopeBuilder();
150
+ }
151
+ // --- UUID helper ---
152
+ function generateUUID() {
153
+ // Simple UUID v4 generator (no crypto dependency)
154
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
155
+ const r = (Math.random() * 16) | 0;
156
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
157
+ return v.toString(16);
158
+ });
159
+ }
160
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":";AAAA,kDAAkD;AAClD,yBAAyB;AACzB,0CAA0C;AAC1C,kDAAkD;;;AAiMlD,4BAEC;AAnLD,yCAAsC;AAEtC,MAAa,eAAe;IAA5B;QACU,UAAK,GAAkB,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QAChD,YAAO,GAAW,QAAQ,CAAC;QAC3B,gBAAW,GAAiB,EAAE,CAAC;QAC/B,cAAS,GAAa,gBAAgB,CAAC;QAEvC,aAAQ,GAAa,EAAE,CAAC;QAExB,aAAQ,GAAW,EAAE,CAAC;IAmKhC,CAAC;IAjKC,eAAe;IAEf,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAC3B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AAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { BabelEnvelope, Meta, Intent, Confidence, Basis, Register, Affect, Ground, GroundAuthority, Trajectory, TrajectoryDirection, RuleViolation, RuleSeverity, ValidationResult, SemanticPattern, PatternDetection, } from './types';
2
+ export { validate, validateChain } from './validate';
3
+ export { EnvelopeBuilder, envelope } from './builder';
4
+ export { detectPatterns } from './patterns';
5
+ export { auditChain, ChainAudit, ConfidenceDrift, BasisShift, } from './audit';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,aAAa,EACb,IAAI,EACJ,MAAM,EACN,UAAU,EACV,KAAK,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGtD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EACL,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,GACX,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // ═══════════════════════════════════════════════
3
+ // BABEL-VALIDATE
4
+ // Wire protocol + measurement engine for
5
+ // multi-agent metacognitive integrity.
6
+ //
7
+ // "Your agents are lying to each other.
8
+ // They just don't know it."
9
+ // ═══════════════════════════════════════════════
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.auditChain = exports.detectPatterns = exports.envelope = exports.EnvelopeBuilder = exports.validateChain = exports.validate = void 0;
12
+ // Validation
13
+ var validate_1 = require("./validate");
14
+ Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return validate_1.validate; } });
15
+ Object.defineProperty(exports, "validateChain", { enumerable: true, get: function () { return validate_1.validateChain; } });
16
+ // Builder
17
+ var builder_1 = require("./builder");
18
+ Object.defineProperty(exports, "EnvelopeBuilder", { enumerable: true, get: function () { return builder_1.EnvelopeBuilder; } });
19
+ Object.defineProperty(exports, "envelope", { enumerable: true, get: function () { return builder_1.envelope; } });
20
+ // Pattern Detection
21
+ var patterns_1 = require("./patterns");
22
+ Object.defineProperty(exports, "detectPatterns", { enumerable: true, get: function () { return patterns_1.detectPatterns; } });
23
+ // Chain Audit
24
+ var audit_1 = require("./audit");
25
+ Object.defineProperty(exports, "auditChain", { enumerable: true, get: function () { return audit_1.auditChain; } });
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kDAAkD;AAClD,iBAAiB;AACjB,yCAAyC;AACzC,uCAAuC;AACvC,EAAE;AACF,wCAAwC;AACxC,6BAA6B;AAC7B,kDAAkD;;;AAsBlD,aAAa;AACb,uCAAqD;AAA5C,oGAAA,QAAQ,OAAA;AAAE,yGAAA,aAAa,OAAA;AAEhC,UAAU;AACV,qCAAsD;AAA7C,0GAAA,eAAe,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAElC,oBAAoB;AACpB,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AAEvB,cAAc;AACd,iCAKiB;AAJf,mGAAA,UAAU,OAAA"}
@@ -0,0 +1,8 @@
1
+ import { BabelEnvelope, PatternDetection } from './types';
2
+ /**
3
+ * Detect semantic patterns — coherence signals and contradiction
4
+ * signals that grammar rules don't catch. These are the "idioms"
5
+ * of Babel: meaning from cross-field combination.
6
+ */
7
+ export declare function detectPatterns(envelope: BabelEnvelope): PatternDetection[];
8
+ //# sourceMappingURL=patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../src/patterns.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,aAAa,GAAG,gBAAgB,EAAE,CAoG1E"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ // ═══════════════════════════════════════════════
3
+ // BABEL SEMANTIC PATTERN DETECTOR
4
+ // Spec: Babel v0.2 "Semantic Combinations"
5
+ // These are recognized patterns that carry meaning
6
+ // beyond their individual fields — like idioms in
7
+ // a natural language.
8
+ // ═══════════════════════════════════════════════
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.detectPatterns = detectPatterns;
11
+ /**
12
+ * Detect semantic patterns — coherence signals and contradiction
13
+ * signals that grammar rules don't catch. These are the "idioms"
14
+ * of Babel: meaning from cross-field combination.
15
+ */
16
+ function detectPatterns(envelope) {
17
+ const patterns = [];
18
+ // --- THE CALM ALERT ---
19
+ // confidence: 0.8+ | intent: FLAG_RISK | affect: low activation, moderate certainty
20
+ // "Sender is flagging something real but isn't panicking.
21
+ // Receiving agent should treat as important but not crisis."
22
+ if (envelope.intent === 'FLAG_RISK' && envelope.affect) {
23
+ const maxScore = Math.max(...envelope.confidence.map((c) => c.score));
24
+ if (maxScore >= 0.8 &&
25
+ envelope.affect.activation < 0 &&
26
+ envelope.affect.certainty > 0) {
27
+ patterns.push({
28
+ pattern: 'CALM_ALERT',
29
+ description: 'High-confidence risk flag with calm affect. Sender is flagging something real but isn\'t panicking. Treat as important but not crisis.',
30
+ confidence: 0.7,
31
+ });
32
+ }
33
+ }
34
+ // --- THE RELUCTANT ESCALATION ---
35
+ // intent: ESCALATE | affect: contracted, uncertain | trajectory: prior_handoffs 2+
36
+ // "This has been handed off multiple times. The escalator isn't confident
37
+ // this will help either. Address the systemic pattern, not just the immediate issue."
38
+ if (envelope.intent === 'ESCALATE' && envelope.affect) {
39
+ const hasMultipleHandoffs = envelope.trajectory && envelope.trajectory.prior_handoffs !== undefined &&
40
+ envelope.trajectory.prior_handoffs >= 2;
41
+ if (envelope.affect.expansion < -0.3 &&
42
+ envelope.affect.certainty < -0.3 &&
43
+ hasMultipleHandoffs) {
44
+ patterns.push({
45
+ pattern: 'RELUCTANT_ESCALATION',
46
+ description: `Escalation with contracted affect and ${envelope.trajectory.prior_handoffs} prior handoffs. Escalator isn't confident this will help either. Address the systemic pattern, not just the immediate issue.`,
47
+ confidence: 0.75,
48
+ });
49
+ }
50
+ }
51
+ // --- THE CONFIDENT DELEGATION ---
52
+ // intent: DELEGATE | confidence: 0.9+ | grounds: POLICY | affect: certainty 0.6+
53
+ // "Sender knows what needs to happen and is handing it to the right agent.
54
+ // Receiving agent should execute, not re-analyze."
55
+ if (envelope.intent === 'DELEGATE' && envelope.affect) {
56
+ const allHighConf = envelope.confidence.every((c) => c.score >= 0.9);
57
+ const hasPolicyGrounds = envelope.grounds?.some((g) => g.authority === 'POLICY');
58
+ if (allHighConf && hasPolicyGrounds && envelope.affect.certainty >= 0.6) {
59
+ patterns.push({
60
+ pattern: 'CONFIDENT_DELEGATION',
61
+ description: 'High-confidence delegation with policy grounds and strong certainty. Sender knows what needs to happen. Receiving agent should execute, not re-analyze.',
62
+ confidence: 0.8,
63
+ });
64
+ }
65
+ }
66
+ // --- THE LOADED INFORM ---
67
+ // intent: INFORM | trajectory: DEGRADING, long duration | register: BOARD_FACING
68
+ // "Surface reads as neutral update. Trajectory says this is a pattern
69
+ // the board needs to see. Frame as trend, not snapshot."
70
+ if (envelope.intent === 'INFORM' &&
71
+ envelope.register === 'BOARD_FACING' &&
72
+ envelope.trajectory &&
73
+ envelope.trajectory.direction === 'DEGRADING') {
74
+ patterns.push({
75
+ pattern: 'LOADED_INFORM',
76
+ description: `INFORM intent with BOARD_FACING register but DEGRADING trajectory ("${truncate(envelope.trajectory.pattern)}"). Surface reads as neutral update, but trajectory says this is a pattern the board needs to see. Frame as trend, not snapshot.`,
77
+ confidence: 0.7,
78
+ });
79
+ }
80
+ // --- THE CONTRADICTION SIGNAL ---
81
+ // affect: certainty 0.8+ | max(confidence) < 0.3
82
+ // "Sender *feels* certain but *evidence* is weak. This is the envelope
83
+ // telling on itself — confidence may be emotional rather than evidentiary."
84
+ // (This is also what SHOULD rule S2 catches — patterns detects it as a named idiom.)
85
+ if (envelope.affect) {
86
+ const maxScore = Math.max(...envelope.confidence.map((c) => c.score));
87
+ if (envelope.affect.certainty > 0.5 && maxScore < 0.4) {
88
+ patterns.push({
89
+ pattern: 'CONTRADICTION_SIGNAL',
90
+ description: `Affect certainty is ${envelope.affect.certainty.toFixed(2)} but max confidence score is only ${maxScore.toFixed(2)}. Sender feels certain but evidence is weak. Confidence may be emotional rather than evidentiary. Probe the basis.`,
91
+ confidence: 0.65,
92
+ });
93
+ }
94
+ }
95
+ return patterns;
96
+ }
97
+ function truncate(s, len = 50) {
98
+ return s.length > len ? s.slice(0, len) + '...' : s;
99
+ }
100
+ //# sourceMappingURL=patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.js","sourceRoot":"","sources":["../src/patterns.ts"],"names":[],"mappings":";AAAA,kDAAkD;AAClD,kCAAkC;AAClC,2CAA2C;AAC3C,mDAAmD;AACnD,kDAAkD;AAClD,sBAAsB;AACtB,kDAAkD;;AASlD,wCAoGC;AAzGD;;;;GAIG;AACH,SAAgB,cAAc,CAAC,QAAuB;IACpD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