@ghilteras/opencode-agent-memory 0.5.0 → 0.5.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.
- package/README.md +5 -4
- package/package.json +1 -1
- package/src/journal.ts +0 -18
- package/src/plugin-disabled.test.ts +53 -0
- package/src/plugin.test.ts +11 -36
- package/src/plugin.ts +1 -14
- package/src/tools.test.ts +167 -0
- package/src/tools.ts +14 -5
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Think of it as a searchable sidecar to `AGENTS.md`. OpenCode supports [rules](ht
|
|
|
19
19
|
- **Append-only journal** - Entries survive across sessions and context compaction
|
|
20
20
|
- **Local semantic search** - Find entries by meaning, not just keywords
|
|
21
21
|
- **Metadata on every entry** - Project, model, provider, agent, session, timestamp, tags
|
|
22
|
-
- **
|
|
22
|
+
- **Guidance in tool descriptions** - Journal usage guidance lives in the descriptions of the journal tools, so an agent sees it only when it is allowed to call them
|
|
23
23
|
- **No data leaves the machine** - Embeddings run locally
|
|
24
24
|
|
|
25
25
|
## Requirements
|
|
@@ -50,7 +50,7 @@ The journal is **opt-in**. Enable it in `~/.config/opencode/agent-memory.json`:
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
With the journal disabled the plugin registers **no tools
|
|
53
|
+
With the journal disabled the plugin registers **no tools**.
|
|
54
54
|
|
|
55
55
|
### Tools
|
|
56
56
|
|
|
@@ -101,7 +101,7 @@ Tags are free-form strings - the agent can use any tag, not just the suggested o
|
|
|
101
101
|
}
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
Suggested
|
|
104
|
+
Suggested tag **names** (not their descriptions) appear in the `journal_write` tool description as guidance.
|
|
105
105
|
|
|
106
106
|
### cacheDir
|
|
107
107
|
|
|
@@ -126,8 +126,9 @@ Existing `~/.config/opencode/memory/` and `.opencode/memory/` directories are **
|
|
|
126
126
|
|
|
127
127
|
- **Requires OpenCode v1.0.115+.**
|
|
128
128
|
- **Restart after config changes.** Plugin config changes require a full OpenCode restart to take effect; editing the config file alone is not sufficient.
|
|
129
|
-
- **Journal is opt-in.** You must explicitly enable it in `~/.config/opencode/agent-memory.json`; with it disabled the plugin registers no tools
|
|
129
|
+
- **Journal is opt-in.** You must explicitly enable it in `~/.config/opencode/agent-memory.json`; with it disabled the plugin registers no tools.
|
|
130
130
|
- **Local embeddings, no data leaves the machine.** Semantic search uses a locally cached transformers.js model; no external API calls are made for search or embedding.
|
|
131
|
+
- **Known limitation (0.5.1): guidance-in-descriptions depends on an unverified premise.** 0.5.1 moved journal guidance from the injected system-prompt note into the three journal tool descriptions, so only agents allowed to call those tools should see it. That relies on opencode omitting a permission-denied tool from the definitions sent to the model. This is **unverified**: a `tool.definition` probe on the isolated instance fires before permission filtering, so it cannot confirm what the model actually receives. If the premise does not hold, an agent denied `journal_*` may still read the description text; `deny` still blocks execution, so there is no capability escalation and no data disclosure — the blast radius is the three tools' description strings.
|
|
131
132
|
|
|
132
133
|
## Inspiration
|
|
133
134
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghilteras/opencode-agent-memory",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Journal-only memory plugin for OpenCode: tagged, searchable, append-only journal with semantic search.",
|
|
5
5
|
"author": "Angelo Pantano <ghilteras@protonmail.com>",
|
|
6
6
|
"license": "MIT",
|
package/src/journal.ts
CHANGED
|
@@ -452,21 +452,3 @@ export function createJournalStore(configDir?: string, cacheDir?: string): Journ
|
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
454
|
|
|
455
|
-
export function buildJournalSystemNote(
|
|
456
|
-
tags?: readonly JournalTag[],
|
|
457
|
-
): string {
|
|
458
|
-
const tagSection =
|
|
459
|
-
tags && tags.length > 0
|
|
460
|
-
? `\n\nSuggested tags:\n${tags.map((t) => `- ${t.name}: ${t.description}`).join("\n")}`
|
|
461
|
-
: "";
|
|
462
|
-
|
|
463
|
-
return `<journal_instructions>
|
|
464
|
-
You have access to a private journal. Use it to record thoughts, discoveries, and decisions as you work.
|
|
465
|
-
Tags are free-form strings — use them to classify entries however makes sense.${tagSection}
|
|
466
|
-
|
|
467
|
-
Before starting complex tasks, search the journal for relevant past context.
|
|
468
|
-
Journal entries are append-only: you write new entries but never edit old ones.
|
|
469
|
-
Use journal_search to find past entries semantically, and journal_read to read a specific entry.
|
|
470
|
-
The journal is global across all projects but each entry records which project it was written from.
|
|
471
|
-
</journal_instructions>`;
|
|
472
|
-
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
// Mock journal module with journal DISABLED — the control path.
|
|
4
|
+
mock.module("./journal", () => ({
|
|
5
|
+
loadConfig: async () => ({
|
|
6
|
+
journal: { enabled: false },
|
|
7
|
+
}),
|
|
8
|
+
createJournalStore: () => ({}),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
// Mock embeddings to avoid model download
|
|
12
|
+
mock.module("./embeddings", () => ({
|
|
13
|
+
warmupEmbedder: async () => {},
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
import { MemoryPlugin } from "./plugin";
|
|
17
|
+
import type { PluginInput } from "@opencode-ai/plugin";
|
|
18
|
+
|
|
19
|
+
const stubInput = { directory: "/tmp/test-plugin-disabled" } as unknown as PluginInput;
|
|
20
|
+
|
|
21
|
+
describe("plugin disabled path", () => {
|
|
22
|
+
test("registers zero tools when journal is disabled", async () => {
|
|
23
|
+
const plugin = await MemoryPlugin(stubInput);
|
|
24
|
+
// tool should be undefined or an empty object
|
|
25
|
+
if (plugin.tool) {
|
|
26
|
+
expect(Object.keys(plugin.tool)).toHaveLength(0);
|
|
27
|
+
} else {
|
|
28
|
+
expect(plugin.tool).toBeUndefined();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("produces no guidance text when disabled", async () => {
|
|
33
|
+
const plugin = await MemoryPlugin(stubInput);
|
|
34
|
+
// There should be no system transform hook injecting guidance
|
|
35
|
+
expect(plugin["experimental.chat.system.transform"]).toBeUndefined();
|
|
36
|
+
// Tool definitions (if any exist as empty object) must not contain
|
|
37
|
+
// any description with journal guidance keywords
|
|
38
|
+
if (plugin.tool) {
|
|
39
|
+
for (const def of Object.values(plugin.tool)) {
|
|
40
|
+
const desc = (def as { description?: string }).description ?? "";
|
|
41
|
+
expect(desc).not.toMatch(/append-only|journal|search.*entry/i);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("chat.message hook is still present when disabled", async () => {
|
|
47
|
+
const plugin = await MemoryPlugin(stubInput);
|
|
48
|
+
// The chat.message hook updates model/provider context — it should
|
|
49
|
+
// still be present even when journal is disabled.
|
|
50
|
+
expect(plugin["chat.message"]).toBeDefined();
|
|
51
|
+
expect(typeof plugin["chat.message"]).toBe("function");
|
|
52
|
+
});
|
|
53
|
+
});
|
package/src/plugin.test.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { describe, expect, mock, test } from "bun:test";
|
|
2
2
|
|
|
3
3
|
// Mock journal module so we don't hit the real filesystem for config/journal
|
|
4
|
-
const JOURNAL_NOTE = `<journal_instructions>
|
|
5
|
-
You have access to a private journal.
|
|
6
|
-
</journal_instructions>`;
|
|
7
|
-
|
|
8
4
|
mock.module("./journal", () => ({
|
|
9
5
|
loadConfig: async () => ({
|
|
10
6
|
journal: { enabled: true },
|
|
11
7
|
}),
|
|
12
8
|
createJournalStore: () => ({}),
|
|
13
|
-
buildJournalSystemNote: () => JOURNAL_NOTE,
|
|
14
9
|
}));
|
|
15
10
|
|
|
16
11
|
// Mock embeddings to avoid model download
|
|
@@ -24,43 +19,23 @@ import type { PluginInput } from "@opencode-ai/plugin";
|
|
|
24
19
|
// Minimal stub: the plugin only reads `directory` from the input.
|
|
25
20
|
const stubInput = { directory: "/tmp/test-plugin-regression" } as unknown as PluginInput;
|
|
26
21
|
|
|
27
|
-
describe("plugin
|
|
28
|
-
test("
|
|
22
|
+
describe("plugin structure", () => {
|
|
23
|
+
test("returns chat.message hook", async () => {
|
|
29
24
|
const plugin = await MemoryPlugin(stubInput);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
expect(transform).toBeDefined();
|
|
33
|
-
|
|
34
|
-
const output = { system: [] as string[] };
|
|
35
|
-
// The chat.message hook expects a model param; the transform hook does not use it.
|
|
36
|
-
// Pass a minimal mock for the transform signature.
|
|
37
|
-
await (transform as Function)({}, output);
|
|
38
|
-
|
|
39
|
-
// The journal note MUST be present — this is the core regression check.
|
|
40
|
-
// With the old early-return (`if (!xml) return;`), when renderMemoryBlocks
|
|
41
|
-
// returned "" (no blocks), the entire transform returned before pushing
|
|
42
|
-
// journalSystemNote, silently disabling the journal.
|
|
43
|
-
expect(output.system).toContain(JOURNAL_NOTE);
|
|
25
|
+
expect(plugin["chat.message"]).toBeDefined();
|
|
26
|
+
expect(typeof plugin["chat.message"]).toBe("function");
|
|
44
27
|
});
|
|
45
28
|
|
|
46
|
-
test("
|
|
29
|
+
test("does NOT return experimental.chat.system.transform hook", async () => {
|
|
47
30
|
const plugin = await MemoryPlugin(stubInput);
|
|
48
|
-
|
|
49
|
-
const transform = plugin["experimental.chat.system.transform"];
|
|
50
|
-
const output = { system: [] as string[] };
|
|
51
|
-
await (transform as Function)({}, output);
|
|
52
|
-
|
|
53
|
-
const count = output.system.filter((s) => s === JOURNAL_NOTE).length;
|
|
54
|
-
expect(count).toBe(1);
|
|
31
|
+
expect(plugin["experimental.chat.system.transform"]).toBeUndefined();
|
|
55
32
|
});
|
|
56
33
|
|
|
57
|
-
test("
|
|
34
|
+
test("registers journal tools when enabled", async () => {
|
|
58
35
|
const plugin = await MemoryPlugin(stubInput);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expect(output.system.length).toBeGreaterThan(0);
|
|
36
|
+
expect(plugin.tool).toBeDefined();
|
|
37
|
+
expect(plugin.tool!["journal_write"]).toBeDefined();
|
|
38
|
+
expect(plugin.tool!["journal_read"]).toBeDefined();
|
|
39
|
+
expect(plugin.tool!["journal_search"]).toBeDefined();
|
|
65
40
|
});
|
|
66
41
|
});
|
package/src/plugin.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Plugin, ToolDefinition } from "@opencode-ai/plugin";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
buildJournalSystemNote,
|
|
5
4
|
createJournalStore,
|
|
6
5
|
loadConfig,
|
|
7
6
|
} from "./journal";
|
|
@@ -26,7 +25,6 @@ export const MemoryPlugin: Plugin = async ({ directory }) => {
|
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
let journalTools: Record<string, ToolDefinition> = {};
|
|
29
|
-
let journalSystemNote = "";
|
|
30
28
|
|
|
31
29
|
if (journalEnabled) {
|
|
32
30
|
const journalStore = createJournalStore(undefined, config.cacheDir);
|
|
@@ -34,11 +32,10 @@ export const MemoryPlugin: Plugin = async ({ directory }) => {
|
|
|
34
32
|
// first-init-wins singleton caches to the correct directory.
|
|
35
33
|
void warmupEmbedder(config.cacheDir).catch(() => {});
|
|
36
34
|
journalTools = {
|
|
37
|
-
journal_write: JournalWrite(journalStore, journalCtx),
|
|
35
|
+
journal_write: JournalWrite(journalStore, journalCtx, config.journal?.tags),
|
|
38
36
|
journal_read: JournalRead(journalStore),
|
|
39
37
|
journal_search: JournalSearch(journalStore),
|
|
40
38
|
};
|
|
41
|
-
journalSystemNote = buildJournalSystemNote(config.journal?.tags);
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
return {
|
|
@@ -49,16 +46,6 @@ export const MemoryPlugin: Plugin = async ({ directory }) => {
|
|
|
49
46
|
}
|
|
50
47
|
},
|
|
51
48
|
|
|
52
|
-
"experimental.chat.system.transform": async (_input, output) => {
|
|
53
|
-
// Inject journal instructions unconditionally when enabled.
|
|
54
|
-
// Previous versions returned early when no memory blocks were present,
|
|
55
|
-
// which also skipped the journal note — a regression-class bug that
|
|
56
|
-
// silently disabled the journal entirely once blocks were removed.
|
|
57
|
-
if (journalSystemNote) {
|
|
58
|
-
output.system.push(journalSystemNote);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
|
|
62
49
|
tool: {
|
|
63
50
|
...journalTools,
|
|
64
51
|
},
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { JournalRead, JournalSearch, JournalWrite } from "./tools";
|
|
4
|
+
import type { JournalContext } from "./tools";
|
|
5
|
+
import type { JournalStore, JournalTag } from "./journal";
|
|
6
|
+
|
|
7
|
+
// Minimal mock store — tests only check description strings, not execute.
|
|
8
|
+
const mockStore: JournalStore = {
|
|
9
|
+
write: async () => {
|
|
10
|
+
throw new Error("not implemented");
|
|
11
|
+
},
|
|
12
|
+
read: async () => {
|
|
13
|
+
throw new Error("not implemented");
|
|
14
|
+
},
|
|
15
|
+
search: async () => {
|
|
16
|
+
throw new Error("not implemented");
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const mockCtx: JournalContext = {
|
|
21
|
+
directory: "/tmp/test",
|
|
22
|
+
model: "test-model",
|
|
23
|
+
provider: "test-provider",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// ─── Tool description tests ───────────────────────────────────────────────
|
|
27
|
+
// These assert semantic properties of the description strings: that guidance
|
|
28
|
+
// content is present, that stale/hallucinated text is absent, and that structural
|
|
29
|
+
// invariants hold. They use substring/regex assertions, so intra-sentence
|
|
30
|
+
// rewording is tolerated; only content-level regressions trip them.
|
|
31
|
+
|
|
32
|
+
const WRITE_DESC_NO_TAGS = JournalWrite(mockStore, mockCtx).description;
|
|
33
|
+
const WRITE_DESC_WITH_TAGS = JournalWrite(mockStore, mockCtx, [
|
|
34
|
+
{ name: "perf", description: "Performance optimization" },
|
|
35
|
+
{ name: "debug", description: "Debugging sessions" },
|
|
36
|
+
]).description;
|
|
37
|
+
const READ_DESC = JournalRead(mockStore).description;
|
|
38
|
+
const SEARCH_TOOL = JournalSearch(mockStore);
|
|
39
|
+
const SEARCH_DESC = SEARCH_TOOL.description;
|
|
40
|
+
|
|
41
|
+
describe("journal_write description", () => {
|
|
42
|
+
test("mentions append-only semantics", () => {
|
|
43
|
+
expect(WRITE_DESC_NO_TAGS).toContain("append-only");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("explains that entries cannot be edited", () => {
|
|
47
|
+
expect(WRITE_DESC_NO_TAGS).toMatch(/never edit|cannot be (edited|modified)/i);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("documents tag format", () => {
|
|
51
|
+
expect(WRITE_DESC_NO_TAGS).toMatch(/tags/i);
|
|
52
|
+
expect(WRITE_DESC_NO_TAGS).toMatch(/comma.separated/i);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("contains no dynamic or timestamped content", () => {
|
|
56
|
+
// A static description must not embed a date or ISO timestamp
|
|
57
|
+
expect(WRITE_DESC_NO_TAGS).not.toMatch(/\d{4}-\d{2}-\d{2}T/);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("mentions the journal is for recording insights", () => {
|
|
61
|
+
expect(WRITE_DESC_NO_TAGS).toMatch(/insight|discovery|decision|observation/i);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("does not include suggested tags when none provided", () => {
|
|
65
|
+
expect(WRITE_DESC_NO_TAGS).not.toMatch(/suggested tags/i);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("includes suggested tags when provided", () => {
|
|
69
|
+
expect(WRITE_DESC_WITH_TAGS).toMatch(/suggested tags/i);
|
|
70
|
+
expect(WRITE_DESC_WITH_TAGS).toContain("perf");
|
|
71
|
+
expect(WRITE_DESC_WITH_TAGS).toContain("debug");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("suggested tags are tag names only, not descriptions", () => {
|
|
75
|
+
expect(WRITE_DESC_WITH_TAGS).toContain("perf");
|
|
76
|
+
expect(WRITE_DESC_WITH_TAGS).toContain("debug");
|
|
77
|
+
// Tag descriptions should NOT appear in the tool description
|
|
78
|
+
expect(WRITE_DESC_WITH_TAGS).not.toContain("Performance optimization");
|
|
79
|
+
expect(WRITE_DESC_WITH_TAGS).not.toContain("Debugging sessions");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("journal_read description", () => {
|
|
84
|
+
test("mentions reading a specific entry by ID", () => {
|
|
85
|
+
expect(READ_DESC).toMatch(/by.*ID/i);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("does not contain write-only guidance", () => {
|
|
89
|
+
// Write-scoping guidance (append-only, cannot be edited) belongs only in
|
|
90
|
+
// journal_write's description. An agent with read-but-not-write would
|
|
91
|
+
// see this guidance without the ability to act on it.
|
|
92
|
+
expect(READ_DESC).not.toMatch(/append.only|cannot be (edited|modified)/i);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("contains no dynamic or timestamped content", () => {
|
|
96
|
+
expect(READ_DESC).not.toMatch(/\d{4}-\d{2}-\d{2}T/);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("journal_search description", () => {
|
|
101
|
+
test("mentions searching semantically", () => {
|
|
102
|
+
expect(SEARCH_DESC).toMatch(/semantic|similarity|meaning/i);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("mentions that filters can be combined", () => {
|
|
106
|
+
expect(SEARCH_DESC).toMatch(/filter/i);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("documents the project filter argument", () => {
|
|
110
|
+
// The project filter is documented via the tool's args schema, not the
|
|
111
|
+
// description prose. Assert the arg exists so a schema regression is caught.
|
|
112
|
+
expect(SEARCH_TOOL.args).toBeDefined();
|
|
113
|
+
expect(SEARCH_TOOL.args!.project).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("mentions pagination (offset)", () => {
|
|
117
|
+
expect(SEARCH_DESC).toMatch(/offset|paginate/i);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("mentions the journal is global across projects", () => {
|
|
121
|
+
expect(SEARCH_DESC).toMatch(/global.*project|across.*project/i);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("advises searching before complex tasks", () => {
|
|
125
|
+
expect(SEARCH_DESC).toMatch(/complex task|before start/i);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("contains no dynamic or timestamped content", () => {
|
|
129
|
+
expect(SEARCH_DESC).not.toMatch(/\d{4}-\d{2}-\d{2}T/);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ─── Cross-tool invariants ───────────────────────────────────────────────────
|
|
134
|
+
|
|
135
|
+
describe("cross-tool invariants", () => {
|
|
136
|
+
test("no description mentions another journal tool by name", () => {
|
|
137
|
+
const toolNames = ["journal_search", "journal_read", "journal_write"];
|
|
138
|
+
for (const name of toolNames) {
|
|
139
|
+
const desc =
|
|
140
|
+
name === "journal_write"
|
|
141
|
+
? WRITE_DESC_NO_TAGS
|
|
142
|
+
: name === "journal_read"
|
|
143
|
+
? READ_DESC
|
|
144
|
+
: SEARCH_DESC;
|
|
145
|
+
const others = toolNames.filter((n) => n !== name);
|
|
146
|
+
for (const other of others) {
|
|
147
|
+
expect(desc).not.toContain(other);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("all descriptions are non-empty strings", () => {
|
|
153
|
+
expect(typeof WRITE_DESC_NO_TAGS).toBe("string");
|
|
154
|
+
expect(WRITE_DESC_NO_TAGS.length).toBeGreaterThan(0);
|
|
155
|
+
expect(typeof READ_DESC).toBe("string");
|
|
156
|
+
expect(READ_DESC.length).toBeGreaterThan(0);
|
|
157
|
+
expect(typeof SEARCH_DESC).toBe("string");
|
|
158
|
+
expect(SEARCH_DESC.length).toBeGreaterThan(0);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("no description contains the retired invitation phrase", () => {
|
|
162
|
+
const retired = "record thoughts, discoveries, and decisions as you work";
|
|
163
|
+
expect(WRITE_DESC_NO_TAGS).not.toContain(retired);
|
|
164
|
+
expect(READ_DESC).not.toContain(retired);
|
|
165
|
+
expect(SEARCH_DESC).not.toContain(retired);
|
|
166
|
+
});
|
|
167
|
+
});
|
package/src/tools.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tool } from "@opencode-ai/plugin";
|
|
2
2
|
|
|
3
|
-
import type { JournalStore } from "./journal";
|
|
3
|
+
import type { JournalStore, JournalTag } from "./journal";
|
|
4
4
|
|
|
5
5
|
export type JournalContext = {
|
|
6
6
|
directory: string;
|
|
@@ -11,12 +11,19 @@ export type JournalContext = {
|
|
|
11
11
|
export function JournalWrite(
|
|
12
12
|
store: JournalStore,
|
|
13
13
|
ctx: JournalContext,
|
|
14
|
+
tags?: readonly JournalTag[],
|
|
14
15
|
) {
|
|
16
|
+
const suggestedTags =
|
|
17
|
+
tags && tags.length > 0
|
|
18
|
+
? ` Suggested tags: ${tags.map((t) => t.name).join(", ")}.`
|
|
19
|
+
: "";
|
|
15
20
|
return tool({
|
|
16
21
|
description:
|
|
17
|
-
"Write a new journal entry. Use this to capture insights, technical discoveries, " +
|
|
18
|
-
"design decisions, observations, or reflections.
|
|
19
|
-
"
|
|
22
|
+
"Write a new append-only journal entry. Use this to capture insights, technical discoveries, " +
|
|
23
|
+
"design decisions, observations, or reflections. " +
|
|
24
|
+
"Entries are append-only: you write new entries but never edit old ones. " +
|
|
25
|
+
"Tags are optional comma-separated names, e.g. \"perf, debugging\"." +
|
|
26
|
+
suggestedTags,
|
|
20
27
|
args: {
|
|
21
28
|
title: tool.schema.string(),
|
|
22
29
|
body: tool.schema.string(),
|
|
@@ -82,7 +89,9 @@ export function JournalSearch(store: JournalStore) {
|
|
|
82
89
|
description:
|
|
83
90
|
"Search journal entries using semantic similarity. Returns matching entries " +
|
|
84
91
|
"sorted by relevance. All filters are optional and combined with AND logic. " +
|
|
85
|
-
"Use with no arguments to list recent entries. Use offset to paginate."
|
|
92
|
+
"Use with no arguments to list recent entries. Use offset to paginate. " +
|
|
93
|
+
"Before starting complex tasks, search the journal for relevant past context. " +
|
|
94
|
+
"The journal is global across all projects but each entry records which project it was written from.",
|
|
86
95
|
args: {
|
|
87
96
|
text: tool.schema.string().optional(),
|
|
88
97
|
project: tool.schema.string().optional(),
|