fix(opencode): address round-2 review findings on the hooks surface

- R2-1: the V2 execute.after adapter passed { result: ... } as the tool
  output; skill-run-tracker derives outcomes from error fields on the
  response itself, so failed skills recorded as successes. The adapter
  now forwards the raw event.result ?? event.output. Covered by a T05
  assertion that an is_error skill event records outcome failure and a
  clean event still records success.
- R2-2: cmd.exe expands %VAR% and honors embedded quotes even inside
  double quotes, so escaping " was unsafe. spawnCommand now refuses
  arguments carrying ", %, CR or LF (nothing spawns; the rejection
  surfaces through the formatter's catch) and emits the canonical /s
  form with one outer quote pair around the whole command. T01 asserts
  the outer pair, strips it before inspecting the inner quoting, and
  covers two refusal payloads.
- R2-3: repo review rules ban console.log; the client-less log fallback
  and the startup line now use console.info (identical stdout behavior).
- R2-4: declined installs recorded before the barrel split retained the
  old module/factory stub in plugins/index.ts, and a later selective
  install (e.g. commands-core) has no operation rewriting it, so the
  strict deactivation gate failed the install after all writes landed.
  The strict branch now migrates such retained files in place only when
  ownership is proven twice (managed-recorded contentSha256 matches disk
  AND disk equals an exact historical disabled-stub payload), written
  through writeFileNoFollow with that digest as expectedContent;
  anything else keeps failing closed. The preflight branch accepts an
  already-inactive recorded config under the same digest-verified
  condition, since selective installs legitimately plan no .opencode
  writes. New lifecycle test covers both the migration (install ok,
  doctor clean, ownership retained) and the refusal path (mis-recorded
  digest never grants a rewrite).
This commit is contained in:
MohammadAminDHM committed 2026-11-03 20:13:58 +03:30
1 parent 6286b7c2f1
commit 76f8ea4bd3
5 files changed
+234 -10

No files matched your search

+36 -2
View File
@@ -14,6 +14,7 @@ const {
parseJsoncConfig,
getDisabledOpenCodePluginContent,
isInertOpenCodePluginStub,
isLegacyDisabledOpenCodePluginStub,
isOpenCodeHookConfigRegistration,
getRecordedHookConsent,
getOpenCodeActivationPathKind,
@@ -538,7 +539,35 @@ function assertOpenCodeHookDeactivationReady(plan, options = {}) {
const digest = content === null ? null : crypto.createHash('sha256').update(content).digest('hex');
snapshot.set(key, digest);
if (content === null) continue;
const inactive = activationIsInactive(kind, operation, content, options.requireInactive);
let inactive = activationIsInactive(kind, operation, content, options.requireInactive);
if (options.requireInactive && !inactive && kind === 'plugin') {
// R2-4 (review 4456945413): installs that declined hooks before the
// barrel split wrote the module stub (or the older factory stub) to
// EVERY plugin file, the barrel included. This selective plan has no
// operation that would rewrite the retained file, so the strict gate
// would fail the install after all writes landed. Migrate it in place
// — ownership is proven twice: install-state records the file as
// managed AND its bytes still match a historical disabled-stub payload
// exactly, so no user edit can be lost. Anything else keeps failing.
const recorded = previous.get(key);
if (recorded
&& typeof recorded.contentSha256 === 'string'
&& recorded.contentSha256 === digest
&& isLegacyDisabledOpenCodePluginStub(content)) {
const current = getDisabledOpenCodePluginContent(operation.sourceRelativePath);
writeFileNoFollow(operation.destinationPath, current, {
expectedContent: { kind: 'sha256', digest },
action: 'migrate legacy OpenCode plugin stub',
validateDestination(destinationPath) {
assertSafeInstallOperation(plan, { destinationPath });
assertSafeClaudeSkillOperation(plan, { destinationPath });
return destinationPath;
},
});
snapshot.set(key, crypto.createHash('sha256').update(current).digest('hex'));
inactive = activationIsInactive(kind, operation, current, true);
}
}
if (options.requireInactive) {
if (!inactive) {
throw new Error(`OpenCode hook activation remains active at ${operation.destinationPath}`);
@@ -546,7 +575,12 @@ function assertOpenCodeHookDeactivationReady(plan, options = {}) {
continue;
}
const recorded = previous.get(key);
if (inactive && (kind === 'plugin' || options.allowVerifiedLegacyRemoval || !recorded)) continue;
// R2-4: a recorded config that already parses as inactive needs no
// replacement operation when its bytes still match the managed digest —
// selective installs (e.g. commands-core) legitimately plan no .opencode
// writes at all. Unverifiable or modified records keep refusing.
if (inactive && (kind === 'plugin' || options.allowVerifiedLegacyRemoval || !recorded
|| (typeof recorded.contentSha256 === 'string' && recorded.contentSha256 === digest))) continue;
if (options.allowVerifiedLegacyRemoval && recorded) {
const verified = verifyManagedLegacyFile(recorded, {
targetRoot: plan.targetRoot, installStatePath: plan.installStatePath,
+12
View File
@@ -233,6 +233,17 @@ function isInertOpenCodePluginStub(content) {
|| text === LEGACY_DISABLED_OPENCODE_PLUGIN_CONTENT;
}
// Exact historical disabled-entrypoint payloads that earlier ECC releases
// wrote to EVERY plugin file, barrel included. Retained copies of these are
// migrated in place to the current expected stub before the strict
// deactivation gate verifies the install; a rewrite is only allowed for
// files whose managed-recorded digest still matches these bytes.
function isLegacyDisabledOpenCodePluginStub(content) {
const text = content.toString('utf8');
return text === DISABLED_OPENCODE_PLUGIN_STUB
|| text === LEGACY_DISABLED_OPENCODE_PLUGIN_CONTENT;
}
function isOpenCodeHookActivationOperation(operation = {}) {
return getOpenCodeSourceActivationKind(operation) !== null;
}
@@ -472,6 +483,7 @@ module.exports = {
parseJsoncConfig,
getDisabledOpenCodePluginContent,
isInertOpenCodePluginStub,
isLegacyDisabledOpenCodePluginStub,
getOpenCodeActivationPathKind,
getOpenCodeSourceActivationKind,
formatHookCapabilityDisclosure,