@vorionsys/atsf-core 0.1.0 → 0.2.1
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 +12 -12
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +463 -35
- package/dist/api/server.js.map +1 -1
- package/dist/arbitration/index.d.ts.map +1 -1
- package/dist/arbitration/index.js +8 -6
- package/dist/arbitration/index.js.map +1 -1
- package/dist/audit/key-manager.d.ts +118 -0
- package/dist/audit/key-manager.d.ts.map +1 -0
- package/dist/audit/key-manager.js +565 -0
- package/dist/audit/key-manager.js.map +1 -0
- package/dist/basis/evaluator.d.ts +31 -0
- package/dist/basis/evaluator.d.ts.map +1 -1
- package/dist/basis/evaluator.js +205 -10
- package/dist/basis/evaluator.js.map +1 -1
- package/dist/basis/parser.d.ts +210 -210
- package/dist/basis/parser.js.map +1 -1
- package/dist/carbon-aware/carbon-metrics.d.ts +151 -0
- package/dist/carbon-aware/carbon-metrics.d.ts.map +1 -0
- package/dist/carbon-aware/carbon-metrics.js +370 -0
- package/dist/carbon-aware/carbon-metrics.js.map +1 -0
- package/dist/carbon-aware/carbon-router.d.ts +101 -0
- package/dist/carbon-aware/carbon-router.d.ts.map +1 -0
- package/dist/carbon-aware/carbon-router.js +400 -0
- package/dist/carbon-aware/carbon-router.js.map +1 -0
- package/dist/chain/index.d.ts +147 -0
- package/dist/chain/index.d.ts.map +1 -0
- package/dist/chain/index.js +219 -0
- package/dist/chain/index.js.map +1 -0
- package/dist/cognigate/index.d.ts +33 -4
- package/dist/cognigate/index.d.ts.map +1 -1
- package/dist/cognigate/index.js +199 -24
- package/dist/cognigate/index.js.map +1 -1
- package/dist/common/adapters.d.ts +172 -0
- package/dist/common/adapters.d.ts.map +1 -0
- package/dist/common/adapters.js +329 -0
- package/dist/common/adapters.js.map +1 -0
- package/dist/common/config.d.ts +168 -163
- package/dist/common/config.d.ts.map +1 -1
- package/dist/common/config.js +2 -0
- package/dist/common/config.js.map +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -0
- package/dist/common/index.js.map +1 -1
- package/dist/common/types.d.ts +67 -16
- package/dist/common/types.d.ts.map +1 -1
- package/dist/common/types.js +4 -0
- package/dist/common/types.js.map +1 -1
- package/dist/enforce/index.d.ts +226 -16
- package/dist/enforce/index.d.ts.map +1 -1
- package/dist/enforce/index.js +196 -49
- package/dist/enforce/index.js.map +1 -1
- package/dist/governance/fluid-workflow.d.ts +217 -0
- package/dist/governance/fluid-workflow.d.ts.map +1 -0
- package/dist/governance/fluid-workflow.js +491 -0
- package/dist/governance/fluid-workflow.js.map +1 -0
- package/dist/governance/index.d.ts +1 -0
- package/dist/governance/index.d.ts.map +1 -1
- package/dist/governance/index.js +1 -0
- package/dist/governance/index.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/intent/index.d.ts +127 -10
- package/dist/intent/index.d.ts.map +1 -1
- package/dist/intent/index.js +121 -16
- package/dist/intent/index.js.map +1 -1
- package/dist/langchain/executor.d.ts +19 -5
- package/dist/langchain/executor.d.ts.map +1 -1
- package/dist/langchain/executor.js +287 -36
- package/dist/langchain/executor.js.map +1 -1
- package/dist/langchain/index.d.ts +2 -1
- package/dist/langchain/index.d.ts.map +1 -1
- package/dist/langchain/index.js +3 -1
- package/dist/langchain/index.js.map +1 -1
- package/dist/langchain/tools.d.ts.map +1 -1
- package/dist/langchain/tools.js +2 -1
- package/dist/langchain/tools.js.map +1 -1
- package/dist/langchain/types.d.ts +41 -0
- package/dist/langchain/types.d.ts.map +1 -1
- package/dist/layers/index.d.ts +1 -1
- package/dist/layers/index.d.ts.map +1 -1
- package/dist/persistence/file.d.ts +35 -3
- package/dist/persistence/file.d.ts.map +1 -1
- package/dist/persistence/file.js +138 -11
- package/dist/persistence/file.js.map +1 -1
- package/dist/persistence/index.d.ts +11 -1
- package/dist/persistence/index.d.ts.map +1 -1
- package/dist/persistence/index.js +25 -1
- package/dist/persistence/index.js.map +1 -1
- package/dist/persistence/sqlite.d.ts +135 -0
- package/dist/persistence/sqlite.d.ts.map +1 -0
- package/dist/persistence/sqlite.js +372 -0
- package/dist/persistence/sqlite.js.map +1 -0
- package/dist/persistence/supabase.d.ts +93 -0
- package/dist/persistence/supabase.d.ts.map +1 -0
- package/dist/persistence/supabase.js +219 -0
- package/dist/persistence/supabase.js.map +1 -0
- package/dist/persistence/types.d.ts +5 -1
- package/dist/persistence/types.d.ts.map +1 -1
- package/dist/phase6/ceiling.d.ts +177 -0
- package/dist/phase6/ceiling.d.ts.map +1 -0
- package/dist/phase6/ceiling.js +463 -0
- package/dist/phase6/ceiling.js.map +1 -0
- package/dist/phase6/context.d.ts +207 -0
- package/dist/phase6/context.d.ts.map +1 -0
- package/dist/phase6/context.js +603 -0
- package/dist/phase6/context.js.map +1 -0
- package/dist/phase6/index.d.ts +79 -0
- package/dist/phase6/index.d.ts.map +1 -0
- package/dist/phase6/index.js +152 -0
- package/dist/phase6/index.js.map +1 -0
- package/dist/phase6/presets.d.ts +148 -0
- package/dist/phase6/presets.d.ts.map +1 -0
- package/dist/phase6/presets.js +467 -0
- package/dist/phase6/presets.js.map +1 -0
- package/dist/phase6/provenance.d.ts +148 -0
- package/dist/phase6/provenance.d.ts.map +1 -0
- package/dist/phase6/provenance.js +545 -0
- package/dist/phase6/provenance.js.map +1 -0
- package/dist/phase6/role-gates/index.d.ts +7 -0
- package/dist/phase6/role-gates/index.d.ts.map +1 -0
- package/dist/phase6/role-gates/index.js +7 -0
- package/dist/phase6/role-gates/index.js.map +1 -0
- package/dist/phase6/role-gates/kernel.d.ts +84 -0
- package/dist/phase6/role-gates/kernel.d.ts.map +1 -0
- package/dist/phase6/role-gates/kernel.js +258 -0
- package/dist/phase6/role-gates/kernel.js.map +1 -0
- package/dist/phase6/role-gates/policy.d.ts +110 -0
- package/dist/phase6/role-gates/policy.d.ts.map +1 -0
- package/dist/phase6/role-gates/policy.js +157 -0
- package/dist/phase6/role-gates/policy.js.map +1 -0
- package/dist/phase6/role-gates.d.ts +164 -0
- package/dist/phase6/role-gates.d.ts.map +1 -0
- package/dist/phase6/role-gates.js +536 -0
- package/dist/phase6/role-gates.js.map +1 -0
- package/dist/phase6/types.d.ts +1827 -0
- package/dist/phase6/types.d.ts.map +1 -0
- package/dist/phase6/types.js +450 -0
- package/dist/phase6/types.js.map +1 -0
- package/dist/phase6/weight-presets/canonical.d.ts +93 -0
- package/dist/phase6/weight-presets/canonical.d.ts.map +1 -0
- package/dist/phase6/weight-presets/canonical.js +122 -0
- package/dist/phase6/weight-presets/canonical.js.map +1 -0
- package/dist/phase6/weight-presets/deltas.d.ts +144 -0
- package/dist/phase6/weight-presets/deltas.d.ts.map +1 -0
- package/dist/phase6/weight-presets/deltas.js +184 -0
- package/dist/phase6/weight-presets/deltas.js.map +1 -0
- package/dist/phase6/weight-presets/index.d.ts +8 -0
- package/dist/phase6/weight-presets/index.d.ts.map +1 -0
- package/dist/phase6/weight-presets/index.js +8 -0
- package/dist/phase6/weight-presets/index.js.map +1 -0
- package/dist/phase6/weight-presets/merger.d.ts +79 -0
- package/dist/phase6/weight-presets/merger.d.ts.map +1 -0
- package/dist/phase6/weight-presets/merger.js +161 -0
- package/dist/phase6/weight-presets/merger.js.map +1 -0
- package/dist/proof/index.d.ts +50 -1
- package/dist/proof/index.d.ts.map +1 -1
- package/dist/proof/index.js +122 -3
- package/dist/proof/index.js.map +1 -1
- package/dist/proof/merkle.d.ts +195 -0
- package/dist/proof/merkle.d.ts.map +1 -0
- package/dist/proof/merkle.js +412 -0
- package/dist/proof/merkle.js.map +1 -0
- package/dist/proof/zk-proofs.d.ts +218 -0
- package/dist/proof/zk-proofs.d.ts.map +1 -0
- package/dist/proof/zk-proofs.js +531 -0
- package/dist/proof/zk-proofs.js.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/audit.d.ts +98 -0
- package/dist/trust-engine/ceiling-enforcement/audit.d.ts.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/audit.js +160 -0
- package/dist/trust-engine/ceiling-enforcement/audit.js.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/index.d.ts +6 -0
- package/dist/trust-engine/ceiling-enforcement/index.d.ts.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/index.js +6 -0
- package/dist/trust-engine/ceiling-enforcement/index.js.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.d.ts +112 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.d.ts.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.js +158 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.js.map +1 -0
- package/dist/trust-engine/context-policy/enforcement.d.ts +62 -0
- package/dist/trust-engine/context-policy/enforcement.d.ts.map +1 -0
- package/dist/trust-engine/context-policy/enforcement.js +104 -0
- package/dist/trust-engine/context-policy/enforcement.js.map +1 -0
- package/dist/trust-engine/context-policy/factory.d.ts +75 -0
- package/dist/trust-engine/context-policy/factory.d.ts.map +1 -0
- package/dist/trust-engine/context-policy/factory.js +130 -0
- package/dist/trust-engine/context-policy/factory.js.map +1 -0
- package/dist/trust-engine/context-policy/index.d.ts +6 -0
- package/dist/trust-engine/context-policy/index.d.ts.map +1 -0
- package/dist/trust-engine/context-policy/index.js +6 -0
- package/dist/trust-engine/context-policy/index.js.map +1 -0
- package/dist/trust-engine/creation-modifiers/index.d.ts +5 -0
- package/dist/trust-engine/creation-modifiers/index.d.ts.map +1 -0
- package/dist/trust-engine/creation-modifiers/index.js +5 -0
- package/dist/trust-engine/creation-modifiers/index.js.map +1 -0
- package/dist/trust-engine/creation-modifiers/types.d.ts +112 -0
- package/dist/trust-engine/creation-modifiers/types.d.ts.map +1 -0
- package/dist/trust-engine/creation-modifiers/types.js +166 -0
- package/dist/trust-engine/creation-modifiers/types.js.map +1 -0
- package/dist/trust-engine/decay-profiles.d.ts +159 -0
- package/dist/trust-engine/decay-profiles.d.ts.map +1 -0
- package/dist/trust-engine/decay-profiles.js +210 -0
- package/dist/trust-engine/decay-profiles.js.map +1 -0
- package/dist/trust-engine/index.d.ts +144 -5
- package/dist/trust-engine/index.d.ts.map +1 -1
- package/dist/trust-engine/index.js +320 -15
- package/dist/trust-engine/index.js.map +1 -1
- package/dist/trust-engine/phase6-types.d.ts +123 -0
- package/dist/trust-engine/phase6-types.d.ts.map +1 -0
- package/dist/trust-engine/phase6-types.js +88 -0
- package/dist/trust-engine/phase6-types.js.map +1 -0
- package/package.json +26 -10
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Q2: Context Policy - Multi-Tenant Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates and manages agent contexts across multiple tenants
|
|
5
|
+
* Ensures strict isolation and immutability per tenant
|
|
6
|
+
*/
|
|
7
|
+
import { ContextType, AgentContext } from './enforcement.js';
|
|
8
|
+
/**
|
|
9
|
+
* Agent context registry per tenant
|
|
10
|
+
* Maintains immutable contexts and prevents cross-tenant access
|
|
11
|
+
*/
|
|
12
|
+
export declare class MultiTenantContextFactory {
|
|
13
|
+
private contexts;
|
|
14
|
+
private tenantHierarchy;
|
|
15
|
+
private creationLog;
|
|
16
|
+
/**
|
|
17
|
+
* Register a tenant with maximum allowed context level
|
|
18
|
+
*/
|
|
19
|
+
registerTenant(tenantId: string, maxContext: ContextType): void;
|
|
20
|
+
/**
|
|
21
|
+
* Create an agent context for a specific tenant
|
|
22
|
+
* Enforces tenant's maximum context level
|
|
23
|
+
*/
|
|
24
|
+
createContextForTenant(tenantId: string, agentId: string, requestedContext: ContextType, createdBy: string): AgentContext;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieve an agent's context (only from its own tenant)
|
|
27
|
+
* Enforces strict multi-tenant isolation
|
|
28
|
+
*/
|
|
29
|
+
getContextForAgent(tenantId: string, agentId: string): AgentContext | null;
|
|
30
|
+
/**
|
|
31
|
+
* Verify context integrity across all tenants
|
|
32
|
+
* Detects tampering or corruption
|
|
33
|
+
*/
|
|
34
|
+
verifyAllContexts(): {
|
|
35
|
+
valid: number;
|
|
36
|
+
invalid: number;
|
|
37
|
+
invalidContexts: Array<{
|
|
38
|
+
tenantId: string;
|
|
39
|
+
agentId: string;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Get creation audit log
|
|
44
|
+
*/
|
|
45
|
+
getCreationLog(): Array<{
|
|
46
|
+
timestamp: Date;
|
|
47
|
+
tenantId: string;
|
|
48
|
+
agentId: string;
|
|
49
|
+
contextType: ContextType;
|
|
50
|
+
createdBy: string;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Get creation log for specific tenant
|
|
54
|
+
*/
|
|
55
|
+
getTenantCreationLog(tenantId: string): Array<{
|
|
56
|
+
timestamp: Date;
|
|
57
|
+
tenantId: string;
|
|
58
|
+
agentId: string;
|
|
59
|
+
contextType: ContextType;
|
|
60
|
+
createdBy: string;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Count agents per tenant
|
|
64
|
+
*/
|
|
65
|
+
getAgentCountPerTenant(): Map<string, number>;
|
|
66
|
+
/**
|
|
67
|
+
* Clear all data (for testing)
|
|
68
|
+
*/
|
|
69
|
+
clear(): void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Global multi-tenant factory instance
|
|
73
|
+
*/
|
|
74
|
+
export declare const globalContextFactory: MultiTenantContextFactory;
|
|
75
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/context-policy/factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EACX,YAAY,EAGb,MAAM,kBAAkB,CAAC;AAE1B;;;GAGG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,QAAQ,CA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@@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Q2: Context Policy - Multi-Tenant Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates and manages agent contexts across multiple tenants
|
|
5
|
+
* Ensures strict isolation and immutability per tenant
|
|
6
|
+
*/
|
|
7
|
+
import { ContextType, createAgentContext, verifyContextIntegrity, } from './enforcement.js';
|
|
8
|
+
/**
|
|
9
|
+
* Agent context registry per tenant
|
|
10
|
+
* Maintains immutable contexts and prevents cross-tenant access
|
|
11
|
+
*/
|
|
12
|
+
export class MultiTenantContextFactory {
|
|
13
|
+
contexts = new Map(); // tenantId → agentId → context
|
|
14
|
+
tenantHierarchy = new Map(); // tenantId → max allowed context
|
|
15
|
+
creationLog = [];
|
|
16
|
+
/**
|
|
17
|
+
* Register a tenant with maximum allowed context level
|
|
18
|
+
*/
|
|
19
|
+
registerTenant(tenantId, maxContext) {
|
|
20
|
+
this.tenantHierarchy.set(tenantId, maxContext);
|
|
21
|
+
this.contexts.set(tenantId, new Map());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create an agent context for a specific tenant
|
|
25
|
+
* Enforces tenant's maximum context level
|
|
26
|
+
*/
|
|
27
|
+
createContextForTenant(tenantId, agentId, requestedContext, createdBy) {
|
|
28
|
+
// Validate tenant exists
|
|
29
|
+
if (!this.tenantHierarchy.has(tenantId)) {
|
|
30
|
+
throw new Error(`Tenant not registered: ${tenantId}`);
|
|
31
|
+
}
|
|
32
|
+
// Enforce tenant's max context level
|
|
33
|
+
const maxContext = this.tenantHierarchy.get(tenantId);
|
|
34
|
+
const contextOrder = [
|
|
35
|
+
ContextType.LOCAL,
|
|
36
|
+
ContextType.ENTERPRISE,
|
|
37
|
+
ContextType.SOVEREIGN,
|
|
38
|
+
];
|
|
39
|
+
const requestedRank = contextOrder.indexOf(requestedContext);
|
|
40
|
+
const maxRank = contextOrder.indexOf(maxContext);
|
|
41
|
+
if (requestedRank > maxRank) {
|
|
42
|
+
throw new Error(`Tenant ${tenantId} not allowed context ${requestedContext} (max: ${maxContext})`);
|
|
43
|
+
}
|
|
44
|
+
// Check if context already exists (immutability - can't recreate)
|
|
45
|
+
const tenantContexts = this.contexts.get(tenantId);
|
|
46
|
+
if (tenantContexts.has(agentId)) {
|
|
47
|
+
throw new Error(`Agent ${agentId} context already exists (immutable) - cannot recreate`);
|
|
48
|
+
}
|
|
49
|
+
// Create context
|
|
50
|
+
const context = createAgentContext(requestedContext, agentId, tenantId, createdBy);
|
|
51
|
+
// Store in tenant's registry
|
|
52
|
+
tenantContexts.set(agentId, context);
|
|
53
|
+
// Log creation
|
|
54
|
+
this.creationLog.push({
|
|
55
|
+
timestamp: new Date(),
|
|
56
|
+
tenantId,
|
|
57
|
+
agentId,
|
|
58
|
+
contextType: requestedContext,
|
|
59
|
+
createdBy,
|
|
60
|
+
});
|
|
61
|
+
return context;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieve an agent's context (only from its own tenant)
|
|
65
|
+
* Enforces strict multi-tenant isolation
|
|
66
|
+
*/
|
|
67
|
+
getContextForAgent(tenantId, agentId) {
|
|
68
|
+
const tenantContexts = this.contexts.get(tenantId);
|
|
69
|
+
if (!tenantContexts) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return tenantContexts.get(agentId) || null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Verify context integrity across all tenants
|
|
76
|
+
* Detects tampering or corruption
|
|
77
|
+
*/
|
|
78
|
+
verifyAllContexts() {
|
|
79
|
+
let valid = 0;
|
|
80
|
+
let invalid = 0;
|
|
81
|
+
const invalidContexts = [];
|
|
82
|
+
this.contexts.forEach((tenantContexts, tenantId) => {
|
|
83
|
+
tenantContexts.forEach((context, agentId) => {
|
|
84
|
+
if (verifyContextIntegrity(context)) {
|
|
85
|
+
valid++;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
invalid++;
|
|
89
|
+
invalidContexts.push({ tenantId, agentId });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return { valid, invalid, invalidContexts };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get creation audit log
|
|
97
|
+
*/
|
|
98
|
+
getCreationLog() {
|
|
99
|
+
return [...this.creationLog];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get creation log for specific tenant
|
|
103
|
+
*/
|
|
104
|
+
getTenantCreationLog(tenantId) {
|
|
105
|
+
return this.creationLog.filter((log) => log.tenantId === tenantId);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Count agents per tenant
|
|
109
|
+
*/
|
|
110
|
+
getAgentCountPerTenant() {
|
|
111
|
+
const counts = new Map();
|
|
112
|
+
this.contexts.forEach((tenantContexts, tenantId) => {
|
|
113
|
+
counts.set(tenantId, tenantContexts.size);
|
|
114
|
+
});
|
|
115
|
+
return counts;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Clear all data (for testing)
|
|
119
|
+
*/
|
|
120
|
+
clear() {
|
|
121
|
+
this.contexts.clear();
|
|
122
|
+
this.tenantHierarchy.clear();
|
|
123
|
+
this.creationLog = [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Global multi-tenant factory instance
|
|
128
|
+
*/
|
|
129
|
+
export const globalContextFactory = new MultiTenantContextFactory();
|
|
130
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/trust-engine/context-policy/factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,WAAW,EAEX,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IAC5B,QAAQ,GAA2C,IAAI,GAAG,EAAE,CAAC,CAAC,+BAA+B;IAC7F,eAAe,GAA6B,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EH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,cAAc;QAOZ,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,QAAgB;QAOnC,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACH,sBAAsB;QACpB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;QACzC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,QAAQ,EAAE,EAAE;YACjD,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/context-policy/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trust-engine/context-policy/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/creation-modifiers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trust-engine/creation-modifiers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Q5: Creation Modifiers - Type & Migration Layer
|
|
3
|
+
*
|
|
4
|
+
* Core responsibility: Track agent creation type immutably
|
|
5
|
+
* - Type set at instantiation, never changes
|
|
6
|
+
* - Modifiers applied to initial trust score
|
|
7
|
+
* - Migration events for lifecycle transitions
|
|
8
|
+
* - Cryptographic proof of origin facts
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Agent creation types with assigned modifiers
|
|
12
|
+
* These determine initial trust score adjustments
|
|
13
|
+
*/
|
|
14
|
+
export declare enum CreationType {
|
|
15
|
+
FRESH = "fresh",// +0 modifier: New agent, baseline
|
|
16
|
+
CLONED = "cloned",// -50 modifier: Cloned from existing (uncertainty)
|
|
17
|
+
EVOLVED = "evolved",// +25 modifier: Evolved from existing (proven)
|
|
18
|
+
PROMOTED = "promoted",// +50 modifier: Promoted from lower tier
|
|
19
|
+
IMPORTED = "imported"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Modifiers applied based on creation type
|
|
23
|
+
* These adjust the initial trust score
|
|
24
|
+
*/
|
|
25
|
+
export declare const CREATION_MODIFIERS: Record<CreationType, number>;
|
|
26
|
+
/**
|
|
27
|
+
* Immutable creation information
|
|
28
|
+
*/
|
|
29
|
+
export interface CreationInfo {
|
|
30
|
+
readonly creationType: CreationType;
|
|
31
|
+
readonly parentAgentId?: string;
|
|
32
|
+
readonly createdAt: Date;
|
|
33
|
+
readonly createdBy: string;
|
|
34
|
+
readonly creationHash: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Migration event for creation type changes (rare, tracked)
|
|
38
|
+
*/
|
|
39
|
+
export interface CreationMigrationEvent {
|
|
40
|
+
timestamp: Date;
|
|
41
|
+
agentId: string;
|
|
42
|
+
fromType: CreationType;
|
|
43
|
+
toType: CreationType;
|
|
44
|
+
reason: string;
|
|
45
|
+
approvedBy: string;
|
|
46
|
+
migrationHash: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validate that a creation type is valid
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateCreationType(value: unknown): value is CreationType;
|
|
52
|
+
/**
|
|
53
|
+
* Get modifier for a creation type
|
|
54
|
+
*/
|
|
55
|
+
export declare function getCreationModifier(creationType: CreationType): number;
|
|
56
|
+
/**
|
|
57
|
+
* Compute cryptographic hash of creation info for immutability proof
|
|
58
|
+
*/
|
|
59
|
+
export declare function computeCreationHash(creationType: CreationType, parentAgentId: string | undefined, createdAt: Date, createdBy: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Create immutable creation info at instantiation
|
|
62
|
+
* This is the ONLY place creation type can be set
|
|
63
|
+
*/
|
|
64
|
+
export declare function createCreationInfo(creationType: CreationType, parentAgentId: string | undefined, createdBy: string): CreationInfo;
|
|
65
|
+
/**
|
|
66
|
+
* Verify creation info hasn't been tampered with
|
|
67
|
+
*/
|
|
68
|
+
export declare function verifyCreationIntegrity(creation: CreationInfo): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Apply creation modifier to base trust score
|
|
71
|
+
* Clamps result to [0, 1000]
|
|
72
|
+
*/
|
|
73
|
+
export declare function applyCreationModifier(baseScore: number, creationType: CreationType): number;
|
|
74
|
+
/**
|
|
75
|
+
* Compute initial trust score based on creation type
|
|
76
|
+
* FRESH agents start at 250 (T1 monitored)
|
|
77
|
+
* Modifiers adjust from there
|
|
78
|
+
*/
|
|
79
|
+
export declare function computeInitialTrustScore(creationType: CreationType, baselineScore?: number): number;
|
|
80
|
+
/**
|
|
81
|
+
* Migration tracker for creation type transitions (rare)
|
|
82
|
+
*/
|
|
83
|
+
export declare class CreationMigrationTracker {
|
|
84
|
+
private migrations;
|
|
85
|
+
/**
|
|
86
|
+
* Record a creation type migration
|
|
87
|
+
* These are exceptional and require explicit approval
|
|
88
|
+
*/
|
|
89
|
+
recordMigration(agentId: string, fromType: CreationType, toType: CreationType, reason: string, approvedBy: string): CreationMigrationEvent;
|
|
90
|
+
/**
|
|
91
|
+
* Get all migrations for an agent
|
|
92
|
+
*/
|
|
93
|
+
getMigrationsForAgent(agentId: string): CreationMigrationEvent[];
|
|
94
|
+
/**
|
|
95
|
+
* Get all migrations
|
|
96
|
+
*/
|
|
97
|
+
getAllMigrations(): CreationMigrationEvent[];
|
|
98
|
+
/**
|
|
99
|
+
* Verify migration integrity
|
|
100
|
+
*/
|
|
101
|
+
verifyMigrationIntegrity(event: CreationMigrationEvent): boolean;
|
|
102
|
+
private computeMigrationHash;
|
|
103
|
+
/**
|
|
104
|
+
* Clear migrations (for testing)
|
|
105
|
+
*/
|
|
106
|
+
clear(): void;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Global migration tracker instance
|
|
110
|
+
*/
|
|
111
|
+
export declare const globalMigrationTracker: CreationMigrationTracker;
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/creation-modifiers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,oBAAY,YAAY;IACtB,KAAK,UAAU,CAAQ,mCAAmC;IAC1D,MAAM,WAAW,CAAM,mDAAmD;IAC1E,OAAO,YAAY,CAAI,+CAA+C;IACtE,QAAQ,aAAa,CAAE,yCAAyC;IAChE,QAAQ,aAAa;CACtB;AAED;;;GAGG;AACH,e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R;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,YAAY,EAC1B,aAAa,GAAE,MAAY,GAC1B,MAAM,CAER;AAED;;GAEG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,UAAU,CAAgC;IAElD;;;OAGG;IACH,eAAe,CACb,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,sBAAsB;IAoBzB;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,EAAE;IAIhE;;OAEG;IACH,gBAAgB,IAAI,sBAAsB,EAAE;IAI5C;;OAEG;IACH,wBAAwB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO;IAUhE,OAAO,CAAC,oBAAoB;IAgB5B;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,0BAAiC,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Q5: Creation Modifiers - Type & Migration Layer
|
|
3
|
+
*
|
|
4
|
+
* Core responsibility: Track agent creation type immutably
|
|
5
|
+
* - Type set at instantiation, never changes
|
|
6
|
+
* - Modifiers applied to initial trust score
|
|
7
|
+
* - Migration events for lifecycle transitions
|
|
8
|
+
* - Cryptographic proof of origin facts
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Agent creation types with assigned modifiers
|
|
12
|
+
* These determine initial trust score adjustments
|
|
13
|
+
*/
|
|
14
|
+
export var CreationType;
|
|
15
|
+
(function (CreationType) {
|
|
16
|
+
CreationType["FRESH"] = "fresh";
|
|
17
|
+
CreationType["CLONED"] = "cloned";
|
|
18
|
+
CreationType["EVOLVED"] = "evolved";
|
|
19
|
+
CreationType["PROMOTED"] = "promoted";
|
|
20
|
+
CreationType["IMPORTED"] = "imported";
|
|
21
|
+
})(CreationType || (CreationType = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Modifiers applied based on creation type
|
|
24
|
+
* These adjust the initial trust score
|
|
25
|
+
*/
|
|
26
|
+
export const CREATION_MODIFIERS = {
|
|
27
|
+
[CreationType.FRESH]: 0, // Start at baseline
|
|
28
|
+
[CreationType.CLONED]: -50, // Discount for uncertainty
|
|
29
|
+
[CreationType.EVOLVED]: 25, // Bonus for proven evolution
|
|
30
|
+
[CreationType.PROMOTED]: 50, // Bonus for promotion
|
|
31
|
+
[CreationType.IMPORTED]: -100, // Heavy discount for external origin
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Validate that a creation type is valid
|
|
35
|
+
*/
|
|
36
|
+
export function validateCreationType(value) {
|
|
37
|
+
return Object.values(CreationType).includes(value);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get modifier for a creation type
|
|
41
|
+
*/
|
|
42
|
+
export function getCreationModifier(creationType) {
|
|
43
|
+
if (!validateCreationType(creationType)) {
|
|
44
|
+
throw new Error(`Invalid creation type: ${creationType}`);
|
|
45
|
+
}
|
|
46
|
+
return CREATION_MODIFIERS[creationType];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Compute cryptographic hash of creation info for immutability proof
|
|
50
|
+
*/
|
|
51
|
+
export function computeCreationHash(creationType, parentAgentId, createdAt, createdBy) {
|
|
52
|
+
const data = `${creationType}|${parentAgentId || 'none'}|${createdAt.toISOString()}|${createdBy}`;
|
|
53
|
+
let hash = 0;
|
|
54
|
+
for (let i = 0; i < data.length; i++) {
|
|
55
|
+
const char = data.charCodeAt(i);
|
|
56
|
+
hash = (hash << 5) - hash + char;
|
|
57
|
+
hash = hash & hash;
|
|
58
|
+
}
|
|
59
|
+
return Math.abs(hash).toString(16);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create immutable creation info at instantiation
|
|
63
|
+
* This is the ONLY place creation type can be set
|
|
64
|
+
*/
|
|
65
|
+
export function createCreationInfo(creationType, parentAgentId, createdBy) {
|
|
66
|
+
if (!validateCreationType(creationType)) {
|
|
67
|
+
throw new Error(`Invalid creation type: ${creationType}`);
|
|
68
|
+
}
|
|
69
|
+
const createdAt = new Date();
|
|
70
|
+
const creationHash = computeCreationHash(creationType, parentAgentId, createdAt, createdBy);
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
creationType,
|
|
73
|
+
parentAgentId,
|
|
74
|
+
createdAt,
|
|
75
|
+
createdBy,
|
|
76
|
+
creationHash,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Verify creation info hasn't been tampered with
|
|
81
|
+
*/
|
|
82
|
+
export function verifyCreationIntegrity(creation) {
|
|
83
|
+
const expectedHash = computeCreationHash(creation.creationType, creation.parentAgentId, creation.createdAt, creation.createdBy);
|
|
84
|
+
return creation.creationHash === expectedHash;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Apply creation modifier to base trust score
|
|
88
|
+
* Clamps result to [0, 1000]
|
|
89
|
+
*/
|
|
90
|
+
export function applyCreationModifier(baseScore, creationType) {
|
|
91
|
+
const modifier = getCreationModifier(creationType);
|
|
92
|
+
const adjusted = baseScore + modifier;
|
|
93
|
+
return Math.max(0, Math.min(1000, adjusted));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Compute initial trust score based on creation type
|
|
97
|
+
* FRESH agents start at 250 (T1 monitored)
|
|
98
|
+
* Modifiers adjust from there
|
|
99
|
+
*/
|
|
100
|
+
export function computeInitialTrustScore(creationType, baselineScore = 250 // T1 (monitored) baseline
|
|
101
|
+
) {
|
|
102
|
+
return applyCreationModifier(baselineScore, creationType);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Migration tracker for creation type transitions (rare)
|
|
106
|
+
*/
|
|
107
|
+
export class CreationMigrationTracker {
|
|
108
|
+
migrations = [];
|
|
109
|
+
/**
|
|
110
|
+
* Record a creation type migration
|
|
111
|
+
* These are exceptional and require explicit approval
|
|
112
|
+
*/
|
|
113
|
+
recordMigration(agentId, fromType, toType, reason, approvedBy) {
|
|
114
|
+
const event = {
|
|
115
|
+
timestamp: new Date(),
|
|
116
|
+
agentId,
|
|
117
|
+
fromType,
|
|
118
|
+
toType,
|
|
119
|
+
reason,
|
|
120
|
+
approvedBy,
|
|
121
|
+
migrationHash: this.computeMigrationHash(agentId, fromType, toType, reason),
|
|
122
|
+
};
|
|
123
|
+
this.migrations.push(event);
|
|
124
|
+
return event;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get all migrations for an agent
|
|
128
|
+
*/
|
|
129
|
+
getMigrationsForAgent(agentId) {
|
|
130
|
+
return this.migrations.filter((m) => m.agentId === agentId);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get all migrations
|
|
134
|
+
*/
|
|
135
|
+
getAllMigrations() {
|
|
136
|
+
return [...this.migrations];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Verify migration integrity
|
|
140
|
+
*/
|
|
141
|
+
verifyMigrationIntegrity(event) {
|
|
142
|
+
const expectedHash = this.computeMigrationHash(event.agentId, event.fromType, event.toType, event.reason);
|
|
143
|
+
return event.migrationHash === expectedHash;
|
|
144
|
+
}
|
|
145
|
+
computeMigrationHash(agentId, fromType, toType, reason) {
|
|
146
|
+
const data = `${agentId}|${fromType}→${toType}|${reason}`;
|
|
147
|
+
let hash = 0;
|
|
148
|
+
for (let i = 0; i < data.length; i++) {
|
|
149
|
+
const char = data.charCodeAt(i);
|
|
150
|
+
hash = (hash << 5) - hash + char;
|
|
151
|
+
hash = hash & hash;
|
|
152
|
+
}
|
|
153
|
+
return Math.abs(hash).toString(16);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Clear migrations (for testing)
|
|
157
|
+
*/
|
|
158
|
+
clear() {
|
|
159
|
+
this.migrations = [];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Global migration tracker instance
|
|
164
|
+
*/
|
|
165
|
+
export const globalMigrationTracker = new CreationMigrationTracker();
|
|
166
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/trust-engine/creation-modifiers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,MAAM,CAAN,IAAY,YAMX;AAND,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;AACvB,CAAC,EANW,YAAY,KAAZ,YAAY,QAMvB;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAiC;IAC9D,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,EAAQ,oBAAoB;IACnD,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAK,2BAA2B;IAC1D,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,EAAE,EAAK,6BAA6B;IAC5D,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAI,sBAAsB;IACrD,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,qCAAqC;CACrE,CAAC;AA0BF;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,KAAqB,CAAC,CAAC;AACrE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,YAA0B;IAC5D,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,0BAA0B,YAAY,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAC;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