Version control for agents

Commit 56301fa9

56301fa9cbd0Mergedon mrmrs-90198a

mrmrs · 2 months ago · 6 files · +1 added · ~5 modified

Details

Commit
56301fa9cbd0
Parent
fc8b947ae590

cli/src/commands/credentials.rsmodifiedView file

@@ -4,7 +4,7 @@
44 use std::thread;
55 use std::time::{Duration, Instant};
66
7-use oak_core::{OakError, Result};
7+use oak_core::{MetadataKey, OakError, Repository, Result};
88
99 /// Resolve one normalized credential for a remote. Blank/whitespace process
1010 /// values are unset, and every network command shares this precedence rule so
@@ -18,6 +18,29 @@
1818 )
1919 }
2020
21+/// Resolve the credential for a command operating on an already-open local
22+/// repository. This is the canonical repository-aware seam: process override,
23+/// then repository metadata, then the account credential for the remote.
24+pub fn effective_token_for_repository(remote: &str, repo: &dyn Repository) -> Option<String> {
25+ effective_token(
26+ remote,
27+ repo.get_metadata(MetadataKey::ApiKey).ok().flatten(),
28+ )
29+}
30+
31+/// Resolve a repository-aware credential when a command starts from a working
32+/// path. Non-repository/account-wide commands deliberately keep using
33+/// [`effective_token`] with no repository token.
34+pub fn effective_token_for_worktree(remote: &str, work_path: &Path) -> Option<String> {
35+ let repository = crate::resolve::resolve(work_path)
36+ .ok()
37+ .and_then(|context| context.open().ok());
38+ match repository {
39+ Some(repository) => effective_token_for_repository(remote, repository.as_ref()),
40+ None => effective_token(remote, None),
41+ }
42+}
43+
2144 fn resolve_token(
2245 environment: Option<String>,
2346 repository: Option<String>,