opencode-claude-memory 1.7.7 → 2.0.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.
Files changed (69) hide show
  1. package/README.md +104 -214
  2. package/dist/agents.d.ts +12 -0
  3. package/dist/agents.js +69 -0
  4. package/dist/config.d.ts +112 -0
  5. package/dist/config.js +79 -0
  6. package/dist/extraction/ExtractionCoordinator.d.ts +62 -0
  7. package/dist/extraction/ExtractionCoordinator.js +386 -0
  8. package/dist/extraction/autodream.d.ts +33 -0
  9. package/dist/extraction/autodream.js +85 -0
  10. package/dist/extraction/forkSession.d.ts +37 -0
  11. package/dist/extraction/forkSession.js +133 -0
  12. package/dist/extraction/lock.d.ts +29 -0
  13. package/dist/extraction/lock.js +191 -0
  14. package/dist/extraction/prompts.d.ts +5 -0
  15. package/dist/extraction/prompts.js +78 -0
  16. package/dist/extraction/state.d.ts +38 -0
  17. package/dist/extraction/state.js +159 -0
  18. package/dist/hooks/ignore.d.ts +6 -0
  19. package/dist/hooks/ignore.js +53 -0
  20. package/dist/hooks/messages.d.ts +14 -0
  21. package/dist/hooks/messages.js +96 -0
  22. package/dist/index.d.ts +7 -1
  23. package/dist/index.js +50 -665
  24. package/dist/prompt/sections.d.ts +7 -0
  25. package/dist/{prompt.js → prompt/sections.js} +16 -72
  26. package/dist/prompt/systemPrompt.d.ts +7 -0
  27. package/dist/prompt/systemPrompt.js +64 -0
  28. package/dist/recall/RecallCoordinator.d.ts +36 -0
  29. package/dist/recall/RecallCoordinator.js +140 -0
  30. package/dist/recall/format.d.ts +17 -0
  31. package/dist/{recall.js → recall/format.js} +13 -36
  32. package/dist/{recallSelector.d.ts → recall/selector.d.ts} +26 -16
  33. package/dist/recall/selector.js +92 -0
  34. package/dist/sdk.d.ts +12 -0
  35. package/dist/sdk.js +8 -0
  36. package/dist/store/MemoryStore.d.ts +41 -0
  37. package/dist/store/MemoryStore.js +105 -0
  38. package/dist/store/frontmatter.d.ts +25 -0
  39. package/dist/store/frontmatter.js +61 -0
  40. package/dist/store/indexFile.d.ts +15 -0
  41. package/dist/store/indexFile.js +153 -0
  42. package/dist/{paths.d.ts → store/paths.d.ts} +7 -6
  43. package/dist/store/paths.js +187 -0
  44. package/dist/store/scan.d.ts +29 -0
  45. package/dist/store/scan.js +112 -0
  46. package/dist/tools.d.ts +9 -0
  47. package/dist/tools.js +142 -0
  48. package/dist/util/exclusiveFile.d.ts +11 -0
  49. package/dist/util/exclusiveFile.js +108 -0
  50. package/dist/util/legacyShellHook.d.ts +3 -0
  51. package/dist/util/legacyShellHook.js +23 -0
  52. package/dist/util/log.d.ts +6 -0
  53. package/dist/util/log.js +29 -0
  54. package/dist/util/ownedSessions.d.ts +7 -0
  55. package/dist/util/ownedSessions.js +39 -0
  56. package/dist/util/timeout.d.ts +5 -0
  57. package/dist/util/timeout.js +39 -0
  58. package/package.json +15 -8
  59. package/bin/opencode-memory +0 -1436
  60. package/dist/memory.d.ts +0 -31
  61. package/dist/memory.js +0 -224
  62. package/dist/memoryScan.d.ts +0 -20
  63. package/dist/memoryScan.js +0 -106
  64. package/dist/nativeExtraction.d.ts +0 -9
  65. package/dist/nativeExtraction.js +0 -80
  66. package/dist/paths.js +0 -141
  67. package/dist/prompt.d.ts +0 -4
  68. package/dist/recall.d.ts +0 -12
  69. package/dist/recallSelector.js +0 -154
