diff --git a/.opencode/plugins/ecc-hooks.ts b/.opencode/plugins/ecc-hooks.ts index 86eaa7cdf..00b0ca76c 100644 --- a/.opencode/plugins/ecc-hooks.ts +++ b/.opencode/plugins/ecc-hooks.ts @@ -639,6 +639,10 @@ export const ECCHooksPlugin: ECCHooksPluginFn = async ({ * Action: Sets PROJECT_ROOT, PACKAGE_MANAGER, DETECTED_LANGUAGES, ECC_VERSION */ "shell.env": async (_input: { cwd: string }, output: { env: Record }) => { + // OpenCode may invoke this hook with no output object. Dereferencing + // output.env unconditionally below throws and aborts the shell environment + // hook, so bail out early instead (#3934). + if (!output) return const env: Record = { ECC_VERSION: getECCVersion(eccRoot), ECC_PLUGIN: "true", @@ -744,9 +748,11 @@ export const ECCHooksPlugin: ECCHooksPluginFn = async ({ ] // OpenCode requires output assignment and skips context when a prompt is set. - if (output.prompt !== undefined) { + // Guard against a missing output object so a hook invocation that omits it + // no-ops instead of throwing and aborting compaction (#3934). + if (output && output.prompt !== undefined) { output.prompt = [output.prompt, ...eccContext].join("\n\n") - } else { + } else if (output) { output.context = [...output.context, ...eccContext] } }, diff --git a/tests/opencode-plugin-hooks.test.js b/tests/opencode-plugin-hooks.test.js index dc3dcee23..b2a863933 100644 --- a/tests/opencode-plugin-hooks.test.js +++ b/tests/opencode-plugin-hooks.test.js @@ -347,6 +347,22 @@ async function main() { } }, ], + [ + "shell.env no-ops instead of throwing when the host omits the output object", + async () => withTempProject([], async (projectDir) => { + const client = createClient() + const $ = createFailingShell() + const hooks = await ECCHooksPlugin({ client, $, directory: projectDir }) + + // OpenCode may invoke the hook with no output object; the previous + // implementation dereferenced output.env unconditionally and aborted + // the shell environment hook with TypeError: undefined is not an + // object (#3934). + await hooks["shell.env"]({ cwd: projectDir }, undefined) + + assert.deepStrictEqual($.calls, [], "Expected no shell probes") + }), + ], [ "compacting appends ECC context without replacing the host compaction prompt", async () => withTempProject([], async (projectDir) => { @@ -388,6 +404,21 @@ async function main() { assert.deepStrictEqual($.calls, []) }), ], + [ + "compacting no-ops instead of throwing when the host omits the output object", + async () => withTempProject([], async (projectDir) => { + const client = createClient() + const $ = createFailingShell() + const hooks = await ECCHooksPlugin({ client, $, directory: projectDir }) + + // OpenCode may invoke the hook with no output object; the previous + // implementation dereferenced output.prompt unconditionally and aborted + // compaction with TypeError: undefined is not an object (#3934). + await hooks["experimental.session.compacting"]({ sessionID: "session-1" }, undefined) + + assert.deepStrictEqual($.calls, [], "Expected no shell probes") + }), + ], [ "permission.ask handles read-only tools correctly", async () => withTempProject(