aKode fase 2b-1 (WIP): rimossi cloud-config, apps MCP ChatGPT, upload file, connectors-extension, rate limits backend; plugin remoti in corso (test non ancora compilanti)
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
This commit is contained in:
@@ -1,118 +1,38 @@
|
||||
mod policy;
|
||||
mod world_state;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
use codex_extension_api::ContextContributor;
|
||||
use codex_extension_api::ExtensionFuture;
|
||||
use codex_extension_api::ExtensionRegistryBuilder;
|
||||
use codex_extension_api::WorldStateContributionInput;
|
||||
use codex_extension_api::WorldStateSectionContribution;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_login::AuthManager;
|
||||
use codex_model_provider::ProviderAuthContext;
|
||||
|
||||
use crate::policy::GitAttributionPolicy;
|
||||
use crate::policy::GitAttributionRetry;
|
||||
use crate::policy::POLICY_RETRY_DELAY;
|
||||
use crate::policy::auth_generation;
|
||||
use crate::policy::cached_attribution_policy;
|
||||
use crate::policy::resolve_attribution_policy;
|
||||
use crate::policy::retry_deferred;
|
||||
use crate::world_state::git_attribution_world_state_section;
|
||||
|
||||
/// Local default for commit and pull request attribution. aKode never fetches a
|
||||
/// remote workspace policy, so attribution stays disabled.
|
||||
const ATTRIBUTION_ENABLED_BY_DEFAULT: bool = false;
|
||||
|
||||
/// Contributes model instructions for agent-created git commits and pull requests.
|
||||
#[derive(Clone)]
|
||||
struct GitAttributionExtension {
|
||||
auth_manager: Arc<AuthManager>,
|
||||
base_url: String,
|
||||
http_client_factory: HttpClientFactory,
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl ContextContributor for GitAttributionExtension {
|
||||
fn contribute_world_state<'a>(
|
||||
&'a self,
|
||||
input: WorldStateContributionInput<'a>,
|
||||
_input: WorldStateContributionInput<'a>,
|
||||
) -> ExtensionFuture<'a, Vec<WorldStateSectionContribution>> {
|
||||
Box::pin(async move {
|
||||
let auth_context = input.thread_store.get::<ProviderAuthContext>();
|
||||
let auth_manager = auth_context
|
||||
.as_ref()
|
||||
.map_or(&self.auth_manager, |context| &context.credentials);
|
||||
let runtime_auth = auth_context
|
||||
.as_ref()
|
||||
.and_then(|context| context.runtime_auth.as_ref());
|
||||
let enabled = loop {
|
||||
let current_auth_generation = auth_generation(auth_manager.as_ref());
|
||||
let policy = match cached_attribution_policy(
|
||||
input.thread_store,
|
||||
input.turn_store,
|
||||
current_auth_generation,
|
||||
) {
|
||||
Some(policy) => policy,
|
||||
None if retry_deferred(input.thread_store, current_auth_generation) => {
|
||||
GitAttributionPolicy {
|
||||
auth_generation: current_auth_generation,
|
||||
enabled: false,
|
||||
}
|
||||
}
|
||||
None => {
|
||||
match resolve_attribution_policy(
|
||||
auth_manager,
|
||||
&self.base_url,
|
||||
&self.http_client_factory,
|
||||
runtime_auth,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(Some(policy)) => {
|
||||
input.thread_store.insert(policy.clone());
|
||||
policy
|
||||
}
|
||||
Ok(None) => {
|
||||
input.turn_store.insert(GitAttributionPolicy {
|
||||
auth_generation: current_auth_generation,
|
||||
enabled: false,
|
||||
});
|
||||
break false;
|
||||
}
|
||||
Err(_) => {
|
||||
let auth_generation = auth_generation(auth_manager.as_ref());
|
||||
if auth_generation == current_auth_generation {
|
||||
input.thread_store.insert(GitAttributionRetry {
|
||||
auth_generation,
|
||||
retry_at: Instant::now() + POLICY_RETRY_DELAY,
|
||||
});
|
||||
}
|
||||
break false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if policy.auth_generation == auth_generation(auth_manager.as_ref()) {
|
||||
break policy.enabled;
|
||||
}
|
||||
};
|
||||
vec![git_attribution_world_state_section(enabled)]
|
||||
})
|
||||
let enabled = self.enabled;
|
||||
Box::pin(async move { vec![git_attribution_world_state_section(enabled)] })
|
||||
}
|
||||
}
|
||||
|
||||
/// Installs the git-attribution contributor into the extension registry.
|
||||
pub fn install<C: Sync>(
|
||||
registry: &mut ExtensionRegistryBuilder<C>,
|
||||
auth_manager: Arc<AuthManager>,
|
||||
base_url: String,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) {
|
||||
pub fn install<C: Sync>(registry: &mut ExtensionRegistryBuilder<C>) {
|
||||
registry.prompt_contributor(Arc::new(GitAttributionExtension {
|
||||
auth_manager,
|
||||
base_url,
|
||||
http_client_factory,
|
||||
enabled: ATTRIBUTION_ENABLED_BY_DEFAULT,
|
||||
}));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "git_attribution_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
Reference in New Issue
Block a user