@longarc/mdash 3.0.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 +278 -0
- package/dist/checkpoint/engine.d.ts +208 -0
- package/dist/checkpoint/engine.d.ts.map +1 -0
- package/dist/checkpoint/engine.js +369 -0
- package/dist/checkpoint/engine.js.map +1 -0
- package/dist/context/engine.d.ts +197 -0
- package/dist/context/engine.d.ts.map +1 -0
- package/dist/context/engine.js +392 -0
- package/dist/context/engine.js.map +1 -0
- package/dist/core/commitment.d.ts +154 -0
- package/dist/core/commitment.d.ts.map +1 -0
- package/dist/core/commitment.js +305 -0
- package/dist/core/commitment.js.map +1 -0
- package/dist/core/crypto.d.ts +100 -0
- package/dist/core/crypto.d.ts.map +1 -0
- package/dist/core/crypto.js +243 -0
- package/dist/core/crypto.js.map +1 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +234 -0
- package/dist/index.js.map +1 -0
- package/dist/mcca/engine.d.ts +260 -0
- package/dist/mcca/engine.d.ts.map +1 -0
- package/dist/mcca/engine.js +518 -0
- package/dist/mcca/engine.js.map +1 -0
- package/dist/physics/engine.d.ts +165 -0
- package/dist/physics/engine.d.ts.map +1 -0
- package/dist/physics/engine.js +371 -0
- package/dist/physics/engine.js.map +1 -0
- package/dist/tee/engine.d.ts +285 -0
- package/dist/tee/engine.d.ts.map +1 -0
- package/dist/tee/engine.js +505 -0
- package/dist/tee/engine.js.map +1 -0
- package/dist/warrant/engine.d.ts +195 -0
- package/dist/warrant/engine.d.ts.map +1 -0
- package/dist/warrant/engine.js +409 -0
- package/dist/warrant/engine.js.map +1 -0
- package/dist/zk/engine.d.ts +243 -0
- package/dist/zk/engine.d.ts.map +1 -0
- package/dist/zk/engine.js +489 -0
- package/dist/zk/engine.js.map +1 -0
- package/package.json +25 -0
- package/src/__tests__/phase1.test.ts +1120 -0
- package/src/__tests__/phase2-4.test.ts +898 -0
- package/src/checkpoint/engine.ts +532 -0
- package/src/context/engine.ts +598 -0
- package/src/core/commitment.ts +438 -0
- package/src/core/crypto.ts +304 -0
- package/src/index.ts +320 -0
- package/src/mcca/engine.ts +778 -0
- package/src/physics/engine.ts +563 -0
- package/src/tee/engine.ts +810 -0
- package/src/warrant/engine.ts +625 -0
- package/src/zk/engine.ts +730 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mdash v3.0 - Physics Engine
|
|
3
|
+
*
|
|
4
|
+
* "Physics" = the laws of agent behavior that cannot be violated.
|
|
5
|
+
* Validates actions against constraints with signed artifacts.
|
|
6
|
+
*
|
|
7
|
+
* Key Concept: Plausibility scoring determines if an action
|
|
8
|
+
* is physically possible given the warrant and context.
|
|
9
|
+
*/
|
|
10
|
+
import { Hash, Seal, Timestamp, WarrantId, CheckpointId } from '../core/crypto';
|
|
11
|
+
import { Warrant } from '../warrant/engine';
|
|
12
|
+
export type PhysicsViolationType = 'amount_exceeded' | 'rate_exceeded' | 'domain_forbidden' | 'time_forbidden' | 'delegation_forbidden' | 'scope_violation' | 'causality_violation' | 'invariant_violation';
|
|
13
|
+
export interface PhysicsConstraint {
|
|
14
|
+
/** Constraint type */
|
|
15
|
+
type: string;
|
|
16
|
+
/** Constraint parameters */
|
|
17
|
+
params: Record<string, unknown>;
|
|
18
|
+
/** Whether violation should block or warn */
|
|
19
|
+
severity: 'block' | 'warn';
|
|
20
|
+
}
|
|
21
|
+
export interface PhysicsAction {
|
|
22
|
+
/** Action identifier */
|
|
23
|
+
action_id: string;
|
|
24
|
+
/** Action type */
|
|
25
|
+
type: string;
|
|
26
|
+
/** Agent performing the action */
|
|
27
|
+
agent_id: string;
|
|
28
|
+
/** Warrant authorizing the action */
|
|
29
|
+
warrant_id: WarrantId;
|
|
30
|
+
/** Action parameters */
|
|
31
|
+
params: Record<string, unknown>;
|
|
32
|
+
/** Timestamp */
|
|
33
|
+
timestamp: Timestamp;
|
|
34
|
+
}
|
|
35
|
+
export interface PhysicsValidation {
|
|
36
|
+
/** Action being validated */
|
|
37
|
+
action: PhysicsAction;
|
|
38
|
+
/** Whether action is valid */
|
|
39
|
+
valid: boolean;
|
|
40
|
+
/** Plausibility score (0-1) */
|
|
41
|
+
score: number;
|
|
42
|
+
/** Violations found */
|
|
43
|
+
violations: PhysicsViolation[];
|
|
44
|
+
/** Validation timestamp */
|
|
45
|
+
validated_at: Timestamp;
|
|
46
|
+
/** Validation hash (for audit) */
|
|
47
|
+
hash: Hash;
|
|
48
|
+
}
|
|
49
|
+
export interface PhysicsViolation {
|
|
50
|
+
/** Violation type */
|
|
51
|
+
type: PhysicsViolationType;
|
|
52
|
+
/** Constraint that was violated */
|
|
53
|
+
constraint: PhysicsConstraint;
|
|
54
|
+
/** Human-readable message */
|
|
55
|
+
message: string;
|
|
56
|
+
/** Severity */
|
|
57
|
+
severity: 'block' | 'warn';
|
|
58
|
+
}
|
|
59
|
+
export interface SignedArtifact {
|
|
60
|
+
/** Artifact type */
|
|
61
|
+
type: 'validation' | 'constraint' | 'policy';
|
|
62
|
+
/** Artifact content */
|
|
63
|
+
content: unknown;
|
|
64
|
+
/** Content hash */
|
|
65
|
+
hash: Hash;
|
|
66
|
+
/** HMAC seal */
|
|
67
|
+
seal: Seal;
|
|
68
|
+
/** Creation timestamp */
|
|
69
|
+
created_at: Timestamp;
|
|
70
|
+
/** Version for hot-swap */
|
|
71
|
+
version: string;
|
|
72
|
+
}
|
|
73
|
+
export interface PhysicsPolicy {
|
|
74
|
+
/** Policy identifier */
|
|
75
|
+
id: string;
|
|
76
|
+
/** Policy name */
|
|
77
|
+
name: string;
|
|
78
|
+
/** Policy version */
|
|
79
|
+
version: string;
|
|
80
|
+
/** Constraints defined by this policy */
|
|
81
|
+
constraints: PhysicsConstraint[];
|
|
82
|
+
/** Whether policy is active */
|
|
83
|
+
active: boolean;
|
|
84
|
+
}
|
|
85
|
+
export declare const DEFAULT_POLICIES: PhysicsPolicy[];
|
|
86
|
+
export declare class PhysicsEngine {
|
|
87
|
+
private key;
|
|
88
|
+
private policies;
|
|
89
|
+
private validationHistory;
|
|
90
|
+
private rateCounters;
|
|
91
|
+
constructor();
|
|
92
|
+
/**
|
|
93
|
+
* Initialize the engine with a seal key
|
|
94
|
+
*/
|
|
95
|
+
initialize(sealKey: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Validate an action against physics constraints
|
|
98
|
+
*/
|
|
99
|
+
validate(action: PhysicsAction, warrant: Warrant): Promise<PhysicsValidation>;
|
|
100
|
+
/**
|
|
101
|
+
* Check a specific constraint
|
|
102
|
+
*/
|
|
103
|
+
private checkConstraint;
|
|
104
|
+
/**
|
|
105
|
+
* Check warrant-level constraints
|
|
106
|
+
*/
|
|
107
|
+
private checkWarrantConstraints;
|
|
108
|
+
/**
|
|
109
|
+
* Check rate limits
|
|
110
|
+
*/
|
|
111
|
+
private checkRateLimit;
|
|
112
|
+
/**
|
|
113
|
+
* Create a signed artifact
|
|
114
|
+
*/
|
|
115
|
+
createSignedArtifact(type: SignedArtifact['type'], content: unknown, version: string): Promise<SignedArtifact>;
|
|
116
|
+
/**
|
|
117
|
+
* Hot-swap a policy (for runtime updates)
|
|
118
|
+
*/
|
|
119
|
+
hotSwapPolicy(policy: PhysicsPolicy): Promise<SignedArtifact>;
|
|
120
|
+
/**
|
|
121
|
+
* Get policy by ID
|
|
122
|
+
*/
|
|
123
|
+
getPolicy(id: string): PhysicsPolicy | null;
|
|
124
|
+
/**
|
|
125
|
+
* Get all policies
|
|
126
|
+
*/
|
|
127
|
+
getAllPolicies(): PhysicsPolicy[];
|
|
128
|
+
/**
|
|
129
|
+
* Get validation history for an agent
|
|
130
|
+
*/
|
|
131
|
+
getValidationHistory(agentId?: string, limit?: number): PhysicsValidation[];
|
|
132
|
+
/**
|
|
133
|
+
* Get plausibility statistics
|
|
134
|
+
*/
|
|
135
|
+
getStats(): {
|
|
136
|
+
totalValidations: number;
|
|
137
|
+
validCount: number;
|
|
138
|
+
invalidCount: number;
|
|
139
|
+
averageScore: number;
|
|
140
|
+
violationsByType: Record<string, number>;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Ensures actions respect causal ordering
|
|
145
|
+
* "Effect cannot precede cause"
|
|
146
|
+
*/
|
|
147
|
+
export declare class CausalityChecker {
|
|
148
|
+
private actionLog;
|
|
149
|
+
/**
|
|
150
|
+
* Record an action with its checkpoint
|
|
151
|
+
*/
|
|
152
|
+
record(action: PhysicsAction, checkpoint: CheckpointId): void;
|
|
153
|
+
/**
|
|
154
|
+
* Check if an action would violate causality
|
|
155
|
+
*/
|
|
156
|
+
checkCausality(_action: PhysicsAction, dependencies: CheckpointId[]): {
|
|
157
|
+
valid: boolean;
|
|
158
|
+
violation?: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Get causal chain for an action
|
|
162
|
+
*/
|
|
163
|
+
getCausalChain(checkpointId: CheckpointId): PhysicsAction[];
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/physics/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,YAAY,EAKb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,OAAO,EAAsB,MAAM,mBAAmB,CAAC;AAMhE,MAAM,MAAM,oBAAoB,GAC5B,iBAAiB,GACjB,eAAe,GACf,kBAAkB,GAClB,gBAAgB,GAChB,sBAAsB,GACtB,iBAAiB,GACjB,qBAAqB,GACrB,qBAAqB,CAAC;AAE1B,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA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UhF;;OAEG;IACH,QAAQ,IAAI;QACV,gBAAgB,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC1C;CAuBF;AAMD;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAkE;IAEnF;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,GAAG,IAAI;IAI7D;;OAEG;IACH,cAAc,CACZ,OAAO,EAAE,aAAa,EACtB,YAAY,EAAE,YAAY,EAAE,GAC3B;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAezC;;OAEG;IACH,cAAc,CAAC,YAAY,EAAE,YAAY,GAAG,aAAa,EAAE;CAM5D"}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mdash v3.0 - Physics Engine
|
|
3
|
+
*
|
|
4
|
+
* "Physics" = the laws of agent behavior that cannot be violated.
|
|
5
|
+
* Validates actions against constraints with signed artifacts.
|
|
6
|
+
*
|
|
7
|
+
* Key Concept: Plausibility scoring determines if an action
|
|
8
|
+
* is physically possible given the warrant and context.
|
|
9
|
+
*/
|
|
10
|
+
import { sha256Object, hmacSeal, deriveKey, generateTimestamp, } from '../core/crypto';
|
|
11
|
+
// Default policies
|
|
12
|
+
export const DEFAULT_POLICIES = [
|
|
13
|
+
{
|
|
14
|
+
id: 'financial-transfer-v2',
|
|
15
|
+
name: 'Financial Transfer',
|
|
16
|
+
version: '2.0',
|
|
17
|
+
active: true,
|
|
18
|
+
constraints: [
|
|
19
|
+
{
|
|
20
|
+
type: 'max_amount',
|
|
21
|
+
params: { limit: 100000, currency: 'USD' },
|
|
22
|
+
severity: 'block',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 'rate_limit',
|
|
26
|
+
params: { max_per_hour: 10, max_per_day: 50 },
|
|
27
|
+
severity: 'block',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'allowlist',
|
|
31
|
+
params: { field: 'destination', required: true },
|
|
32
|
+
severity: 'block',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'data-access-v1',
|
|
38
|
+
name: 'Data Access',
|
|
39
|
+
version: '1.0',
|
|
40
|
+
active: true,
|
|
41
|
+
constraints: [
|
|
42
|
+
{
|
|
43
|
+
type: 'scope_restriction',
|
|
44
|
+
params: { allowed_tables: [], require_explicit: true },
|
|
45
|
+
severity: 'block',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: 'rate_limit',
|
|
49
|
+
params: { max_per_minute: 100 },
|
|
50
|
+
severity: 'warn',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'external-api-v1',
|
|
56
|
+
name: 'External API',
|
|
57
|
+
version: '1.0',
|
|
58
|
+
active: true,
|
|
59
|
+
constraints: [
|
|
60
|
+
{
|
|
61
|
+
type: 'domain_allowlist',
|
|
62
|
+
params: { domains: [], require_explicit: true },
|
|
63
|
+
severity: 'block',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'rate_limit',
|
|
67
|
+
params: { max_per_minute: 60 },
|
|
68
|
+
severity: 'warn',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
// ============================================================================
|
|
74
|
+
// PHYSICS ENGINE
|
|
75
|
+
// ============================================================================
|
|
76
|
+
export class PhysicsEngine {
|
|
77
|
+
key = null;
|
|
78
|
+
policies = new Map();
|
|
79
|
+
validationHistory = [];
|
|
80
|
+
rateCounters = new Map();
|
|
81
|
+
constructor() {
|
|
82
|
+
// Load default policies
|
|
83
|
+
for (const policy of DEFAULT_POLICIES) {
|
|
84
|
+
this.policies.set(policy.id, policy);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Initialize the engine with a seal key
|
|
89
|
+
*/
|
|
90
|
+
async initialize(sealKey) {
|
|
91
|
+
this.key = await deriveKey(sealKey);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Validate an action against physics constraints
|
|
95
|
+
*/
|
|
96
|
+
async validate(action, warrant) {
|
|
97
|
+
if (!this.key) {
|
|
98
|
+
throw new Error('Engine not initialized. Call initialize() first.');
|
|
99
|
+
}
|
|
100
|
+
const startTime = performance.now();
|
|
101
|
+
const violations = [];
|
|
102
|
+
// Get policy for the warrant
|
|
103
|
+
const policy = this.policies.get(warrant.policy_id);
|
|
104
|
+
if (!policy) {
|
|
105
|
+
violations.push({
|
|
106
|
+
type: 'scope_violation',
|
|
107
|
+
constraint: { type: 'policy_required', params: {}, severity: 'block' },
|
|
108
|
+
message: `Unknown policy: ${warrant.policy_id}`,
|
|
109
|
+
severity: 'block',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Check each constraint
|
|
114
|
+
for (const constraint of policy.constraints) {
|
|
115
|
+
const violation = await this.checkConstraint(constraint, action, warrant.constraints);
|
|
116
|
+
if (violation) {
|
|
117
|
+
violations.push(violation);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Check warrant-level constraints
|
|
122
|
+
const warrantViolations = this.checkWarrantConstraints(action, warrant.constraints);
|
|
123
|
+
violations.push(...warrantViolations);
|
|
124
|
+
// Check rate limits
|
|
125
|
+
const rateViolation = this.checkRateLimit(action);
|
|
126
|
+
if (rateViolation) {
|
|
127
|
+
violations.push(rateViolation);
|
|
128
|
+
}
|
|
129
|
+
// Calculate plausibility score
|
|
130
|
+
const blockingViolations = violations.filter(v => v.severity === 'block');
|
|
131
|
+
const score = blockingViolations.length === 0
|
|
132
|
+
? Math.max(0, 1 - violations.length * 0.1)
|
|
133
|
+
: 0;
|
|
134
|
+
const now = generateTimestamp();
|
|
135
|
+
// Create validation record
|
|
136
|
+
const validationData = {
|
|
137
|
+
action,
|
|
138
|
+
valid: blockingViolations.length === 0,
|
|
139
|
+
score,
|
|
140
|
+
violations,
|
|
141
|
+
validated_at: now,
|
|
142
|
+
};
|
|
143
|
+
const hash = await sha256Object(validationData);
|
|
144
|
+
const validation = {
|
|
145
|
+
...validationData,
|
|
146
|
+
hash,
|
|
147
|
+
};
|
|
148
|
+
// Store in history
|
|
149
|
+
this.validationHistory.push(validation);
|
|
150
|
+
const elapsed = performance.now() - startTime;
|
|
151
|
+
if (elapsed > 5) {
|
|
152
|
+
console.warn(`Physics validation exceeded target: ${elapsed.toFixed(2)}ms`);
|
|
153
|
+
}
|
|
154
|
+
return validation;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Check a specific constraint
|
|
158
|
+
*/
|
|
159
|
+
async checkConstraint(constraint, action, warrantConstraints) {
|
|
160
|
+
switch (constraint.type) {
|
|
161
|
+
case 'max_amount': {
|
|
162
|
+
const amount = action.params.amount;
|
|
163
|
+
const limit = warrantConstraints.maxAmount ?? constraint.params.limit;
|
|
164
|
+
if (amount !== undefined && amount > limit) {
|
|
165
|
+
return {
|
|
166
|
+
type: 'amount_exceeded',
|
|
167
|
+
constraint,
|
|
168
|
+
message: `Amount ${amount} exceeds limit ${limit}`,
|
|
169
|
+
severity: constraint.severity,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'domain_allowlist': {
|
|
175
|
+
const domain = action.params.domain;
|
|
176
|
+
const allowed = warrantConstraints.allowedDomains ?? constraint.params.domains;
|
|
177
|
+
if (domain && allowed.length > 0 && !allowed.includes(domain)) {
|
|
178
|
+
return {
|
|
179
|
+
type: 'domain_forbidden',
|
|
180
|
+
constraint,
|
|
181
|
+
message: `Domain ${domain} not in allowlist`,
|
|
182
|
+
severity: constraint.severity,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case 'allowlist': {
|
|
188
|
+
const field = constraint.params.field;
|
|
189
|
+
const value = action.params[field];
|
|
190
|
+
const allowed = warrantConstraints.allowedAccounts ?? [];
|
|
191
|
+
if (constraint.params.required && value && allowed.length > 0) {
|
|
192
|
+
// Check suffix matching for account numbers
|
|
193
|
+
const matches = allowed.some(pattern => {
|
|
194
|
+
if (pattern.startsWith('*')) {
|
|
195
|
+
return value.endsWith(pattern.slice(1));
|
|
196
|
+
}
|
|
197
|
+
return value === pattern;
|
|
198
|
+
});
|
|
199
|
+
if (!matches) {
|
|
200
|
+
return {
|
|
201
|
+
type: 'scope_violation',
|
|
202
|
+
constraint,
|
|
203
|
+
message: `${field} "${value}" not in allowlist`,
|
|
204
|
+
severity: constraint.severity,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Check warrant-level constraints
|
|
215
|
+
*/
|
|
216
|
+
checkWarrantConstraints(action, constraints) {
|
|
217
|
+
const violations = [];
|
|
218
|
+
// Check 2FA requirement
|
|
219
|
+
if (constraints.require2FA && !action.params.has2FA) {
|
|
220
|
+
violations.push({
|
|
221
|
+
type: 'scope_violation',
|
|
222
|
+
constraint: { type: 'require_2fa', params: {}, severity: 'block' },
|
|
223
|
+
message: '2FA required but not provided',
|
|
224
|
+
severity: 'block',
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return violations;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check rate limits
|
|
231
|
+
*/
|
|
232
|
+
checkRateLimit(action) {
|
|
233
|
+
const key = `${action.agent_id}:${action.type}`;
|
|
234
|
+
const now = Date.now();
|
|
235
|
+
const windowMs = 60 * 1000; // 1 minute window
|
|
236
|
+
let counter = this.rateCounters.get(key);
|
|
237
|
+
if (!counter || now - counter.windowStart > windowMs) {
|
|
238
|
+
counter = { count: 0, windowStart: now };
|
|
239
|
+
}
|
|
240
|
+
counter.count++;
|
|
241
|
+
this.rateCounters.set(key, counter);
|
|
242
|
+
// Default rate limit: 100 actions per minute
|
|
243
|
+
const limit = 100;
|
|
244
|
+
if (counter.count > limit) {
|
|
245
|
+
return {
|
|
246
|
+
type: 'rate_exceeded',
|
|
247
|
+
constraint: { type: 'rate_limit', params: { limit }, severity: 'block' },
|
|
248
|
+
message: `Rate limit exceeded: ${counter.count}/${limit} per minute`,
|
|
249
|
+
severity: 'block',
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Create a signed artifact
|
|
256
|
+
*/
|
|
257
|
+
async createSignedArtifact(type, content, version) {
|
|
258
|
+
if (!this.key) {
|
|
259
|
+
throw new Error('Engine not initialized. Call initialize() first.');
|
|
260
|
+
}
|
|
261
|
+
const now = generateTimestamp();
|
|
262
|
+
const hash = await sha256Object({ type, content, version, created_at: now });
|
|
263
|
+
const seal = await hmacSeal({ hash, type, version }, this.key);
|
|
264
|
+
return {
|
|
265
|
+
type,
|
|
266
|
+
content,
|
|
267
|
+
hash,
|
|
268
|
+
seal,
|
|
269
|
+
created_at: now,
|
|
270
|
+
version,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Hot-swap a policy (for runtime updates)
|
|
275
|
+
*/
|
|
276
|
+
async hotSwapPolicy(policy) {
|
|
277
|
+
// Create signed artifact for audit
|
|
278
|
+
const artifact = await this.createSignedArtifact('policy', policy, policy.version);
|
|
279
|
+
// Replace policy
|
|
280
|
+
this.policies.set(policy.id, policy);
|
|
281
|
+
return artifact;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get policy by ID
|
|
285
|
+
*/
|
|
286
|
+
getPolicy(id) {
|
|
287
|
+
return this.policies.get(id) || null;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get all policies
|
|
291
|
+
*/
|
|
292
|
+
getAllPolicies() {
|
|
293
|
+
return Array.from(this.policies.values());
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Get validation history for an agent
|
|
297
|
+
*/
|
|
298
|
+
getValidationHistory(agentId, limit = 100) {
|
|
299
|
+
let history = this.validationHistory;
|
|
300
|
+
if (agentId) {
|
|
301
|
+
history = history.filter(v => v.action.agent_id === agentId);
|
|
302
|
+
}
|
|
303
|
+
return history.slice(-limit);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Get plausibility statistics
|
|
307
|
+
*/
|
|
308
|
+
getStats() {
|
|
309
|
+
const total = this.validationHistory.length;
|
|
310
|
+
const valid = this.validationHistory.filter(v => v.valid).length;
|
|
311
|
+
const scores = this.validationHistory.map(v => v.score);
|
|
312
|
+
const avgScore = scores.length > 0
|
|
313
|
+
? scores.reduce((a, b) => a + b, 0) / scores.length
|
|
314
|
+
: 0;
|
|
315
|
+
const violationsByType = {};
|
|
316
|
+
for (const validation of this.validationHistory) {
|
|
317
|
+
for (const violation of validation.violations) {
|
|
318
|
+
violationsByType[violation.type] = (violationsByType[violation.type] || 0) + 1;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
totalValidations: total,
|
|
323
|
+
validCount: valid,
|
|
324
|
+
invalidCount: total - valid,
|
|
325
|
+
averageScore: avgScore,
|
|
326
|
+
violationsByType,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// ============================================================================
|
|
331
|
+
// CAUSALITY CHECKER
|
|
332
|
+
// ============================================================================
|
|
333
|
+
/**
|
|
334
|
+
* Ensures actions respect causal ordering
|
|
335
|
+
* "Effect cannot precede cause"
|
|
336
|
+
*/
|
|
337
|
+
export class CausalityChecker {
|
|
338
|
+
actionLog = [];
|
|
339
|
+
/**
|
|
340
|
+
* Record an action with its checkpoint
|
|
341
|
+
*/
|
|
342
|
+
record(action, checkpoint) {
|
|
343
|
+
this.actionLog.push({ action, checkpoint });
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Check if an action would violate causality
|
|
347
|
+
*/
|
|
348
|
+
checkCausality(_action, dependencies) {
|
|
349
|
+
// All dependencies must be in the log
|
|
350
|
+
for (const dep of dependencies) {
|
|
351
|
+
const found = this.actionLog.some(entry => entry.checkpoint === dep);
|
|
352
|
+
if (!found) {
|
|
353
|
+
return {
|
|
354
|
+
valid: false,
|
|
355
|
+
violation: `Dependency checkpoint ${dep} not found in causal history`,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return { valid: true };
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Get causal chain for an action
|
|
363
|
+
*/
|
|
364
|
+
getCausalChain(checkpointId) {
|
|
365
|
+
const index = this.actionLog.findIndex(e => e.checkpoint === checkpointId);
|
|
366
|
+
if (index === -1)
|
|
367
|
+
return [];
|
|
368
|
+
return this.actionLog.slice(0, index + 1).map(e => e.action);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/physics/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAML,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAoGxB,mBAAmB;AACnB,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C;QACE,EAAE,EAAE,uBAAuB;QAC3B,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE;YACX;gBACE,IAAI,EAAE,YAAY;gBAClB,MAAM,EA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