Skip to content

Commit 487cd74

Browse files
authored
fix(opencode): register the ruleset on the compaction hook (#1086) (#1089)
1 parent f8e7ad4 commit 487cd74

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎.opencode/plugins/ponytail.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,15 @@ export default {
132132

133133
// Append the ruleset to the system prompt every turn. V2 hands over owned
134134
// system parts, so push one instead of rewriting the tail of another.
135-
await ctx.session.hook('context', (event) => {
135+
// Summary compaction runs its own hook with the same event shape; without
136+
// it the compaction request misses the ruleset and the provider prompt cache.
137+
const addRuleset = (event) => {
136138
const mode = readMode();
137139
if (mode === 'off') return;
138140
event.system.push({ type: 'text', text: getPonytailInstructions(mode) });
139-
});
141+
};
142+
await ctx.session.hook('context', addRuleset);
143+
await ctx.session.hook('compaction', addRuleset);
140144
},
141145

142146
// OpenCode V1: same three behaviors, as hooks on the V1 hook names.

‎tests/opencode-plugin.test.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ test('V2 context hook injects the ruleset, and stays silent when off', async ()
136136
assert.deepEqual(quiet.system, []);
137137
});
138138

139+
test('V2 compaction hook injects the same ruleset as context, and stays silent when off (#1086)', async () => {
140+
try { fs.unlinkSync(statePath); } catch (e) {}
141+
let { hooks } = await setupV2();
142+
const fromContext = { system: [] };
143+
const fromCompaction = { system: [] };
144+
await hooks.context(fromContext);
145+
await hooks.compaction(fromCompaction);
146+
assert.equal(fromCompaction.system.length, 1);
147+
assert.deepEqual(fromCompaction.system, fromContext.system);
148+
149+
fs.writeFileSync(statePath, 'off');
150+
({ hooks } = await setupV2());
151+
const quiet = { system: [] };
152+
await hooks.compaction(quiet);
153+
assert.deepEqual(quiet.system, []);
154+
});
155+
139156
test('V2 unsupported /ponytail arguments do not reset the current mode', async () => {
140157
const { added } = await setupV2();
141158
fs.writeFileSync(statePath, 'ultra');

0 commit comments

Comments
 (0)