Skip to content

[detector-report] KeyedLookupEnvyDetector #589

Description

@jessegall

Detector: KeyedLookupEnvyDetector

Report (why the flagged code is CORRECT and the detector is wrong):
OfferedModels::of is an assembler over two collaborators: it resolves the agent's AgentConfiguration from the AgentConfigurations registry (keyed by the agent's provider enum) and asks it for models using the agent's bound login credential store. The tell-dont-ask skill names two non-fixes for exactly this: moving the query onto the keyed store (AgentConfigurations::modelsFor), and adding it to the Eloquent AgentRecord, which would give the model the registry as a collaborator. Combining the registry with the agent's credentials is this class's single job.

Cleanest design the reporter can conceive:
A small readonly OfferedModels service holding the AgentConfigurations registry, whose of(AgentRecord) guards an unbound agent and then asks the provider's configuration for models with the agent's credential store. That is the flagged code.

⚖️ Maintainer litmus: a valid detector-report needs the flagged code to ALREADY BE the
cleanest design. If the design above differs from the flagged code at all, THAT design is
the owed fix — close this report; the fix is still owed.

Where: src/Orchestration/OfferedModels.php:16

Code (src/Orchestration/OfferedModels.php:16):

  13      /**
  14       * @return array<string, string>
  15       */16      public function of(AgentRecord $agent): array
  17      {
  18          if (! $agent->isBound())
  19          {
  20              return [];
  21          }
  22  
  23          return $this->configurations->get($agent->provider)->models($agent->boundLogin()->credentialStore());
  24      }
  25  }

Where: src/Orchestration/AgentConfigurations.php:11

Code (src/Orchestration/AgentConfigurations.php:11):

   8  /**
   9   * @extends Registry<AgentConfiguration>
  10   */11  final class AgentConfigurations extends Registry
  12  {
  13      protected function validate(mixed $item): void
  14      {
  15          if (! $item instanceof AgentConfiguration)
  16          {
  17              throw UnknownAgentConfiguration::notAConfiguration(get_debug_type($item));
  18          }
  19      }
  20  }

Where: src/Orchestration/AgentConfiguration.php:37

Code (src/Orchestration/AgentConfiguration.php:37):

  34       *
  35       * @return array<string, string>
  36       */
→ 37      public function models(string $home): array;
  38  
  39      /**
  40       * The model a turn runs on when the agent names none.
  41       */
  42      public function defaultModel(string $home): string;
  43  
  44      /**
  45       * @return list<string>
  46       */
  47      public function signIn(): array;
  48  
  49      /**
  50       * @return list<string>
  51       */
  52      public function authStatus(): array;
  53  
  54      public function reportsLoggedIn(string $output, int $exitCode): bool;
  55  
  56      public function identityFrom(string $output): string;
  57  
  58      public function displayCodeFrom(string $output): string;
  59  
  60      public function signsInWithPastedCode(): bool;
  61  

Filed via commandments report from a consumer project.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions