From 06207fb810128a56a254baa2a75fba9f7d90d02e Mon Sep 17 00:00:00 2001 From: Kevin Codex Date: Wed, 18 Nov 2026 11:37:16 +0800 Subject: [PATCH 1/4] feat: accept the twigpine:// scheme and rename names nothing compares Third step of the rename: the protocol names. - Remote URLs and UCAN resources: the helper, the CLI and the node accept twigpine:// as well as gitlawb://, through twigpine_core::url_scheme. The two spellings of a UCAN resource attenuate as one resource, so a delegation chain may mix them. Writers keep the old scheme until a later release. - The npm package ships git-remote-twigpine, which git runs for twigpine:// remotes; every other install method already does. - twigpine doctor checks for both helper names: missing the old one fails, missing the new one warns. - CLI Arweave discovery finds anchors tagged App-Name twigpine or gitlawb. - twigpine status recognises a remote named twigpine. - Renamed outright, since nothing compares them: the CLI and helper user agents, the MCP server name, the auth realm, and the libp2p identify string. - docs/LEGACY-NAMES.md lists every name kept from before the rename and why. Internal identifiers stay permanently: the refs/gitlawb namespace, the cert type, the gossip topic, the DHT key prefix, the key-derivation and signing labels, and did:gitlawb. Each definition points at the list. --- README.md | 2 + crates/git-remote-twigpine/src/main.rs | 22 +++- .../tests/real_git_fetch.rs | 34 ++++++ crates/twigpine-attest/src/attestation.rs | 1 + crates/twigpine-cli/src/changelog.rs | 2 +- crates/twigpine-cli/src/clone.rs | 11 +- crates/twigpine-cli/src/doctor.rs | 44 ++++++-- crates/twigpine-cli/src/http.rs | 2 +- crates/twigpine-cli/src/mcp.rs | 7 +- crates/twigpine-cli/src/pr.rs | 2 +- crates/twigpine-cli/src/status.rs | 6 +- crates/twigpine-cli/src/ucan_cmd.rs | 5 +- crates/twigpine-core/src/cert.rs | 1 + crates/twigpine-core/src/did.rs | 1 + crates/twigpine-core/src/lib.rs | 1 + crates/twigpine-core/src/ucan.rs | 57 +++++++++- crates/twigpine-core/src/url_scheme.rs | 106 ++++++++++++++++++ crates/twigpine-node/src/ans104.rs | 1 + crates/twigpine-node/src/api/repos.rs | 1 + crates/twigpine-node/src/api/task_cursor.rs | 1 + crates/twigpine-node/src/auth/mod.rs | 2 +- crates/twigpine-node/src/encrypted_pin.rs | 1 + crates/twigpine-node/src/p2p/mod.rs | 5 +- crates/twigpine-node/src/state.rs | 2 + docs/LEGACY-NAMES.md | 57 ++++++++++ npm/packages/gl/install.js | 6 + npm/packages/gl/package.json | 3 +- 27 files changed, 343 insertions(+), 40 deletions(-) create mode 100644 crates/twigpine-core/src/url_scheme.rs create mode 100644 docs/LEGACY-NAMES.md diff --git a/README.md b/README.md index 3c664c373..107cc23bd 100644 --- a/README.md +++ b/README.md @@ -405,6 +405,8 @@ The default key folder is `~/.twigpine`. An existing `~/.gitlawb` keeps being us Response headers and webhook deliveries carry both `X-Twigpine-*` and the older `X-Gitlawb-*` names with the same values. +Repository URLs and UCAN resources accept `twigpine://` as well as `gitlawb://`; new ones are still written as `gitlawb://` until a later release. [`docs/LEGACY-NAMES.md`](docs/LEGACY-NAMES.md) lists every name kept from before the rename and why. + Minimum required for a persistent node: ```env diff --git a/crates/git-remote-twigpine/src/main.rs b/crates/git-remote-twigpine/src/main.rs index a94290fd9..97373f452 100644 --- a/crates/git-remote-twigpine/src/main.rs +++ b/crates/git-remote-twigpine/src/main.rs @@ -480,7 +480,7 @@ fn same_origin_redirect(attempt: reqwest::redirect::Attempt<'_>) -> reqwest::red // ── Smart-protocol request builders ─────────────────────────────────────────── -const USER_AGENT: &str = "git/2.0 git-remote-gitlawb/0.1.0"; +const USER_AGENT: &str = concat!("git/2.0 git-remote-twigpine/", env!("CARGO_PKG_VERSION")); /// Build the Phase-1 ref-advertisement GET, signing it when an identity is /// present. The node gates the ref advertisement on read visibility for BOTH @@ -773,18 +773,19 @@ fn build_pack_post_request( // ── URL helpers ─────────────────────────────────────────────────────────────── -/// Parse a `gitlawb://did:key:z6Mk.../repo-name` URL. +/// Parse a `twigpine://did:key:z6Mk.../repo-name` URL, or its `gitlawb://` +/// spelling from before the rename. Git runs this helper as +/// `git-remote-twigpine` for the first and `git-remote-gitlawb` for the second. /// /// Returns `(did_string, short_owner, repo_name)`. fn parse_gitlawb_url(url: &str) -> Result<(String, String, String)> { - let without_scheme = url - .strip_prefix("gitlawb://") - .ok_or_else(|| anyhow::anyhow!("not a gitlawb:// URL: {url}"))?; + let without_scheme = twigpine_core::url_scheme::strip_scheme(url) + .ok_or_else(|| anyhow::anyhow!("not a twigpine:// URL: {url}"))?; // without_scheme = "did:key:z6Mk.../repo-name" let (did_string, repo_name) = without_scheme .rsplit_once('/') - .ok_or_else(|| anyhow::anyhow!("gitlawb:// URL must be did:.../repo-name, got: {url}"))?; + .ok_or_else(|| anyhow::anyhow!("twigpine:// URL must be did:.../repo-name, got: {url}"))?; // short_owner = last colon-delimited segment, e.g. "z6Mk..." // The node's DB uses a LIKE '%' query to match the full DID. @@ -2385,6 +2386,15 @@ mod tests { assert_eq!(repo, "my-repo"); } + #[test] + fn parse_url_under_the_new_scheme() { + let (did, owner, repo) = + parse_gitlawb_url("twigpine://did:key:z6MkFoo123/my-repo.git").unwrap(); + assert_eq!(did, "did:key:z6MkFoo123"); + assert_eq!(owner, "z6MkFoo123"); + assert_eq!(repo, "my-repo"); + } + #[test] fn parse_url_strips_dot_git() { let (_, _, repo) = parse_gitlawb_url("gitlawb://did:key:z6MkFoo123/my-repo.git").unwrap(); diff --git a/crates/git-remote-twigpine/tests/real_git_fetch.rs b/crates/git-remote-twigpine/tests/real_git_fetch.rs index ef8c5f25d..c42000b5c 100644 --- a/crates/git-remote-twigpine/tests/real_git_fetch.rs +++ b/crates/git-remote-twigpine/tests/real_git_fetch.rs @@ -1146,6 +1146,40 @@ fn real_git_multi_round_fetch_completes() { // No manual cleanup: `repos` drops here (or on unwind) and removes the tree. } +/// A `twigpine://` remote: git runs `git-remote-twigpine` for it, and the +/// fetch completes exactly as it does under the old scheme. +#[test] +fn real_git_fetch_through_a_twigpine_remote() { + let repos = build_divergent_repos(3); + let (server, clone) = (repos.server.clone(), repos.clone.clone()); + git( + &clone, + &[ + "remote", + "set-url", + "origin", + "twigpine://did:key:zTESTOWNER/myrepo", + ], + ); + // Both helper names sit in the same build directory, which + // `fetch_with_helper` puts on PATH; the scheme alone picks this one. + assert!( + PathBuf::from(env!("CARGO_BIN_EXE_git-remote-twigpine")).is_file(), + "the helper must exist under its new name" + ); + let shim = start_shim(server.clone(), ShimMode::Normal); + + let (completed, out) = fetch_with_helper(&clone, &shim.base_url); + assert!( + completed && out.status.success(), + "fetch through twigpine:// failed. stderr:\n{}", + String::from_utf8_lossy(&out.stderr) + ); + let server_head = String::from_utf8(git(&server, &["rev-parse", "HEAD"])).unwrap(); + let fetched = String::from_utf8(git(&clone, &["rev-parse", "FETCH_HEAD"])).unwrap(); + assert_eq!(server_head.trim(), fetched.trim()); +} + /// #192 (F3): a panic (any unwind) mid-test still removes the repos. The old /// success-only `cleanup()` ran after the assertions, so a failing test leaked real /// git repos; the RAII `TempDir` drops during unwind instead. Load-bearing: the diff --git a/crates/twigpine-attest/src/attestation.rs b/crates/twigpine-attest/src/attestation.rs index 14be16b90..4c6697017 100644 --- a/crates/twigpine-attest/src/attestation.rs +++ b/crates/twigpine-attest/src/attestation.rs @@ -23,6 +23,7 @@ use crate::error::{Error, Result}; /// Domain-separation tag prepended to the JCS signing input. Bumped to /// `v2` if the signing-input shape changes. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. const SIGNING_DOMAIN: &[u8] = b"gitlawb-attest-sig/v1\n"; /// Multicodec varint prefix for Ed25519 public keys (0xed 0x01). diff --git a/crates/twigpine-cli/src/changelog.rs b/crates/twigpine-cli/src/changelog.rs index 4e3d71ec4..7c473c441 100644 --- a/crates/twigpine-cli/src/changelog.rs +++ b/crates/twigpine-cli/src/changelog.rs @@ -111,7 +111,7 @@ fn detect_repo_from_remote() -> Option { return None; } let url = String::from_utf8(out.stdout).ok()?; - let rest = url.trim().strip_prefix("gitlawb://")?; + let rest = twigpine_core::url_scheme::strip_scheme(url.trim())?; let slash = rest.rfind('/')?; let did = &rest[..slash]; let repo = &rest[slash + 1..]; diff --git a/crates/twigpine-cli/src/clone.rs b/crates/twigpine-cli/src/clone.rs index 6afd94433..08b93243f 100644 --- a/crates/twigpine-cli/src/clone.rs +++ b/crates/twigpine-cli/src/clone.rs @@ -237,16 +237,17 @@ pub fn setup_partial_clone( } /// Parse `repo` into (gitlawb_url, owner, name). Accepts a full -/// `gitlawb:///` URL or a bare `/`. The owner DID may +/// `twigpine:///` URL (or the `gitlawb://` spelling) or a bare +/// `/`. The owner DID may /// itself contain colons but no slash, so split on the first slash. fn parse_repo(repo: &str) -> Result<(String, String, String)> { - let stripped = repo.strip_prefix("gitlawb://").unwrap_or(repo); + let stripped = twigpine_core::url_scheme::strip_scheme(repo).unwrap_or(repo); let (owner, name) = stripped .trim_end_matches('/') .split_once('/') - .context("repo must be / or gitlawb:///")?; + .context("repo must be / or twigpine:///")?; if owner.is_empty() || name.is_empty() || name.contains('/') { - bail!("repo must be / or gitlawb:///"); + bail!("repo must be / or twigpine:///"); } Ok(( format!("gitlawb://{owner}/{name}"), @@ -489,7 +490,7 @@ const ARWEAVE_PAGE_SIZE: usize = 100; /// Paginated discovery query: manifests tagged for this repo, newest first, with /// `pageInfo` for cursor pagination and `block{height}` for the recency tie-break. -const ARWEAVE_DISCOVERY_QUERY: &str = r#"query($repo:String!,$cursor:String){transactions(tags:[{name:"App-Name",values:["gitlawb"]},{name:"Schema",values:["gitlawb/encrypted-manifest/v1"]},{name:"Repo",values:[$repo]}],first:100,after:$cursor){pageInfo{hasNextPage endCursor}edges{cursor node{id block{height}}}}}"#; +const ARWEAVE_DISCOVERY_QUERY: &str = r#"query($repo:String!,$cursor:String){transactions(tags:[{name:"App-Name",values:["twigpine","gitlawb"]},{name:"Schema",values:["gitlawb/encrypted-manifest/v1"]},{name:"Repo",values:[$repo]}],first:100,after:$cursor){pageInfo{hasNextPage endCursor}edges{cursor node{id block{height}}}}}"#; /// A parsed page of an Arweave GraphQL `transactions` response: the edge refs /// plus pagination state. `has_next` is `None` when the response omitted diff --git a/crates/twigpine-cli/src/doctor.rs b/crates/twigpine-cli/src/doctor.rs index a6286a931..4a10a3475 100644 --- a/crates/twigpine-cli/src/doctor.rs +++ b/crates/twigpine-cli/src/doctor.rs @@ -328,15 +328,10 @@ pub async fn run(args: DoctorArgs) -> Result<()> { // Git picks its helper by URL scheme, so a `gitlawb://` remote runs the helper // under the scheme's name. It is the same program as git-remote-twigpine; // probing this name is what tells us clone and push will work. - if which_in_path("git-remote-gitlawb") { - checks.push(Check::pass("git-remote-gitlawb", "found in PATH")); - } else { - checks.push(Check::fail( - "git-remote-gitlawb", - "not found in PATH — gitlawb:// clone/push will not work", - "curl -fsSL https://twigpine.com/install.sh | sh", - )); - } + checks.push(helper_check( + which_in_path("git-remote-gitlawb"), + which_in_path("git-remote-twigpine"), + )); // ── 6. git ──────────────────────────────────────────────────────────── match std::process::Command::new("git") @@ -604,6 +599,27 @@ fn is_loopback_url(value: &str) -> bool { } /// Check if a binary name exists anywhere on PATH. +/// The git helper row. Git runs `git-remote-gitlawb` for `gitlawb://` remotes, +/// which is what every remote created so far uses, so without it clone and push +/// fail now: a failure. `git-remote-twigpine` runs `twigpine://` remotes, which +/// new remotes will use from a coming release: a warning until then. +fn helper_check(has_old_name: bool, has_new_name: bool) -> Check { + const INSTALL: &str = "curl -fsSL https://twigpine.com/install.sh | sh"; + match (has_old_name, has_new_name) { + (true, true) => Check::pass("git helper", "git-remote-twigpine and git-remote-gitlawb found in PATH"), + (false, _) => Check::fail( + "git helper", + "git-remote-gitlawb not found in PATH — clone and push of gitlawb:// remotes will not work", + INSTALL, + ), + (true, false) => Check::warn( + "git helper", + "git-remote-twigpine not found in PATH — twigpine:// remotes will not work", + INSTALL, + ), + } +} + fn which_in_path(name: &str) -> bool { std::env::var_os("PATH") .map(|paths| { @@ -645,7 +661,7 @@ fn legacy_settings_check(report: &twigpine_core::legacy_env::Report) -> Option Check { let client = match reqwest::Client::builder() - .user_agent(format!("gl/{current}")) + .user_agent(format!("twigpine/{current}")) .timeout(std::time::Duration::from_secs(5)) .build() { @@ -924,6 +940,14 @@ mod tests { /// re-tier so flipping it back to `Check::fail` breaks the suite — the /// previous `has_failures`-only tests built their own `Check::warn` rows /// and could not see the re-tier at all. + #[test] + fn helper_row_needs_the_old_name_and_wants_the_new_one() { + assert!(matches!(helper_check(true, true).state, CheckState::Ok)); + assert!(matches!(helper_check(false, true).state, CheckState::Fail)); + assert!(matches!(helper_check(false, false).state, CheckState::Fail)); + assert!(matches!(helper_check(true, false).state, CheckState::Warn)); + } + #[test] fn legacy_settings_row_appears_only_when_an_old_name_is_in_use() { use twigpine_core::legacy_env::Report; diff --git a/crates/twigpine-cli/src/http.rs b/crates/twigpine-cli/src/http.rs index c2cc4696f..309b0d100 100644 --- a/crates/twigpine-cli/src/http.rs +++ b/crates/twigpine-cli/src/http.rs @@ -218,7 +218,7 @@ impl NodeClient { let mut builder = reqwest::Client::builder() .timeout(timeout) .redirect(reqwest::redirect::Policy::custom(same_origin_redirect)) - .user_agent(format!("gl/{} gitlawb-cli", env!("CARGO_PKG_VERSION"))); + .user_agent(format!("twigpine/{}", env!("CARGO_PKG_VERSION"))); // A loopback node is reached directly, ignoring HTTP_PROXY/ALL_PROXY, so // a proxy can never carry its signed requests off this machine and the // guard needs no model of the proxy environment. Redirects cannot leave diff --git a/crates/twigpine-cli/src/mcp.rs b/crates/twigpine-cli/src/mcp.rs index e8b33fd41..a8703c31e 100644 --- a/crates/twigpine-cli/src/mcp.rs +++ b/crates/twigpine-cli/src/mcp.rs @@ -136,11 +136,8 @@ async fn dispatch( "initialize" => Ok(json!({ "protocolVersion": "2024-11-05", "capabilities": { "tools": {} }, - // Wire-visible, like the CLI's user agent: it moves to "twigpine" - // with the other names peers and clients can see, in the protocol - // step of the rename, not here. "serverInfo": { - "name": "gitlawb", + "name": "twigpine", "version": env!("CARGO_PKG_VERSION"), } })), @@ -1825,7 +1822,7 @@ mod tests { .await .unwrap(); assert_eq!(result["protocolVersion"], "2024-11-05"); - assert_eq!(result["serverInfo"]["name"], "gitlawb"); + assert_eq!(result["serverInfo"]["name"], "twigpine"); } #[tokio::test] diff --git a/crates/twigpine-cli/src/pr.rs b/crates/twigpine-cli/src/pr.rs index c9308f29c..5874de05c 100644 --- a/crates/twigpine-cli/src/pr.rs +++ b/crates/twigpine-cli/src/pr.rs @@ -230,7 +230,7 @@ fn detect_remote_owner() -> Option { return None; } let url = String::from_utf8(out.stdout).ok()?; - let rest = url.trim().strip_prefix("gitlawb://")?; + let rest = twigpine_core::url_scheme::strip_scheme(url.trim())?; let slash = rest.rfind('/')?; let did = &rest[..slash]; Some(did.split(':').next_back().unwrap_or(did).to_string()) diff --git a/crates/twigpine-cli/src/status.rs b/crates/twigpine-cli/src/status.rs index b23a038be..70771b037 100644 --- a/crates/twigpine-cli/src/status.rs +++ b/crates/twigpine-cli/src/status.rs @@ -198,7 +198,9 @@ fn detect_gitlawb_remote() -> Option<(String, String)> { .map(str::to_string) .collect(); - let preferred = ["origin", "gitlawb"]; + // `twigpine init` names its remote `gitlawb` today and `twigpine` once + // writers move to the new name; either is ours. + let preferred = ["origin", "twigpine", "gitlawb"]; let ordered = preferred .iter() .filter(|p| names.iter().any(|n| n == *p)) @@ -240,7 +242,7 @@ fn detect_gitlawb_remote() -> Option<(String, String)> { /// Parse a gitlawb:// URL string into (did, repo). fn parse_gitlawb_url(url: &str) -> Option<(String, String)> { - let rest = url.trim().strip_prefix("gitlawb://")?; + let rest = twigpine_core::url_scheme::strip_scheme(url.trim())?; let slash = rest.rfind('/')?; let did = rest[..slash].to_string(); let repo = rest[slash + 1..].to_string(); diff --git a/crates/twigpine-cli/src/ucan_cmd.rs b/crates/twigpine-cli/src/ucan_cmd.rs index 0056a4516..a53199c62 100644 --- a/crates/twigpine-cli/src/ucan_cmd.rs +++ b/crates/twigpine-cli/src/ucan_cmd.rs @@ -109,13 +109,14 @@ fn is_safe_component(s: &str) -> bool { .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '-' | '_' | ':')) } -/// Pull the repo this capability names out of `gitlawb://repos//`. +/// Pull the repo this capability names out of `twigpine://repos//` +/// (or the `gitlawb://` spelling from before the rename). /// /// Requires exactly two components after the prefix. Anything else — extra /// segments, a trailing slash, an empty half — is refused rather than /// interpreted, so no input can address a location the caller did not intend. fn repo_from_resource(with: &str) -> Option<(String, String)> { - let rest = with.strip_prefix("gitlawb://repos/")?; + let rest = twigpine_core::url_scheme::strip_resource_prefix(with)?; let mut parts = rest.split('/'); let owner = parts.next()?; let name = parts.next()?; diff --git a/crates/twigpine-core/src/cert.rs b/crates/twigpine-core/src/cert.rs index 7e77fde38..db5bad67f 100644 --- a/crates/twigpine-core/src/cert.rs +++ b/crates/twigpine-core/src/cert.rs @@ -39,6 +39,7 @@ use crate::identity::{verify, Keypair}; use crate::{Error, Result}; /// The certificate type discriminant. Always `"gitlawb/ref-update/v1"`. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. pub const CERT_TYPE: &str = "gitlawb/ref-update/v1"; /// Exact url-safe unpadded base64 length of a 64-byte Ed25519 signature. diff --git a/crates/twigpine-core/src/did.rs b/crates/twigpine-core/src/did.rs index 24433fbb7..0348c0226 100644 --- a/crates/twigpine-core/src/did.rs +++ b/crates/twigpine-core/src/did.rs @@ -58,6 +58,7 @@ impl Did { } /// Construct a `did:gitlawb` DID from a DHT key (base58btc-encoded). + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. pub fn gitlawb(key: &str) -> Self { Self(format!("did:gitlawb:{key}")) } diff --git a/crates/twigpine-core/src/lib.rs b/crates/twigpine-core/src/lib.rs index 66a61aa3a..d53b5ea21 100644 --- a/crates/twigpine-core/src/lib.rs +++ b/crates/twigpine-core/src/lib.rs @@ -22,6 +22,7 @@ pub mod scan_token; #[cfg(any(feature = "redirect", test))] pub mod transport_policy; pub mod ucan; +pub mod url_scheme; /// Node URL the git transport falls back to when `TWIGPINE_NODE` is unset. /// diff --git a/crates/twigpine-core/src/ucan.rs b/crates/twigpine-core/src/ucan.rs index fdf26dd1a..d4e2e2a71 100644 --- a/crates/twigpine-core/src/ucan.rs +++ b/crates/twigpine-core/src/ucan.rs @@ -79,7 +79,10 @@ impl Capability { /// granted it. Since `nb` has no interpreted semantics yet, "different" cannot /// be shown to be narrower and is refused with it. pub fn is_attenuated_by(&self, parent: &Capability) -> bool { - let resource_ok = parent.with == self.with || parent.with == "*"; + // `twigpine://repos/...` and `gitlawb://repos/...` name the same + // repository, so a chain that mixes the two spellings still attenuates. + let resource_ok = + crate::url_scheme::same_resource(&parent.with, &self.with) || parent.with == "*"; let action_ok = parent.can == self.can || parent.can == "*" || parent.can == caps::REPO_ADMIN; let constraints_ok = match (&parent.constraints, &self.constraints) { @@ -148,12 +151,12 @@ pub mod push { can == caps::GIT_PUSH || can == "*" || can == caps::REPO_ADMIN } - /// `gitlawb://repos//` → `(owner, repo)`, or `None` for any other - /// shape. Exactly two non-empty segments: an owner DID never contains `/`, so + /// `twigpine://repos//` (or the `gitlawb://` spelling from + /// before the rename) → `(owner, repo)`, or `None` for any other shape. Exactly two non-empty segments: an owner DID never contains `/`, so /// a third segment, a trailing slash, or an empty half is malformed rather than /// something to interpret. pub fn parse_repo_resource(with: &str) -> Option<(&str, &str)> { - let rest = with.strip_prefix("gitlawb://repos/")?; + let rest = crate::url_scheme::strip_resource_prefix(with)?; let (owner, repo) = rest.split_once('/')?; if owner.is_empty() || repo.is_empty() || repo.contains('/') { return None; @@ -1171,6 +1174,10 @@ mod push_scope_tests { parse_repo_resource("gitlawb://repos/did:key:z6Mk/r"), Some(("did:key:z6Mk", "r")) ); + assert_eq!( + parse_repo_resource("twigpine://repos/did:key:z6Mk/r"), + Some(("did:key:z6Mk", "r")) + ); for bad in [ "*", "", @@ -1258,6 +1265,48 @@ mod push_scope_tests { /// The chain walk, at every depth: a wildcard anywhere denies; concrete /// everywhere grants. The grandparent case is the one a single-level check /// misses, because the immediate proof already names the repo. + #[test] + fn a_chain_mixing_the_two_resource_spellings_verifies_and_grants() { + let owner = Keypair::generate(); + let a = Keypair::generate(); + let node = Keypair::generate(); + let owner_s = owner.did().to_string(); + let old = format!("gitlawb://repos/{owner_s}/r"); + let new = format!("twigpine://repos/{owner_s}/r"); + + // A delegation issued before the rename, re-delegated after it. + let proof = Ucan::issue( + &owner, + a.did(), + vec![Capability::new(&old, caps::GIT_PUSH)], + Some(hour()), + ) + .unwrap(); + let leaf = Ucan::delegate( + &a, + node.did(), + vec![Capability::new(&new, caps::GIT_PUSH)], + Some(hour()), + &proof, + ) + .unwrap(); + assert!(leaf.verify_chain().is_ok()); + assert!(leaf.chain_grants_push_to(&owner_s, "r")); + + // The spelling is all that may differ: another repository is still + // not covered. + let other = format!("twigpine://repos/{owner_s}/other"); + assert!(Ucan::delegate( + &a, + node.did(), + vec![Capability::new(&other, caps::GIT_PUSH)], + Some(hour()), + &proof, + ) + .map(|u| u.verify_chain().is_err()) + .unwrap_or(true)); + } + #[test] fn chain_grants_push_only_when_every_link_names_the_repo() { let owner = Keypair::generate(); diff --git a/crates/twigpine-core/src/url_scheme.rs b/crates/twigpine-core/src/url_scheme.rs new file mode 100644 index 000000000..4586f3506 --- /dev/null +++ b/crates/twigpine-core/src/url_scheme.rs @@ -0,0 +1,106 @@ +//! The URL scheme of repository addresses and UCAN resources. +//! +//! It was `gitlawb://` before the rename to Twigpine and is `twigpine://` now. +//! Everything that reads one of these addresses accepts both, through the +//! functions here, so the rule lives in one place: +//! +//! - remote URLs: `twigpine:///` or `gitlawb:///`. +//! Git picks the helper by scheme, and every install ships both +//! `git-remote-twigpine` and `git-remote-gitlawb`. +//! - UCAN resources: `twigpine://repos//` or `gitlawb://repos/...`. +//! The two spellings name the same repository, so a delegation chain may mix +//! them and still attenuate. +//! +//! Writers still produce the old scheme. They switch in a later release, once +//! the readers here have shipped: remote URLs when users have a helper that +//! reads both, UCAN resources once every node on the network does. See +//! `docs/LEGACY-NAMES.md`. + +/// The scheme, without `://`. +pub const SCHEME: &str = "twigpine"; + +/// The scheme before the rename, still accepted everywhere. +pub const LEGACY_SCHEME: &str = "gitlawb"; + +/// Both schemes, current first, each with `://`. +const PREFIXES: [&str; 2] = ["twigpine://", "gitlawb://"]; + +/// What follows the scheme in a remote URL, or `None` when `url` uses neither +/// scheme. Matched exactly, as before the rename: `GITLAWB://` was never a +/// repository address. +pub fn strip_scheme(url: &str) -> Option<&str> { + PREFIXES.iter().find_map(|prefix| url.strip_prefix(prefix)) +} + +/// What follows `://repos/` in a UCAN resource, or `None` for any other +/// shape. +pub fn strip_resource_prefix(with: &str) -> Option<&str> { + strip_scheme(with)?.strip_prefix("repos/") +} + +/// Whether two UCAN resources name the same thing: equal, or equal after +/// reading past either scheme. Any other difference, including case, keeps +/// them apart. +pub fn same_resource(a: &str, b: &str) -> bool { + if a == b { + return true; + } + match (strip_resource_prefix(a), strip_resource_prefix(b)) { + (Some(x), Some(y)) => x == y, + _ => false, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn both_schemes_are_read_and_nothing_else() { + assert_eq!( + strip_scheme("twigpine://did:key:z6Mk/r"), + Some("did:key:z6Mk/r") + ); + assert_eq!( + strip_scheme("gitlawb://did:key:z6Mk/r"), + Some("did:key:z6Mk/r") + ); + for other in [ + "https://node.twigpine.com/r", + "TWIGPINE://did:key:z6Mk/r", + "twigpine:/did:key:z6Mk/r", + "xtwigpine://did:key:z6Mk/r", + "", + ] { + assert_eq!(strip_scheme(other), None, "{other:?}"); + } + } + + #[test] + fn resources_under_either_scheme() { + assert_eq!(strip_resource_prefix("twigpine://repos/o/r"), Some("o/r")); + assert_eq!(strip_resource_prefix("gitlawb://repos/o/r"), Some("o/r")); + assert_eq!(strip_resource_prefix("twigpine://o/r"), None); + assert_eq!(strip_resource_prefix("*"), None); + } + + #[test] + fn the_two_spellings_of_a_resource_are_the_same_resource() { + assert!(same_resource("gitlawb://repos/o/r", "twigpine://repos/o/r")); + assert!(same_resource( + "twigpine://repos/o/r", + "twigpine://repos/o/r" + )); + assert!(same_resource("*", "*")); + assert!(!same_resource( + "gitlawb://repos/o/r", + "twigpine://repos/o/other" + )); + assert!(!same_resource( + "gitlawb://repos/o/r", + "twigpine://repos/O/r" + )); + assert!(!same_resource("*", "twigpine://repos/o/r")); + assert!(!same_resource("https://repos/o/r", "twigpine://repos/o/r")); + } +} diff --git a/crates/twigpine-node/src/ans104.rs b/crates/twigpine-node/src/ans104.rs index 07819a65e..201ab8c8a 100644 --- a/crates/twigpine-node/src/ans104.rs +++ b/crates/twigpine-node/src/ans104.rs @@ -999,6 +999,7 @@ mod tests { fn sample_tags() -> Vec<(&'static [u8], &'static [u8])> { vec![ + // Written under the old name until the writers switch: see docs/LEGACY-NAMES.md. (b"App-Name", b"gitlawb"), (b"Schema", b"gitlawb/ref-update/v1"), ] diff --git a/crates/twigpine-node/src/api/repos.rs b/crates/twigpine-node/src/api/repos.rs index aab1d4f44..7af38a666 100644 --- a/crates/twigpine-node/src/api/repos.rs +++ b/crates/twigpine-node/src/api/repos.rs @@ -5907,6 +5907,7 @@ impl Drop for IntentDropGuard { /// no internal refs yet. Extracted so the gate predicate is unit-testable; /// the handler denies any push naming such a ref before intent is written. fn ref_is_internal_namespace(ref_name: &str) -> bool { + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. ref_name == "refs/gitlawb" || ref_name.starts_with("refs/gitlawb/") } diff --git a/crates/twigpine-node/src/api/task_cursor.rs b/crates/twigpine-node/src/api/task_cursor.rs index 5c0b542d5..acace876a 100644 --- a/crates/twigpine-node/src/api/task_cursor.rs +++ b/crates/twigpine-node/src/api/task_cursor.rs @@ -55,6 +55,7 @@ use crate::error::AppError; type HmacSha256 = Hmac; const CURSOR_PREFIX: &str = "v1"; +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. const KEY_DERIVATION_LABEL: &[u8] = b"gitlawb/tasks-cursor-key/v1"; const TAG_DOMAIN: &[u8] = b"gitlawb/tasks-cursor-tag/v1"; const STREAM_DOMAIN: &[u8] = b"gitlawb/tasks-cursor-stream/v1"; diff --git a/crates/twigpine-node/src/auth/mod.rs b/crates/twigpine-node/src/auth/mod.rs index 2f53a7520..2f97865cb 100644 --- a/crates/twigpine-node/src/auth/mod.rs +++ b/crates/twigpine-node/src/auth/mod.rs @@ -995,7 +995,7 @@ fn human_detected(message: &str) -> impl IntoResponse { [ ( "WWW-Authenticate", - "Signature realm=\"gitlawb-alpha\", alg=\"ed25519\"", + "Signature realm=\"twigpine-alpha\", alg=\"ed25519\"", ), ("X-Twigpine-Error", "human_detected"), ], diff --git a/crates/twigpine-node/src/encrypted_pin.rs b/crates/twigpine-node/src/encrypted_pin.rs index d7af80b80..5749fee5a 100644 --- a/crates/twigpine-node/src/encrypted_pin.rs +++ b/crates/twigpine-node/src/encrypted_pin.rs @@ -25,6 +25,7 @@ type HmacSha256 = Hmac; /// Order-insensitive (the input `BTreeSet` is already sorted). pub fn recipients_tag(node_seed: &[u8; 32], dids: &BTreeSet) -> String { let mut mac = HmacSha256::new_from_slice(node_seed).expect("HMAC accepts any key length"); + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. mac.update(b"gitlawb/recipients-tag/v1"); for did in dids { mac.update(b"\n"); diff --git a/crates/twigpine-node/src/p2p/mod.rs b/crates/twigpine-node/src/p2p/mod.rs index da4e96309..4475199fc 100644 --- a/crates/twigpine-node/src/p2p/mod.rs +++ b/crates/twigpine-node/src/p2p/mod.rs @@ -32,6 +32,7 @@ use twigpine_core::identity::Keypair; use crate::db::{Db, PeerWriteDenied, ReceivedRefUpdate}; /// Topic for ref-update notifications published after every push. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. pub const REF_UPDATES_TOPIC: &str = "gitlawb/ref-updates/v1"; /// Pre-parse budget, keyed on the mesh peer that HANDED us the message: 2000 @@ -1661,6 +1662,7 @@ impl P2pHandle { /// Derive a stable Kademlia record key from a DID string. fn did_to_kad_key(did: &str) -> kad::RecordKey { + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. kad::RecordKey::new(&format!("/gitlawb/did/{did}").as_bytes()) } @@ -4135,8 +4137,9 @@ pub async fn start( ) .expect("gossipsub behaviour"); + // Informational: libp2p reports it to peers, and nothing compares it. let identify = identify::Behaviour::new(identify::Config::new( - "/gitlawb/1.0.0".to_string(), + "/twigpine/1.0.0".to_string(), local_key.public(), )); diff --git a/crates/twigpine-node/src/state.rs b/crates/twigpine-node/src/state.rs index 56fd7b91a..9a05e0fb7 100644 --- a/crates/twigpine-node/src/state.rs +++ b/crates/twigpine-node/src/state.rs @@ -19,6 +19,7 @@ const SCAN_TOKEN_KEY_SALT: &[u8] = b"gitlawb/hkdf-salt/ipfs-scan-token"; /// trailing version rotates every node's token key on its next boot, which invalidates /// outstanding continuations (they simply fail to open and the caller restarts at the /// front) and needs no migration, no config, and no change to this function. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. const SCAN_TOKEN_KEY_INFO: &[u8] = b"gitlawb/ipfs-scan-token/v1"; /// HKDF salt for [`AppState::derive_webhook_secret_key`]. A constant, not a @@ -32,6 +33,7 @@ const WEBHOOK_SECRET_KEY_SALT: &[u8] = b"gitlawb/hkdf-salt/webhook-secret"; /// rotation: sealed secrets persist, `open` has no old-key fallback, and a new /// version renders every stored ciphertext permanently unopenable until a /// re-seal path exists. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. const WEBHOOK_SECRET_KEY_INFO: &[u8] = b"gitlawb/webhook-secret/v1"; #[derive(Clone, Debug)] diff --git a/docs/LEGACY-NAMES.md b/docs/LEGACY-NAMES.md new file mode 100644 index 000000000..8f1eaf8c4 --- /dev/null +++ b/docs/LEGACY-NAMES.md @@ -0,0 +1,57 @@ +# Names from before the rename + +The project was called Gitlawb before it was renamed to Twigpine. Most of the +old name is gone from the code. What remains is listed here, each with the +reason it stays and when, if ever, it goes. Anything not on this list that +still says "gitlawb" is an oversight. + +## Kept permanently + +These are machine identifiers that people do not see, that every node on the +network has to agree on, or that are baked into signed or stored data. Renaming +them would need every node, including ones we do not run, to change in step, +and would buy nothing a user can see. + +| Name | Where | Why it stays | +|---|---|---| +| `refs/gitlawb/*` | `twigpine-node`: the internal-ref gate in `api/repos.rs`, `hideRefs` in `git/store.rs`, the mirror prune in `sync.rs`, issues in `git/issues.rs` | The namespace holds node-managed data (issues, request markers) in every repository, and nodes copy it from each other with `+refs/*:refs/*`. Renaming it means migrating that data on every node; during the change an older node would treat the new namespace as ordinary user refs. | +| `gitlawb/ref-update/v1` | `twigpine-core/src/cert.rs` (`CERT_TYPE`), and the Arweave `Schema` tag in `twigpine-node/src/ans104.rs` and `arweave.rs` | Signed into every ref-update certificate. Peers refuse a type they do not know, and certificates already signed and anchored carry this one forever. | +| `gitlawb/encrypted-manifest/v1` | `twigpine-node/src/arweave.rs`, CLI Arweave discovery in `clone.rs` | Schema of anchored manifests, stored permanently. | +| `gitlawb/ref-updates/v1` | `twigpine-node/src/p2p/mod.rs` (`REF_UPDATES_TOPIC`) | The gossip topic. A node on another topic hears nothing. | +| `/gitlawb/did/` | `twigpine-node/src/p2p/mod.rs` (DHT record key) | Key prefix of DHT records other nodes look up. | +| `gitlawb/webhook-secret/v1`, `gitlawb/ipfs-scan-token/v1` | `twigpine-node/src/state.rs` | Key-derivation labels. Webhook secrets at rest are sealed under a key derived with this label; changing it means re-sealing them. | +| `gitlawb/recipients-tag/v1` | `twigpine-node/src/encrypted_pin.rs` | Tag over the recipient list of encrypted pins already stored. | +| `gitlawb/tasks-cursor-key/v1`, `-tag/v1`, `-stream/v1` | `twigpine-node/src/api/task_cursor.rs` | Key derivation and domain separation for task-list cursors. | +| `gitlawb-attest-sig/v1` | `twigpine-attest` (`SIGNING_DOMAIN`) | Signing domain of attestations; pinned by the canonical-vector tests. | +| `did:gitlawb` | `twigpine-core/src/did.rs` | A DID method the code accepts. Nothing creates one. Renaming an identity method is its own decision, not part of the rename. | + +## Read under both names, written under the old one for now + +Readers accept both spellings today. Writers switch in a later release, once +enough of the network reads the new one. + +| Name | Read | Written by | Writers switch | +|---|---|---|---| +| `gitlawb://` remote URLs | Helper and CLI, through `twigpine_core::url_scheme` | `twigpine clone`, `init`, `repo`, `mirror`, `quickstart`, the MCP tools | The release after the one that reads both. Client-side only: every install ships the helper under both names. | +| `gitlawb://repos//` UCAN resources | Node and helper, through `twigpine_core::url_scheme`; the two spellings attenuate as one resource | `twigpine ucan delegate`, the MCP tools | Once every bootstrap peer runs a release that reads both. The node hosting a repository is the one that checks it. | +| Arweave `App-Name: gitlawb` | CLI discovery queries both values | `twigpine-node/src/ans104.rs` | The release after the one that reads both. | +| The git remote named `gitlawb` | `twigpine status` looks for both names | `twigpine init` | With the remote URLs. | + +## Temporary fallbacks, removed in 1.0 + +| Name | Where | +|---|---| +| `GITLAWB_*` settings | `twigpine-core/src/legacy_env.rs`, the Docker image's `ENV` defaults, `install.sh`, `install.ps1`, `docker-compose.yml` | +| `~/.gitlawb` | `twigpine-core/src/identity_path.rs` | +| `X-Gitlawb-*` headers | `twigpine-core/src/legacy_headers.rs` | +| `gl`, `git-remote-gitlawb`, `gitlawb-node` command names | Installers, Homebrew formula, Docker image, npm package. `git-remote-gitlawb` stays as long as `gitlawb://` remotes exist. | + +## Not decided yet + +- `gitlawb_*` metric names, with the infra change and whatever dashboards read them. +- `infra/`, the macOS app and `bootstrap-peers.json`, which still set the old + setting names and work through the fallback. + +## Not ours + +- `rapybus-gitlawb.com`, a host run by another operator. diff --git a/npm/packages/gl/install.js b/npm/packages/gl/install.js index 2a2c3d579..7e5b98239 100644 --- a/npm/packages/gl/install.js +++ b/npm/packages/gl/install.js @@ -84,6 +84,12 @@ function install() { copyFileSync(join(binDir, "gl"), renamed); chmodSync(renamed, 0o755); + // Git picks its remote helper by URL scheme: `git-remote-twigpine` runs + // twigpine:// remotes, `git-remote-gitlawb` runs gitlawb:// ones. + const helper = join(binDir, "git-remote-twigpine"); + copyFileSync(join(binDir, "git-remote-gitlawb"), helper); + chmodSync(helper, 0o755); + console.log(`@gitlawb/gl: Installed Twigpine CLI for ${platformKey}`); } diff --git a/npm/packages/gl/package.json b/npm/packages/gl/package.json index d6a160a91..96d720d11 100644 --- a/npm/packages/gl/package.json +++ b/npm/packages/gl/package.json @@ -7,7 +7,8 @@ "twigpine": "bin/twigpine", "twig": "bin/twigpine", "gl": "bin/gl", - "git-remote-gitlawb": "bin/git-remote-gitlawb" + "git-remote-gitlawb": "bin/git-remote-gitlawb", + "git-remote-twigpine": "bin/git-remote-twigpine" }, "scripts": { "postinstall": "node install.js" From 5afaefc85f9f3c3c7af5f3414eea6de42ebda2ad Mon Sep 17 00:00:00 2001 From: Kevin Codex Date: Wed, 18 Nov 2026 11:53:59 +0800 Subject: [PATCH 2/4] fix: review follow-ups for the protocol names, and npm commands that were never linked - npm: the published @gitlawb/gl links no commands at all. npm links each command before the install step runs and skips any whose file is missing, and bin/ shipped empty. The wrapper now ships a placeholder at every command path; install.js overwrites them with the real programs. Checked by installing a packed wrapper into a scratch prefix: before, nothing on PATH; after, twigpine, twig, gl and both helper names, each running the real binary. - Ucan::can follows the same resource rule as attenuation. - docs/LEGACY-NAMES.md: the Arweave App-Name writer is arweave.rs; adds the stored names it missed (HKDF salts, signature-ledger labels, push-event cursors, object metadata key, reflog action, the attest cert type, the bootstrap resource); UCAN resources keep the old spelling, since the node a user pushes to checks them and may be one we do not run. - Remaining user-facing old wording in doctor, quickstart, register and the helper's help text and package description. - Remote-URL parsing in changelog and pr split into pure functions with tests; changelog drops one trailing .git. Tests for the new scheme in status, clone and ucan delegate, and a tighter mixed-chain test. --- crates/git-remote-twigpine/Cargo.toml | 2 +- crates/git-remote-twigpine/src/main.rs | 21 +++++---- crates/twigpine-attest/src/cert.rs | 1 + crates/twigpine-cli/src/changelog.rs | 43 ++++++++++++++++++- crates/twigpine-cli/src/clone.rs | 6 +++ crates/twigpine-cli/src/doctor.rs | 6 +-- crates/twigpine-cli/src/pr.rs | 24 ++++++++++- crates/twigpine-cli/src/quickstart.rs | 2 +- crates/twigpine-cli/src/register.rs | 2 +- crates/twigpine-cli/src/status.rs | 8 ++++ crates/twigpine-cli/src/ucan_cmd.rs | 14 ++++++ .../tests/doctor_transport_node.rs | 6 +-- crates/twigpine-core/src/ucan.rs | 22 +++++++--- crates/twigpine-core/src/url_scheme.rs | 7 ++- crates/twigpine-node/src/ans104.rs | 1 - crates/twigpine-node/src/api/events.rs | 1 + crates/twigpine-node/src/api/repos.rs | 1 + crates/twigpine-node/src/arweave.rs | 2 + crates/twigpine-node/src/auth/mod.rs | 2 + crates/twigpine-node/src/git/publish.rs | 1 + crates/twigpine-node/src/state.rs | 2 + docs/LEGACY-NAMES.md | 38 +++++++++------- npm/.gitignore | 6 +-- npm/packages/gl/bin/git-remote-gitlawb | 8 ++++ npm/packages/gl/bin/git-remote-twigpine | 8 ++++ npm/packages/gl/bin/gl | 8 ++++ npm/packages/gl/bin/twigpine | 8 ++++ 27 files changed, 199 insertions(+), 51 deletions(-) create mode 100755 npm/packages/gl/bin/git-remote-gitlawb create mode 100755 npm/packages/gl/bin/git-remote-twigpine create mode 100755 npm/packages/gl/bin/gl create mode 100755 npm/packages/gl/bin/twigpine diff --git a/crates/git-remote-twigpine/Cargo.toml b/crates/git-remote-twigpine/Cargo.toml index b5702e2e8..b50a85831 100644 --- a/crates/git-remote-twigpine/Cargo.toml +++ b/crates/git-remote-twigpine/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git-remote-twigpine" -description = "Git remote helper — enables 'git clone gitlawb://did:gitlawb:...'" +description = "Git remote helper — enables 'git clone twigpine://did:key:...'" version = "0.7.1" # x-release-please-version edition.workspace = true rust-version.workspace = true diff --git a/crates/git-remote-twigpine/src/main.rs b/crates/git-remote-twigpine/src/main.rs index 97373f452..1f2b5d9ca 100644 --- a/crates/git-remote-twigpine/src/main.rs +++ b/crates/git-remote-twigpine/src/main.rs @@ -1,11 +1,13 @@ -//! git-remote-twigpine — git remote helper for gitlawb:// URLs +//! git-remote-twigpine — git remote helper for twigpine:// URLs //! -//! Git calls this binary when it encounters a remote URL with the "gitlawb://" scheme. -//! It implements the git remote helper protocol, translating gitlawb:// URLs into -//! HTTP smart-protocol requests against a twigpine-node. +//! Git calls this binary when it encounters a remote URL with the "twigpine://" +//! scheme, and runs it as `git-remote-gitlawb` for the "gitlawb://" spelling +//! from before the rename. It implements the git remote helper protocol, +//! translating those URLs into HTTP smart-protocol requests against a +//! twigpine-node. //! //! # URL format -//! gitlawb://did:key:z6Mk.../repo-name +//! twigpine://did:key:z6Mk.../repo-name (or gitlawb://...) //! //! # v0.1 resolution //! DID → http://127.0.0.1:7545 (hardcoded; v0.2 will use DHT) @@ -207,11 +209,12 @@ fn help_text() -> String { format!( "{}\n\ \n\ - Git remote helper for gitlawb:// URLs. Git invokes this automatically\n\ - when it encounters a gitlawb:// remote; you normally do not run it directly.\n\ + Git remote helper for twigpine:// URLs, and for gitlawb:// from before the\n\ + rename. Git invokes it automatically for such a remote; you normally do not\n\ + run it directly.\n\ \n\ USAGE:\n\ - \x20 git clone gitlawb://did:key:z6Mk.../\n\ + \x20 git clone twigpine://did:key:z6Mk.../\n\ \n\ ENVIRONMENT:\n\ \x20 TWIGPINE_NODE Node base URL (default: {DEFAULT_LOCAL_NODE})\n\ @@ -780,7 +783,7 @@ fn build_pack_post_request( /// Returns `(did_string, short_owner, repo_name)`. fn parse_gitlawb_url(url: &str) -> Result<(String, String, String)> { let without_scheme = twigpine_core::url_scheme::strip_scheme(url) - .ok_or_else(|| anyhow::anyhow!("not a twigpine:// URL: {url}"))?; + .ok_or_else(|| anyhow::anyhow!("not a twigpine:// or gitlawb:// URL: {url}"))?; // without_scheme = "did:key:z6Mk.../repo-name" let (did_string, repo_name) = without_scheme diff --git a/crates/twigpine-attest/src/cert.rs b/crates/twigpine-attest/src/cert.rs index 74c89a622..874b0e9ce 100644 --- a/crates/twigpine-attest/src/cert.rs +++ b/crates/twigpine-attest/src/cert.rs @@ -14,6 +14,7 @@ use crate::verifier::{Registry, VerifiedAttestation}; /// The discriminator the wrapped cert must carry. Matches the constant of the /// same name in `twigpine-core::cert`. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. pub const CERT_TYPE: &str = "gitlawb/ref-update/v1"; /// A ref-update cert with optional attestations. diff --git a/crates/twigpine-cli/src/changelog.rs b/crates/twigpine-cli/src/changelog.rs index 7c473c441..244951b15 100644 --- a/crates/twigpine-cli/src/changelog.rs +++ b/crates/twigpine-cli/src/changelog.rs @@ -110,15 +110,54 @@ fn detect_repo_from_remote() -> Option { if !out.status.success() { return None; } - let url = String::from_utf8(out.stdout).ok()?; + repo_from_remote_url(&String::from_utf8(out.stdout).ok()?) +} + +/// `twigpine://did:key:z6Mk.../repo[.git]` (or `gitlawb://...`) → `z6Mk.../repo`. +/// One trailing `.git` is dropped, as the node's own names have none. +fn repo_from_remote_url(url: &str) -> Option { let rest = twigpine_core::url_scheme::strip_scheme(url.trim())?; let slash = rest.rfind('/')?; let did = &rest[..slash]; - let repo = &rest[slash + 1..]; + let repo = twigpine_core::ucan::push::canonical_repo_name(&rest[slash + 1..]); + if did.is_empty() || repo.is_empty() { + return None; + } let short_did = did.split(':').next_back().unwrap_or(did); Some(format!("{short_did}/{repo}")) } +#[cfg(test)] +mod remote_url_tests { + use super::repo_from_remote_url; + + #[test] + fn either_scheme_and_one_git_suffix() { + for url in [ + "twigpine://did:key:z6MkA/repo\n", + "gitlawb://did:key:z6MkA/repo", + "twigpine://did:key:z6MkA/repo.git", + ] { + assert_eq!( + repo_from_remote_url(url).as_deref(), + Some("z6MkA/repo"), + "{url:?}" + ); + } + assert_eq!( + repo_from_remote_url("twigpine://did:key:z6MkA/foo.git.git").as_deref(), + Some("z6MkA/foo.git") + ); + for bad in [ + "https://x/did/repo", + "twigpine://", + "twigpine://did:key:z6MkA/", + ] { + assert_eq!(repo_from_remote_url(bad), None, "{bad:?}"); + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/twigpine-cli/src/clone.rs b/crates/twigpine-cli/src/clone.rs index 08b93243f..246923800 100644 --- a/crates/twigpine-cli/src/clone.rs +++ b/crates/twigpine-cli/src/clone.rs @@ -2226,6 +2226,12 @@ mod tests { let (url2, o2, n2) = parse_repo("did:key:zAbc/myrepo").unwrap(); assert_eq!(url2, "gitlawb://did:key:zAbc/myrepo"); assert_eq!((o2.as_str(), n2.as_str()), ("did:key:zAbc", "myrepo")); + + // The new scheme is read; the remote is still written under the old + // one until writers switch (docs/LEGACY-NAMES.md). + let (url3, o3, n3) = parse_repo("twigpine://did:key:zAbc/myrepo").unwrap(); + assert_eq!(url3, "gitlawb://did:key:zAbc/myrepo"); + assert_eq!((o3.as_str(), n3.as_str()), ("did:key:zAbc", "myrepo")); } #[test] diff --git a/crates/twigpine-cli/src/doctor.rs b/crates/twigpine-cli/src/doctor.rs index 4a10a3475..8acbd289c 100644 --- a/crates/twigpine-cli/src/doctor.rs +++ b/crates/twigpine-cli/src/doctor.rs @@ -504,7 +504,7 @@ async fn probe_transport(url: &str) -> TransportVerdict { if body.truncated || body.read_failed { return TransportVerdict { usable: false, - detail: "response too large or incomplete for a gitlawb node".to_string(), + detail: "response too large or incomplete for a Twigpine node".to_string(), }; } let info = serde_json::from_slice::(&body.bytes).unwrap_or_default(); @@ -519,7 +519,7 @@ async fn probe_transport(url: &str) -> TransportVerdict { } else { TransportVerdict { usable: false, - detail: "something is listening but it is not a gitlawb node".to_string(), + detail: "something is listening but it is not a Twigpine node".to_string(), } } } @@ -598,7 +598,6 @@ fn is_loopback_url(value: &str) -> bool { .unwrap_or(false) } -/// Check if a binary name exists anywhere on PATH. /// The git helper row. Git runs `git-remote-gitlawb` for `gitlawb://` remotes, /// which is what every remote created so far uses, so without it clone and push /// fail now: a failure. `git-remote-twigpine` runs `twigpine://` remotes, which @@ -620,6 +619,7 @@ fn helper_check(has_old_name: bool, has_new_name: bool) -> Check { } } +/// Check if a binary name exists anywhere on PATH. fn which_in_path(name: &str) -> bool { std::env::var_os("PATH") .map(|paths| { diff --git a/crates/twigpine-cli/src/pr.rs b/crates/twigpine-cli/src/pr.rs index 5874de05c..f010be0ab 100644 --- a/crates/twigpine-cli/src/pr.rs +++ b/crates/twigpine-cli/src/pr.rs @@ -229,7 +229,11 @@ fn detect_remote_owner() -> Option { if !out.status.success() { return None; } - let url = String::from_utf8(out.stdout).ok()?; + owner_from_remote_url(&String::from_utf8(out.stdout).ok()?) +} + +/// `twigpine://did:key:z6Mk.../repo` (or `gitlawb://...`) → `z6Mk...`. +fn owner_from_remote_url(url: &str) -> Option { let rest = twigpine_core::url_scheme::strip_scheme(url.trim())?; let slash = rest.rfind('/')?; let did = &rest[..slash]; @@ -583,6 +587,24 @@ async fn cmd_comments(repo: String, number: u64, node: String, dir: Option Result<()> { println!(" ✓ Repository created"); println!(); println!("══════════════════════════════════════════════════════════════════════"); - println!(" You're set up on gitlawb."); + println!(" You're set up on Twigpine."); println!(); println!(" Your DID: {did}"); println!(" Node: {}", args.node); diff --git a/crates/twigpine-cli/src/register.rs b/crates/twigpine-cli/src/register.rs index 720352be1..df4431d28 100644 --- a/crates/twigpine-cli/src/register.rs +++ b/crates/twigpine-cli/src/register.rs @@ -110,7 +110,7 @@ pub async fn run(args: RegisterArgs) -> Result<()> { match &saved_to { Some(path) => { println!(" Bootstrap UCAN saved to {}", path.display()); - println!(" You are now a verified agent on the gitlawb network."); + println!(" You are now a verified agent on the Twigpine network."); } None => { println!(" The node returned no bootstrap UCAN, so this identity is not"); diff --git a/crates/twigpine-cli/src/status.rs b/crates/twigpine-cli/src/status.rs index 70771b037..2f6198420 100644 --- a/crates/twigpine-cli/src/status.rs +++ b/crates/twigpine-cli/src/status.rs @@ -256,6 +256,14 @@ fn parse_gitlawb_url(url: &str) -> Option<(String, String)> { mod tests { use super::*; + #[test] + fn parse_url_under_the_new_scheme() { + assert_eq!( + parse_gitlawb_url("twigpine://did:key:z6Mk1234/myrepo"), + Some(("did:key:z6Mk1234".to_string(), "myrepo".to_string())) + ); + } + #[test] fn parse_simple_gitlawb_url() { let result = parse_gitlawb_url("gitlawb://did:key:z6Mk1234/myrepo"); diff --git a/crates/twigpine-cli/src/ucan_cmd.rs b/crates/twigpine-cli/src/ucan_cmd.rs index a53199c62..c5c23dffd 100644 --- a/crates/twigpine-cli/src/ucan_cmd.rs +++ b/crates/twigpine-cli/src/ucan_cmd.rs @@ -993,6 +993,20 @@ async fn cmd_verify(token: String) -> Result<()> { #[cfg(test)] mod tests { + #[test] + fn a_resource_typed_with_the_new_scheme_is_issued_under_the_old_one() { + // UCAN resources keep the old spelling: the node hosting a repository + // checks it, and that node may not read the new one yet. + assert_eq!( + super::canonical_resource("twigpine://repos/did:key:z6MkA/r.git"), + "gitlawb://repos/did:key:z6MkA/r" + ); + assert_eq!( + super::canonical_resource("gitlawb://repos/did:key:z6MkA/r"), + "gitlawb://repos/did:key:z6MkA/r" + ); + } + use super::*; use tempfile::TempDir; use twigpine_core::identity::Keypair; diff --git a/crates/twigpine-cli/tests/doctor_transport_node.rs b/crates/twigpine-cli/tests/doctor_transport_node.rs index d20f125db..5ab0e4e13 100644 --- a/crates/twigpine-cli/tests/doctor_transport_node.rs +++ b/crates/twigpine-cli/tests/doctor_transport_node.rs @@ -233,7 +233,7 @@ fn unset_env_with_flag_equal_to_transport_default_still_warns_not_set() { } /// The bug this check exists to prevent, one level down: something answering 200 -/// on the transport port is not proof a gitlawb node is there. Reporting it as a +/// on the transport port is not proof a Twigpine node is there. Reporting it as a /// healthy transport is the same false green doctor already shipped once. #[test] fn a_non_gitlawb_200_is_not_a_healthy_transport() { @@ -267,7 +267,7 @@ fn a_non_gitlawb_200_is_not_a_healthy_transport() { // Positive assertion: only the identity check can produce this text, so the // test cannot pass by the probe quietly failing instead. assert!( - line.contains("not a gitlawb node"), + line.contains("not a Twigpine node"), "a non-gitlawb 200 must be called out, not reported reachable, got: {line}" ); } @@ -585,7 +585,7 @@ fn an_empty_or_malformed_did_is_not_a_healthy_transport() { .divergence_line() .unwrap_or_else(|| panic!("no row for {body}:\n{}", r.stdout)); assert!( - line.contains("not a gitlawb node"), + line.contains("not a Twigpine node"), "{body} must not read as healthy, got: {line}" ); } diff --git a/crates/twigpine-core/src/ucan.rs b/crates/twigpine-core/src/ucan.rs index d4e2e2a71..4d9da2521 100644 --- a/crates/twigpine-core/src/ucan.rs +++ b/crates/twigpine-core/src/ucan.rs @@ -413,7 +413,8 @@ impl Ucan { /// exactly that capability (see `is_attenuated_by`). pub fn can(&self, resource: &str, action: &str) -> bool { self.payload.att.iter().any(|cap| { - let resource_ok = cap.with == resource || cap.with == "*"; + let resource_ok = + crate::url_scheme::same_resource(&cap.with, resource) || cap.with == "*"; let action_ok = cap.can == action || cap.can == "*" || cap.can == caps::REPO_ADMIN; resource_ok && action_ok }) @@ -1262,9 +1263,6 @@ mod push_scope_tests { ); } - /// The chain walk, at every depth: a wildcard anywhere denies; concrete - /// everywhere grants. The grandparent case is the one a single-level check - /// misses, because the immediate proof already names the repo. #[test] fn a_chain_mixing_the_two_resource_spellings_verifies_and_grants() { let owner = Keypair::generate(); @@ -1296,17 +1294,27 @@ mod push_scope_tests { // The spelling is all that may differ: another repository is still // not covered. let other = format!("twigpine://repos/{owner_s}/other"); - assert!(Ucan::delegate( + let stray = Ucan::delegate( &a, node.did(), vec![Capability::new(&other, caps::GIT_PUSH)], Some(hour()), &proof, ) - .map(|u| u.verify_chain().is_err()) - .unwrap_or(true)); + .unwrap(); + assert!(stray.verify_chain().is_err()); + assert!(!stray.chain_grants_push_to(&owner_s, "other")); + assert!(!leaf.chain_grants_push_to(&owner_s, "other")); + + // `Ucan::can` follows the same rule. + assert!(leaf.can(&old, caps::GIT_PUSH)); + assert!(leaf.can(&new, caps::GIT_PUSH)); + assert!(!leaf.can(&other, caps::GIT_PUSH)); } + /// The chain walk, at every depth: a wildcard anywhere denies; concrete + /// everywhere grants. The grandparent case is the one a single-level check + /// misses, because the immediate proof already names the repo. #[test] fn chain_grants_push_only_when_every_link_names_the_repo() { let owner = Keypair::generate(); diff --git a/crates/twigpine-core/src/url_scheme.rs b/crates/twigpine-core/src/url_scheme.rs index 4586f3506..ba94177ec 100644 --- a/crates/twigpine-core/src/url_scheme.rs +++ b/crates/twigpine-core/src/url_scheme.rs @@ -11,10 +11,9 @@ //! The two spellings name the same repository, so a delegation chain may mix //! them and still attenuate. //! -//! Writers still produce the old scheme. They switch in a later release, once -//! the readers here have shipped: remote URLs when users have a helper that -//! reads both, UCAN resources once every node on the network does. See -//! `docs/LEGACY-NAMES.md`. +//! Writers still produce the old scheme. Remote URLs switch in a later release; +//! UCAN resources keep it, because the node a user pushes to checks them and +//! may be one we do not run. See `docs/LEGACY-NAMES.md`. /// The scheme, without `://`. pub const SCHEME: &str = "twigpine"; diff --git a/crates/twigpine-node/src/ans104.rs b/crates/twigpine-node/src/ans104.rs index 201ab8c8a..07819a65e 100644 --- a/crates/twigpine-node/src/ans104.rs +++ b/crates/twigpine-node/src/ans104.rs @@ -999,7 +999,6 @@ mod tests { fn sample_tags() -> Vec<(&'static [u8], &'static [u8])> { vec![ - // Written under the old name until the writers switch: see docs/LEGACY-NAMES.md. (b"App-Name", b"gitlawb"), (b"Schema", b"gitlawb/ref-update/v1"), ] diff --git a/crates/twigpine-node/src/api/events.rs b/crates/twigpine-node/src/api/events.rs index fb2d76eaf..3c00eb491 100644 --- a/crates/twigpine-node/src/api/events.rs +++ b/crates/twigpine-node/src/api/events.rs @@ -361,6 +361,7 @@ const PUSH_CURSOR_VERSION: &str = "1"; fn push_cursor_tag(node_did: &str, repo_id: &str) -> String { use sha2::{Digest, Sha256}; let mut h = Sha256::new(); + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. h.update(b"gitlawb-push-cursor:v1:"); h.update(node_did.as_bytes()); h.update([0u8]); diff --git a/crates/twigpine-node/src/api/repos.rs b/crates/twigpine-node/src/api/repos.rs index 7af38a666..bfe73d249 100644 --- a/crates/twigpine-node/src/api/repos.rs +++ b/crates/twigpine-node/src/api/repos.rs @@ -3127,6 +3127,7 @@ pub async fn git_receive_pack( // fixed `push` message and ignores GIT_REFLOG_ACTION); causality // still relies on marker + tuple/timestamp + history guards. Marker // namespace hiding was verified above by `verify_recovery_prereqs`. + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. let reflog_action = format!("gitlawb-request:{request_id}"); // Phase-flip the drop-guard: git is about to start, so a dropped future // from here forward is a mid-git disconnect (not a pre-git shed). The diff --git a/crates/twigpine-node/src/arweave.rs b/crates/twigpine-node/src/arweave.rs index 0fe3e56cd..76383eaad 100644 --- a/crates/twigpine-node/src/arweave.rs +++ b/crates/twigpine-node/src/arweave.rs @@ -196,6 +196,7 @@ fn manifest_blob_json(oid: &str, cid: &str) -> serde_json::Value { /// are the tags the `twigpine` recovery query filters on. fn build_manifest_tags_header(manifest: &EncryptedManifest<'_>) -> String { [ + // Written under the old name until writers switch: see docs/LEGACY-NAMES.md. "App-Name:gitlawb".to_string(), "Schema:gitlawb/encrypted-manifest/v1".to_string(), format!("Repo:{}", sanitize_tag(manifest.repo)), @@ -214,6 +215,7 @@ pub fn arweave_url(tx_id: &str) -> String { /// Format: comma-separated "name:value" pairs. fn build_tags_header(anchor: &RefAnchor) -> String { [ + // Written under the old name until writers switch: see docs/LEGACY-NAMES.md. "App-Name:gitlawb".to_string(), "Schema:gitlawb/ref-update/v1".to_string(), format!("Repo:{}", sanitize_tag(&anchor.repo)), diff --git a/crates/twigpine-node/src/auth/mod.rs b/crates/twigpine-node/src/auth/mod.rs index 2f97865cb..eae95884f 100644 --- a/crates/twigpine-node/src/auth/mod.rs +++ b/crates/twigpine-node/src/auth/mod.rs @@ -708,12 +708,14 @@ fn ledger_key(identity: &SignatureIdentity) -> String { let mut hasher = Sha256::new(); match unique_nonce(identity) { Some(nonce) => { + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. hasher.update(b"gitlawb/sig-nonce\x00"); hasher.update(identity.key_fingerprint.as_bytes()); hasher.update(b"\x00"); hasher.update(nonce.as_bytes()); } None => { + // Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. hasher.update(b"gitlawb/sig-string\x00"); hasher.update(identity.signing_string_hash.as_bytes()); } diff --git a/crates/twigpine-node/src/git/publish.rs b/crates/twigpine-node/src/git/publish.rs index d1222a670..f4528b6a3 100644 --- a/crates/twigpine-node/src/git/publish.rs +++ b/crates/twigpine-node/src/git/publish.rs @@ -80,6 +80,7 @@ impl std::fmt::Display for PublishAttemptId { /// /// S3 lowercases user-metadata keys, so this must already be lowercase or the /// read back would never match what was written. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. pub const ATTEMPT_METADATA_KEY: &str = "gitlawb-attempt"; /// The precondition an upload is fenced on. diff --git a/crates/twigpine-node/src/state.rs b/crates/twigpine-node/src/state.rs index 9a05e0fb7..9deaef6c1 100644 --- a/crates/twigpine-node/src/state.rs +++ b/crates/twigpine-node/src/state.rs @@ -11,6 +11,7 @@ use crate::rate_limit::RateLimiter; /// HKDF salt for [`AppState::derive_scan_token_key`]. A constant, not a secret: HKDF's /// salt is a domain qualifier, and the confidentiality of the derived key rests entirely /// on the node's private seed being the input keying material. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. const SCAN_TOKEN_KEY_SALT: &[u8] = b"gitlawb/hkdf-salt/ipfs-scan-token"; /// HKDF `info` for [`AppState::derive_scan_token_key`]: the domain separation AND the @@ -25,6 +26,7 @@ const SCAN_TOKEN_KEY_INFO: &[u8] = b"gitlawb/ipfs-scan-token/v1"; /// HKDF salt for [`AppState::derive_webhook_secret_key`]. A constant, not a /// secret: the confidentiality of the derived key rests on the node's private /// seed being the input keying material, exactly as for the scan-token key. +// Kept from before the rename on purpose: see docs/LEGACY-NAMES.md. const WEBHOOK_SECRET_KEY_SALT: &[u8] = b"gitlawb/hkdf-salt/webhook-secret"; /// HKDF `info` for [`AppState::derive_webhook_secret_key`]: the domain diff --git a/docs/LEGACY-NAMES.md b/docs/LEGACY-NAMES.md index 8f1eaf8c4..a2c072cf0 100644 --- a/docs/LEGACY-NAMES.md +++ b/docs/LEGACY-NAMES.md @@ -2,40 +2,46 @@ The project was called Gitlawb before it was renamed to Twigpine. Most of the old name is gone from the code. What remains is listed here, each with the -reason it stays and when, if ever, it goes. Anything not on this list that -still says "gitlawb" is an oversight. +reason it stays and when, if ever, it goes. Each kept definition in the code +carries a comment pointing at this file. Anything not on this list that still +says "gitlawb" is an oversight. ## Kept permanently These are machine identifiers that people do not see, that every node on the network has to agree on, or that are baked into signed or stored data. Renaming them would need every node, including ones we do not run, to change in step, -and would buy nothing a user can see. +or would invalidate data already stored, and would buy nothing a user can see. | Name | Where | Why it stays | |---|---|---| | `refs/gitlawb/*` | `twigpine-node`: the internal-ref gate in `api/repos.rs`, `hideRefs` in `git/store.rs`, the mirror prune in `sync.rs`, issues in `git/issues.rs` | The namespace holds node-managed data (issues, request markers) in every repository, and nodes copy it from each other with `+refs/*:refs/*`. Renaming it means migrating that data on every node; during the change an older node would treat the new namespace as ordinary user refs. | -| `gitlawb/ref-update/v1` | `twigpine-core/src/cert.rs` (`CERT_TYPE`), and the Arweave `Schema` tag in `twigpine-node/src/ans104.rs` and `arweave.rs` | Signed into every ref-update certificate. Peers refuse a type they do not know, and certificates already signed and anchored carry this one forever. | -| `gitlawb/encrypted-manifest/v1` | `twigpine-node/src/arweave.rs`, CLI Arweave discovery in `clone.rs` | Schema of anchored manifests, stored permanently. | -| `gitlawb/ref-updates/v1` | `twigpine-node/src/p2p/mod.rs` (`REF_UPDATES_TOPIC`) | The gossip topic. A node on another topic hears nothing. | -| `/gitlawb/did/` | `twigpine-node/src/p2p/mod.rs` (DHT record key) | Key prefix of DHT records other nodes look up. | -| `gitlawb/webhook-secret/v1`, `gitlawb/ipfs-scan-token/v1` | `twigpine-node/src/state.rs` | Key-derivation labels. Webhook secrets at rest are sealed under a key derived with this label; changing it means re-sealing them. | +| `gitlawb/ref-update/v1` | `CERT_TYPE` in `twigpine-core/src/cert.rs` and `twigpine-attest/src/cert.rs`; the Arweave `Schema` tag written in `twigpine-node/src/arweave.rs` | Signed into every ref-update certificate. Peers refuse a type they do not know, and certificates already signed and anchored carry this one forever. | +| `gitlawb/encrypted-manifest/v1` | `twigpine-node/src/arweave.rs`; CLI Arweave discovery in `clone.rs` | Schema of anchored manifests, stored permanently. | +| `gitlawb/ref-updates/v1` | `REF_UPDATES_TOPIC` in `twigpine-node/src/p2p/mod.rs` | The gossip topic. A node on another topic hears nothing. | +| `/gitlawb/did/` | DHT record key in `twigpine-node/src/p2p/mod.rs` | Key prefix of DHT records other nodes look up. | +| `gitlawb/hkdf-salt/webhook-secret`, `gitlawb/webhook-secret/v1` | `twigpine-node/src/state.rs` | Salt and label of the key that seals webhook secrets at rest. Changing either means re-sealing every stored secret. | +| `gitlawb/hkdf-salt/ipfs-scan-token`, `gitlawb/ipfs-scan-token/v1` | `twigpine-node/src/state.rs` | Salt and label of the scan-token key. Changing them is safe (outstanding tokens would simply be re-issued) but buys nothing; kept beside the webhook pair for consistency. | +| `gitlawb/sig-nonce`, `gitlawb/sig-string` | Signature-ledger hashing in `twigpine-node/src/auth/mod.rs` | Domain labels of replay-ledger entries. Changing them across an upgrade would let a signature seen just before the upgrade be replayed just after it, within the signature-age window. | | `gitlawb/recipients-tag/v1` | `twigpine-node/src/encrypted_pin.rs` | Tag over the recipient list of encrypted pins already stored. | | `gitlawb/tasks-cursor-key/v1`, `-tag/v1`, `-stream/v1` | `twigpine-node/src/api/task_cursor.rs` | Key derivation and domain separation for task-list cursors. | -| `gitlawb-attest-sig/v1` | `twigpine-attest` (`SIGNING_DOMAIN`) | Signing domain of attestations; pinned by the canonical-vector tests. | +| `gitlawb-push-cursor:v1:` | `twigpine-node/src/api/events.rs` | Domain prefix of push-event cursors that clients hold. | +| `gitlawb-attest-sig/v1` | `SIGNING_DOMAIN` in `twigpine-attest/src/attestation.rs` | Signing domain of attestations; pinned by the canonical-vector tests. | +| `gitlawb-attempt` | `ATTEMPT_METADATA_KEY` in `twigpine-node/src/git/publish.rs`, read back in `git/tigris.rs` | Object-metadata key on objects already in storage. | +| `gitlawb-request:` | Reflog action in `twigpine-node/src/api/repos.rs`, read by the recovery in `durable_outbox.rs` | Recovery matches reflog entries written before an upgrade. | | `did:gitlawb` | `twigpine-core/src/did.rs` | A DID method the code accepts. Nothing creates one. Renaming an identity method is its own decision, not part of the rename. | +| `gitlawb://alpha` | Bootstrap UCAN resource in `twigpine-core/src/ucan.rs` | The resource of the network-join capability in bootstrap tokens. Nothing compares it with the `twigpine://` spelling. | -## Read under both names, written under the old one for now +## Read under both names, written under the old one -Readers accept both spellings today. Writers switch in a later release, once -enough of the network reads the new one. +Readers accept both spellings today, through `twigpine_core::url_scheme`. | Name | Read | Written by | Writers switch | |---|---|---|---| -| `gitlawb://` remote URLs | Helper and CLI, through `twigpine_core::url_scheme` | `twigpine clone`, `init`, `repo`, `mirror`, `quickstart`, the MCP tools | The release after the one that reads both. Client-side only: every install ships the helper under both names. | -| `gitlawb://repos//` UCAN resources | Node and helper, through `twigpine_core::url_scheme`; the two spellings attenuate as one resource | `twigpine ucan delegate`, the MCP tools | Once every bootstrap peer runs a release that reads both. The node hosting a repository is the one that checks it. | -| Arweave `App-Name: gitlawb` | CLI discovery queries both values | `twigpine-node/src/ans104.rs` | The release after the one that reads both. | +| `gitlawb://` remote URLs | Helper and CLI | `twigpine clone`, `init`, `repo`, `mirror`, `quickstart`, the MCP tools | In a later release. Every install ships the helper under both names, but URLs are also shared in docs, the web and MCP output, so a machine with only an older helper cannot use a `twigpine://` URL. Switch once that is rare. | +| Arweave `App-Name: gitlawb` | CLI discovery queries both values | `twigpine-node/src/arweave.rs` | In a later release. An older CLI does not find anchors written under the new value. | | The git remote named `gitlawb` | `twigpine status` looks for both names | `twigpine init` | With the remote URLs. | +| `gitlawb://repos//` UCAN resources | Node, helper and CLI; the two spellings attenuate as one resource | `twigpine ucan delegate` and the MCP tool, which write the old spelling even when given the new one | Not planned. The node a user pushes to checks the resource, and that can be any node, including ones we do not run; people never see the string. | ## Temporary fallbacks, removed in 1.0 @@ -49,8 +55,10 @@ enough of the network reads the new one. ## Not decided yet - `gitlawb_*` metric names, with the infra change and whatever dashboards read them. +- The default database URL `postgresql://localhost/gitlawb` in `twigpine-node/src/config.rs`, and the database and user names in `docker-compose.yml`: existing databases carry these names. - `infra/`, the macOS app and `bootstrap-peers.json`, which still set the old setting names and work through the fallback. +- The npm package name `@gitlawb/gl`, replaced by `@twigpine/cli` in its own change. ## Not ours diff --git a/npm/.gitignore b/npm/.gitignore index 586a17aad..c113adb7a 100644 --- a/npm/.gitignore +++ b/npm/.gitignore @@ -10,6 +10,6 @@ packages/gl-linux-arm64/git-remote-gitlawb packages/gl-linux-x64/gl packages/gl-linux-x64/git-remote-gitlawb -# Wrapper bin placeholders are overwritten by postinstall. -packages/gl/bin/gl -packages/gl/bin/git-remote-gitlawb +# The wrapper's bin/ placeholders are committed: npm links commands before the +# install step runs and skips any whose file is missing. install.js overwrites +# them with the real programs. diff --git a/npm/packages/gl/bin/git-remote-gitlawb b/npm/packages/gl/bin/git-remote-gitlawb new file mode 100755 index 000000000..bcf6b0d4c --- /dev/null +++ b/npm/packages/gl/bin/git-remote-gitlawb @@ -0,0 +1,8 @@ +#!/bin/sh +# Placeholder. npm links each command before the install step runs, and skips +# a command whose file is missing, so this file has to exist in the package. +# The install step (install.js) replaces it with the real program. +echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 +exit 1 diff --git a/npm/packages/gl/bin/git-remote-twigpine b/npm/packages/gl/bin/git-remote-twigpine new file mode 100755 index 000000000..bcf6b0d4c --- /dev/null +++ b/npm/packages/gl/bin/git-remote-twigpine @@ -0,0 +1,8 @@ +#!/bin/sh +# Placeholder. npm links each command before the install step runs, and skips +# a command whose file is missing, so this file has to exist in the package. +# The install step (install.js) replaces it with the real program. +echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 +exit 1 diff --git a/npm/packages/gl/bin/gl b/npm/packages/gl/bin/gl new file mode 100755 index 000000000..bcf6b0d4c --- /dev/null +++ b/npm/packages/gl/bin/gl @@ -0,0 +1,8 @@ +#!/bin/sh +# Placeholder. npm links each command before the install step runs, and skips +# a command whose file is missing, so this file has to exist in the package. +# The install step (install.js) replaces it with the real program. +echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 +exit 1 diff --git a/npm/packages/gl/bin/twigpine b/npm/packages/gl/bin/twigpine new file mode 100755 index 000000000..bcf6b0d4c --- /dev/null +++ b/npm/packages/gl/bin/twigpine @@ -0,0 +1,8 @@ +#!/bin/sh +# Placeholder. npm links each command before the install step runs, and skips +# a command whose file is missing, so this file has to exist in the package. +# The install step (install.js) replaces it with the real program. +echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 +exit 1 From d0f0e38c345e0842bc3a60585289751e59c0572e Mon Sep 17 00:00:00 2001 From: Kevin Codex Date: Wed, 18 Nov 2026 12:01:50 +0800 Subject: [PATCH 3/4] fix(npm): the reinstall hint also overrides an ignore-scripts setting --- npm/packages/gl/bin/git-remote-gitlawb | 2 +- npm/packages/gl/bin/git-remote-twigpine | 2 +- npm/packages/gl/bin/gl | 2 +- npm/packages/gl/bin/twigpine | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/npm/packages/gl/bin/git-remote-gitlawb b/npm/packages/gl/bin/git-remote-gitlawb index bcf6b0d4c..d0c13fe27 100755 --- a/npm/packages/gl/bin/git-remote-gitlawb +++ b/npm/packages/gl/bin/git-remote-gitlawb @@ -3,6 +3,6 @@ # a command whose file is missing, so this file has to exist in the package. # The install step (install.js) replaces it with the real program. echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 -echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --no-ignore-scripts --allow-scripts=@gitlawb/gl" >&2 echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 exit 1 diff --git a/npm/packages/gl/bin/git-remote-twigpine b/npm/packages/gl/bin/git-remote-twigpine index bcf6b0d4c..d0c13fe27 100755 --- a/npm/packages/gl/bin/git-remote-twigpine +++ b/npm/packages/gl/bin/git-remote-twigpine @@ -3,6 +3,6 @@ # a command whose file is missing, so this file has to exist in the package. # The install step (install.js) replaces it with the real program. echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 -echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --no-ignore-scripts --allow-scripts=@gitlawb/gl" >&2 echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 exit 1 diff --git a/npm/packages/gl/bin/gl b/npm/packages/gl/bin/gl index bcf6b0d4c..d0c13fe27 100755 --- a/npm/packages/gl/bin/gl +++ b/npm/packages/gl/bin/gl @@ -3,6 +3,6 @@ # a command whose file is missing, so this file has to exist in the package. # The install step (install.js) replaces it with the real program. echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 -echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --no-ignore-scripts --allow-scripts=@gitlawb/gl" >&2 echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 exit 1 diff --git a/npm/packages/gl/bin/twigpine b/npm/packages/gl/bin/twigpine index bcf6b0d4c..d0c13fe27 100755 --- a/npm/packages/gl/bin/twigpine +++ b/npm/packages/gl/bin/twigpine @@ -3,6 +3,6 @@ # a command whose file is missing, so this file has to exist in the package. # The install step (install.js) replaces it with the real program. echo "@gitlawb/gl: the install step did not run, so this command is not set up." >&2 -echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --allow-scripts=@gitlawb/gl" >&2 +echo "Reinstall with scripts allowed: npm install -g @gitlawb/gl --no-ignore-scripts --allow-scripts=@gitlawb/gl" >&2 echo "or install without npm: curl -fsSL https://twigpine.com/install.sh | sh" >&2 exit 1 From f82b77c5c872077c7c9e6ed78466ff81800036a9 Mon Sep 17 00:00:00 2001 From: Kevin Codex Date: Wed, 18 Nov 2026 12:28:51 +0800 Subject: [PATCH 4/4] fix: name a repository by the node's .git rule in the helper, status and ucan delegate The node strips at most one .git from a repository name, so a repository literally named foo.git is addressed as foo.git.git. Three clients disagreed: - the helper stripped every .git before building the node URL, so foo.git.git fetched from and pushed to foo. It now passes the path segment through and leaves the suffix to the node, as the delegation lookup already did; - twigpine status stripped none, so a remote ending in .git asked the API for a repository that does not exist; - twigpine ucan delegate stripped one and the node stripped another when reading the token, so foo.git.git minted a token for foo. A name that itself ends in .git is now written with one more. Each has a test, including the foo.git.git case. --- crates/git-remote-twigpine/src/main.rs | 39 ++++++++++++++++++++++---- crates/twigpine-cli/src/status.rs | 23 +++++++++++++-- crates/twigpine-cli/src/ucan_cmd.rs | 34 +++++++++++++++++++++- 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/crates/git-remote-twigpine/src/main.rs b/crates/git-remote-twigpine/src/main.rs index 1f2b5d9ca..2d7ab2837 100644 --- a/crates/git-remote-twigpine/src/main.rs +++ b/crates/git-remote-twigpine/src/main.rs @@ -798,7 +798,12 @@ fn parse_gitlawb_url(url: &str) -> Result<(String, String, String)> { .unwrap_or(did_string) .to_string(); - let repo_name = repo_name.trim_end_matches(".git").to_string(); + // The path segment goes to the node as written. The node strips at most one + // `.git` (`smart_http_repo_name`), the same rule as the delegation lookup + // below (`canonical_repo_name`), so `my-repo.git` reaches `my-repo` and a + // repository literally named `foo.git` is reached as `foo.git.git`. + // Stripping here as well would send `foo.git.git` to `foo`. + let repo_name = repo_name.to_string(); tracing::debug!("parsed URL → did={did_string}, owner={short_owner}, repo={repo_name}"); Ok((did_string.to_string(), short_owner, repo_name)) @@ -2392,16 +2397,40 @@ mod tests { #[test] fn parse_url_under_the_new_scheme() { let (did, owner, repo) = - parse_gitlawb_url("twigpine://did:key:z6MkFoo123/my-repo.git").unwrap(); + parse_gitlawb_url("twigpine://did:key:z6MkFoo123/my-repo").unwrap(); assert_eq!(did, "did:key:z6MkFoo123"); assert_eq!(owner, "z6MkFoo123"); assert_eq!(repo, "my-repo"); } + /// The path segment reaches the node as written, and the node's + /// at-most-one `.git` rule names the repository: `my-repo.git` is + /// `my-repo`, and `foo.git.git` is the repository literally named + /// `foo.git`, not `foo`. #[test] - fn parse_url_strips_dot_git() { - let (_, _, repo) = parse_gitlawb_url("gitlawb://did:key:z6MkFoo123/my-repo.git").unwrap(); - assert_eq!(repo, "my-repo"); + fn parse_url_leaves_the_git_suffix_to_the_node() { + use twigpine_core::ucan::push::canonical_repo_name; + for (url, segment, repository) in [ + ( + "gitlawb://did:key:z6MkFoo123/my-repo.git", + "my-repo.git", + "my-repo", + ), + ( + "twigpine://did:key:z6MkFoo123/my-repo", + "my-repo", + "my-repo", + ), + ( + "twigpine://did:key:z6MkFoo123/foo.git.git", + "foo.git.git", + "foo.git", + ), + ] { + let (_, _, repo) = parse_gitlawb_url(url).unwrap(); + assert_eq!(repo, segment, "{url}"); + assert_eq!(canonical_repo_name(&repo), repository, "{url}"); + } } #[test] diff --git a/crates/twigpine-cli/src/status.rs b/crates/twigpine-cli/src/status.rs index 2f6198420..b9aaebfca 100644 --- a/crates/twigpine-cli/src/status.rs +++ b/crates/twigpine-cli/src/status.rs @@ -55,7 +55,7 @@ pub async fn run(args: StatusArgs) -> Result<()> { println!(" repo {short_did}/{repo}"); } None => { - println!(" repo (not in a Twigpine repo — no gitlawb:// remote)"); + println!(" repo (not in a Twigpine repo — no twigpine:// remote)"); } } @@ -240,12 +240,14 @@ fn detect_gitlawb_remote() -> Option<(String, String)> { None } -/// Parse a gitlawb:// URL string into (did, repo). +/// Parse a twigpine:// (or gitlawb://) remote URL into (did, repo). fn parse_gitlawb_url(url: &str) -> Option<(String, String)> { let rest = twigpine_core::url_scheme::strip_scheme(url.trim())?; let slash = rest.rfind('/')?; let did = rest[..slash].to_string(); - let repo = rest[slash + 1..].to_string(); + // The API names repositories without the `.git` a remote URL may carry: + // at most one is dropped, the node's own rule. + let repo = twigpine_core::ucan::push::canonical_repo_name(&rest[slash + 1..]).to_string(); if did.is_empty() || repo.is_empty() { return None; } @@ -256,6 +258,21 @@ fn parse_gitlawb_url(url: &str) -> Option<(String, String)> { mod tests { use super::*; + #[test] + fn parse_drops_one_git_suffix_like_the_node() { + for (url, repo) in [ + ("twigpine://did:key:z6Mk1234/myrepo.git", "myrepo"), + ("twigpine://did:key:z6Mk1234/foo.git.git", "foo.git"), + ] { + assert_eq!( + parse_gitlawb_url(url), + Some(("did:key:z6Mk1234".to_string(), repo.to_string())), + "{url}" + ); + } + assert_eq!(parse_gitlawb_url("twigpine://did:key:z6Mk1234/.git"), None); + } + #[test] fn parse_url_under_the_new_scheme() { assert_eq!( diff --git a/crates/twigpine-cli/src/ucan_cmd.rs b/crates/twigpine-cli/src/ucan_cmd.rs index c5c23dffd..5aacf3971 100644 --- a/crates/twigpine-cli/src/ucan_cmd.rs +++ b/crates/twigpine-cli/src/ucan_cmd.rs @@ -140,7 +140,18 @@ fn repo_from_resource(with: &str) -> Option<(String, String)> { /// before. pub(crate) fn canonical_resource(with: &str) -> String { match repo_from_resource(with) { - Some((owner, repo)) => format!("gitlawb://repos/{owner}/{repo}"), + Some((owner, repo)) => { + // Read back, the resource loses at most one `.git` + // (`Capability::grants_push_to`). A repository whose name itself + // ends in `.git` is therefore written with one more, or the token + // would name the repository without it. + let written = if repo.ends_with(".git") { + format!("{repo}.git") + } else { + repo + }; + format!("gitlawb://repos/{owner}/{written}") + } None => with.to_string(), } } @@ -1007,6 +1018,27 @@ mod tests { ); } + /// The resource a token is minted with names the same repository when the + /// node reads it back: `r.git` is `r`, and `foo.git.git` is the repository + /// literally named `foo.git`. + #[test] + fn a_minted_resource_reads_back_as_the_repository_it_was_given() { + use twigpine_core::ucan::{caps, Capability}; + for (typed, repository, not) in [ + ("twigpine://repos/did:key:z6MkA/r.git", "r", "r.git"), + ( + "twigpine://repos/did:key:z6MkA/foo.git.git", + "foo.git", + "foo", + ), + ("gitlawb://repos/did:key:z6MkA/plain", "plain", "plain.git"), + ] { + let cap = Capability::new(super::canonical_resource(typed), caps::GIT_PUSH); + assert!(cap.grants_push_to("did:key:z6MkA", repository), "{typed}"); + assert!(!cap.grants_push_to("did:key:z6MkA", not), "{typed}"); + } + } + use super::*; use tempfile::TempDir; use twigpine_core::identity::Keypair;