diff options
| -rw-r--r-- | .opencode/plugins/superpowers.js | 12 | ||||
| -rw-r--r-- | tests/opencode/test-session-bootstrap.mjs | 10 |
2 files changed, 18 insertions, 4 deletions
diff --git a/.opencode/plugins/superpowers.js b/.opencode/plugins/superpowers.js index 9eff811..50e123f 100644 --- a/.opencode/plugins/superpowers.js +++ b/.opencode/plugins/superpowers.js @@ -112,6 +112,11 @@ Use OpenCode's native \`skill\` tool to list and load skills.`; // regex work on every agent step. See #1202 for the full analysis. const _bootstrapCache = new Map(); // mapping -> bootstrap (null = file missing) +// Opening of every injected bootstrap part. The already-injected guards match +// it at the start of a part, so a prompt that merely mentions the tag (#2197) +// is not mistaken for the bootstrap. +const BOOTSTRAP_MARKER = '<EXTREMELY_IMPORTANT>\nYou have superpowers.'; + // Helper to generate bootstrap content (cached after first call per mapping) const getBootstrapContent = (toolMapping) => { // Return cached result on subsequent calls @@ -127,8 +132,7 @@ const getBootstrapContent = (toolMapping) => { const fullContent = fs.readFileSync(skillPath, 'utf8'); const { content } = extractAndStripFrontmatter(fullContent); - _bootstrapCache.set(toolMapping, `<EXTREMELY_IMPORTANT> -You have superpowers. + _bootstrapCache.set(toolMapping, `${BOOTSTRAP_MARKER} **IMPORTANT: The using-superpowers skill content is included below. It is ALREADY LOADED - you are currently following it. Do NOT use the skill tool to load "using-superpowers" again - that would be redundant.** @@ -248,7 +252,7 @@ export const SuperpowersPlugin = async ({ client, directory }) => { if (!firstUser || !firstUser.parts.length) return; // Guard: skip if first user message already contains bootstrap. - if (firstUser.parts.some(p => p.type === 'text' && p.text.includes('EXTREMELY_IMPORTANT'))) return; + if (firstUser.parts.some(p => p.type === 'text' && p.text.startsWith(BOOTSTRAP_MARKER))) return; // #2160: never restart the controller workflow inside task subagent // (child) sessions. V1 passes no input to this hook (verified in the @@ -342,7 +346,7 @@ async function setup(ctx) { if (!bootstrap || !event.messages || !event.messages.length) return; const firstUser = event.messages.find(m => m.role === 'user'); if (firstUser && (!firstUser.content || !firstUser.content.length)) return; - if (firstUser?.content.some(p => p.type === 'text' && p.text && p.text.includes('EXTREMELY_IMPORTANT'))) return; + if (firstUser?.content.some(p => p.type === 'text' && p.text && p.text.startsWith(BOOTSTRAP_MARKER))) return; // #2160: the context event carries the sessionID directly. Skip the // controller bootstrap when this prompt belongs to a task subagent diff --git a/tests/opencode/test-session-bootstrap.mjs b/tests/opencode/test-session-bootstrap.mjs index 31658d5..67b3118 100644 --- a/tests/opencode/test-session-bootstrap.mjs +++ b/tests/opencode/test-session-bootstrap.mjs @@ -139,6 +139,16 @@ for (const flavor of ['v1', 'v2']) { await unknown.invoke(noID); assert.equal(bootstrapCount(noID), 1); assert.deepEqual(unknown.lookups, []); + + // #2197: a prompt that merely mentions the bootstrap's tag is not the bootstrap. + const mentions = await makeHarness(flavor, (id) => reply(flavor, { id })); + const probe = makeEvent(flavor, `${flavor}-mentions-tag`); + (probe.messages[0].parts ?? probe.messages[0].content)[0].text = + "Is there an 'EXTREMELY_IMPORTANT' block in your context?"; + await mentions.invoke(probe); + assert.equal(bootstrapCount(probe), 1, `${flavor}: prompt mentioning the tag still gets bootstrap`); + await mentions.invoke(probe); + assert.equal(bootstrapCount(probe), 1, `${flavor}: prompt mentioning the tag, repeated event`); } function compactedEvent(sessionID) { |
