Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .opencode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,8 @@ selection, and its subagents inherit the invoking primary agent's model.
## License

MIT

Home-target installations keep `plugins/index.ts` inert even with hooks enabled.
OpenCode automatically loads `plugins/ecc-hooks.ts`; loading the barrel as well
would initialize every ECC hook twice. The source and published package barrel
remain available for module imports.
19 changes: 12 additions & 7 deletions scripts/lib/install/hook-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ function withoutOpenCodeHookActivation(operation) {
};
}

function transformOpenCodeHookActivationOperations(operations) {
return (Array.isArray(operations) ? operations : []).map(withoutOpenCodeHookActivation);
}

function planSelectsHookRuntime(plan = {}) {
return (
Array.isArray(plan.selectedModuleIds)
Expand All @@ -189,17 +185,26 @@ function planSelectsHookRuntime(plan = {}) {
}

function disableUnselectedOpenCodeHooks(plan) {
if (plan.target !== 'opencode' || planSelectsHookRuntime(plan)) {
if (plan.target !== 'opencode') {
return plan;
}
const runtimeSelected = planSelectsHookRuntime(plan);
const transformOperations = operations => (Array.isArray(operations) ? operations : []).map(operation => {
// The source barrel is needed by the published package, but OpenCode scans
// plugins/index.ts and plugins/ecc-hooks.ts independently in home installs.
if (!runtimeSelected || normalizeOperationPath(operation.sourceRelativePath) === '.opencode/plugins/index.ts') {
return withoutOpenCodeHookActivation(operation);
}
return operation;
});

return {
...plan,
operations: transformOpenCodeHookActivationOperations(plan.operations),
operations: transformOperations(plan.operations),
statePreview: plan.statePreview
? {
...plan.statePreview,
operations: transformOpenCodeHookActivationOperations(plan.statePreview.operations),
operations: transformOperations(plan.statePreview.operations),
}
: plan.statePreview,
};
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/hook-consent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ function runTests() {
const pending = withHookConsent(selected, null);
assert.throws(() => assertHookConsentReady(pending), /automatic hook runtime/);
const enabled = withHookConsent(selected, 'enabled');
assert.ok(enabled.operations.every(operation => operation.contentTransform === undefined));
for (const operation of [...enabled.operations, ...enabled.statePreview.operations]) {
assert.strictEqual(operation.contentTransform, operation.sourceRelativePath.endsWith('/index.ts') ? 'opencode-disable-plugin-entrypoint' : undefined);
}
assert.doesNotThrow(() => assertHookConsentReady(enabled));
const declined = withHookConsent(selected, 'declined');
assert.strictEqual(declined.operations.length, 2);
Expand Down
6 changes: 5 additions & 1 deletion tests/lib/install-executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,9 +990,13 @@ function runTests() {
for (const name of OPENCODE_ENTRYPOINTS) {
assert.strictEqual(
fs.readFileSync(path.join(homeDir, '.config', 'opencode', 'plugins', name), 'utf8'),
fs.readFileSync(path.join(REPO_ROOT, '.opencode', 'plugins', name), 'utf8')
name === 'index.ts' ? INERT_OPENCODE_PLUGIN : fs.readFileSync(path.join(REPO_ROOT, '.opencode', 'plugins', name), 'utf8')
);
}
assert.strictEqual(
enabledPlan.statePreview.operations.find(operation => operation.sourceRelativePath.split(path.sep).join('/') === '.opencode/plugins/index.ts').contentTransform,
'opencode-disable-plugin-entrypoint'
);
applyInstallPlanDirect(declinedPlan);
const declinedState = JSON.parse(fs.readFileSync(declinedPlan.installStatePath, 'utf8'));
assert.strictEqual(declinedState.request.hookConsent, 'declined');
Expand Down