*/ public function run(): array { $by_namespace = array(); foreach ( $this->registry->all() as $ability ) { if ( ! is_object( $ability ) || ! method_exists( $ability, 'get_name' ) ) { continue; } $name = (string) $ability->get_name(); $separator = strpos( $name, '/' ); $namespace = false === $separator ? $name : substr( $name, 0, $separator ); if ( '' === $namespace ) { continue; } $by_namespace[ $namespace ] = ( $by_namespace[ $namespace ] ?? 0 ) + 1; } ksort( $by_namespace ); $plugins = $this->active_plugin_slugs(); $findings = array(); foreach ( $by_namespace as $namespace => $count ) { $attributed = self::CORE_NAMESPACE === $namespace || in_array( $namespace, $plugins, true ); $findings[] = new Finding( $this->id(), $attributed ? Severity::REVIEW : Severity::ATTENTION, $attributed ? __( 'Abilities registered by installed software', 'agentic-daisy-ai-agent-firewall' ) : __( 'Abilities nobody on this site accounts for', 'agentic-daisy-ai-agent-firewall' ), $attributed ? sprintf( /* translators: 1: number of abilities, 2: the namespace they are registered under. */ __( '%1$d registered under "%2$s", which matches software installed on this site. Agents can call these.', 'agentic-daisy-ai-agent-firewall' ), $count, $namespace ) : sprintf( /* translators: 1: number of abilities, 2: the namespace they are registered under. */ __( '%1$d registered under "%2$s", which matches no active plugin and is not WordPress itself. Something registered them - find out what before agents are allowed to call them.', 'agentic-daisy-ai-agent-firewall' ), $count, $namespace ), (string) $namespace, 'policies' ); } return $findings; } /** * Directory slugs of the site's active plugins. * * The slug is what a namespace is compared against, since a plugin's * folder is the closest thing WordPress has to the identity a namespace * is declaring. * * @return list */ private function active_plugin_slugs(): array { $active = get_option( 'active_plugins' ); if ( ! is_array( $active ) ) { return array(); } $slugs = array(); foreach ( $active as $path ) { $directory = dirname( (string) $path ); if ( '.' !== $directory && '' !== $directory ) { $slugs[] = $directory; } } return $slugs; } }