Skip to main content

agentmux_srv_core/identity/resolver/
effective_links.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The account links a definition resolves through, for callers outside the
5//! spawn gate (a new fork copies its source's from here).
6
7use crate::backend::storage::store::{AgentDefinition, AgentIdentityLink, Store};
8use crate::backend::storage::StoreError;
9
10use super::inject::template_parent_id_if_seeded;
11
12/// The account links a definition's spawn resolves through: its own direct
13/// links, or, only when it has none, its seeded template parent's. The same
14/// rule `resolve_bindings_for_instance` applies at the spawn gate, without
15/// its "no links" diagnostic. `forkagentdefinition` copies a new fork's links
16/// from this, so the fork starts on the account its source runs on.
17pub fn effective_identity_links(
18    mstore: &Store,
19    identity_store: &Store,
20    def: &AgentDefinition,
21) -> Result<Vec<AgentIdentityLink>, StoreError> {
22    let direct = identity_store.agent_identity_list_for_agent(&def.id)?;
23    if !direct.is_empty() {
24        return Ok(direct);
25    }
26    let parent = template_parent_id_if_seeded(mstore, &def.parent_id);
27    if parent.is_empty() {
28        return Ok(Vec::new());
29    }
30    identity_store.agent_identity_list_for_agent(&parent)
31}