Skip to content

3D engine that AI agents drive

Skip malformed npm addon search entries (#2622)

Veeramanikandanr482d37f1f963c2
diff --git a/changes/2622.md b/changes/2622.md
new file mode 100644
index 00000000..90ef942e
--- /dev/null
+++ b/changes/2622.md
@@ -0,0 +1 @@
+- The Marketplace addon list now skips npm search entries without a publishable package name, so one bad entry no longer hides the other addons (#2622)
diff --git a/docs/packs.md b/docs/packs.md
index b6835bc1..3e61e3b9 100644
--- a/docs/packs.md
+++ b/docs/packs.md
@@ -63,7 +63,7 @@ It runs the same checks as the server and prints `ok` or `FAIL` with the error.
## Install
-The [Marketplace page](https://crucible.codepawl.com/marketplace.html) lists the published packs with a checksum. Unzip each pack into its own subfolder of one packs folder and start the server with that folder:
+The [Marketplace page](https://crucible.codepawl.com/marketplace.html) lists the published packs with a checksum. A malformed npm search entry is skipped so one bad listing does not hide the rest. Unzip each pack into its own subfolder of one packs folder and start the server with that folder:
```sh
crucible-mcp --packs /absolute/path/to/packs
diff --git a/src/marketplace-npm.js b/src/marketplace-npm.js
index ee53e4f8..c3bf7199 100644
--- a/src/marketplace-npm.js
+++ b/src/marketplace-npm.js
@@ -10,6 +10,18 @@ export function npmManifestPath(name) {
export const FIRST_PARTY_PREFIX = '@codepawlhq/crucible-';
const ADDON_KEYWORD = 'crucible-addon';
+/** The addons from an npm search result: only publishable names, so one bad entry cannot hide the rest of the list. */
+export function addonPackages(searchObjects) {
+ if (!Array.isArray(searchObjects)) return [];
+ const packages = [];
+ for (const object of searchObjects) {
+ const entry = object?.package;
+ if (typeof entry?.name !== 'string' || npmManifestPath(entry.name) === null) continue;
+ packages.push({ name: entry.name, version: entry.version, description: entry.description ?? '', range: null });
+ }
+ return packages;
+}
+
/**
* The companion packages CodePawl publishes beside the engine, from an npm search result: names under
* `@codepawlhq/crucible-`, valid npm names, and not addons (those carry the `crucible-addon` keyword and list under Addons).
diff --git a/src/marketplace.js b/src/marketplace.js
index 4582a969..29c26b45 100644
--- a/src/marketplace.js
+++ b/src/marketplace.js
@@ -1,7 +1,7 @@
import './site.css';
import './brand.js';
import './marketplace.css';
-import { firstPartyPackages, npmManifestPath } from './marketplace-npm.js';
+import { addonPackages, firstPartyPackages, npmManifestPath } from './marketplace-npm.js';
const NPM_SEARCH_URL = 'https://registry.npmjs.org/-/v1/search?text=keywords:crucible-addon&size=50';
const NPM_MANIFEST_URL = 'https://registry.npmjs.org/';
@@ -189,7 +189,7 @@ async function loadAddons(container) {
const response = await fetch(NPM_SEARCH_URL);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const { objects } = await response.json();
- const addons = (objects ?? []).map(({ package: entry }) => ({ name: entry.name, version: entry.version, description: entry.description ?? '', range: null }));
+ const addons = addonPackages(objects);
if (addons.length === 0) {
showState(container, 'empty', 'No addons are published yet.', link('Write the first one', ADDONS_DOC_URL));
return;
diff --git a/tests/marketplace-npm.test.js b/tests/marketplace-npm.test.js
index 40638cde..2de98451 100644
--- a/tests/marketplace-npm.test.js
+++ b/tests/marketplace-npm.test.js
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
-import { firstPartyPackages, npmManifestPath } from '../src/marketplace-npm.js';
+import { addonPackages, firstPartyPackages, npmManifestPath } from '../src/marketplace-npm.js';
test('a plain or scoped npm name becomes its registry manifest path', () => {
assert.equal(npmManifestPath('hover-controller'), 'hover-controller/latest');
@@ -30,6 +30,19 @@ test('only published @codepawlhq/crucible- companion packages are listed, sorted
]);
});
+test('one malformed addon entry is skipped without hiding the rest of the list', () => {
+ const objects = [
+ { package: { name: 'hover-controller', version: '1.0.0' } },
+ { package: null },
+ { package: { name: '../bad', version: '2.0.0' } },
+ { package: { name: '@studio/crucible-hover', version: '2.0.0', description: 'A hover addon' } },
+ ];
+ assert.deepEqual(addonPackages(objects), [
+ { name: 'hover-controller', version: '1.0.0', description: '', range: null },
+ { name: '@studio/crucible-hover', version: '2.0.0', description: 'A hover addon', range: null },
+ ]);
+});
+
test('a search result that is not a list gives no packages', () => {
for (const value of [undefined, null, {}, 'x']) assert.deepEqual(firstPartyPackages(value), []);
});