mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 13:32:18 +00:00
fix(opencode): guard hooks against undefined output to prevent compaction crash
The shell.env and experimental.session.compacting hooks dereferenced output.env and output.prompt unconditionally. When OpenCode invokes a hook without an output object, this threw TypeError: undefined is not an object and aborted compaction entirely. - shell.env: early-return when output is undefined - experimental.session.compacting: guard the output.prompt/output.context branches so a missing output no-ops instead of throwing Add regression tests for both hooks covering the undefined-output case. Fixes #3934
This commit is contained in:
1 parent
d2ef268059
commit
9ce5cd92e7
2 files changed
+39
-2
No files matched your search
@@ -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<string, string> }) => {
|
||||
// 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<string, string> = {
|
||||
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]
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user