Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat(assets): support fixed Git commits, explicit targets, and private repository auth (#3703)
zihenglicd55ec89a643
diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rsindex 0cb60acc1..352567110 100644--- a/crates/ov_cli/src/main.rs+++ b/crates/ov_cli/src/main.rs@@ -374,7 +374,7 @@ enum Commands {/// Wait until processing is complete#[arg(long, help_heading = "Common options")]wait: bool,- /// Wait timeout in seconds (only used with --wait)+ /// Request timeout in seconds. Used with --wait and by Manifest private Git imports#[arg(long,value_parser = config::parse_positive_timeout,diff --git a/crates/ov_cli/src/openviking_assets.rs b/crates/ov_cli/src/openviking_assets.rsindex ed0b03c8e..7dc49156c 100644--- a/crates/ov_cli/src/openviking_assets.rs+++ b/crates/ov_cli/src/openviking_assets.rs@@ -23,19 +23,40 @@ use crate::output::OutputFormat;pub const STATE_PROTOCOL: &str = "openviking-assets-state/1";const DEFAULT_CATALOG_FILENAME: &str = "catalog.yaml";const CREDENTIALS_ENV: &str = "OPENVIKING_ASSETS_CREDENTIALS_FILE";+const NATIVE_AUTH_REQUEST_TIMEOUT_SECONDS: f64 = 300.0;fn client_err(msg: impl Into<String>) -> Error {Error::Client(msg.into())}+fn manifest_request_timeout(+ wait: bool,+ requested_timeout: Option<f64>,+ configured_timeout: f64,+ has_native_auth: bool,+) -> f64 {+ let default_timeout = if has_native_auth {+ NATIVE_AUTH_REQUEST_TIMEOUT_SECONDS+ } else if wait {+ 60.0+ } else {+ 20.0+ };+ requested_timeout+ .unwrap_or(default_timeout)+ .max(configured_timeout)+}+// The server owns OpenViking Assets syntax parsing and semantic validation.// The CLI receives only the resolved execution plan.#[derive(Debug, Clone, Deserialize)]pub struct ResolvedAsset {pub name: String,pub connector: String,+ pub to: Option<String>,pub repo_url: String,pub branch: Option<String>,+ pub commit: Option<String>,pub auth_ref: Option<String>,pub watch_interval: f64,pub locator: String,@@ -258,16 +279,32 @@ fn effective_add_type(external_connector: bool, connector: &str) -> Option<Strin/// Where one asset lands.///-/// A resource already recorded in State is synced in place. A first create-/// normally lets the server name the resource, but a declared `add_type`-/// requires an exact target, so external-Connector runs derive one from the-/// asset name — unique within a manifest and already URI-safe.+/// A manifest-declared `to` is authoritative. It may create a new resource or+/// sync the resource already recorded at that exact URI, but it never silently+/// moves an existing asset. Without `to`, a resource already recorded in State+/// is synced in place. A first create normally lets the server name the+/// resource, while external-Connector runs derive the required exact target+/// from the asset name.fn target_uri(- existing: Option<String>,+ declared: Option<&str>,+ existing: Option<&str>,external_connector: bool,asset_name: &str,-) -> Option<String> {- existing.or_else(|| external_connector.then(|| format!("viking://resources/{asset_name}")))+) -> Result<Option<String>> {+ if let Some(declared) = declared {+ if let Some(existing) = existing+ && existing.trim_end_matches('/') != declared.trim_end_matches('/')+ {+ return Err(client_err(format!(+ "asset '{asset_name}' declares target '{declared}', but its State entry points to \+ '{existing}'; move or remove the old resource and State entry before changing 'to'"+ )));+ }+ return Ok(Some(declared.to_string()));+ }+ Ok(existing+ .map(str::to_string)+ .or_else(|| external_connector.then(|| format!("viking://resources/{asset_name}"))))}impl Default for ManifestRunOptions {@@ -381,12 +418,17 @@ fn build_args(asset: &ResolvedAsset,credential_args: &Map<String, Value>,) -> Option<Map<String, Value>> {- let mut args = Map::new();- if let Some(branch) = &asset.branch {- args.insert("branch".to_string(), json!(branch));+ let mut args = credential_args.clone();+ // Source selection belongs to the manifest, not the credential alias. Drop+ // any legacy selector smuggled through the credentials file so the resolved+ // plan remains authoritative and branch/commit cannot become ambiguous.+ for key in ["branch", "ref", "commit"] {+ args.remove(key);}- for (key, value) in credential_args {- args.insert(key.clone(), value.clone());+ if let Some(commit) = &asset.commit {+ args.insert("commit".to_string(), json!(commit));+ } else if let Some(branch) = &asset.branch {+ args.insert("branch".to_string(), json!(branch));}if args.is_empty() { None } else { Some(args) }}@@ -406,6 +448,80 @@ fn git_auth_config(args: Option<&Map<String, Value>>) -> Option<Value> {}}+/// Shape resolved Manifest credentials for the selected Git ingestion path.+///+/// External connectors keep their historical flat `username` / `token`+/// contract. The native Git accessor accepts the same credentials under+/// `args.auth_config`; source selectors remain top-level parser arguments.+fn git_submit_args(+ external_connector: bool,+ args: Option<Map<String, Value>>,+) -> Option<Map<String, Value>> {+ if external_connector {+ return args;+ }++ let mut args = args?;+ let mut auth = Map::new();+ for key in ["username", "token"] {+ if let Some(value) = args.remove(key) {+ auth.insert(key.to_string(), value);+ }+ }+ if !auth.is_empty() {+ args.insert("auth_config".to_string(), Value::Object(auth));+ }+ Some(args)+}++fn validate_native_git_auth(+ asset: &ResolvedAsset,+ args: &Map<String, Value>,+ _watch_interval: f64,+ external_connector: bool,+) -> Result<()> {+ if external_connector {+ return Ok(());+ }+ if args.keys().any(|key| key != "username" && key != "token") {+ return Err(client_err(format!(+ "asset '{}' native Git credentials contain unsupported fields; only username and token are allowed",+ asset.name+ )));+ }+ if args.is_empty() && asset.auth_ref.is_none() {+ return Ok(());+ }++ let token_valid = args+ .get("token")+ .and_then(Value::as_str)+ .is_some_and(|token| !token.trim().is_empty());+ if !token_valid {+ return Err(client_err(format!(+ "asset '{}' native Git credentials require a non-empty string token",+ asset.name+ )));+ }+ if args.get("username").is_some_and(|username| {+ username+ .as_str()+ .is_none_or(|value| value.trim().is_empty())+ }) {+ return Err(client_err(format!(+ "asset '{}' native Git username must be a non-empty string",+ asset.name+ )));+ }+ if !asset.repo_url.to_ascii_lowercase().starts_with("https://") {+ return Err(client_err(format!(+ "asset '{}' token authentication requires an HTTPS Git URL",+ asset.name+ )));+ }+ Ok(())+}+/// Preflight and then apply (or dry-run) a resolved manifest.////// Every source is checked before the first mutation. A preflight failure@@ -421,6 +537,94 @@ pub async fn apply_manifest_core<S: Submitter>() -> Result<ApplySummary> {let mut state = load_state(manifest_path)?;+ // Resolve all destinations before credential checks, permission preflight,+ // or submission. A stale State mapping must never silently override a+ // declarative target from the Manifest.+ let mut target_uris = Vec::with_capacity(assets.len());+ let mut existing_state_ids = Vec::with_capacity(assets.len());+ for asset in assets {+ let exact_state_id = state+ .assets+ .contains_key(&asset.asset_id)+ .then(|| asset.asset_id.clone());+ let adopted_state_id = if exact_state_id.is_none() {+ if let Some(declared) = asset.to.as_deref() {+ let matches = state+ .assets+ .iter()+ .filter(|(_, entry)| {+ entry.resource_uri.as_deref().is_some_and(|uri| {+ uri.trim_end_matches('/') == declared.trim_end_matches('/')+ })+ })+ .map(|(asset_id, _)| asset_id.clone())+ .collect::<Vec<_>>();+ if matches.len() > 1 {+ return Err(client_err(format!(+ "asset '{}' declares target '{}', but multiple State entries point to it; \+ repair the State file before applying the Manifest",+ asset.name, declared+ )));+ }+ matches.into_iter().next()+ } else {+ None+ }+ } else {+ None+ };+ let existing_state_id = exact_state_id.or(adopted_state_id);+ let existing = existing_state_id+ .as_ref()+ .and_then(|asset_id| state.assets.get(asset_id))+ .and_then(|entry| entry.resource_uri.as_deref());+ target_uris.push(target_uri(+ asset.to.as_deref(),+ existing,+ options.external_connector,+ &asset.name,+ )?);+ existing_state_ids.push(existing_state_id);+ }++ // A target may come from the Manifest, an existing State entry, or the+ // external-Connector fallback. Validate the completed plan rather than+ // only the declarative `to` fields so two assets can never overwrite the+ // same resource during one apply.+ let mut claimed_targets = BTreeMap::<String, String>::new();+ for (index, target) in target_uris.iter().enumerate() {+ let Some(target) = target else {+ continue;+ };+ let normalized = target.trim_end_matches('/').to_string();+ if let Some(previous) =+ claimed_targets.insert(normalized.clone(), assets[index].name.clone())+ {+ return Err(client_err(format!(+ "assets '{}' and '{}' both resolve to target '{}'",+ previous, assets[index].name, normalized+ )));+ }+ }++ // State adoption represents ownership transfer after a selector change.+ // One old entry cannot be transferred to two current assets, even if a+ // malformed State entry has no resource_uri for the target check above.+ let mut claimed_state_entries = BTreeMap::<String, String>::new();+ for (index, state_id) in existing_state_ids.iter().enumerate() {+ let Some(state_id) = state_id else {+ continue;+ };+ if let Some(previous) =+ claimed_state_entries.insert(state_id.clone(), assets[index].name.clone())+ {+ return Err(client_err(format!(+ "assets '{}' and '{}' both claim State entry '{}'",+ previous, assets[index].name, state_id+ )));+ }+ }+// Pre-flight: every declared auth_ref must resolve before anything is submitted.let credentials = load_credentials(credentials_file)?;let mut credential_args: BTreeMap<String, Map<String, Value>> = BTreeMap::new();@@ -429,11 +633,19 @@ pub async fn apply_manifest_core<S: Submitter>(Some(auth_ref) => resolve_auth_ref(auth_ref, &credentials, credentials_file)?,None => Map::new(),};+ validate_native_git_auth(+ asset,+ &args,+ options.watch_interval.unwrap_or(asset.watch_interval),+ options.external_connector,+ )?;credential_args.insert(asset.name.clone(), args);}- let current_ids: HashSet<String> = assets.iter().map(|a| a.asset_id.clone()).collect();- for (asset_id, orphan) in state.orphans(¤t_ids) {+ let mut state_ids_in_use: HashSet<String> =+ assets.iter().map(|asset| asset.asset_id.clone()).collect();+ state_ids_in_use.extend(existing_state_ids.iter().flatten().cloned());+ for (asset_id, orphan) in state.orphans(&state_ids_in_use) {emit(json!({"event": "orphan","asset_id": asset_id,@@ -462,6 +674,7 @@ pub async fn apply_manifest_core<S: Submitter>("connector": asset.connector,"locator": asset.locator,"ref": asset.git_ref,+ "to": target_uris[index],});emit({let mut event = base.as_object().cloned().unwrap_or_default();@@ -493,7 +706,10 @@ pub async fn apply_manifest_core<S: Submitter>(};let mut stop = false;for (index, asset) in assets.iter().enumerate() {- let existing = state.assets.get(&asset.asset_id).cloned();+ let existing = existing_state_ids[index]+ .as_ref()+ .and_then(|asset_id| state.assets.get(asset_id))+ .cloned();let action = match &existing {Some(entry) if entry.resource_uri.is_some() => "sync",_ => "create",@@ -508,6 +724,7 @@ pub async fn apply_manifest_core<S: Submitter>("locator": asset.locator,"ref": asset.git_ref,"action": action,+ "to": target_uris[index],"watch_interval": watch_interval,});let with = |base: &Value, extra: Value| {@@ -543,16 +760,7 @@ pub async fn apply_manifest_core<S: Submitter>(};let args = build_args(asset, &credential_args[&asset.name]);match submitter- .submit(- asset,- target_uri(- entry.resource_uri.clone(),- options.external_connector,- &asset.name,- ),- watch_interval,- args,- )+ .submit(asset, target_uris[index].clone(), watch_interval, args).await{Ok(response) => {@@ -562,6 +770,10 @@ pub async fn apply_manifest_core<S: Submitter>(extract_str(&response, &["root_uri", "uri", "resource_uri", "to"]){entry.resource_uri = Some(uri);+ } else if entry.resource_uri.is_none() {+ // An explicit Manifest target remains a stable State mapping+ // even when an older server response omits its root URI.+ entry.resource_uri = target_uris[index].clone();}if let Some(task_id) = extract_str(&response, &["task_id"]) {entry.task_id = Some(task_id);@@ -575,6 +787,11 @@ pub async fn apply_manifest_core<S: Submitter>("task_id": entry.task_id,}),);+ if let Some(previous_id) = &existing_state_ids[index]+ && previous_id != &asset.asset_id+ {+ state.assets.remove(previous_id);+ }state.record(&asset.asset_id, entry);summary.succeeded.push(asset.name.clone());emit(done);@@ -583,6 +800,11 @@ pub async fn apply_manifest_core<S: Submitter>(let message = err.to_string();entry.status = "failed".to_string();entry.error = Some(message.clone());+ if let Some(previous_id) = &existing_state_ids[index]+ && previous_id != &asset.asset_id+ {+ state.assets.remove(previous_id);+ }state.record(&asset.asset_id, entry);summary.failed.insert(asset.name.clone(), message.clone());emit(with(@@ -637,6 +859,7 @@ impl Submitter for HttpSubmitter {"connector": asset.connector,"repo_url": asset.repo_url,"branch": asset.branch,+ "commit": asset.commit,"auth_config": git_auth_config(args.as_ref()),}),)@@ -650,6 +873,7 @@ impl Submitter for HttpSubmitter {watch_interval: f64,args: Option<Map<String, Value>>,) -> Result<Value> {+ let args = git_submit_args(self.external_connector, args);self.client.add_resource(&asset.repo_url,@@ -840,11 +1064,8 @@ pub async fn handle_manifest_apply(}).transpose()?;- let effective_timeout = if options.wait {- timeout.unwrap_or(60.0).max(ctx.config.timeout)- } else {- ctx.config.timeout.max(20.0)- };+ let effective_timeout =+ manifest_request_timeout(options.wait, timeout, ctx.config.timeout, false);let client = ctx.get_client_with_timeout(Some(effective_timeout));let mut request = json!({"manifest_yaml": manifest_yaml,@@ -857,6 +1078,11 @@ pub async fn handle_manifest_apply(let resolved: ResolveResponse = client.post("/api/v1/openviking-assets/resolve", &request).await?;+ let has_native_auth =+ !options.external_connector && resolved.assets.iter().any(|asset| asset.auth_ref.is_some());+ let effective_timeout =+ manifest_request_timeout(options.wait, timeout, ctx.config.timeout, has_native_auth);+ let client = ctx.get_client_with_timeout(Some(effective_timeout));let json_mode = matches!(ctx.output_format, OutputFormat::Json);let mut emit = |event: Value| {@@ -921,6 +1147,145 @@ mod tests {assert_eq!(effective_add_type(true, "tos"), Some("tos".to_string()));}+ #[test]+ fn native_auth_requests_get_a_long_default_and_honor_explicit_timeout() {+ assert_eq!(manifest_request_timeout(false, None, 60.0, false), 60.0);+ assert_eq!(manifest_request_timeout(false, None, 60.0, true), 300.0);+ assert_eq!(+ manifest_request_timeout(false, Some(900.0), 60.0, true),+ 900.0+ );+ assert_eq!(+ manifest_request_timeout(false, Some(120.0), 180.0, true),+ 180.0+ );+ }++ #[test]+ fn build_args_uses_manifest_commit_as_authoritative_selector() {+ let (_dir, _manifest, _catalog, mut assets) = workspace();+ assets[0].branch = None;+ assets[0].commit = Some("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".into());+ let credentials = json!({+ "token": "sekrit",+ "branch": "credential-branch",+ "ref": "credential-ref",+ "commit": "credential-commit",+ })+ .as_object()+ .unwrap()+ .clone();++ let args = build_args(&assets[0], &credentials).unwrap();++ assert_eq!(args["token"], json!("sekrit"));+ assert_eq!(+ args["commit"],+ json!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")+ );+ assert!(!args.contains_key("branch"));+ assert!(!args.contains_key("ref"));+ }++ #[test]+ fn native_git_submit_nests_credentials_but_keeps_source_selector_flat() {+ let args = json!({+ "username": "oauth2",+ "token": "sekrit",+ "branch": "main",+ })+ .as_object()+ .cloned();++ let args = git_submit_args(false, args).unwrap();++ assert_eq!(+ args["auth_config"],+ json!({"username": "oauth2", "token": "sekrit"})+ );+ assert_eq!(args["branch"], json!("main"));+ assert!(!args.contains_key("username"));+ assert!(!args.contains_key("token"));+ }++ #[test]+ fn git_preflight_keeps_auth_config_separate_from_source_selector() {+ let args = json!({+ "username": "oauth2",+ "token": "sekrit",+ "branch": "main",+ })+ .as_object()+ .cloned();++ assert_eq!(+ git_auth_config(args.as_ref()),+ Some(json!({"username": "oauth2", "token": "sekrit"}))+ );+ }++ #[test]+ fn external_git_submit_keeps_connector_credentials_flat() {+ let args = json!({+ "username": "oauth2",+ "token": "sekrit",+ "commit": "deadbeef",+ })+ .as_object()+ .cloned();++ let args = git_submit_args(true, args).unwrap();++ assert_eq!(args["username"], json!("oauth2"));+ assert_eq!(args["token"], json!("sekrit"));+ assert_eq!(args["commit"], json!("deadbeef"));+ assert!(!args.contains_key("auth_config"));+ }++ #[test]+ fn native_git_auth_validation_matches_server_contract() {+ let (_dir, _manifest, _catalog, mut assets) = workspace();+ let username_only = json!({"username": "oauth2"}).as_object().unwrap().clone();+ assert!(+ validate_native_git_auth(&assets[0], &username_only, 0.0, false)+ .unwrap_err()+ .to_string()+ .contains("token")+ );++ let token = json!({"token": "sekrit"}).as_object().unwrap().clone();+ assets[0].repo_url = "[email protected]:org/alpha.git".into();+ assert!(+ validate_native_git_auth(&assets[0], &token, 0.0, false)+ .unwrap_err()+ .to_string()+ .contains("HTTPS")+ );++ assets[0].repo_url = "http://github.com/org/alpha.git".into();+ assert!(+ validate_native_git_auth(&assets[0], &token, 0.0, false)+ .unwrap_err()+ .to_string()+ .contains("HTTPS")+ );++ let unknown = json!({"password": "must-not-persist"})+ .as_object()+ .unwrap()+ .clone();+ assert!(+ validate_native_git_auth(&assets[0], &unknown, 0.0, false)+ .unwrap_err()+ .to_string()+ .contains("unsupported")+ );++ assets[0].repo_url = "https://github.com/org/alpha.git".into();+ assert!(validate_native_git_auth(&assets[0], &token, 30.0, false).is_ok());+ assert!(validate_native_git_auth(&assets[0], &token, 30.0, true).is_ok());+ }+#[test]fn manifest_run_args_parse_known_keys() {let args = serde_json::json!({@@ -940,7 +1305,7 @@ mod tests {#[test]fn manifest_run_args_reject_unknown_keys_and_bad_types() {- // Catalog params (e.g. git branch) belong in the catalog file, not+ // Catalog params (e.g. git branch or commit) belong in the catalog file, not// here; an unknown key must not silently do nothing.let unknown = serde_json::json!({"branch": "main"});let err = parse_manifest_run_args(unknown.as_object()).unwrap_err();@@ -959,18 +1324,38 @@ mod tests {}#[test]- fn creates_get_an_exact_target_only_for_external_connector_runs() {+ fn manifest_target_is_authoritative_and_external_connector_has_a_fallback() {// Standard runs let the server name a new resource.- assert_eq!(target_uri(None, false, "alpha"), None);+ assert_eq!(target_uri(None, None, false, "alpha").unwrap(), None);+ // A declared target is used for a first create in either mode.+ assert_eq!(+ target_uri(Some("viking://resources/repos/alpha"), None, false, "alpha").unwrap(),+ Some("viking://resources/repos/alpha".to_string())+ );// A declared add_type requires an exact target, derived from the name.assert_eq!(- target_uri(None, true, "alpha"),+ target_uri(None, None, true, "alpha").unwrap(),Some("viking://resources/alpha".to_string()));// An existing resource is synced in place under either mode.- let existing = Some("viking://resources/renamed".to_string());- assert_eq!(target_uri(existing.clone(), false, "alpha"), existing);- assert_eq!(target_uri(existing.clone(), true, "alpha"), existing);+ let existing = "viking://resources/renamed";+ assert_eq!(+ target_uri(None, Some(existing), false, "alpha").unwrap(),+ Some(existing.to_string())+ );+ assert_eq!(+ target_uri(None, Some(existing), true, "alpha").unwrap(),+ Some(existing.to_string())+ );+ // A changed declaration cannot silently move a State-owned resource.+ let err = target_uri(+ Some("viking://resources/new"),+ Some(existing),+ false,+ "alpha",+ )+ .unwrap_err();+ assert!(err.to_string().contains("State entry"), "{err}");}#[test]@@ -1005,8 +1390,10 @@ mod tests {ResolvedAsset {name: "alpha".into(),connector: "git".into(),+ to: Some("viking://resources/repos/alpha".into()),repo_url: "https://github.com/org/alpha".into(),branch: Some("main".into()),+ commit: None,auth_ref: None,watch_interval: 30.0,locator: "github.com/org/alpha".into(),@@ -1016,8 +1403,10 @@ mod tests {ResolvedAsset {name: "beta".into(),connector: "git".into(),+ to: None,repo_url: "https://github.com/org/beta".into(),branch: None,+ commit: None,auth_ref: None,watch_interval: 30.0,locator: "github.com/org/beta".into(),@@ -1027,8 +1416,10 @@ mod tests {ResolvedAsset {name: "gamma".into(),connector: "git".into(),+ to: None,repo_url: "[email protected]:org/gamma.git".into(),branch: Some("dev".into()),+ commit: None,auth_ref: None,watch_interval: 0.0,locator: "github.com/org/gamma".into(),@@ -1129,6 +1520,9 @@ mod tests {watch_interval: f64,args: Option<Map<String, Value>>,) -> Result<Value> {+ let root_uri = to+ .clone()+ .unwrap_or_else(|| format!("viking://resources/{}", asset.name));self.calls.lock().unwrap()@@ -1137,7 +1531,7 @@ mod tests {return Err(client_err(format!("boom: {}", asset.name)));}Ok(json!({- "root_uri": format!("viking://resources/{}", asset.name),+ "root_uri": root_uri,"task_id": format!("task-{}", asset.name),}))}@@ -1182,7 +1576,11 @@ mod tests {assert_eq!(summary.succeeded, ["alpha", "beta", "gamma"]);{let calls = submitter.calls.lock().unwrap();- assert!(calls.iter().all(|(_, to, _, _)| to.is_none()));+ assert_eq!(+ calls[0].1.as_deref(),+ Some("viking://resources/repos/alpha")+ );+ assert!(calls[1..].iter().all(|(_, to, _, _)| to.is_none()));assert_eq!(calls[0].2, 30.0);assert_eq!(calls[2].2, 0.0);let alpha_args = calls[0].3.as_ref().unwrap();@@ -1203,7 +1601,10 @@ mod tests {.await;assert_eq!(summary2.succeeded.len(), 3);let calls = submitter2.calls.lock().unwrap();- assert_eq!(calls[0].1.as_deref(), Some("viking://resources/alpha"));+ assert_eq!(+ calls[0].1.as_deref(),+ Some("viking://resources/repos/alpha")+ );let actions: Vec<&str> = events.iter().filter(|e| e["event"] == "asset_done")@@ -1212,6 +1613,132 @@ mod tests {assert_eq!(actions, ["sync", "sync", "sync"]);}+ #[tokio::test]+ async fn changed_manifest_target_conflicts_with_existing_state() {+ let (dir, manifest, catalog, mut assets) = workspace();+ let creds = dir.path().join("no-creds.yaml");+ let submitter = FakeSubmitter::new(vec![]);+ run(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ )+ .await;++ assets[0].to = Some("viking://resources/repos/moved-alpha".into());+ let submitter = FakeSubmitter::new(vec![]);+ let mut emit = |_event: Value| {};+ let err = apply_manifest_core(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ &mut emit,+ )+ .await+ .unwrap_err();++ assert!(err.to_string().contains("State entry"), "{err}");+ assert!(submitter.preflight_calls.lock().unwrap().is_empty());+ assert!(submitter.calls.lock().unwrap().is_empty());+ }++ #[tokio::test]+ async fn changed_ref_at_same_manifest_target_migrates_state() {+ let (dir, manifest, catalog, mut assets) = workspace();+ let creds = dir.path().join("no-creds.yaml");+ let submitter = FakeSubmitter::new(vec![]);+ run(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ )+ .await;++ let previous_id = assets[0].asset_id.clone();+ assets[0].asset_id = "alpha-dev-id".into();+ assets[0].branch = Some("dev".into());+ assets[0].git_ref = "dev".into();+ let submitter = FakeSubmitter::new(vec![]);+ let (_, events) = run(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ )+ .await;++ assert_eq!(+ submitter.calls.lock().unwrap()[0].1.as_deref(),+ Some("viking://resources/repos/alpha")+ );+ assert!(+ !events+ .iter()+ .any(|event| event["event"] == "orphan" && event["name"] == "alpha")+ );+ let state = load_state(&manifest).unwrap();+ assert!(!state.assets.contains_key(&previous_id));+ assert!(state.assets.contains_key("alpha-dev-id"));+ }++ #[tokio::test]+ async fn inherited_and_declared_target_collision_aborts_before_preflight() {+ let (dir, manifest, catalog, assets) = workspace();+ let creds = dir.path().join("no-creds.yaml");+ let submitter = FakeSubmitter::new(vec![]);+ run(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ )+ .await;++ let state_path = state_path_for(&manifest);+ let original_state = std::fs::read_to_string(&state_path).unwrap();++ let mut inherited = assets[0].clone();+ inherited.to = None;+ let mut declared = assets[1].clone();+ declared.asset_id = "beta-at-alpha-target".into();+ declared.to = Some("viking://resources/repos/alpha/".into());+ let selected = vec![inherited, declared];+ let submitter = FakeSubmitter::new(vec![]);+ let mut emit = |_event: Value| {};+ let err = apply_manifest_core(+ &manifest,+ &catalog,+ &selected,+ &creds,+ &run_opts(),+ &submitter,+ &mut emit,+ )+ .await+ .unwrap_err();++ let message = err.to_string();+ assert!(message.contains("alpha"), "{message}");+ assert!(message.contains("beta"), "{message}");+ assert!(message.contains("both resolve to target"), "{message}");+ assert!(submitter.preflight_calls.lock().unwrap().is_empty());+ assert!(submitter.calls.lock().unwrap().is_empty());+ assert_eq!(std::fs::read_to_string(state_path).unwrap(), original_state);+ }+#[tokio::test]async fn fail_fast_and_skip_failed() {let (dir, manifest, catalog, assets) = workspace();@@ -1302,6 +1829,105 @@ mod tests {);}+ #[tokio::test]+ async fn native_auth_watch_is_preflighted_and_submitted() {+ let (dir, manifest, catalog, mut assets) = workspace();+ assets[1].auth_ref = Some("team-git".into());+ let creds = write(+ dir.path(),+ "creds.yaml",+ "credentials:\n team-git:\n token: sekrit\n",+ );+ let submitter = FakeSubmitter::new(vec![]);+ let mut emit = |_event: Value| {};++ let summary = apply_manifest_core(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ &mut emit,+ )+ .await+ .unwrap();++ assert_eq!(summary.succeeded, ["alpha", "beta", "gamma"]);+ let preflight_calls = submitter.preflight_calls.lock().unwrap();+ let beta_preflight = preflight_calls+ .iter()+ .find(|call| call.0 == "beta")+ .unwrap();+ assert_eq!(beta_preflight.1.as_ref().unwrap()["token"], json!("sekrit"));+ drop(preflight_calls);+ let calls = submitter.calls.lock().unwrap();+ let beta_submit = calls.iter().find(|call| call.0 == "beta").unwrap();+ assert_eq!(beta_submit.2, 30.0);+ assert_eq!(beta_submit.3.as_ref().unwrap()["token"], json!("sekrit"));+ assert!(state_path_for(&manifest).exists());+ }++ #[tokio::test]+ async fn native_unknown_credential_field_aborts_before_preflight_or_submission() {+ let (dir, manifest, catalog, mut assets) = workspace();+ assets[1].auth_ref = Some("team-git".into());+ let creds = write(+ dir.path(),+ "creds.yaml",+ "credentials:\n team-git:\n password: must-not-persist\n",+ );+ let submitter = FakeSubmitter::new(vec![]);+ let mut emit = |_event: Value| {};++ let err = apply_manifest_core(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ &mut emit,+ )+ .await+ .unwrap_err();++ assert!(err.to_string().contains("unsupported"), "{err}");+ assert!(!err.to_string().contains("must-not-persist"), "{err}");+ assert!(submitter.preflight_calls.lock().unwrap().is_empty());+ assert!(submitter.calls.lock().unwrap().is_empty());+ }++ #[tokio::test]+ async fn native_empty_credential_alias_aborts_before_preflight_or_submission() {+ for credentials_yaml in [+ "credentials:\n team-git: {}\n",+ "credentials:\n team-git:\n",+ ] {+ let (dir, manifest, catalog, mut assets) = workspace();+ assets[1].auth_ref = Some("team-git".into());+ let creds = write(dir.path(), "creds.yaml", credentials_yaml);+ let submitter = FakeSubmitter::new(vec![]);+ let mut emit = |_event: Value| {};++ let err = apply_manifest_core(+ &manifest,+ &catalog,+ &assets,+ &creds,+ &run_opts(),+ &submitter,+ &mut emit,+ )+ .await+ .unwrap_err();++ assert!(err.to_string().contains("token"), "{err}");+ assert!(submitter.preflight_calls.lock().unwrap().is_empty());+ assert!(submitter.calls.lock().unwrap().is_empty());+ }+ }+#[tokio::test]async fn orphan_reported_but_kept() {let (dir, manifest, catalog, assets) = workspace();@@ -1337,6 +1963,7 @@ mod tests {async fn auth_ref_precheck_and_merge() {let (dir, manifest, catalog, mut assets) = workspace();assets[0].auth_ref = Some("team-git".into());+ assets[0].watch_interval = 0.0;// Missing alias fails before anything is submitted.let submitter = FakeSubmitter::new(vec![]);diff --git a/docs/en/api/01-overview.md b/docs/en/api/01-overview.mdindex 93060f536..f2f95f049 100644--- a/docs/en/api/01-overview.md+++ b/docs/en/api/01-overview.md@@ -400,6 +400,7 @@ This catalog follows the routes actually mounted by the server. Each group headi| POST | `/api/v1/sessions` | Create a session || GET | `/api/v1/sessions` | List sessions || GET | `/api/v1/sessions/{session_id}` | Get a session |+| PATCH | `/api/v1/sessions/{session_id}/config` | Update mutable session configuration || GET | `/api/v1/sessions/{session_id}/tool-results` | List tool results || GET | `/api/v1/sessions/{session_id}/tool-results/{tool_result_id}` | Read a tool result || GET | `/api/v1/sessions/{session_id}/tool-results/{tool_result_id}/search` | Search within a tool result |diff --git a/docs/en/api/02-resources.md b/docs/en/api/02-resources.mdindex e5826b7d5..4319fe6c7 100644--- a/docs/en/api/02-resources.md+++ b/docs/en/api/02-resources.md@@ -177,7 +177,7 @@ This endpoint is the core entry point for resource management, supporting adding| exclude | string | No | None | File patterns to exclude (glob) || directly_upload_media | bool | No | True | Whether to directly upload media files || preserve_structure | bool | No | None | Whether to preserve directory structure |-| args | object | No | `{}` | Parser-specific import options forwarded to the source parser/accessor. `args.parse_mode` accepts `default` (existing splitting behavior) or `no_split` (parse and convert each source document to one Markdown body). E.g. `args.site=true/false` forces/opts out of whole-site (sitemap/RSS) ingestion, `args.max_pages` etc. override the `webfeed` config; the recursive web crawler accepts `args.depth`, `args.max_pages`, `args.include_paths`, `args.exclude_paths`, `args.allow_external_links`, `args.skip_download_links`; Feishu user-token imports pass `args.feishu_access_token`. Core `add_resource` fields such as `path`, `to`, `watch_interval`, `include`, and `exclude` are not allowed inside `args` |+| args | object | No | `{}` | Parser-specific import options forwarded to the source parser/accessor. Native HTTPS Git imports and watches accept HTTP Basic credentials over TLS as `args.auth_config={"username":"oauth2","token":"..."}`; `username` defaults to `oauth2`. Git `branch` or `commit` remains at the top level of `args`. `args.parse_mode` accepts `default` (existing splitting behavior) or `no_split` (parse and convert each source document to one Markdown body). E.g. `args.site=true/false` forces/opts out of whole-site (sitemap/RSS) ingestion, `args.max_pages` etc. override the `webfeed` config; the recursive web crawler accepts `args.depth`, `args.max_pages`, `args.include_paths`, `args.exclude_paths`, `args.allow_external_links`, `args.skip_download_links`; Feishu user-token imports pass `args.feishu_access_token`. Core `add_resource` fields such as `path`, `to`, `watch_interval`, `include`, and `exclude` are not allowed inside `args` || watch_interval | float | No | 0 | Scheduled update interval (minutes). >0 creates a task for a re-readable URL/sitemap/RSS source; uploaded `temp_file_id` content is a one-time snapshot and must be re-added when it changes. <=0 cancels a task; explicit `to` wins, otherwise binds to the imported `root_uri` || processing_mode | string | No | `semantic_and_vectors` | Post-ingest processing mode. `semantic_and_vectors` is the normal flow: generate semantic artifacts (`.abstract.md`, `.overview.md`) and vectors. `vectors_only` skips semantic understanding/VLM summarization and only vectorizes current resource files || telemetry | TelemetryRequest | No | False | Whether to return telemetry data |@@ -191,6 +191,8 @@ This endpoint is the core entry point for resource management, supporting adding- Raw HTTP calls for local files require first uploading via [temp_upload](#temp_upload) to obtain `temp_file_id`- When `to` is specified and the target already exists, triggers incremental update- Only Git repository sources use full background import when `wait=false`; OpenViking performs repository preflight and target planning before returning the `task_id`.+- Native HTTPS Git credentials in `args.auth_config` remain request-local when `watch_interval <= 0`. When `watch_interval > 0`, OpenViking stores the repository-bound username/token in private watch state and restores it only for later Git fetches. The credentials are excluded from ordinary queue payloads and watch API/MCP/CLI responses. Git PATs have no generic refresh flow; rotate an expired or revoked token by recreating the watch. Legacy URL-embedded credentials such as `https://user:token@host/repo.git` remain accepted and are passed through unchanged; because that URL is also the source identifier, it may be recorded in process arguments, logs, queues, resource metadata, and watch state. Prefer `args.auth_config` for new integrations. Plaintext HTTP authentication and authenticated redirects for `args.auth_config` remain rejected.+- The token travels in the HTTPS request body. Keep diagnostic request-body dumping disabled in production because explicitly enabling it can record secrets.- Memory generated from `reason` is extracted through the same pipeline as `session.commit`. It uses `reason`, the resource URI, available source name, and available directory abstract; it does not inspect or expand the full resource content. OpenViking writes to existing memory types such as `entities`, `events`, or `preferences`, not a dedicated resource memory directory.- When deleting a resource, OpenViking scans the self or peer memories targeted by the current context before deletion, removes the matching resource URI and content introduced by that `reason`, and refreshes the semantic index for the affected memories.- Other sources with `wait=false` finish source parsing, target resolution, and AGFS writes before returning. Only semantic and embedding queues continue asynchronously.@@ -228,6 +230,23 @@ curl -X POST http://localhost:1933/api/v1/resources \"wait": true}'+# Import and watch a private HTTPS Git repository+curl -X POST http://localhost:1933/api/v1/resources \+ -H "Content-Type: application/json" \+ -H "X-API-Key: your-key" \+ -d '{+ "path": "https://git.example.com/team/private-repo.git",+ "to": "viking://resources/private-repo",+ "watch_interval": 60,+ "args": {+ "branch": "main",+ "auth_config": {+ "username": "oauth2",+ "token": "replace-with-your-token"+ }+ }+ }'+# Add a resource and only build vectors, without VLM semantic understandingcurl -X POST http://localhost:1933/api/v1/resources \-H "Content-Type: application/json" \diff --git a/docs/en/api/05-sessions.md b/docs/en/api/05-sessions.mdindex be38b301b..cad0e7464 100644--- a/docs/en/api/05-sessions.md+++ b/docs/en/api/05-sessions.md@@ -44,7 +44,7 @@ Create a new session. Sessions are containers for conversations, storing message|-----------|------|----------|---------|-------------|| session_id | str | No | None | Session ID. Creates new session with auto-generated ID if None || memory_policy | object | No | None | Default memory extraction policy for the session. Optional `self` and `peer` switches control write targets, optional `working_memory.enabled=false` skips archive summaries, and optional top-level `memory_types` limits extraction to specific enabled memory schemas. Use JSON booleans for every `enabled` value. Legacy boolean-like values remain accepted temporarily (including string `"false"`, which is parsed as false) but emit a deprecation warning. When `memory_types` is omitted or `null`, all enabled memory schemas are allowed. Invalid shapes or unknown memory types are rejected with `InvalidArgumentError`. |-| auto_commit_policy | object | No | None | Optional auto-commit policy (see table below). Any provided fields are validated, clamped to their bounds, and merged over the defaults; the effective policy is returned in the response `result.auto_commit_policy` and persisted into session metadata. If no policy is provided, auto commit is disabled unless `memory.session_auto_commit.default_enabled=true`. The policy is immutable after creation. |+| auto_commit_policy | object | No | None | Optional auto-commit policy (see table below). Any provided fields are validated, clamped to their bounds, and merged over the defaults; the effective policy is returned in the response `result.auto_commit_policy` and persisted into session metadata. If no policy is provided, auto commit is disabled unless `memory.session_auto_commit.default_enabled=true`. The policy can later be partially updated or disabled through `update_session_config()`. |`auto_commit_policy` fields (all optional; omitted fields fall back to the defaults when a policy is present):@@ -399,12 +399,141 @@ ov session get a1b2c3d4----### Updating Session Config+### update_session_config()-The auto-commit policy is immutable after creation. Set `auto_commit_policy` when-creating the session, then use `GET /api/v1/sessions/{session_id}` to inspect the-effective config. Runtime session-config updates are not exposed by the Sessions-API.+#### 1. API Implementation Introduction++Partially update the mutable configuration of an existing session. Changes take+effect on subsequent message writes, idle scans, and commits. Only the+`/api/v1/sessions/{session_id}/config` subpath accepts `PATCH`; the base+`/api/v1/sessions/{session_id}` endpoint does not.++**Code Entry Points**:+- `openviking/server/routers/sessions.py:update_session_config()` - HTTP route+- `openviking/service/session_service.py:SessionService.update_config()` - Config validation and update+- `sdk/python/openviking_sdk/client.py:update_session_config()` - Python SDK+- `sdk/typescript/src/client.ts:updateSessionConfig()` - TypeScript SDK+- `sdk/go/sessions.go:UpdateSessionConfig()` - Go SDK+- `crates/ov_cli/src/commands/session.rs:set_session_config()` - CLI command++#### 2. Interface and Parameter Description++| Parameter | Type | Required | Default | Description |+|-----------|------|----------|---------|-------------|+| session_id | string | Yes | - | Session ID in the URL path |+| memory_extraction_config | object | No | Omitted | Mutable extraction settings. Currently supports `events.tags`, an array of strict `key=value` strings. Omit it to preserve the current tags; pass `events.tags=[]` to clear them. Tags are trimmed, lowercased, and deduplicated. |+| auto_commit_policy | object or null | No | Omitted | An object merges only the supplied policy fields into the current policy, with the same validation, clamping, defaults, and bounds documented under `create_session()`. Pass `null` to disable automatic commits; omit the field to leave the policy unchanged. Individual policy fields cannot be `null`. |+| telemetry | boolean or object | No | `false` | Set to `true`, or pass `{"summary": true}`, to include the operation telemetry summary in the response. `false` omits it. |++An empty request object is a valid no-op and returns the effective configuration.+Unknown request fields are rejected. The response always returns the effective+policy with defaults filled in, or `null` when automatic commits are disabled.++#### 3. Usage Examples++**HTTP API**++```http+PATCH /api/v1/sessions/{session_id}/config+```++```bash+# Merge one policy field and replace the default event-memory tags+curl -X PATCH http://localhost:1933/api/v1/sessions/a1b2c3d4/config \+ -H "Content-Type: application/json" \+ -H "X-API-Key: your-key" \+ -d '{+ "memory_extraction_config": {+ "events": {"tags": ["team=search", "channel=app"]}+ },+ "auto_commit_policy": {"message_count_threshold": 25},+ "telemetry": true+ }'++# Disable automatic commits without changing event-memory tags+curl -X PATCH http://localhost:1933/api/v1/sessions/a1b2c3d4/config \+ -H "Content-Type: application/json" \+ -H "X-API-Key: your-key" \+ -d '{"auto_commit_policy": null}'+```++**Python SDK**++```python+result = client.update_session_config(+ "a1b2c3d4",+ memory_extraction_config={+ "events": {"tags": ["team=search", "channel=app"]}+ },+ auto_commit_policy={"message_count_threshold": 25},+)+```++**TypeScript SDK**++```typescript+const result = await client.updateSessionConfig("a1b2c3d4", {+ memoryExtractionConfig: {+ events: { tags: ["team=search", "channel=app"] },+ },+ autoCommitPolicy: { message_count_threshold: 25 },+});+```++**Go SDK**++```go+policy := map[string]any{"message_count_threshold": 25}+result, err := client.UpdateSessionConfig(ctx, "a1b2c3d4", &openviking.UpdateSessionConfigOptions{+ MemoryExtractionConfig: map[string]any{+ "events": map[string]any{"tags": []string{"team=search", "channel=app"}},+ },+ AutoCommitPolicy: &policy,+})+```++**CLI**++```bash+ov session config set a1b2c3d4 \+ --event-tags team=search,channel=app \+ --auto-commit-policy-json '{"message_count_threshold":25}'++# Clear the default tags, or disable automatic commits+ov session config set a1b2c3d4 --no-event-tags+ov session config set a1b2c3d4 --no-auto-commit+```++**Response example**++```json+{+ "status": "ok",+ "result": {+ "session_id": "a1b2c3d4",+ "auto_commit_policy": {+ "pending_token_threshold": 10000,+ "message_count_threshold": 25,+ "idle_timeout_seconds": 86400,+ "keep_recent_count": 2,+ "min_commit_interval_seconds": 0+ },+ "memory_extraction_config": {+ "events": {+ "tags": ["team=search", "channel=app"]+ }+ }+ },+ "telemetry": {+ "id": "tm_xxx",+ "summary": {+ "operation": "session.update_config",+ "status": "ok",+ "duration_ms": 4.2+ }+ }+}+```---diff --git a/docs/en/guides/01-configuration.md b/docs/en/guides/01-configuration.mdindex 53cea7820..562d0964d 100644--- a/docs/en/guides/01-configuration.md+++ b/docs/en/guides/01-configuration.md@@ -1209,7 +1209,7 @@ Legacy compatibility example:Notes:- `memory.session_auto_commit` is a server-wide control surface, not a per-session business policy.-- Per-session auto-commit behavior is configured through the session-level `auto_commit_policy` (see the table below). It is set only when creating a session (`POST /api/v1/sessions` with a top-level `auto_commit_policy` field) and viewed via `GET /api/v1/sessions/{session_id}`; runtime config PATCH is not supported.+- Per-session auto-commit behavior is configured through the session-level `auto_commit_policy` (see the table below). Set it when creating a session with `POST /api/v1/sessions`, or partially update it through `PATCH /api/v1/sessions/{session_id}/config`. Omitting `auto_commit_policy` from a PATCH preserves it; sending `null` disables automatic commits. Use `GET /api/v1/sessions/{session_id}` to inspect the effective policy.- When `default_enabled=false`, sessions created without `auto_commit_policy` keep auto commit disabled and return `auto_commit_policy: null`. Providing `{}` or any policy field explicitly enables auto commit for that session and fills missing fields from the defaults below.- When `default_enabled=true`, sessions created without `auto_commit_policy` get the default policy below.- When `idle_enabled=false`:diff --git a/docs/en/guides/18-openviking-assets.md b/docs/en/guides/18-openviking-assets.mdindex 57d934fd9..17ec50552 100644--- a/docs/en/guides/18-openviking-assets.md+++ b/docs/en/guides/18-openviking-assets.md@@ -69,7 +69,7 @@ protocol: openviking-assets/1defaults:git:auth_ref: team-git- watch_interval: 1440+ watch_interval: 60catalog:- name: openviking@@ -139,7 +139,7 @@ protocol: openviking-assets/1defaults:git:auth_ref: team-git- watch_interval: 1440+ watch_interval: 60catalog:- name: openviking@@ -292,9 +292,26 @@ export OPENVIKING_ASSETS_CREDENTIALS_FILE=/secure/path/assets-credentials.yamlBefore submitting any resource, the CLI resolves every selected `auth_ref`, then the server runs`git ls-remote` in the execution environment to verify read access to every repository. A missingalias or unreadable repository fails the whole operation before the first submission; dry-run-performs the same preflight. Resolved Git arguments are sent to the preflight and resource-endpoints over the configured OpenViking service connection. Use TLS for remote deployments and-restrict local access to the credentials file.+performs the same preflight. `username` and `token` are the only supported fields under a native+Git credentials alias; keep them flat as shown above. For the standard, native Git path, the CLI sends them to `add_resource` as+`args.auth_config`, while `branch` or `commit` remains a top-level member of `args`. Resolved Git+arguments are sent over the configured OpenViking service connection. Use TLS for remote+deployments and restrict local access to the credentials file.++When the effective `watch_interval` is positive, OpenViking stores an HTTPS Git token resolved+from `auth_ref` in the Watch task's private, repository-bound authentication state. The token is+not written to Manifest State, ordinary ingestion queues, or watch API/MCP/CLI responses. A zero+interval keeps the token request-local. Git PATs have no generic refresh flow, so recreate the+Watch when a token expires or is revoked.++Private watch state is stored in `viking://resources/.watch_tasks.json`. It is encrypted at rest+when VikingFS file encryption is enabled; otherwise the server-side control file and its backup+contain plaintext token state. Restrict server storage access and enable encryption in production.++Native credential imports wait for clone and parse before the server returns a task, even without+`--wait`; the CLI therefore uses a 300-second request timeout by default for these assets. Use+`--timeout <seconds>` for a larger repository. The token is carried in the HTTPS request body, so+keep diagnostic request-body dumping disabled in production.Omit `auth_ref` when the target service already has the SSH keys or other authentication needed toaccess the repository.@@ -355,8 +372,9 @@ Temporarily apply a 60-minute interval to every selected asset:ov add-resource --manifest manifest.yaml --watch-interval 60```-Subsequent content refreshes are performed by Watches. You do not need to apply the Manifest on a-schedule. Reapply it to pick up Catalog or Manifest composition changes, retry failed assets, or+Subsequent content refreshes are performed by Watches. For native HTTPS Git assets using+`auth_ref`, the server restores the repository-bound token from private Watch state for each+refresh. Reapply assets to pick up Catalog or Manifest composition changes, retry failures, orexplicitly trigger synchronization.## Failure Handling@@ -396,7 +414,7 @@ Options used with `--manifest`:| `-m, --manifest <file>` | Manifest file. || `--args <key:value,...>` | Manifest-run options, comma-separated; supported keys below. || `--wait` | Wait for each resource to finish processing. |-| `--timeout <seconds>` | Timeout used with `--wait`. |+| `--timeout <seconds>` | HTTP request timeout. Native private Git imports honor it even without `--wait`; their default is 300 seconds. || `--watch-interval <minutes>` | Override the refresh interval for all assets. |Run options supported by `--args`:diff --git a/docs/zh/api/01-overview.md b/docs/zh/api/01-overview.mdindex 859ee5b9c..7bb23870a 100644--- a/docs/zh/api/01-overview.md+++ b/docs/zh/api/01-overview.md@@ -395,6 +395,7 @@ JSON 输出 - 错误:| POST | `/api/v1/sessions` | 创建会话 || GET | `/api/v1/sessions` | 列出会话 || GET | `/api/v1/sessions/{session_id}` | 获取会话 |+| PATCH | `/api/v1/sessions/{session_id}/config` | 更新可变的会话配置 || GET | `/api/v1/sessions/{session_id}/tool-results` | 列出工具结果 || GET | `/api/v1/sessions/{session_id}/tool-results/{tool_result_id}` | 读取工具结果 || GET | `/api/v1/sessions/{session_id}/tool-results/{tool_result_id}/search` | 在工具结果内搜索 |diff --git a/docs/zh/api/02-resources.md b/docs/zh/api/02-resources.mdindex 19b740dd4..6eaf34ce1 100644--- a/docs/zh/api/02-resources.md+++ b/docs/zh/api/02-resources.md@@ -170,7 +170,7 @@ URL/文件 Parser TreeBuilder AGFS Summarizer/Vector| exclude | string | 否 | None | 排除的文件模式(glob) || directly_upload_media | bool | 否 | True | 是否直接上传媒体文件 || preserve_structure | bool | 否 | None | 是否保留目录结构 |-| args | object | 否 | `{}` | 传给特定 parser/accessor 的导入参数。`args.parse_mode` 支持 `default`(保持现有拆分行为)和 `no_split`(正常解析并将每个源文档正文保存为一个 Markdown 文件)。例如 `args.site=true/false` 强制/禁用整站(sitemap/RSS)导入,`args.max_pages` 等可覆盖 `webfeed` 配置;递归网页爬虫支持 `args.depth`、`args.max_pages`、`args.include_paths`、`args.exclude_paths`、`args.allow_external_links`、`args.skip_download_links`;飞书用户 token 导入传 `args.feishu_access_token`。`path`、`to`、`watch_interval`、`include`、`exclude` 等 `add_resource` 核心字段不能放入 `args` |+| args | object | 否 | `{}` | 传给特定 parser/accessor 的导入参数。原生 HTTPS Git 导入和 Watch 可通过 `args.auth_config={"username":"oauth2","token":"..."}` 在 TLS 上传递 HTTP Basic 凭据;`username` 默认为 `oauth2`。Git 的 `branch` 或 `commit` 仍放在 `args` 顶层。`args.parse_mode` 支持 `default`(保持现有拆分行为)和 `no_split`(正常解析并将每个源文档正文保存为一个 Markdown 文件)。例如 `args.site=true/false` 强制/禁用整站(sitemap/RSS)导入,`args.max_pages` 等可覆盖 `webfeed` 配置;递归网页爬虫支持 `args.depth`、`args.max_pages`、`args.include_paths`、`args.exclude_paths`、`args.allow_external_links`、`args.skip_download_links`;飞书用户 token 导入传 `args.feishu_access_token`。`path`、`to`、`watch_interval`、`include`、`exclude` 等 `add_resource` 核心字段不能放入 `args` || watch_interval | float | 否 | 0 | 定时更新间隔(分钟)。>0 为 URL/sitemap/RSS 等可重新读取的来源创建任务;通过 `temp_file_id` 上传的内容是一次性快照,变化后需重新添加。≤0 取消任务;显式 `to` 优先,否则绑定本次导入的 `root_uri` || processing_mode | string | 否 | `semantic_and_vectors` | 入库后的处理模式。`semantic_and_vectors` 是默认流程:生成语义产物(`.abstract.md`、`.overview.md`)并生成向量。`vectors_only` 跳过语义理解/VLM 总结,只对当前资源文件生成向量 || tags | string[] | 否 | None | 导入时写入向量检索记录的显式检索标签,格式必须是 `k=v`,例如 `["team=search", "env=test"]`。搜索接口可用同名 `tags` 参数过滤召回 |@@ -185,6 +185,8 @@ URL/文件 Parser TreeBuilder AGFS Summarizer/Vector- `path` 和 `temp_file_id` 不能同时指定,上传本地文件需要先通过 [temp_upload](#temp_upload) 上传获取 `temp_file_id`,在 SDK 和 CLI 中已经封装好。- `tags` 会在资源解析后、向量记录写入时同步写入底层向量库。`add_resource(tags=...)` 不返回 `tags_result`;需要验证时,可在 `/api/v1/search/find` 或 `/api/v1/search/search` 中传相同 `tags` 过滤召回。- 只有 Git 仓库来源在 `wait=false` 时使用完整后台导入;OpenViking 会先完成仓库 preflight 和目标规划,再返回 `task_id`。+- 原生 HTTPS Git 的 `args.auth_config` 在 `watch_interval <= 0` 时只用于本次请求;当 `watch_interval > 0` 时,OpenViking 会把与仓库 URL 绑定的 username/token 保存到 Watch 私有鉴权状态,并只在后续 Git 拉取时恢复使用。凭据不会进入普通持久队列,也不会出现在 Watch API/MCP/CLI 返回中。Git PAT 没有通用刷新流程,过期或撤销后需要重建 Watch 来更换 token。为兼容已有用法,系统仍接受 `https://user:token@host/repo.git` 形式的 URL 内嵌凭据并原样传递;由于该 URL 同时也是资源来源标识,它可能被记录到进程参数、日志、队列、资源元数据和 Watch 状态中。新接入建议使用 `args.auth_config`。`args.auth_config` 的明文 HTTP 鉴权和带鉴权重定向仍会被拒绝。+- token 会放在 HTTPS 请求体中传输。生产环境应保持诊断请求体 dump 关闭;显式启用该功能可能记录秘密。- `reason` 触发的记忆生成复用 `session.commit` 的抽取链路,只使用 `reason`、资源 URI、可用的资源名称和目录摘要,不会读取或展开完整资源正文;系统会写入 `entities`、`events`、`preferences` 等已有记忆类型,不创建独立的资源记忆目录。- 删除资源时,系统会在删除前扫描本次上下文对应的 self 或 peer 记忆中的 `resource_refs`,清理对应资源 URI 和由该 `reason` 引入的内容,并重新刷新相关记忆的语义索引。- 其他来源在 `wait=false` 时会在响应前完成来源解析、目标解析和 AGFS 写入,仅 semantic 与 embedding 队列继续异步处理。@@ -222,6 +224,23 @@ curl -X POST http://localhost:1933/api/v1/resources \"wait": true}'+# 导入并定时同步 HTTPS 私有 Git 仓库+curl -X POST http://localhost:1933/api/v1/resources \+ -H "Content-Type: application/json" \+ -H "X-API-Key: your-key" \+ -d '{+ "path": "https://git.example.com/team/private-repo.git",+ "to": "viking://resources/private-repo",+ "watch_interval": 60,+ "args": {+ "branch": "main",+ "auth_config": {+ "username": "oauth2",+ "token": "replace-with-your-token"+ }+ }+ }'+# 添加资源但只生成向量,不走 VLM 语义理解curl -X POST http://localhost:1933/api/v1/resources \-H "Content-Type: application/json" \diff --git a/docs/zh/api/05-sessions.md b/docs/zh/api/05-sessions.mdindex 18288e9ae..9dead5168 100644--- a/docs/zh/api/05-sessions.md+++ b/docs/zh/api/05-sessions.md@@ -44,7 +44,7 @@ Session API 按认证用户作用域访问会话,并返回 canonical user sess|------|------|------|--------|------|| session_id | str | 否 | None | 会话 ID。如果为 None,则创建一个自动生成 ID 的新会话 || memory_policy | object | 否 | None | 会话默认的记忆抽取策略。可选的 `self` 和 `peer` 开关控制写入目标;可选的 `working_memory.enabled=false` 跳过 archive summary;可选的顶层 `memory_types` 将抽取限制为指定的 enabled memory schema。所有 `enabled` 值都应使用 JSON 布尔值。旧版 boolean-like 值暂时仍兼容(字符串 `"false"` 会正确解析为 false),但会产生弃用警告。未传或为 `null` 时允许所有 enabled memory schema。非法结构或未知 memory type 会以 `InvalidArgumentError` 拒绝。 |-| auto_commit_policy | object | 否 | None | 可选的自动 commit 策略(见下表)。传入的字段会被校验并 clamp 到取值范围,然后合并到默认值之上;最终生效的策略会在响应的 `result.auto_commit_policy` 中返回,并持久化到 session meta。未传 policy 时 auto commit 关闭,除非 `memory.session_auto_commit.default_enabled=true`。该策略创建后不可变。 |+| auto_commit_policy | object | 否 | None | 可选的自动 commit 策略(见下表)。传入的字段会被校验并 clamp 到取值范围,然后合并到默认值之上;最终生效的策略会在响应的 `result.auto_commit_policy` 中返回,并持久化到 session meta。未传 policy 时 auto commit 关闭,除非 `memory.session_auto_commit.default_enabled=true`。之后可通过 `update_session_config()` 部分更新或禁用该策略。 |`auto_commit_policy` 字段(均为可选;存在 policy 时,未传字段回退到默认值):@@ -399,11 +399,139 @@ ov session get a1b2c3d4----### 更新 Session 配置+### update_session_config()-自动 commit 策略创建后不可变。请在创建 session 时设置-`auto_commit_policy`,之后通过 `GET /api/v1/sessions/{session_id}` 查看生效配置。-Sessions API 不提供运行期 session 配置更新接口。+#### 1. API 实现介绍++部分更新已有 session 的可变配置。修改会在后续消息写入、idle 扫描和 commit+中生效。只有 `/api/v1/sessions/{session_id}/config` 子路径接受 `PATCH`;基础+`/api/v1/sessions/{session_id}` 端点不支持该方法。++**代码入口**:+- `openviking/server/routers/sessions.py:update_session_config()` - HTTP 路由+- `openviking/service/session_service.py:SessionService.update_config()` - 配置校验与更新+- `sdk/python/openviking_sdk/client.py:update_session_config()` - Python SDK+- `sdk/typescript/src/client.ts:updateSessionConfig()` - TypeScript SDK+- `sdk/go/sessions.go:UpdateSessionConfig()` - Go SDK+- `crates/ov_cli/src/commands/session.rs:set_session_config()` - CLI 命令++#### 2. 接口和参数说明++| 参数 | 类型 | 必填 | 默认值 | 说明 |+|------|------|------|--------|------|+| session_id | string | 是 | - | URL 路径中的 session ID |+| memory_extraction_config | object | 否 | 未传 | 可变的抽取配置。目前支持 `events.tags`,其值为严格 `key=value` 字符串数组。省略时保留现有 tags;传 `events.tags=[]` 时清空。系统会 trim、转为小写并去重。 |+| auto_commit_policy | object 或 null | 否 | 未传 | object 只把已提供的策略字段合并到现有策略中,并沿用 `create_session()` 记录的校验、clamp、默认值和上限。传 `null` 禁用自动 commit;省略该字段则保持策略不变。策略内部的单个字段不能为 `null`。 |+| telemetry | boolean 或 object | 否 | `false` | 传 `true` 或 `{"summary": true}` 时在响应中包含本次操作的 telemetry summary;`false` 时省略。 |++空请求对象是合法的 no-op,并会返回当前生效配置。未知请求字段会被拒绝。+响应始终返回补齐默认值后的生效策略;自动 commit 已禁用时返回 `null`。++#### 3. 使用示例++**HTTP API**++```http+PATCH /api/v1/sessions/{session_id}/config+```++```bash+# 合并一个策略字段,并替换事件记忆的默认 tags+curl -X PATCH http://localhost:1933/api/v1/sessions/a1b2c3d4/config \+ -H "Content-Type: application/json" \+ -H "X-API-Key: your-key" \+ -d '{+ "memory_extraction_config": {+ "events": {"tags": ["team=search", "channel=app"]}+ },+ "auto_commit_policy": {"message_count_threshold": 25},+ "telemetry": true+ }'++# 禁用自动 commit,同时不修改事件记忆 tags+curl -X PATCH http://localhost:1933/api/v1/sessions/a1b2c3d4/config \+ -H "Content-Type: application/json" \+ -H "X-API-Key: your-key" \+ -d '{"auto_commit_policy": null}'+```++**Python SDK**++```python+result = client.update_session_config(+ "a1b2c3d4",+ memory_extraction_config={+ "events": {"tags": ["team=search", "channel=app"]}+ },+ auto_commit_policy={"message_count_threshold": 25},+)+```++**TypeScript SDK**++```typescript+const result = await client.updateSessionConfig("a1b2c3d4", {+ memoryExtractionConfig: {+ events: { tags: ["team=search", "channel=app"] },+ },+ autoCommitPolicy: { message_count_threshold: 25 },+});+```++**Go SDK**++```go+policy := map[string]any{"message_count_threshold": 25}+result, err := client.UpdateSessionConfig(ctx, "a1b2c3d4", &openviking.UpdateSessionConfigOptions{+ MemoryExtractionConfig: map[string]any{+ "events": map[string]any{"tags": []string{"team=search", "channel=app"}},+ },+ AutoCommitPolicy: &policy,+})+```++**CLI**++```bash+ov session config set a1b2c3d4 \+ --event-tags team=search,channel=app \+ --auto-commit-policy-json '{"message_count_threshold":25}'++# 清空默认 tags,或禁用自动 commit+ov session config set a1b2c3d4 --no-event-tags+ov session config set a1b2c3d4 --no-auto-commit+```++**响应示例**++```json+{+ "status": "ok",+ "result": {+ "session_id": "a1b2c3d4",+ "auto_commit_policy": {+ "pending_token_threshold": 10000,+ "message_count_threshold": 25,+ "idle_timeout_seconds": 86400,+ "keep_recent_count": 2,+ "min_commit_interval_seconds": 0+ },+ "memory_extraction_config": {+ "events": {+ "tags": ["team=search", "channel=app"]+ }+ }+ },+ "telemetry": {+ "id": "tm_xxx",+ "summary": {+ "operation": "session.update_config",+ "status": "ok",+ "duration_ms": 4.2+ }+ }+}+```---diff --git a/docs/zh/guides/01-configuration.md b/docs/zh/guides/01-configuration.mdindex ea2ddc609..63cfb4700 100644--- a/docs/zh/guides/01-configuration.md+++ b/docs/zh/guides/01-configuration.md@@ -1295,7 +1295,7 @@ Redis Sentinel 分别配置数据节点和 Sentinel 的 ACL:说明:- `memory.session_auto_commit` 是服务端全局配置,不是单个 session 的业务 policy。-- session 级别的自动触发参数通过 session 级 `auto_commit_policy` 设置(见下表)。它只能在创建 session 时通过 `POST /api/v1/sessions` 的顶层 `auto_commit_policy` 字段设置,之后通过 `GET /api/v1/sessions/{session_id}` 查看;不支持运行期 PATCH 修改。+- session 级别的自动触发参数通过 session 级 `auto_commit_policy` 设置(见下表)。可以在创建 session 时通过 `POST /api/v1/sessions` 设置,也可以通过 `PATCH /api/v1/sessions/{session_id}/config` 部分更新。PATCH 时省略 `auto_commit_policy` 会保留现有策略,传 `null` 会禁用自动 commit;通过 `GET /api/v1/sessions/{session_id}` 查看生效策略。- `default_enabled=false` 时,未传 `auto_commit_policy` 创建的 session 保持 auto commit 关闭,返回 `auto_commit_policy: null`。显式传 `{}` 或任意 policy 字段会为该 session 开启 auto commit,并用下方默认值补齐缺失字段。- `default_enabled=true` 时,未传 `auto_commit_policy` 创建的 session 会带上下方默认 policy。- `idle_enabled=false` 时:diff --git a/docs/zh/guides/18-openviking-assets.md b/docs/zh/guides/18-openviking-assets.mdindex f28cf7678..dbeaf6822 100644--- a/docs/zh/guides/18-openviking-assets.md+++ b/docs/zh/guides/18-openviking-assets.md@@ -63,7 +63,7 @@ protocol: openviking-assets/1defaults:git:auth_ref: team-git- watch_interval: 1440+ watch_interval: 60catalog:- name: openviking@@ -131,7 +131,7 @@ protocol: openviking-assets/1defaults:git:auth_ref: team-git- watch_interval: 1440+ watch_interval: 60catalog:- name: openviking@@ -275,9 +275,23 @@ export OPENVIKING_ASSETS_CREDENTIALS_FILE=/secure/path/assets-credentials.yaml执行前,CLI 会先解析所有选中资产的 `auth_ref`,然后由服务端在实际执行环境中用`git ls-remote` 校验每个仓库的读取权限。只要有一个别名不存在或仓库不可读,整个操作都会-在提交任何资源之前失败;`dry_run` 也执行相同预检。解析出的 Git 参数会通过当前配置的-OpenViking 服务连接发送给 preflight 和资源接口,因此远程部署应使用 TLS,并限制凭据文件-的本地访问权限。+在提交任何资源之前失败;`dry_run` 也执行相同预检。原生 Git 凭据别名只支持 `username` 和+`token`,并保持上述扁平结构。使用默认的原生 Git 链路时,CLI 会在调用 `add_resource` 时将它们放入+`args.auth_config`,而 `branch` 或 `commit` 仍留在 `args` 顶层。解析出的 Git 参数会通过+当前配置的 OpenViking 服务连接发送,因此远程部署应使用 TLS,并限制凭据文件的本地访问权限。++当最终 `watch_interval` 大于 `0` 时,OpenViking 会把通过 `auth_ref` 解析出的 HTTPS Git+token 保存到 Watch task 私有且与仓库 URL 绑定的鉴权状态中。token 不会写入 Manifest+State、普通入库队列或 Watch API/MCP/CLI 返回。周期为 `0` 时,token 仍只在本次请求内使用。+Git PAT 没有通用刷新流程,token 过期或被撤销后需要重建 Watch。++Watch 私有状态保存在 `viking://resources/.watch_tasks.json`。启用 VikingFS 文件加密时会+静态加密;否则服务端控制文件及其备份包含明文 token 状态。生产环境应限制服务端存储访问并+启用加密。++即使没有指定 `--wait`,原生凭据导入也需要等 clone 和 parse 完成后,服务端才会返回 task;+因此 CLI 对这类资产默认使用 300 秒请求超时,大仓库可通过 `--timeout <秒>` 调大。token+会放在 HTTPS 请求体中传输,生产环境应保持诊断请求体 dump 关闭。如果目标服务已经具备访问仓库所需的 SSH key 或其他认证配置,可以不设置 `auth_ref`。@@ -336,8 +350,9 @@ State 属于执行环境,不是 Catalog 或 Manifest 协议的一部分。共ov add-resource --manifest manifest.yaml --watch-interval 60```-后续内容刷新由 Watch 执行,不需要周期性重新运行 Manifest。重新运行 Manifest 主要用于应用-Catalog 或 Manifest 的构成变化、恢复失败资产,或显式触发同步。+后续内容刷新由 Watch 执行。原生 HTTPS Git 资产使用 `auth_ref` 时,服务端会在每次刷新时+从 Watch 私有状态恢复与仓库绑定的 token。重新运行 Manifest 仍可用于应用 Catalog/Manifest+构成变化、恢复失败资产或显式触发同步。## 失败处理@@ -375,7 +390,7 @@ ov add-resource --manifest manifest.yaml --args skip_failed:true| `-m, --manifest <file>` | Manifest 文件。 || `--args <key:value,...>` | Manifest 运行选项,多个选项用逗号分隔,支持的键见下表。 || `--wait` | 等待每个资源处理完成。 |-| `--timeout <seconds>` | `--wait` 的超时时间。 |+| `--timeout <seconds>` | HTTP 请求超时。原生私有 Git 即使没有 `--wait` 也会使用该值,默认 300 秒。 || `--watch-interval <minutes>` | 覆盖全部资产的更新周期。 |`--args` 支持的运行选项:diff --git a/examples/openviking-assets/catalog.yaml b/examples/openviking-assets/catalog.yamlindex 06edc8604..ae43ca171 100644--- a/examples/openviking-assets/catalog.yaml+++ b/examples/openviking-assets/catalog.yaml@@ -11,6 +11,7 @@ catalog:- name: openvikingconnector: gitdescription: OpenViking main repository — server, CLI and SDKs+ to: viking://resources/repos/openvikingparams:repo_url: https://github.com/volcengine/OpenVikingbranch: maindiff --git a/openviking/parse/accessors/git_accessor.py b/openviking/parse/accessors/git_accessor.pyindex 8b57621c2..7752ea49b 100644--- a/openviking/parse/accessors/git_accessor.py+++ b/openviking/parse/accessors/git_accessor.py@@ -8,6 +8,7 @@ This is the DataAccessor layer extracted from CodeRepositoryParser."""import asyncio+import contextlibimport osimport shutilimport stat@@ -28,6 +29,10 @@ from openviking.utils.code_hosting_utils import (is_git_repo_url,validate_git_ssh_uri,)+from openviking.utils.git_auth import (+ build_git_http_auth_env,+ parse_git_http_auth_config,+)from openviking_cli.utils.logger import get_loggerfrom .base import DataAccessor, LocalResource, SourceType@@ -101,6 +106,8 @@ class GitAccessor(DataAccessor):temp_local_dir = Nonebranch = kwargs.get("branch") or kwargs.get("ref")commit = kwargs.get("commit")+ auth_config = parse_git_http_auth_config(kwargs.get("auth_config"), source_str)+ git_env = Nonetry:# Create local temp directory (non-blocking)@@ -118,10 +125,13 @@ class GitAccessor(DataAccessor):temp_local_dir,branch=branch,commit=commit,+ env=git_env,)elif source_str.startswith(("http://", "https://", "git://", "ssh://")):repo_url, branch, commit = self._parse_repo_source(source_str, **kwargs)- if self._is_github_url(repo_url):+ if auth_config is not None:+ git_env = build_git_http_auth_env(auth_config, repo_url)+ if self._is_github_url(repo_url) and auth_config is None:# Try GitHub ZIP API first, fall back to git clonetry:local_dir, repo_name = await self._github_zip_download(@@ -146,8 +156,9 @@ class GitAccessor(DataAccessor):temp_local_dir,branch=branch,commit=commit,+ env=git_env,)- elif self._can_use_gitlab_zip(repo_url):+ elif self._can_use_gitlab_zip(repo_url) and auth_config is None:# Try GitLab ZIP API first, fall back to git clonetry:local_dir, repo_name = await self._gitlab_zip_download(@@ -172,6 +183,7 @@ class GitAccessor(DataAccessor):temp_local_dir,branch=branch,commit=commit,+ env=git_env,)else:# Other configured code-hosting URLs: use git clone@@ -180,6 +192,7 @@ class GitAccessor(DataAccessor):temp_local_dir,branch=branch,commit=commit,+ env=git_env,)else:raise ValueError(f"Unsupported source for GitAccessor: {source}")@@ -201,10 +214,12 @@ class GitAccessor(DataAccessor):is_temporary=True,)- except Exception as e:- logger.error(- f"[GitAccessor] Failed to access git repository {source}: {e}", exc_info=True- )+ except BaseException as e:+ if not isinstance(e, asyncio.CancelledError):+ logger.error(+ f"[GitAccessor] Failed to access git repository {source}: {e}",+ exc_info=True,+ )# Clean up on errorif temp_local_dir and os.path.exists(temp_local_dir):try:@@ -272,15 +287,29 @@ class GitAccessor(DataAccessor):name = "".join(c if c.isalnum() or c in "-_" else "_" for c in name)return name or "repository"- async def _run_git(self, args: list[str], cwd: Optional[str] = None) -> str:+ async def _run_git(+ self,+ args: list[str],+ cwd: Optional[str] = None,+ env: Optional[dict[str, str]] = None,+ ) -> str:"""Run a git command."""- proc = await asyncio.create_subprocess_exec(- *args,- cwd=cwd,- stdout=asyncio.subprocess.PIPE,- stderr=asyncio.subprocess.PIPE,- )- stdout, stderr = await proc.communicate()+ process_kwargs = {+ "cwd": cwd,+ "stdout": asyncio.subprocess.PIPE,+ "stderr": asyncio.subprocess.PIPE,+ }+ if env is not None:+ process_kwargs["env"] = env+ proc = await asyncio.create_subprocess_exec(*args, **process_kwargs)+ try:+ stdout, stderr = await proc.communicate()+ except BaseException:+ with contextlib.suppress(ProcessLookupError):+ proc.kill()+ with contextlib.suppress(Exception):+ await asyncio.shield(proc.wait())+ raiseif proc.returncode != 0:error_msg = stderr.decode().strip()user_msg = "Git command failed."@@ -292,14 +321,28 @@ class GitAccessor(DataAccessor):user_msg = ("Git command failed: authentication error. Check your SSH keys or credentials.")- logger.warning(f"[GitAccessor] {user_msg} Details: {error_msg}")+ if env is None:+ logger.warning(f"[GitAccessor] {user_msg} Details: {error_msg}")+ else:+ # An authenticated remote controls parts of stderr and may echo+ # the request's Authorization header. Keep credentialed failures+ # out of logs as well as argv and raised exceptions.+ logger.warning(f"[GitAccessor] {user_msg}")raise RuntimeError(user_msg)return stdout.decode().strip()- async def _has_commit(self, repo_dir: str, commit: str) -> bool:+ async def _has_commit(+ self,+ repo_dir: str,+ commit: str,+ env: Optional[dict[str, str]] = None,+ ) -> bool:"""Check if a commit exists in the repository."""try:- await self._run_git(["git", "-C", repo_dir, "rev-parse", "--verify", commit])+ await self._run_git(+ ["git", "-C", repo_dir, "rev-parse", "--verify", commit],+ env=env,+ )return Trueexcept RuntimeError:return False@@ -327,6 +370,7 @@ class GitAccessor(DataAccessor):target_dir: str,branch: Optional[str] = None,commit: Optional[str] = None,+ env: Optional[dict[str, str]] = None,) -> str:"""Clone a git repository into target_dir; return the repo name."""name = self._get_repo_name(url)@@ -342,27 +386,32 @@ class GitAccessor(DataAccessor):if branch and not commit:clone_args.extend(["--branch", branch])clone_args.extend([url, target_dir])- await self._run_git(clone_args)+ await self._run_git(clone_args, env=env)if commit:try:- await self._run_git(["git", "-C", target_dir, "fetch", "origin", commit])+ await self._run_git(+ ["git", "-C", target_dir, "fetch", "origin", commit],+ env=env,+ )except RuntimeError:try:await self._run_git(- ["git", "-C", target_dir, "fetch", "--all", "--tags", "--prune"]+ ["git", "-C", target_dir, "fetch", "--all", "--tags", "--prune"],+ env=env,)except RuntimeError:pass- ok = await self._has_commit(target_dir, commit)+ ok = await self._has_commit(target_dir, commit, env=env)if not ok:try:await self._run_git(- ["git", "-C", target_dir, "fetch", "--unshallow", "origin"]+ ["git", "-C", target_dir, "fetch", "--unshallow", "origin"],+ env=env,)except RuntimeError:pass- ok = await self._has_commit(target_dir, commit)+ ok = await self._has_commit(target_dir, commit, env=env)if not ok:await self._run_git([@@ -372,12 +421,16 @@ class GitAccessor(DataAccessor):"fetch","origin","+refs/heads/*:refs/remotes/origin/*",- ]+ ],+ env=env,)- ok = await self._has_commit(target_dir, commit)+ ok = await self._has_commit(target_dir, commit, env=env)if not ok:raise RuntimeError(f"Failed to fetch commit {commit} from {url}")- await self._run_git(["git", "-C", target_dir, "checkout", commit])+ await self._run_git(+ ["git", "-C", target_dir, "checkout", commit],+ env=env,+ )# Add .git_source_repo marker file with original URL (for consistency)def _write_marker():diff --git a/openviking/resource/git_watch_auth.py b/openviking/resource/git_watch_auth.pynew file mode 100644index 000000000..2cdce54d9--- /dev/null+++ b/openviking/resource/git_watch_auth.py@@ -0,0 +1,52 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0+"""Private authentication state for watched HTTPS Git repositories."""++from __future__ import annotations++from typing import Any, Dict, Optional++from openviking.utils.git_auth import GitHttpAuthConfig, parse_git_http_auth_config+from openviking_cli.exceptions import InvalidArgumentError++GIT_HTTP_AUTH_PROVIDER = "git_http_basic"+++def create_git_http_auth_state(+ config: GitHttpAuthConfig,+ repo_url: str,+) -> Dict[str, Any]:+ """Create private, repository-bound auth state for a Git watch task."""+ return {+ "provider": GIT_HTTP_AUTH_PROVIDER,+ "username": config.username,+ "token": config.token,+ "repo_url": repo_url.strip(),+ }+++def is_git_http_auth_state(auth_state: Optional[Dict[str, Any]]) -> bool:+ return isinstance(auth_state, dict) and auth_state.get("provider") == GIT_HTTP_AUTH_PROVIDER+++def git_http_auth_config_from_state(+ auth_state: Dict[str, Any],+ repo_url: str,+) -> Dict[str, str]:+ """Restore request-local Git auth after validating its repository binding."""+ bound_repo_url = auth_state.get("repo_url")+ if not isinstance(bound_repo_url, str) or bound_repo_url.strip() != repo_url.strip():+ raise InvalidArgumentError(+ "Stored Git watch credentials do not match the watched repository."+ )++ config = parse_git_http_auth_config(+ {+ "username": auth_state.get("username"),+ "token": auth_state.get("token"),+ },+ repo_url,+ )+ if config is None: # pragma: no cover - the mapping above is never None+ raise InvalidArgumentError("Stored Git watch credentials are invalid.")+ return {"username": config.username, "token": config.token}diff --git a/openviking/resource/watch_scheduler.py b/openviking/resource/watch_scheduler.pyindex 7e12b2bcc..9dc9d10d4 100644--- a/openviking/resource/watch_scheduler.py+++ b/openviking/resource/watch_scheduler.py@@ -17,6 +17,10 @@ from openviking.resource.feishu_watch_auth import (feishu_auth_state_needs_refresh,is_feishu_auth_state,)+from openviking.resource.git_watch_auth import (+ git_http_auth_config_from_state,+ is_git_http_auth_state,+)from openviking.resource.uri_mutation_coordinator import UriMutationCoordinatorfrom openviking.resource.watch_manager import WatchManagerfrom openviking.server.error_mapping import is_not_found_error@@ -318,6 +322,11 @@ class WatchScheduler:)else:raise+ elif is_git_http_auth_state(auth_state):+ processor_kwargs["auth_config"] = git_http_auth_config_from_state(+ auth_state,+ task.path,+ )if not should_deactivate:result = await self._resource_service.refresh_resource(diff --git a/openviking/server/mcp_endpoint.py b/openviking/server/mcp_endpoint.pyindex 3e2c3f695..63593c249 100644--- a/openviking/server/mcp_endpoint.py+++ b/openviking/server/mcp_endpoint.py@@ -587,9 +587,10 @@ async def add_resource(with ``to`` and not supported when ``add_type`` is set.tags: Optional explicit k=v retrieval tags to apply after ingestion.tag_mode: Tag update mode, "replace" or "append". Defaults to "replace".- args: Parser-specific options, e.g. {"feishu_access_token": "..."} for Feishu imports,- {"site": true} for whole-site ingestion, or {"parse_mode": "no_split"}- to keep each parsed document body in one file.+ args: Parser-specific options, e.g. {"auth_config": {"token": "..."}}+ for native HTTPS Git imports and watches, {"feishu_access_token": "..."}+ for Feishu imports, {"site": true} for whole-site ingestion, or+ {"parse_mode": "no_split"} to keep each parsed document body in one file."""from openviking.server.local_input_guard import require_remote_resource_sourcediff --git a/openviking/server/openviking_assets.py b/openviking/server/openviking_assets.pyindex 4ccb0758f..4f54b562e 100644--- a/openviking/server/openviking_assets.py+++ b/openviking/server/openviking_assets.py@@ -5,7 +5,7 @@from __future__ import annotationsimport asyncio-import base64+import contextlibimport hashlibimport mathimport os@@ -15,7 +15,14 @@ from typing import Anyimport yamlfrom pydantic import BaseModel, ConfigDict, ValidationError+from openviking.core.namespace import classify_uri, uri_parts+from openviking.core.uri_validation import validate_content_target_uri, validate_viking_uri+from openviking.server.identity import RequestContextfrom openviking.server.local_input_guard import require_remote_resource_source+from openviking.utils.git_auth import (+ GitHttpAuthConfig,+ build_git_http_auth_env,+)from openviking_cli.exceptions import (DeadlineExceededError,InvalidArgumentError,@@ -27,6 +34,7 @@ from openviking_cli.exceptions import (PROTOCOL = "openviking-assets/1"GIT_PREFLIGHT_TIMEOUT_SECONDS = 15.0_ASSET_NAME_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*$")+_FULL_COMMIT_SHA_RE = re.compile(r"^[0-9a-fA-F]{40}$")_REMOTE_HELPER_RE = re.compile(r"^[A-Za-z][A-Za-z0-9+.-]*::")_NETWORK_FAILURE_PATTERNS = ("could not resolve host",@@ -56,6 +64,7 @@ class _CatalogAsset(_StrictModel):name: strconnector: strdescription: str = ""+ to: str | None = Noneparams: dict[str, Any]auth_ref: str | None = Nonewatch_interval: float | None = None@@ -85,6 +94,7 @@ class _Manifest(_StrictModel):class _GitParams(_StrictModel):repo_url: strbranch: str | None = None+ commit: str | None = Noneclass ResolvedAsset(_StrictModel):@@ -92,8 +102,10 @@ class ResolvedAsset(_StrictModel):name: strconnector: str+ to: str | None = Nonerepo_url: strbranch: str | None = None+ commit: str | None = Noneauth_ref: str | None = Nonewatch_interval: floatlocator: str@@ -135,6 +147,38 @@ def _check_watch_interval(value: float | None, where: str) -> float | None:return value+def _normalize_asset_target_uri(+ value: str | None,+ where: str,+ ctx: RequestContext | None,+) -> str | None:+ """Validate one optional exact resource target and return its normalized URI."""++ if value is None:+ return None+ target = value.strip()+ if not target:+ raise InvalidArgumentError(f"{where}: 'to' must be a non-empty string when set")++ if ctx is not None:+ # Use the same canonicalization, namespace-shape and access checks as+ # add_resource itself. In particular, this expands current-user+ # shorthand before the plan reaches the CLI and its local State file.+ return validate_content_target_uri(target, ctx, kind="resource", field_name="to")++ # Direct resolver callers do not always have a request identity. Preserve+ # that API while still enforcing the public URI grammar and resource shape;+ # HTTP callers take the context-aware path above.+ normalized = validate_viking_uri(target, field_name="to").rstrip("/")+ parts = uri_parts(normalized)+ classification = classify_uri(normalized)+ if parts[:1] == ["resources"] or (+ classification.context_type == "resource" and classification.content_index is not None+ ):+ return normalized+ raise InvalidArgumentError(f"{where}: 'to' must target resource content")++def _strip_port(host: str) -> str:head, separator, tail = host.rpartition(":")if separator and tail and tail.isascii() and tail.isdigit():@@ -201,6 +245,17 @@ def _asset_id(connector: str, locator: str, git_ref: str) -> str:return hashlib.sha1(identity).hexdigest()[:12] # noqa: S324 - stable identity, not security+def _normalize_commit_sha(commit: str | None, where: str) -> str | None:+ if commit is None:+ return None+ normalized = commit.strip()+ if not normalized:+ raise InvalidArgumentError(f"{where}: commit must be a non-empty string when set")+ if not _FULL_COMMIT_SHA_RE.fullmatch(normalized):+ raise InvalidArgumentError(f"{where}: commit must be a full 40-character hexadecimal SHA")+ return normalized.lower()++def _append_git_process_config(env: dict[str, str], key: str, value: str) -> None:"""Append one process-local Git config entry without putting secrets in argv."""@@ -218,6 +273,7 @@ async def preflight_git_repository(asset_name: str,repo_url: str,branch: str | None = None,+ commit: str | None = None,username: str | None = None,token: str | None = None,timeout: float = GIT_PREFLIGHT_TIMEOUT_SECONDS,@@ -234,12 +290,18 @@ async def preflight_git_repository(raise InvalidArgumentError(f"asset '{asset_name}': branch must be a non-empty string when set")+ normalized_commit = _normalize_commit_sha(commit, f"asset '{asset_name}'")+ if normalized_branch and normalized_commit:+ raise InvalidArgumentError(+ f"asset '{asset_name}': branch and commit are mutually exclusive"+ )+ git_ref = normalized_commit or normalized_branchnormalized_token = token or ""normalized_username = (username or ("oauth2" if normalized_token else "")).strip()- if normalized_token and not repo_url.strip().lower().startswith(("http://", "https://")):+ if normalized_token and not repo_url.strip().lower().startswith("https://"):raise InvalidArgumentError(- f"asset '{asset_name}': token authentication requires an HTTP(S) Git URL"+ f"asset '{asset_name}': token authentication requires an HTTPS Git URL")if normalized_token and not normalized_username:raise InvalidArgumentError(@@ -253,11 +315,11 @@ async def preflight_git_repository(if normalized_token:# An explicit auth_ref must be authoritative: disable credential-helper# fallback and pass HTTP Basic auth through process-local config.- _append_git_process_config(env, "credential.helper", "")- encoded = base64.b64encode(- f"{normalized_username}:{normalized_token}".encode()- ).decode()- _append_git_process_config(env, "http.extraHeader", f"Authorization: Basic {encoded}")+ env = build_git_http_auth_env(+ GitHttpAuthConfig(username=normalized_username, token=normalized_token),+ repo_url,+ base_env=env,+ )elif normalized_username:_append_git_process_config(env, "credential.username", normalized_username)@@ -270,6 +332,10 @@ async def preflight_git_repository(])else:+ # ls-remote cannot prove that an arbitrary historical commit is+ # reachable. For a pinned commit, preflight therefore verifies repository+ # access via HEAD; the import pipeline validates the exact SHA when it+ # fetches and checks out the commit.command.append("HEAD")try:@@ -288,6 +354,12 @@ async def preflight_git_repository(process.kill()await process.communicate()raise DeadlineExceededError("Git repository permission preflight", timeout) from exc+ except BaseException:+ with contextlib.suppress(ProcessLookupError):+ process.kill()+ with contextlib.suppress(Exception):+ await asyncio.shield(process.wait())+ raiselocator = normalize_repo_url(repo_url)if process.returncode == 0:@@ -295,7 +367,7 @@ async def preflight_git_repository("name": asset_name,"connector": "git","locator": locator,- "git_ref": normalized_branch,+ "git_ref": git_ref,"accessible": True,}@@ -320,6 +392,7 @@ def resolve_openviking_assets(catalog_yaml: str | None = None,manifest_label: str = "manifest.yaml",catalog_label: str = "catalog.yaml",+ ctx: RequestContext | None = None,) -> ResolveResult:"""Parse and resolve one flat manifest, optionally against a separate catalog.@@ -359,9 +432,7 @@ def resolve_openviking_assets(f"manifest '{manifest_label}': 'protocol' is required when the manifest "f"defines 'catalog' (expected '{PROTOCOL}')")- catalog = _Catalog(- protocol=PROTOCOL, defaults=manifest.defaults, catalog=manifest.catalog- )+ catalog = _Catalog(protocol=PROTOCOL, defaults=manifest.defaults, catalog=manifest.catalog)catalog_label = manifest_labelelse:if manifest.defaults is not None:@@ -448,9 +519,19 @@ def resolve_openviking_assets(resolved: list[ResolvedAsset] = []identity_names: dict[str, str] = {}+ target_names: dict[str, str] = {}for name in names:asset = catalog_by_name[name]where = f"catalog '{catalog_label}' asset '{name}'"+ target = _normalize_asset_target_uri(asset.to, where, ctx)+ if target is not None:+ if target in target_names:+ other = target_names[target]+ raise InvalidArgumentError(+ f"assets '{other}' and '{name}' declare the same target URI '{target}'; "+ "each selected asset must use a unique 'to'"+ )+ target_names[target] = nametry:params = _GitParams.model_validate(asset.params)except ValidationError as exc:@@ -462,8 +543,13 @@ def resolve_openviking_assets(raise InvalidArgumentError(f"{where}: params.branch must be a non-empty string when set")+ commit = _normalize_commit_sha(params.commit, f"{where}: params")+ if branch and commit:+ raise InvalidArgumentError(+ f"{where}: params.branch and params.commit are mutually exclusive"+ )locator = normalize_repo_url(repo_url)- git_ref = branch or ""+ git_ref = commit or branch or ""asset_id = _asset_id(asset.connector, locator, git_ref)if asset_id in identity_names:other = identity_names[asset_id]@@ -477,8 +563,10 @@ def resolve_openviking_assets(ResolvedAsset(name=name,connector=asset.connector,+ to=target,repo_url=repo_url,branch=branch,+ commit=commit,auth_ref=asset.auth_ref or default_auth_ref,watch_interval=(asset.watch_interval if asset.watch_interval is not None else default_watchdiff --git a/openviking/server/routers/openviking_assets.py b/openviking/server/routers/openviking_assets.pyindex 7635ce9b9..36ec693af 100644--- a/openviking/server/routers/openviking_assets.py+++ b/openviking/server/routers/openviking_assets.py@@ -47,13 +47,14 @@ class PreflightOpenVikingAssetRequest(BaseModel):connector: Literal["git"]repo_url: str = Field(min_length=1, max_length=8192)branch: str | None = Field(default=None, min_length=1, max_length=1024)+ commit: str | None = Field(default=None, min_length=1, max_length=40)auth_config: GitAuthConfig | None = None@router.post("/resolve")async def resolve_assets(request: ResolveOpenVikingAssetsRequest,- _ctx: RequestContext = Depends(get_request_context),+ ctx: RequestContext = Depends(get_request_context),):"""Parse and validate configuration without submitting resources."""@@ -62,6 +63,7 @@ async def resolve_assets(catalog_yaml=request.catalog_yaml,manifest_label=request.manifest_label,catalog_label=request.catalog_label,+ ctx=ctx,)return response_from_result(result.model_dump())@@ -78,6 +80,7 @@ async def preflight_asset(asset_name=request.name,repo_url=request.repo_url,branch=request.branch,+ commit=request.commit,username=auth.username if auth else None,token=auth.token.get_secret_value() if auth and auth.token else None,)diff --git a/openviking/server/routers/resources.py b/openviking/server/routers/resources.pyindex 55cf40f0a..4fc9d73d8 100644--- a/openviking/server/routers/resources.py+++ b/openviking/server/routers/resources.py@@ -56,7 +56,10 @@ class AddResourceRequest(BaseModel):exclude: Glob pattern for files to exclude during parsing.directly_upload_media: Whether to directly upload media files. Default is True.preserve_structure: Whether to preserve directory structure when adding directories.- args: Parser-specific import options. For Feishu one-time user-token imports,+ args: Parser-specific import options. Native HTTPS Git imports accept+ {"auth_config": {"username": "oauth2", "token": "..."}}; when+ watch_interval > 0 the credentials are stored in private watch state.+ For Feishu one-time user-token imports,pass {"feishu_access_token": "..."}. For Feishu user-token watches,pass {"feishu_access_token": "...", "feishu_refresh_token": "..."}.watch_interval: Watch interval in minutes for automatic resource monitoring.@@ -67,9 +70,9 @@ class AddResourceRequest(BaseModel):- watch_interval < 0: Same as watch_interval = 0, cancels any existing watch task.Default is 0 (no monitoring).- Note: If the target URI already has an active watch task, a ConflictError will be- raised. You must first cancel the existing watch (set watch_interval <= 0) before- creating a new one.+ Note: Re-adding the same source to the same target updates its active watch task.+ A different source targeting an active watch raises ConflictError; cancel that+ watch first with watch_interval <= 0."""model_config = ConfigDict(extra="forbid")diff --git a/openviking/service/resource_service.py b/openviking/service/resource_service.pyindex d45598b79..25eba470d 100644--- a/openviking/service/resource_service.py+++ b/openviking/service/resource_service.py@@ -27,6 +27,7 @@ from openviking.resource.feishu_watch_auth import (create_feishu_auth_state,load_feishu_app_credentials,)+from openviking.resource.git_watch_auth import create_git_http_auth_statefrom openviking.resource.processing_mode import (DEFAULT_PROCESSING_MODE,ProcessingMode,@@ -50,6 +51,7 @@ from openviking.telemetry.resource_summary import (build_queue_status_payload,)from openviking.utils import is_git_repo_url, parse_code_hosting_url+from openviking.utils.git_auth import parse_git_http_auth_configfrom openviking.utils.ingest_options import IngestOptionsfrom openviking.utils.media_processor import _smart_stemfrom openviking.utils.network_guard import ensure_public_remote_target@@ -192,6 +194,12 @@ class ResourceService:def _sanitize_watch_processor_kwargs(self, processor_kwargs: Dict[str, Any]) -> Dict[str, Any]:sanitized: Dict[str, Any] = {}for key, value in processor_kwargs.items():+ if key in {+ "auth_config",+ FEISHU_ACCESS_TOKEN_ARG,+ FEISHU_REFRESH_TOKEN_ARG,+ }:+ continuetry:json.dumps(value, ensure_ascii=False)except TypeError:@@ -287,8 +295,6 @@ class ResourceService:)try:sanitized = self._sanitize_watch_processor_kwargs(processor_kwargs)- if watch_auth_state is not None:- sanitized.pop(FEISHU_ACCESS_TOKEN_ARG, None)await self._handle_watch_task_creation(path=path,to_uri=watch_to,@@ -342,9 +348,7 @@ class ResourceService:try:parse_mode = normalize_parse_mode(raw_parse_mode)except InvalidArgumentError as exc:- raise InvalidArgumentError(- str(exc).replace("parse_mode", "args.parse_mode")- ) from exc+ raise InvalidArgumentError(str(exc).replace("parse_mode", "args.parse_mode")) from exctoken = normalized.get(FEISHU_ACCESS_TOKEN_ARG)refresh_token = normalized.pop(FEISHU_REFRESH_TOKEN_ARG, None)watch_auth_state = None@@ -612,6 +616,12 @@ class ResourceService:else normalized_args.parse_mode)kwargs.update(normalized_args.processor_kwargs)+ if "auth_config" in kwargs:+ raise InvalidArgumentError(+ "args.auth_config cannot be used with enqueue_git_add_resource because "+ "native Git credentials must be consumed before durable queue submission. "+ "Call add_resource instead."+ )from openviking.connector.routing import credential_arg_namescredential_args = credential_arg_names("git", kwargs)@@ -946,9 +956,9 @@ class ResourceService:- watch_interval < 0: Same as watch_interval = 0, cancels any existing watch task.Default is 0 (no monitoring).- Note: If the target URI already has an active watch task, a ConflictError will be- raised. You must first cancel the existing watch (set watch_interval <= 0) before- creating a new one.+ Note: Re-adding the same source to the same target updates its active watch+ task in place. A different source targeting an active watch raises+ ConflictError; cancel that watch first with watch_interval <= 0.enforce_public_remote_targets: When True, reject non-public remote hosts andvalidate each outbound HTTP request URL during fetch.args: Parser/accessor-specific options forwarded to the processing chain.@@ -958,7 +968,7 @@ class ResourceService:Processing result containing 'root_uri' and other metadataRaises:- ConflictError: If the target URI already has an active watch task+ ConflictError: If a different source targets an active watch taskInvalidArgumentError: If the URI scope is not 'resources'"""self._ensure_initialized()@@ -971,6 +981,7 @@ class ResourceService:else normalized_args.parse_mode)kwargs.update(normalized_args.processor_kwargs)+ git_repo_source = is_git_repo_url(path)if watch_interval > 0 and kwargs.get("temp_file_id"):# Fail fast, before any ingestion: an uploaded source is a one-time# snapshot, so a watch on it can never observe the live source (see the@@ -1023,28 +1034,73 @@ class ResourceService:**kwargs,)- if is_git_repo_url(path):- result = await self.enqueue_git_add_resource(- path=path,- ctx=ctx,- to=to,- to_is_directory=to_is_directory,- parent=parent,- reason=reason,- instruction=instruction,- timeout=timeout,- build_index=build_index,- summarize=summarize,- processing_mode=processing_mode,- parse_mode=mode,- watch_interval=watch_interval,- manage_watch=manage_watch,- tags=tags,- tag_mode=tag_mode,- allow_local_path_resolution=allow_local_path_resolution,- enforce_public_remote_targets=enforce_public_remote_targets,- **kwargs,- )+ if git_repo_source:+ if "auth_config" in kwargs:+ git_auth = parse_git_http_auth_config(+ kwargs["auth_config"],+ path,+ )+ if git_auth is None:+ raise InvalidArgumentError("args.auth_config must be an object.")++ watch_auth_state = normalized_args.watch_auth_state+ if watch_interval > 0:+ watch_auth_state = create_git_http_auth_state(git_auth, path)++ # The native Git queue is durable, so credentials must be consumed+ # before crossing that boundary. Fetch and parse in this request;+ # _execute_resource_ingestion only queues the credential-free+ # prepared post-processing payload when defer_post_processing=True.+ request_local_kwargs = dict(kwargs)+ request_local_kwargs["auth_config"] = {+ "username": git_auth.username,+ "token": git_auth.token,+ }+ result = await self._execute_resource_ingestion(+ path=path,+ ctx=ctx,+ to=to,+ to_is_directory=to_is_directory,+ parent=parent,+ reason=reason,+ instruction=instruction,+ defer_post_processing=True,+ timeout=timeout,+ build_index=build_index,+ summarize=summarize,+ processing_mode=processing_mode,+ parse_mode=mode,+ watch_interval=watch_interval,+ manage_watch=manage_watch,+ tags=tags,+ tag_mode=tag_mode,+ allow_local_path_resolution=allow_local_path_resolution,+ enforce_public_remote_targets=enforce_public_remote_targets,+ watch_auth_state=watch_auth_state,+ **request_local_kwargs,+ )+ else:+ result = await self.enqueue_git_add_resource(+ path=path,+ ctx=ctx,+ to=to,+ to_is_directory=to_is_directory,+ parent=parent,+ reason=reason,+ instruction=instruction,+ timeout=timeout,+ build_index=build_index,+ summarize=summarize,+ processing_mode=processing_mode,+ parse_mode=mode,+ watch_interval=watch_interval,+ manage_watch=manage_watch,+ tags=tags,+ tag_mode=tag_mode,+ allow_local_path_resolution=allow_local_path_resolution,+ enforce_public_remote_targets=enforce_public_remote_targets,+ **kwargs,+ )else:result = await self._execute_resource_ingestion(path=path,@@ -1596,7 +1652,7 @@ class ResourceService:ctx: Request context with user identityRaises:- ConflictError: If target URI is already used by another active task+ ConflictError: If target URI is actively watched from a different source"""watch_manager = self._get_watch_manager()if not watch_manager:@@ -1609,12 +1665,13 @@ class ResourceService:role=str(ctx.role),)if existing_task:- if existing_task.is_active:+ if existing_task.is_active and existing_task.path != path:raise ConflictError(f"Target URI '{to_uri}' is already being monitored by task {existing_task.task_id}. "f"Please cancel the existing task first.",resource=to_uri,)+ was_active = existing_task.is_activeawait watch_manager.update_task(task_id=existing_task.task_id,account_id=ctx.account_id,@@ -1635,7 +1692,8 @@ class ResourceService:is_active=True,)logger.info(- f"[ResourceService] Reactivated and updated watch task {existing_task.task_id} for {to_uri}"+ f"[ResourceService] {'Updated active' if was_active else 'Reactivated and updated'} "+ f"watch task {existing_task.task_id} for {to_uri}")else:task = await watch_manager.create_task(diff --git a/openviking/utils/git_auth.py b/openviking/utils/git_auth.pynew file mode 100644index 000000000..c3d47074c--- /dev/null+++ b/openviking/utils/git_auth.py@@ -0,0 +1,109 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0+"""Request-local HTTP authentication for Git subprocesses."""++from __future__ import annotations++import base64+import os+from dataclasses import dataclass, field+from typing import Mapping++from openviking_cli.exceptions import InvalidArgumentError+++@dataclass(frozen=True)+class GitHttpAuthConfig:+ """Validated request-local HTTP Basic credentials for one Git operation."""++ username: str+ token: str = field(repr=False)+++def _validate_git_https_auth_url(repo_url: str) -> str:+ normalized = repo_url.strip() if isinstance(repo_url, str) else ""+ if not normalized.lower().startswith("https://"):+ raise InvalidArgumentError(+ "args.auth_config token authentication requires an HTTPS Git URL."+ )+ return normalized+++def parse_git_http_auth_config(+ value: object,+ repo_url: str,+) -> GitHttpAuthConfig | None:+ """Validate an ``args.auth_config`` value for an HTTP(S) Git source."""++ if value is None:+ return None+ if not isinstance(value, dict):+ raise InvalidArgumentError("args.auth_config must be an object.")++ if set(value) - {"username", "token"}:+ raise InvalidArgumentError("args.auth_config contains unsupported fields.")++ token = value.get("token")+ if not isinstance(token, str) or not token.strip():+ raise InvalidArgumentError("args.auth_config.token must be a non-empty string.")++ username = value.get("username", "oauth2")+ if not isinstance(username, str) or not username.strip():+ raise InvalidArgumentError("args.auth_config.username must be a non-empty string.")++ _validate_git_https_auth_url(repo_url)++ return GitHttpAuthConfig(username=username.strip(), token=token)+++def git_http_basic_auth_header(config: GitHttpAuthConfig) -> str:+ """Return the Git ``http.extraHeader`` value for validated credentials."""++ credential = f"{config.username}:{config.token}".encode()+ encoded = base64.b64encode(credential).decode("ascii")+ return f"Authorization: Basic {encoded}"+++def _append_git_process_config(env: dict[str, str], key: str, value: str) -> None:+ """Append a process-local Git config entry without putting it in argv."""++ try:+ count = int(env.get("GIT_CONFIG_COUNT", "0"))+ except ValueError:+ count = 0+ env[f"GIT_CONFIG_KEY_{count}"] = key+ env[f"GIT_CONFIG_VALUE_{count}"] = value+ env["GIT_CONFIG_COUNT"] = str(count + 1)+++def build_git_http_auth_env(+ config: GitHttpAuthConfig,+ repo_url: str,+ base_env: Mapping[str, str] | None = None,+) -> dict[str, str]:+ """Build an isolated child-process environment containing Git HTTP auth."""++ normalized_repo_url = _validate_git_https_auth_url(repo_url)+ env = dict(os.environ if base_env is None else base_env)+ env["GIT_TERMINAL_PROMPT"] = "0"+ env["GCM_INTERACTIVE"] = "Never"+ _append_git_process_config(env, "credential.helper", "")+ _append_git_process_config(env, f"credential.{normalized_repo_url}.helper", "")+ # Clear inherited extraHeader values before adding the one request-local+ # Authorization value. Git treats extraHeader as multi-valued otherwise.+ _append_git_process_config(env, "http.extraHeader", "")+ scoped_extra_header = f"http.{normalized_repo_url}.extraHeader"+ _append_git_process_config(env, scoped_extra_header, "")+ _append_git_process_config(+ env,+ scoped_extra_header,+ git_http_basic_auth_header(config),+ )+ # Refuse redirects at the same URL-specific precedence as the header, so+ # inherited per-repository config cannot move it to another host or HTTP.+ _append_git_process_config(+ env,+ f"http.{normalized_repo_url}.followRedirects",+ "false",+ )+ return envdiff --git a/openviking/utils/media_processor.py b/openviking/utils/media_processor.pyindex 15a04fcde..e121005b4 100644--- a/openviking/utils/media_processor.py+++ b/openviking/utils/media_processor.py@@ -256,6 +256,9 @@ class UnifiedResourceProcessor:try:# Phase 2: Parser - parse the local resourceparse_kwargs = dict(kwargs)+ # Source credentials are consumed by the accessor. Never forward+ # them into parser kwargs, parse results, or later queue payloads.+ parse_kwargs.pop("auth_config", None)parse_kwargs["instruction"] = instructionparse_kwargs["_source_meta"] = local_resource.metaparse_kwargs["resolved_extension"] = kwargs.get(diff --git a/tests/resource/test_git_watch_auth.py b/tests/resource/test_git_watch_auth.pynew file mode 100644index 000000000..f584155be--- /dev/null+++ b/tests/resource/test_git_watch_auth.py@@ -0,0 +1,59 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0++import pytest++from openviking.resource.git_watch_auth import (+ create_git_http_auth_state,+ git_http_auth_config_from_state,+ is_git_http_auth_state,+)+from openviking.resource.watch_manager import WatchTask+from openviking.utils.git_auth import GitHttpAuthConfig+from openviking_cli.exceptions import InvalidArgumentError+++def test_git_watch_auth_state_round_trip_is_repository_bound():+ repo_url = "https://git.example/org/private.git"+ state = create_git_http_auth_state(+ GitHttpAuthConfig(username="git-user", token="git-secret"),+ repo_url,+ )++ assert is_git_http_auth_state(state)+ assert git_http_auth_config_from_state(state, repo_url) == {+ "username": "git-user",+ "token": "git-secret",+ }+++def test_git_watch_auth_state_rejects_a_different_repository_without_leaking_token():+ state = create_git_http_auth_state(+ GitHttpAuthConfig(username="git-user", token="git-secret"),+ "https://git.example/org/private.git",+ )++ with pytest.raises(InvalidArgumentError) as exc_info:+ git_http_auth_config_from_state(+ state,+ "https://attacker.example/org/private.git",+ )++ assert "git-secret" not in str(exc_info.value)+++def test_git_watch_auth_state_is_persisted_but_hidden_from_public_task_dict():+ repo_url = "https://git.example/org/private.git"+ state = create_git_http_auth_state(+ GitHttpAuthConfig(username="git-user", token="git-secret"),+ repo_url,+ )+ task = WatchTask(path=repo_url, auth_state=state)++ stored = task.to_storage_dict()+ restored = WatchTask.from_dict(stored)++ assert stored["auth_state"] == state+ assert restored.auth_state == state+ assert "auth_state" not in task.to_dict()+ assert "git-secret" not in str(task.to_dict())diff --git a/tests/server/test_openviking_assets.py b/tests/server/test_openviking_assets.pyindex cddade18a..f62ae17d8 100644--- a/tests/server/test_openviking_assets.py+++ b/tests/server/test_openviking_assets.py@@ -2,11 +2,15 @@# SPDX-License-Identifier: AGPL-3.0"""Tests for server-side OpenViking Assets configuration resolution."""+import asyncioimport hashlib+from unittest.mock import AsyncMock, Mockimport httpximport pytest+import pytest_asyncio+from openviking.server.identity import RequestContext, Rolefrom openviking.server.openviking_assets import (normalize_repo_url,preflight_git_repository,@@ -17,6 +21,9 @@ from openviking_cli.exceptions import (NotFoundError,PermissionDeniedError,)+from openviking_cli.session.user_id import UserIdentifier++FULL_COMMIT_SHA = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"CATALOG = """\protocol: openviking-assets/1@@ -29,6 +36,7 @@ catalog:- name: alphaconnector: gitdescription: alpha repo+ to: viking://resources/repos/alphaparams:repo_url: https://github.com/org/alphabranch: main@@ -57,6 +65,7 @@ catalog:- name: alphaconnector: gitdescription: alpha repo+ to: viking://resources/repos/alphaparams:repo_url: https://github.com/org/alphabranch: main@@ -80,6 +89,25 @@ def _request(**overrides):return body+@pytest_asyncio.fixture+async def assets_client():+ """Client for resolver endpoints, which do not require a storage service."""+ from types import SimpleNamespace++ from openviking.server.app import create_app+ from openviking.server.auth import get_request_context+ from openviking.server.config import ServerConfig++ app = create_app(config=ServerConfig(), service=SimpleNamespace(sessions=None))+ app.dependency_overrides[get_request_context] = lambda: RequestContext(+ user=UserIdentifier(account_id="acct", user_id="alice"),+ role=Role.USER,+ )+ transport = httpx.ASGITransport(app=app)+ async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:+ yield client++def test_resolver_normalizes_and_resolves_defaults():result = resolve_openviking_assets(manifest_yaml=MANIFEST,@@ -89,6 +117,8 @@ def test_resolver_normalizes_and_resolves_defaults():)assert [asset.name for asset in result.assets] == ["alpha", "beta"]+ assert result.assets[0].to == "viking://resources/repos/alpha"+ assert result.assets[1].to is Noneassert result.assets[0].watch_interval == 30assert result.assets[1].watch_interval == 0assert result.assets[1].locator == "github.com/org/beta"@@ -109,6 +139,53 @@ def test_resolver_accepts_single_file_manifest():assert result.assets[1].watch_interval == 0+def test_resolver_accepts_and_normalizes_full_commit_sha():+ manifest = f"""\+protocol: openviking-assets/1+catalog:+ - name: pinned+ connector: git+ params:+ repo_url: https://github.com/org/pinned+ commit: {FULL_COMMIT_SHA.upper()}+"""++ result = resolve_openviking_assets(manifest_yaml=manifest)++ asset = result.assets[0]+ assert asset.branch is None+ assert asset.commit == FULL_COMMIT_SHA+ assert asset.git_ref == FULL_COMMIT_SHA+ identity = f"git\ngithub.com/org/pinned\n{FULL_COMMIT_SHA}".encode()+ assert asset.asset_id == hashlib.sha1(identity).hexdigest()[:12]+++ ("params", "message"),+ [+ (+ f"branch: main\n commit: {FULL_COMMIT_SHA}",+ "branch and params.commit are mutually exclusive",+ ),+ ("commit: deadbee", "full 40-character hexadecimal SHA"),+ ("commit: ' '", "commit must be a non-empty string"),+ ],+)+def test_resolver_rejects_invalid_commit_selection(params: str, message: str):+ manifest = f"""\+protocol: openviking-assets/1+catalog:+ - name: pinned+ connector: git+ params:+ repo_url: https://github.com/org/pinned+ {params}+"""++ with pytest.raises(InvalidArgumentError, match=message):+ resolve_openviking_assets(manifest_yaml=manifest)++def test_single_file_manifest_selects_subset():result = resolve_openviking_assets(manifest_yaml=SINGLE_FILE_MANIFEST + "\nassets:\n - beta\n",@@ -117,6 +194,49 @@ def test_single_file_manifest_selects_subset():assert [asset.name for asset in result.assets] == ["beta"]+ ("to", "message"),+ [+ ("' '", "must be a non-empty string"),+ ("viking://user/skills/repo", "must target resource content"),+ ("https://example.com/repo", "unsupported URI scheme"),+ ],+)+def test_resolver_rejects_invalid_asset_target(to: str, message: str):+ manifest = f"""\+protocol: openviking-assets/1+catalog:+ - name: targeted+ connector: git+ to: {to}+ params:+ repo_url: https://github.com/org/targeted+"""++ with pytest.raises(InvalidArgumentError, match=message):+ resolve_openviking_assets(manifest_yaml=manifest)+++def test_resolver_rejects_duplicate_selected_targets():+ manifest = """\+protocol: openviking-assets/1+catalog:+ - name: alpha+ connector: git+ to: viking://resources/repos/shared+ params:+ repo_url: https://github.com/org/alpha+ - name: beta+ connector: git+ to: viking://resources/repos/shared/+ params:+ repo_url: https://github.com/org/beta+"""++ with pytest.raises(InvalidArgumentError, match="same target URI"):+ resolve_openviking_assets(manifest_yaml=manifest)++@pytest.mark.parametrize(("url", "expected"),[@@ -210,6 +330,100 @@ async def test_git_preflight_uses_process_local_auth_without_secret_in_argv(monkassert captured["env"]["GIT_TERMINAL_PROMPT"] == "0"[email protected]("repo_url", ["http://github.com/org/private.git"])+async def test_git_preflight_rejects_unsafe_token_urls_before_spawn(monkeypatch, repo_url):+ exec_mock = AsyncMock()+ monkeypatch.setattr("asyncio.create_subprocess_exec", exec_mock)++ with pytest.raises(InvalidArgumentError):+ await preflight_git_repository(+ asset_name="private",+ repo_url=repo_url,+ token="secret-token",+ )++ exec_mock.assert_not_awaited()+++async def test_git_preflight_cancellation_kills_and_reaps_authenticated_process(monkeypatch):+ process = Mock()+ process.communicate = AsyncMock(side_effect=asyncio.CancelledError)+ process.kill = Mock()+ process.wait = AsyncMock()++ async def fake_exec(*_args, **_kwargs):+ return process++ monkeypatch.setattr("asyncio.create_subprocess_exec", fake_exec)++ with pytest.raises(asyncio.CancelledError):+ await preflight_git_repository(+ asset_name="private",+ repo_url="https://github.com/org/private.git",+ token="secret-token",+ )++ process.kill.assert_called_once_with()+ process.wait.assert_awaited_once_with()+++async def test_git_preflight_preserves_ssh_username(monkeypatch):+ captured = {}++ async def fake_exec(*args, **_kwargs):+ captured["args"] = args+ return _GitProcess(0)++ monkeypatch.setattr("asyncio.create_subprocess_exec", fake_exec)+ repo_url = "ssh://[email protected]/org/private.git"++ result = await preflight_git_repository(asset_name="private", repo_url=repo_url)++ assert result["accessible"] is True+ assert repo_url in captured["args"]+++async def test_git_preflight_accepts_commit_and_checks_repository_head(monkeypatch):+ captured = {}++ async def fake_exec(*args, **_kwargs):+ captured["args"] = args+ return _GitProcess(0)++ monkeypatch.setattr("asyncio.create_subprocess_exec", fake_exec)+ result = await preflight_git_repository(+ asset_name="pinned",+ repo_url="https://github.com/org/pinned",+ commit=FULL_COMMIT_SHA.upper(),+ )++ assert captured["args"] == (+ "git",+ "ls-remote",+ "--exit-code",+ "https://github.com/org/pinned",+ "HEAD",+ )+ assert result["git_ref"] == FULL_COMMIT_SHA+++async def test_git_preflight_rejects_invalid_commit_selection():+ with pytest.raises(InvalidArgumentError, match="mutually exclusive"):+ await preflight_git_repository(+ asset_name="pinned",+ repo_url="https://github.com/org/pinned",+ branch="main",+ commit=FULL_COMMIT_SHA,+ )++ with pytest.raises(InvalidArgumentError, match="full 40-character hexadecimal SHA"):+ await preflight_git_repository(+ asset_name="pinned",+ repo_url="https://github.com/org/pinned",+ commit="deadbee",+ )++async def test_git_preflight_maps_private_repository_failure_to_permission_denied(monkeypatch):async def fake_exec(*_args, **_kwargs):return _GitProcess(128, b"remote: Repository not found.")@@ -243,8 +457,8 @@ async def test_git_preflight_rejects_server_local_paths():)-async def test_resolve_endpoint_returns_standard_envelope(client: httpx.AsyncClient):- response = await client.post("/api/v1/openviking-assets/resolve", json=_request())+async def test_resolve_endpoint_returns_standard_envelope(assets_client: httpx.AsyncClient):+ response = await assets_client.post("/api/v1/openviking-assets/resolve", json=_request())assert response.status_code == 200body = response.json()@@ -253,8 +467,8 @@ async def test_resolve_endpoint_returns_standard_envelope(client: httpx.AsyncCliassert body["result"]["manifest"] == "manifests/code-qa.yaml"-async def test_resolve_endpoint_accepts_single_file_manifest(client: httpx.AsyncClient):- response = await client.post(+async def test_resolve_endpoint_accepts_single_file_manifest(assets_client: httpx.AsyncClient):+ response = await assets_client.post("/api/v1/openviking-assets/resolve",json={"manifest_yaml": SINGLE_FILE_MANIFEST, "manifest_label": "single-file.yaml"},)@@ -266,8 +480,32 @@ async def test_resolve_endpoint_accepts_single_file_manifest(client: httpx.Asyncassert body["result"]["catalog"] == "single-file.yaml"-async def test_resolve_endpoint_maps_configuration_errors(client: httpx.AsyncClient):- response = await client.post(+async def test_resolve_endpoint_canonicalizes_current_user_target(+ assets_client: httpx.AsyncClient,+):+ manifest = """\+protocol: openviking-assets/1+catalog:+ - name: private+ connector: git+ to: viking://user/resources/repos/private+ params:+ repo_url: https://github.com/org/private+"""++ response = await assets_client.post(+ "/api/v1/openviking-assets/resolve",+ json={"manifest_yaml": manifest},+ )++ assert response.status_code == 200+ assert response.json()["result"]["assets"][0]["to"] == (+ "viking://user/alice/resources/repos/private"+ )+++async def test_resolve_endpoint_maps_configuration_errors(assets_client: httpx.AsyncClient):+ response = await assets_client.post("/api/v1/openviking-assets/resolve",json=_request(manifest_yaml="include:\n - base.yaml\nassets:\n - alpha\n"),)@@ -280,7 +518,7 @@ async def test_resolve_endpoint_maps_configuration_errors(client: httpx.AsyncCliasync def test_preflight_endpoint_maps_source_permission_errors(- client: httpx.AsyncClient, monkeypatch+ assets_client: httpx.AsyncClient, monkeypatch):async def deny(**_kwargs):raise PermissionDeniedError("repository access denied")@@ -289,7 +527,7 @@ async def test_preflight_endpoint_maps_source_permission_errors("openviking.server.routers.openviking_assets.preflight_git_repository",deny,)- response = await client.post(+ response = await assets_client.post("/api/v1/openviking-assets/preflight",json={"name": "private",@@ -302,3 +540,29 @@ async def test_preflight_endpoint_maps_source_permission_errors(body = response.json()assert body["status"] == "error"assert body["error"]["code"] == "PERMISSION_DENIED"+++async def test_preflight_endpoint_forwards_commit(assets_client: httpx.AsyncClient, monkeypatch):+ captured = {}++ async def allow(**kwargs):+ captured.update(kwargs)+ return {"accessible": True, "git_ref": kwargs["commit"]}++ monkeypatch.setattr(+ "openviking.server.routers.openviking_assets.preflight_git_repository",+ allow,+ )+ response = await assets_client.post(+ "/api/v1/openviking-assets/preflight",+ json={+ "name": "pinned",+ "connector": "git",+ "repo_url": "https://github.com/org/pinned",+ "commit": FULL_COMMIT_SHA,+ },+ )++ assert response.status_code == 200+ assert captured["branch"] is None+ assert captured["commit"] == FULL_COMMIT_SHAdiff --git a/tests/service/test_resource_service_connector.py b/tests/service/test_resource_service_connector.pyindex cb930deb3..a8409e110 100644--- a/tests/service/test_resource_service_connector.py+++ b/tests/service/test_resource_service_connector.py@@ -3,6 +3,7 @@"""Core routing and task-state tests for Connector imports."""import asyncio+import jsonfrom types import SimpleNamespacefrom unittest.mock import AsyncMock, Mock@@ -759,6 +760,202 @@ async def test_native_git_enqueue_rejects_credentials_before_durable_job(service._enqueue_add_resource_job.assert_not_awaited()+async def test_native_git_nested_auth_runs_request_local_before_durable_queue(+ monkeypatch,+ connector_config,+ ctx,+ service,+):+ monkeypatch.setattr(resource_service_module, "is_git_repo_url", lambda _path: True)+ service._execute_resource_ingestion = AsyncMock(+ return_value={+ "status": "success",+ "root_uri": "viking://resources/private",+ "task_id": "task-private",+ }+ )+ service.enqueue_git_add_resource = AsyncMock()++ result = await service.add_resource(+ path="https://git.example/org/private.git",+ ctx=ctx,+ to="viking://resources/private",+ args={+ "branch": "main",+ "auth_config": {"username": "oauth2", "token": "secret-token"},+ },+ )++ assert result["task_id"] == "task-private"+ service.enqueue_git_add_resource.assert_not_awaited()+ call = service._execute_resource_ingestion.await_args.kwargs+ assert call["defer_post_processing"] is True+ assert call["branch"] == "main"+ assert call["auth_config"] == {"username": "oauth2", "token": "secret-token"}+++async def test_native_git_nested_auth_watch_uses_private_auth_state(+ monkeypatch,+ connector_config,+ ctx,+ service,+):+ monkeypatch.setattr(resource_service_module, "is_git_repo_url", lambda _path: True)+ service._execute_resource_ingestion = AsyncMock(+ return_value={+ "status": "success",+ "root_uri": "viking://resources/private",+ "task_id": "task-private",+ }+ )+ service.enqueue_git_add_resource = AsyncMock()++ result = await service.add_resource(+ path="https://git.example/org/private.git",+ ctx=ctx,+ to="viking://resources/private",+ watch_interval=5,+ args={"auth_config": {"token": "secret-token"}},+ )++ assert result["task_id"] == "task-private"+ call = service._execute_resource_ingestion.await_args.kwargs+ assert call["auth_config"] == {"username": "oauth2", "token": "secret-token"}+ assert call["watch_auth_state"] == {+ "provider": "git_http_basic",+ "username": "oauth2",+ "token": "secret-token",+ "repo_url": "https://git.example/org/private.git",+ }+ service.enqueue_git_add_resource.assert_not_awaited()+++async def test_native_git_watch_refresh_consumes_restored_auth_before_queue(+ monkeypatch,+ connector_config,+ ctx,+ service,+):+ monkeypatch.setattr(resource_service_module, "is_git_repo_url", lambda _path: True)+ service._execute_resource_ingestion = AsyncMock(+ return_value={+ "status": "success",+ "root_uri": "viking://resources/private",+ "task_id": "task-refresh",+ }+ )+ service.enqueue_git_add_resource = AsyncMock()++ result = await service.refresh_resource(+ path="https://git.example/org/private.git",+ ctx=ctx,+ to="viking://resources/private",+ watch_interval=5,+ auth_config={"username": "oauth2", "token": "secret-token"},+ )++ assert result["task_id"] == "task-refresh"+ call = service._execute_resource_ingestion.await_args.kwargs+ assert call["manage_watch"] is False+ assert call["auth_config"] == {"username": "oauth2", "token": "secret-token"}+ service.enqueue_git_add_resource.assert_not_awaited()+++async def test_native_git_enqueue_rejects_nested_auth_without_secret_in_error(ctx, service):+ service._enqueue_add_resource_job = AsyncMock()++ with pytest.raises(InvalidArgumentError, match="auth_config") as exc_info:+ await service.enqueue_git_add_resource(+ path="https://git.example/org/private.git",+ ctx=ctx,+ to="viking://resources/private",+ args={"auth_config": {"username": "oauth2", "token": "secret-token"}},+ )++ assert "secret-token" not in str(exc_info.value)+ service._enqueue_add_resource_job.assert_not_awaited()+++async def test_git_url_embedded_credentials_are_passed_to_native_queue_unchanged(+ monkeypatch,+ connector_config,+ ctx,+ service,+):+ monkeypatch.setattr(resource_service_module, "is_git_repo_url", lambda _path: True)+ service.enqueue_git_add_resource = AsyncMock(+ return_value={+ "status": "success",+ "root_uri": "viking://resources/private",+ "task_id": "task-private",+ }+ )+ source = "https://user:[email protected]/org/private.git"+ result = await service.add_resource(+ path=source,+ ctx=ctx,+ to="viking://resources/private",+ )++ assert result["task_id"] == "task-private"+ assert service.enqueue_git_add_resource.await_args.kwargs["path"] == source+++def test_prepared_add_resource_payload_drops_nested_git_auth():+ msg = AddResourceMsg(+ task_id="task-private",+ path="https://git.example/org/private.git",+ root_uri="viking://resources/private",+ account_id="acct",+ user_id="alice",+ role="user",+ prepared={"root_uri": "viking://resources/private"},+ args={"auth_config": {"username": "oauth2", "token": "secret-token"}},+ )++ payload = msg.to_dict()++ assert payload["args"] == {}+ assert "secret-token" not in json.dumps(payload)+++async def test_request_local_git_auth_is_absent_from_real_prepared_queue_message(ctx, service):+ service._resource_processor = SimpleNamespace(+ process_resource=AsyncMock(+ return_value={+ "status": "success",+ "root_uri": "viking://resources/private",+ "source_path": "https://git.example/org/private.git",+ "_post_process": {"root_is_file": False},+ "_resource_lock": None,+ }+ )+ )+ service._enqueue_add_resource_job = AsyncMock(+ return_value=SimpleNamespace(task_id="task-private")+ )++ result = await service._execute_resource_ingestion(+ path="https://git.example/org/private.git",+ ctx=ctx,+ to="viking://resources/private",+ defer_post_processing=True,+ auth_config={"username": "oauth2", "token": "secret-token"},+ )++ assert result["task_id"] == "task-private"+ queued_msg = service._enqueue_add_resource_job.await_args.args[0]+ payload = queued_msg.to_dict()+ assert payload["args"] == {}+ assert "secret-token" not in json.dumps(payload)++@pytest.mark.parametrize("to", ["viking://resources/manuals", "resources/manuals"])def test_connector_route_accepts_public_exact_to(connector_config, ctx, service, to):connector_config.allowed_add_types = ["tos", "git"]diff --git a/tests/service/test_resource_service_watch.py b/tests/service/test_resource_service_watch.pyindex fbbf0852a..aa5955cf1 100644--- a/tests/service/test_resource_service_watch.py+++ b/tests/service/test_resource_service_watch.py@@ -127,9 +127,7 @@ async def resource_service(watch_manager: WatchManager) -> AsyncGenerator[Resourskill_processor=MockSkillProcessor(),watch_scheduler=scheduler,)- service._enqueue_add_resource_job = AsyncMock(- return_value=SimpleNamespace(task_id="test-task")- )+ service._enqueue_add_resource_job = AsyncMock(return_value=SimpleNamespace(task_id="test-task"))yield service@@ -253,7 +251,9 @@ class TestWatchTaskCreation:return {}monkeypatch.setattr(ContentWriteCoordinator, "set_tags", fake_set_tags)- monkeypatch.setattr(resource_service_module, "get_queue_manager", lambda: FakeQueueManager())+ monkeypatch.setattr(+ resource_service_module, "get_queue_manager", lambda: FakeQueueManager()+ )result = await resource_service.add_resource(path="/test/path",@@ -303,7 +303,9 @@ class TestWatchTaskCreation:return {}monkeypatch.setattr(ContentWriteCoordinator, "set_tags", fake_set_tags)- monkeypatch.setattr(resource_service_module, "get_queue_manager", lambda: FakeQueueManager())+ monkeypatch.setattr(+ resource_service_module, "get_queue_manager", lambda: FakeQueueManager()+ )await resource_service.add_resource(path="/test/path",@@ -480,6 +482,51 @@ class TestAddResourceArgs:}assert "auth_state" not in task.to_dict()+ @pytest.mark.asyncio+ async def test_git_token_watch_stores_private_auth_state(+ self,+ monkeypatch: pytest.MonkeyPatch,+ resource_service: ResourceService,+ request_context: RequestContext,+ ):+ monkeypatch.setattr(resource_service_module, "is_git_repo_url", lambda _path: True)+ disable_task_tracker(monkeypatch)+ repo_url = "https://git.example/org/private.git"+ to_uri = "viking://resources/git_private_watch"++ await resource_service.add_resource(+ path=repo_url,+ ctx=request_context,+ to=to_uri,+ watch_interval=30,+ args={+ "branch": "main",+ "auth_config": {+ "username": "git-user",+ "token": "git-secret",+ },+ },+ )++ processor = resource_service._resource_processor+ assert processor.calls[-1]["auth_config"] == {+ "username": "git-user",+ "token": "git-secret",+ }++ task = await get_task_by_uri(resource_service, to_uri, request_context)+ assert task is not None+ assert task.processor_kwargs == {"branch": "main"}+ assert task.auth_state == {+ "provider": "git_http_basic",+ "username": "git-user",+ "token": "git-secret",+ "repo_url": repo_url,+ }+ public_task = task.to_dict()+ assert "auth_state" not in public_task+ assert "git-secret" not in str(public_task)+class TestWatchTaskConflict:"""Tests for watch task conflict detection."""@@ -488,7 +535,7 @@ class TestWatchTaskConflict:async def test_conflict_when_active_task_exists(self, resource_service: ResourceService, request_context: RequestContext):- """Test that ConflictError is raised when an active task already exists."""+ """A different source cannot replace an active watch."""to_uri = "viking://resources/conflict_test"await resource_service.add_resource(@@ -509,6 +556,43 @@ class TestWatchTaskConflict:assert "already being monitored" in str(exc_info.value)assert to_uri in str(exc_info.value)+ @pytest.mark.asyncio+ async def test_same_source_updates_active_task(+ self, resource_service: ResourceService, request_context: RequestContext+ ):+ """Re-applying one source updates its active watch instead of conflicting."""+ to_uri = "viking://resources/idempotent_watch"+ source = "/test/same-path"++ await resource_service.add_resource(+ path=source,+ ctx=request_context,+ to=to_uri,+ reason="Original reason",+ watch_interval=30.0,+ args={"branch": "main"},+ )+ original = await get_task_by_uri(resource_service, to_uri, request_context)+ assert original is not None++ await resource_service.add_resource(+ path=source,+ ctx=request_context,+ to=to_uri,+ reason="Updated reason",+ watch_interval=45.0,+ args={"branch": "release"},+ )++ updated = await get_task_by_uri(resource_service, to_uri, request_context)+ assert updated is not None+ assert updated.task_id == original.task_id+ assert updated.path == source+ assert updated.reason == "Updated reason"+ assert updated.watch_interval == 45.0+ assert updated.processor_kwargs == {"branch": "release"}+ assert updated.is_active is True+@pytest.mark.asyncioasync def test_conflict_does_not_create_async_task(self, resource_service: ResourceService, request_context: RequestContextdiff --git a/tests/service/test_watch_recovery.py b/tests/service/test_watch_recovery.pyindex 083d7fcef..354370eae 100644--- a/tests/service/test_watch_recovery.py+++ b/tests/service/test_watch_recovery.py@@ -7,15 +7,18 @@ import jsonfrom datetime import datetime, timedeltafrom pathlib import Pathfrom typing import AsyncGenerator+from unittest.mock import AsyncMockimport pytestimport pytest_asynciofrom openviking.resource.feishu_watch_auth import FeishuRefreshedToken+from openviking.resource.git_watch_auth import create_git_http_auth_statefrom openviking.resource.watch_manager import WatchManagerfrom openviking.resource.watch_scheduler import WatchSchedulerfrom openviking.server.identity import RequestContext, Rolefrom openviking.service.resource_service import ResourceService+from openviking.utils.git_auth import GitHttpAuthConfigfrom openviking_cli.session.user_id import UserIdentifierfrom tests.utils.mock_agfs import MockLocalAGFS@@ -456,6 +459,45 @@ class TestResourceExistenceCheck:assert updated_task.auth_state["refresh_token"] == "r-new"assert updated_task.auth_state["expires_at"] is not None+ @pytest.mark.asyncio+ async def test_git_token_watch_restores_request_local_auth_for_execution(+ self, temp_storage: Path, request_context: RequestContext+ ):+ resource_service = ResourceService(+ vikingdb=MockVikingDB(),+ viking_fs=MockVikingFS(root_path=str(temp_storage)),+ resource_processor=MockResourceProcessor(),+ skill_processor=MockSkillProcessor(),+ watch_scheduler=None,+ )+ resource_service.refresh_resource = AsyncMock(+ return_value={"root_uri": "viking://resources/git-private-watch"}+ )+ scheduler = WatchScheduler(resource_service=resource_service, viking_fs=None)+ await scheduler.start()+ watch_manager = scheduler.watch_manager+ repo_url = "https://git.example/org/private.git"++ task = await watch_manager.create_task(+ path=repo_url,+ to_uri="viking://resources/git-private-watch",+ watch_interval=30.0,+ auth_state=create_git_http_auth_state(+ GitHttpAuthConfig(username="git-user", token="git-secret"),+ repo_url,+ ),+ )++ await scheduler._execute_task(task)++ call = resource_service.refresh_resource.await_args.kwargs+ assert call["auth_config"] == {+ "username": "git-user",+ "token": "git-secret",+ }+ assert "auth_config" not in task.processor_kwargs+ assert "git-secret" not in str(task.to_dict())+class TestSchedulerIntegration:"""Integration tests for WatchScheduler with WatchManager."""diff --git a/tests/unit/test_accessors_git.py b/tests/unit/test_accessors_git.pyindex fae625e7f..f07d9c645 100644--- a/tests/unit/test_accessors_git.py+++ b/tests/unit/test_accessors_git.py@@ -2,15 +2,24 @@# SPDX-License-Identifier: AGPL-3.0"""Unit tests for GitAccessor."""+import asyncio+import base64+import osfrom pathlib import Pathfrom types import SimpleNamespace-from unittest.mock import AsyncMock, patch+from unittest.mock import AsyncMock, Mock, patchimport pytestfrom openviking.parse.accessors import GitAccessorfrom openviking.parse.parsers.directory import DirectoryParserfrom openviking.utils import code_hosting_utils+from openviking.utils.git_auth import (+ build_git_http_auth_env,+ git_http_basic_auth_header,+ parse_git_http_auth_config,+)+from openviking_cli.exceptions import InvalidArgumentError_GENERIC_CODE_HOSTING_DOMAINS = ["github.com",@@ -25,6 +34,85 @@ _GENERIC_CODE_HOSTING_DOMAINS = []+def _git_config_entries(env: dict[str, str]) -> dict[str, str]:+ count = int(env["GIT_CONFIG_COUNT"])+ return {+ env[f"GIT_CONFIG_KEY_{index}"]: env[f"GIT_CONFIG_VALUE_{index}"]+ for index in range(count)+ }+++def test_git_http_auth_config_defaults_username_and_builds_isolated_env() -> None:+ base_env = {"EXISTING": "kept"}+ config = parse_git_http_auth_config(+ {"token": "secret-token"},+ "https://git.example.com/org/private.git",+ )++ assert config is not None+ assert config.username == "oauth2"+ assert config.token == "secret-token"+ assert "secret-token" not in repr(config)+ assert git_http_basic_auth_header(config) == (+ "Authorization: Basic "+ + base64.b64encode(b"oauth2:secret-token").decode("ascii")+ )++ repo_url = "https://git.example.com/org/private.git"+ env = build_git_http_auth_env(config, repo_url, base_env=base_env)+ assert base_env == {"EXISTING": "kept"}+ assert env["EXISTING"] == "kept"+ assert env["GIT_TERMINAL_PROMPT"] == "0"+ assert env["GCM_INTERACTIVE"] == "Never"+ assert _git_config_entries(env) == {+ "credential.helper": "",+ f"credential.{repo_url}.helper": "",+ "http.extraHeader": "",+ f"http.{repo_url}.extraHeader": git_http_basic_auth_header(config),+ f"http.{repo_url}.followRedirects": "false",+ }+ assert env["GIT_CONFIG_COUNT"] == "6"+ assert env["GIT_CONFIG_KEY_3"] == f"http.{repo_url}.extraHeader"+ assert env["GIT_CONFIG_VALUE_3"] == ""+ assert env["GIT_CONFIG_KEY_4"] == f"http.{repo_url}.extraHeader"+++ ("value", "repo_url", "message"),+ [+ ("secret-token", "https://git.example.com/org/repo.git", "object"),+ ({}, "https://git.example.com/org/repo.git", "token"),+ ({"token": " "}, "https://git.example.com/org/repo.git", "token"),+ ({"token": 123}, "https://git.example.com/org/repo.git", "token"),+ (+ {"token": "secret-token", "username": " "},+ "https://git.example.com/org/repo.git",+ "username",+ ),+ (+ {"token": "secret-token", "password": "wrong-field"},+ "https://git.example.com/org/repo.git",+ "unsupported",+ ),+ (+ {"token": "secret-token"},+ "[email protected]:org/repo.git",+ "HTTPS",+ ),+ (+ {"token": "secret-token"},+ "http://git.example.com/org/repo.git",+ "HTTPS",+ ),+ ],+)+def test_git_http_auth_config_rejects_invalid_values(value, repo_url: str, message: str) -> None:+ with pytest.raises(InvalidArgumentError, match=message) as exc_info:+ parse_git_http_auth_config(value, repo_url)++ assert "secret-token" not in str(exc_info.value)++def _mock_config():return SimpleNamespace(code=SimpleNamespace(@@ -351,6 +439,78 @@ class TestGitAccessor:git_clone.assert_awaited_once()assert git_clone.await_args.args[0] == source+ @pytest.mark.parametrize(+ ("source", "zip_method"),+ [+ ("https://github.com/org/private.git", "_github_zip_download"),+ ("https://gitlab.com/org/private.git", "_gitlab_zip_download"),+ ],+ )+ async def test_explicit_http_auth_skips_archive_fast_path_and_reaches_clone_env(+ self,+ accessor: GitAccessor,+ tmp_path: Path,+ source: str,+ zip_method: str,+ ) -> None:+ token = "private-token"+ with (+ patch(+ "openviking.parse.accessors.git_accessor.tempfile.mkdtemp",+ return_value=str(tmp_path),+ ),+ patch.object(accessor, zip_method, new_callable=AsyncMock) as zip_download,+ patch.object(+ accessor,+ "_git_clone",+ new_callable=AsyncMock,+ return_value="org/private",+ ) as git_clone,+ ):+ resource = await accessor.access(+ source,+ auth_config={"token": token, "username": "git-user"},+ )++ zip_download.assert_not_awaited()+ git_clone.assert_awaited_once()+ clone_call = git_clone.await_args+ assert clone_call.args[0] == source+ env = clone_call.kwargs["env"]+ assert token not in " ".join(str(arg) for arg in clone_call.args)+ assert _git_config_entries(env)[f"http.{source}.extraHeader"] == (+ "Authorization: Basic "+ + base64.b64encode(f"git-user:{token}".encode()).decode("ascii")+ )+ assert resource.original_source == source+ assert token not in str(resource.meta)++ async def test_embedded_http_credentials_are_passed_through_unchanged(+ self,+ accessor: GitAccessor,+ tmp_path: Path,+ ) -> None:+ source = "https://user:[email protected]/org/private.git"+ with (+ patch(+ "openviking.parse.accessors.git_accessor.tempfile.mkdtemp",+ return_value=str(tmp_path),+ ),+ patch.object(+ accessor,+ "_git_clone",+ new_callable=AsyncMock,+ return_value="org/private",+ ) as git_clone,+ ):+ resource = await accessor.access(source)++ git_clone.assert_awaited_once()+ call = git_clone.await_args+ assert call.args[0] == source+ assert call.kwargs["env"] is None+ assert resource.original_source == source+def test_normalize_repo_url_github_commit_page(self, accessor: GitAccessor) -> None:"""Commit-pin URLs normalize to the bare repo; the ref is extracted separately."""assert (@@ -398,6 +558,100 @@ class TestGitAccessor:assert "--no-recurse-submodules" in clone_argsassert "--recursive" not in clone_args+ async def test_git_clone_reuses_auth_env_for_clone_and_commit_fetches(+ self, accessor: GitAccessor, tmp_path: Path+ ) -> None:+ config = parse_git_http_auth_config(+ {"token": "secret-token"},+ "https://git.example.com/org/private.git",+ )+ assert config is not None+ auth_env = build_git_http_auth_env(+ config,+ "https://git.example.com/org/private.git",+ base_env={},+ )++ async def run_git(args, cwd=None, env=None):+ if "rev-parse" in args:+ return "deadbeef"+ return ""++ with patch.object(accessor, "_run_git", new=AsyncMock(side_effect=run_git)) as run_git_mock:+ await accessor._git_clone(+ "https://git.example.com/org/private.git",+ str(tmp_path),+ commit="deadbeef",+ env=auth_env,+ )++ network_calls = [+ call+ for call in run_git_mock.await_args_list+ if "clone" in call.args[0] or "fetch" in call.args[0]+ ]+ assert len(network_calls) >= 2+ assert all(call.kwargs["env"] is auth_env for call in network_calls)++ async def test_authenticated_git_failure_does_not_log_remote_stderr_or_auth(+ self, accessor: GitAccessor, caplog+ ) -> None:+ config = parse_git_http_auth_config(+ {"token": "secret-token"},+ "https://git.example.com/org/private.git",+ )+ assert config is not None+ env = build_git_http_auth_env(+ config,+ "https://git.example.com/org/private.git",+ base_env={},+ )+ encoded = base64.b64encode(b"oauth2:secret-token").decode("ascii")+ process = SimpleNamespace(+ returncode=1,+ communicate=AsyncMock(+ return_value=(+ b"",+ f"remote reflected secret-token and {encoded}".encode(),+ )+ ),+ )+ with patch(+ "openviking.parse.accessors.git_accessor.asyncio.create_subprocess_exec",+ new=AsyncMock(return_value=process),+ ):+ with pytest.raises(RuntimeError, match="Git command failed"):+ await accessor._run_git(+ ["git", "clone", "https://git.example.com/org/private.git"],+ env=env,+ )++ assert "secret-token" not in caplog.text+ assert encoded not in caplog.text+ assert "remote reflected" not in caplog.text+ assert os.environ.get("GIT_CONFIG_COUNT") != env["GIT_CONFIG_COUNT"]++ async def test_cancelled_git_process_is_killed_and_reaped(+ self,+ accessor: GitAccessor,+ ) -> None:+ process = SimpleNamespace(+ communicate=AsyncMock(side_effect=asyncio.CancelledError),+ kill=Mock(),+ wait=AsyncMock(),+ )+ with patch(+ "openviking.parse.accessors.git_accessor.asyncio.create_subprocess_exec",+ new=AsyncMock(return_value=process),+ ):+ with pytest.raises(asyncio.CancelledError):+ await accessor._run_git(+ ["git", "clone", "https://git.example.com/org/private.git"]+ )++ process.kill.assert_called_once_with()+ process.wait.assert_awaited_once_with()+@pytest.mark.parametrize(("source", "repo_name"),[