@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.
Files changed (215) hide show
  1. package/README.md +12 -12
  2. package/dist/api/server.d.ts.map +1 -1
  3. package/dist/api/server.js +463 -35
  4. package/dist/api/server.js.map +1 -1
  5. package/dist/arbitration/index.d.ts.map +1 -1
  6. package/dist/arbitration/index.js +8 -6
  7. package/dist/arbitration/index.js.map +1 -1
  8. package/dist/audit/key-manager.d.ts +118 -0
  9. package/dist/audit/key-manager.d.ts.map +1 -0
  10. package/dist/audit/key-manager.js +565 -0
  11. package/dist/audit/key-manager.js.map +1 -0
  12. package/dist/basis/evaluator.d.ts +31 -0
  13. package/dist/basis/evaluator.d.ts.map +1 -1
  14. package/dist/basis/evaluator.js +205 -10
  15. package/dist/basis/evaluator.js.map +1 -1
  16. package/dist/basis/parser.d.ts +210 -210
  17. package/dist/basis/parser.js.map +1 -1
  18. package/dist/carbon-aware/carbon-metrics.d.ts +151 -0
  19. package/dist/carbon-aware/carbon-metrics.d.ts.map +1 -0
  20. package/dist/carbon-aware/carbon-metrics.js +370 -0
  21. package/dist/carbon-aware/carbon-metrics.js.map +1 -0
  22. package/dist/carbon-aware/carbon-router.d.ts +101 -0
  23. package/dist/carbon-aware/carbon-router.d.ts.map +1 -0
  24. package/dist/carbon-aware/carbon-router.js +400 -0
  25. package/dist/carbon-aware/carbon-router.js.map +1 -0
  26. package/dist/chain/index.d.ts +147 -0
  27. package/dist/chain/index.d.ts.map +1 -0
  28. package/dist/chain/index.js +219 -0
  29. package/dist/chain/index.js.map +1 -0
  30. package/dist/cognigate/index.d.ts +33 -4
  31. package/dist/cognigate/index.d.ts.map +1 -1
  32. package/dist/cognigate/index.js +199 -24
  33. package/dist/cognigate/index.js.map +1 -1
  34. package/dist/common/adapters.d.ts +172 -0
  35. package/dist/common/adapters.d.ts.map +1 -0
  36. package/dist/common/adapters.js +329 -0
  37. package/dist/common/adapters.js.map +1 -0
  38. package/dist/common/config.d.ts +168 -163
  39. package/dist/common/config.d.ts.map +1 -1
  40. package/dist/common/config.js +2 -0
  41. package/dist/common/config.js.map +1 -1
  42. package/dist/common/index.d.ts +1 -0
  43. package/dist/common/index.d.ts.map +1 -1
  44. package/dist/common/index.js +1 -0
  45. package/dist/common/index.js.map +1 -1
  46. package/dist/common/types.d.ts +67 -16
  47. package/dist/common/types.d.ts.map +1 -1
  48. package/dist/common/types.js +4 -0
  49. package/dist/common/types.js.map +1 -1
  50. package/dist/enforce/index.d.ts +226 -16
  51. package/dist/enforce/index.d.ts.map +1 -1
  52. package/dist/enforce/index.js +196 -49
  53. package/dist/enforce/index.js.map +1 -1
  54. package/dist/governance/fluid-workflow.d.ts +217 -0
  55. package/dist/governance/fluid-workflow.d.ts.map +1 -0
  56. package/dist/governance/fluid-workflow.js +491 -0
  57. package/dist/governance/fluid-workflow.js.map +1 -0
  58. package/dist/governance/index.d.ts +1 -0
  59. package/dist/governance/index.d.ts.map +1 -1
  60. package/dist/governance/index.js +1 -0
  61. package/dist/governance/index.js.map +1 -1
  62. package/dist/index.d.ts +9 -3
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +14 -3
  65. package/dist/index.js.map +1 -1
  66. package/dist/intent/index.d.ts +127 -10
  67. package/dist/intent/index.d.ts.map +1 -1
  68. package/dist/intent/index.js +121 -16
  69. package/dist/intent/index.js.map +1 -1
  70. package/dist/langchain/executor.d.ts +19 -5
  71. package/dist/langchain/executor.d.ts.map +1 -1
  72. package/dist/langchain/executor.js +287 -36
  73. package/dist/langchain/executor.js.map +1 -1
  74. package/dist/langchain/index.d.ts +2 -1
  75. package/dist/langchain/index.d.ts.map +1 -1
  76. package/dist/langchain/index.js +3 -1
  77. package/dist/langchain/index.js.map +1 -1
  78. package/dist/langchain/tools.d.ts.map +1 -1
  79. package/dist/langchain/tools.js +2 -1
  80. package/dist/langchain/tools.js.map +1 -1
  81. package/dist/langchain/types.d.ts +41 -0
  82. package/dist/langchain/types.d.ts.map +1 -1
  83. package/dist/layers/index.d.ts +1 -1
  84. package/dist/layers/index.d.ts.map +1 -1
  85. package/dist/persistence/file.d.ts +35 -3
  86. package/dist/persistence/file.d.ts.map +1 -1
  87. package/dist/persistence/file.js +138 -11
  88. package/dist/persistence/file.js.map +1 -1
  89. package/dist/persistence/index.d.ts +11 -1
  90. package/dist/persistence/index.d.ts.map +1 -1
  91. package/dist/persistence/index.js +25 -1
  92. package/dist/persistence/index.js.map +1 -1
  93. package/dist/persistence/sqlite.d.ts +135 -0
  94. package/dist/persistence/sqlite.d.ts.map +1 -0
  95. package/dist/persistence/sqlite.js +372 -0
  96. package/dist/persistence/sqlite.js.map +1 -0
  97. package/dist/persistence/supabase.d.ts +93 -0
  98. package/dist/persistence/supabase.d.ts.map +1 -0
  99. package/dist/persistence/supabase.js +219 -0
  100. package/dist/persistence/supabase.js.map +1 -0
  101. package/dist/persistence/types.d.ts +5 -1
  102. package/dist/persistence/types.d.ts.map +1 -1
  103. package/dist/phase6/ceiling.d.ts +177 -0
  104. package/dist/phase6/ceiling.d.ts.map +1 -0
  105. package/dist/phase6/ceiling.js +463 -0
  106. package/dist/phase6/ceiling.js.map +1 -0
  107. package/dist/phase6/context.d.ts +207 -0
  108. package/dist/phase6/context.d.ts.map +1 -0
  109. package/dist/phase6/context.js +603 -0
  110. package/dist/phase6/context.js.map +1 -0
  111. package/dist/phase6/index.d.ts +79 -0
  112. package/dist/phase6/index.d.ts.map +1 -0
  113. package/dist/phase6/index.js +152 -0
  114. package/dist/phase6/index.js.map +1 -0
  115. package/dist/phase6/presets.d.ts +148 -0
  116. package/dist/phase6/presets.d.ts.map +1 -0
  117. package/dist/phase6/presets.js +467 -0
  118. package/dist/phase6/presets.js.map +1 -0
  119. package/dist/phase6/provenance.d.ts +148 -0
  120. package/dist/phase6/provenance.d.ts.map +1 -0
  121. package/dist/phase6/provenance.js +545 -0
  122. package/dist/phase6/provenance.js.map +1 -0
  123. package/dist/phase6/role-gates/index.d.ts +7 -0
  124. package/dist/phase6/role-gates/index.d.ts.map +1 -0
  125. package/dist/phase6/role-gates/index.js +7 -0
  126. package/dist/phase6/role-gates/index.js.map +1 -0
  127. package/dist/phase6/role-gates/kernel.d.ts +84 -0
  128. package/dist/phase6/role-gates/kernel.d.ts.map +1 -0
  129. package/dist/phase6/role-gates/kernel.js +258 -0
  130. package/dist/phase6/role-gates/kernel.js.map +1 -0
  131. package/dist/phase6/role-gates/policy.d.ts +110 -0
  132. package/dist/phase6/role-gates/policy.d.ts.map +1 -0
  133. package/dist/phase6/role-gates/policy.js +157 -0
  134. package/dist/phase6/role-gates/policy.js.map +1 -0
  135. package/dist/phase6/role-gates.d.ts +164 -0
  136. package/dist/phase6/role-gates.d.ts.map +1 -0
  137. package/dist/phase6/role-gates.js +536 -0
  138. package/dist/phase6/role-gates.js.map +1 -0
  139. package/dist/phase6/types.d.ts +1827 -0
  140. package/dist/phase6/types.d.ts.map +1 -0
  141. package/dist/phase6/types.js +450 -0
  142. package/dist/phase6/types.js.map +1 -0
  143. package/dist/phase6/weight-presets/canonical.d.ts +93 -0
  144. package/dist/phase6/weight-presets/canonical.d.ts.map +1 -0
  145. package/dist/phase6/weight-presets/canonical.js +122 -0
  146. package/dist/phase6/weight-presets/canonical.js.map +1 -0
  147. package/dist/phase6/weight-presets/deltas.d.ts +144 -0
  148. package/dist/phase6/weight-presets/deltas.d.ts.map +1 -0
  149. package/dist/phase6/weight-presets/deltas.js +184 -0
  150. package/dist/phase6/weight-presets/deltas.js.map +1 -0
  151. package/dist/phase6/weight-presets/index.d.ts +8 -0
  152. package/dist/phase6/weight-presets/index.d.ts.map +1 -0
  153. package/dist/phase6/weight-presets/index.js +8 -0
  154. package/dist/phase6/weight-presets/index.js.map +1 -0
  155. package/dist/phase6/weight-presets/merger.d.ts +79 -0
  156. package/dist/phase6/weight-presets/merger.d.ts.map +1 -0
  157. package/dist/phase6/weight-presets/merger.js +161 -0
  158. package/dist/phase6/weight-presets/merger.js.map +1 -0
  159. package/dist/proof/index.d.ts +50 -1
  160. package/dist/proof/index.d.ts.map +1 -1
  161. package/dist/proof/index.js +122 -3
  162. package/dist/proof/index.js.map +1 -1
  163. package/dist/proof/merkle.d.ts +195 -0
  164. package/dist/proof/merkle.d.ts.map +1 -0
  165. package/dist/proof/merkle.js +412 -0
  166. package/dist/proof/merkle.js.map +1 -0
  167. package/dist/proof/zk-proofs.d.ts +218 -0
  168. package/dist/proof/zk-proofs.d.ts.map +1 -0
  169. package/dist/proof/zk-proofs.js +531 -0
  170. package/dist/proof/zk-proofs.js.map +1 -0
  171. package/dist/trust-engine/ceiling-enforcement/audit.d.ts +98 -0
  172. package/dist/trust-engine/ceiling-enforcement/audit.d.ts.map +1 -0
  173. package/dist/trust-engine/ceiling-enforcement/audit.js +160 -0
  174. package/dist/trust-engine/ceiling-enforcement/audit.js.map +1 -0
  175. package/dist/trust-engine/ceiling-enforcement/index.d.ts +6 -0
  176. package/dist/trust-engine/ceiling-enforcement/index.d.ts.map +1 -0
  177. package/dist/trust-engine/ceiling-enforcement/index.js +6 -0
  178. package/dist/trust-engine/ceiling-enforcement/index.js.map +1 -0
  179. package/dist/trust-engine/ceiling-enforcement/kernel.d.ts +112 -0
  180. package/dist/trust-engine/ceiling-enforcement/kernel.d.ts.map +1 -0
  181. package/dist/trust-engine/ceiling-enforcement/kernel.js +158 -0
  182. package/dist/trust-engine/ceiling-enforcement/kernel.js.map +1 -0
  183. package/dist/trust-engine/context-policy/enforcement.d.ts +62 -0
  184. package/dist/trust-engine/context-policy/enforcement.d.ts.map +1 -0
  185. package/dist/trust-engine/context-policy/enforcement.js +104 -0
  186. package/dist/trust-engine/context-policy/enforcement.js.map +1 -0
  187. package/dist/trust-engine/context-policy/factory.d.ts +75 -0
  188. package/dist/trust-engine/context-policy/factory.d.ts.map +1 -0
  189. package/dist/trust-engine/context-policy/factory.js +130 -0
  190. package/dist/trust-engine/context-policy/factory.js.map +1 -0
  191. package/dist/trust-engine/context-policy/index.d.ts +6 -0
  192. package/dist/trust-engine/context-policy/index.d.ts.map +1 -0
  193. package/dist/trust-engine/context-policy/index.js +6 -0
  194. package/dist/trust-engine/context-policy/index.js.map +1 -0
  195. package/dist/trust-engine/creation-modifiers/index.d.ts +5 -0
  196. package/dist/trust-engine/creation-modifiers/index.d.ts.map +1 -0
  197. package/dist/trust-engine/creation-modifiers/index.js +5 -0
  198. package/dist/trust-engine/creation-modifiers/index.js.map +1 -0
  199. package/dist/trust-engine/creation-modifiers/types.d.ts +112 -0
  200. package/dist/trust-engine/creation-modifiers/types.d.ts.map +1 -0
  201. package/dist/trust-engine/creation-modifiers/types.js +166 -0
  202. package/dist/trust-engine/creation-modifiers/types.js.map +1 -0
  203. package/dist/trust-engine/decay-profiles.d.ts +159 -0
  204. package/dist/trust-engine/decay-profiles.d.ts.map +1 -0
  205. package/dist/trust-engine/decay-profiles.js +210 -0
  206. package/dist/trust-engine/decay-profiles.js.map +1 -0
  207. package/dist/trust-engine/index.d.ts +144 -5
  208. package/dist/trust-engine/index.d.ts.map +1 -1
  209. package/dist/trust-engine/index.js +320 -15
  210. package/dist/trust-engine/index.js.map +1 -1
  211. package/dist/trust-engine/phase6-types.d.ts +123 -0
  212. package/dist/trust-engine/phase6-types.d.ts.map +1 -0
  213. package/dist/trust-engine/phase6-types.js +88 -0
  214. package/dist/trust-engine/phase6-types.js.map +1 -0
  215. package/package.json +26 -10
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Phase 6 Q1: Ceiling Enforcement - Audit Layer
3
+ *
4
+ * Core responsibility: Log and track all ceiling enforcement decisions
5
+ * - Dual logging: raw_score + clamped_score for every event
6
+ * - Audit trail: timestamp, reason, context
7
+ * - Analytics: ceiling hit frequency, patterns, drift detection
8
+ */
9
+ import { ContextType, } from './kernel';
10
+ /**
11
+ * In-memory audit log (would be backed by persistent storage in production)
12
+ */
13
+ export class CeilingAuditLog {
14
+ entries = [];
15
+ maxEntries = 10000; // Prevent unbounded growth in memory
16
+ /**
17
+ * Record a ceiling enforcement operation
18
+ */
19
+ addEntry(eventId, agentId, result, reason = 'automatic', tags = []) {
20
+ const entry = {
21
+ eventId,
22
+ agentId,
23
+ timestamp: new Date(),
24
+ rawScore: result.rawScore,
25
+ clampedScore: result.clampedScore,
26
+ ceiling: result.ceiling,
27
+ contextType: result.contextType,
28
+ ceilingHit: result.ceilingApplied,
29
+ reason,
30
+ tags,
31
+ };
32
+ this.entries.push(entry);
33
+ // Rotate oldest entries if we exceed max
34
+ if (this.entries.length > this.maxEntries) {
35
+ this.entries = this.entries.slice(-this.maxEntries);
36
+ }
37
+ return entry;
38
+ }
39
+ /**
40
+ * Get all audit entries
41
+ */
42
+ getEntries() {
43
+ return [...this.entries];
44
+ }
45
+ /**
46
+ * Get audit entries for a specific agent
47
+ */
48
+ getEntriesForAgent(agentId) {
49
+ return this.entries.filter((e) => e.agentId === agentId);
50
+ }
51
+ /**
52
+ * Get recent entries (last N)
53
+ */
54
+ getRecentEntries(count) {
55
+ return this.entries.slice(-count);
56
+ }
57
+ /**
58
+ * Clear audit log (for testing or reset)
59
+ */
60
+ clear() {
61
+ this.entries = [];
62
+ }
63
+ /**
64
+ * Compute statistics from audit log
65
+ */
66
+ computeStatistics() {
67
+ if (this.entries.length === 0) {
68
+ return {
69
+ totalEvents: 0,
70
+ ceilingHits: 0,
71
+ ceilingHitRate: 0,
72
+ avgRawScore: 0,
73
+ avgClampedScore: 0,
74
+ maxRawScore: 0,
75
+ maxClampingDelta: 0,
76
+ byContext: {
77
+ [ContextType.LOCAL]: { hits: 0, rate: 0 },
78
+ [ContextType.ENTERPRISE]: { hits: 0, rate: 0 },
79
+ [ContextType.SOVEREIGN]: { hits: 0, rate: 0 },
80
+ },
81
+ };
82
+ }
83
+ let totalRawScore = 0;
84
+ let totalClampedScore = 0;
85
+ let ceilingHits = 0;
86
+ let maxRawScore = -Infinity;
87
+ let maxClampingDelta = 0;
88
+ const byContext = {
89
+ [ContextType.LOCAL]: { hits: 0, total: 0 },
90
+ [ContextType.ENTERPRISE]: { hits: 0, total: 0 },
91
+ [ContextType.SOVEREIGN]: { hits: 0, total: 0 },
92
+ };
93
+ for (const entry of this.entries) {
94
+ totalRawScore += entry.rawScore;
95
+ totalClampedScore += entry.clampedScore;
96
+ maxRawScore = Math.max(maxRawScore, entry.rawScore);
97
+ maxClampingDelta = Math.max(maxClampingDelta, entry.rawScore - entry.clampedScore);
98
+ if (entry.ceilingHit) {
99
+ ceilingHits++;
100
+ }
101
+ byContext[entry.contextType].total++;
102
+ if (entry.ceilingHit) {
103
+ byContext[entry.contextType].hits++;
104
+ }
105
+ }
106
+ return {
107
+ totalEvents: this.entries.length,
108
+ ceilingHits,
109
+ ceilingHitRate: ceilingHits / this.entries.length,
110
+ avgRawScore: totalRawScore / this.entries.length,
111
+ avgClampedScore: totalClampedScore / this.entries.length,
112
+ maxRawScore,
113
+ maxClampingDelta,
114
+ byContext: {
115
+ [ContextType.LOCAL]: {
116
+ hits: byContext[ContextType.LOCAL].hits,
117
+ rate: byContext[ContextType.LOCAL].total === 0
118
+ ? 0
119
+ : byContext[ContextType.LOCAL].hits /
120
+ byContext[ContextType.LOCAL].total,
121
+ },
122
+ [ContextType.ENTERPRISE]: {
123
+ hits: byContext[ContextType.ENTERPRISE].hits,
124
+ rate: byContext[ContextType.ENTERPRISE].total === 0
125
+ ? 0
126
+ : byContext[ContextType.ENTERPRISE].hits /
127
+ byContext[ContextType.ENTERPRISE].total,
128
+ },
129
+ [ContextType.SOVEREIGN]: {
130
+ hits: byContext[ContextType.SOVEREIGN].hits,
131
+ rate: byContext[ContextType.SOVEREIGN].total === 0
132
+ ? 0
133
+ : byContext[ContextType.SOVEREIGN].hits /
134
+ byContext[ContextType.SOVEREIGN].total,
135
+ },
136
+ },
137
+ };
138
+ }
139
+ /**
140
+ * Check for anomalies (ceiling hits for normally-trusted agents)
141
+ */
142
+ detectCeilingAnomalies(agentId, anomalyThreshold = 0.05) {
143
+ const agentEntries = this.getEntriesForAgent(agentId);
144
+ if (agentEntries.length === 0) {
145
+ return [];
146
+ }
147
+ const hitRate = agentEntries.filter((e) => e.ceilingHit).length /
148
+ agentEntries.length;
149
+ // If hit rate is above threshold (normally 5%), flag as anomaly
150
+ if (hitRate > anomalyThreshold) {
151
+ return agentEntries.filter((e) => e.ceilingHit);
152
+ }
153
+ return [];
154
+ }
155
+ }
156
+ /**
157
+ * Global audit log instance
158
+ */
159
+ export const globalCeilingAuditLog = new CeilingAuditLog();
160
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,EAEL,WAAW,GAEZ,MAAM,UAAU,CAAC;AAkDlB;;GAEG;AACH,MAAM,OAAO,eAAe;IAClB,OAAO,GAAwB,EAAE,CAAC;IAClC,UAAU,GAAW,KAAK,CAAC,CAAC,qCAAqC;IAEzE;;OAEG;IACH,QAAQ,CACN,OAAe,EACf,OAAe,EACf,MAAgC,EAChC,SAAiB,WAAW,EAC5B,OAAiB,EAAE;QAEnB,MAAM,KAAK,GAAsB;YAC/B,OAAO;YACP,OAAO;YACP,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,UAAU,EAAE,MAAM,CAAC,cAAc;YACjC,MAAM;YACN,IAAI;SACL,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEzB,yCAAyC;QACzC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KA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B,CACpB,OAAe,EACf,mBAA2B,IAAI;QAE/B,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,OAAO,GACX,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM;YAC/C,YAAY,CAAC,MAAM,CAAC;QAEtB,gEAAgE;QAChE,IAAI,OAAO,GAAG,gBAAgB,EAAE,CAAC;YAC/B,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,eAAe,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Ceiling Enforcement Module (Q1) - Public API
3
+ */
4
+ export * from './kernel.js';
5
+ export * from './audit.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Ceiling Enforcement Module (Q1) - Public API
3
+ */
4
+ export * from './kernel.js';
5
+ export * from './audit.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Phase 6 Q1: Ceiling Enforcement - Kernel Layer
3
+ *
4
+ * Core responsibility: Apply ceiling enforcement at kernel level (0-1000 scale)
5
+ * - Receives raw trust scores (any numeric value)
6
+ * - Clamps to 0-1000 based on context ceiling
7
+ * - Preserves raw score for audit trail (ceilingApplied flag)
8
+ * - <1ms latency target
9
+ */
10
+ import { TrustEvent } from '../phase6-types.js';
11
+ /**
12
+ * Context-based ceiling levels (from CONTEXT_CEILINGS)
13
+ */
14
+ export declare enum ContextType {
15
+ LOCAL = "local",// 0-700: Restricted to test environments
16
+ ENTERPRISE = "enterprise",// 0-900: Approved for business operations
17
+ SOVEREIGN = "sovereign"
18
+ }
19
+ /**
20
+ * Result of ceiling enforcement operation
21
+ */
22
+ export interface CeilingEnforcementResult {
23
+ /** Original raw score (unclamped) */
24
+ rawScore: number;
25
+ /** Clamped score (post-ceiling) */
26
+ clampedScore: number;
27
+ /** Ceiling that was applied */
28
+ ceiling: number;
29
+ /** Whether clamping occurred (rawScore !== clampedScore) */
30
+ ceilingApplied: boolean;
31
+ /** Context type that determined the ceiling */
32
+ contextType: ContextType;
33
+ }
34
+ /**
35
+ * Get ceiling value for a context type
36
+ *
37
+ * @param contextType - The context (local/enterprise/sovereign)
38
+ * @returns The ceiling value (700/900/1000)
39
+ */
40
+ export declare function getCeilingForContext(contextType: ContextType): number;
41
+ /**
42
+ * Clamp a raw score to the ceiling for a given context
43
+ *
44
+ * This is the core Q1 enforcement: kernel-level ceiling with dual logging
45
+ * - Raw score always preserved (for analytics)
46
+ * - Clamped score enforced at runtime (for authorization decisions)
47
+ * - Flag indicates whether ceiling was applied
48
+ *
49
+ * @param rawScore - The unprocessed trust score (may be >1000 or <0)
50
+ * @param contextType - The context determining the ceiling
51
+ * @returns CeilingEnforcementResult with raw/clamped scores and flags
52
+ *
53
+ * @example
54
+ * const result = clampTrustScore(1050, ContextType.ENTERPRISE);
55
+ * // { rawScore: 1050, clampedScore: 900, ceiling: 900, ceilingApplied: true, contextType: 'enterprise' }
56
+ */
57
+ export declare function clampTrustScore(rawScore: number, contextType: ContextType): CeilingEnforcementResult;
58
+ /**
59
+ * Apply ceiling enforcement to a TrustEvent
60
+ *
61
+ * This wraps clampTrustScore and populates the event's score and ceilingApplied fields
62
+ *
63
+ * @param event - The trust event to enforce ceiling on
64
+ * @param contextType - The context determining the ceiling
65
+ * @returns The modified TrustEvent with score clamped and ceilingApplied set
66
+ */
67
+ export declare function applyCeilingEnforcement(event: TrustEvent, contextType: ContextType): TrustEvent;
68
+ /**
69
+ * Validate that a score complies with its context ceiling
70
+ *
71
+ * This is used for assertions/validation - checking that a score
72
+ * was properly clamped before being used in authorization decisions
73
+ *
74
+ * @param score - The score to validate
75
+ * @param contextType - The context that should be limiting the score
76
+ * @returns true if score ≤ ceiling for this context
77
+ */
78
+ export declare function validateScoreForContext(score: number, contextType: ContextType): boolean;
79
+ /**
80
+ * Get the effective autonomy tier based on clamped score
81
+ *
82
+ * Maps the clamped score (after ceiling enforcement) to a tier level.
83
+ * This is used downstream (in role-gates, context-policy) to determine
84
+ * what operations are allowed.
85
+ *
86
+ * Tier mapping:
87
+ * - T0: 0-100 (Sandbox)
88
+ * - T1: 100-300 (Monitored)
89
+ * - T2: 300-500 (Supervised)
90
+ * - T3: 500-700 (Autonomous)
91
+ * - T4: 700-900 (Sovereign)
92
+ * - T5: 900-1000 (Verified)
93
+ *
94
+ * @param clampedScore - Score after ceiling enforcement
95
+ * @returns Tier number 0-5
96
+ */
97
+ export declare function getTierFromScore(clampedScore: number): number;
98
+ /**
99
+ * Compute the effective authorization tier
100
+ *
101
+ * This combines:
102
+ * 1. The clamped trust score (from ceiling enforcement)
103
+ * 2. The context ceiling
104
+ *
105
+ * Result is the minimum tier that respects both constraints.
106
+ *
107
+ * @param clampedScore - Score after ceiling enforcement
108
+ * @param contextType - Context that limited the score
109
+ * @returns Effective tier 0-5
110
+ */
111
+ export declare function getEffectiveAuthorizationTier(clampedScore: number, contextType: ContextType): number;
112
+ //# sourceMappingURL=kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAkC,MAAM,oBAAoB,CAAC;AAEhF;;GAEG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU,CAAS,yCAAyC;IACjE,UAAU,eAAe,CAAE,0CAA0C;IACrE,SAAS,cAAc;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,cAAc,EAAE,OAAO,CAAC;IACxB,+CAA+C;IAC/C,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAWrE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,GACvB,wBAAwB,CAqB1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,WAAW,GACvB,UAAU,CAQZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,WAAW,GACvB,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAW7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,WAAW,GACvB,MAAM,CASR"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Phase 6 Q1: Ceiling Enforcement - Kernel Layer
3
+ *
4
+ * Core responsibility: Apply ceiling enforcement at kernel level (0-1000 scale)
5
+ * - Receives raw trust scores (any numeric value)
6
+ * - Clamps to 0-1000 based on context ceiling
7
+ * - Preserves raw score for audit trail (ceilingApplied flag)
8
+ * - <1ms latency target
9
+ */
10
+ import { CONTEXT_CEILINGS } from '../phase6-types.js';
11
+ /**
12
+ * Context-based ceiling levels (from CONTEXT_CEILINGS)
13
+ */
14
+ export var ContextType;
15
+ (function (ContextType) {
16
+ ContextType["LOCAL"] = "local";
17
+ ContextType["ENTERPRISE"] = "enterprise";
18
+ ContextType["SOVEREIGN"] = "sovereign";
19
+ })(ContextType || (ContextType = {}));
20
+ /**
21
+ * Get ceiling value for a context type
22
+ *
23
+ * @param contextType - The context (local/enterprise/sovereign)
24
+ * @returns The ceiling value (700/900/1000)
25
+ */
26
+ export function getCeilingForContext(contextType) {
27
+ switch (contextType) {
28
+ case ContextType.LOCAL:
29
+ return CONTEXT_CEILINGS.local;
30
+ case ContextType.ENTERPRISE:
31
+ return CONTEXT_CEILINGS.enterprise;
32
+ case ContextType.SOVEREIGN:
33
+ return CONTEXT_CEILINGS.sovereign;
34
+ default:
35
+ throw new Error(`Unknown context type: ${contextType}`);
36
+ }
37
+ }
38
+ /**
39
+ * Clamp a raw score to the ceiling for a given context
40
+ *
41
+ * This is the core Q1 enforcement: kernel-level ceiling with dual logging
42
+ * - Raw score always preserved (for analytics)
43
+ * - Clamped score enforced at runtime (for authorization decisions)
44
+ * - Flag indicates whether ceiling was applied
45
+ *
46
+ * @param rawScore - The unprocessed trust score (may be >1000 or <0)
47
+ * @param contextType - The context determining the ceiling
48
+ * @returns CeilingEnforcementResult with raw/clamped scores and flags
49
+ *
50
+ * @example
51
+ * const result = clampTrustScore(1050, ContextType.ENTERPRISE);
52
+ * // { rawScore: 1050, clampedScore: 900, ceiling: 900, ceilingApplied: true, contextType: 'enterprise' }
53
+ */
54
+ export function clampTrustScore(rawScore, contextType) {
55
+ // Validate inputs
56
+ if (!Number.isFinite(rawScore)) {
57
+ throw new Error(`Invalid raw score: ${rawScore}`);
58
+ }
59
+ if (!Object.values(ContextType).includes(contextType)) {
60
+ throw new Error(`Invalid context type: ${contextType}`);
61
+ }
62
+ const ceiling = getCeilingForContext(contextType);
63
+ // Clamp to [0, ceiling]
64
+ const clampedScore = Math.max(0, Math.min(rawScore, ceiling));
65
+ return {
66
+ rawScore,
67
+ clampedScore,
68
+ ceiling,
69
+ ceilingApplied: rawScore !== clampedScore,
70
+ contextType,
71
+ };
72
+ }
73
+ /**
74
+ * Apply ceiling enforcement to a TrustEvent
75
+ *
76
+ * This wraps clampTrustScore and populates the event's score and ceilingApplied fields
77
+ *
78
+ * @param event - The trust event to enforce ceiling on
79
+ * @param contextType - The context determining the ceiling
80
+ * @returns The modified TrustEvent with score clamped and ceilingApplied set
81
+ */
82
+ export function applyCeilingEnforcement(event, contextType) {
83
+ const result = clampTrustScore(event.rawScore, contextType);
84
+ return {
85
+ ...event,
86
+ score: result.clampedScore,
87
+ ceilingApplied: result.ceilingApplied,
88
+ };
89
+ }
90
+ /**
91
+ * Validate that a score complies with its context ceiling
92
+ *
93
+ * This is used for assertions/validation - checking that a score
94
+ * was properly clamped before being used in authorization decisions
95
+ *
96
+ * @param score - The score to validate
97
+ * @param contextType - The context that should be limiting the score
98
+ * @returns true if score ≤ ceiling for this context
99
+ */
100
+ export function validateScoreForContext(score, contextType) {
101
+ const ceiling = getCeilingForContext(contextType);
102
+ return score >= 0 && score <= ceiling;
103
+ }
104
+ /**
105
+ * Get the effective autonomy tier based on clamped score
106
+ *
107
+ * Maps the clamped score (after ceiling enforcement) to a tier level.
108
+ * This is used downstream (in role-gates, context-policy) to determine
109
+ * what operations are allowed.
110
+ *
111
+ * Tier mapping:
112
+ * - T0: 0-100 (Sandbox)
113
+ * - T1: 100-300 (Monitored)
114
+ * - T2: 300-500 (Supervised)
115
+ * - T3: 500-700 (Autonomous)
116
+ * - T4: 700-900 (Sovereign)
117
+ * - T5: 900-1000 (Verified)
118
+ *
119
+ * @param clampedScore - Score after ceiling enforcement
120
+ * @returns Tier number 0-5
121
+ */
122
+ export function getTierFromScore(clampedScore) {
123
+ if (clampedScore < 0 || clampedScore > 1000) {
124
+ throw new Error(`Score out of range: ${clampedScore}`);
125
+ }
126
+ if (clampedScore < 100)
127
+ return 0;
128
+ if (clampedScore < 300)
129
+ return 1;
130
+ if (clampedScore < 500)
131
+ return 2;
132
+ if (clampedScore < 700)
133
+ return 3;
134
+ if (clampedScore < 900)
135
+ return 4;
136
+ return 5;
137
+ }
138
+ /**
139
+ * Compute the effective authorization tier
140
+ *
141
+ * This combines:
142
+ * 1. The clamped trust score (from ceiling enforcement)
143
+ * 2. The context ceiling
144
+ *
145
+ * Result is the minimum tier that respects both constraints.
146
+ *
147
+ * @param clampedScore - Score after ceiling enforcement
148
+ * @param contextType - Context that limited the score
149
+ * @returns Effective tier 0-5
150
+ */
151
+ export function getEffectiveAuthorizationTier(clampedScore, contextType) {
152
+ // Validate that score respects the context ceiling
153
+ if (!validateScoreForContext(clampedScore, contextType)) {
154
+ throw new Error(`Score ${clampedScore} violates ceiling for context ${contextType}`);
155
+ }
156
+ return getTierFromScore(clampedScore);
157
+ }
158
+ //# sourceMappingURL=kernel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.js","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAA4B,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEhF;;GAEG;AACH,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,wCAAyB,CAAA;IACzB,sCAAuB,CAAA;AACzB,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AAkBD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,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,KAAK;QACR,KAAK,EAAE,MAAM,CAAC,YAAY;QAC1B,cAAc,EAAE,MAAM,CAAC,cAAc;KACtC,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CACrC,KAAa,EACb,WAAwB;IAExB,MAAM,OAAO,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAClD,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAoB;IACnD,IAAI,YAAY,GAAG,CAAC,IAAI,YAAY,GAAG,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,uBAAuB,YAAY,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,YAAY,GAAG,GAAG;QAAE,OAAO,CAAC,CAAC;IACjC,IAAI,YAAY,GAAG,GAAG;QAAE,OAAO,CAAC,CAAC;IACjC,IAAI,YAAY,GAAG,GAAG;QAAE,OAAO,CAAC,CAAC;IACjC,IAAI,YAAY,GAAG,GAAG;QAAE,OAAO,CAAC,CAAC;IACjC,IAAI,YAAY,GAAG,GAAG;QAAE,OAAO,CAAC,CAAC;IACjC,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,6BAA6B,CAC3C,YAAoB,EACpB,WAAwB;IAExB,mDAAmD;IACnD,IAAI,CAAC,uBAAuB,CAAC,YAAY,EAAE,WAAW,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CACb,SAAS,YAAY,iCAAiC,WAAW,EAAE,CACpE,CAAC;IACJ,CAAC;IAED,OAAO,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Phase 6 Q2: Context Policy - Enforcement Layer
3
+ *
4
+ * Core responsibility: Enforce immutable agent context at instantiation
5
+ * - Context set at construction, never changes
6
+ * - Unforgeable governance audit trail
7
+ * - Clean multi-tenant isolation
8
+ * - <0.5ms validation latency
9
+ */
10
+ /**
11
+ * Valid context types for agents
12
+ */
13
+ export declare enum ContextType {
14
+ LOCAL = "local",// 0-700: Test/sandbox only
15
+ ENTERPRISE = "enterprise",// 0-900: Internal operations
16
+ SOVEREIGN = "sovereign"
17
+ }
18
+ /**
19
+ * Agent context with immutability guarantees
20
+ */
21
+ export interface AgentContext {
22
+ readonly contextType: ContextType;
23
+ readonly agentId: string;
24
+ readonly tenantId: string;
25
+ readonly createdAt: Date;
26
+ readonly createdBy: string;
27
+ readonly contextHash: string;
28
+ }
29
+ /**
30
+ * Validate that a context type is valid
31
+ */
32
+ export declare function validateContextType(value: unknown): value is ContextType;
33
+ /**
34
+ * Create a cryptographic hash of context properties for immutability proof
35
+ * This prevents tampering with context post-creation
36
+ */
37
+ export declare function computeContextHash(contextType: ContextType, agentId: string, tenantId: string, createdAt: Date, createdBy: string): string;
38
+ /**
39
+ * Create an immutable agent context at instantiation time
40
+ * This is the only place context can be set - thereafter readonly
41
+ */
42
+ export declare function createAgentContext(contextType: ContextType, agentId: string, tenantId: string, createdBy: string): AgentContext;
43
+ /**
44
+ * Verify that context hasn't been tampered with
45
+ * by checking the cryptographic hash
46
+ */
47
+ export declare function verifyContextIntegrity(context: AgentContext): boolean;
48
+ /**
49
+ * Get the ceiling for a context (0-1000 scale)
50
+ */
51
+ export declare function getContextCeiling(contextType: ContextType): number;
52
+ /**
53
+ * Validate that an agent's context is appropriate for a given operation
54
+ * This is called by upstream decision layers (ceiling enforcement, role gates)
55
+ */
56
+ export declare function validateContextForOperation(context: AgentContext, requiredContext: ContextType): boolean;
57
+ /**
58
+ * Multi-tenant isolation check
59
+ * Ensures agents from one tenant can't access another tenant's context
60
+ */
61
+ export declare function validateTenantIsolation(context: AgentContext, targetTenantId: string): boolean;
62
+ //# sourceMappingURL=enforcement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enforcement.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/context-policy/enforcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU,CAAc,2BAA2B;IACxD,UAAU,eAAe,CAAI,6BAA6B;IAC1D,SAAS,cAAc;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAExE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,IAAI,EACf,SAAS,EAAE,MAAM,GAChB,MAAM,CAUR;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,YAAY,CAuBd;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CASrE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CASlE;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,YAAY,EACrB,eAAe,EAAE,WAAW,GAC3B,OAAO,CAaT;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,YAAY,EACrB,cAAc,EAAE,MAAM,GACrB,OAAO,CAET"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Phase 6 Q2: Context Policy - Enforcement Layer
3
+ *
4
+ * Core responsibility: Enforce immutable agent context at instantiation
5
+ * - Context set at construction, never changes
6
+ * - Unforgeable governance audit trail
7
+ * - Clean multi-tenant isolation
8
+ * - <0.5ms validation latency
9
+ */
10
+ /**
11
+ * Valid context types for agents
12
+ */
13
+ export var ContextType;
14
+ (function (ContextType) {
15
+ ContextType["LOCAL"] = "local";
16
+ ContextType["ENTERPRISE"] = "enterprise";
17
+ ContextType["SOVEREIGN"] = "sovereign";
18
+ })(ContextType || (ContextType = {}));
19
+ /**
20
+ * Validate that a context type is valid
21
+ */
22
+ export function validateContextType(value) {
23
+ return Object.values(ContextType).includes(value);
24
+ }
25
+ /**
26
+ * Create a cryptographic hash of context properties for immutability proof
27
+ * This prevents tampering with context post-creation
28
+ */
29
+ export function computeContextHash(contextType, agentId, tenantId, createdAt, createdBy) {
30
+ const data = `${contextType}|${agentId}|${tenantId}|${createdAt.toISOString()}|${createdBy}`;
31
+ // Simple hash for demo (production would use crypto.createHash)
32
+ let hash = 0;
33
+ for (let i = 0; i < data.length; i++) {
34
+ const char = data.charCodeAt(i);
35
+ hash = (hash << 5) - hash + char;
36
+ hash = hash & hash; // Convert to 32-bit integer
37
+ }
38
+ return Math.abs(hash).toString(16);
39
+ }
40
+ /**
41
+ * Create an immutable agent context at instantiation time
42
+ * This is the only place context can be set - thereafter readonly
43
+ */
44
+ export function createAgentContext(contextType, agentId, tenantId, createdBy) {
45
+ // Validate context type
46
+ if (!validateContextType(contextType)) {
47
+ throw new Error(`Invalid context type: ${contextType}`);
48
+ }
49
+ const createdAt = new Date();
50
+ const contextHash = computeContextHash(contextType, agentId, tenantId, createdAt, createdBy);
51
+ return Object.freeze({
52
+ contextType,
53
+ agentId,
54
+ tenantId,
55
+ createdAt,
56
+ createdBy,
57
+ contextHash,
58
+ });
59
+ }
60
+ /**
61
+ * Verify that context hasn't been tampered with
62
+ * by checking the cryptographic hash
63
+ */
64
+ export function verifyContextIntegrity(context) {
65
+ const expectedHash = computeContextHash(context.contextType, context.agentId, context.tenantId, context.createdAt, context.createdBy);
66
+ return context.contextHash === expectedHash;
67
+ }
68
+ /**
69
+ * Get the ceiling for a context (0-1000 scale)
70
+ */
71
+ export function getContextCeiling(contextType) {
72
+ switch (contextType) {
73
+ case ContextType.LOCAL:
74
+ return 700;
75
+ case ContextType.ENTERPRISE:
76
+ return 900;
77
+ case ContextType.SOVEREIGN:
78
+ return 1000;
79
+ }
80
+ }
81
+ /**
82
+ * Validate that an agent's context is appropriate for a given operation
83
+ * This is called by upstream decision layers (ceiling enforcement, role gates)
84
+ */
85
+ export function validateContextForOperation(context, requiredContext) {
86
+ // Can't operate in a context more privileged than the agent's context
87
+ const contextHierarchy = [
88
+ ContextType.LOCAL,
89
+ ContextType.ENTERPRISE,
90
+ ContextType.SOVEREIGN,
91
+ ];
92
+ const agentContextRank = contextHierarchy.indexOf(context.contextType);
93
+ const requiredRank = contextHierarchy.indexOf(requiredContext);
94
+ // Agent can operate in required context if agent's context >= required
95
+ return agentContextRank >= requiredRank;
96
+ }
97
+ /**
98
+ * Multi-tenant isolation check
99
+ * Ensures agents from one tenant can't access another tenant's context
100
+ */
101
+ export function validateTenantIsolation(context, targetTenantId) {
102
+ return context.tenantId === targetTenantId;
103
+ }
104
+ //# sourceMappingURL=enforcement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enforcement.js","sourceRoot":"","sources":["../../../src/trust-engine/context-policy/enforcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,wCAAyB,CAAA;IACzB,sCAAuB,CAAA;AACzB,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AAcD;;GAEG;AACH,MAAM,UAAU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