@matimo/core 0.1.0-alpha.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +341 -14
- package/dist/approval/approval-handler.d.ts +5 -1
- package/dist/approval/approval-handler.d.ts.map +1 -1
- package/dist/approval/approval-handler.js +6 -0
- package/dist/approval/approval-handler.js.map +1 -1
- package/dist/core/schema.d.ts +41 -10
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +40 -4
- package/dist/core/schema.js.map +1 -1
- package/dist/core/skill-content-parser.d.ts +91 -0
- package/dist/core/skill-content-parser.d.ts.map +1 -0
- package/dist/core/skill-content-parser.js +248 -0
- package/dist/core/skill-content-parser.js.map +1 -0
- package/dist/core/skill-loader.d.ts +46 -0
- package/dist/core/skill-loader.d.ts.map +1 -0
- package/dist/core/skill-loader.js +310 -0
- package/dist/core/skill-loader.js.map +1 -0
- package/dist/core/skill-registry.d.ts +131 -0
- package/dist/core/skill-registry.d.ts.map +1 -0
- package/dist/core/skill-registry.js +316 -0
- package/dist/core/skill-registry.js.map +1 -0
- package/dist/core/tfidf-embedding.d.ts +45 -0
- package/dist/core/tfidf-embedding.d.ts.map +1 -0
- package/dist/core/tfidf-embedding.js +199 -0
- package/dist/core/tfidf-embedding.js.map +1 -0
- package/dist/core/tool-loader.d.ts +3 -1
- package/dist/core/tool-loader.d.ts.map +1 -1
- package/dist/core/tool-loader.js +33 -10
- package/dist/core/tool-loader.js.map +1 -1
- package/dist/core/types.d.ts +203 -6
- package/dist/core/types.d.ts.map +1 -1
- package/dist/encodings/parameter-encoding.d.ts +1 -1
- package/dist/encodings/parameter-encoding.d.ts.map +1 -1
- package/dist/encodings/parameter-encoding.js +9 -4
- package/dist/encodings/parameter-encoding.js.map +1 -1
- package/dist/errors/matimo-error.d.ts +11 -2
- package/dist/errors/matimo-error.d.ts.map +1 -1
- package/dist/errors/matimo-error.js +25 -1
- package/dist/errors/matimo-error.js.map +1 -1
- package/dist/executors/command-executor.d.ts +9 -2
- package/dist/executors/command-executor.d.ts.map +1 -1
- package/dist/executors/command-executor.js +29 -5
- package/dist/executors/command-executor.js.map +1 -1
- package/dist/executors/function-executor.d.ts +10 -3
- package/dist/executors/function-executor.d.ts.map +1 -1
- package/dist/executors/function-executor.js +44 -24
- package/dist/executors/function-executor.js.map +1 -1
- package/dist/executors/http-executor.d.ts +79 -4
- package/dist/executors/http-executor.d.ts.map +1 -1
- package/dist/executors/http-executor.js +232 -28
- package/dist/executors/http-executor.js.map +1 -1
- package/dist/index.d.ts +25 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/langchain.d.ts +55 -0
- package/dist/integrations/langchain.d.ts.map +1 -1
- package/dist/integrations/langchain.js +71 -4
- package/dist/integrations/langchain.js.map +1 -1
- package/dist/logging/winston-logger.d.ts.map +1 -1
- package/dist/logging/winston-logger.js +9 -1
- package/dist/logging/winston-logger.js.map +1 -1
- package/dist/matimo-instance.d.ts +230 -18
- package/dist/matimo-instance.d.ts.map +1 -1
- package/dist/matimo-instance.js +739 -40
- package/dist/matimo-instance.js.map +1 -1
- package/dist/mcp/index.d.ts +18 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +24 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +141 -0
- package/dist/mcp/mcp-server.d.ts.map +1 -0
- package/dist/mcp/mcp-server.js +754 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/mcp/secrets/aws-resolver.d.ts +41 -0
- package/dist/mcp/secrets/aws-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/aws-resolver.js +141 -0
- package/dist/mcp/secrets/aws-resolver.js.map +1 -0
- package/dist/mcp/secrets/dotenv-resolver.d.ts +23 -0
- package/dist/mcp/secrets/dotenv-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/dotenv-resolver.js +94 -0
- package/dist/mcp/secrets/dotenv-resolver.js.map +1 -0
- package/dist/mcp/secrets/env-resolver.d.ts +14 -0
- package/dist/mcp/secrets/env-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/env-resolver.js +27 -0
- package/dist/mcp/secrets/env-resolver.js.map +1 -0
- package/dist/mcp/secrets/index.d.ts +14 -0
- package/dist/mcp/secrets/index.d.ts.map +1 -0
- package/dist/mcp/secrets/index.js +13 -0
- package/dist/mcp/secrets/index.js.map +1 -0
- package/dist/mcp/secrets/resolver-chain.d.ts +34 -0
- package/dist/mcp/secrets/resolver-chain.d.ts.map +1 -0
- package/dist/mcp/secrets/resolver-chain.js +141 -0
- package/dist/mcp/secrets/resolver-chain.js.map +1 -0
- package/dist/mcp/secrets/types.d.ts +73 -0
- package/dist/mcp/secrets/types.d.ts.map +1 -0
- package/dist/mcp/secrets/types.js +8 -0
- package/dist/mcp/secrets/types.js.map +1 -0
- package/dist/mcp/secrets/vault-resolver.d.ts +43 -0
- package/dist/mcp/secrets/vault-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/vault-resolver.js +127 -0
- package/dist/mcp/secrets/vault-resolver.js.map +1 -0
- package/dist/mcp/tool-converter.d.ts +40 -0
- package/dist/mcp/tool-converter.d.ts.map +1 -0
- package/dist/mcp/tool-converter.js +185 -0
- package/dist/mcp/tool-converter.js.map +1 -0
- package/dist/policy/approval-manifest.d.ts +76 -0
- package/dist/policy/approval-manifest.d.ts.map +1 -0
- package/dist/policy/approval-manifest.js +197 -0
- package/dist/policy/approval-manifest.js.map +1 -0
- package/dist/policy/content-validator.d.ts +19 -0
- package/dist/policy/content-validator.d.ts.map +1 -0
- package/dist/policy/content-validator.js +196 -0
- package/dist/policy/content-validator.js.map +1 -0
- package/dist/policy/default-policy.d.ts +46 -0
- package/dist/policy/default-policy.d.ts.map +1 -0
- package/dist/policy/default-policy.js +241 -0
- package/dist/policy/default-policy.js.map +1 -0
- package/dist/policy/events.d.ts +71 -0
- package/dist/policy/events.d.ts.map +1 -0
- package/dist/policy/events.js +8 -0
- package/dist/policy/events.js.map +1 -0
- package/dist/policy/index.d.ts +13 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +9 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/integrity-tracker.d.ts +62 -0
- package/dist/policy/integrity-tracker.d.ts.map +1 -0
- package/dist/policy/integrity-tracker.js +79 -0
- package/dist/policy/integrity-tracker.js.map +1 -0
- package/dist/policy/policy-loader.d.ts +58 -0
- package/dist/policy/policy-loader.d.ts.map +1 -0
- package/dist/policy/policy-loader.js +156 -0
- package/dist/policy/policy-loader.js.map +1 -0
- package/dist/policy/risk-classifier.d.ts +18 -0
- package/dist/policy/risk-classifier.d.ts.map +1 -0
- package/dist/policy/risk-classifier.js +47 -0
- package/dist/policy/risk-classifier.js.map +1 -0
- package/dist/policy/types.d.ts +131 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +8 -0
- package/dist/policy/types.js.map +1 -0
- package/package.json +22 -6
- package/tools/matimo_approve_tool/definition.yaml +36 -0
- package/tools/matimo_approve_tool/matimo_approve_tool.ts +90 -0
- package/tools/matimo_create_skill/definition.yaml +46 -0
- package/tools/matimo_create_skill/matimo_create_skill.ts +75 -0
- package/tools/matimo_create_tool/definition.yaml +48 -0
- package/tools/matimo_create_tool/matimo_create_tool.ts +137 -0
- package/tools/matimo_get_skill/definition.yaml +60 -0
- package/tools/matimo_get_skill/matimo_get_skill.ts +182 -0
- package/tools/matimo_get_tool/definition.yaml +36 -0
- package/tools/matimo_get_tool/matimo_get_tool.ts +56 -0
- package/tools/matimo_get_tool_status/definition.yaml +42 -0
- package/tools/matimo_get_tool_status/matimo_get_tool_status.ts +101 -0
- package/tools/matimo_list_skills/definition.yaml +52 -0
- package/tools/matimo_list_skills/matimo_list_skills.ts +138 -0
- package/tools/matimo_list_user_tools/definition.yaml +32 -0
- package/tools/matimo_list_user_tools/matimo_list_user_tools.ts +74 -0
- package/tools/matimo_reload_tools/definition.yaml +35 -0
- package/tools/matimo_reload_tools/matimo_reload_tools.ts +29 -0
- package/tools/matimo_search_tools/definition.yaml +32 -0
- package/tools/matimo_search_tools/matimo_search_tools.ts +82 -0
- package/tools/matimo_validate_skill/definition.yaml +43 -0
- package/tools/matimo_validate_skill/matimo_validate_skill.ts +137 -0
- package/tools/matimo_validate_tool/definition.yaml +34 -0
- package/tools/matimo_validate_tool/matimo_validate_tool.ts +168 -0
- package/tools/shared/skill-validation.ts +335 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,156 @@
|
|
|
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 fs from 'fs';
|
|
34
|
+
import yaml from 'js-yaml';
|
|
35
|
+
import { z } from 'zod';
|
|
36
|
+
import { DefaultPolicyEngine } from './default-policy';
|
|
37
|
+
import { MatimoError, ErrorCode } from '../errors/matimo-error';
|
|
38
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
39
|
+
// Zod schema — validates the YAML before constructing PolicyConfig
|
|
40
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
41
|
+
// Valid HTTP methods supported by the policy engine
|
|
42
|
+
const VALID_HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
|
|
43
|
+
const ValidHttpMethodEnum = z.enum(VALID_HTTP_METHODS);
|
|
44
|
+
const PolicyFileSchema = z.object({
|
|
45
|
+
allowedDomains: z.array(z.string()).optional(),
|
|
46
|
+
allowedCredentials: z.array(z.string()).optional(),
|
|
47
|
+
allowedHttpMethods: z
|
|
48
|
+
.array(z
|
|
49
|
+
.string()
|
|
50
|
+
.transform((val) => val.toUpperCase())
|
|
51
|
+
.pipe(ValidHttpMethodEnum))
|
|
52
|
+
.optional(),
|
|
53
|
+
allowCommandTools: z.boolean().optional(),
|
|
54
|
+
allowFunctionTools: z.boolean().optional(),
|
|
55
|
+
protectedNamespaces: z.array(z.string()).optional(),
|
|
56
|
+
enableHITL: z.boolean().optional(),
|
|
57
|
+
quarantineRiskLevels: z.array(z.enum(['low', 'medium', 'high', 'critical'])).optional(),
|
|
58
|
+
approvalTtlSeconds: z.number().int().positive().optional(),
|
|
59
|
+
});
|
|
60
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
61
|
+
// Public API
|
|
62
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
63
|
+
/**
|
|
64
|
+
* Parse a YAML policy file and return a PolicyEngine configured from it.
|
|
65
|
+
*
|
|
66
|
+
* Throws `MatimoError(INVALID_SCHEMA)` if the file cannot be read or fails validation.
|
|
67
|
+
*
|
|
68
|
+
* @param filePath - Absolute or cwd-relative path to the policy YAML file
|
|
69
|
+
* @returns A frozen `DefaultPolicyEngine` built from the parsed config
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* // Direct usage
|
|
74
|
+
* const engine = loadPolicyFromFile('./policy.yaml');
|
|
75
|
+
* const matimo = await MatimoInstance.init({ policy: engine });
|
|
76
|
+
*
|
|
77
|
+
* // Or use the shorthand InitOption (preferred)
|
|
78
|
+
* const matimo = await MatimoInstance.init({ policyFile: './policy.yaml' });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function loadPolicyFromFile(filePath) {
|
|
82
|
+
let raw;
|
|
83
|
+
try {
|
|
84
|
+
raw = fs.readFileSync(filePath, 'utf-8');
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
throw new MatimoError(`Cannot read policy file "${filePath}": ${err.message}`, ErrorCode.INVALID_SCHEMA, { filePath });
|
|
88
|
+
}
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = yaml.load(raw);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
throw new MatimoError(`Policy file "${filePath}" contains invalid YAML: ${err.message}`, ErrorCode.INVALID_SCHEMA, { filePath });
|
|
95
|
+
}
|
|
96
|
+
const result = PolicyFileSchema.safeParse(parsed ?? {});
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
const issues = result.error.issues
|
|
99
|
+
.map((i) => ` • ${i.path.join('.')}: ${i.message}`)
|
|
100
|
+
.join('\n');
|
|
101
|
+
throw new MatimoError(`Policy file "${filePath}" is invalid:\n${issues}`, ErrorCode.INVALID_SCHEMA, { filePath, issues: result.error.issues });
|
|
102
|
+
}
|
|
103
|
+
const policyConfig = buildPolicyConfig(result.data);
|
|
104
|
+
return new DefaultPolicyEngine(policyConfig);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Parse a YAML policy file into a PolicyConfig (without creating an engine).
|
|
108
|
+
* Useful for hot-reload: parse the new file, then call engine.updateConfig().
|
|
109
|
+
*/
|
|
110
|
+
export function parsePolicyFile(filePath) {
|
|
111
|
+
let raw;
|
|
112
|
+
try {
|
|
113
|
+
raw = fs.readFileSync(filePath, 'utf-8');
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
throw new MatimoError(`Cannot read policy file "${filePath}": ${err.message}`, ErrorCode.INVALID_SCHEMA, { filePath });
|
|
117
|
+
}
|
|
118
|
+
let parsed;
|
|
119
|
+
try {
|
|
120
|
+
parsed = yaml.load(raw);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
throw new MatimoError(`Policy file "${filePath}" contains invalid YAML: ${err.message}`, ErrorCode.INVALID_SCHEMA, { filePath });
|
|
124
|
+
}
|
|
125
|
+
const result = PolicyFileSchema.safeParse(parsed ?? {});
|
|
126
|
+
if (!result.success) {
|
|
127
|
+
const issues = result.error.issues
|
|
128
|
+
.map((i) => ` \u2022 ${i.path.join('.')}: ${i.message}`)
|
|
129
|
+
.join('\n');
|
|
130
|
+
throw new MatimoError(`Policy file "${filePath}" is invalid:\n${issues}`, ErrorCode.INVALID_SCHEMA, { filePath, issues: result.error.issues });
|
|
131
|
+
}
|
|
132
|
+
return buildPolicyConfig(result.data);
|
|
133
|
+
}
|
|
134
|
+
function buildPolicyConfig(data) {
|
|
135
|
+
const config = {};
|
|
136
|
+
if (data.allowedDomains !== undefined)
|
|
137
|
+
config.allowedDomains = data.allowedDomains;
|
|
138
|
+
if (data.allowedCredentials !== undefined)
|
|
139
|
+
config.allowedCredentials = data.allowedCredentials;
|
|
140
|
+
if (data.allowedHttpMethods !== undefined)
|
|
141
|
+
config.allowedHttpMethods = data.allowedHttpMethods;
|
|
142
|
+
if (data.allowCommandTools !== undefined)
|
|
143
|
+
config.allowCommandTools = data.allowCommandTools;
|
|
144
|
+
if (data.allowFunctionTools !== undefined)
|
|
145
|
+
config.allowFunctionTools = data.allowFunctionTools;
|
|
146
|
+
if (data.protectedNamespaces !== undefined)
|
|
147
|
+
config.protectedNamespaces = data.protectedNamespaces;
|
|
148
|
+
if (data.enableHITL !== undefined)
|
|
149
|
+
config.enableHITL = data.enableHITL;
|
|
150
|
+
if (data.quarantineRiskLevels !== undefined)
|
|
151
|
+
config.quarantineRiskLevels = data.quarantineRiskLevels;
|
|
152
|
+
if (data.approvalTtlSeconds !== undefined)
|
|
153
|
+
config.approvalTtlSeconds = data.approvalTtlSeconds;
|
|
154
|
+
return config;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=policy-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-loader.js","sourceRoot":"","sources":["../../src/policy/policy-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEhE,iFAAiF;AACjF,mEAAmE;AACnE,iFAAiF;AAEjF,oDAAoD;AACpD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAU,CAAC;AACjG,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAEvD,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC9C,kBAAkB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAClD,kBAAkB,EAAE,CAAC;SAClB,KAAK,CACJ,CAAC;SACE,MAAM,EAAE;SACR,SAAS,CAAC,CAAC,GAAW,EAAE,EAAE,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,CAAC,iBAAiB,KAAK,SAAS;QAAE,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;IAC5F,IAAI,IAAI,CAAC,kBAAkB,KAAK,SAAS;QAAE,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;IAC/F,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS;QAAE,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC;IAClG,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS;QAAE,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACvE,IAAI,IAAI,CAAC,oBAAoB,KAAK,SAAS;QACzC,MAAM,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;IAC1D,IAAI,IAAI,CAAC,kBAAkB,KAAK,SAAS;QAAE,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;IAC/F,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk Classifier for Matimo tools.
|
|
3
|
+
*
|
|
4
|
+
* Pure function that classifies a tool's risk level based on its execution
|
|
5
|
+
* type, HTTP method, and approval requirements. No schema changes needed.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolDefinition } from '../core/schema';
|
|
8
|
+
import type { RiskLevel } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Classify the risk level of a tool based on its definition.
|
|
11
|
+
*
|
|
12
|
+
* - critical: arbitrary code execution (type: function)
|
|
13
|
+
* - high: shell execution (type: command), HTTP DELETE, or explicit requires_approval
|
|
14
|
+
* - medium: HTTP POST/PUT/PATCH (write operations)
|
|
15
|
+
* - low: HTTP GET, read-only tools
|
|
16
|
+
*/
|
|
17
|
+
export declare function classifyRisk(tool: ToolDefinition): RiskLevel;
|
|
18
|
+
//# sourceMappingURL=risk-classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk-classifier.d.ts","sourceRoot":"","sources":["../../src/policy/risk-classifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,CAoC5D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk Classifier for Matimo tools.
|
|
3
|
+
*
|
|
4
|
+
* Pure function that classifies a tool's risk level based on its execution
|
|
5
|
+
* type, HTTP method, and approval requirements. No schema changes needed.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Classify the risk level of a tool based on its definition.
|
|
9
|
+
*
|
|
10
|
+
* - critical: arbitrary code execution (type: function)
|
|
11
|
+
* - high: shell execution (type: command), HTTP DELETE, or explicit requires_approval
|
|
12
|
+
* - medium: HTTP POST/PUT/PATCH (write operations)
|
|
13
|
+
* - low: HTTP GET, read-only tools
|
|
14
|
+
*/
|
|
15
|
+
export function classifyRisk(tool) {
|
|
16
|
+
// Explicit override declared in the tool YAML takes precedence
|
|
17
|
+
if (tool.risk) {
|
|
18
|
+
return tool.risk;
|
|
19
|
+
}
|
|
20
|
+
const exec = tool.execution;
|
|
21
|
+
// Arbitrary code execution is always critical risk
|
|
22
|
+
if (exec.type === 'function') {
|
|
23
|
+
return 'critical';
|
|
24
|
+
}
|
|
25
|
+
// Shell commands are high risk (injection vectors)
|
|
26
|
+
if (exec.type === 'command') {
|
|
27
|
+
return 'high';
|
|
28
|
+
}
|
|
29
|
+
// HTTP tools: risk depends on method
|
|
30
|
+
if (exec.type === 'http') {
|
|
31
|
+
if (tool.requires_approval === true) {
|
|
32
|
+
return 'high';
|
|
33
|
+
}
|
|
34
|
+
const method = exec.method.toUpperCase();
|
|
35
|
+
if (method === 'DELETE') {
|
|
36
|
+
return 'high';
|
|
37
|
+
}
|
|
38
|
+
if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
|
|
39
|
+
return 'medium';
|
|
40
|
+
}
|
|
41
|
+
// GET is low risk
|
|
42
|
+
return 'low';
|
|
43
|
+
}
|
|
44
|
+
// Unknown execution type — treat as high
|
|
45
|
+
return 'high';
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=risk-classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk-classifier.js","sourceRoot":"","sources":["../../src/policy/risk-classifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,IAAoB;IAC/C,+DAA+D;IAC/D,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,OAAO,IAAI,CAAC,IAAiB,CAAC;IAChC,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;IAE5B,mDAAmD;IACnD,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,mDAAmD;IACnD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,qCAAqC;IACrC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACzC,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxB,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YAChE,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,kBAAkB;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,yCAAyC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy Engine types for Matimo Agent-Native SDK.
|
|
3
|
+
*
|
|
4
|
+
* The policy engine governs what tools agents can create, execute, and discover.
|
|
5
|
+
* Agents cannot mutate policy at runtime; the host configures it and may hot-reload via `updateConfig()`.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolDefinition } from '../core/schema';
|
|
8
|
+
export type RiskLevel = 'low' | 'medium' | 'high' | 'critical';
|
|
9
|
+
/**
|
|
10
|
+
* Three-tier classification for agent-created tool proposals.
|
|
11
|
+
*
|
|
12
|
+
* - `auto`: Can be created and used immediately (low-risk GET tools, no auth).
|
|
13
|
+
* - `approval-required`: Allowed but must be approved before execution
|
|
14
|
+
* (tools with auth, POST/PUT/DELETE, external data writes).
|
|
15
|
+
* - `blocked`: Can never be created regardless of policy config
|
|
16
|
+
* (reserved namespaces, function/command execution, SSRF targets,
|
|
17
|
+
* tools referencing policy internals).
|
|
18
|
+
*/
|
|
19
|
+
export type PolicyTier = 'auto' | 'approval-required' | 'blocked';
|
|
20
|
+
/**
|
|
21
|
+
* Identity and environment context passed by the host application.
|
|
22
|
+
* Matimo does not authenticate — this is whatever the caller provides.
|
|
23
|
+
*/
|
|
24
|
+
export interface PolicyContext {
|
|
25
|
+
/** Identifier for the calling agent (optional — SDK doesn't mandate identity) */
|
|
26
|
+
agentId?: string;
|
|
27
|
+
/** Deployment environment (e.g. 'dev', 'staging', 'prod') */
|
|
28
|
+
environment?: string;
|
|
29
|
+
/** Roles assigned to the caller (e.g. ['reader', 'writer', 'admin']) */
|
|
30
|
+
roles?: string[];
|
|
31
|
+
/** Extensible metadata for custom policy rules */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
export type PolicyDecision = {
|
|
35
|
+
allowed: true;
|
|
36
|
+
} | {
|
|
37
|
+
allowed: false;
|
|
38
|
+
reason: string;
|
|
39
|
+
riskLevel?: RiskLevel;
|
|
40
|
+
} | {
|
|
41
|
+
allowed: 'pending_approval';
|
|
42
|
+
reason: string;
|
|
43
|
+
riskLevel: RiskLevel;
|
|
44
|
+
/** Tool name for the approval flow to reference */
|
|
45
|
+
toolName?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Async callback invoked when a tool enters the quarantine/HITL state.
|
|
49
|
+
* Returns `true` if the admin approves, `false` if rejected.
|
|
50
|
+
* Integrators wire this to a UI, Slack message, or approval queue.
|
|
51
|
+
*/
|
|
52
|
+
export type HITLCallback = (request: HITLRequest) => Promise<boolean>;
|
|
53
|
+
export interface HITLRequest {
|
|
54
|
+
toolName: string;
|
|
55
|
+
riskLevel: RiskLevel;
|
|
56
|
+
reason: string;
|
|
57
|
+
environment?: string;
|
|
58
|
+
agentId?: string;
|
|
59
|
+
/** Full tool definition for admin review */
|
|
60
|
+
toolDefinition?: unknown;
|
|
61
|
+
}
|
|
62
|
+
export interface Violation {
|
|
63
|
+
/** Machine-readable rule identifier (e.g. 'no-ssrf', 'reserved-namespace') */
|
|
64
|
+
rule: string;
|
|
65
|
+
/** Severity of the violation */
|
|
66
|
+
severity: RiskLevel;
|
|
67
|
+
/** Human-readable explanation */
|
|
68
|
+
message: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ValidationResult {
|
|
71
|
+
valid: boolean;
|
|
72
|
+
violations: Violation[];
|
|
73
|
+
}
|
|
74
|
+
export interface ValidationContext {
|
|
75
|
+
/** Whether the tool comes from a trusted or untrusted path */
|
|
76
|
+
source: 'trusted' | 'untrusted';
|
|
77
|
+
/** Active policy configuration (defaults to empty/permissive) */
|
|
78
|
+
policy?: PolicyConfig;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Developer-configurable policy rules. All fields optional with conservative defaults.
|
|
82
|
+
*/
|
|
83
|
+
export interface PolicyConfig {
|
|
84
|
+
/** HTTP tool URL domain allowlist. If set, only these domains are permitted. */
|
|
85
|
+
allowedDomains?: string[];
|
|
86
|
+
/** Env var names that agent-created tools may reference for auth. */
|
|
87
|
+
allowedCredentials?: string[];
|
|
88
|
+
/** HTTP methods allowed for agent-created tools (default: ['GET', 'POST']). */
|
|
89
|
+
allowedHttpMethods?: string[];
|
|
90
|
+
/** Allow agent-created tools with execution type 'command' (default: false). */
|
|
91
|
+
allowCommandTools?: boolean;
|
|
92
|
+
/** Allow agent-created tools with execution type 'function' (default: false — always false for untrusted). */
|
|
93
|
+
allowFunctionTools?: boolean;
|
|
94
|
+
/** Tool name prefixes reserved for built-in tools (default: ['matimo_']). */
|
|
95
|
+
protectedNamespaces?: string[];
|
|
96
|
+
/**
|
|
97
|
+
* Enable quarantine/HITL for medium-risk tools in production.
|
|
98
|
+
* When true, `canCreate()` returns `pending_approval` instead of `allowed: false`
|
|
99
|
+
* for medium-risk tools, allowing a human reviewer to approve or reject.
|
|
100
|
+
* Default: false (original binary behavior preserved).
|
|
101
|
+
*/
|
|
102
|
+
enableHITL?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Risk levels eligible for HITL quarantine instead of outright rejection.
|
|
105
|
+
* Default: ['medium'] — critical/high are always blocked, low is always auto.
|
|
106
|
+
*/
|
|
107
|
+
quarantineRiskLevels?: RiskLevel[];
|
|
108
|
+
/**
|
|
109
|
+
* Number of seconds after which an approval expires and the tool must be re-approved.
|
|
110
|
+
* If not set, approvals never expire.
|
|
111
|
+
*/
|
|
112
|
+
approvalTtlSeconds?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The PolicyEngine interface. Implementations are frozen at boot time and
|
|
116
|
+
* cannot be mutated by agents at runtime.
|
|
117
|
+
*/
|
|
118
|
+
export interface PolicyEngine {
|
|
119
|
+
/** Check whether this agent is allowed to execute a given tool. */
|
|
120
|
+
canExecute(context: PolicyContext, tool: ToolDefinition): PolicyDecision;
|
|
121
|
+
/** Check whether this agent is allowed to create/propose a tool definition. */
|
|
122
|
+
canCreate(context: PolicyContext, toolDef: ToolDefinition): PolicyDecision;
|
|
123
|
+
/**
|
|
124
|
+
* Update the policy configuration at runtime (hot-reload).
|
|
125
|
+
* Implementations should validate the new config before applying.
|
|
126
|
+
*/
|
|
127
|
+
updateConfig?(config: PolicyConfig): void;
|
|
128
|
+
/** Filter a list of tools to only those this agent is allowed to see/use. */
|
|
129
|
+
filterForAgent(context: PolicyContext, tools: ToolDefinition[]): ToolDefinition[];
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/policy/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIrD,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAI/D;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAAC;AAIlE;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAID,MAAM,MAAM,cAAc,GACtB;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GACjB;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAA;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OAAO,CAAC;IAC7B,6EAA6E;IAC7E,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,SAAS,EAAE,CAAC;IACnC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAID;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,GAAG,cAAc,CAAC;IAEzE,+EAA+E;IAC/E,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAG,cAAc,CAAC;IAE3E;;;OAGG;IACH,YAAY,CAAC,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAE1C,6EAA6E;IAC7E,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAAC;CACnF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy Engine types for Matimo Agent-Native SDK.
|
|
3
|
+
*
|
|
4
|
+
* The policy engine governs what tools agents can create, execute, and discover.
|
|
5
|
+
* Agents cannot mutate policy at runtime; the host configures it and may hot-reload via `updateConfig()`.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/policy/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matimo/core",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Core SDK for Matimo: Framework-agnostic YAML-driven tool ecosystem for AI agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./mcp": {
|
|
15
|
+
"types": "./dist/mcp/index.d.ts",
|
|
16
|
+
"default": "./dist/mcp/index.js"
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
19
|
"engines": {
|
|
@@ -54,14 +58,26 @@
|
|
|
54
58
|
"access": "public"
|
|
55
59
|
},
|
|
56
60
|
"dependencies": {
|
|
57
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
58
|
-
"axios": "^1.
|
|
61
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
62
|
+
"axios": "^1.15.2",
|
|
59
63
|
"dotenv": "^17.2.3",
|
|
60
64
|
"js-yaml": "^4.1.1",
|
|
61
65
|
"winston": "^3.19.0",
|
|
62
66
|
"yaml": "^2.8.2",
|
|
63
67
|
"zod": "^4.3.6"
|
|
64
68
|
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@aws-sdk/client-secrets-manager": ">=3.0.0",
|
|
71
|
+
"node-vault": ">=0.10.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependenciesMeta": {
|
|
74
|
+
"node-vault": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"@aws-sdk/client-secrets-manager": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
80
|
+
},
|
|
65
81
|
"devDependencies": {
|
|
66
82
|
"@commitlint/cli": "^20.3.1",
|
|
67
83
|
"@commitlint/config-conventional": "^20.3.1",
|
|
@@ -69,14 +85,14 @@
|
|
|
69
85
|
"@types/jest": "^30.0.0",
|
|
70
86
|
"@types/js-yaml": "^4.0.9",
|
|
71
87
|
"@types/node": "^25.1.0",
|
|
72
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
73
|
-
"@typescript-eslint/parser": "^8.
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^8.58.0",
|
|
89
|
+
"@typescript-eslint/parser": "^8.58.0",
|
|
74
90
|
"eslint": "^9.39.2",
|
|
75
91
|
"husky": "^9.1.7",
|
|
76
92
|
"jest": "^30.2.0",
|
|
77
93
|
"langchain": "^1.2.18",
|
|
78
94
|
"prettier": "^3.8.1",
|
|
79
|
-
"ts-jest": "^29.4.
|
|
95
|
+
"ts-jest": "^29.4.9",
|
|
80
96
|
"ts-node": "^10.9.2",
|
|
81
97
|
"tsx": "^4.21.0",
|
|
82
98
|
"typescript": "^5.9.3"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: matimo_approve_tool
|
|
2
|
+
version: '1.0.0'
|
|
3
|
+
description: Approve a draft tool for production use. Re-validates the tool, requires admin role, signs with HMAC, and updates the approval manifest.
|
|
4
|
+
requires_approval: true
|
|
5
|
+
tags:
|
|
6
|
+
- matimo
|
|
7
|
+
- meta
|
|
8
|
+
- approval
|
|
9
|
+
|
|
10
|
+
parameters:
|
|
11
|
+
name:
|
|
12
|
+
type: string
|
|
13
|
+
required: true
|
|
14
|
+
description: Name of the tool to approve
|
|
15
|
+
tool_dir:
|
|
16
|
+
type: string
|
|
17
|
+
required: false
|
|
18
|
+
description: Directory containing the tool (default ./matimo-tools)
|
|
19
|
+
|
|
20
|
+
execution:
|
|
21
|
+
type: function
|
|
22
|
+
code: './matimo_approve_tool.ts'
|
|
23
|
+
|
|
24
|
+
output_schema:
|
|
25
|
+
type: object
|
|
26
|
+
properties:
|
|
27
|
+
success:
|
|
28
|
+
type: boolean
|
|
29
|
+
name:
|
|
30
|
+
type: string
|
|
31
|
+
hash:
|
|
32
|
+
type: string
|
|
33
|
+
approvedAt:
|
|
34
|
+
type: string
|
|
35
|
+
message:
|
|
36
|
+
type: string
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
import {
|
|
5
|
+
validateToolDefinition,
|
|
6
|
+
validateToolContent,
|
|
7
|
+
ApprovalManifest,
|
|
8
|
+
getGlobalMatimoLogger,
|
|
9
|
+
} from '@matimo/core';
|
|
10
|
+
import type { Violation } from '@matimo/core';
|
|
11
|
+
|
|
12
|
+
interface ApproveParams {
|
|
13
|
+
name: string;
|
|
14
|
+
tool_dir?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface ApproveResult {
|
|
18
|
+
success: boolean;
|
|
19
|
+
name?: string;
|
|
20
|
+
hash?: string;
|
|
21
|
+
approvedAt?: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default async function matimoApproveTool(
|
|
26
|
+
params: ApproveParams,
|
|
27
|
+
context?: { credentials?: Record<string, string> },
|
|
28
|
+
): Promise<ApproveResult> {
|
|
29
|
+
const logger = getGlobalMatimoLogger();
|
|
30
|
+
const toolDir = params.tool_dir || './matimo-tools';
|
|
31
|
+
|
|
32
|
+
// Step 1: Read tool definition
|
|
33
|
+
const defPath = path.join(toolDir, params.name, 'definition.yaml');
|
|
34
|
+
if (!fs.existsSync(defPath)) {
|
|
35
|
+
return { success: false, message: `Tool not found: ${defPath}` };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const yamlContent = fs.readFileSync(defPath, 'utf-8');
|
|
39
|
+
|
|
40
|
+
// Step 2: Parse and validate
|
|
41
|
+
let tool;
|
|
42
|
+
try {
|
|
43
|
+
const parsed = yaml.load(yamlContent);
|
|
44
|
+
tool = validateToolDefinition(parsed);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
return { success: false, message: `Validation failed: ${(err as Error).message}` };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Step 3: Re-run content validator
|
|
50
|
+
const validation = validateToolContent(tool, { source: 'untrusted' });
|
|
51
|
+
const criticalOrHigh = validation.violations.filter(
|
|
52
|
+
(v: Violation) => v.severity === 'critical' || v.severity === 'high',
|
|
53
|
+
);
|
|
54
|
+
if (criticalOrHigh.length > 0) {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
message: 'Tool has policy violations that must be resolved before approval',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Step 4: Approve via manifest
|
|
62
|
+
const approvalDir = path.resolve(toolDir);
|
|
63
|
+
const manifest = new ApprovalManifest(
|
|
64
|
+
approvalDir,
|
|
65
|
+
context?.credentials?.MATIMO_APPROVAL_SECRET,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const hash = manifest.computeHash(yamlContent);
|
|
69
|
+
manifest.approve(params.name, hash);
|
|
70
|
+
const approval = manifest.getApproval(params.name);
|
|
71
|
+
|
|
72
|
+
// Step 5: Update status in YAML
|
|
73
|
+
const parsed = yaml.load(yamlContent) as Record<string, unknown>;
|
|
74
|
+
parsed.status = 'approved';
|
|
75
|
+
const updatedYaml = yaml.dump(parsed);
|
|
76
|
+
fs.writeFileSync(defPath, updatedYaml, 'utf-8');
|
|
77
|
+
|
|
78
|
+
logger.info('matimo_approve_tool: tool approved', {
|
|
79
|
+
name: params.name,
|
|
80
|
+
hash,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
success: true,
|
|
85
|
+
name: params.name,
|
|
86
|
+
hash,
|
|
87
|
+
approvedAt: approval?.approvedAt,
|
|
88
|
+
message: 'Tool approved. Effective after reload or immediately if auto-reload is active.',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: matimo_create_skill
|
|
2
|
+
version: '1.0.0'
|
|
3
|
+
description: >-
|
|
4
|
+
Create a new skill following the Agent Skills specification
|
|
5
|
+
(https://agentskills.io/specification). Validates name (lowercase, hyphens,
|
|
6
|
+
max 64 chars), YAML frontmatter (name, description required), and enforces
|
|
7
|
+
that the frontmatter name matches the directory name.
|
|
8
|
+
requires_approval: true
|
|
9
|
+
tags:
|
|
10
|
+
- matimo
|
|
11
|
+
- meta
|
|
12
|
+
- skill
|
|
13
|
+
|
|
14
|
+
parameters:
|
|
15
|
+
name:
|
|
16
|
+
type: string
|
|
17
|
+
required: true
|
|
18
|
+
description: >-
|
|
19
|
+
Skill directory name. Must be lowercase letters, numbers, and hyphens
|
|
20
|
+
only. Max 64 characters. Must not start/end with a hyphen or contain
|
|
21
|
+
consecutive hyphens. Must match the name field in the YAML frontmatter.
|
|
22
|
+
content:
|
|
23
|
+
type: string
|
|
24
|
+
required: true
|
|
25
|
+
description: >-
|
|
26
|
+
The full SKILL.md content including YAML frontmatter (--- delimited) and
|
|
27
|
+
markdown body. Required frontmatter fields: name, description. Optional:
|
|
28
|
+
license, compatibility, metadata, allowed-tools.
|
|
29
|
+
target_dir:
|
|
30
|
+
type: string
|
|
31
|
+
required: false
|
|
32
|
+
description: Directory to create the skill in (default ./matimo-tools/skills)
|
|
33
|
+
|
|
34
|
+
execution:
|
|
35
|
+
type: function
|
|
36
|
+
code: './matimo_create_skill.ts'
|
|
37
|
+
|
|
38
|
+
output_schema:
|
|
39
|
+
type: object
|
|
40
|
+
properties:
|
|
41
|
+
success:
|
|
42
|
+
type: boolean
|
|
43
|
+
path:
|
|
44
|
+
type: string
|
|
45
|
+
message:
|
|
46
|
+
type: string
|