Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .workers/plugins-registry/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Serves a unified plugin registry that merges:
* - Free registry (public, plugins/registry.json on GitHub)
* - Pro registry (private, plugins-pro/registry.json via GitHub API with token)
* - Pro registry (private, the Bundles repo registry.json via GitHub API with token)
*
* Endpoints:
* GET /registry.json Combined registry (free + pro), or ?tier=free|pro to filter
Expand Down Expand Up @@ -34,7 +34,7 @@
* stats:global — request statistics
*
* Secrets (set via wrangler secret put):
* GH_ACCESS_TOKEN — Fine-grained PAT with contents:read on nself-org/plugins-pro
* GH_ACCESS_TOKEN — Fine-grained PAT with contents:read on nself-org/bundles
* Also used for authenticated free registry fetch (avoids raw CDN cache)
* GITHUB_SYNC_TOKEN — Bearer token for POST /api/sync (from GitHub Actions)
* SIGNING_PRIVATE_KEY — Ed25519 private key (32 bytes as hex, 64 hex chars)
Expand All @@ -54,7 +54,7 @@ const FREE_REGISTRY_API_URL =
'https://api.github.com/repos/nself-org/plugins/contents/registry.json';

const PRO_REGISTRY_API_URL =
'https://api.github.com/repos/nself-org/plugins-pro/contents/registry.json';
'https://api.github.com/repos/nself-org/bundles/contents/registry.json';

// Fallback: unauthenticated raw URL for free registry (used when GITHUB_TOKEN absent)
const FREE_REGISTRY_RAW_URL =
Expand All @@ -68,16 +68,16 @@ const KV_STATS = 'stats:global';
const DEFAULT_CACHE_TTL = 300; // seconds

// bundles.json — P6-E4-W3-S3-T8 (ADR-P6-03: served by this worker at
// plugins.nself.org/bundles.json). Lives in plugins-pro alongside registry.json
// plugins.nself.org/bundles.json). Lives in the Bundles repo alongside registry.json
// today; the path becomes nself-org/bundles/contents/bundles.json once the
// plugins-pro -> bundles repo rename (ADR-P6-01 / W3-S3-T6) has landed — update
// plugins-pro -> bundles rename (ADR-P6-01 / W3-S3-T6) landed 2026-09-16; updated
// these two URL constants then, nothing else in this route needs to change.
// Own KV keys, distinct from registry:*, so a bundles.json refresh/miss never
// invalidates the unrelated registry cache.
const BUNDLES_JSON_API_URL =
'https://api.github.com/repos/nself-org/plugins-pro/contents/bundles.json';
'https://api.github.com/repos/nself-org/bundles/contents/bundles.json';
const BUNDLES_SCHEMA_API_URL =
'https://api.github.com/repos/nself-org/plugins-pro/contents/bundles-schema.json';
'https://api.github.com/repos/nself-org/bundles/contents/bundles-schema.json';
const KV_BUNDLES_JSON = 'bundles-json-v1';
const KV_BUNDLES_SCHEMA = 'bundles-schema-v1';
const BUNDLES_CACHE_CONTROL = 'public, s-maxage=60, stale-while-revalidate=300';
Expand Down Expand Up @@ -572,7 +572,7 @@ async function handlePluginTarball(plugin, env) {
);
}

const repo = (tier === 'pro') ? 'plugins-pro' : 'plugins';
const repo = (tier === 'pro') ? 'bundles' : 'plugins';
const tarballUrl =
`https://github.com/nself-org/${repo}/releases/download/v${resolvedVersion}/${name}-${resolvedVersion}.tar.gz`;

Expand Down Expand Up @@ -620,7 +620,7 @@ async function handlePluginSignature(plugin, env) {
);
}

const repo = (tier === 'pro') ? 'plugins-pro' : 'plugins';
const repo = (tier === 'pro') ? 'bundles' : 'plugins';
const tarballUrl =
`https://github.com/nself-org/${repo}/releases/download/v${resolvedVersion}/${name}-${resolvedVersion}.tar.gz`;
const canonical = canonicalPluginString(name, resolvedVersion, tarballUrl);
Expand Down
8 changes: 4 additions & 4 deletions .workers/plugins-registry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Secrets (set via `wrangler secret put`):
* SIGNING_PRIVATE_KEY — Ed25519 seed, 32 bytes as 64 lowercase hex chars
* PUBLIC_KEY_HEX — Ed25519 public key, 32 bytes as 64 lowercase hex chars
* GH_ACCESS_TOKEN — Fine-grained PAT (contents:read on plugins + plugins-pro)
* GH_ACCESS_TOKEN — Fine-grained PAT (contents:read on plugins + bundles)
* GITHUB_SYNC_TOKEN — Bearer token for POST /api/sync
*/

Expand Down Expand Up @@ -473,7 +473,7 @@ async function handlePluginTarball(plugin: PluginEntry, env: Env): Promise<Respo
return jsonResponse({ error: "plugin version revoked", plugin: name, version }, 410);
}

