Skip to content

Add setup support for agent enablement and image-based authentication #1605

Closed

Description

@propr-dev

Context

Setup needs to detect which coding agents are usable, offer to enable selected agents in ProPR, and authenticate through the agent Docker images. Host-level agent runtime installation is not required, but the selected agent images must be available.

Requirements

  • Reuse agent metadata from shared model definitions where possible.
  • For selected agents, add or update backend agent configuration after the stack is running.
  • Use planAgentLogin() for image-based authentication where available.
  • Pull only selected agent images.
  • Do not disable or delete existing agents when setup is re-run.

Implementation Specification

Add packages/cli/src/commands/setup/agents.ts and call it from the setup engine after stack startup. This can be a follow-up patch to the engine from the earlier issue.

Acceptance Criteria

  • Existing enabled agents remain enabled.
  • Selected new agents are added if missing.
  • Authentication is attempted only for agents with an image login plan and only when the user confirms.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    Agent setup is split out because it crosses image management, credentials, backend API writes, and optional interactive Docker login. Keeping it separate from the main engine prevents the setup runner from becoming a large procedural file. The helper uses add-if-missing semantics because re-running setup should not erase custom models, aliases, or user edits.

    File: packages/cli/src/commands/setup/agents.ts (new file)

    Why this file: This file owns setup-specific agent configuration. It connects selected agent choices to backend agent records and optional Docker-based login.

    import { spawnSync } from 'node:child_process';
    import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
    import { tmpdir } from 'node:os';
    import { join } from 'node:path';
    import { AGENT_DEFAULTS, type AgentType } from '@propr/shared';
    import { addAgent, listAgents, type AgentConfig } from '../../api/agents.js';
    import type { ApiClient } from '../../api/client.js';
    import type { OrchestratorConfig, OrchestratorModule } from '../../orchestrator/index.js';
    import { planAgentLogin } from '../agentValidation.js';
    import type { SetupPrompts } from './engine.js';
    
    function hasAgent(existing: AgentConfig[], type: AgentType): boolean {
      return existing.some((agent) => agent.type === type || agent.alias.toLowerCase() === AGENT_DEFAULTS[type].defaultAlias.toLowerCase());
    }
    
    export async function ensureSelectedAgents(
      selectedAgents: AgentType[],
      client: ApiClient,
      orch: OrchestratorModule,
      cfg: OrchestratorConfig,
      prompts: SetupPrompts,
      onMessage: (message: string) => void = () => {}
    ): Promise<void> {
      if (selectedAgents.length === 0) return;
    
      const existing = (await listAgents(client)).agents;
      for (const type of selectedAgents) {
        const defaults = AGENT_DEFAULTS[type];
        if (!hasAgent(existing, type)) {
          // Use the shared model defaults so setup creates the same baseline agent
          // catalog the UI expects. Existing custom agents are preserved by only
          // adding when no matching type or default alias exists.
          await addAgent({
            alias: defaults.defaultAlias,
            type,
            models: defaults.defaultModels,
            defaultModel: defaults.defaultModels[0],
            dockerImage: defaults.dockerImage,
            enabled: true,
          }, client);
          onMessage(`Added ${defaults.defaultAlias} agent.`);
        } else {
          onMessage(`Keeping existing ${type} agent configuration.`);
        }
      }
    
      for (const type of selectedAgents) {
        const shouldLogin = await prompts.confirm(`Authenticate ${type} through its ProPR Docker image now?`, false);
        if (!shouldLogin) continue;
    
        const tmp = mkdtempSync(join(tmpdir(), 'propr-setup-login-'));
        const workspaceDir = join(tmp, 'workspace');
        mkdirSync(workspaceDir, { recursive: true });
        try {
          const { plan, error } = planAgentLogin(type, cfg, workspaceDir, orch.validateDockerBindPath);
          if (error || !plan) {
            onMessage(`${type} login skipped: ${error ?? 'no login plan available'}`);
            continue;
          }
          mkdirSync(plan.hostDir, { recursive: true, mode: 0o700 });
          // Inherit stdio because these vendor login flows may open browser/device
          // prompts and require a real terminal attached to docker -it.
          const result = spawnSync('docker', plan.dockerArgs, { stdio: 'inherit' });
          if (result.status !== 0) onMessage(`${type} login exited with code ${result.status ?? '?'}.`);
        } finally {
          rmSync(tmp, { recursive: true, force: true });
        }
      }
    }

    File: packages/cli/src/commands/setup/engine.ts

    Why this file: The engine needs to invoke agent enablement after the stack is running because agent configuration is persisted through the backend API.

    --- a/packages/cli/src/commands/setup/engine.ts
    +++ b/packages/cli/src/commands/setup/engine.ts
    @@
     import { writeSetupEnv, stackEnvExists, updateStep } from './state.js';
    +import { ensureSelectedAgents } from './agents.js';
    @@
       const client = createApiClientWithConfig(configManager, { baseUrl: cfg.apiPublicUrl });
    @@
       emit(updateStep(nextState, 'stack-start', { status: 'complete', detail: `Backend responded with HTTP ${status.status}.` }));
    +
    +  emit(updateStep(nextState, 'agents', { status: 'running', detail: 'Saving selected agent configuration.' }));
    +  await ensureSelectedAgents(selectedAgents, client, orch, cfg, prompts, hooks.onMessage);
    +  emit(updateStep(nextState, 'agents', { status: 'complete', detail: 'Selected agent configuration is available.' }));
  2. propr-dev commented on Jun 22, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using claude agent with claude-opus-4-8 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-4-8
    • Branch: 1605/claude-opus-4-8-add-setup-support-for-age-20260622-1045-bjc
    • Base Branch: 1599-epic-build-comprehensive-b5c
    • Worktree: issue-1605-20260622-1045-claude-opus-4-8-bjc

    🔍 Track Task Execution

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions