feat(#1855): add Claude plugin marketplace manifest

Add .claude-plugin/marketplace.json so Claude-plugin-compatible runtimes
(ZCODE et al.) discover gsd-core from a custom marketplace source. The
canonical version lives at plugins[0].version and tracks package.json via
the release version-sync.

Refactor scripts/sync-manifest-versions.cjs so VERSIONED_MANIFESTS entries
are {path, versionKey} dot-path descriptors (default 'version'); register
marketplace.json with versionKey 'plugins.0.version'. getByPath/setByPath
reject __proto__/constructor/prototype (prototype-pollution guard).
plugin.json / gemini-extension.json behavior is unchanged.

- tests/issue-1855-marketplace-manifest.test.cjs: schema + version-sync guard
- tests/issue-844-manifest-version-sync.test.cjs: updated for descriptor shape
- VERSIONING.md + auto-backmerge VERSION_STAMP_MANIFESTS: include marketplace.json
- docs/how-to/install-on-your-runtime.md: marketplace discovery how-to
This commit is contained in:
Tom Boucher
2026-07-01 11:06:21 -04:00
parent 251cfa1f3c
commit 2391632973
8 changed files with 369 additions and 45 deletions

View File

@@ -21,18 +21,65 @@ const { execFileSync } = require('child_process');
const ROOT = path.resolve(__dirname, '..');
// Single source of truth: runtime-integration manifests whose top-level `version`
// MUST track package.json. Add a new manifest here so `npm version` keeps it in
// sync — the regression guard test (issue 844) fails if you forget.
// Single source of truth: runtime-integration manifests whose `version` field
// MUST track package.json. Each entry names the manifest path plus the dotted
// path to the version field inside that JSON document. Top-level `version` is
// the default (plugin.json, gemini-extension.json); the Claude plugin
// marketplace manifest carries its canonical version at plugins[0].version
// (the schema-canonical location runtimes read — issue #1855).
//
// Add a new manifest here so `npm version` keeps it in sync — the regression
// guard test (issue 844) fails if you forget.
const VERSIONED_MANIFESTS = [
'.claude-plugin/plugin.json',
'gemini-extension.json',
{ path: '.claude-plugin/plugin.json', versionKey: 'version' },
{ path: 'gemini-extension.json', versionKey: 'version' },
{ path: '.claude-plugin/marketplace.json', versionKey: 'plugins.0.version' },
];
// Convenience: just the registered paths, for consumers that only need to
// iterate files (e.g. the issue-844 regression-guard ALLOWED set).
const VERSIONED_MANIFEST_PATHS = VERSIONED_MANIFESTS.map((e) => e.path);
function readJson(p) {
return JSON.parse(fs.readFileSync(p, 'utf8'));
}
// Property names that must never be traversed/assigned through a dotted path —
// the prototype-pollution triple. Mirrors the _isSafePropKey CodeQL barrier used
// elsewhere in the repo. Versions are hand-authored descriptors, but the helpers
// are exported, so guard them before reuse across a trust boundary.
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
function assertSafePath(dotPath) {
for (const seg of String(dotPath).split('.')) {
if (UNSAFE_KEYS.has(seg)) {
throw new Error(`refusing to traverse reserved property "${seg}" in version path "${dotPath}"`);
}
}
}
// Read a dotted path ('plugins.0.version') from a parsed JSON document.
// Returns undefined if any intermediate is missing. Array indices are plain
// numeric keys, so 'plugins.0.version' resolves obj.plugins[0].version.
// Reserved properties (__proto__/constructor/prototype) are rejected.
function getByPath(obj, dotPath) {
assertSafePath(dotPath);
return String(dotPath).split('.').reduce((cur, key) => (cur == null ? cur : cur[key]), obj);
}
// Write a value at a dotted path. Intermediate nodes must already exist (every
// registered manifest is hand-authored with its version slot present, so this
// never needs to materialize a path). Reserved properties are rejected. Kept
// trivial — no eval, no creation.
function setByPath(obj, dotPath, value) {
assertSafePath(dotPath);
const parts = String(dotPath).split('.');
let cur = obj;
for (let i = 0; i < parts.length - 1; i++) {
cur = cur[parts[i]];
}
cur[parts[parts.length - 1]] = value;
}
function getPackageVersion(root) {
const r = root || ROOT;
return readJson(path.join(r, 'package.json')).version;
@@ -44,13 +91,13 @@ function syncManifestVersions(opts) {
const root = (opts && opts.root) || ROOT;
const v = (opts && opts.version) != null ? opts.version : getPackageVersion(root);
const changed = [];
for (const rel of VERSIONED_MANIFESTS) {
const abs = path.join(root, rel);
for (const entry of VERSIONED_MANIFESTS) {
const abs = path.join(root, entry.path);
const manifest = readJson(abs);
if (manifest.version !== v) {
manifest.version = v;
if (getByPath(manifest, entry.versionKey) !== v) {
setByPath(manifest, entry.versionKey, v);
fs.writeFileSync(abs, JSON.stringify(manifest, null, 2) + '\n');
changed.push(rel);
changed.push(entry.path);
}
}
return changed;
@@ -61,9 +108,10 @@ function findDrift(opts) {
const root = (opts && opts.root) || ROOT;
const v = (opts && opts.version) != null ? opts.version : getPackageVersion(root);
const drift = [];
for (const rel of VERSIONED_MANIFESTS) {
const found = readJson(path.join(root, rel)).version;
if (found !== v) drift.push({ manifest: rel, found, expected: v });
for (const entry of VERSIONED_MANIFESTS) {
const manifest = readJson(path.join(root, entry.path));
const found = getByPath(manifest, entry.versionKey);
if (found !== v) drift.push({ manifest: entry.path, found, expected: v });
}
return drift;
}
@@ -143,7 +191,7 @@ function stageManifests(opts) {
console.warn('sync-manifest-versions: not a git work tree; skipping staging.');
return;
}
const toStage = [...VERSIONED_MANIFESTS, ...listCapabilityManifests({ root })];
const toStage = [...VERSIONED_MANIFEST_PATHS, ...listCapabilityManifests({ root })];
try {
execFileSync('git', ['add', '--', ...toStage], { cwd: root, stdio: ['ignore', 'ignore', 'pipe'] });
} catch (err) {
@@ -154,6 +202,9 @@ function stageManifests(opts) {
module.exports = {
VERSIONED_MANIFESTS,
VERSIONED_MANIFEST_PATHS,
getByPath,
setByPath,
syncManifestVersions,
findDrift,
getPackageVersion,