/ src / capabilityRouting.ts
capabilityRouting.ts
 1  import type { CliCommand } from './registry.js';
 2  
 3  /** Pipeline steps that require a live browser session. */
 4  export const BROWSER_ONLY_STEPS = new Set([
 5    'navigate',
 6    'click',
 7    'type',
 8    'wait',
 9    'press',
10    'snapshot',
11    'evaluate',
12    'intercept',
13    'tap',
14  ]);
15  
16  function pipelineNeedsBrowserSession(pipeline: Record<string, unknown>[]): boolean {
17    return pipeline.some((step) => {
18      if (!step || typeof step !== 'object') return false;
19      return Object.keys(step).some((op) => BROWSER_ONLY_STEPS.has(op));
20    });
21  }
22  
23  export function shouldUseBrowserSession(cmd: CliCommand): boolean {
24    if (!cmd.browser) return false;
25    if (cmd.func) return true;
26    if (!cmd.pipeline || cmd.pipeline.length === 0) return true;
27    // normalizeCommand sets navigateBefore to a URL string (needs pre-nav) or
28    // boolean true (needs authenticated context, no specific URL). Either way
29    // the pipeline requires a browser session even if no step is browser-only.
30    if (cmd.navigateBefore) return true;
31    return pipelineNeedsBrowserSession(cmd.pipeline as Record<string, unknown>[]);
32  }