const repo = tier === "pro" ? "plugins-pro" : "plugins";
const repo = tier === "pro" ? "bundles" : "plugins";
// GitHub Releases URL (canonical fallback, always valid)
const githubURL =
`https://github.com/nself-org/${repo}/releases/download/v${version}/${name}-${version}.tar.gz`;
Expand Down Expand Up @@ -519,7 +519,7 @@ async function handlePluginTarball(plugin: PluginEntry, env: Env): Promise<Respo
async function handlePluginSignature(plugin: PluginEntry, env: Env): Promise<Response> {
const { name, version, tier } = plugin;

const repo = tier === "pro" ? "plugins-pro" : "plugins";
const repo = tier === "pro" ? "bundles" : "plugins";
const tarballURL =
`https://github.com/nself-org/${repo}/releases/download/v${version}/${name}-${version}.tar.gz`;

Expand Down Expand Up @@ -653,7 +653,7 @@ async function handleManifest(env: Env, ctx: ExecutionContext): Promise<Response
// ---------------------------------------------------------------------------
// GET /bundles.json — P6-E4-W3-S3-T8 (ADR-P6-03).
//
// Serves the bundle-to-plugin membership map from plugins-pro (today; the
// Serves the bundle-to-plugin membership map from the Bundles repo (today; the
// nself-org/bundles repo after the rename lands), cached in PLUGINS_KV under
// its own key (bundles-json-v1, distinct from the registry:* keys) so a
// stale registry cache and a stale bundles.json cache invalidate
Expand Down
2 changes: 1 addition & 1 deletion .workers/plugins-registry/src/marketplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/

// ---------------------------------------------------------------------------
// Bundle membership. Mirrors plugins-pro/bundles.json, which is canonical per
// Bundle membership. Mirrors the Bundles repo bundles.json, which is canonical per
// ADR-P6-03. SPORT F06-BUNDLE-INVENTORY.md is a superseded redirect stub and must
// NOT be used as the source here. Canon order: task, chat, claw, family, sentry, clawde.
// ---------------------------------------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions .workers/plugins-registry/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function normaliseToArray(data: RegistryWireFormat, expectedTier: PluginTier): P
raw = data.plugins;
} else if ("plugins" in data && typeof data.plugins === "object" && data.plugins !== null) {
// Use Object.entries so the dict key becomes the fallback name when the entry
// omits the "name" field (plugins-pro/registry.json uses this dict format).
// omits the "name" field (the Bundles repo registry.json uses this dict format).
raw = Object.entries(data.plugins as Record<string, Omit<PluginEntry, "tier"> & { tier?: PluginTier }>)
.map(([key, entry]) => (entry.name ? entry : { ...entry, name: key }));
} else {
Expand Down Expand Up @@ -270,7 +270,7 @@ function normaliseToArray(data: RegistryWireFormat, expectedTier: PluginTier): P
const FREE_REGISTRY_API_URL =
"https://api.github.com/repos/nself-org/plugins/contents/registry.json";
const PRO_REGISTRY_API_URL =
"https://api.github.com/repos/nself-org/plugins-pro/contents/registry.json";
"https://api.github.com/repos/nself-org/bundles/contents/registry.json";
const FREE_REGISTRY_RAW_URL =
"https://raw.githubusercontent.com/nself-org/plugins/main/registry.json";

Expand Down Expand Up @@ -429,19 +429,19 @@ export async function fetchAllPlugins(

// ---------------------------------------------------------------------------
// bundles.json — P6-E4-W3-S3-T8 (ADR-P6-03: served by this worker at
// plugins.nself.org/bundles.json). Lives in plugins-pro alongside
// plugins.nself.org/bundles.json). Lives in the Bundles repo alongside
// registry.json today; the path becomes nself-org/bundles/contents/*.json
// once the plugins-pro -> bundles repo rename (ADR-P6-01 / W3-S3-T6) has
// the plugins-pro -> bundles rename (ADR-P6-01 / W3-S3-T6) landed 2026-09-16 and these are updated; it
// landed — update the two URL constants below then, nothing else here needs
// to change. Fetched the same way as the pro registry via the GitHub
// Contents API and cached under its own KV key so a bundles.json miss/
// refresh never invalidates the unrelated pro-registry cache.
// ---------------------------------------------------------------------------

const BUNDLES_JSON_API_URL =
"https://api.github.com/repos/nself-org/plugins-pro/contents/bundles.json";
"https://api.github.com/repos/nself-org/bundles/contents/bundles.json";
const BUNDLES_SCHEMA_API_URL =
"https://api.github.com/repos/nself-org/plugins-pro/contents/bundles-schema.json";
"https://api.github.com/repos/nself-org/bundles/contents/bundles-schema.json";

export const KV_BUNDLES_JSON = "bundles-json-v1";
export const KV_BUNDLES_SCHEMA = "bundles-schema-v1";
Expand Down Expand Up @@ -516,7 +516,7 @@ export function validateBundlesJson(data: unknown): { valid: boolean; errors: st
}

/**
* Fetches bundles.json from the plugins-pro repo via the GitHub Contents
* Fetches bundles.json from the Bundles repo via the GitHub Contents
* API, mirroring fetchProRegistry's auth + KV-cache pattern above (reused
* rather than re-implemented per DRY). Returns the raw parsed JSON
* (unvalidated — callers run validateBundlesJson separately so a schema
Expand Down
2 changes: 1 addition & 1 deletion .workers/plugins-registry/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MARKETPLACE_GET_RATE_LIMIT = "60"
MARKETPLACE_GET_RATE_WINDOW_MS = "60000"

# Secrets (set via wrangler secret put <NAME>):
# GH_ACCESS_TOKEN — Fine-grained PAT with contents:read on nself-org/plugins-pro
# GH_ACCESS_TOKEN — Fine-grained PAT with contents:read on nself-org/bundles
# Used to fetch the private pro registry from the GitHub Contents API.
# GITHUB_SYNC_TOKEN — Bearer token for POST /api/sync (triggered by GitHub Actions)

Expand Down
Loading