@kodama-run/sdk 0.1.1 → 0.2.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/LICENSE +21 -0
- package/bin/cli.js +0 -0
- package/package.json +11 -14
- package/src/__tests__/crypto.test.ts +47 -0
- package/src/__tests__/permissions.test.ts +71 -0
- package/src/adapters/mcp.ts +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kodama Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kodama-run/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts"
|
|
7
7
|
},
|
|
8
|
-
"bin":
|
|
9
|
-
"kodama-mcp": "./bin/mcp.js",
|
|
10
|
-
"kodama": "./bin/cli.js"
|
|
11
|
-
},
|
|
8
|
+
"bin": "bin/mcp.js",
|
|
12
9
|
"files": [
|
|
13
10
|
"src/**/*.ts",
|
|
14
11
|
"!src/__tests__",
|
|
@@ -16,21 +13,21 @@
|
|
|
16
13
|
"bin/cli.js",
|
|
17
14
|
"README.md"
|
|
18
15
|
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "echo 'No build step for sdk (source-only)'",
|
|
21
|
-
"test": "bun test",
|
|
22
|
-
"lint": "tsc --noEmit",
|
|
23
|
-
"clean": "rm -rf dist"
|
|
24
|
-
},
|
|
25
16
|
"dependencies": {
|
|
26
|
-
"@kodama-run/shared": "workspace:*",
|
|
27
17
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
28
18
|
"commander": "^13",
|
|
29
19
|
"ws": "^8",
|
|
30
|
-
"zod": "^4.3.6"
|
|
20
|
+
"zod": "^4.3.6",
|
|
21
|
+
"@kodama-run/shared": "0.1.0"
|
|
31
22
|
},
|
|
32
23
|
"devDependencies": {
|
|
33
24
|
"@types/ws": "^8",
|
|
34
25
|
"typescript": "*"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "echo 'No build step for sdk (source-only)'",
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"lint": "tsc --noEmit",
|
|
31
|
+
"clean": "rm -rf dist"
|
|
35
32
|
}
|
|
36
|
-
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import { KodamaCrypto } from "../crypto.ts";
|
|
3
|
+
|
|
4
|
+
describe("KodamaCrypto", () => {
|
|
5
|
+
it("generates a session key (non-empty base64 string)", async () => {
|
|
6
|
+
const key = await KodamaCrypto.generateKey();
|
|
7
|
+
expect(typeof key).toBe("string");
|
|
8
|
+
expect(key.length).toBeGreaterThan(0);
|
|
9
|
+
// AES-256 key = 32 bytes = 44 chars in base64
|
|
10
|
+
expect(key.length).toBe(44);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("encrypts and decrypts roundtrip", async () => {
|
|
14
|
+
const key = await KodamaCrypto.generateKey();
|
|
15
|
+
const plaintext = "Hello, Kodama! 🌿 This is a secret message.";
|
|
16
|
+
|
|
17
|
+
const { ciphertext, iv } = await KodamaCrypto.encrypt(key, plaintext);
|
|
18
|
+
expect(ciphertext.length).toBeGreaterThan(0);
|
|
19
|
+
expect(iv.length).toBeGreaterThan(0);
|
|
20
|
+
|
|
21
|
+
const decrypted = await KodamaCrypto.decrypt(key, ciphertext, iv);
|
|
22
|
+
expect(decrypted).toBe(plaintext);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("fails to decrypt with wrong key", async () => {
|
|
26
|
+
const key1 = await KodamaCrypto.generateKey();
|
|
27
|
+
const key2 = await KodamaCrypto.generateKey();
|
|
28
|
+
const plaintext = "Secret data";
|
|
29
|
+
|
|
30
|
+
const { ciphertext, iv } = await KodamaCrypto.encrypt(key1, plaintext);
|
|
31
|
+
|
|
32
|
+
expect(KodamaCrypto.decrypt(key2, ciphertext, iv)).rejects.toThrow();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("produces different ciphertext for same plaintext (unique IVs)", async () => {
|
|
36
|
+
const key = await KodamaCrypto.generateKey();
|
|
37
|
+
const plaintext = "Same input, different output";
|
|
38
|
+
|
|
39
|
+
const result1 = await KodamaCrypto.encrypt(key, plaintext);
|
|
40
|
+
const result2 = await KodamaCrypto.encrypt(key, plaintext);
|
|
41
|
+
|
|
42
|
+
// IVs should be different (random)
|
|
43
|
+
expect(result1.iv).not.toBe(result2.iv);
|
|
44
|
+
// Ciphertext should also differ due to different IVs
|
|
45
|
+
expect(result1.ciphertext).not.toBe(result2.ciphertext);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import { PermissionChecker } from "../permissions.ts";
|
|
3
|
+
|
|
4
|
+
describe("PermissionChecker", () => {
|
|
5
|
+
it("allows everything with no config", () => {
|
|
6
|
+
const checker = new PermissionChecker();
|
|
7
|
+
expect(checker.isAllowed("src/main.ts")).toBe(true);
|
|
8
|
+
expect(checker.isAllowed("docs/readme.md")).toBe(true);
|
|
9
|
+
expect(checker.isAllowed("any/deep/nested/file.txt")).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("always denies secret patterns (.env, .pem, .key, credentials.*)", () => {
|
|
13
|
+
const checker = new PermissionChecker();
|
|
14
|
+
expect(checker.isAllowed(".env")).toBe(false);
|
|
15
|
+
expect(checker.isAllowed(".env.local")).toBe(false);
|
|
16
|
+
expect(checker.isAllowed("certs/server.pem")).toBe(false);
|
|
17
|
+
expect(checker.isAllowed("keys/private.key")).toBe(false);
|
|
18
|
+
expect(checker.isAllowed("credentials.json")).toBe(false);
|
|
19
|
+
expect(checker.isAllowed("dir/credentials.yaml")).toBe(false);
|
|
20
|
+
expect(checker.isAllowed("tls/cert.p12")).toBe(false);
|
|
21
|
+
expect(checker.isAllowed("tls/cert.pfx")).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("respects allow list — only allowed patterns pass", () => {
|
|
25
|
+
const checker = new PermissionChecker({
|
|
26
|
+
allow: ["src/**", "docs/*.md"],
|
|
27
|
+
});
|
|
28
|
+
expect(checker.isAllowed("src/index.ts")).toBe(true);
|
|
29
|
+
expect(checker.isAllowed("src/deep/nested/file.ts")).toBe(true);
|
|
30
|
+
expect(checker.isAllowed("docs/guide.md")).toBe(true);
|
|
31
|
+
// Not in allow list
|
|
32
|
+
expect(checker.isAllowed("test/foo.ts")).toBe(false);
|
|
33
|
+
expect(checker.isAllowed("package.json")).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("respects deny list — denied patterns are blocked", () => {
|
|
37
|
+
const checker = new PermissionChecker({
|
|
38
|
+
deny: ["*.log", "tmp/**"],
|
|
39
|
+
});
|
|
40
|
+
expect(checker.isAllowed("src/main.ts")).toBe(true);
|
|
41
|
+
expect(checker.isAllowed("server.log")).toBe(false);
|
|
42
|
+
expect(checker.isAllowed("tmp/cache.dat")).toBe(false);
|
|
43
|
+
expect(checker.isAllowed("tmp/deep/file.txt")).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("filterMessage passes content through", () => {
|
|
47
|
+
const checker = new PermissionChecker();
|
|
48
|
+
const content = "Hello, this is a test message with sensitive data";
|
|
49
|
+
expect(checker.filterMessage(content)).toBe(content);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("parses YAML format correctly", () => {
|
|
53
|
+
const yaml = `
|
|
54
|
+
allow:
|
|
55
|
+
- src/**
|
|
56
|
+
- docs/*.md
|
|
57
|
+
deny:
|
|
58
|
+
- "*.log"
|
|
59
|
+
- tmp/**
|
|
60
|
+
`;
|
|
61
|
+
const checker = PermissionChecker.fromYaml(yaml);
|
|
62
|
+
expect(checker.isAllowed("src/index.ts")).toBe(true);
|
|
63
|
+
expect(checker.isAllowed("docs/guide.md")).toBe(true);
|
|
64
|
+
expect(checker.isAllowed("test/foo.ts")).toBe(false);
|
|
65
|
+
expect(checker.isAllowed("server.log")).toBe(false);
|
|
66
|
+
expect(checker.isAllowed("tmp/cache.dat")).toBe(false);
|
|
67
|
+
// Auto-deny patterns still active
|
|
68
|
+
expect(checker.isAllowed(".env")).toBe(false);
|
|
69
|
+
expect(checker.isAllowed("keys/private.key")).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
package/src/adapters/mcp.ts
CHANGED
|
File without changes
|