Skip to content

Commit 5fa2a47

Browse files
committed
fix(update): persist bundle install metadata
1 parent 47be055 commit 5fa2a47

9 files changed

Lines changed: 119 additions & 7 deletions

‎src/cli/plugins-cli.install.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,8 @@ describe("plugins cli install", () => {
12061206
ok: true,
12071207
pluginId: "alpha",
12081208
targetDir: cliInstallPath("alpha"),
1209+
format: "bundle",
1210+
bundleFormat: "claude",
12091211
extensions: ["index.js"],
12101212
version: "1.2.3",
12111213
marketplaceName: "Claude",
@@ -1230,6 +1232,8 @@ describe("plugins cli install", () => {
12301232

12311233
expect(persistedInstallRecord("alpha").source).toBe("marketplace");
12321234
expect(persistedInstallRecord("alpha").installPath).toBe(cliInstallPath("alpha"));
1235+
expect(persistedInstallRecord("alpha").format).toBe("bundle");
1236+
expect(persistedInstallRecord("alpha").bundleFormat).toBe("claude");
12331237
expect(writeConfigFile).toHaveBeenCalledWith(enabledCfg);
12341238
expect(replaceConfigCall().baseHash).toBe("mock");
12351239
expect(replaceConfigCall().nextConfig).toBe(enabledCfg);

‎src/cli/plugins-install-command.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,8 @@ export async function runPluginInstallCommand(params: {
10161016
install: {
10171017
source: "marketplace",
10181018
installPath: result.targetDir,
1019+
...(result.format ? { format: result.format } : {}),
1020+
...(result.bundleFormat ? { bundleFormat: result.bundleFormat } : {}),
10191021
version: result.version,
10201022
marketplaceName: result.marketplaceName,
10211023
marketplaceSource: result.marketplaceSource,

‎src/cli/update-cli/plugin-payload-validation.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ describe("runPluginPayloadSmokeCheck", () => {
141141
marketplace: {
142142
source: "marketplace",
143143
installPath: dir,
144+
format: "bundle",
145+
bundleFormat: "claude",
144146
marketplaceName: "local",
145147
marketplaceSource: "owner/repo",
146148
marketplacePlugin: "claude-bundle",
@@ -152,6 +154,31 @@ describe("runPluginPayloadSmokeCheck", () => {
152154
expect(result.failures).toEqual([]);
153155
});
154156

157+
it("does not reinterpret marketplace package records without durable bundle metadata", async () => {
158+
const dir = path.join(tmpRoot, "marketplace-native-with-skills-leftover");
159+
await writeManifestlessClaudeBundle(dir);
160+
const result = await runPluginPayloadSmokeCheck({
161+
records: {
162+
marketplace: {
163+
source: "marketplace",
164+
installPath: dir,
165+
marketplaceName: "local",
166+
marketplaceSource: "owner/repo",
167+
marketplacePlugin: "native",
168+
},
169+
},
170+
env: {},
171+
});
172+
expect(result.failures).toStrictEqual([
173+
{
174+
pluginId: "marketplace",
175+
installPath: dir,
176+
reason: "missing-package-json",
177+
detail: `package.json is missing under ${dir}`,
178+
},
179+
]);
180+
});
181+
155182
it("keeps reporting missing package.json for non-bundle payloads without package.json", async () => {
156183
const dir = path.join(tmpRoot, "empty-package");
157184
await fs.mkdir(dir, { recursive: true });

‎src/cli/update-cli/plugin-payload-validation.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ function isKnownNativePackageInstallRecord(record: PluginInstallRecord): boolean
212212
return record.source === "npm" || record.clawhubFamily === "code-plugin";
213213
}
214214

215-
function canDetectBundlePayloadFromInstallPath(record: PluginInstallRecord): boolean {
216-
return isBundleInstallRecord(record) || record.source === "marketplace";
217-
}
218-
219215
function readBundleFormat(record: PluginInstallRecord): PluginBundleFormat | null {
220216
const raw = (record as { bundleFormat?: unknown }).bundleFormat;
221217
return raw === "codex" || raw === "claude" || raw === "cursor" ? raw : null;
@@ -251,7 +247,7 @@ async function resolveBundlePayloadFormat(params: {
251247
if (explicitManifestFormat) {
252248
return explicitManifestFormat;
253249
}
254-
if (!canDetectBundlePayloadFromInstallPath(params.record)) {
250+
if (!isBundleInstallRecord(params.record)) {
255251
return null;
256252
}
257253
return readBundleFormat(params.record) ?? detectBundleManifestFormat(params.installPath);

‎src/config/types.installs.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export type InstallRecordBase = {
44
spec?: string;
55
sourcePath?: string;
66
installPath?: string;
7+
format?: "bundle";
8+
bundleFormat?: "codex" | "claude" | "cursor";
79
version?: string;
810
resolvedName?: string;
911
resolvedVersion?: string;

‎src/plugins/install.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export type InstallPluginResult =
157157
ok: true;
158158
pluginId: string;
159159
targetDir: string;
160+
format?: "bundle";
161+
bundleFormat?: "codex" | "claude" | "cursor";
160162
manifestName?: string;
161163
version?: string;
162164
extensions: string[];
@@ -545,6 +547,8 @@ function buildFileInstallResult(pluginId: string, targetFile: string): InstallPl
545547
function buildDirectoryInstallResult(params: {
546548
pluginId: string;
547549
targetDir: string;
550+
format?: "bundle";
551+
bundleFormat?: "codex" | "claude" | "cursor";
548552
manifestName?: string;
549553
version?: string;
550554
extensions: string[];
@@ -553,6 +557,8 @@ function buildDirectoryInstallResult(params: {
553557
ok: true,
554558
pluginId: params.pluginId,
555559
targetDir: params.targetDir,
560+
...(params.format ? { format: params.format } : {}),
561+
...(params.bundleFormat ? { bundleFormat: params.bundleFormat } : {}),
556562
manifestName: params.manifestName,
557563
version: params.version,
558564
extensions: params.extensions,
@@ -2114,6 +2120,8 @@ async function runInstallSourceScan(params: {
21142120
async function installPluginDirectoryIntoExtensions(params: {
21152121
sourceDir: string;
21162122
pluginId: string;
2123+
format?: "bundle";
2124+
bundleFormat?: "codex" | "claude" | "cursor";
21172125
manifestName?: string;
21182126
version?: string;
21192127
extensions: string[];
@@ -2160,6 +2168,8 @@ async function installPluginDirectoryIntoExtensions(params: {
21602168
return buildDirectoryInstallResult({
21612169
pluginId: params.pluginId,
21622170
targetDir,
2171+
format: params.format,
2172+
bundleFormat: params.bundleFormat,
21632173
manifestName: params.manifestName,
21642174
version: params.version,
21652175
extensions: params.extensions,
@@ -2200,6 +2210,8 @@ async function installPluginDirectoryIntoExtensions(params: {
22002210
return buildDirectoryInstallResult({
22012211
pluginId: params.pluginId,
22022212
targetDir,
2213+
format: params.format,
2214+
bundleFormat: params.bundleFormat,
22032215
manifestName: params.manifestName,
22042216
version: params.version,
22052217
extensions: params.extensions,
@@ -2327,6 +2339,8 @@ async function installBundleFromSourceDir(
23272339
return await installPluginDirectoryIntoExtensions({
23282340
sourceDir: params.sourceDir,
23292341
pluginId,
2342+
format: "bundle",
2343+
bundleFormat,
23302344
manifestName: manifestRes.manifest.name,
23312345
version: manifestRes.manifest.version,
23322346
extensions: [],

‎src/plugins/installed-plugin-index-install-records.ts‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function normalizeInstallRecord(
6666
setInstallStringField(normalized, "spec", record.spec);
6767
setInstallStringField(normalized, "sourcePath", record.sourcePath);
6868
setInstallStringField(normalized, "installPath", record.installPath);
69+
setInstallStringField(normalized, "format", record.format);
70+
setInstallStringField(normalized, "bundleFormat", record.bundleFormat);
6971
setInstallStringField(normalized, "version", record.version);
7072
setInstallStringField(normalized, "resolvedName", record.resolvedName);
7173
setInstallStringField(normalized, "resolvedVersion", record.resolvedVersion);
@@ -121,6 +123,24 @@ function restoreInstallRecord(
121123
return structuredClone(record) as PluginInstallRecord;
122124
}
123125

126+
function isBundleFormat(value: unknown): value is NonNullable<PluginInstallRecord["bundleFormat"]> {
127+
return value === "codex" || value === "claude" || value === "cursor";
128+
}
129+
130+
function enrichInstallRecordWithIndexedFormat(
131+
restored: PluginInstallRecord | undefined,
132+
plugin: InstalledPluginIndex["plugins"][number],
133+
): PluginInstallRecord | undefined {
134+
if (!restored || plugin.format !== "bundle" || !isBundleFormat(plugin.bundleFormat)) {
135+
return restored;
136+
}
137+
return {
138+
...restored,
139+
format: "bundle",
140+
bundleFormat: plugin.bundleFormat,
141+
};
142+
}
143+
124144
/** Normalizes raw plugin install records into index-safe install record metadata. */
125145
export function normalizeInstallRecordMap(
126146
records: Record<string, PluginInstallRecord> | undefined,
@@ -157,11 +177,21 @@ export function extractPluginInstallRecordsFromInstalledPluginIndex(
157177
index: InstalledPluginIndex | null | undefined,
158178
): Record<string, PluginInstallRecord> {
159179
if (index && Object.hasOwn(index, "installRecords")) {
160-
return restoreInstallRecordMap(index.installRecords);
180+
const records = restoreInstallRecordMap(index.installRecords);
181+
for (const plugin of index.plugins) {
182+
const enriched = enrichInstallRecordWithIndexedFormat(records[plugin.pluginId], plugin);
183+
if (enriched) {
184+
records[plugin.pluginId] = enriched;
185+
}
186+
}
187+
return records;
161188
}
162189
const records: Record<string, PluginInstallRecord> = {};
163190
for (const plugin of index?.plugins ?? []) {
164-
const record = restoreInstallRecord(plugin.installRecord);
191+
const record = enrichInstallRecordWithIndexedFormat(
192+
restoreInstallRecord(plugin.installRecord),
193+
plugin,
194+
);
165195
if (record) {
166196
records[plugin.pluginId] = record;
167197
}

‎src/plugins/installed-plugin-index-types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export type InstalledPluginInstallRecordInfo = Pick<
5656
| "spec"
5757
| "sourcePath"
5858
| "installPath"
59+
| "format"
60+
| "bundleFormat"
5961
| "version"
6062
| "resolvedName"
6163
| "resolvedVersion"

‎src/plugins/installed-plugin-index.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from "node:fs";
33
import path from "node:path";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import type { PluginCandidate } from "./discovery.js";
6+
import { extractPluginInstallRecordsFromInstalledPluginIndex } from "./installed-plugin-index-install-records.js";
67
import { buildInstalledPluginIndexRecords } from "./installed-plugin-index-record-builder.js";
78
import {
89
loadInstalledPluginIndexInstallRecordsSync,
@@ -405,6 +406,40 @@ describe("installed plugin index", () => {
405406
expectSha256(plugin.manifestHash);
406407
});
407408

409+
it("restores bundle install metadata from indexed plugin records", () => {
410+
const rootDir = path.join(makeTempDir(), "workspace");
411+
writeManifestlessClaudeBundle(rootDir);
412+
413+
const index = loadInstalledPluginIndex({
414+
candidates: [
415+
createPluginCandidate({
416+
rootDir,
417+
idHint: "workspace",
418+
format: "bundle",
419+
bundleFormat: "claude",
420+
origin: "config",
421+
}),
422+
],
423+
installRecords: {
424+
workspace: {
425+
source: "marketplace",
426+
installPath: rootDir,
427+
marketplaceSource: "owner/repo",
428+
marketplacePlugin: "workspace",
429+
},
430+
},
431+
env: hermeticEnv(),
432+
});
433+
434+
expect(index.installRecords.workspace?.format).toBeUndefined();
435+
expect(extractPluginInstallRecordsFromInstalledPluginIndex(index).workspace).toMatchObject({
436+
source: "marketplace",
437+
installPath: rootDir,
438+
format: "bundle",
439+
bundleFormat: "claude",
440+
});
441+
});
442+
408443
it("changes manifestless Claude bundle hashes when derived metadata changes", () => {
409444
const rootDir = path.join(makeTempDir(), "workspace");
410445
writeManifestlessClaudeBundle(rootDir, ["skills"]);

0 commit comments

Comments
 (0)