@matimo/core 0.1.0-alpha.9 → 0.1.2

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 (187) hide show
  1. package/README.md +341 -14
  2. package/dist/approval/approval-handler.d.ts +5 -1
  3. package/dist/approval/approval-handler.d.ts.map +1 -1
  4. package/dist/approval/approval-handler.js +7 -1
  5. package/dist/approval/approval-handler.js.map +1 -1
  6. package/dist/auth/oauth2-handler.d.ts +2 -2
  7. package/dist/auth/oauth2-handler.d.ts.map +1 -1
  8. package/dist/auth/oauth2-handler.js +2 -2
  9. package/dist/auth/oauth2-handler.js.map +1 -1
  10. package/dist/auth/oauth2-provider-loader.d.ts +2 -2
  11. package/dist/auth/oauth2-provider-loader.d.ts.map +1 -1
  12. package/dist/auth/oauth2-provider-loader.js +2 -2
  13. package/dist/auth/oauth2-provider-loader.js.map +1 -1
  14. package/dist/core/schema.d.ts +42 -11
  15. package/dist/core/schema.d.ts.map +1 -1
  16. package/dist/core/schema.js +42 -6
  17. package/dist/core/schema.js.map +1 -1
  18. package/dist/core/skill-content-parser.d.ts +91 -0
  19. package/dist/core/skill-content-parser.d.ts.map +1 -0
  20. package/dist/core/skill-content-parser.js +248 -0
  21. package/dist/core/skill-content-parser.js.map +1 -0
  22. package/dist/core/skill-loader.d.ts +46 -0
  23. package/dist/core/skill-loader.d.ts.map +1 -0
  24. package/dist/core/skill-loader.js +311 -0
  25. package/dist/core/skill-loader.js.map +1 -0
  26. package/dist/core/skill-registry.d.ts +131 -0
  27. package/dist/core/skill-registry.d.ts.map +1 -0
  28. package/dist/core/skill-registry.js +316 -0
  29. package/dist/core/skill-registry.js.map +1 -0
  30. package/dist/core/tfidf-embedding.d.ts +45 -0
  31. package/dist/core/tfidf-embedding.d.ts.map +1 -0
  32. package/dist/core/tfidf-embedding.js +199 -0
  33. package/dist/core/tfidf-embedding.js.map +1 -0
  34. package/dist/core/tool-loader.d.ts +4 -2
  35. package/dist/core/tool-loader.d.ts.map +1 -1
  36. package/dist/core/tool-loader.js +35 -12
  37. package/dist/core/tool-loader.js.map +1 -1
  38. package/dist/core/tool-registry.d.ts +1 -1
  39. package/dist/core/tool-registry.d.ts.map +1 -1
  40. package/dist/core/tool-registry.js +1 -1
  41. package/dist/core/tool-registry.js.map +1 -1
  42. package/dist/core/types.d.ts +204 -7
  43. package/dist/core/types.d.ts.map +1 -1
  44. package/dist/decorators/index.d.ts +1 -1
  45. package/dist/decorators/index.d.ts.map +1 -1
  46. package/dist/decorators/index.js +1 -1
  47. package/dist/decorators/index.js.map +1 -1
  48. package/dist/decorators/tool-decorator.js +1 -1
  49. package/dist/decorators/tool-decorator.js.map +1 -1
  50. package/dist/encodings/parameter-encoding.d.ts +1 -1
  51. package/dist/encodings/parameter-encoding.d.ts.map +1 -1
  52. package/dist/encodings/parameter-encoding.js +10 -5
  53. package/dist/encodings/parameter-encoding.js.map +1 -1
  54. package/dist/errors/matimo-error.d.ts +11 -2
  55. package/dist/errors/matimo-error.d.ts.map +1 -1
  56. package/dist/errors/matimo-error.js +25 -1
  57. package/dist/errors/matimo-error.js.map +1 -1
  58. package/dist/executors/command-executor.d.ts +10 -3
  59. package/dist/executors/command-executor.d.ts.map +1 -1
  60. package/dist/executors/command-executor.js +30 -6
  61. package/dist/executors/command-executor.js.map +1 -1
  62. package/dist/executors/function-executor.d.ts +11 -4
  63. package/dist/executors/function-executor.d.ts.map +1 -1
  64. package/dist/executors/function-executor.js +46 -26
  65. package/dist/executors/function-executor.js.map +1 -1
  66. package/dist/executors/http-executor.d.ts +80 -5
  67. package/dist/executors/http-executor.d.ts.map +1 -1
  68. package/dist/executors/http-executor.js +233 -29
  69. package/dist/executors/http-executor.js.map +1 -1
  70. package/dist/index.d.ts +45 -23
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +34 -16
  73. package/dist/index.js.map +1 -1
  74. package/dist/integrations/langchain.d.ts +57 -2
  75. package/dist/integrations/langchain.d.ts.map +1 -1
  76. package/dist/integrations/langchain.js +71 -4
  77. package/dist/integrations/langchain.js.map +1 -1
  78. package/dist/logging/winston-logger.d.ts.map +1 -1
  79. package/dist/logging/winston-logger.js +9 -1
  80. package/dist/logging/winston-logger.js.map +1 -1
  81. package/dist/matimo-instance.d.ts +231 -19
  82. package/dist/matimo-instance.d.ts.map +1 -1
  83. package/dist/matimo-instance.js +747 -48
  84. package/dist/matimo-instance.js.map +1 -1
  85. package/dist/mcp/index.d.ts +18 -0
  86. package/dist/mcp/index.d.ts.map +1 -0
  87. package/dist/mcp/index.js +24 -0
  88. package/dist/mcp/index.js.map +1 -0
  89. package/dist/mcp/mcp-server.d.ts +141 -0
  90. package/dist/mcp/mcp-server.d.ts.map +1 -0
  91. package/dist/mcp/mcp-server.js +754 -0
  92. package/dist/mcp/mcp-server.js.map +1 -0
  93. package/dist/mcp/secrets/aws-resolver.d.ts +41 -0
  94. package/dist/mcp/secrets/aws-resolver.d.ts.map +1 -0
  95. package/dist/mcp/secrets/aws-resolver.js +141 -0
  96. package/dist/mcp/secrets/aws-resolver.js.map +1 -0
  97. package/dist/mcp/secrets/dotenv-resolver.d.ts +23 -0
  98. package/dist/mcp/secrets/dotenv-resolver.d.ts.map +1 -0
  99. package/dist/mcp/secrets/dotenv-resolver.js +94 -0
  100. package/dist/mcp/secrets/dotenv-resolver.js.map +1 -0
  101. package/dist/mcp/secrets/env-resolver.d.ts +14 -0
  102. package/dist/mcp/secrets/env-resolver.d.ts.map +1 -0
  103. package/dist/mcp/secrets/env-resolver.js +27 -0
  104. package/dist/mcp/secrets/env-resolver.js.map +1 -0
  105. package/dist/mcp/secrets/index.d.ts +14 -0
  106. package/dist/mcp/secrets/index.d.ts.map +1 -0
  107. package/dist/mcp/secrets/index.js +13 -0
  108. package/dist/mcp/secrets/index.js.map +1 -0
  109. package/dist/mcp/secrets/resolver-chain.d.ts +34 -0
  110. package/dist/mcp/secrets/resolver-chain.d.ts.map +1 -0
  111. package/dist/mcp/secrets/resolver-chain.js +141 -0
  112. package/dist/mcp/secrets/resolver-chain.js.map +1 -0
  113. package/dist/mcp/secrets/types.d.ts +73 -0
  114. package/dist/mcp/secrets/types.d.ts.map +1 -0
  115. package/dist/mcp/secrets/types.js +8 -0
  116. package/dist/mcp/secrets/types.js.map +1 -0
  117. package/dist/mcp/secrets/vault-resolver.d.ts +43 -0
  118. package/dist/mcp/secrets/vault-resolver.d.ts.map +1 -0
  119. package/dist/mcp/secrets/vault-resolver.js +127 -0
  120. package/dist/mcp/secrets/vault-resolver.js.map +1 -0
  121. package/dist/mcp/tool-converter.d.ts +40 -0
  122. package/dist/mcp/tool-converter.d.ts.map +1 -0
  123. package/dist/mcp/tool-converter.js +185 -0
  124. package/dist/mcp/tool-converter.js.map +1 -0
  125. package/dist/policy/approval-manifest.d.ts +76 -0
  126. package/dist/policy/approval-manifest.d.ts.map +1 -0
  127. package/dist/policy/approval-manifest.js +197 -0
  128. package/dist/policy/approval-manifest.js.map +1 -0
  129. package/dist/policy/content-validator.d.ts +19 -0
  130. package/dist/policy/content-validator.d.ts.map +1 -0
  131. package/dist/policy/content-validator.js +196 -0
  132. package/dist/policy/content-validator.js.map +1 -0
  133. package/dist/policy/default-policy.d.ts +46 -0
  134. package/dist/policy/default-policy.d.ts.map +1 -0
  135. package/dist/policy/default-policy.js +241 -0
  136. package/dist/policy/default-policy.js.map +1 -0
  137. package/dist/policy/events.d.ts +71 -0
  138. package/dist/policy/events.d.ts.map +1 -0
  139. package/dist/policy/events.js +8 -0
  140. package/dist/policy/events.js.map +1 -0
  141. package/dist/policy/index.d.ts +13 -0
  142. package/dist/policy/index.d.ts.map +1 -0
  143. package/dist/policy/index.js +9 -0
  144. package/dist/policy/index.js.map +1 -0
  145. package/dist/policy/integrity-tracker.d.ts +62 -0
  146. package/dist/policy/integrity-tracker.d.ts.map +1 -0
  147. package/dist/policy/integrity-tracker.js +79 -0
  148. package/dist/policy/integrity-tracker.js.map +1 -0
  149. package/dist/policy/policy-loader.d.ts +58 -0
  150. package/dist/policy/policy-loader.d.ts.map +1 -0
  151. package/dist/policy/policy-loader.js +156 -0
  152. package/dist/policy/policy-loader.js.map +1 -0
  153. package/dist/policy/risk-classifier.d.ts +18 -0
  154. package/dist/policy/risk-classifier.d.ts.map +1 -0
  155. package/dist/policy/risk-classifier.js +47 -0
  156. package/dist/policy/risk-classifier.js.map +1 -0
  157. package/dist/policy/types.d.ts +131 -0
  158. package/dist/policy/types.d.ts.map +1 -0
  159. package/dist/policy/types.js +8 -0
  160. package/dist/policy/types.js.map +1 -0
  161. package/package.json +22 -6
  162. package/tools/matimo_approve_tool/definition.yaml +36 -0
  163. package/tools/matimo_approve_tool/matimo_approve_tool.ts +90 -0
  164. package/tools/matimo_create_skill/definition.yaml +46 -0
  165. package/tools/matimo_create_skill/matimo_create_skill.ts +75 -0
  166. package/tools/matimo_create_tool/definition.yaml +48 -0
  167. package/tools/matimo_create_tool/matimo_create_tool.ts +137 -0
  168. package/tools/matimo_get_skill/definition.yaml +60 -0
  169. package/tools/matimo_get_skill/matimo_get_skill.ts +182 -0
  170. package/tools/matimo_get_tool/definition.yaml +36 -0
  171. package/tools/matimo_get_tool/matimo_get_tool.ts +56 -0
  172. package/tools/matimo_get_tool_status/definition.yaml +42 -0
  173. package/tools/matimo_get_tool_status/matimo_get_tool_status.ts +101 -0
  174. package/tools/matimo_list_skills/definition.yaml +52 -0
  175. package/tools/matimo_list_skills/matimo_list_skills.ts +138 -0
  176. package/tools/matimo_list_user_tools/definition.yaml +32 -0
  177. package/tools/matimo_list_user_tools/matimo_list_user_tools.ts +74 -0
  178. package/tools/matimo_reload_tools/definition.yaml +35 -0
  179. package/tools/matimo_reload_tools/matimo_reload_tools.ts +29 -0
  180. package/tools/matimo_search_tools/definition.yaml +32 -0
  181. package/tools/matimo_search_tools/matimo_search_tools.ts +82 -0
  182. package/tools/matimo_validate_skill/definition.yaml +43 -0
  183. package/tools/matimo_validate_skill/matimo_validate_skill.ts +137 -0
  184. package/tools/matimo_validate_tool/definition.yaml +34 -0
  185. package/tools/matimo_validate_tool/matimo_validate_tool.ts +168 -0
  186. package/tools/shared/skill-validation.ts +335 -0
  187. package/LICENSE +0 -21
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Default Policy Engine for Matimo.
3
+ *
4
+ * Conservative defaults that protect against malicious agent-created tools.
5
+ * Frozen at boot time — agents cannot modify policy at runtime.
6
+ */
7
+ import { validateToolContent } from './content-validator.js';
8
+ import { classifyRisk } from './risk-classifier.js';
9
+ import { extractAuthPlaceholders } from '../mcp/tool-converter.js';
10
+ const DEFAULT_CONFIG = {
11
+ allowedDomains: [],
12
+ allowedCredentials: [],
13
+ allowedHttpMethods: ['GET', 'POST'],
14
+ allowCommandTools: false,
15
+ allowFunctionTools: false,
16
+ protectedNamespaces: ['matimo_'],
17
+ enableHITL: false,
18
+ quarantineRiskLevels: ['medium'],
19
+ };
20
+ export class DefaultPolicyEngine {
21
+ constructor(config) {
22
+ this.config = { ...DEFAULT_CONFIG, ...config };
23
+ }
24
+ /**
25
+ * Check whether a tool definition may be created/proposed.
26
+ * First applies the tier gate (fast early-return for TIER 3 blocked tools),
27
+ * then runs ContentValidator rules.
28
+ */
29
+ canCreate(context, toolDef) {
30
+ // Hard TIER 3 gate — blocked regardless of content validator.
31
+ // Each check uses a reason string that the policy tests assert (.toContain).
32
+ const protectedNamespaces = this.config.protectedNamespaces;
33
+ if (protectedNamespaces.some((ns) => toolDef.name.startsWith(ns))) {
34
+ return {
35
+ allowed: false,
36
+ reason: `reserved-namespace: Tool "${toolDef.name}" uses a protected namespace (${protectedNamespaces.join(', ')})`,
37
+ riskLevel: 'critical',
38
+ };
39
+ }
40
+ if (toolDef.execution.type === 'function') {
41
+ return {
42
+ allowed: false,
43
+ reason: `no-function-execution: Agent-created tools may not use execution type "function"`,
44
+ riskLevel: 'critical',
45
+ };
46
+ }
47
+ if (toolDef.execution.type === 'command') {
48
+ return {
49
+ allowed: false,
50
+ reason: `no-command-execution: Agent-created tools may not use execution type "command"`,
51
+ riskLevel: 'critical',
52
+ };
53
+ }
54
+ if (toolDef.execution.type === 'http') {
55
+ const url = toolDef.execution.url ?? '';
56
+ if (isBlockedUrl(url)) {
57
+ return {
58
+ allowed: false,
59
+ reason: `no-ssrf: URL "${url}" targets a blocked internal/metadata address`,
60
+ riskLevel: 'critical',
61
+ };
62
+ }
63
+ }
64
+ const result = validateToolContent(toolDef, {
65
+ source: 'untrusted',
66
+ policy: this.config,
67
+ });
68
+ if (!result.valid) {
69
+ const critical = result.violations.filter((v) => v.severity === 'critical' || v.severity === 'high');
70
+ if (critical.length > 0) {
71
+ return {
72
+ allowed: false,
73
+ reason: critical.map((v) => `[${v.rule}] ${v.message}`).join('; '),
74
+ riskLevel: critical[0].severity,
75
+ };
76
+ }
77
+ // No high/critical violations, but the content is still invalid.
78
+ // Treat these (e.g., medium "forced-draft-status") as policy violations:
79
+ // either deny or quarantine for HITL, rather than silently allowing.
80
+ if (result.violations.length > 0) {
81
+ const orderedSeverities = ['low', 'medium', 'high', 'critical'];
82
+ const mostSevere = result.violations
83
+ .map((v) => v.severity)
84
+ .sort((a, b) => orderedSeverities.indexOf(b) - orderedSeverities.indexOf(a))[0];
85
+ const reason = result.violations.map((v) => `[${v.rule}] ${v.message}`).join('; ');
86
+ // Gate pending_approval behind quarantineRiskLevels: only quarantine if this risk level
87
+ // is explicitly configured for HITL. High/critical violations block unless explicitly allowed.
88
+ if (this.config.enableHITL && this.config.quarantineRiskLevels.includes(mostSevere)) {
89
+ return {
90
+ allowed: 'pending_approval',
91
+ reason,
92
+ riskLevel: mostSevere,
93
+ toolName: toolDef.name,
94
+ };
95
+ }
96
+ return {
97
+ allowed: false,
98
+ reason,
99
+ riskLevel: mostSevere,
100
+ };
101
+ }
102
+ }
103
+ // In production, block anything above low risk — unless HITL is enabled
104
+ // for the tool's risk level, in which case quarantine it for human review
105
+ const risk = classifyRisk(toolDef);
106
+ if (context.environment === 'prod' && risk !== 'low') {
107
+ if (this.config.enableHITL && this.config.quarantineRiskLevels.includes(risk)) {
108
+ return {
109
+ allowed: 'pending_approval',
110
+ reason: `Tool risk level "${risk}" requires human approval in production`,
111
+ riskLevel: risk,
112
+ toolName: toolDef.name,
113
+ };
114
+ }
115
+ return {
116
+ allowed: false,
117
+ reason: `Tool risk level "${risk}" is too high for production environment`,
118
+ riskLevel: risk,
119
+ };
120
+ }
121
+ return { allowed: true };
122
+ }
123
+ /**
124
+ * Check whether the caller is allowed to execute a given tool.
125
+ */
126
+ canExecute(context, tool) {
127
+ const status = tool.status;
128
+ // Block deprecated tools
129
+ if (status === 'deprecated' || tool.deprecated === true) {
130
+ return {
131
+ allowed: false,
132
+ reason: tool.deprecation_message ?? `Tool "${tool.name}" is deprecated`,
133
+ };
134
+ }
135
+ // Draft tools in prod: deny
136
+ if (status === 'draft' && context.environment === 'prod') {
137
+ return {
138
+ allowed: false,
139
+ reason: `Draft tool "${tool.name}" is not available in production`,
140
+ riskLevel: 'medium',
141
+ };
142
+ }
143
+ // Draft tools without admin role: deny
144
+ if (status === 'draft' && !context.roles?.includes('admin')) {
145
+ return {
146
+ allowed: false,
147
+ reason: `Draft tool "${tool.name}" requires admin role`,
148
+ riskLevel: 'medium',
149
+ };
150
+ }
151
+ // In prod, tools requiring approval need admin or operator role
152
+ if (context.environment === 'prod' &&
153
+ tool.requires_approval === true &&
154
+ !context.roles?.includes('admin') &&
155
+ !context.roles?.includes('operator')) {
156
+ return {
157
+ allowed: false,
158
+ reason: `Tool "${tool.name}" requires approval and caller lacks admin/operator role in production`,
159
+ riskLevel: 'high',
160
+ };
161
+ }
162
+ return { allowed: true };
163
+ }
164
+ /**
165
+ * Filter tools to only those the caller is allowed to see and use.
166
+ */
167
+ filterForAgent(context, tools) {
168
+ return tools.filter((tool) => {
169
+ const decision = this.canExecute(context, tool);
170
+ return decision.allowed;
171
+ });
172
+ }
173
+ /** Expose the resolved config (read-only snapshot). */
174
+ getConfig() {
175
+ return { ...this.config };
176
+ }
177
+ /**
178
+ * Hot-reload policy configuration at runtime.
179
+ * Merges the new config with DEFAULT_CONFIG (preserving conservative defaults
180
+ * for any unset fields), then replaces the active config atomically.
181
+ */
182
+ updateConfig(config) {
183
+ this.config = { ...DEFAULT_CONFIG, ...config };
184
+ }
185
+ }
186
+ /**
187
+ * Pure utility: classify an agent-proposed tool into a policy tier.
188
+ *
189
+ * - `blocked`: reserved namespace, function/command execution type, SSRF URL
190
+ * - `approval-required`: any auth credential, non-GET HTTP method, any data write
191
+ * - `auto`: low-risk read-only HTTP GET with no auth
192
+ *
193
+ * This runs BEFORE content validation and is a hard gate — `blocked` tools
194
+ * are rejected immediately without running the full content-validator.
195
+ */
196
+ export function getTierForTool(tool, config) {
197
+ const protectedNamespaces = config?.protectedNamespaces ?? ['matimo_'];
198
+ // TIER 3 — ALWAYS BLOCKED
199
+ if (protectedNamespaces.some((ns) => tool.name.startsWith(ns)))
200
+ return 'blocked';
201
+ if (tool.execution.type === 'function')
202
+ return 'blocked';
203
+ if (tool.execution.type === 'command')
204
+ return 'blocked';
205
+ if (tool.execution.type === 'http') {
206
+ const url = tool.execution.url ?? '';
207
+ if (isBlockedUrl(url))
208
+ return 'blocked';
209
+ }
210
+ // TIER 2 — APPROVAL REQUIRED
211
+ if (tool.execution.type === 'http') {
212
+ const method = (tool.execution.method ?? 'GET').toUpperCase();
213
+ if (method !== 'GET')
214
+ return 'approval-required';
215
+ const authVars = extractAuthPlaceholders(tool);
216
+ if (authVars.length > 0)
217
+ return 'approval-required';
218
+ }
219
+ // TIER 1 — AUTO (low-risk read-only)
220
+ return 'auto';
221
+ }
222
+ /** Check if a URL targets a blocked/internal destination (mirrors content-validator SSRF check). */
223
+ function isBlockedUrl(url) {
224
+ if (!url)
225
+ return false;
226
+ try {
227
+ const parsed = new URL(url);
228
+ const hostname = parsed.hostname.toLowerCase();
229
+ return (hostname === 'localhost' ||
230
+ hostname === '127.0.0.1' ||
231
+ hostname === '::1' ||
232
+ hostname.startsWith('169.254.') || // link-local / AWS metadata
233
+ hostname.startsWith('10.') ||
234
+ hostname.startsWith('192.168.') ||
235
+ /^172\.(1[6-9]|2\d|3[01])\./.test(hostname));
236
+ }
237
+ catch {
238
+ return false;
239
+ }
240
+ }
241
+ //# sourceMappingURL=default-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-policy.js","sourceRoot":"","sources":["../../src/policy/default-policy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,MAAM,cAAc,GACyB;IAC3C,cAAc,EAAE,EAAE;IAClB,kBAAkB,EAAE,EAAE;IACtB,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;IACnC,iBAAiB,EAAE,KAAK;IACxB,kBAAkB,EAAE,KAAK;IACzB,mBAAmB,EAAE,CAAC,SAAS,CAAC;IAChC,UAAU,EAAE,KAAK;IACjB,oBAAoB,EAAE,CAAC,QAAQ,CAAC;CACjC,CAAC;AAEF,MAAM,OAAO,mBAAmB;IAI9B,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,OAAsB,EAAE,OAAuB;QACvD,8DAA8D;QAC9D,6EAA6E;QAC7E,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC;QAC5D,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAClE,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,6BAA6B,OAAO,CAAC,IAAI,iCAAiC,mBAAmB,CA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I,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/C,OAAO,CACL,QAAQ,KAAK,WAAW;YACxB,QAAQ,KAAK,WAAW;YACxB,QAAQ,KAAK,KAAK;YAClB,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,4BAA4B;YAC/D,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;YAC1B,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC;YAC/B,4BAA4B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAC5C,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Typed audit events for Matimo.
3
+ *
4
+ * Host applications subscribe via `onEvent` in InitOptions and route
5
+ * events to their own logging/audit system.
6
+ */
7
+ import type { RiskLevel } from './types.js';
8
+ import type { Violation } from './types.js';
9
+ export type MatimoEvent = {
10
+ type: 'tool:created';
11
+ toolName: string;
12
+ source: 'trusted' | 'untrusted';
13
+ riskLevel: RiskLevel;
14
+ timestamp: string;
15
+ } | {
16
+ type: 'tool:approved';
17
+ toolName: string;
18
+ approvedBy?: string;
19
+ hash: string;
20
+ timestamp: string;
21
+ } | {
22
+ type: 'tool:rejected';
23
+ toolName: string;
24
+ violations: Violation[];
25
+ timestamp: string;
26
+ } | {
27
+ type: 'tool:revoked';
28
+ toolName: string;
29
+ reason: string;
30
+ timestamp: string;
31
+ } | {
32
+ type: 'tool:executed';
33
+ toolName: string;
34
+ agentId?: string;
35
+ duration: number;
36
+ success: boolean;
37
+ timestamp: string;
38
+ } | {
39
+ type: 'tool:execution_denied';
40
+ toolName: string;
41
+ reason: string;
42
+ agentId?: string;
43
+ timestamp: string;
44
+ } | {
45
+ type: 'tool:quarantined';
46
+ toolName: string;
47
+ riskLevel: RiskLevel;
48
+ reason: string;
49
+ environment?: string;
50
+ timestamp: string;
51
+ } | {
52
+ type: 'tool:quarantine_approved';
53
+ toolName: string;
54
+ approvedBy?: string;
55
+ timestamp: string;
56
+ } | {
57
+ type: 'tool:quarantine_rejected';
58
+ toolName: string;
59
+ timestamp: string;
60
+ } | {
61
+ type: 'policy:reloaded';
62
+ timestamp: string;
63
+ } | {
64
+ type: 'tools:reloaded';
65
+ loaded: number;
66
+ removed: number;
67
+ rejected: string[];
68
+ timestamp: string;
69
+ };
70
+ export type MatimoEventHandler = (event: MatimoEvent) => void;
71
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/policy/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,WAAW,GACnB;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;IAChC,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,uBAAuB,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,0BAA0B,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,0BAA0B,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEN,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Typed audit events for Matimo.
3
+ *
4
+ * Host applications subscribe via `onEvent` in InitOptions and route
5
+ * events to their own logging/audit system.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/policy/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Policy Engine — barrel export.
3
+ */
4
+ export type { PolicyEngine, PolicyContext, PolicyDecision, PolicyConfig, RiskLevel, Violation, ValidationResult, ValidationContext, } from './types.js';
5
+ export { DefaultPolicyEngine } from './default-policy.js';
6
+ export { validateToolContent, isSSRFTarget } from './content-validator.js';
7
+ export { classifyRisk } from './risk-classifier.js';
8
+ export { ToolIntegrityTracker } from './integrity-tracker.js';
9
+ export type { IntegrityRecord, IntegrityAction } from './integrity-tracker.js';
10
+ export { ApprovalManifest } from './approval-manifest.js';
11
+ export type { ApprovalRecord } from './approval-manifest.js';
12
+ export type { MatimoEvent, MatimoEventHandler } from './events.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,YAAY,EACZ,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Policy Engine — barrel export.
3
+ */
4
+ export { DefaultPolicyEngine } from './default-policy.js';
5
+ export { validateToolContent, isSSRFTarget } from './content-validator.js';
6
+ export { classifyRisk } from './risk-classifier.js';
7
+ export { ToolIntegrityTracker } from './integrity-tracker.js';
8
+ export { ApprovalManifest } from './approval-manifest.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policy/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Tool Integrity Tracker.
3
+ *
4
+ * Tracks SHA-256 hashes of tool YAML content to detect modifications.
5
+ * Used during hot-reload to decide whether re-validation is needed.
6
+ */
7
+ export interface IntegrityRecord {
8
+ hash: string;
9
+ source: 'trusted' | 'untrusted';
10
+ validatedAt: Date;
11
+ }
12
+ export type IntegrityAction = {
13
+ action: 'keep';
14
+ reason: 'unchanged';
15
+ } | {
16
+ action: 'revalidate';
17
+ reason: 'content-modified';
18
+ } | {
19
+ action: 'revalidate';
20
+ reason: 'source-changed';
21
+ } | {
22
+ action: 'validate';
23
+ reason: 'new-tool';
24
+ };
25
+ export declare class ToolIntegrityTracker {
26
+ private readonly records;
27
+ /**
28
+ * Compute SHA-256 hash of content.
29
+ */
30
+ computeHash(content: string): string;
31
+ /**
32
+ * Called when a tool is loaded. Compares the content hash and source with the stored
33
+ * record and returns what action the caller should take.
34
+ * If the tool moved between trusted/untrusted paths, revalidate is required even if content unchanged.
35
+ */
36
+ onToolLoaded(toolName: string, yamlContent: string, source: 'trusted' | 'untrusted'): IntegrityAction;
37
+ /**
38
+ * Record a tool's hash after successful validation/loading.
39
+ */
40
+ record(toolName: string, yamlContent: string, source: 'trusted' | 'untrusted'): void;
41
+ /**
42
+ * Get the stored record for a tool.
43
+ */
44
+ getRecord(toolName: string): IntegrityRecord | undefined;
45
+ /**
46
+ * Get the stored hash for a tool.
47
+ */
48
+ getHash(toolName: string): string | undefined;
49
+ /**
50
+ * Remove a tool entry (e.g. when it's been removed from disk).
51
+ */
52
+ removeEntry(toolName: string): boolean;
53
+ /**
54
+ * Clear all records. Used when doing a full reset.
55
+ */
56
+ clear(): void;
57
+ /**
58
+ * Get the number of tracked tools.
59
+ */
60
+ get size(): number;
61
+ }
62
+ //# sourceMappingURL=integrity-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrity-tracker.d.ts","sourceRoot":"","sources":["../../src/policy/integrity-tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;IAChC,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GACvC;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,GACpD;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,GAClD;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAE/C,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2C;IAEnE;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAIpC;;;;OAIG;IACH,YAAY,CACV,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,GAAG,WAAW,GAC9B,eAAe;IAoBlB;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,IAAI;IAQpF;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIxD;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI7C;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAItC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Tool Integrity Tracker.
3
+ *
4
+ * Tracks SHA-256 hashes of tool YAML content to detect modifications.
5
+ * Used during hot-reload to decide whether re-validation is needed.
6
+ */
7
+ import { createHash } from 'crypto';
8
+ export class ToolIntegrityTracker {
9
+ constructor() {
10
+ this.records = new Map();
11
+ }
12
+ /**
13
+ * Compute SHA-256 hash of content.
14
+ */
15
+ computeHash(content) {
16
+ return createHash('sha256').update(content, 'utf8').digest('hex');
17
+ }
18
+ /**
19
+ * Called when a tool is loaded. Compares the content hash and source with the stored
20
+ * record and returns what action the caller should take.
21
+ * If the tool moved between trusted/untrusted paths, revalidate is required even if content unchanged.
22
+ */
23
+ onToolLoaded(toolName, yamlContent, source) {
24
+ const hash = this.computeHash(yamlContent);
25
+ const existing = this.records.get(toolName);
26
+ if (!existing) {
27
+ return { action: 'validate', reason: 'new-tool' };
28
+ }
29
+ // Check if source changed (trusted ↔ untrusted): must revalidate for policy enforcement
30
+ if (existing.source !== source) {
31
+ return { action: 'revalidate', reason: 'source-changed' };
32
+ }
33
+ if (existing.hash === hash) {
34
+ return { action: 'keep', reason: 'unchanged' };
35
+ }
36
+ return { action: 'revalidate', reason: 'content-modified' };
37
+ }
38
+ /**
39
+ * Record a tool's hash after successful validation/loading.
40
+ */
41
+ record(toolName, yamlContent, source) {
42
+ this.records.set(toolName, {
43
+ hash: this.computeHash(yamlContent),
44
+ source,
45
+ validatedAt: new Date(),
46
+ });
47
+ }
48
+ /**
49
+ * Get the stored record for a tool.
50
+ */
51
+ getRecord(toolName) {
52
+ return this.records.get(toolName);
53
+ }
54
+ /**
55
+ * Get the stored hash for a tool.
56
+ */
57
+ getHash(toolName) {
58
+ return this.records.get(toolName)?.hash;
59
+ }
60
+ /**
61
+ * Remove a tool entry (e.g. when it's been removed from disk).
62
+ */
63
+ removeEntry(toolName) {
64
+ return this.records.delete(toolName);
65
+ }
66
+ /**
67
+ * Clear all records. Used when doing a full reset.
68
+ */
69
+ clear() {
70
+ this.records.clear();
71
+ }
72
+ /**
73
+ * Get the number of tracked tools.
74
+ */
75
+ get size() {
76
+ return this.records.size;
77
+ }
78
+ }
79
+ //# sourceMappingURL=integrity-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrity-tracker.js","sourceRoot":"","sources":["../../src/policy/integrity-tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAcpC,MAAM,OAAO,oBAAoB;IAAjC;QACmB,YAAO,GAAiC,IAAI,GAAG,EAAE,CAAC;IAmFrE,CAAC;IAjFC;;OAEG;IACH,WAAW,CAAC,OAAe;QACzB,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC;IAED;;;;OAIG;IACH,YAAY,CACV,QAAgB,EAChB,WAAmB,EACnB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AM,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Policy-as-YAML loader for Matimo.
3
+ *
4
+ * Allows the developer to configure the policy engine through a YAML file
5
+ * instead of inline TypeScript, making it easy to adjust policy across
6
+ * environments without rebuilding.
7
+ *
8
+ * Schema for policy.yaml:
9
+ *
10
+ * ```yaml
11
+ * allowedDomains:
12
+ * - api.slack.com
13
+ * - slack.com
14
+ *
15
+ * allowedCredentials:
16
+ * - SLACK_BOT_TOKEN
17
+ * - OPENAI_API_KEY
18
+ *
19
+ * allowedHttpMethods:
20
+ * - GET
21
+ * - POST
22
+ *
23
+ * allowCommandTools: false
24
+ * allowFunctionTools: false
25
+ *
26
+ * protectedNamespaces:
27
+ * - matimo_
28
+ * ```
29
+ *
30
+ * Usage:
31
+ * const matimo = await MatimoInstance.init({ policyFile: './policy.yaml' });
32
+ */
33
+ import type { PolicyEngine, PolicyConfig } from './types.js';
34
+ /**
35
+ * Parse a YAML policy file and return a PolicyEngine configured from it.
36
+ *
37
+ * Throws `MatimoError(INVALID_SCHEMA)` if the file cannot be read or fails validation.
38
+ *
39
+ * @param filePath - Absolute or cwd-relative path to the policy YAML file
40
+ * @returns A frozen `DefaultPolicyEngine` built from the parsed config
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * // Direct usage
45
+ * const engine = loadPolicyFromFile('./policy.yaml');
46
+ * const matimo = await MatimoInstance.init({ policy: engine });
47
+ *
48
+ * // Or use the shorthand InitOption (preferred)
49
+ * const matimo = await MatimoInstance.init({ policyFile: './policy.yaml' });
50
+ * ```
51
+ */
52
+ export declare function loadPolicyFromFile(filePath: string): PolicyEngine;
53
+ /**
54
+ * Parse a YAML policy file into a PolicyConfig (without creating an engine).
55
+ * Useful for hot-reload: parse the new file, then call engine.updateConfig().
56
+ */
57
+ export declare function parsePolicyFile(filePath: string): PolicyConfig;
58
+ //# sourceMappingURL=policy-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-loader.d.ts","sourceRoot":"","sources":["../../src/policy/policy-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAoC7D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAqCjE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAoC9D"}