From 290c7fc46de6b5d8895af46256edb089568e8942 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 29 Nov 2026 16:58:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(github):=20=E4=B8=80=E4=B8=AA=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=8F=91=E5=B8=83=E5=A4=9A=E4=B8=AA=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E6=8C=89=E6=A0=87=E7=AD=BE=E5=89=8D=E7=BC=80=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 市场索引条目新增输出字段 releaseTagPrefix,从下载地址的标签派生(索引 schema 不变,旧宿主不受影响)。listReleases 接受 tagPrefix:读 100 条、只保留该前缀的发布、最多 20 条;每条发布新增 version,宿主用它判断已安装版本。 --- rust/Cargo.lock | 1 + rust/contracts/github.md | 25 +++- rust/crates/core/src/tests/github.rs | 133 +++++++++++++++++- .../core/src/tests/marketplace_plugins.rs | 34 +++++ rust/crates/github/src/lib.rs | 98 ++++++++++++- rust/crates/plugin-marketplace/Cargo.toml | 1 + rust/crates/plugin-marketplace/src/lib.rs | 34 +++++ shared/plugins/contract/v1/README.md | 19 ++- .../v1/fixtures/marketplace/index-cases.json | 10 +- .../plugins/reference/domains/marketplace.md | 16 ++- 10 files changed, 349 insertions(+), 22 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index f58956f4..66cf5b38 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1450,6 +1450,7 @@ dependencies = [ name = "lithe-plugin-marketplace" version = "0.1.0" dependencies = [ + "lithe-github", "lithe-plugin-manifest", "lithe-plugin-model", "lithe-protocol", diff --git a/rust/contracts/github.md b/rust/contracts/github.md index cf792216..8a68f68d 100644 --- a/rust/contracts/github.md +++ b/rust/contracts/github.md @@ -52,8 +52,9 @@ GitHub sign-in unavailable rather than asking the user for a personal token. - `github.requestPlan` accepts an `operation` and typed operation fields. It returns `host`, uppercase `method`, absolute `path`, ordered `query`, optional JSON `body`, and `requiresAuthentication`. -- `github.normalizeResponse` accepts `operation`, HTTP `status`, and raw UTF-8 - JSON `body`. It returns a normalized value or the standard Core error. +- `github.normalizeResponse` accepts `operation`, HTTP `status`, raw UTF-8 + JSON `body`, and, for `listReleases`, the optional `tagPrefix` the request was + planned with. It returns a normalized value or the standard Core error. - `github.deviceAuthorizationTransition` accepts `event`, `expiresIn`, `interval`, `elapsedMilliseconds`, and optional `suggestedInterval`. It returns `action`, `intervalSeconds`, and `waitMilliseconds`; it accepts no @@ -100,9 +101,23 @@ leading `-` and the revision operators `~ ^ : ? * [ \` are refused) and returns Hosts use it to pin a marketplace index to a commit, because raw file URLs of a branch are cached for minutes (see `plugins.marketplace.resolveSource`). `listReleases` (`GET /repos/{owner}/{name}/releases`, first page of 20) returns -`[{ tagName, name, body, publishedAt, prerelease, url }]` newest publication -first, ties ordered by tag; drafts are dropped, an empty title is `null` and -missing notes are `""`. +`[{ tagName, version, name, body, publishedAt, prerelease, url }]` newest +publication first, ties ordered by tag; drafts are dropped, an empty title is +`null` and missing notes are `""`. `version` is the `MAJOR.MINOR.PATCH` the tag +ends with, or `null`: the major number takes every digit before it and a +prefix ending in `.` has no split, so `v1.2.0`, `codex-v1.2.0` and `1.2.0` all +read `1.2.0` while `x1.2.3.4` and `v1.2.0-beta.1` read `null`. Hosts compare it +with an installed plugin version. + +A repository that publishes several plugins tags each plugin's releases with +its own prefix (`codex-v0.1.0`, `claude-code-v0.1.0`). Pass the plugin's prefix +as `tagPrefix` (the marketplace entry's `releaseTagPrefix`) to both +`github.requestPlan` and `github.normalizeResponse`: the plan reads one page of +100, and normalization keeps only tags that split into exactly that prefix and +a version, newest first, at most 20. The empty prefix keeps bare +`MAJOR.MINOR.PATCH` tags; an absent `tagPrefix` keeps every release. A prefix +ending in a digit or `.`, or containing whitespace or a control character, can +never match and is refused with `invalid_request` (details `tagPrefix`). `listReviewComments` (`GET /repos/{owner}/{name}/pulls/{number}/comments`, first page of 100) needs `pullNumber` and returns a flat array of diff --git a/rust/crates/core/src/tests/github.rs b/rust/crates/core/src/tests/github.rs index fcf52561..b60d536e 100644 --- a/rust/crates/core/src/tests/github.rs +++ b/rust/crates/core/src/tests/github.rs @@ -433,6 +433,35 @@ fn request_plan_reads_the_newest_commit_and_releases_without_credentials() { assert_eq!(response["data"]["query"], json!({"per_page": "20"})); assert_eq!(response["data"]["requiresAuthentication"], false); + // A plugin sharing its repository reads GitHub's largest page, so its + // own releases remain after the siblings' are filtered out. + for prefix in ["codex-v", ""] { + let response = execute( + "github.requestPlan", + json!({ + "operation": "listReleases", + "repository": {"owner": "example", "name": "lithe-ai-plugins"}, + "tagPrefix": prefix + }), + ); + assert_eq!(response["ok"], true, "{prefix}: {response:?}"); + assert_eq!(response["data"]["query"], json!({"per_page": "100"})); + } + // A prefix ending in a digit or "." never splits off a tag, so it is + // refused instead of answering with an empty changelog. + for prefix in ["codex-1", "codex-v.", "codex v", "a\nb"] { + let response = execute( + "github.requestPlan", + json!({ + "operation": "listReleases", + "repository": {"owner": "example", "name": "lithe-ai-plugins"}, + "tagPrefix": prefix + }), + ); + assert_eq!(response["ok"], false, "{prefix}: {response:?}"); + assert_eq!(response["error"]["code"], "invalid_request"); + } + for git_ref in ["", "main..x", "-x", "main x", "HEAD~1", "a:b"] { let response = execute( "github.requestPlan", @@ -499,12 +528,12 @@ fn normalizes_releases_newest_first_without_drafts() { response["data"], json!([ { - "tagName": "v0.1.1", "name": null, "body": "## Fixes\n- One.", + "tagName": "v0.1.1", "version": "0.1.1", "name": null, "body": "## Fixes\n- One.", "publishedAt": "2026-11-22T13:31:49Z", "prerelease": false, "url": "https://github.com/example/p/releases/tag/v0.1.1" }, { - "tagName": "v0.1.0", "name": "v0.1.0", "body": "First.", + "tagName": "v0.1.0", "version": "0.1.0", "name": "v0.1.0", "body": "First.", "publishedAt": "2026-11-21T08:00:00Z", "prerelease": true, "url": "https://github.com/example/p/releases/tag/v0.1.0" } @@ -518,3 +547,103 @@ fn normalizes_releases_newest_first_without_drafts() { assert_eq!(response["ok"], false, "{response:?}"); assert_eq!(response["error"]["code"], "invalid_request"); } + +#[test] +fn release_tags_split_into_one_prefix_and_version() { + use lithe_github::split_release_tag; + assert_eq!(split_release_tag("v1.2.0"), Some(("v", "1.2.0"))); + assert_eq!( + split_release_tag("codex-v0.1.0"), + Some(("codex-v", "0.1.0")) + ); + assert_eq!(split_release_tag("1.2.0"), Some(("", "1.2.0"))); + // The major number takes every digit, so "v10" never reads as prefix "v1". + assert_eq!(split_release_tag("v10.0.0"), Some(("v", "10.0.0"))); + assert_eq!( + split_release_tag("plugin-2-v1.0.0"), + Some(("plugin-2-v", "1.0.0")) + ); + // Four parts would make "x1." a prefix; refusing it keeps the split unique. + for tag in ["x1.2.3.4", "v1.2", "v1.2.3-beta.1", "1.2.", "v.1.2", ""] { + assert_eq!(split_release_tag(tag), None, "{tag}"); + } +} + +#[test] +fn a_tag_prefix_keeps_only_that_plugins_releases() { + let release = |tag: &str, published: &str| { + json!({ + "tag_name": tag, "name": tag, "body": "", "draft": false, "prerelease": false, + "published_at": published, + "html_url": format!("https://github.com/example/lithe-ai-plugins/releases/tag/{tag}") + }) + }; + let body = json!([ + release("claude-code-v0.1.0", "2026-11-29T10:00:00Z"), + release("codex-v0.1.0", "2026-11-29T09:00:00Z"), + release("codex-v0.0.1", "2026-11-28T09:00:00Z"), + release("codex-vnext", "2026-11-28T08:00:00Z"), + release("0.0.9", "2026-11-27T09:00:00Z"), + ]); + let normalize = |prefix: Value| { + let mut payload = + json!({"operation": "listReleases", "status": 200, "body": body.to_string()}); + if !prefix.is_null() { + payload["tagPrefix"] = prefix; + } + let response = execute("github.normalizeResponse", payload); + assert_eq!(response["ok"], true, "{response:?}"); + response["data"] + .as_array() + .unwrap() + .iter() + .map(|release| (release["tagName"].clone(), release["version"].clone())) + .collect::>() + }; + assert_eq!( + normalize(json!("codex-v")), + vec![ + (json!("codex-v0.1.0"), json!("0.1.0")), + (json!("codex-v0.0.1"), json!("0.0.1")) + ] + ); + assert_eq!(normalize(json!("")), vec![(json!("0.0.9"), json!("0.0.9"))]); + // Without a prefix every release stays; a tag without a version has none. + let all = normalize(Value::Null); + assert_eq!(all.len(), 5); + assert_eq!(all[3], (json!("codex-vnext"), Value::Null)); + + let response = execute( + "github.normalizeResponse", + json!({"operation": "listReleases", "status": 200, "body": body.to_string(), "tagPrefix": "codex-1"}), + ); + assert_eq!(response["ok"], false, "{response:?}"); + assert_eq!(response["error"]["code"], "invalid_request"); +} + +#[test] +fn a_prefixed_release_list_keeps_the_newest_twenty() { + // The prefixed request reads 100 releases; the changelog still shows + // the same bounded number as an unprefixed one. + let body: Vec = (0..30) + .map(|patch| { + json!({ + "tag_name": format!("codex-v0.0.{patch}"), "draft": false, + "published_at": format!("2026-11-01T00:00:{patch:02}Z"), + "html_url": format!("https://github.com/example/p/releases/tag/codex-v0.0.{patch}") + }) + }) + .collect(); + let response = execute( + "github.normalizeResponse", + json!({ + "operation": "listReleases", "status": 200, + "body": Value::Array(body).to_string(), "tagPrefix": "codex-v" + }), + ); + assert_eq!(response["ok"], true, "{response:?}"); + let releases = response["data"].as_array().unwrap(); + assert_eq!(releases.len(), 20); + assert_eq!(releases[0]["tagName"], "codex-v0.0.29"); + assert_eq!(releases[19]["tagName"], "codex-v0.0.10"); +} diff --git a/rust/crates/core/src/tests/marketplace_plugins.rs b/rust/crates/core/src/tests/marketplace_plugins.rs index c28a0574..b61834f0 100644 --- a/rust/crates/core/src/tests/marketplace_plugins.rs +++ b/rust/crates/core/src/tests/marketplace_plugins.rs @@ -145,6 +145,40 @@ fn accepted_entries_are_normalized_newest_first() { assert_eq!(zig["repository"], "https://github.com/example/lithe-zig"); } +#[test] +fn a_release_tag_prefix_is_derived_only_from_one_consistent_convention() { + let elixir = |edit: Option<&str>| { + let mut entry = json_file(INDEX)["plugins"][3].clone(); + assert_eq!(entry["id"], "io.example.elixir-tools"); + if let Some(url) = edit { + *entry + .pointer_mut("/versions/1/downloads/0/downloadURL") + .unwrap() = json!(url); + } + let outcome = validate( + json!({ "schemaVersion": 0, "plugins": [entry] }), + "thirdParty", + "darwin-arm64", + ); + assert_eq!(outcome["index"]["rejected"], json!([]), "{outcome}"); + outcome["index"]["plugins"][0]["releaseTagPrefix"].clone() + }; + assert_eq!(elixir(None), json!("v")); + let base = "https://github.com/example/lithe-elixir/releases/download"; + for tag in [ + // Another plugin's prefix in the same entry: two conventions. + "elixir-v2.0.0", + // A tag for a version other than the one listing it. + "v2.0.1", + // No version at the end, and an escaped segment. + "latest", + "v%32.0.0", + ] { + let url = format!("{base}/{tag}/elixir-tools-2.0.0.zip"); + assert_eq!(elixir(Some(&url)), Value::Null, "{tag}"); + } +} + #[test] fn invalid_index_entries_report_their_stable_codes() { let cases = json_file(INVALID_ENTRIES); diff --git a/rust/crates/github/src/lib.rs b/rust/crates/github/src/lib.rs index b1f8c77e..8f151498 100644 --- a/rust/crates/github/src/lib.rs +++ b/rust/crates/github/src/lib.rs @@ -18,6 +18,10 @@ const DEVICE_SLOW_DOWN_SECONDS: u64 = 5; // The changelog shows the newest releases; one bounded page keeps the // anonymous request small. const RELEASE_PAGE_SIZE: u64 = 20; +// With a tag prefix, the releases of other plugins sharing the repository +// are filtered out, so one larger page (GitHub's maximum) is read to still +// find RELEASE_PAGE_SIZE of the plugin's own. +const PREFIXED_RELEASE_PAGE_SIZE: u64 = 100; // A Git ref name is bounded like a file name; GitHub refuses longer ones. const GIT_REF_MAX_BYTES: usize = 255; @@ -244,6 +248,12 @@ pub struct RequestPlanRequest { /// Optional assignee logins for issue metadata updates. #[serde(default)] pub assignees: Option>, + /// `listReleases` only: the release tag prefix of one plugin in a + /// repository that publishes several (see [`split_release_tag`]). Absent + /// lists every release; present, even empty, reads a larger page so the + /// plugin's own releases remain after `normalizeResponse` filters. + #[serde(default)] + pub tag_prefix: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] @@ -285,6 +295,11 @@ pub struct NormalizeResponseRequest { pub status: u16, /// UTF-8 response body, or an empty string for a bodyless response. pub body: String, + /// `listReleases` only: the same `tagPrefix` the request was planned + /// with. Present, only releases tagged `` + /// are kept. + #[serde(default)] + pub tag_prefix: Option, } #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] @@ -466,6 +481,10 @@ pub struct GitHubComparison { pub struct GitHubRelease { /// Git tag the release was published from. pub tag_name: String, + /// `MAJOR.MINOR.PATCH` the tag ends with (see [`split_release_tag`]), + /// which a host compares with an installed plugin version; null for a tag + /// that does not end with one. + pub version: Option, /// Release title; null when the author left it empty. pub name: Option, /// Markdown release notes; empty when the author wrote none. @@ -478,6 +497,47 @@ pub struct GitHubRelease { pub url: String, } +/// Splits a release tag into its prefix and the `MAJOR.MINOR.PATCH` it ends +/// with: `v1.2.0` is `("v", "1.2.0")`, `codex-v0.1.0` is `("codex-v", +/// "0.1.0")`, and `1.2.0` has the empty prefix. +/// +/// The major number takes every digit before it, and a prefix ending in `.` +/// is refused (`x1.2.3.4` has no split). Each tag therefore has at most one +/// split, so plugins sharing a repository under different prefixes never +/// claim each other's releases. +pub fn split_release_tag(tag: &str) -> Option<(&str, &str)> { + let bytes = tag.as_bytes(); + let mut start = bytes.len(); + for part in 0..3 { + let end = start; + while start > 0 && bytes[start - 1].is_ascii_digit() { + start -= 1; + } + if start == end { + return None; + } + if part < 2 { + if start == 0 || bytes[start - 1] != b'.' { + return None; + } + start -= 1; + } + } + let prefix = &tag[..start]; + (!prefix.ends_with('.')).then(|| (prefix, &tag[start..])) +} + +/// Whether `prefix` can be the prefix [`split_release_tag`] returns. A +/// prefix ending in a digit or `.` would never match, so it is a caller error +/// rather than an empty list. +fn is_release_tag_prefix(prefix: &str) -> bool { + prefix.len() <= GIT_REF_MAX_BYTES + && !prefix + .chars() + .any(|character| character.is_whitespace() || character.is_control()) + && !prefix.ends_with(|character: char| character == '.' || character.is_ascii_digit()) +} + /// Parses one supported GitHub remote URL. pub fn parse_remote(request: ParseRemoteRequest) -> Result { let value = request.remote_url.trim().trim_end_matches('/'); @@ -677,7 +737,11 @@ pub fn request_plan(request: RequestPlanRequest) -> Result { let repository = repository_path(&request)?; - query.insert("per_page".to_string(), RELEASE_PAGE_SIZE.to_string()); + let page_size = match release_tag_prefix(request.tag_prefix.as_deref())? { + Some(_) => PREFIXED_RELEASE_PAGE_SIZE, + None => RELEASE_PAGE_SIZE, + }; + query.insert("per_page".to_string(), page_size.to_string()); ( GitHubHost::Api, "GET", @@ -797,7 +861,9 @@ pub fn normalize_response(request: NormalizeResponseRequest) -> Result normalize_check_run_list(value), "getCombinedStatus" => normalize_combined_status(value), "latestCommit" => normalize_latest_commit(value), - "listReleases" => normalize_release_list(value), + "listReleases" => { + normalize_release_list(value, release_tag_prefix(request.tag_prefix.as_deref())?) + } "createPullRequestComment" => { Ok(serde_json::to_value(normalize_comment(&value)?).expect("comment encodes")) } @@ -838,6 +904,15 @@ fn git_ref(request: &RequestPlanRequest) -> Result<&str, CoreError> { } } +/// Validates an optional `tagPrefix`; the empty prefix is a real filter (bare +/// `MAJOR.MINOR.PATCH` tags), so only absence means "every release". +fn release_tag_prefix(value: Option<&str>) -> Result, CoreError> { + match value { + Some(prefix) if !is_release_tag_prefix(prefix) => Err(invalid_field("tagPrefix")), + other => Ok(other), + } +} + fn repository_path(request: &RequestPlanRequest) -> Result { request .repository @@ -1184,16 +1259,23 @@ fn normalize_latest_commit(value: Value) -> Result { Ok(json!({ "sha": sha.to_ascii_lowercase() })) } -/// Drafts are dropped (an anonymous reader never sees them). The newest -/// publication comes first; equal timestamps fall back to the tag so the -/// order does not depend on GitHub's. -fn normalize_release_list(value: Value) -> Result { +/// Drafts are dropped (an anonymous reader never sees them). With a tag +/// prefix, so are the releases of other plugins sharing the repository. The +/// newest publication comes first; equal timestamps fall back to the tag so +/// the order does not depend on GitHub's. At most `RELEASE_PAGE_SIZE` remain, +/// whatever page size the request read. +fn normalize_release_list(value: Value, tag_prefix: Option<&str>) -> Result { let mut releases = Vec::new(); for value in value.as_array().ok_or_else(parse_shape_error)? { let object = object(value)?; if object.get("draft").and_then(Value::as_bool) == Some(true) { continue; } + let tag_name = text(object, "tag_name")?; + let split = split_release_tag(tag_name); + if tag_prefix.is_some_and(|prefix| split.map(|(own, _)| own) != Some(prefix)) { + continue; + } let optional = |key: &str| { object .get(key) @@ -1202,7 +1284,8 @@ fn normalize_release_list(value: Value) -> Result { .map(str::to_string) }; releases.push(GitHubRelease { - tag_name: text(object, "tag_name")?.to_string(), + tag_name: tag_name.to_string(), + version: split.map(|(_, version)| version.to_string()), name: optional("name"), body: optional("body").unwrap_or_default(), published_at: optional("published_at"), @@ -1219,6 +1302,7 @@ fn normalize_release_list(value: Value) -> Result { .cmp(&left.published_at) .then_with(|| right.tag_name.cmp(&left.tag_name)) }); + releases.truncate(RELEASE_PAGE_SIZE as usize); Ok(serde_json::to_value(releases).expect("release list encodes")) } diff --git a/rust/crates/plugin-marketplace/Cargo.toml b/rust/crates/plugin-marketplace/Cargo.toml index 0bf6f0b0..8fadd3d7 100644 --- a/rust/crates/plugin-marketplace/Cargo.toml +++ b/rust/crates/plugin-marketplace/Cargo.toml @@ -6,6 +6,7 @@ license = "Apache-2.0" description = "Plugin marketplace indexes: validation, platform and plugin API filtering, source URL resolution and install reviews" [dependencies] +lithe-github = { path = "../github" } lithe-plugin-manifest = { path = "../plugin-manifest" } lithe-plugin-model = { path = "../plugin-model" } lithe-protocol = { path = "../protocol" } diff --git a/rust/crates/plugin-marketplace/src/lib.rs b/rust/crates/plugin-marketplace/src/lib.rs index 681ca204..7dd64318 100644 --- a/rust/crates/plugin-marketplace/src/lib.rs +++ b/rust/crates/plugin-marketplace/src/lib.rs @@ -377,11 +377,13 @@ fn validate_entry( let latest = &versions[0]; let availability = availability(&versions, platform, host_capabilities); + let release_tag_prefix = release_tag_prefix(&versions, &repository); Ok(json!({ "id": entry.id, "name": entry.name.trim(), "author": entry.author.trim(), "repository": repository.web_url(), + "releaseTagPrefix": release_tag_prefix, "homepage": entry.homepage, "description": entry.description.trim(), "localizedDescriptions": localized_descriptions, @@ -404,6 +406,38 @@ fn validate_entry( })) } +/// The release tag prefix an entry's plugin publishes under, derived from +/// its download URLs because the index has no field for it (older hosts +/// refuse unknown index fields): every download's tag must split (see +/// [`lithe_github::split_release_tag`]) into one shared prefix and the +/// version listing it. A host reads the plugin's changelog with this prefix, +/// so plugins sharing one repository each see only their own releases. None +/// when the index mixes conventions or a tag is percent-encoded; the host +/// then lists every release of the repository. +fn release_tag_prefix(versions: &[ListedVersion], repository: &GitHubRepository) -> Option { + let mut prefix: Option = None; + for listed in versions { + for download in &listed.version.downloads { + let tag = release_asset_tag(&download.download_url, repository, ".zip")?; + // The tag is a raw path segment; an escaped one would not equal + // the tag name GitHub reports for the release. + if tag.contains('%') { + return None; + } + let (own, version) = lithe_github::split_release_tag(&tag)?; + if version != listed.version.version { + return None; + } + match &prefix { + Some(known) if known != own => return None, + Some(_) => {} + None => prefix = Some(own.to_owned()), + } + } + } + prefix +} + /// One validated version of an entry. struct ListedVersion<'a> { number: (u32, u32, u32), diff --git a/shared/plugins/contract/v1/README.md b/shared/plugins/contract/v1/README.md index df4c36a3..882bac2e 100644 --- a/shared/plugins/contract/v1/README.md +++ b/shared/plugins/contract/v1/README.md @@ -2014,6 +2014,15 @@ repository (`https://github.com///releases/download//.z owner and repository compared case-insensitively), so an index cannot point a plugin at another project's release. +Release tags are ``: `v1.2.0` for a repository with one +plugin, and a distinct prefix per plugin when a repository publishes several +(`codex-v0.1.0`, `claude-code-v0.1.0`). A tag splits into the +`MAJOR.MINOR.PATCH` it ends with, whose major number takes every digit before +it, and the prefix before that; a prefix ending in `.` has no split, so each +tag has at most one. The index carries no prefix field, because hosts that +predate it refuse unknown fields; Core derives `releaseTagPrefix` instead (see +below). + ### Validation and availability `plugins.marketplace.validateIndex` accepts @@ -2028,7 +2037,15 @@ index. Otherwise it returns `{ "status": "ok", "index": { "plugins", "rejected" - `plugins` is sorted by ID. Each accepted entry is normalized, lists `versions` newest first (each with its `requires`), reports `platforms`, `latestVersion`, and `latestReleaseDate` of the newest - version, and an `availability`: + version, a `releaseTagPrefix`, and an `availability`. +- `releaseTagPrefix` is the prefix every download tag of the entry splits + into, each with the version listing it, or null when the tags mix + conventions, a tag does not match its version, or a tag is percent-encoded. + A host reads the plugin's changelog with GitHub `listReleases` and this value + as `tagPrefix` (see `rust/contracts/github.md`), so plugins sharing a + repository each see only their own releases; null lists every release of the + repository. +- `availability` is: - `{status: "available", version, pluginAPIVersion, releaseDate, downloadURL, sha256}` for the newest version with this platform's archive that the host can run: `pluginAPIVersion` `0` and every capability of its `requires` hosted diff --git a/shared/plugins/contract/v1/fixtures/marketplace/index-cases.json b/shared/plugins/contract/v1/fixtures/marketplace/index-cases.json index 728235d7..e76584bd 100644 --- a/shared/plugins/contract/v1/fixtures/marketplace/index-cases.json +++ b/shared/plugins/contract/v1/fixtures/marketplace/index-cases.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "description": "Expected plugins.marketplace.validateIndex outcomes for index.json. `plugins` lists every accepted ID in output order with its availability; `rejected` lists refused entries in index order. `hostCapabilities`, when present, is sent with the request; a request without it offers no capability, so every version on a listed platform is unavailable with plugin.index.apiUnsupported.", + "description": "Expected plugins.marketplace.validateIndex outcomes for index.json. `plugins` lists every accepted ID in output order with its availability (and, in the first case, the release tag prefix derived from its download URLs); `rejected` lists refused entries in index order. `hostCapabilities`, when present, is sent with the request; a request without it offers no capability, so every version on a listed platform is unavailable with plugin.index.apiUnsupported.", "cases": [ { "name": "official source on Apple silicon without a host capability table", @@ -8,10 +8,10 @@ "platform": "darwin-arm64", "expected": { "plugins": [ - { "id": "dev.lithe.fixture.language-packaged-server", "latestVersion": "1.1.0", "platforms": ["darwin-arm64", "darwin-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } }, - { "id": "io.example.elixir-tools", "latestVersion": "3.0.0", "platforms": ["darwin-arm64", "windows-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } }, - { "id": "io.example.future-tools", "latestVersion": "3.0.0", "platforms": ["darwin-arm64", "linux-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } }, - { "id": "io.example.zig-support", "latestVersion": "2.0.0", "platforms": ["darwin-arm64", "windows-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } } + { "id": "dev.lithe.fixture.language-packaged-server", "releaseTagPrefix": "plugin-php-support-v", "latestVersion": "1.1.0", "platforms": ["darwin-arm64", "darwin-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } }, + { "id": "io.example.elixir-tools", "releaseTagPrefix": "v", "latestVersion": "3.0.0", "platforms": ["darwin-arm64", "windows-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } }, + { "id": "io.example.future-tools", "releaseTagPrefix": "", "latestVersion": "3.0.0", "platforms": ["darwin-arm64", "linux-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } }, + { "id": "io.example.zig-support", "releaseTagPrefix": "v", "latestVersion": "2.0.0", "platforms": ["darwin-arm64", "windows-x64"], "availability": { "status": "unsupported", "code": "plugin.index.apiUnsupported" } } ], "rejected": [ { "id": "io.example.zig-support", "code": "plugin.index.duplicate" } diff --git a/shared/plugins/reference/domains/marketplace.md b/shared/plugins/reference/domains/marketplace.md index 3680c19c..2efe1046 100644 --- a/shared/plugins/reference/domains/marketplace.md +++ b/shared/plugins/reference/domains/marketplace.md @@ -62,6 +62,12 @@ raw.githubusercontent.com 会把分支地址缓存几分钟,刚合入的索引 `downloadURL` 必须是条目自己仓库的 GitHub Release `.zip` 资源(`https://github.com///releases/download//.zip`,owner 和仓库名不区分大小写),索引不能把插件指向别的项目的发布。 +#### 一个仓库发布多个插件 + +发布标签写成 `<前缀><版本号>`:只有一个插件的仓库用 `v1.2.0`,同一个仓库里的多个插件各用自己的前缀,例如 `codex-v0.1.0`、`claude-code-v0.1.0`。前缀不能以数字或 `.` 结尾,这样每个标签最多拆出一种前缀和版本号,不同前缀的插件不会认领彼此的发布。 + +索引没有前缀字段(旧宿主会拒绝不认识的字段),Core 从下载地址推出前缀:每个下载地址的 `` 都拆成同一个前缀加上列出它的那个版本号时,条目输出 `releaseTagPrefix`;混用写法、标签和版本号对不上或标签经过百分号编码时为 null。宿主读取插件的更新日志时把它当作 GitHub `listReleases` 的 `tagPrefix` 传入,只显示这个插件自己的发布,见 [GitHub 契约](../../../../rust/contracts/github.md);为 null 时显示仓库的全部发布。 + ### 校验与可用性 `validateIndex` 的输入是 `{index, sourceKind: "official" | "thirdParty", platform, hostCapabilities?}`。索引根对象格式错误或 `schemaVersion` 不是 `0` 时整份拒绝;否则返回 `{plugins, rejected}`: @@ -69,7 +75,7 @@ raw.githubusercontent.com 会把分支地址缓存几分钟,刚合入的索引 | 输出 | 内容 | | --- | --- | | `rejected` | 按索引顺序列出被拒绝的条目和错误:格式错误 `plugin.index.invalid`;第三方来源列出官方命名空间 ID `plugin.index.officialNamespace`;重复 ID 保留第一个,之后的 `plugin.index.duplicate` | -| `plugins` | 按 ID 排序;每个条目规范化,`versions` 从新到旧(各带自己的 `requires`),带 `platforms`、`latestVersion`、`latestReleaseDate` 和 `availability` | +| `plugins` | 按 ID 排序;每个条目规范化,`versions` 从新到旧(各带自己的 `requires`),带 `platforms`、`latestVersion`、`latestReleaseDate`、`releaseTagPrefix`(见[一个仓库发布多个插件](#一个仓库发布多个插件))和 `availability` | | `availability` | 条件 | | --- | --- | @@ -201,6 +207,12 @@ Fetched indexes are cached in platform cache or Application Support storage, nev A `downloadURL` must be a `.zip` GitHub Release asset of the entry's own repository (`https://github.com///releases/download//.zip`, owner and repository compared case-insensitively), so an index cannot point a plugin at another project's release. +#### Several plugins in one repository + +Tag releases ``: a repository with one plugin uses `v1.2.0`, and plugins sharing a repository each use their own prefix, such as `codex-v0.1.0` and `claude-code-v0.1.0`. A prefix must not end in a digit or `.`, so each tag splits into at most one prefix and version and plugins with different prefixes never claim each other's releases. + +The index has no prefix field (older hosts refuse unknown fields), so Core derives it from the download URLs: when every download's `` splits into one shared prefix and the version listing it, the entry reports `releaseTagPrefix`; it is null when the index mixes conventions, a tag does not match its version, or a tag is percent-encoded. A host passes it as the `tagPrefix` of GitHub `listReleases` when it reads the plugin's changelog, so only the plugin's own releases are shown; see the [GitHub contract](../../../../rust/contracts/github.md). When it is null, the host shows every release of the repository. + ### Validation and availability `validateIndex` takes `{index, sourceKind: "official" | "thirdParty", platform, hostCapabilities?}`. A malformed index root or a `schemaVersion` other than `0` rejects the whole index; otherwise it returns `{plugins, rejected}`: @@ -208,7 +220,7 @@ A `downloadURL` must be a `.zip` GitHub Release asset of the entry's own reposit | Output | Contents | | --- | --- | | `rejected` | Refused entries in index order with their error: malformed entries `plugin.index.invalid`; an official-namespace ID from a third-party source `plugin.index.officialNamespace`; a repeated ID keeps the first listing and refuses later ones with `plugin.index.duplicate` | -| `plugins` | Sorted by ID; each entry is normalized, lists `versions` newest first (each with its own `requires`), and carries `platforms`, `latestVersion`, `latestReleaseDate`, and `availability` | +| `plugins` | Sorted by ID; each entry is normalized, lists `versions` newest first (each with its own `requires`), and carries `platforms`, `latestVersion`, `latestReleaseDate`, `releaseTagPrefix` (see [Several plugins in one repository](#several-plugins-in-one-repository)), and `availability` | | `availability` | When | | --- | --- | From b0d3191f3b16b3b1ecb92e7714fdf7087de344bb Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Sun, 29 Nov 2026 16:59:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs(plugins):=20=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=B0=E5=BD=95=E7=99=BB=E8=AE=B0=20#227?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/plugins/reference/protocol-changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index d14a20af..1743fa07 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -19,6 +19,7 @@ | PR | 修改人 | API 编号 | 协议 / 能力 | 改动 | | --- | --- | --- | --- | --- | | [#218](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/218)(待合入) | [@WhiteZeek](https://github.com/WhiteZeek) | API-29 | `buildSystems` 0 内的补充 | 清单 `buildSystems[].detection` 新增可选 `ignoredPaths`:最多 256 条有序的 `.gitignore` 目录规则,每条不超过 1024 个 UTF-8 字节,相对工作区根匹配,只过滤这个构建系统的候选目录。候选目录或它到工作区根之间的任一目录被忽略就不算实例,`outermost` 下被忽略的外层根下的标记文件也不会变成实例;每一层先看工作区规则,工作区的 `!` 规则可以放回;工作区根本身不参与匹配。规则无法编译或超长时整个清单以 `plugin.manifest.invalid` 拒绝,字段为 `buildSystems[i].detection.ignoredPaths[j]`。Core 命令 `build.detect` 的回答总是带 `detection.pluginIgnoredPaths`(`{pluginID, buildSystemID, displayName, patterns}`,按构建系统 ID 排序,只列胜出的声明,没有时为 `[]`),供宿主和可编辑的工作区规则分开展示。固定样例见 [`detect-plugin-ignored-paths-v1.json`](../../../rust/fixtures/build/detect-plugin-ignored-paths-v1.json)。不影响项目树、搜索和索引;没有新增宿主方法、通知、错误码或 SDK 版本。旧宿主会拒绝使用该字段的清单,插件要等包含这个改动的桌面端发布后再用。 | +| [#227](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/227)(待合入) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | — | 市场索引 `schemaVersion` 0 内的补充 | 一个仓库发布多个插件时,每个插件的 Release 标签用自己的前缀:`<前缀>MAJOR.MINOR.PATCH`(如 `codex-v0.1.0`、`claude-code-v0.1.0`)。索引字段不变:`plugins.marketplace.validateIndex` 的输出条目新增 `releaseTagPrefix`,由 Core 从下载地址的标签派生;每个标签都拆成同一个前缀加上列出它的版本号时为该前缀,否则为 `null`。宿主用它读取插件自己的更新日志(`listReleases` 的 `tagPrefix`)。只新增 Core 输出字段,旧宿主照常读取同一份索引;没有新增宿主方法、通知、错误码、能力版本或 SDK 版本。规则见 [`marketplace.md`](domains/marketplace.md#一个仓库发布多个插件)。 | ## 按协议查首次出现