iai-mcp-opencode/deploy/opencode/iai-mcp-session-init.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* @deprecated Use `iai-mcp-memory-inject.js` instead.
*
* This plugin forces a tool call via a phantom "INIT" user turn, which
* corrupts session title generation. The memory-inject plugin uses the
* system.transform hook to inject memory directly into the system prompt
* no phantom turn, clean titles, memory visible every turn.
*
* Retained temporarily for backward compatibility. Will be removed in a
* future release. Migrate to iai-mcp-memory-inject.js:
*
* cp deploy/opencode/iai-mcp-memory-inject.js ~/.config/opencode/plugins/
*
* Then replace this plugin reference in ~/.config/opencode/config.json.
*/
export const IaiMcpSessionInit = async ({
client,
project,
directory,
worktree,
experimental_workspace,
serverUrl,
$,
}) => {
const doneSessions = new Set();
return {
event: async ({ event }) => {
if (event.type !== "session.updated") return;
const sid = event.properties?.info?.id;
if (!sid || doneSessions.has(sid)) return;
doneSessions.add(sid);
try {
await client.session.prompt({
path: { id: sid },
body: {
system: "MANDATORY: Call `memory_session_context` (no arguments) BEFORE answering any user query.",
parts: [{ type: "text", text: "INIT" }],
noReply: false,
},
});
} catch {}
},
};
};