@codemem/opencode-plugin 0.50.0-beta.1 → 0.50.0-beta.2
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.
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
148
|
"name": "memory_search_index",
|
|
149
|
-
"description": "Keyword-search memories when you know exact terms or identifiers. Returns compact entries
|
|
149
|
+
"description": "Keyword-search memories when you know exact terms or identifiers. Returns compact entries without bodies: IDs, clipped titles, and widening labels when present. Expand selected IDs with memory_get or memory_get_observations.",
|
|
150
150
|
"input": {
|
|
151
151
|
"type": "object",
|
|
152
152
|
"properties": {
|
|
@@ -1204,7 +1204,7 @@
|
|
|
1204
1204
|
},
|
|
1205
1205
|
{
|
|
1206
1206
|
"name": "memory_get_observations",
|
|
1207
|
-
"description": "Fetch multiple memories by exact IDs. Does not inherit the default project. Missing or filtered-out IDs are omitted
|
|
1207
|
+
"description": "Fetch multiple memories by exact IDs. Returns full rows by default. Use compact for full body text without metadata. Does not inherit the default project. Missing or filtered-out IDs are omitted.",
|
|
1208
1208
|
"input": {
|
|
1209
1209
|
"type": "object",
|
|
1210
1210
|
"properties": {
|
|
@@ -1216,6 +1216,10 @@
|
|
|
1216
1216
|
"maxItems": 200,
|
|
1217
1217
|
"description": "Memory IDs to fetch"
|
|
1218
1218
|
},
|
|
1219
|
+
"compact": {
|
|
1220
|
+
"type": "boolean",
|
|
1221
|
+
"description": "Return only id, kind, title, body_text, and project"
|
|
1222
|
+
},
|
|
1219
1223
|
"kind": {
|
|
1220
1224
|
"type": "string",
|
|
1221
1225
|
"description": "Filter by memory kind"
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isMemoryToolId,
|
|
9
9
|
MEMORY_TOOL_NAMESPACE,
|
|
10
10
|
MEMORY_TOOL_NAMESPACE_DESCRIPTION,
|
|
11
|
+
memoryToolId,
|
|
11
12
|
} from "./memory-tools.js";
|
|
12
13
|
import { addCallerToPooledMcpTools, createCallSequence } from "./pooled-mcp-caller.js";
|
|
13
14
|
import { createCodememRuntime } from "./runtime.js";
|
|
@@ -22,6 +23,10 @@ const FAILED_TOOL_ERROR = Object.freeze({
|
|
|
22
23
|
const CODEMEM_CONTEXT_PART_ID_PREFIX = "codemem-context-";
|
|
23
24
|
const CODEMEM_RECALL_METADATA_VERSION = 1;
|
|
24
25
|
const CODEMEM_V2_PART_METADATA_KEY = "codememPart";
|
|
26
|
+
const PINNED_RETRIEVAL_IDS = new Set([
|
|
27
|
+
memoryToolId("memory_search_index"),
|
|
28
|
+
memoryToolId("memory_get_observations"),
|
|
29
|
+
]);
|
|
25
30
|
|
|
26
31
|
const asRecord = (value) =>
|
|
27
32
|
value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -345,6 +350,10 @@ export const translateV2Event = (event) => createV2EventTranslator().translate(e
|
|
|
345
350
|
export const translateV2ToolResult = (input) => {
|
|
346
351
|
const failed = input?.status === "error";
|
|
347
352
|
const result = asRecord(input?.result);
|
|
353
|
+
const nestedCalls = asRecord(result.metadata).toolCalls;
|
|
354
|
+
const executionWrapper = input?.tool === "execute" && Array.isArray(nestedCalls);
|
|
355
|
+
const containsMemoryCalls = executionWrapper
|
|
356
|
+
&& nestedCalls.some((call) => isMemoryToolId(call?.tool));
|
|
348
357
|
let output = null;
|
|
349
358
|
if (!failed) output = result.output ?? result.content ?? input?.result ?? null;
|
|
350
359
|
return {
|
|
@@ -353,6 +362,10 @@ export const translateV2ToolResult = (input) => {
|
|
|
353
362
|
sessionID: typeof input?.sessionID === "string" ? input.sessionID : null,
|
|
354
363
|
tool: typeof input?.tool === "string" ? input.tool : "unknown",
|
|
355
364
|
args: asRecord(input?.input),
|
|
365
|
+
...(typeof input?.codemode === "boolean" ? { codemode: input.codemode } : {}),
|
|
366
|
+
...(typeof input?.messageID === "string" ? { messageID: input.messageID } : {}),
|
|
367
|
+
...(executionWrapper ? { executionWrapper } : {}),
|
|
368
|
+
...(containsMemoryCalls ? { containsMemoryCalls } : {}),
|
|
356
369
|
},
|
|
357
370
|
output: {
|
|
358
371
|
output,
|
|
@@ -432,6 +445,26 @@ const addV2MemoryTools = (editor, memoryTools, options) => {
|
|
|
432
445
|
}
|
|
433
446
|
};
|
|
434
447
|
|
|
448
|
+
const supportsRetrievalPins = (version) => {
|
|
449
|
+
const match = /^v?2\.(\d+)\.(\d+)(?:\+.+)?$/.exec(version ?? "");
|
|
450
|
+
if (!match) return false;
|
|
451
|
+
const [, minor, patch] = match;
|
|
452
|
+
return Number(minor) > 4 || (Number(minor) === 4 && Number(patch) >= 1);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
export const pinV2RetrievalCatalog = (editor, version) => {
|
|
456
|
+
if (!supportsRetrievalPins(version)) return;
|
|
457
|
+
if (typeof editor.list !== "function" || typeof editor.update !== "function") return;
|
|
458
|
+
for (const tool of editor.list()) {
|
|
459
|
+
if (!PINNED_RETRIEVAL_IDS.has(tool.id) || tool.options?.namespace !== MEMORY_TOOL_NAMESPACE) continue;
|
|
460
|
+
if (tool.options.codemode === false) continue;
|
|
461
|
+
editor.update(tool.id, (target) => {
|
|
462
|
+
const options = target.options;
|
|
463
|
+
target.options = { ...options, codemode: { ...asRecord(options.codemode), pinned: true } };
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
435
468
|
const isV2CodememMcpConfigured = async (context) => {
|
|
436
469
|
const response = await context.mcp.list();
|
|
437
470
|
if (!Array.isArray(response?.data)) throw new TypeError("MCP server list unavailable");
|
|
@@ -493,6 +526,7 @@ const registerV2Tools = async (context, runtime, isActive) => {
|
|
|
493
526
|
directory: context.location.directory,
|
|
494
527
|
isActive,
|
|
495
528
|
});
|
|
529
|
+
pinV2RetrievalCatalog(editor, context.app?.version);
|
|
496
530
|
});
|
|
497
531
|
return mcpObserver ? [tools, mcpObserver] : [tools];
|
|
498
532
|
};
|
package/.opencode/lib/runtime.js
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
|
|
39
39
|
const TRUTHY_VALUES = ["1", "true", "yes"];
|
|
40
40
|
const DISABLED_VALUES = ["0", "false", "off"];
|
|
41
|
-
const PINNED_BACKEND_VERSION = "0.50.0-beta.
|
|
41
|
+
const PINNED_BACKEND_VERSION = "0.50.0-beta.2";
|
|
42
42
|
const COMPAT_CHECK_DELAY_MS = 1500;
|
|
43
43
|
const COMPAT_CHECK_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
44
44
|
const MAX_UPDATE_STATUS_BYTES = 16 * 1024;
|
|
@@ -1854,6 +1854,29 @@ const mapOpencodeEventTypeToAdapterType = (eventType) => {
|
|
|
1854
1854
|
return null;
|
|
1855
1855
|
};
|
|
1856
1856
|
|
|
1857
|
+
const toolCaptureMetadata = (event) => ({
|
|
1858
|
+
...(typeof event.codemode === "boolean" ? { codemode: event.codemode } : {}),
|
|
1859
|
+
...(event.message_id ? { message_id: event.message_id } : {}),
|
|
1860
|
+
...(event.execution_wrapper ? { execution_wrapper: true } : {}),
|
|
1861
|
+
...(event.contains_memory_calls ? { contains_memory_calls: true } : {}),
|
|
1862
|
+
});
|
|
1863
|
+
|
|
1864
|
+
const buildToolCaptureEvent = (input, output, serialize) => ({
|
|
1865
|
+
type: "tool.execute.after",
|
|
1866
|
+
tool: input.tool,
|
|
1867
|
+
args: input.args ?? {},
|
|
1868
|
+
result: output.error ? null : serialize(output.output),
|
|
1869
|
+
error: output.error ? serialize(output.error) : null,
|
|
1870
|
+
...(input.id ? { tool_call_id: String(input.id) } : {}),
|
|
1871
|
+
...toolCaptureMetadata({
|
|
1872
|
+
codemode: input.codemode,
|
|
1873
|
+
message_id: input.messageID,
|
|
1874
|
+
execution_wrapper: input.executionWrapper,
|
|
1875
|
+
contains_memory_calls: input.containsMemoryCalls,
|
|
1876
|
+
}),
|
|
1877
|
+
timestamp: new Date().toISOString(),
|
|
1878
|
+
});
|
|
1879
|
+
|
|
1857
1880
|
const buildOpencodeAdapterPayload = (event) => {
|
|
1858
1881
|
const eventType = event?.type;
|
|
1859
1882
|
if (eventType === "user_prompt") {
|
|
@@ -1889,6 +1912,7 @@ const buildOpencodeAdapterPayload = (event) => {
|
|
|
1889
1912
|
tool_output: event?.result ?? null,
|
|
1890
1913
|
error: event?.error ?? null,
|
|
1891
1914
|
...(toolCallID ? { tool_call_id: toolCallID } : {}),
|
|
1915
|
+
...toolCaptureMetadata(event),
|
|
1892
1916
|
};
|
|
1893
1917
|
}
|
|
1894
1918
|
|
|
@@ -1921,6 +1945,10 @@ const sanitizeIdPart = (value, fallback, maxChars) => {
|
|
|
1921
1945
|
const buildAdapterEventId = ({ sessionID, eventType, event, payload, ts }) => {
|
|
1922
1946
|
const safeSessionID = sanitizeIdPart(sessionID, "unknown", 48);
|
|
1923
1947
|
const safeType = sanitizeIdPart(eventType, "event", 24);
|
|
1948
|
+
if (typeof event.codemode === "boolean" && event.tool_call_id && eventType === "tool_result") {
|
|
1949
|
+
const digest = stableDigest([sessionID, event.message_id ?? null, event.tool_call_id]);
|
|
1950
|
+
return `oc:${safeSessionID}:${safeType}:${digest}`;
|
|
1951
|
+
}
|
|
1924
1952
|
const rawTimestamp =
|
|
1925
1953
|
typeof event?.timestamp === "string" && event.timestamp.trim()
|
|
1926
1954
|
? event.timestamp.trim()
|
|
@@ -3937,6 +3965,7 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
3937
3965
|
return String(value);
|
|
3938
3966
|
}
|
|
3939
3967
|
};
|
|
3968
|
+
const serializeToolCapture = (value) => truncate(safeStringify(value));
|
|
3940
3969
|
|
|
3941
3970
|
const trimRetainedEvents = (retainedEvents) => {
|
|
3942
3971
|
trimEventQueue({
|
|
@@ -4755,14 +4784,11 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
4755
4784
|
if (sessionID) await capturePendingPrompts({ sessionID });
|
|
4756
4785
|
if (!runtimeActive) return;
|
|
4757
4786
|
const args = input.args ?? {};
|
|
4758
|
-
const result = output.output;
|
|
4759
|
-
const error = output.error ?? null;
|
|
4760
4787
|
const toolName = input.tool;
|
|
4761
|
-
const toolCallID = input.id ?? null;
|
|
4762
4788
|
|
|
4763
4789
|
// Update activity and session context
|
|
4764
4790
|
updateActivity();
|
|
4765
|
-
sessionContext.toolCount++;
|
|
4791
|
+
if (!input.executionWrapper) sessionContext.toolCount++;
|
|
4766
4792
|
|
|
4767
4793
|
// Track files from tool events
|
|
4768
4794
|
const filePath = args.filePath || args.path;
|
|
@@ -4781,15 +4807,7 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
4781
4807
|
}
|
|
4782
4808
|
}
|
|
4783
4809
|
|
|
4784
|
-
captureCodememEvent(input.sessionID,
|
|
4785
|
-
type: "tool.execute.after",
|
|
4786
|
-
tool: toolName,
|
|
4787
|
-
args,
|
|
4788
|
-
result: error ? null : truncate(safeStringify(result)),
|
|
4789
|
-
error: error ? truncate(safeStringify(error)) : null,
|
|
4790
|
-
...(toolCallID ? { tool_call_id: String(toolCallID) } : {}),
|
|
4791
|
-
timestamp: new Date().toISOString(),
|
|
4792
|
-
});
|
|
4810
|
+
captureCodememEvent(input.sessionID, buildToolCaptureEvent(input, output, serializeToolCapture));
|
|
4793
4811
|
await logLine(`tool.execute.after ${toolName} queued=${events.length} tools=${sessionContext.toolCount}`);
|
|
4794
4812
|
|
|
4795
4813
|
// Check if we should force flush due to threshold
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemem/opencode-plugin",
|
|
3
|
-
"version": "0.50.0-beta.
|
|
3
|
+
"version": "0.50.0-beta.2",
|
|
4
4
|
"description": "Codemem plugin for OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/parser": "8.1.0",
|
|
43
43
|
"@opencode/cli": "2.0.24",
|
|
44
44
|
"@types/node": "^24.12.4",
|
|
45
|
-
"codemem": "^0.50.0-beta.
|
|
45
|
+
"codemem": "^0.50.0-beta.2",
|
|
46
46
|
"vitest": "^4.1.11"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|