@codemem/opencode-plugin 0.49.1 → 0.50.0-beta.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.
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
MEMORY_TOOL_NAMESPACE,
|
|
10
10
|
MEMORY_TOOL_NAMESPACE_DESCRIPTION,
|
|
11
11
|
} from "./memory-tools.js";
|
|
12
|
+
import { addCallerToPooledMcpTools, createCallSequence } from "./pooled-mcp-caller.js";
|
|
12
13
|
import { createCodememRuntime } from "./runtime.js";
|
|
13
14
|
import { registerV2NotificationBridge } from "./v2-notification-bridge.js";
|
|
14
15
|
import { readV2SessionOwnership } from "./v2-session-location.js";
|
|
@@ -478,8 +479,11 @@ const registerV2Tools = async (context, runtime, isActive) => {
|
|
|
478
479
|
const mcpObserver = memoryTools
|
|
479
480
|
? await observeV2McpPrecedence(context, memoryTools, gate, isActive)
|
|
480
481
|
: null;
|
|
482
|
+
const nextSequence = createCallSequence();
|
|
481
483
|
const tools = await context.tool.transform((editor) => {
|
|
482
484
|
if (!isActive()) return;
|
|
485
|
+
// A shared codemem MCP server needs this instance's directory on each call.
|
|
486
|
+
addCallerToPooledMcpTools(editor, { directory: context.location.directory, nextSequence });
|
|
483
487
|
for (const [name, definition] of Object.entries(runtime.tools)) {
|
|
484
488
|
editor.add(createV2Tool(name, definition, { isActive }));
|
|
485
489
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caller context for a codemem MCP server that several project directories
|
|
3
|
+
* share (OpenCode `pool: true`). A shared server has one fixed working
|
|
4
|
+
* directory, so it started with `--caller-context required` and declares a
|
|
5
|
+
* `_codemem_caller` argument on every tool. This module fills that argument
|
|
6
|
+
* in from the plugin instance that runs the call and hides it from the model.
|
|
7
|
+
* Tools that do not declare the argument are left alone, so a private
|
|
8
|
+
* per-project server is unaffected. So are tools of any other MCP server: the
|
|
9
|
+
* argument carries the project path and session ID, which only the server
|
|
10
|
+
* configured under the name `codemem` should receive.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
|
|
15
|
+
export const CALLER_ARGUMENT = "_codemem_caller";
|
|
16
|
+
const CODEMEM_SERVER = "codemem";
|
|
17
|
+
|
|
18
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
19
|
+
|
|
20
|
+
// The host reports an MCP tool's server name as its namespace. Tool IDs are
|
|
21
|
+
// not enough: a server named `codemem_other` produces IDs with the same prefix.
|
|
22
|
+
const declaresCaller = (tool) =>
|
|
23
|
+
tool?.options?.namespace === CODEMEM_SERVER
|
|
24
|
+
&& isObject(tool.input?.properties)
|
|
25
|
+
&& CALLER_ARGUMENT in tool.input.properties;
|
|
26
|
+
|
|
27
|
+
const cleanProject = (value) => (typeof value === "string" && value.trim() ? value.trim() : null);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Inner calls of one Code Mode block share the block's call ID, so a sequence
|
|
31
|
+
* number keeps each call distinct. The per-instance nonce keeps a provider
|
|
32
|
+
* that reuses call IDs from repeating an identity after the plugin reloads.
|
|
33
|
+
* A redelivery of one dispatched call keeps the value it was dispatched with.
|
|
34
|
+
*/
|
|
35
|
+
export const createCallSequence = (nonce = randomUUID().slice(0, 8)) => {
|
|
36
|
+
let next = 0;
|
|
37
|
+
return () => {
|
|
38
|
+
next += 1;
|
|
39
|
+
return `${nonce}:${next}`;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {{ list(): readonly object[], update(id: string, update: (tool: any) => void): void }} editor
|
|
45
|
+
* @param {{ directory: string, nextSequence: () => string, readEnvProject?: () => unknown }} options
|
|
46
|
+
* @returns {string[]} IDs of the tools that now receive the caller argument.
|
|
47
|
+
*/
|
|
48
|
+
export const addCallerToPooledMcpTools = (editor, options) => {
|
|
49
|
+
const { directory, nextSequence, readEnvProject = () => process.env.CODEMEM_PROJECT } = options;
|
|
50
|
+
// Hosts whose tool editor cannot list or update tools have no pooling either.
|
|
51
|
+
if (typeof editor.list !== "function" || typeof editor.update !== "function") return [];
|
|
52
|
+
const pooled = editor.list().filter(declaresCaller);
|
|
53
|
+
for (const tool of pooled) {
|
|
54
|
+
editor.update(tool.id, (target) => {
|
|
55
|
+
const { [CALLER_ARGUMENT]: _hidden, ...properties } = target.input.properties;
|
|
56
|
+
target.input = { ...target.input, properties };
|
|
57
|
+
const execute = target.execute;
|
|
58
|
+
// The plugin's value always replaces one that arrived with the call.
|
|
59
|
+
target.execute = (input, context) => execute({
|
|
60
|
+
...input,
|
|
61
|
+
[CALLER_ARGUMENT]: {
|
|
62
|
+
directory,
|
|
63
|
+
env_project: cleanProject(readEnvProject()),
|
|
64
|
+
session_id: context.sessionID,
|
|
65
|
+
request_id: `${context.id}:${nextSequence()}`,
|
|
66
|
+
},
|
|
67
|
+
}, context);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return pooled.map((tool) => tool.id);
|
|
71
|
+
};
|
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.
|
|
41
|
+
const PINNED_BACKEND_VERSION = "0.50.0-beta.1";
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemem/opencode-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.50.0-beta.1",
|
|
4
|
+
"description": "Codemem plugin for OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"types": "./index.d.ts",
|
|
@@ -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.
|
|
45
|
+
"codemem": "^0.50.0-beta.1",
|
|
46
46
|
"vitest": "^4.1.11"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|