← Commit history
v2.1.5: `request` works wherever `adom-wiki` is signed in. Parts Search now finds your identity the way the wiki CLI does: `ADOM_WIKI_TOKEN`, then the stored token, then the Adom container key. Before, a Hydrogen workspace signed in through the container key read "not signed in", and `request` refused (adom/adom-parts-search#12). Searches there now run as you too, so private pages you may see show up.
7 files changed
+71−50
Cargo.lock+1−1@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "adom-parts-search"-version = "2.1.4"+version = "2.1.5" dependencies = [ "base64", "clap",
Cargo.toml+1−1@@ -1,6 +1,6 @@ [package] name = "adom-parts-search"-version = "2.1.4"+version = "2.1.5" edition = "2021" description = "Parts Search Electronics component search — CLI, backend HTTP service, and Hydrogen webview app" license = "MIT"
VERSION+1−1@@ -1 +1 @@-2.1.4+2.1.5
install.shpackage.json+1−40@@ -34,44 +34,5 @@ "SKILL.md", "BUILD-SKILL.md", "CHANGELOG.md"- ],- "changelog": "`request` works wherever `adom-wiki` is signed in. Parts Search now finds your identity the way the wiki CLI does: `ADOM_WIKI_TOKEN`, then the stored token, then the Adom container key. Before, a Hydrogen workspace signed in through the container key read \"not signed in\", and `request` refused (adom/adom-parts-search#12). Searches there now run as you too, so private pages you may see show up.",- "discovery_triggers": [- "parts search",- "find part",- "source component",- "source part",- "compare distributors",- "compare vendors",- "Mouser or DigiKey",- "BOM sourcing",- "price this part",- "where can I get",- "check stock",- "parts availability",- "fastest delivery",- "cheapest part",- "component search",- "part lookup",- "price breaks"- ],- "discovery_pitch": "Search Mouser, DigiKey and JLCPCB in parallel with product photos; Mouser-preferred best-source pick. Say 'with parts search' to your AI.",- "sample_prompts": [- {- "label": "source an STM32F103RBT6",- "prompt": "source an STM32F103RBT6"- },- {- "label": "where can I get an ESP32-S3-WROOM cheape",- "prompt": "where can I get an ESP32-S3-WROOM cheapest and fastest"- },- {- "label": "compare Mouser, DigiKey and JLCPCB for a",- "prompt": "compare Mouser, DigiKey and JLCPCB for an LM555"- },- {- "label": "price this BOM across distributors",- "prompt": "price this BOM across distributors"- } ]-}+}
src/wiki.rs+67−7@@ -6,7 +6,8 @@ //! miss and can be requested; Adom's factory builds the page. No distributor is asked on a person's search: the //! wiki's stock route serves its cache only. //!-//! Auth is the wiki CLI's own (ADOM_WIKI_TOKEN, else ~/.config/adom-wiki/token or its config.json), so a signed-in+//! Auth is the wiki CLI's own (ADOM_WIKI_TOKEN, else ~/.config/adom-wiki/token or its config.json, else the Adom+//! container key at /var/run/adom/api-key), so a signed-in //! user also sees the private pages they may see and nothing else; without a token the search is anonymous and only //! public pages come back. @@ -96,13 +97,72 @@ pub struct WikiBlock { pub fn norm(s: &str) -> String { s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::<String>().to_ascii_uppercase() } -/// The wiki CLI's token: ADOM_WIKI_TOKEN, else ~/.config/adom-wiki/token, else that folder's config.json api_token.+/// The Adom container key: in a Hydrogen local workspace or an Adom cloud container this is the identity the wiki CLI+/// signs in with when nothing else is set (`adom-wiki auth token` reports `container:/var/run/adom/api-key`).+pub const CONTAINER_KEY: &str = "/var/run/adom/api-key";++fn read_trimmed(path: &str) -> Option<String> {+ std::fs::read_to_string(path).ok().map(|t| t.trim().to_string()).filter(|t| !t.is_empty())+}++/// The identity the wiki CLI uses, in the CLI's order: ADOM_WIKI_TOKEN, then the stored token+/// (~/.config/adom-wiki/token, else that folder's config.json api_token), then the container key. Before 2.1.5 the+/// container key was never tried, so `request` said "not signed in" in a workspace where adom-wiki was signed in+/// (adom/adom-parts-search#12). fn token() -> Option<String> {- if let Ok(t) = std::env::var("ADOM_WIKI_TOKEN") { if !t.trim().is_empty() { return Some(t.trim().into()); } }- let dir = format!("{}/.config/adom-wiki", std::env::var("HOME").unwrap_or_default());- if let Ok(t) = std::fs::read_to_string(format!("{}/token", dir)) { if !t.trim().is_empty() { return Some(t.trim().into()); } }- let cfg: Value = serde_json::from_str(&std::fs::read_to_string(format!("{}/config.json", dir)).ok()?).ok()?;- cfg.get("api_token").and_then(|v| v.as_str()).filter(|s| !s.is_empty()).map(String::from)+ token_from(std::env::var("ADOM_WIKI_TOKEN").ok(), &format!("{}/.config/adom-wiki", std::env::var("HOME").unwrap_or_default()), CONTAINER_KEY)+}++fn token_from(env: Option<String>, dir: &str, container_key: &str) -> Option<String> {+ if let Some(t) = env.map(|t| t.trim().to_string()).filter(|t| !t.is_empty()) { return Some(t); }+ if let Some(t) = read_trimmed(&format!("{}/token", dir)) { return Some(t); }+ let cfg = read_trimmed(&format!("{}/config.json", dir)).and_then(|c| serde_json::from_str::<Value>(&c).ok());+ if let Some(t) = cfg.as_ref().and_then(|c| c.get("api_token")).and_then(|v| v.as_str()).map(str::trim).filter(|s| !s.is_empty()) {+ return Some(t.to_string());+ }+ read_trimmed(container_key)+}++#[cfg(test)]+mod token_tests {+ use super::token_from;++ fn scratch(name: &str) -> String {+ let d = std::env::temp_dir().join(format!("ps-token-{}-{}", name, std::process::id()));+ let _ = std::fs::remove_dir_all(&d);+ std::fs::create_dir_all(&d).unwrap();+ d.to_string_lossy().into_owned()+ }++ /// adom/adom-parts-search#12: nothing but the container key, as in a Hydrogen local workspace.+ #[test]+ fn the_container_key_signs_in_when_nothing_else_is_set() {+ let d = scratch("container");+ let key = format!("{}/api-key", d);+ std::fs::write(&key, "container-key\n").unwrap();+ assert_eq!(token_from(None, &format!("{}/nowhere", d), &key).as_deref(), Some("container-key"));+ assert_eq!(token_from(Some(" ".into()), &format!("{}/nowhere", d), &key).as_deref(), Some("container-key"));+ }++ #[test]+ fn the_cli_order_holds_env_then_stored_then_container() {+ let d = scratch("order");+ let key = format!("{}/api-key", d);+ std::fs::write(&key, "container-key").unwrap();+ std::fs::write(format!("{}/config.json", d), r#"{"api_token": "config-token"}"#).unwrap();+ assert_eq!(token_from(None, &d, &key).as_deref(), Some("config-token"));+ std::fs::write(format!("{}/token", d), "stored-token\n").unwrap();+ assert_eq!(token_from(None, &d, &key).as_deref(), Some("stored-token"));+ assert_eq!(token_from(Some("env-token".into()), &d, &key).as_deref(), Some("env-token"));+ }++ #[test]+ fn no_identity_anywhere_is_signed_out() {+ let d = scratch("none");+ assert_eq!(token_from(None, &d, &format!("{}/missing", d)), None);+ std::fs::write(format!("{}/api-key", d), " \n").unwrap();+ assert_eq!(token_from(None, &d, &format!("{}/api-key", d)), None);+ } } /// Where the distributor search goes (Ray, 2026-11-04: through the wiki, which forwards to Component Ocean).
uninstall.sh