Question
I'm trying to give OpenCode the ability to compact "itself":
plugin/compact.ts:
import type { Plugin } from "@opencode-ai/plugin"
import { tool } from "@opencode-ai/plugin"
export const CompactPlugin: Plugin = async ({ client }) => {
// 'client' here is the SDK client connected to THIS server instance
return {
tool: {
compact: tool({
description: "Compact the current session to reduce token usage. Use this after having EXPLICITLY been instructed to write a <plan>.md file.",
args: {
reason: tool.schema.string().optional().describe("Optional reason for compacting"),
},
async execute(args, context) {
// client is captured from the plugin closure
// It knows which server/port to talk to!
try {
const res = await client.session.summarize({
path: { id: context.sessionID },
body: {
providerID: "zai-coding-plan",
modelID: "glm-4.6",
}
});
console.warn(`Session ${context.sessionID} compacted successfully. Result: ${JSON.stringify(res)}`);
return args.reason
? `Session compacted successfully. Reason: ${args.reason}`
: "Session compacted successfully";
} catch (error) {
return `Failed to compact session: ${error}`;
}
},
}),
},
};
};
It shows as summarizing in the UI:
But hangs forever in this state (no matter which valid provider/model combination I try).
Any clues?
Question
I'm trying to give OpenCode the ability to compact "itself":
plugin/compact.ts:
It shows as summarizing in the UI:
But hangs forever in this state (no matter which valid provider/model combination I try).
Any clues?