Add iai-mcp-session-init plugin for automatic memory loading in OpenCode
This commit is contained in:
parent
ebe7ebf17a
commit
31a69186a3
2 changed files with 68 additions and 7 deletions
40
deploy/opencode/iai-mcp-session-init.js
Normal file
40
deploy/opencode/iai-mcp-session-init.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* iai-mcp session-init plugin for OpenCode.
|
||||
*
|
||||
* Sets the system prompt via chat.message hook's UserMessage.system field.
|
||||
* This reaches the main agent and triggers memory_session_context on every session.
|
||||
*/
|
||||
|
||||
export const IaiMcpSessionInit = async ({
|
||||
client,
|
||||
project,
|
||||
directory,
|
||||
worktree,
|
||||
experimental_workspace,
|
||||
serverUrl,
|
||||
$,
|
||||
}) => {
|
||||
const injectedSessions = new Set();
|
||||
|
||||
return {
|
||||
event: async ({ event }) => {
|
||||
if (event.type !== "session.updated") return;
|
||||
const sid = event.properties?.info?.id;
|
||||
if (!sid || injectedSessions.has(sid)) return;
|
||||
injectedSessions.add(sid);
|
||||
},
|
||||
|
||||
"chat.message": async (input, output) => {
|
||||
const sid = input.sessionID;
|
||||
if (!sid || !injectedSessions.has(sid)) return;
|
||||
if (injectedSessions.has(`done-${sid}`)) return;
|
||||
|
||||
if (output.message) {
|
||||
output.message.system =
|
||||
"MANDATORY: Call `memory_session_context` (no arguments) BEFORE answering any user query.";
|
||||
}
|
||||
|
||||
injectedSessions.add(`done-${sid}`);
|
||||
},
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue