fix: third-party capability skills surface correctly (#2045)

A skills-only role:feature third-party capability installed 'active' but its skills never reached the runtime surface, capability enable/set rejected it as 'unknown capability', and capability list disagreed with capability state. Three defects, fix shape 1b (teach resolveSurface, no on-disk linking):

D1 (materialization): resolveSurface built the surfaced skills Set only from the on-disk manifest; third-party cap skills live at ~/.gsd/capabilities/<id>/skills/ and never entered the Set -> surfaced:false. Fix: union registry.capabilityClusters values into the Set in the full-profile branch (idempotent for first-party, additive for third-party; prototype-pollution guarded).

D2 (enable/set unknown): setCapabilityState validated the capId against the static first-party registry instead of the composed overlay-aware registry. Fix: validate against loadRegistry({includeInstalled}) like capability-state.cts does.

D3 (list vs state): capability list derived status purely from ledger existence, never surface composition. Fix: add a 'surfaced' field to list rows sourced from the same resolver capability state uses, so list and state agree.

Regression coverage: tests/issue-2045-third-party-skills-surface.test.cjs asserts all five acceptance criteria (resolveSurface union, state surfaced:true, enable/set not-unknown, list/state agreement, first-party + unknown-id regression). gsd-test: 23916/23916 green (linux-node22 + linux-node24).
This commit is contained in:
Tom Boucher
2026-07-07 08:11:44 -04:00
parent 2372a221eb
commit 847de596b8
21 changed files with 352 additions and 17 deletions

View File

@@ -2140,6 +2140,28 @@ async function runCommand(command, args, cwd, raw, defaultValue, originalCommand
}
}
} catch { /* best-effort — list still works without the inactive annotation */ }
// Issue #2045 (DEFECT 3): derive each capability's SURFACED state from the
// SAME resolver `capability state` uses (resolveCapabilityRuntimeState), so
// `list` and `state` stop disagreeing. `list` previously derived `status`
// purely from ledger-entry existence — an installed-but-not-surfaced cap
// reported active in `list` and absent in `state`. Surfaced is evaluated at
// the default runtime config dir (the resolver resolves it when undefined),
// matching `capability state <id>` with no --config-dir. Best-effort: a
// resolver failure leaves surfacedById empty (rows report surfaced:null).
const surfacedById = {};
// surfacedById is keyed by capId only (NOT `${scope} ${capId}`): surface
// state is single-source — one runtime config dir → one .gsd-surface.json
// → one surfaced truth per capId — and the loader dedupes overlay caps to
// one registry entry per id (first-party-wins). So a cap installed in both
// scopes correctly shares one surfaced value across its list rows.
try {
const surfaceState = capabilityState.resolveCapabilityRuntimeState(cwd, undefined);
for (const cap of (surfaceState && surfaceState.capabilities) || []) {
if (cap && typeof cap.id === 'string') {
surfacedById[cap.id] = cap.surfaced === true;
}
}
} catch { /* best-effort — list still works without the surfaced annotation */ }
for (const capId of Object.keys(fp)) {
const cap = fp[capId] || {};
rows.push({
@@ -2150,6 +2172,7 @@ async function runCommand(command, args, cwd, raw, defaultValue, originalCommand
source: 'first-party',
scope: 'first-party',
status: 'active',
surfaced: Object.prototype.hasOwnProperty.call(surfacedById, capId) ? surfacedById[capId] === true : null,
title: cap.title || null,
});
}
@@ -2199,6 +2222,12 @@ async function runCommand(command, args, cwd, raw, defaultValue, originalCommand
scope: sc,
status,
reason,
// Issue #2045 (DEFECT 3): surfaced reflects surface composition, so
// list and state agree. An inactive (unconsented/incompatible) cap is
// surfaced:false by definition; otherwise defer to the resolver.
surfaced: status === 'active'
? (Object.prototype.hasOwnProperty.call(surfacedById, capId) ? surfacedById[capId] === true : null)
: false,
title: manifest.title || null,
});
}