@@ -1,154 +0,0 @@
1
- import { formatMemoryManifest } from "./memoryScan.js";
2
- export const SELECT_MEMORIES_SYSTEM_PROMPT = `You are selecting memories that will be useful to OpenCode as it processes a user's query. You will be given the user's query and a list of available memory files with their filenames and descriptions.
3
-
4
- Return a list of filenames for the memories that will clearly be useful to OpenCode as it processes the user's query (up to 5). Only include memories that you are certain will be helpful based on their name and description.
5
- - If you are unsure if a memory will be useful in processing the user's query, then do not include it in your list. Be selective and discerning.
6
- - If there are no memories in the list that would clearly be useful, feel free to return an empty list.
7
- - If a list of recently-used tools is provided, do not select memories that are usage reference or API documentation for those tools (OpenCode is already exercising them). DO still select memories containing warnings, gotchas, or known issues about those tools — active use is exactly when those matter.
8
- `;
9
- const SELECT_MEMORIES_FORMAT = {
10
- type: "json_schema",
11
- schema: {
12
- type: "object",
13
- properties: {
14
- selected_memories: { type: "array", items: { type: "string" } },
15
- },
16
- required: ["selected_memories"],
17
- additionalProperties: false,
18
- },
19
- };
20
- export const UNSUPPORTED_RECALL_SELECTOR_CLIENT_MESSAGE = "opencode-claude-memory LLM recall requires an OpenCode SDK session client with create/prompt/delete support.";
21
- function unwrapData(response) {
22
- if (!response || typeof response !== "object")
23
- return response;
24
- if ("data" in response)
25
- return response.data;
26
- return response;
27
- }
28
- function extractSessionID(response) {
29
- const data = unwrapData(response);
30
- if (!data || typeof data !== "object")
31
- return undefined;
32
- const id = data.id ?? data.sessionID;
33
- return typeof id === "string" ? id : undefined;
34
- }
35
- function tryParseSelectedMemories(raw) {
36
- try {
37
- const parsed = JSON.parse(raw);
38
- if (!Array.isArray(parsed.selected_memories))
39
- return undefined;
40
- return parsed.selected_memories.filter((item) => typeof item === "string");
41
- }
42
- catch {
43
- return undefined;
44
- }
45
- }
46
- function extractSelectedMemories(response) {
47
- const data = unwrapData(response);
48
- if (!data || typeof data !== "object")
49
- return [];
50
- const structured = data.info?.structured;
51
- if (structured && typeof structured === "object") {
52
- const selected = structured.selected_memories;
53
- if (Array.isArray(selected)) {
54
- return selected.filter((item) => typeof item === "string");
55
- }
56
- }
57
- const parts = data.parts;
58
- if (!Array.isArray(parts))
59
- return [];
60
- for (const part of parts) {
61
- if (!part || typeof part !== "object")
62
- continue;
63
- const text = part.text;
64
- if (typeof text !== "string")
65
- continue;
66
- const parsed = tryParseSelectedMemories(text);
67
- if (parsed)
68
- return parsed;
69
- }
70
- return [];
71
- }
72
- export function isSupportedRecallSelectorClient(client) {
73
- const session = client?.session;
74
- return Boolean(typeof session?.create === "function" &&
75
- typeof session.prompt === "function" &&
76
- typeof session.delete === "function");
77
- }
78
- export function assertSupportedRecallSelectorClient(client) {
79
- if (!isSupportedRecallSelectorClient(client)) {
80
- throw new Error(UNSUPPORTED_RECALL_SELECTOR_CLIENT_MESSAGE);
81
- }
82
- }
83
- async function createSelectorSession(client, directory, parentSessionID) {
84
- if (!client.session?.create)
85
- return undefined;
86
- const response = await client.session.create({
87
- body: {
88
- parentID: parentSessionID,
89
- title: "opencode-memory recall selector",
90
- },
91
- query: { directory },
92
- });
93
- return extractSessionID(response);
94
- }
95
- async function promptSelectorSession(client, sessionID, directory, agent, model, content) {
96
- if (!client.session?.prompt)
97
- return undefined;
98
- const body = {
99
- agent,
100
- ...(model ? { model } : {}),
101
- tools: {},
102
- system: SELECT_MEMORIES_SYSTEM_PROMPT,
103
- format: SELECT_MEMORIES_FORMAT,
104
- parts: [{ type: "text", text: content }],
105
- };
106
- return client.session.prompt({
107
- path: { id: sessionID },
108
- query: { directory },
109
- body,
110
- });
111
- }
112
- async function deleteSelectorSession(client, sessionID, directory) {
113
- if (!client.session?.delete)
114
- return;
115
- try {
116
- await client.session.delete({
117
- path: { id: sessionID },
118
- query: { directory },
119
- });
120
- }
121
- catch {
122
- // Best-effort cleanup. A failed selector deletion should not affect recall.
123
- }
124
- }
125
- export async function selectRelevantMemoryFilenames(input) {
126
- if (input.memories.length === 0)
127
- return [];
128
- assertSupportedRecallSelectorClient(input.client);
129
- let selectorSessionID;
130
- try {
131
- selectorSessionID = await createSelectorSession(input.client, input.directory, input.parentSessionID);
132
- if (!selectorSessionID)
133
- return [];
134
- input.selectorSessionIDs.add(selectorSessionID);
135
- const toolsSection = input.recentTools.length > 0
136
- ? `\n\nRecently used tools: ${input.recentTools.join(", ")}`
137
- : "";
138
- const manifest = formatMemoryManifest(input.memories);
139
- const response = await promptSelectorSession(input.client, selectorSessionID, input.directory, input.agent, input.model, `Query: ${input.query}\n\nAvailable memories:\n${manifest}${toolsSection}`);
140
- const validFilenames = new Set(input.memories.map((memory) => memory.filename));
141
- return extractSelectedMemories(response)
142
- .filter((filename) => validFilenames.has(filename))
143
- .slice(0, 5);
144
- }
145
- catch {
146
- return [];
147
- }
148
- finally {
149
- if (selectorSessionID) {
150
- input.selectorSessionIDs.delete(selectorSessionID);
151
- await deleteSelectorSession(input.client, selectorSessionID, input.directory);
152
- }
153
- }
154
- }