Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Build Launch Command

From Leeroopedia
Knowledge Sources
Domains Agent_Orchestration, CLI_Building
Last Updated 2026-10-26 10:00 GMT

Overview

Concrete tool for building the shell command that starts an agent's program, provided by AI Maestro's `lib/launch-command.ts`.

Description

The buildLaunchCommand function is the single place that constructs the command an agent runs. Both agent creation and waking call it, so a new agent behaves the same from the first wake. It takes a resolved program command, the agent's permission mode, and tool-specific launch options, then assembles the full command with flags for the model, permission mode (per-tool), Claude session name, channels, scrollback renderer, and OTLP telemetry. The sanitizeLaunchOptions function validates untrusted user-supplied options against a per-tool declaration list, dropping anything unknown or invalid — a pure function with no side effects.

Usage

  • Call `buildLaunchCommand` when creating or waking an agent to produce the exact start command.
  • Call `sanitizeLaunchOptions` independently to validate user-supplied launch options before storing them on the agent.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: lib/launch-command.ts (L34-92)
  • Supporting: lib/launch-options.ts (L83-99), lib/program-choices.ts, lib/freedom.ts, lib/claude-session-name.ts, lib/claude-telemetry.ts

Signature

export function buildLaunchCommand(input: LaunchCommandInput): string

export function sanitizeLaunchOptions(
  kind: ProgramKind | null | undefined,
  raw: unknown
): LaunchOptions

interface LaunchCommandInput {
  command: string                 // resolved start command ('claude', 'grok', wrapper path)
  kind: ProgramKind | null        // 'claude' | 'grok' | 'codex' | 'copilot' | null
  agentName: string
  programArgs?: string            // agent's extra arguments (sanitised here)
  model?: string
  permissionMode?: AgentPermissionMode | string | null
  launchOptions?: unknown         // tool-specific choices, validated here
  env?: NodeJS.ProcessEnv
}

Import

import { buildLaunchCommand } from '@/lib/launch-command'
import { sanitizeLaunchOptions } from '@/lib/launch-options'

I/O Contract

Inputs

Name Type Required Description
input.command string Yes Resolved program command
input.kind null Yes Tool kind (drives per-tool flags)
input.permissionMode string No Permission mode; default 'supervised'
input.model string No Model override
input.launchOptions unknown No Tool-specific launch choices (validated)
kind ProgramKind Yes (sanitize) Tool kind to validate against
raw unknown Yes (sanitize) Untrusted user options object

Outputs

Name Type Description
buildLaunchCommand() returns string Full shell command string with all flags
sanitizeLaunchOptions() returns LaunchOptions Only valid, known options for the tool

Usage Examples

Build a Claude Code launch command

import { buildLaunchCommand } from '@/lib/launch-command'

const cmd = buildLaunchCommand({
  command: 'claude',
  kind: 'claude',
  agentName: 'website',
  permissionMode: 'fullAutonomy',
  model: 'sonnet',
  programArgs: '--verbose',
  env: process.env,
})
// CLAUDE_CODE_DISABLE_ALTERNATE_SCREEN=1 claude --verbose --model sonnet --permission-mode plan ...

Validate user-supplied launch options

import { sanitizeLaunchOptions } from '@/lib/launch-options'

// Unknown options are silently dropped; only declared choices survive
const safe = sanitizeLaunchOptions('grok', { unknownFlag: true, continue: true })
// => { continue: true }  (unknownFlag dropped)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment