obsidian-catui-acp 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.
@@ -0,0 +1,59 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import type { UIMessage } from "ai";
4
+ import { SessionMessagesCache } from "../src/chat/session-messages-cache";
5
+
6
+ function message(id: string): UIMessage {
7
+ return {
8
+ id,
9
+ role: "assistant",
10
+ parts: [{ type: "text", text: id }],
11
+ } as UIMessage;
12
+ }
13
+
14
+ test("save and load round-trip messages", () => {
15
+ const cache = new SessionMessagesCache();
16
+ cache.save("s1", [message("a"), message("b")]);
17
+
18
+ const loaded = cache.load("s1");
19
+ assert.ok(loaded);
20
+ assert.equal(loaded!.length, 2);
21
+ assert.equal(loaded![0]!.id, "a");
22
+ });
23
+
24
+ test("load returns null for unknown sessions", () => {
25
+ const cache = new SessionMessagesCache();
26
+ assert.equal(cache.load("missing"), null);
27
+ });
28
+
29
+ test("load does not mutate the cached messages", () => {
30
+ const cache = new SessionMessagesCache();
31
+ cache.save("s1", [message("a")]);
32
+ const loaded = cache.load("s1");
33
+ loaded!.push(message("c"));
34
+ assert.equal(cache.load("s1")!.length, 1);
35
+ });
36
+
37
+ test("evict removes a session", () => {
38
+ const cache = new SessionMessagesCache();
39
+ cache.save("s1", [message("a")]);
40
+ cache.evict("s1");
41
+ assert.equal(cache.load("s1"), null);
42
+ });
43
+
44
+ test("capacity evicts the oldest session", () => {
45
+ const cache = new SessionMessagesCache(2);
46
+ cache.save("s1", [message("a")]);
47
+ cache.save("s2", [message("b")]);
48
+ cache.save("s3", [message("c")]);
49
+
50
+ assert.equal(cache.load("s1"), null);
51
+ assert.ok(cache.load("s2"));
52
+ assert.ok(cache.load("s3"));
53
+ });
54
+
55
+ test("save ignores empty message lists", () => {
56
+ const cache = new SessionMessagesCache();
57
+ cache.save("s1", []);
58
+ assert.equal(cache.size, 0);
59
+ });
@@ -0,0 +1,44 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { buildPromptWithVaultContext } from "../src/context/vault-context";
4
+
5
+ test("buildPromptWithVaultContext includes vault rules and active note", () => {
6
+ const prompt = buildPromptWithVaultContext({
7
+ userText: "Summarize this",
8
+ activePath: "wiki/design/AI应用.md",
9
+ selection: "",
10
+ includeActiveNote: true,
11
+ includeSelection: true,
12
+ });
13
+
14
+ assert.match(prompt, /Summarize this/);
15
+ assert.match(prompt, /Active note: wiki\/design\/AI应用\.md/);
16
+ assert.match(prompt, /raw\/ is immutable/);
17
+ assert.match(prompt, /wiki\/ is agent-maintained/);
18
+ });
19
+
20
+ test("buildPromptWithVaultContext includes selected text when enabled", () => {
21
+ const prompt = buildPromptWithVaultContext({
22
+ userText: "Improve wording",
23
+ activePath: "wiki/design/AI应用.md",
24
+ selection: "selected paragraph",
25
+ includeActiveNote: true,
26
+ includeSelection: true,
27
+ });
28
+
29
+ assert.match(prompt, /Selected text:/);
30
+ assert.match(prompt, /selected paragraph/);
31
+ });
32
+
33
+ test("buildPromptWithVaultContext includes the configured CatUI personality", () => {
34
+ const prompt = buildPromptWithVaultContext({
35
+ userText: "Summarize this",
36
+ activePath: null,
37
+ selection: "",
38
+ includeActiveNote: false,
39
+ includeSelection: false,
40
+ personality: "vex",
41
+ });
42
+
43
+ assert.match(prompt, /CatUI personality: vex/);
44
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "inlineSourceMap": true,
5
+ "inlineSources": true,
6
+ "jsx": "react-jsx",
7
+ "lib": ["DOM", "ES2022"],
8
+ "module": "ESNext",
9
+ "moduleResolution": "Bundler",
10
+ "skipLibCheck": true,
11
+ "noImplicitAny": true,
12
+ "strict": true,
13
+ "target": "ES2022",
14
+ "types": ["node"]
15
+ },
16
+ "include": ["src/**/*.ts", "test/**/*.ts"]
17
+ }