@iloom/cli 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/AgentManager.ts","../src/utils/MarkdownAgentParser.ts"],"sourcesContent":["import { readFile } from 'fs/promises'\nimport { accessSync } from 'fs'\nimport path from 'path'\nimport { fileURLToPath } from 'url'\nimport fg from 'fast-glob'\nimport fs from 'fs-extra'\nimport { MarkdownAgentParser } from '../utils/MarkdownAgentParser.js'\nimport { logger } from '../utils/logger.js'\nimport type { IloomSettings } from './SettingsManager.js'\nimport { PromptTemplateManager, TemplateVariables, buildReviewTemplateVariables } from './PromptTemplateManager.js'\n\n// Agent schema interface\nexport interface AgentConfig {\n\tdescription: string\n\tprompt: string\n\ttools?: string[] // Optional - when omitted, agent inherits all tools from parent\n\tmodel: string\n\tcolor?: string\n}\n\n// Container for all loaded agents (keyed by agent name without extension)\nexport interface AgentConfigs {\n\t[agentName: string]: AgentConfig\n}\n\nexport class AgentManager {\n\tprivate agentDir: string\n\tprivate templateManager: PromptTemplateManager\n\n\tconstructor(agentDir?: string, templateManager?: PromptTemplateManager) {\n\t\tthis.templateManager = templateManager ?? new PromptTemplateManager()\n\t\tif (agentDir) {\n\t\t\tthis.agentDir = agentDir\n\t\t} else {\n\t\t\t// Find agents relative to package installation\n\t\t\t// Same pattern as PromptTemplateManager\n\t\t\t// When running from dist/, agents are copied to dist/agents/\n\t\t\tconst currentFileUrl = import.meta.url\n\t\t\tconst currentFilePath = fileURLToPath(currentFileUrl)\n\t\t\tconst distDir = path.dirname(currentFilePath)\n\n\t\t\t// Walk up to find the agents directory\n\t\t\tlet agentDirPath = path.join(distDir, 'agents')\n\t\t\tlet currentDir = distDir\n\n\t\t\twhile (currentDir !== path.dirname(currentDir)) {\n\t\t\t\tconst candidatePath = path.join(currentDir, 'agents')\n\t\t\t\ttry {\n\t\t\t\t\taccessSync(candidatePath)\n\t\t\t\t\tagentDirPath = candidatePath\n\t\t\t\t\tbreak\n\t\t\t\t} catch {\n\t\t\t\t\tcurrentDir = path.dirname(currentDir)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.agentDir = agentDirPath\n\t\t\tlogger.debug('AgentManager initialized', { agentDir: this.agentDir })\n\t\t}\n\t}\n\n\t/**\n\t * Load agent configuration files from markdown (.md) format\n\t * Optionally apply model overrides from settings and template variable substitution\n\t * Throws error if agents directory doesn't exist or files are malformed\n\t * @param settings - Optional project settings with per-agent model overrides\n\t * @param templateVariables - Optional variables for template substitution in agent prompts\n\t * @param patterns - Optional glob patterns to filter which agents to load (default: ['*.md'])\n\t * Supports negation patterns like ['*.md', '!iloom-framework-detector.md']\n\t */\n\tasync loadAgents(\n\t\tsettings?: IloomSettings,\n\t\ttemplateVariables?: TemplateVariables,\n\t\tpatterns: string[] = ['*.md']\n\t): Promise<AgentConfigs> {\n\t\t// Use fast-glob to filter agent files based on patterns\n\t\tconst agentFiles = await fg(patterns, {\n\t\t\tcwd: this.agentDir,\n\t\t\tonlyFiles: true,\n\t\t})\n\n\t\tconst agents: AgentConfigs = {}\n\n\t\tfor (const filename of agentFiles) {\n\t\t\tconst agentPath = path.join(this.agentDir, filename)\n\n\t\t\ttry {\n\t\t\t\tconst content = await readFile(agentPath, 'utf-8')\n\n\t\t\t\t// Parse markdown with frontmatter\n\t\t\t\tconst parsed = this.parseMarkdownAgent(content, filename)\n\t\t\t\tconst agentConfig = parsed.config\n\t\t\t\tconst agentName = parsed.name\n\n\t\t\t\t// Validate required fields\n\t\t\t\tthis.validateAgentConfig(agentConfig, agentName)\n\n\t\t\t\tagents[agentName] = agentConfig\n\t\t\t\tlogger.debug(`Loaded agent: ${agentName}`)\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Failed to load agent from ${filename}`, { error })\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to load agent from ${filename}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\t// Apply template variable substitution to agent prompts if variables provided\n\t\tif (templateVariables) {\n\t\t\t// Extract review config from settings and add to template variables\n\t\t\tObject.assign(templateVariables, buildReviewTemplateVariables(!!templateVariables.SWARM_MODE, settings?.agents))\n\n\t\t\tfor (const [agentName, agentConfig] of Object.entries(agents)) {\n\t\t\t\tagents[agentName] = {\n\t\t\t\t\t...agentConfig,\n\t\t\t\t\tprompt: this.templateManager.substituteVariables(agentConfig.prompt, templateVariables),\n\t\t\t\t}\n\t\t\t\tlogger.debug(`Applied template substitution to agent: ${agentName}`)\n\t\t\t}\n\t\t}\n\n\t\t// Apply settings overrides if provided\n\t\tif (settings?.agents) {\n\t\t\tfor (const [agentName, agentSettings] of Object.entries(settings.agents)) {\n\t\t\t\tif (agents[agentName] && agentSettings.model) {\n\t\t\t\t\tlogger.debug(`Overriding model for ${agentName}: ${agents[agentName].model} -> ${agentSettings.model}`)\n\t\t\t\t\tagents[agentName] = {\n\t\t\t\t\t\t...agents[agentName],\n\t\t\t\t\t\tmodel: agentSettings.model,\n\t\t\t\t\t}\n\t\t\t\t} else if (!agents[agentName]) {\n\t\t\t\t\t// Skip warning for runtime-generated agents (e.g., swarm worker)\n\t\t\t\t\tconst RUNTIME_GENERATED_AGENTS = ['iloom-swarm-worker']\n\t\t\t\t\tif (!RUNTIME_GENERATED_AGENTS.includes(agentName)) {\n\t\t\t\t\t\t// Only warn if the agent file doesn't exist at all (typo in settings)\n\t\t\t\t\t\t// Skip warning if the agent exists but wasn't loaded due to pattern filtering\n\t\t\t\t\t\tconst agentFile = path.join(this.agentDir, `${agentName}.md`)\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\taccessSync(agentFile)\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tlogger.warn(`Settings reference unknown agent: ${agentName}`)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn agents\n\t}\n\n\t/**\n\t * Validate agent configuration has required fields\n\t * Note: tools is optional - when omitted, agent inherits all tools from parent\n\t */\n\tprivate validateAgentConfig(config: AgentConfig, agentName: string): void {\n\t\tconst requiredFields: (keyof AgentConfig)[] = ['description', 'prompt', 'model']\n\n\t\tfor (const field of requiredFields) {\n\t\t\tif (!config[field]) {\n\t\t\t\tthrow new Error(`Agent ${agentName} missing required field: ${field}`)\n\t\t\t}\n\t\t}\n\n\t\t// Tools is optional, but if present must be an array\n\t\tif (config.tools !== undefined && !Array.isArray(config.tools)) {\n\t\t\tthrow new Error(`Agent ${agentName} tools must be an array`)\n\t\t}\n\t}\n\n\t/**\n\t * Parse markdown agent file with YAML frontmatter\n\t * @param content - Raw markdown file content\n\t * @param filename - Original filename for error messages\n\t * @returns Parsed agent config and name\n\t */\n\tprivate parseMarkdownAgent(content: string, filename: string): { config: AgentConfig; name: string } {\n\t\ttry {\n\t\t\t// Parse frontmatter using custom parser\n\t\t\tconst { data, content: markdownBody } = MarkdownAgentParser.parse(content)\n\n\t\t\t// Validate frontmatter has required fields\n\t\t\tif (!data.name) {\n\t\t\t\tthrow new Error('Missing required field: name')\n\t\t\t}\n\t\t\tif (!data.description) {\n\t\t\t\tthrow new Error('Missing required field: description')\n\t\t\t}\n\t\t\t// Note: tools is now optional - when omitted, agent inherits all tools from parent\n\t\t\tif (!data.model) {\n\t\t\t\tthrow new Error('Missing required field: model')\n\t\t\t}\n\n\t\t\t// Parse tools from comma-separated string to array (only if tools field is present)\n\t\t\tlet tools: string[] | undefined\n\t\t\tif (data.tools) {\n\t\t\t\ttools = data.tools\n\t\t\t\t\t.split(',')\n\t\t\t\t\t.map((tool: string) => tool.trim())\n\t\t\t\t\t.filter((tool: string) => tool.length > 0)\n\t\t\t}\n\n\t\t\t// Validate model and warn if non-standard\n\t\t\tconst validModels = ['sonnet', 'opus', 'haiku']\n\t\t\tif (!validModels.includes(data.model)) {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Agent ${data.name} uses model \"${data.model}\" which may not be recognized by Claude CLI, and your workflow may fail or produce unexpected results. ` +\n\t\t\t\t\t\t`Valid values are: ${validModels.join(', ')}`\n\t\t\t\t)\n\t\t\t}\n\n\t\t\t// Construct AgentConfig\n\t\t\tconst config: AgentConfig = {\n\t\t\t\tdescription: data.description,\n\t\t\t\tprompt: markdownBody.trim(),\n\t\t\t\tmodel: data.model,\n\t\t\t\t...(tools && { tools }),\n\t\t\t\t...(data.color && { color: data.color }),\n\t\t\t}\n\n\t\t\treturn { config, name: data.name }\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to parse markdown agent ${filename}: ${error instanceof Error ? error.message : 'Unknown error'}`\n\t\t\t)\n\t\t}\n\t}\n\n\t/**\n\t * Format loaded agents for Claude CLI --agents flag\n\t * Returns object suitable for JSON.stringify\n\t */\n\tformatForCli(agents: AgentConfigs): Record<string, unknown> {\n\t\t// The agents object is already in the correct format\n\t\t// Just return it - launchClaude will JSON.stringify it\n\t\treturn agents as Record<string, unknown>\n\t}\n\n\t/**\n\t * Load agents and prepare them for the current platform.\n\t * On macOS, returns agents formatted for the --agents CLI flag.\n\t * On Linux/Windows, renders agents to disk for auto-discovery and returns undefined.\n\t *\n\t * @param settings - Project settings for model overrides\n\t * @param templateVariables - Variables to substitute in agent prompts\n\t * @param patterns - Glob patterns for which agent files to load\n\t * @param targetDir - Directory for disk rendering (Linux/Windows). Defaults to cwd/.claude/agents/\n\t * @returns Agents object for CLI flag (macOS) or undefined (Linux/Windows, agents on disk)\n\t */\n\tasync loadAndPrepare(\n\t\tsettings: IloomSettings | undefined,\n\t\ttemplateVariables: TemplateVariables,\n\t\tpatterns: string[],\n\t\ttargetDir?: string\n\t): Promise<Record<string, unknown> | undefined> {\n\t\tconst loadedAgents = await this.loadAgents(settings, templateVariables, patterns)\n\n\t\tif (process.platform === 'darwin') {\n\t\t\tconst agents = this.formatForCli(loadedAgents)\n\t\t\tlogger.debug('Loaded agent configurations for CLI', {\n\t\t\t\tagentCount: Object.keys(agents).length,\n\t\t\t\tagentNames: Object.keys(agents),\n\t\t\t})\n\t\t\treturn agents\n\t\t}\n\n\t\tconst dir = targetDir ?? path.join(process.cwd(), '.claude', 'agents')\n\t\tconst rendered = await this.renderAgentsToDisk(loadedAgents, dir)\n\t\tlogger.debug('Rendered agent files to disk for auto-discovery', {\n\t\t\tagentCount: rendered.length,\n\t\t\tagentNames: rendered,\n\t\t\ttargetDir: dir,\n\t\t})\n\t\treturn undefined\n\t}\n\n\t/**\n\t * Render loaded agents to disk as markdown files with YAML frontmatter.\n\t * Claude Code auto-discovers agents from .claude/agents/ directory.\n\t *\n\t * @param agents - Loaded agent configs (from loadAgents())\n\t * @param targetDir - Absolute path to target directory (e.g., <worktree>/.claude/agents/)\n\t * @returns Array of rendered filenames\n\t */\n\tasync renderAgentsToDisk(agents: AgentConfigs, targetDir: string): Promise<string[]> {\n\t\tawait fs.ensureDir(targetDir)\n\n\t\t// Clean existing iloom agent files to avoid stale agents from previous runs\n\t\tconst existingFiles = await fg('iloom-*.md', { cwd: targetDir, onlyFiles: true })\n\t\tfor (const file of existingFiles) {\n\t\t\tawait fs.remove(path.join(targetDir, file))\n\t\t}\n\n\t\tconst renderedFiles: string[] = []\n\t\tfor (const [agentName, config] of Object.entries(agents)) {\n\t\t\tconst safeName = path.basename(agentName)\n\t\t\tconst filename = `${safeName}.md`\n\t\t\t// Build YAML frontmatter\n\t\t\tconst frontmatterLines = ['---', `name: ${agentName}`, `description: ${config.description}`]\n\t\t\tif (config.tools) frontmatterLines.push(`tools: ${config.tools.join(', ')}`)\n\t\t\tfrontmatterLines.push(`model: ${config.model}`)\n\t\t\tif (config.color) frontmatterLines.push(`color: ${config.color}`)\n\t\t\tfrontmatterLines.push('---')\n\n\t\t\tconst content = frontmatterLines.join('\\n') + '\\n\\n' + config.prompt + '\\n'\n\t\t\tawait fs.writeFile(path.join(targetDir, filename), content, 'utf-8')\n\t\t\trenderedFiles.push(filename)\n\t\t}\n\t\treturn renderedFiles\n\t}\n}\n","/**\n * Custom YAML frontmatter parser for agent markdown files\n * Replaces gray-matter dependency with lightweight custom implementation\n */\n\ninterface ParseResult {\n\tdata: Record<string, string>\n\tcontent: string\n}\n\nexport class MarkdownAgentParser {\n\t/**\n\t * Parse markdown content with YAML frontmatter\n\t * @param content - Raw markdown file content\n\t * @returns Object with parsed frontmatter data and markdown body content\n\t * @throws Error if frontmatter is malformed or missing\n\t */\n\tstatic parse(content: string): ParseResult {\n\t\tconst lines = content.split('\\n')\n\n\t\t// Check for opening frontmatter delimiter\n\t\tif (lines[0]?.trim() !== '---') {\n\t\t\tthrow new Error('Missing opening frontmatter delimiter (---)')\n\t\t}\n\n\t\t// Find closing frontmatter delimiter\n\t\tlet closingDelimiterIndex = -1\n\t\tfor (let i = 1; i < lines.length; i++) {\n\t\t\tif (lines[i]?.trim() === '---') {\n\t\t\t\tclosingDelimiterIndex = i\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif (closingDelimiterIndex === -1) {\n\t\t\tthrow new Error('Missing closing frontmatter delimiter (---)')\n\t\t}\n\n\t\t// Extract frontmatter lines (between the delimiters)\n\t\tconst frontmatterLines = lines.slice(1, closingDelimiterIndex)\n\n\t\t// Extract markdown body (after closing delimiter)\n\t\tconst bodyLines = lines.slice(closingDelimiterIndex + 1)\n\t\tconst markdownBody = bodyLines.join('\\n')\n\n\t\t// Parse YAML frontmatter into key-value pairs\n\t\tconst data = this.parseYaml(frontmatterLines.join('\\n'))\n\n\t\treturn {\n\t\t\tdata,\n\t\t\tcontent: markdownBody,\n\t\t}\n\t}\n\n\t/**\n\t * Parse simplified YAML into key-value object\n\t * Supports:\n\t * - Simple key: value pairs\n\t * - Multiline values with | indicator\n\t * - Values with special characters and newlines\n\t *\n\t * @param yaml - YAML string to parse\n\t * @returns Object with parsed key-value pairs\n\t */\n\tprivate static parseYaml(yaml: string): Record<string, string> {\n\t\tconst result: Record<string, string> = {}\n\t\tconst lines = yaml.split('\\n')\n\t\tlet currentKey: string | null = null\n\t\tlet currentValue: string[] = []\n\t\tlet isMultiline = false\n\n\t\tconst finalizeCurrent = (): void => {\n\t\t\tif (currentKey && currentValue.length > 0) {\n\t\t\t\tresult[currentKey] = currentValue.join('\\n').trim()\n\t\t\t\tcurrentKey = null\n\t\t\t\tcurrentValue = []\n\t\t\t}\n\t\t}\n\n\t\tfor (const line of lines) {\n\t\t\t// Skip empty lines when not in multiline mode\n\t\t\tif (!isMultiline && line.trim() === '') {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Check if this is a new key-value pair\n\t\t\tconst keyValueMatch = line.match(/^([a-zA-Z_][a-zA-Z0-9_-]*)\\s*:\\s*(.*)$/)\n\n\t\t\tif (keyValueMatch && !isMultiline) {\n\t\t\t\t// Finalize previous key if exists\n\t\t\t\tfinalizeCurrent()\n\n\t\t\t\tconst [, key, value] = keyValueMatch\n\t\t\t\tif (!key || value === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tcurrentKey = key\n\n\t\t\t\t// Check for multiline indicator\n\t\t\t\tif (value.trim() === '|') {\n\t\t\t\t\tisMultiline = true\n\t\t\t\t\tcurrentValue = []\n\t\t\t\t} else {\n\t\t\t\t\t// Single line value\n\t\t\t\t\tcurrentValue = [value]\n\t\t\t\t\tfinalizeCurrent()\n\t\t\t\t\tisMultiline = false\n\t\t\t\t}\n\t\t\t} else if (isMultiline && currentKey) {\n\t\t\t\t// Continuation of multiline value\n\t\t\t\t// Check if we've returned to normal indentation (new key)\n\t\t\t\tif (line.match(/^[a-zA-Z_][a-zA-Z0-9_-]*\\s*:/) && !line.startsWith(' ')) {\n\t\t\t\t\t// End of multiline, this is a new key\n\t\t\t\t\tfinalizeCurrent()\n\t\t\t\t\tisMultiline = false\n\n\t\t\t\t\t// Process this line as a new key\n\t\t\t\t\tconst match = line.match(/^([a-zA-Z_][a-zA-Z0-9_-]*)\\s*:\\s*(.*)$/)\n\t\t\t\t\tif (match) {\n\t\t\t\t\t\tconst [, key, value] = match\n\t\t\t\t\t\tif (key && value !== undefined) {\n\t\t\t\t\t\t\tcurrentKey = key\n\t\t\t\t\t\t\tcurrentValue = [value]\n\t\t\t\t\t\t\tfinalizeCurrent()\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Remove leading spaces (common indentation) from multiline values\n\t\t\t\t\tconst trimmedLine = line.replace(/^ {2}/, '')\n\t\t\t\t\tcurrentValue.push(trimmedLine)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Finalize last key\n\t\tfinalizeCurrent()\n\n\t\treturn result\n\t}\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;AACf,OAAO,QAAQ;;;ACKR,IAAM,sBAAN,MAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhC,OAAO,MAAM,SAA8B;AAjB5C;AAkBE,UAAM,QAAQ,QAAQ,MAAM,IAAI;AAGhC,UAAI,WAAM,CAAC,MAAP,mBAAU,YAAW,OAAO;AAC/B,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC9D;AAGA,QAAI,wBAAwB;AAC5B,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,YAAI,WAAM,CAAC,MAAP,mBAAU,YAAW,OAAO;AAC/B,gCAAwB;AACxB;AAAA,MACD;AAAA,IACD;AAEA,QAAI,0BAA0B,IAAI;AACjC,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC9D;AAGA,UAAM,mBAAmB,MAAM,MAAM,GAAG,qBAAqB;AAG7D,UAAM,YAAY,MAAM,MAAM,wBAAwB,CAAC;AACvD,UAAM,eAAe,UAAU,KAAK,IAAI;AAGxC,UAAM,OAAO,KAAK,UAAU,iBAAiB,KAAK,IAAI,CAAC;AAEvD,WAAO;AAAA,MAC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,EAAE,KAAK,WAAW,WAAW,KAAK,CAAC;AAChF,eAAW,QAAQ,eAAe;AACjC,YAAM,GAAG,OAAO,KAAK,KAAK,WAAW,IAAI,CAAC;AAAA,IAC3C;AAEA,UAAM,gBAA0B,CAAC;AACjC,eAAW,CAAC,WAAW,MAAM,KAAK,OAAO,QAAQ,MAAM,GAAG;AACzD,YAAM,WAAW,KAAK,SAAS,SAAS;AACxC,YAAM,WAAW,GAAG,QAAQ;AAE5B,YAAM,mBAAmB,CAAC,OAAO,SAAS,SAAS,IAAI,gBAAgB,OAAO,WAAW,EAAE;AAC3F,UAAI,OAAO,MAAO,kBAAiB,KAAK,UAAU,OAAO,MAAM,KAAK,IAAI,CAAC,EAAE;AAC3E,uBAAiB,KAAK,UAAU,OAAO,KAAK,EAAE;AAC9C,UAAI,OAAO,MAAO,kBAAiB,KAAK,UAAU,OAAO,KAAK,EAAE;AAChE,uBAAiB,KAAK,KAAK;AAE3B,YAAM,UAAU,iBAAiB,KAAK,IAAI,IAAI,SAAS,OAAO,SAAS;AACvE,YAAM,GAAG,UAAU,KAAK,KAAK,WAAW,QAAQ,GAAG,SAAS,OAAO;AACnE,oBAAc,KAAK,QAAQ;AAAA,IAC5B;AACA,WAAO;AAAA,EACR;AACD;","names":[]}
package/dist/cli.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  StartCommand,
12
12
  launchFirstRunSetup,
13
13
  needsFirstRunSetup
14
- } from "./chunk-IS46GQRA.js";
14
+ } from "./chunk-DY6MUWQW.js";
15
15
  import {
16
16
  CLIIsolationManager,
17
17
  DatabaseManager,
@@ -58,7 +58,7 @@ import {
58
58
  import "./chunk-CQHHEW2M.js";
59
59
  import {
60
60
  AgentManager
61
- } from "./chunk-JD3K2344.js";
61
+ } from "./chunk-Y2MVSEJK.js";
62
62
  import {
63
63
  CommitManager,
64
64
  UserAbortedCommitError,
@@ -2206,7 +2206,7 @@ async function autoLaunchInitForMultipleRemotes() {
2206
2206
  await waitForKeypress2("Press any key to start configuration...");
2207
2207
  logger.info("");
2208
2208
  try {
2209
- const { InitCommand } = await import("./init-A6WRP77L.js");
2209
+ const { InitCommand } = await import("./init-LWU2M53W.js");
2210
2210
  const initCommand = new InitCommand();
2211
2211
  const customInitialMessage = "Help me configure which git remote iloom should use for GitHub operations. I have multiple remotes and need to select the correct one.";
2212
2212
  await initCommand.execute(customInitialMessage);
@@ -2314,7 +2314,7 @@ program.command("add-issue").alias("a").description("Create and enhance GitHub i
2314
2314
  });
2315
2315
  program.command("feedback").alias("f").description("Submit feedback/bug report to iloom-cli repository").argument("<description>", "Feedback title (>30 chars, >2 spaces; or any non-empty text when --body provided)").option("--body <text>", "Body text for feedback (added after diagnostics)").action(async (description, options) => {
2316
2316
  try {
2317
- const { FeedbackCommand } = await import("./feedback-I6ZEHEUB.js");
2317
+ const { FeedbackCommand } = await import("./feedback-RFWGB4I5.js");
2318
2318
  const command = new FeedbackCommand();
2319
2319
  const feedbackOptions = {};
2320
2320
  if (options.body !== void 0) {
@@ -2495,7 +2495,7 @@ program.command("spin").alias("ignite").description("Launch Claude with auto-det
2495
2495
  options.oneShot = "bypassPermissions";
2496
2496
  }
2497
2497
  try {
2498
- const { IgniteCommand } = await import("./ignite-XZFYRVRJ.js");
2498
+ const { IgniteCommand } = await import("./ignite-X2NNTNUN.js");
2499
2499
  const command = new IgniteCommand();
2500
2500
  if (options.json && options.jsonStream) {
2501
2501
  logger.error("--json and --json-stream are mutually exclusive");
@@ -3008,7 +3008,7 @@ program.command("issues").description("List project issues from configured issue
3008
3008
  });
3009
3009
  program.command("init").alias("config").description("Initialize iloom configuration").argument("[prompt]", 'Custom initial message to send to Claude (defaults to "Help me configure iloom settings.")').addOption(new Option("--accept-defaults").hideHelp()).action(async (prompt, options) => {
3010
3010
  try {
3011
- const { InitCommand } = await import("./init-A6WRP77L.js");
3011
+ const { InitCommand } = await import("./init-LWU2M53W.js");
3012
3012
  const command = new InitCommand();
3013
3013
  const trimmedPrompt = prompt == null ? void 0 : prompt.trim();
3014
3014
  const customPrompt = trimmedPrompt && trimmedPrompt.length > 0 ? trimmedPrompt : void 0;
@@ -3022,7 +3022,7 @@ program.command("plan").description("Launch interactive planning session with Ar
3022
3022
  new Option("--output-format <format>", "Output format for Claude CLI (requires --print)").choices(["json", "stream-json", "text"])
3023
3023
  ).option("--verbose", "Enable verbose output (requires --print)").option("--json", "Output final result as JSON object (requires --print)").option("--json-stream", "Stream JSONL output to stdout in real-time (requires --print)").option("--auto-swarm", "Enable auto-swarm: plan, start epic, and spin automatically").action(async (prompt, options) => {
3024
3024
  try {
3025
- const { PlanCommand } = await import("./plan-PL3ZB32J.js");
3025
+ const { PlanCommand } = await import("./plan-5S6355GF.js");
3026
3026
  const command = new PlanCommand();
3027
3027
  if ((options == null ? void 0 : options.json) && (options == null ? void 0 : options.jsonStream)) {
3028
3028
  logger.error("--json and --json-stream are mutually exclusive");
@@ -8,7 +8,7 @@ import {
8
8
  import "./chunk-CQHHEW2M.js";
9
9
  import {
10
10
  AgentManager
11
- } from "./chunk-JD3K2344.js";
11
+ } from "./chunk-Y2MVSEJK.js";
12
12
  import "./chunk-WEBMMJKL.js";
13
13
  import "./chunk-7RCUWU3I.js";
14
14
  import {
@@ -167,4 +167,4 @@ ${userBody}`;
167
167
  export {
168
168
  FeedbackCommand
169
169
  };
170
- //# sourceMappingURL=feedback-I6ZEHEUB.js.map
170
+ //# sourceMappingURL=feedback-RFWGB4I5.js.map
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  IgniteCommand,
4
4
  WorktreeValidationError
5
- } from "./chunk-PDG74IJT.js";
5
+ } from "./chunk-UVXB6O24.js";
6
6
  import "./chunk-PMB6TYV4.js";
7
7
  import "./chunk-7UBEHQTP.js";
8
8
  import "./chunk-BFF27W3S.js";
9
9
  import "./chunk-MY2Q3FJ3.js";
10
10
  import "./chunk-EGNUOALL.js";
11
11
  import "./chunk-CQHHEW2M.js";
12
- import "./chunk-JD3K2344.js";
12
+ import "./chunk-Y2MVSEJK.js";
13
13
  import "./chunk-R7DGN73N.js";
14
14
  import "./chunk-4232AHNQ.js";
15
15
  import "./chunk-VIQOQ463.js";
@@ -32,4 +32,4 @@ export {
32
32
  IgniteCommand,
33
33
  WorktreeValidationError
34
34
  };
35
- //# sourceMappingURL=ignite-XZFYRVRJ.js.map
35
+ //# sourceMappingURL=ignite-X2NNTNUN.js.map
@@ -13,7 +13,7 @@ import {
13
13
  } from "./chunk-EGNUOALL.js";
14
14
  import {
15
15
  AgentManager
16
- } from "./chunk-JD3K2344.js";
16
+ } from "./chunk-Y2MVSEJK.js";
17
17
  import "./chunk-FV4KXBGO.js";
18
18
  import {
19
19
  PromptTemplateManager
@@ -461,4 +461,4 @@ var InitCommand = class {
461
461
  export {
462
462
  InitCommand
463
463
  };
464
- //# sourceMappingURL=init-A6WRP77L.js.map
464
+ //# sourceMappingURL=init-LWU2M53W.js.map
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  IgniteCommand
4
- } from "./chunk-PDG74IJT.js";
4
+ } from "./chunk-UVXB6O24.js";
5
5
  import {
6
6
  StartCommand,
7
7
  launchFirstRunSetup,
8
8
  needsFirstRunSetup
9
- } from "./chunk-IS46GQRA.js";
9
+ } from "./chunk-DY6MUWQW.js";
10
10
  import "./chunk-GWJWECZB.js";
11
11
  import "./chunk-M3FBM4T3.js";
12
12
  import "./chunk-PMB6TYV4.js";
13
- import "./chunk-7UBEHQTP.js";
13
+ import {
14
+ preAcceptClaudeTrust
15
+ } from "./chunk-7UBEHQTP.js";
14
16
  import "./chunk-BFF27W3S.js";
15
17
  import {
16
18
  matchIssueIdentifier
@@ -25,7 +27,9 @@ import {
25
27
  generateHarnessMcpConfig,
26
28
  generateIssueManagementMcpConfig
27
29
  } from "./chunk-CQHHEW2M.js";
28
- import "./chunk-JD3K2344.js";
30
+ import {
31
+ AgentManager
32
+ } from "./chunk-Y2MVSEJK.js";
29
33
  import {
30
34
  IssueManagementProviderFactory
31
35
  } from "./chunk-R7DGN73N.js";
@@ -251,8 +255,9 @@ function formatDependencies(dependencies, issuePrefix) {
251
255
  return lines.length > 0 ? lines.join("\n") : "None";
252
256
  }
253
257
  var PlanCommand = class {
254
- constructor(templateManager) {
258
+ constructor(templateManager, agentManager) {
255
259
  this.templateManager = templateManager ?? new PromptTemplateManager();
260
+ this.agentManager = agentManager ?? new AgentManager();
256
261
  }
257
262
  /**
258
263
  * Main entry point for the plan command
@@ -386,7 +391,7 @@ var PlanCommand = class {
386
391
  );
387
392
  if (shouldRunInit) {
388
393
  logger.info(chalk.bold("Launching iloom init..."));
389
- const { InitCommand } = await import("./init-A6WRP77L.js");
394
+ const { InitCommand } = await import("./init-LWU2M53W.js");
390
395
  const initCommand = new InitCommand();
391
396
  await initCommand.execute(
392
397
  "Help the user set up a GitHub repository or Linear project for this project so they can use issue management features. When complete tell the user they can exit to continue the planning session."
@@ -529,36 +534,15 @@ var PlanCommand = class {
529
534
  promptLength: architectPrompt.length,
530
535
  mode: decompositionContext ? "decomposition" : "fresh"
531
536
  });
532
- const allowedTools = [
533
- // Issue management tools
534
- "mcp__issue_management__create_issue",
535
- "mcp__issue_management__create_child_issue",
536
- "mcp__issue_management__get_issue",
537
- "mcp__issue_management__get_child_issues",
538
- "mcp__issue_management__get_comment",
539
- "mcp__issue_management__create_comment",
540
- // Dependency management tools
541
- "mcp__issue_management__create_dependency",
542
- "mcp__issue_management__get_dependencies",
543
- "mcp__issue_management__remove_dependency",
544
- // Codebase exploration tools (read-only)
545
- "Read",
546
- "Glob",
547
- "Grep",
548
- "Task",
549
- // Web research tools
550
- "WebFetch",
551
- "WebSearch",
552
- // Git commands for understanding repo state
553
- "Bash(git status:*)",
554
- "Bash(git log:*)",
555
- "Bash(git branch:*)",
556
- "Bash(git remote:*)",
557
- "Bash(git diff:*)",
558
- "Bash(git show:*)"
559
- ];
560
- if (autoSwarm) {
561
- allowedTools.push("mcp__harness__signal");
537
+ let agents;
538
+ try {
539
+ agents = await this.agentManager.loadAndPrepare(
540
+ settings ?? void 0,
541
+ templateVariables,
542
+ ["iloom-issue-analyzer.md"]
543
+ );
544
+ } catch (error) {
545
+ logger.warn(`Failed to load agents: ${error instanceof Error ? error.message : "Unknown error"}`);
562
546
  }
563
547
  const isHeadless = (printOptions == null ? void 0 : printOptions.print) ?? false;
564
548
  const claudeOptions = {
@@ -567,7 +551,7 @@ var PlanCommand = class {
567
551
  appendSystemPrompt: architectPrompt,
568
552
  mcpConfig,
569
553
  addDir: process.cwd(),
570
- allowedTools
554
+ ...agents && { agents }
571
555
  };
572
556
  if ((printOptions == null ? void 0 : printOptions.outputFormat) !== void 0) {
573
557
  claudeOptions.outputFormat = printOptions.outputFormat;
@@ -599,6 +583,11 @@ var PlanCommand = class {
599
583
  yolo,
600
584
  print: isHeadless
601
585
  });
586
+ try {
587
+ await preAcceptClaudeTrust(process.cwd());
588
+ } catch (error) {
589
+ logger.warn(`Failed to pre-accept Claude trust: ${error instanceof Error ? error.message : String(error)}`);
590
+ }
602
591
  let initialMessage;
603
592
  if (decompositionContext) {
604
593
  initialMessage = `Break down issue #${decompositionContext.identifier} into child issues.`;
@@ -723,4 +712,4 @@ ${initialMessage}`;
723
712
  export {
724
713
  PlanCommand
725
714
  };
726
- //# sourceMappingURL=plan-PL3ZB32J.js.map
715
+ //# sourceMappingURL=plan-5S6355GF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/plan.ts","../src/lib/HarnessServer.ts"],"sourcesContent":["/* global AbortController, setImmediate */\nimport { logger, createStderrLogger } from '../utils/logger.js'\nimport { withLogger } from '../utils/logger-context.js'\nimport chalk from 'chalk'\nimport { detectClaudeCli, launchClaude } from '../utils/claude.js'\nimport { preAcceptClaudeTrust } from '../utils/claude-trust.js'\nimport { PromptTemplateManager, type TemplateVariables } from '../lib/PromptTemplateManager.js'\nimport { AgentManager } from '../lib/AgentManager.js'\nimport { generateIssueManagementMcpConfig, generateHarnessMcpConfig } from '../utils/mcp.js'\nimport { HarnessServer } from '../lib/HarnessServer.js'\nimport { SettingsManager, PlanCommandSettingsSchema } from '../lib/SettingsManager.js'\nimport { IssueTrackerFactory } from '../lib/IssueTrackerFactory.js'\nimport { matchIssueIdentifier } from '../utils/IdentifierParser.js'\nimport { IssueManagementProviderFactory } from '../mcp/IssueManagementProviderFactory.js'\nimport { needsFirstRunSetup, launchFirstRunSetup } from '../utils/first-run-setup.js'\nimport type { IssueProvider, ChildIssueResult, DependenciesResult } from '../mcp/types.js'\nimport { promptConfirmation, isInteractiveEnvironment } from '../utils/prompt.js'\nimport { TelemetryService } from '../lib/TelemetryService.js'\nimport { StartCommand } from './start.js'\nimport { IgniteCommand } from './ignite.js'\n\n// Define provider arrays for validation and dynamic flag generation\nconst PLANNER_PROVIDERS = ['claude', 'gemini', 'codex'] as const\nconst REVIEWER_PROVIDERS = ['claude', 'gemini', 'codex', 'none'] as const\n\ntype PlannerProvider = (typeof PLANNER_PROVIDERS)[number]\ntype ReviewerProvider = (typeof REVIEWER_PROVIDERS)[number]\n\n/**\n * Format child issues as a markdown list for inclusion in the prompt\n */\nfunction formatChildIssues(children: ChildIssueResult[], issuePrefix: string): string {\n\tif (children.length === 0) return 'None'\n\treturn children\n\t\t.map(child => `- ${issuePrefix}${child.id}: ${child.title} (${child.state})`)\n\t\t.join('\\n')\n}\n\n/**\n * Format dependencies as a markdown list for inclusion in the prompt\n */\nfunction formatDependencies(dependencies: DependenciesResult, issuePrefix: string): string {\n\tconst lines: string[] = []\n\n\tif (dependencies.blockedBy.length > 0) {\n\t\tlines.push('**Blocked by:**')\n\t\tfor (const dep of dependencies.blockedBy) {\n\t\t\tlines.push(`- ${issuePrefix}${dep.id}: ${dep.title} (${dep.state})`)\n\t\t}\n\t}\n\n\tif (dependencies.blocking.length > 0) {\n\t\tif (lines.length > 0) lines.push('')\n\t\tlines.push('**Blocking:**')\n\t\tfor (const dep of dependencies.blocking) {\n\t\t\tlines.push(`- ${issuePrefix}${dep.id}: ${dep.title} (${dep.state})`)\n\t\t}\n\t}\n\n\treturn lines.length > 0 ? lines.join('\\n') : 'None'\n}\n\n/**\n * Launch interactive planning session with Architect persona\n * Implements the `il plan` command requested in issue #471\n *\n * The Architect persona helps users:\n * - Break epics down into child issues following \"1 issue = 1 loom = 1 PR\" pattern\n * - Think through implementation approaches\n * - Create issues at the end of the planning session using MCP tools\n */\nexport class PlanCommand {\n\tprivate readonly templateManager: PromptTemplateManager\n\tprivate readonly agentManager: AgentManager\n\n\tconstructor(templateManager?: PromptTemplateManager, agentManager?: AgentManager) {\n\t\tthis.templateManager = templateManager ?? new PromptTemplateManager()\n\t\tthis.agentManager = agentManager ?? new AgentManager()\n\t}\n\n\t/**\n\t * Main entry point for the plan command\n\t * @param prompt - Optional initial planning prompt or topic\n\t * @param model - Optional model to use (defaults to 'opus')\n\t * @param yolo - Optional flag to enable autonomous mode (skip permission prompts)\n\t * @param planner - Optional planner provider (defaults to 'claude')\n\t * @param reviewer - Optional reviewer provider (defaults to 'none')\n\t * @param printOptions - Print mode options for headless/CI execution\n\t */\n\tpublic async execute(\n\t\tprompt?: string,\n\t\tmodel?: string,\n\t\tyolo?: boolean,\n\t\tplanner?: string,\n\t\treviewer?: string,\n\t\tprintOptions?: {\n\t\t\tprint?: boolean\n\t\t\toutputFormat?: 'json' | 'stream-json' | 'text'\n\t\t\tverbose?: boolean\n\t\t\tjson?: boolean\n\t\t\tjsonStream?: boolean\n\t\t},\n\t\tautoSwarm?: boolean\n\t): Promise<void> {\n\t\t// Wrap execution in stderr logger for JSON modes to keep stdout clean\n\t\tconst isJsonMode = (printOptions?.json ?? false) || (printOptions?.jsonStream ?? false)\n\t\tif (isJsonMode) {\n\t\t\tconst jsonLogger = createStderrLogger()\n\t\t\treturn withLogger(jsonLogger, () => this.executeInternal(prompt, model, yolo, planner, reviewer, printOptions, autoSwarm))\n\t\t}\n\n\t\treturn this.executeInternal(prompt, model, yolo, planner, reviewer, printOptions, autoSwarm)\n\t}\n\n\t/**\n\t * Internal execution method (separated for withLogger wrapping)\n\t */\n\tprivate async executeInternal(\n\t\tprompt?: string,\n\t\tmodel?: string,\n\t\tyolo?: boolean,\n\t\tplanner?: string,\n\t\treviewer?: string,\n\t\tprintOptions?: {\n\t\t\tprint?: boolean\n\t\t\toutputFormat?: 'json' | 'stream-json' | 'text'\n\t\t\tverbose?: boolean\n\t\t\tjson?: boolean\n\t\t\tjsonStream?: boolean\n\t\t},\n\t\tautoSwarm?: boolean\n\t): Promise<void> {\n\t\t// Validate and normalize planner CLI argument\n\t\tlet normalizedPlanner: PlannerProvider | undefined\n\t\tif (planner) {\n\t\t\tconst normalized = planner.toLowerCase()\n\t\t\tconst result = PlanCommandSettingsSchema.shape.planner.safeParse(normalized)\n\t\t\tif (!result.success) {\n\t\t\t\tthrow new Error(`Invalid planner: \"${planner}\". Allowed values: ${PLANNER_PROVIDERS.join(', ')}`)\n\t\t\t}\n\t\t\tnormalizedPlanner = normalized as PlannerProvider\n\t\t}\n\n\t\t// Validate and normalize reviewer CLI argument\n\t\tlet normalizedReviewer: ReviewerProvider | undefined\n\t\tif (reviewer) {\n\t\t\tconst normalized = reviewer.toLowerCase()\n\t\t\tconst result = PlanCommandSettingsSchema.shape.reviewer.safeParse(normalized)\n\t\t\tif (!result.success) {\n\t\t\t\tthrow new Error(`Invalid reviewer: \"${reviewer}\". Allowed values: ${REVIEWER_PROVIDERS.join(', ')}`)\n\t\t\t}\n\t\t\tnormalizedReviewer = normalized as ReviewerProvider\n\t\t}\n\n\t\tlogger.debug('PlanCommand.execute() starting', {\n\t\t\tcwd: process.cwd(),\n\t\t\thasPrompt: !!prompt,\n\t\t\tyolo,\n\t\t\tplanner: normalizedPlanner ?? planner,\n\t\t\treviewer: normalizedReviewer ?? reviewer,\n\t\t})\n\n\t\t// Check for first-run setup (same check as StartCommand)\n\t\tif (process.env.FORCE_FIRST_TIME_SETUP === \"true\" || await needsFirstRunSetup()) {\n\t\t\tawait launchFirstRunSetup()\n\t\t}\n\n\t\tlogger.info(chalk.bold('Starting interactive planning session...'))\n\n\t\t// Check if Claude CLI is available\n\t\tlogger.debug('Checking Claude CLI availability')\n\t\tconst claudeAvailable = await detectClaudeCli()\n\t\tlogger.debug('Claude CLI availability check result', { claudeAvailable })\n\n\t\tif (!claudeAvailable) {\n\t\t\tlogger.error(\n\t\t\t\t\"Claude Code not detected. Please install it: npm install -g @anthropic-ai/claude-code\"\n\t\t\t)\n\t\t\tthrow new Error('Claude Code CLI is required for planning sessions')\n\t\t}\n\n\t\t// Load settings to detect configured issue provider and model\n\t\tconst settingsManager = new SettingsManager()\n\t\tconst settings = await settingsManager.loadSettings()\n\n\t\t// Detect if prompt is an issue number for decomposition mode\n\t\t// Uses shared matchIssueIdentifier() utility to identify issue identifiers:\n\t\t// - Numeric pattern: #123 or 123 (GitHub format)\n\t\t// - Project key pattern: ENG-123, PROJ-456 (requires at least 2 letters before dash)\n\t\tconst identifierMatch = prompt ? matchIssueIdentifier(prompt) : { isIssueIdentifier: false }\n\t\tconst looksLikeIssueIdentifier = identifierMatch.isIssueIdentifier\n\t\tlet decompositionContext: {\n\t\t\tidentifier: string\n\t\t\ttitle: string\n\t\t\tbody: string\n\t\t\tchildren?: ChildIssueResult[]\n\t\t\tdependencies?: DependenciesResult\n\t\t} | null = null\n\n\t\tconst provider = settings ? IssueTrackerFactory.getProviderName(settings) : 'github'\n\t\tconst issuePrefix = provider === 'github' ? '#' : ''\n\n\t\tif (prompt && looksLikeIssueIdentifier) {\n\t\t\t// Validate and fetch issue using issueTracker.detectInputType() pattern from StartCommand\n\t\t\tconst issueTracker = IssueTrackerFactory.create(settings)\n\n\t\t\tlogger.debug('Detected potential issue identifier, validating via issueTracker', { identifier: prompt })\n\n\t\t\t// Use detectInputType to validate the identifier exists (same pattern as StartCommand)\n\t\t\tconst detection = await issueTracker.detectInputType(prompt)\n\n\t\t\tif (detection.type === 'issue' && detection.identifier) {\n\t\t\t\t// Valid issue found - fetch full details for decomposition context\n\t\t\t\tconst issue = await issueTracker.fetchIssue(detection.identifier)\n\t\t\t\tdecompositionContext = {\n\t\t\t\t\tidentifier: String(issue.number),\n\t\t\t\t\ttitle: issue.title,\n\t\t\t\t\tbody: issue.body\n\t\t\t\t}\n\t\t\t\tlogger.info(chalk.dim(`Preparing to create a detailed plan for issue #${decompositionContext.identifier}: ${decompositionContext.title}`))\n\n\t\t\t\t// Fetch existing children and dependencies using MCP provider\n\t\t\t\t// This allows users to resume planning where they left off\n\t\t\t\ttry {\n\t\t\t\t\tconst mcpProvider = IssueManagementProviderFactory.create(provider as IssueProvider, settings ?? undefined)\n\n\t\t\t\t\t// Fetch child issues\n\t\t\t\t\tlogger.debug('Fetching child issues for decomposition context', { identifier: decompositionContext.identifier })\n\t\t\t\t\tconst children = await mcpProvider.getChildIssues({ number: decompositionContext.identifier })\n\t\t\t\t\tif (children.length > 0) {\n\t\t\t\t\t\tdecompositionContext.children = children\n\t\t\t\t\t\tlogger.debug('Found existing child issues', { count: children.length })\n\t\t\t\t\t}\n\n\t\t\t\t\t// Fetch dependencies (both directions)\n\t\t\t\t\tlogger.debug('Fetching dependencies for decomposition context', { identifier: decompositionContext.identifier })\n\t\t\t\t\tconst dependencies = await mcpProvider.getDependencies({\n\t\t\t\t\t\tnumber: decompositionContext.identifier,\n\t\t\t\t\t\tdirection: 'both'\n\t\t\t\t\t})\n\t\t\t\t\tif (dependencies.blocking.length > 0 || dependencies.blockedBy.length > 0) {\n\t\t\t\t\t\tdecompositionContext.dependencies = dependencies\n\t\t\t\t\t\tlogger.debug('Found existing dependencies', {\n\t\t\t\t\t\t\tblocking: dependencies.blocking.length,\n\t\t\t\t\t\t\tblockedBy: dependencies.blockedBy.length\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Log but don't fail - children/dependencies are optional context\n\t\t\t\t\tlogger.debug('Failed to fetch children/dependencies, continuing without them', {\n\t\t\t\t\t\terror: error instanceof Error ? error.message : 'Unknown error'\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Input matched issue pattern but issue not found - treat as regular prompt\n\t\t\t\tlogger.debug('Input matched issue pattern but issue not found, treating as planning topic', {\n\t\t\t\t\tidentifier: prompt,\n\t\t\t\t\tdetectionType: detection.type\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// Use CLI model if provided, otherwise use settings (plan.model), defaults to opus\n\t\tconst effectiveModel = model ?? settingsManager.getPlanModel(settings ?? undefined)\n\n\t\t// Get effective planner/reviewer (CLI > settings > default)\n\t\tconst effectivePlanner = normalizedPlanner ?? settingsManager.getPlanPlanner(settings ?? undefined)\n\t\tconst effectiveReviewer = normalizedReviewer ?? settingsManager.getPlanReviewer(settings ?? undefined)\n\n\t\tlogger.debug('Detected issue provider, model, planner, and reviewer', {\n\t\t\tprovider,\n\t\t\teffectiveModel,\n\t\t\teffectivePlanner,\n\t\t\teffectiveReviewer,\n\t\t})\n\n\t\t// Generate MCP config for issue management tools\n\t\t// This will throw if no git remote is configured - offer to run 'il init' as fallback\n\t\tlogger.debug('Generating MCP config for issue management')\n\t\tlet mcpConfig: Record<string, unknown>[]\n\t\ttry {\n\t\t\tmcpConfig = await generateIssueManagementMcpConfig(undefined, undefined, provider, settings ?? undefined)\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : 'Unknown error'\n\n\t\t\t// Check if running in interactive mode - offer to run init\n\t\t\tif (isInteractiveEnvironment()) {\n\t\t\t\tconst shouldRunInit = await promptConfirmation(\n\t\t\t\t\t\"No git repository or remote found. Would you like to run 'il init' to set up?\",\n\t\t\t\t\ttrue\n\t\t\t\t)\n\t\t\t\tif (shouldRunInit) {\n\t\t\t\t\t// Dynamically import and run InitCommand\n\t\t\t\t\tlogger.info(chalk.bold('Launching iloom init...'))\n\t\t\t\t\tconst { InitCommand } = await import('./init.js')\n\t\t\t\t\tconst initCommand = new InitCommand()\n\t\t\t\t\tawait initCommand.execute(\n\t\t\t\t\t\t'Help the user set up a GitHub repository or Linear project for this project so they can use issue management features. When complete tell the user they can exit to continue the planning session.'\n\t\t\t\t\t)\n\n\t\t\t\t\t// Retry MCP config generation after init\n\t\t\t\t\tlogger.info(chalk.bold('Retrying planning session setup...'))\n\t\t\t\t\ttry {\n\t\t\t\t\t\tmcpConfig = await generateIssueManagementMcpConfig(undefined, undefined, provider, settings ?? undefined)\n\t\t\t\t\t} catch (retryError) {\n\t\t\t\t\t\tconst retryMessage = retryError instanceof Error ? retryError.message : 'Unknown error'\n\t\t\t\t\t\tlogger.error(`Failed to generate MCP config: ${retryMessage}`)\n\t\t\t\t\t\tif (provider === 'github') {\n\t\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t\t'GitHub issue management requires a git repository with a GitHub remote configured.'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Cannot start planning session after init: ${retryMessage}. Ensure you are in a git repository with a GitHub remote configured.`\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t\t'Linear issue management requires LINEAR_API_TOKEN to be configured.'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Cannot start planning session after init: ${retryMessage}. Ensure LINEAR_API_TOKEN is configured in settings or environment.`\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// User declined init prompt - show provider-specific error messages\n\t\t\t\t\tlogger.error(`Failed to generate MCP config: ${message}`)\n\t\t\t\t\tif (provider === 'github') {\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t'GitHub issue management requires a git repository with a GitHub remote configured.'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot start planning session: ${message}. Ensure you are in a git repository with a GitHub remote configured.`\n\t\t\t\t\t\t)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t'Linear issue management requires LINEAR_API_TOKEN to be configured.'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot start planning session: ${message}. Ensure LINEAR_API_TOKEN is configured in settings or environment.`\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Non-interactive mode - show provider-specific error messages\n\t\t\t\tlogger.error(`Failed to generate MCP config: ${message}`)\n\t\t\t\tif (provider === 'github') {\n\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t'GitHub issue management requires a git repository with a GitHub remote configured.'\n\t\t\t\t\t)\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot start planning session: ${message}. Ensure you are in a git repository with a GitHub remote configured.`\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t'Linear issue management requires LINEAR_API_TOKEN to be configured.'\n\t\t\t\t\t)\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot start planning session: ${message}. Ensure LINEAR_API_TOKEN is configured in settings or environment.`\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlogger.debug('MCP config generated', {\n\t\t\tserverCount: mcpConfig.length,\n\t\t})\n\n\t\t// --- Auto-swarm harness lifecycle ---\n\t\tlet harness: HarnessServer | null = null\n\t\tlet externalHarness = false\n\t\tlet epicData: { epicIssueNumber: string; childIssues: number[] } | null = null\n\t\tconst controller = autoSwarm ? new AbortController() : null\n\t\tconst autoSwarmStartTime = autoSwarm ? Date.now() : null\n\t\tlet autoSwarmSuccess = false\n\t\tlet autoSwarmPhaseReached: 'plan' | 'start' | 'spin' = 'plan'\n\t\tlet autoSwarmFallbackToNormal = false\n\n\t\tif (autoSwarm) {\n\t\t\tconst autoSwarmSource = decompositionContext ? 'decomposition' : 'fresh'\n\t\t\ttry {\n\t\t\t\tTelemetryService.getInstance().track('auto_swarm.started', {\n\t\t\t\t\tsource: autoSwarmSource,\n\t\t\t\t\tplanner: effectivePlanner,\n\t\t\t\t})\n\t\t\t} catch (error) {\n\t\t\t\tlogger.debug(`Telemetry auto_swarm.started tracking failed: ${error instanceof Error ? error.message : error}`)\n\t\t\t}\n\n\t\t\t// 1. Force yolo mode\n\t\t\tyolo = true\n\n\t\t\t// 2. Check for external harness (e.g., VS Code extension provides its own socket)\n\t\t\tconst externalSocket = process.env.ILOOM_HARNESS_SOCKET\n\t\t\texternalHarness = !!externalSocket\n\n\t\t\tif (!externalSocket) {\n\t\t\t\t// 3. Create and start harness server\n\t\t\t\tharness = new HarnessServer()\n\t\t\t\tawait harness.start()\n\t\t\t}\n\n\t\t\tconst socketPath = externalSocket ?? harness?.path\n\t\t\tif (!socketPath) {\n\t\t\t\tthrow new Error('Unexpected: no harness socket path available')\n\t\t\t}\n\n\t\t\t// 4. Register \"done\" handler (only when we own the harness server)\n\t\t\tif (harness) {\n\t\t\t\tharness.registerHandler('done', (data) => {\n\t\t\t\t\tepicData = data as typeof epicData\n\t\t\t\t\tsetImmediate(() => { controller?.abort() })\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: 'instruction' as const,\n\t\t\t\t\t\tcontent: 'Planning complete. The auto-swarm pipeline will now create the epic workspace and launch swarm mode automatically.',\n\t\t\t\t\t}\n\t\t\t\t}, { idempotent: true })\n\t\t\t}\n\n\t\t\t// 5. Merge harness MCP config\n\t\t\tconst harnessMcpConfig = generateHarnessMcpConfig(socketPath)\n\t\t\tmcpConfig = [...mcpConfig, ...harnessMcpConfig]\n\t\t}\n\n\t\t// Detect VS Code mode\n\t\tconst isVscodeMode = process.env.ILOOM_VSCODE === '1'\n\t\tlogger.debug('VS Code mode detection', { isVscodeMode })\n\n\t\t// Compute template variables for multi-AI provider support\n\t\t// Generate USE_*_PLANNER and USE_*_REVIEWER flags dynamically\n\t\tconst providerFlags = PLANNER_PROVIDERS.reduce((acc, p) => ({\n\t\t\t...acc,\n\t\t\t[`USE_${p.toUpperCase()}_PLANNER`]: effectivePlanner === p,\n\t\t}), {} as Record<string, boolean>)\n\n\t\t// Add reviewer flags (excluding 'none')\n\t\t;(['claude', 'gemini', 'codex'] as const).forEach(p => {\n\t\t\tproviderFlags[`USE_${p.toUpperCase()}_REVIEWER`] = effectiveReviewer === p\n\t\t})\n\n\t\t// Get wave verification setting (default true)\n\t\tconst waveVerification = settingsManager.getPlanWaveVerification(settings ?? undefined)\n\n\t\t// Load plan prompt template with mode-specific variables\n\t\tlogger.debug('Loading plan prompt template')\n\t\tconst templateVariables: TemplateVariables = {\n\t\t\tIS_VSCODE_MODE: isVscodeMode,\n\t\t\tWAVE_VERIFICATION: waveVerification,\n\t\t\tEXISTING_ISSUE_MODE: !!decompositionContext,\n\t\t\tFRESH_PLANNING_MODE: !decompositionContext,\n\t\t\tPARENT_ISSUE_NUMBER: decompositionContext?.identifier,\n\t\t\tPARENT_ISSUE_TITLE: decompositionContext?.title,\n\t\t\tPARENT_ISSUE_BODY: decompositionContext?.body,\n\t\t\tPARENT_ISSUE_CHILDREN: decompositionContext?.children\n\t\t\t\t? formatChildIssues(decompositionContext.children, issuePrefix)\n\t\t\t\t: undefined,\n\t\t\tPARENT_ISSUE_DEPENDENCIES: decompositionContext?.dependencies\n\t\t\t\t? formatDependencies(decompositionContext.dependencies, issuePrefix)\n\t\t\t\t: undefined,\n\t\t\tPLANNER: effectivePlanner,\n\t\t\tREVIEWER: effectiveReviewer,\n\t\t\tHAS_REVIEWER: effectiveReviewer !== 'none',\n\t\t\tAUTO_SWARM_MODE: autoSwarm ?? false,\n\t\t\t...providerFlags,\n\t\t}\n\t\tconst architectPrompt = await this.templateManager.getPrompt('plan', templateVariables)\n\t\tlogger.debug('Plan prompt loaded', {\n\t\t\tpromptLength: architectPrompt.length,\n\t\t\tmode: decompositionContext ? 'decomposition' : 'fresh',\n\t\t})\n\n\t\t// Load analyzer agent for research delegation\n\t\tlet agents: Record<string, unknown> | undefined\n\t\ttry {\n\t\t\tagents = await this.agentManager.loadAndPrepare(\n\t\t\t\tsettings ?? undefined,\n\t\t\t\ttemplateVariables,\n\t\t\t\t['iloom-issue-analyzer.md']\n\t\t\t)\n\t\t} catch (error) {\n\t\t\tlogger.warn(`Failed to load agents: ${error instanceof Error ? error.message : 'Unknown error'}`)\n\t\t}\n\n\t\t// Determine if we're in print/headless mode\n\t\tconst isHeadless = printOptions?.print ?? false\n\n\t\t// Build Claude options\n\t\tconst claudeOptions: Parameters<typeof launchClaude>[1] = {\n\t\t\tmodel: effectiveModel,\n\t\t\theadless: isHeadless,\n\t\t\tappendSystemPrompt: architectPrompt,\n\t\t\tmcpConfig,\n\t\t\taddDir: process.cwd(),\n\t\t\t...(agents && { agents }),\n\t\t}\n\n\t\t// Add output format and verbose options if provided (print mode only)\n\t\tif (printOptions?.outputFormat !== undefined) {\n\t\t\tclaudeOptions.outputFormat = printOptions.outputFormat\n\t\t}\n\t\tif (printOptions?.verbose !== undefined) {\n\t\t\tclaudeOptions.verbose = printOptions.verbose\n\t\t}\n\n\t\t// Add JSON mode if specified (requires print mode)\n\t\tif (printOptions?.json) {\n\t\t\tclaudeOptions.jsonMode = 'json'\n\t\t\tclaudeOptions.outputFormat = 'stream-json' // Force stream-json for parsing\n\t\t} else if (printOptions?.jsonStream) {\n\t\t\tclaudeOptions.jsonMode = 'stream'\n\t\t\tclaudeOptions.outputFormat = 'stream-json' // Force stream-json for streaming\n\t\t}\n\n\t\t// Force yolo mode when print mode is enabled (headless execution requires autonomous mode)\n\t\tconst effectiveYolo = (yolo ?? false) || isHeadless\n\n\t\t// Handle --yolo mode\n\t\tif (effectiveYolo) {\n\t\t\t// Only require prompt for explicit --yolo flag, not for print mode auto-yolo\n\t\t\tif (yolo && !prompt) {\n\t\t\t\tthrow new Error('--yolo requires a prompt or issue identifier (e.g., il plan --yolo \"add gitlab support\" or il plan --yolo 42)')\n\t\t\t}\n\t\t\tlogger.warn(\n\t\t\t\t'YOLO mode enabled - Claude will skip permission prompts and proceed autonomously. This could destroy important data or make irreversible changes. Proceeding means you accept this risk.'\n\t\t\t)\n\t\t}\n\n\t\tlogger.debug('Launching Claude with options', {\n\t\t\toptionKeys: Object.keys(claudeOptions),\n\t\t\theadless: claudeOptions.headless,\n\t\t\thasSystemPrompt: !!claudeOptions.appendSystemPrompt,\n\t\t\taddDir: claudeOptions.addDir,\n\t\t\tyolo,\n\t\t\tprint: isHeadless,\n\t\t})\n\n\t\t// Pre-accept Claude Code trust for the working directory\n\t\ttry {\n\t\t\tawait preAcceptClaudeTrust(process.cwd())\n\t\t} catch (error) {\n\t\t\tlogger.warn(`Failed to pre-accept Claude trust: ${error instanceof Error ? error.message : String(error)}`)\n\t\t}\n\n\t\t// Launch Claude in interactive mode\n\t\t// Construct initial message based on mode\n\t\tlet initialMessage: string\n\t\tif (decompositionContext) {\n\t\t\t// Issue decomposition mode - provide context about what to decompose\n\t\t\tinitialMessage = `Break down issue #${decompositionContext.identifier} into child issues.`\n\t\t} else if (prompt) {\n\t\t\t// Fresh planning with user-provided topic\n\t\t\tinitialMessage = prompt\n\t\t} else {\n\t\t\t// Interactive mode - no topic provided\n\t\t\tinitialMessage = 'Help me plan a feature or decompose work into issues.'\n\t\t}\n\n\t\t// Apply yolo mode wrapper if enabled (includes print mode)\n\t\tif (effectiveYolo) {\n\t\t\tinitialMessage = `[AUTONOMOUS MODE]\nProceed through the flow without requiring user interaction. Make and document your assumptions and proceed to create the epic and child issues and dependencies if necessary. This guidance supersedes all previous guidance.\n\n[TOPIC]\n${initialMessage}`\n\t\t}\n\n\t\ttry {\n\t\t\tconst claudeResult = await launchClaude(initialMessage, {\n\t\t\t\t...claudeOptions,\n\t\t\t\t...(effectiveYolo && { permissionMode: 'bypassPermissions' as const }),\n\t\t\t\t...(controller && { signal: controller.signal }),\n\t\t\t})\n\n\t\t\t// Check auto-swarm outcome\n\t\t\tif (autoSwarm) {\n\t\t\t\t// When an external harness (e.g., VS Code) owns the socket, it handles\n\t\t\t\t// the \"done\" signal and manages the start/spin pipeline itself.\n\t\t\t\t// The CLI just exits cleanly after the plan phase.\n\t\t\t\tif (externalHarness) {\n\t\t\t\t\tlogger.info(chalk.green('Planning session ended. External harness will manage the pipeline.'))\n\t\t\t\t\tautoSwarmSuccess = true\n\t\t\t\t\tautoSwarmPhaseReached = 'plan'\n\t\t\t\t} else if (!epicData) {\n\t\t\t\t\tthrow new Error('Plan phase exited without completing. The Architect did not signal done.')\n\t\t\t\t} else {\n\t\t\t\t\t// Cast required because TypeScript cannot narrow let variables mutated in closures.\n\t\t\t\t\t// Defensively default childIssues — the data comes from AI-generated signal payloads.\n\t\t\t\t\tconst resolvedEpicData = epicData as { epicIssueNumber: string; childIssues?: number[] }\n\t\t\t\t\tconst epicIssueNumber = resolvedEpicData.epicIssueNumber\n\t\t\t\t\tconst childIssues = resolvedEpicData.childIssues ?? []\n\t\t\t\t\tlogger.info(chalk.green(`Planning complete. Epic issue: #${epicIssueNumber}`))\n\t\t\t\t\tautoSwarmFallbackToNormal = childIssues.length === 0\n\n\t\t\t\t\tconst startCommand = new StartCommand(IssueTrackerFactory.create(settings ?? {}))\n\n\t\t\t\t\tif (childIssues.length === 0) {\n\t\t\t\t\t\t// Zero-children fallback: normal (non-epic) autonomous loom\n\t\t\t\t\t\tlogger.info('No child issues created. Starting as a normal autonomous loom.')\n\t\t\t\t\t\tlet startResult\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tstartResult = await startCommand.execute({\n\t\t\t\t\t\t\t\tidentifier: String(epicIssueNumber),\n\t\t\t\t\t\t\t\toptions: { oneShot: 'bypassPermissions', json: true, claude: false, code: false, devServer: false, terminal: false },\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t} catch (startError) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Auto-swarm: failed to create epic workspace. ${startError instanceof Error ? startError.message : String(startError)}`\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst epicWorktreePath = startResult?.path\n\t\t\t\t\t\tif (!epicWorktreePath) {\n\t\t\t\t\t\t\tthrow new Error('Auto-swarm: StartCommand did not return a workspace path.')\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst igniteCommand = new IgniteCommand()\n\t\t\t\t\t\tawait igniteCommand.execute('bypassPermissions', undefined, undefined, epicWorktreePath)\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Epic mode: start + spin with swarm\n\t\t\t\t\t\tlet startResult\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tstartResult = await startCommand.execute({\n\t\t\t\t\t\t\t\tidentifier: String(epicIssueNumber),\n\t\t\t\t\t\t\t\toptions: { epic: true, json: true, oneShot: 'bypassPermissions', claude: false, code: false, devServer: false, terminal: false },\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t} catch (startError) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Auto-swarm: failed to create epic workspace. ${startError instanceof Error ? startError.message : String(startError)}`\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst epicWorktreePath = startResult?.path\n\t\t\t\t\t\tif (!epicWorktreePath) {\n\t\t\t\t\t\t\tthrow new Error('Auto-swarm: StartCommand did not return a workspace path.')\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst igniteCommand = new IgniteCommand()\n\t\t\t\t\t\tawait igniteCommand.execute('bypassPermissions', undefined, undefined, epicWorktreePath)\n\t\t\t\t\t}\n\n\t\t\t\t\tautoSwarmSuccess = true\n\t\t\t\t\tautoSwarmPhaseReached = 'spin'\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Track epic.planned telemetry for decomposition sessions\n\t\t\tif (decompositionContext) {\n\t\t\t\ttry {\n\t\t\t\t\tconst mcpProv = IssueManagementProviderFactory.create(provider as IssueProvider, settings ?? undefined)\n\t\t\t\t\tconst children = await mcpProv.getChildIssues({ number: decompositionContext.identifier })\n\t\t\t\t\tTelemetryService.getInstance().track('epic.planned', {\n\t\t\t\t\t\tchild_count: children.length,\n\t\t\t\t\t\ttracker: provider,\n\t\t\t\t\t})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.debug(`Telemetry epic.planned tracking failed: ${error instanceof Error ? error.message : error}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Output final JSON for --json mode (--json-stream already streamed to stdout)\n\t\t\tif (printOptions?.json) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(JSON.stringify({\n\t\t\t\t\tsuccess: true,\n\t\t\t\t\toutput: claudeResult ?? ''\n\t\t\t\t}))\n\t\t\t}\n\n\t\t\tlogger.debug('Claude session completed')\n\t\t\tlogger.info(chalk.green('Planning session ended.'))\n\t\t} finally {\n\t\t\tif (harness) {\n\t\t\t\tawait harness.stop()\n\t\t\t}\n\n\t\t\tif (autoSwarm && autoSwarmStartTime !== null) {\n\t\t\t\tconst durationMinutes = (Date.now() - autoSwarmStartTime) / 60000\n\t\t\t\tconst autoSwarmSource = decompositionContext ? 'decomposition' : 'fresh'\n\t\t\t\tconst resolvedEpicData = epicData as { epicIssueNumber: string; childIssues: number[] } | null\n\t\t\t\ttry {\n\t\t\t\t\tTelemetryService.getInstance().track('auto_swarm.completed', {\n\t\t\t\t\t\tsource: autoSwarmSource,\n\t\t\t\t\t\tsuccess: autoSwarmSuccess,\n\t\t\t\t\t\tchild_count: resolvedEpicData?.childIssues.length ?? 0,\n\t\t\t\t\t\tduration_minutes: Math.round(durationMinutes * 10) / 10,\n\t\t\t\t\t\tphase_reached: autoSwarmPhaseReached,\n\t\t\t\t\t\tfallback_to_normal: autoSwarmFallbackToNormal,\n\t\t\t\t\t})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.debug(`Telemetry auto_swarm.completed tracking failed: ${error instanceof Error ? error.message : error}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","import net from 'net'\nimport fs from 'fs'\nimport os from 'os'\nimport path from 'path'\nimport { randomUUID } from 'crypto'\nimport { logger } from '../utils/logger.js'\n\nexport interface HarnessMessage {\n\ttype: string\n\tdata?: unknown\n}\n\nexport interface HarnessResponse {\n\ttype: 'instruction' | 'acknowledged' | 'error'\n\tcontent?: string\n}\n\nexport type HarnessHandler = (data: unknown) => HarnessResponse | Promise<HarnessResponse>\n\nexport interface HarnessServerOptions {\n\tsocketPath?: string\n}\n\nexport class HarnessServer {\n\tprivate server: net.Server | null = null\n\tprivate readonly socketPath: string\n\tprivate readonly handlers: Map<string, HarnessHandler> = new Map()\n\tprivate readonly idempotentTypes: Set<string> = new Set()\n\tprivate readonly handledTypes: Set<string> = new Set()\n\tprivate readonly connections: Set<net.Socket> = new Set()\n\tprivate readonly waiters: Map<string, Array<(data: unknown) => void>> = new Map()\n\tprivate readonly boundSignalHandler: (signal: NodeJS.Signals) => void\n\n\tconstructor(options: HarnessServerOptions = {}) {\n\t\tthis.socketPath =\n\t\t\toptions.socketPath ??\n\t\t\tpath.join(os.tmpdir(), `iloom-harness-${randomUUID()}.sock`)\n\t\tthis.boundSignalHandler = (signal: NodeJS.Signals): void => {\n\t\t\tvoid this.stop().finally(() => {\n\t\t\t\t// Re-raise so the default handler terminates the process\n\t\t\t\tprocess.kill(process.pid, signal)\n\t\t\t})\n\t\t}\n\t}\n\n\tget path(): string {\n\t\treturn this.socketPath\n\t}\n\n\tregisterHandler(type: string, handler: HarnessHandler, options?: { idempotent?: boolean }): void {\n\t\tthis.handlers.set(type, handler)\n\t\tif (options?.idempotent) {\n\t\t\tthis.idempotentTypes.add(type)\n\t\t}\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.server !== null) {\n\t\t\tthrow new Error('HarnessServer is already started')\n\t\t}\n\n\t\t// Remove stale socket file from crashed previous runs\n\t\tfs.rmSync(this.socketPath, { force: true })\n\n\t\tconst server = net.createServer((socket) => {\n\t\t\tthis.handleConnection(socket)\n\t\t})\n\t\tthis.server = server\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tserver.listen(this.socketPath, () => resolve())\n\t\t\tserver.once('error', reject)\n\t\t})\n\n\t\t// Set socket to owner read/write only\n\t\tfs.chmodSync(this.socketPath, 0o600)\n\n\t\t// Register signal handlers for cleanup on process exit\n\t\tprocess.on('SIGINT', this.boundSignalHandler)\n\t\tprocess.on('SIGTERM', this.boundSignalHandler)\n\n\t\tlogger.debug(`HarnessServer listening on ${this.socketPath}`)\n\t}\n\n\tasync stop(): Promise<void> {\n\t\tif (this.server === null) {\n\t\t\treturn\n\t\t}\n\n\t\t// Destroy all active connections so the server can close\n\t\tfor (const socket of this.connections) {\n\t\t\tsocket.destroy()\n\t\t}\n\t\tthis.connections.clear()\n\n\t\t// Close the server (set to null first for idempotency guard)\n\t\tconst serverToClose = this.server\n\t\tthis.server = null\n\n\t\ttry {\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tserverToClose.close((err) => {\n\t\t\t\t\tif (err) reject(err)\n\t\t\t\t\telse resolve()\n\t\t\t\t})\n\t\t\t})\n\t\t} finally {\n\t\t\t// Cleanup must run even if server.close() rejects\n\t\t\tfs.rmSync(this.socketPath, { force: true })\n\t\t\tthis.waiters.clear()\n\t\t\tprocess.off('SIGINT', this.boundSignalHandler)\n\t\t\tprocess.off('SIGTERM', this.boundSignalHandler)\n\t\t\tlogger.debug('HarnessServer stopped')\n\t\t}\n\t}\n\n\twaitFor(type: string): Promise<unknown> {\n\t\treturn new Promise<unknown>((resolve) => {\n\t\t\tconst resolvers = this.waiters.get(type) ?? []\n\t\t\tresolvers.push(resolve)\n\t\t\tthis.waiters.set(type, resolvers)\n\t\t})\n\t}\n\n\tprivate handleConnection(socket: net.Socket): void {\n\t\tthis.connections.add(socket)\n\t\tlet buffer = ''\n\t\tconst MAX_BUFFER_SIZE = 1024 * 1024 // 1MB\n\n\t\tsocket.on('data', (chunk: Buffer) => {\n\t\t\tbuffer += chunk.toString()\n\t\t\tif (buffer.length > MAX_BUFFER_SIZE) {\n\t\t\t\tsocket.destroy(new Error('Payload too large'))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst lines = buffer.split('\\n')\n\t\t\t// Keep the last potentially incomplete segment in the buffer\n\t\t\tbuffer = lines.pop() ?? ''\n\t\t\tfor (const line of lines) {\n\t\t\t\tconst trimmed = line.trim()\n\t\t\t\tif (trimmed) {\n\t\t\t\t\tvoid this.processMessage(trimmed, socket)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\tsocket.on('close', () => {\n\t\t\tthis.connections.delete(socket)\n\t\t})\n\n\t\tsocket.on('error', (err: Error) => {\n\t\t\tlogger.debug(`HarnessServer socket error: ${err.message}`)\n\t\t})\n\t}\n\n\tprivate async processMessage(raw: string, socket: net.Socket): Promise<void> {\n\t\tlet message: HarnessMessage\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(raw)\n\t\t\tif (!parsed || typeof parsed !== 'object' || typeof (parsed as Record<string, unknown>).type !== 'string') {\n\t\t\t\tthis.sendResponse(socket, { type: 'error', content: 'Invalid message format' })\n\t\t\t\treturn\n\t\t\t}\n\t\t\tmessage = parsed as HarnessMessage\n\t\t} catch {\n\t\t\tthis.sendResponse(socket, { type: 'error', content: 'Malformed JSON' })\n\t\t\treturn\n\t\t}\n\n\t\t// Resolve any waiters registered for this message type\n\t\tconst resolvers = this.waiters.get(message.type)\n\t\tif (resolvers && resolvers.length > 0) {\n\t\t\tthis.waiters.delete(message.type)\n\t\t\tfor (const resolve of resolvers) {\n\t\t\t\tresolve(message.data)\n\t\t\t}\n\t\t}\n\n\t\t// Idempotent handling: only applies to handlers registered with { idempotent: true }\n\t\tif (this.idempotentTypes.has(message.type) && this.handledTypes.has(message.type)) {\n\t\t\tthis.sendResponse(socket, { type: 'acknowledged' })\n\t\t\treturn\n\t\t}\n\n\t\t// No handler registered for this type\n\t\tconst handler = this.handlers.get(message.type)\n\t\tif (!handler) {\n\t\t\tthis.sendResponse(socket, {\n\t\t\t\ttype: 'error',\n\t\t\t\tcontent: `No handler registered for type: ${message.type}`,\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\t// Mark as handled before calling handler (only for idempotent types)\n\t\tif (this.idempotentTypes.has(message.type)) {\n\t\t\tthis.handledTypes.add(message.type)\n\t\t}\n\t\tconst response = await handler(message.data)\n\t\tthis.sendResponse(socket, response)\n\t}\n\n\tprivate sendResponse(socket: net.Socket, response: HarnessResponse): void {\n\t\tsocket.write(JSON.stringify(response) + '\\n')\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,WAAW;;;ACHlB,OAAO,SAAS;AAChB,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,kBAAkB;AAmBpB,IAAM,gBAAN,MAAoB;AAAA,EAU1B,YAAY,UAAgC,CAAC,GAAG;AAThD,SAAQ,SAA4B;AAEpC,SAAiB,WAAwC,oBAAI,IAAI;AACjE,SAAiB,kBAA+B,oBAAI,IAAI;AACxD,SAAiB,eAA4B,oBAAI,IAAI;AACrD,SAAiB,cAA+B,oBAAI,IAAI;AACxD,SAAiB,UAAuD,oBAAI,IAAI;AAI/E,SAAK,aACJ,QAAQ,cACR,KAAK,KAAK,GAAG,OAAO,GAAG,iBAAiB,WAAW,CAAC,OAAO;AAC5D,SAAK,qBAAqB,CAAC,WAAiC;AAC3D,WAAK,KAAK,KAAK,EAAE,QAAQ,MAAM;AAE9B,gBAAQ,KAAK,QAAQ,KAAK,MAAM;AAAA,MACjC,CAAC;AAAA,IACF;AAAA,EACD;AAAA,EAEA,IAAI,OAAe;AAClB,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,gBAAgB,MAAc,SAAyB,SAA0C;AAChG,SAAK,SAAS,IAAI,MAAM,OAAO;AAC/B,QAAI,mCAAS,YAAY;AACxB,WAAK,gBAAgB,IAAI,IAAI;AAAA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AA,MACD;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
@@ -14,7 +14,7 @@ Look for available Gemini MCP tools (typically named with "gemini" in the tool n
14
14
  - Brainstorming and creative exploration
15
15
  - Targeted queries and analysis
16
16
 
17
- **Workflow**: Use these tools during Phase 1 (Understanding) and Phase 2 (Design Exploration) to gather multiple perspectives. Synthesize Gemini's responses into your plan.
17
+ **Workflow**: Use these tools during Phase 1 (Understanding) and Phase 2 (Design Exploration) to gather multiple perspectives. Delegate deep research to the `iloom-issue-analyzer` agent (see Phase 1) and use Gemini for supplementary brainstorming. Synthesize findings into your plan.
18
18
 
19
19
  **Fallback**: If Gemini MCP tools are unavailable (error responses), continue using your own capabilities for planning.
20
20
  {{/if}}
@@ -26,7 +26,7 @@ You have access to Codex AI through MCP tools for code-aware planning.
26
26
  Look for available Codex MCP tools (typically named with "codex" in the tool name) for:
27
27
  - Code-focused analysis and implementation suggestions
28
28
 
29
- **Workflow**: Use this tool during Phase 2 (Design Exploration) and Phase 3 (Issue Decomposition) to get code-specific insights.
29
+ **Workflow**: Use this tool during Phase 2 (Design Exploration) and Phase 3 (Issue Decomposition) for code-specific insights. Delegate deep research to the `iloom-issue-analyzer` agent (see Phase 1) and use Codex for supplementary code analysis.
30
30
 
31
31
  **Fallback**: If Codex MCP tool is unavailable (error response), continue using your own capabilities for planning.
32
32
  {{/if}}
@@ -35,9 +35,9 @@ Look for available Codex MCP tools (typically named with "codex" in the tool nam
35
35
  ### Default Planning (Claude)
36
36
 
37
37
  You are the primary planner for this session. Use your capabilities to:
38
- - Gather context by exploring the codebase with Read, Glob, Grep tools
39
- - Use Task subagents for comprehensive research when needed
40
- - Synthesize information into a coherent implementation plan
38
+ - Delegate deep research to the `iloom-issue-analyzer` agent (see Phase 1 Research Phase) for thorough problem space, codebase, and third-party dependency understanding
39
+ - Use Task subagents for supplementary research tasks, keeping the main conversation focused on planning decisions
40
+ - Synthesize findings into a coherent implementation plan
41
41
  {{/unless}}{{/unless}}
42
42
 
43
43
  {{#if HAS_REVIEWER}}
@@ -154,7 +154,32 @@ Each issue you help create should represent a single, focused unit of work that:
154
154
 
155
155
  ### Phase 1: Understanding (Brainstorming)
156
156
 
157
- Start by understanding the problem space. Ask clarifying questions ONE AT A TIME to prevent cognitive overload.
157
+ Before asking questions, conduct structured research to build a thorough understanding. Research informs better questions and prevents decomposition errors later.
158
+
159
+ #### Research Phase
160
+
161
+ **Delegate research to the `iloom-issue-analyzer` agent** to build thorough understanding before decomposing work.
162
+
163
+ Launch the analyzer as a Task subagent in foreground mode (wait for completion since you need the results before proceeding):
164
+
165
+ ```
166
+ Task(
167
+ subagent_type: "iloom-issue-analyzer",
168
+ prompt: "Analyze [issue description/context]. Focus on: problem space understanding, third-party dependencies, codebase entry points and patterns, cross-cutting concerns, and edge cases. Do NOT create issue comments - just return your findings."
169
+ )
170
+ ```
171
+
172
+ The analyzer agent has a comprehensive research framework covering:
173
+ - Problem space and domain understanding
174
+ - Third-party dependency research (Context7, WebSearch, ToolSearch)
175
+ - Systematic codebase exploration (entry points, dependency mapping, pattern recognition)
176
+ - Cross-cutting concern analysis
177
+
178
+ Wait for the analyzer to complete, then use its findings to inform sharper clarifying questions and better decomposition decisions.
179
+
180
+ ---
181
+
182
+ After research is complete, ask clarifying questions ONE AT A TIME to prevent cognitive overload. Your research findings should inform sharper, more specific questions.
158
183
 
159
184
  **Using the AskUserQuestion Tool:**
160
185
  When asking clarifying questions, use the AskUserQuestion tool to present options to the user. This provides a better UX with structured choices:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iloom/cli",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Control plane for maintaining alignment between you and Claude Code as you work across multiple issues using isolated environments, visible context, and multi-agent workflows to scale understanding, not just output",
5
5
  "keywords": [
6
6
  "ai",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/first-run-setup.ts","../src/commands/start.ts"],"sourcesContent":["import { existsSync } from 'fs'\nimport { readFile } from 'fs/promises'\nimport path from 'path'\nimport chalk from 'chalk'\nimport { logger } from './logger.js'\nimport { FirstRunManager } from './FirstRunManager.js'\nimport { getRepoRoot } from './git.js'\nimport { promptConfirmation, waitForKeypress } from './prompt.js'\n\n/**\n * Get the project root path for first-run tracking\n * Uses git repo root if available, otherwise falls back to cwd\n * This ensures consistent path resolution regardless of where the CLI is run from\n */\nasync function getProjectRoot(): Promise<string> {\n\tconst repoRoot = await getRepoRoot()\n\tif (repoRoot) {\n\t\tlogger.debug(`getProjectRoot: Using git repo root: ${repoRoot}`)\n\t\treturn repoRoot\n\t}\n\tconst cwd = process.cwd()\n\tlogger.debug(`getProjectRoot: Not in git repo, using cwd: ${cwd}`)\n\treturn cwd\n}\n\n/**\n * Check if project needs first-run setup\n * Returns true if:\n * 1. Project is not tracked as configured globally AND\n * 2. .iloom directory is missing or settings files are empty\n *\n * Uses git repo root for path resolution to ensure consistent behavior\n * regardless of whether the CLI is run from a subdirectory or worktree\n */\nexport async function needsFirstRunSetup(): Promise<boolean> {\n\tconst projectRoot = await getProjectRoot()\n\tconst firstRunManager = new FirstRunManager()\n\n\t// Check if project is tracked as configured globally\n\tconst isConfigured = await firstRunManager.isProjectConfigured(projectRoot)\n\tif (isConfigured) {\n\t\tlogger.debug('needsFirstRunSetup: Project is tracked as configured globally')\n\t\treturn false\n\t}\n\n\tconst iloomDir = path.join(projectRoot, '.iloom')\n\n\t// Check if .iloom directory exists\n\tif (!existsSync(iloomDir)) {\n\t\treturn true\n\t}\n\n\t// Check if either settings file has meaningful content\n\tconst settingsPath = path.join(iloomDir, 'settings.json')\n\tconst settingsLocalPath = path.join(iloomDir, 'settings.local.json')\n\n\tconst hasSettings = await hasNonEmptySettings(settingsPath)\n\tconst hasLocalSettings = await hasNonEmptySettings(settingsLocalPath)\n\n\treturn !hasSettings && !hasLocalSettings\n}\n\nasync function hasNonEmptySettings(filePath: string): Promise<boolean> {\n\tif (!existsSync(filePath)) return false\n\ttry {\n\t\tconst content = await readFile(filePath, 'utf-8')\n\t\tconst parsed = JSON.parse(content)\n\t\treturn Object.keys(parsed).length > 0\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/**\n * Display default configuration values in a formatted box\n */\nfunction displayDefaultsBox(): void {\n\tlogger.info(chalk.bold('Default Configuration:'))\n\tlogger.info('')\n\tlogger.info(` ${chalk.cyan('Main Branch:')} main`)\n\tlogger.info(` ${chalk.cyan('IDE:')} vscode`)\n\tlogger.info(` ${chalk.cyan('Issue Tracker:')} GitHub Issues`)\n\tlogger.info(` ${chalk.cyan('Merge Mode:')} local ${chalk.dim('(merge locally)')}`)\n\tlogger.info(` ${chalk.cyan('Base Port:')} 3000`)\n}\n\n/**\n * Launch interactive first-run setup via InitCommand\n * Shows defaults first, allows quick acceptance or full wizard\n */\nexport async function launchFirstRunSetup(): Promise<void> {\n\tlogger.info('First-time project setup detected.')\n\tlogger.info('')\n\n\t// Display the defaults\n\tdisplayDefaultsBox()\n\n\tlogger.info('')\n\n\t// Import prompt utility\n\n\t// Ask if defaults are OK (default to Yes)\n\tconst acceptDefaults = await promptConfirmation(\n\t\t'Are these defaults OK?',\n\t\ttrue // default to true, so Enter accepts\n\t)\n\n\tif (acceptDefaults) {\n\t\t// User accepted defaults - just mark as configured\n\t\tconst projectRoot = await getProjectRoot()\n\t\tconst firstRunManager = new FirstRunManager()\n\t\tawait firstRunManager.markProjectAsConfigured(projectRoot)\n\t\tlogger.info(chalk.green('Configuration complete! Using defaults.'))\n\t\tlogger.info('You can run `il init` anytime to customize settings.')\n\t\treturn\n\t}\n\n\t// User declined - launch full wizard\n\tlogger.info('')\n\tlogger.info('iloom will now launch an interactive configuration session with Claude.')\n\n\tawait waitForKeypress('Press any key to start configuration...')\n\n\tconst { InitCommand } = await import('../commands/init.js')\n\tconst initCommand = new InitCommand()\n\tawait initCommand.execute(\n\t\t'Help me configure iloom settings for this project. This is my first time using iloom here. Note: Your iloom command will execute once we are done with configuration changes.'\n\t)\n\t// Note: InitCommand.execute() now handles markProjectAsConfigured() internally\n\t// when the guided init completes successfully\n\n\tlogger.info('Configuration complete! Continuing with your original command...')\n}\n","import path from 'path'\nimport { getLogger } from '../utils/logger-context.js'\nimport type { IssueTracker } from '../lib/IssueTracker.js'\nimport { GitHubService } from '../lib/GitHubService.js'\nimport { LoomManager } from '../lib/LoomManager.js'\nimport { DefaultBranchNamingService } from '../lib/BranchNamingService.js'\nimport { GitWorktreeManager } from '../lib/GitWorktreeManager.js'\nimport { EnvironmentManager } from '../lib/EnvironmentManager.js'\nimport { ClaudeContextManager } from '../lib/ClaudeContextManager.js'\nimport { ProjectCapabilityDetector } from '../lib/ProjectCapabilityDetector.js'\nimport { CLIIsolationManager } from '../lib/CLIIsolationManager.js'\nimport { SettingsManager } from '../lib/SettingsManager.js'\nimport { AgentManager } from '../lib/AgentManager.js'\nimport { DatabaseManager } from '../lib/DatabaseManager.js'\nimport { findMainWorktreePathWithSettings } from '../utils/git.js'\nimport { matchIssueIdentifier } from '../utils/IdentifierParser.js'\nimport { loadEnvIntoProcess } from '../utils/env.js'\nimport { extractSettingsOverrides } from '../utils/cli-overrides.js'\nimport { createNeonProviderFromSettings } from '../utils/neon-helpers.js'\nimport { getConfiguredRepoFromSettings, hasMultipleRemotes } from '../utils/remote.js'\nimport { capitalizeFirstLetter } from '../utils/text.js'\nimport type { StartOptions, StartResult } from '../types/index.js'\nimport { fetchChildIssues, fetchChildIssueDetails } from '../utils/list-children.js'\nimport { buildDependencyMap } from '../utils/dependency-map.js'\nimport { IssueTrackerFactory } from '../lib/IssueTrackerFactory.js'\nimport { launchFirstRunSetup, needsFirstRunSetup } from '../utils/first-run-setup.js'\nimport { isInteractiveEnvironment, promptConfirmation } from '../utils/prompt.js'\nimport { TelemetryService } from '../lib/TelemetryService.js'\nimport type { LoomCreatedProperties } from '../types/telemetry.js'\nimport { resolveRecapFilePath, readRecapFile, writeRecapFile } from '../utils/mcp.js'\n\nexport interface StartCommandInput {\n\tidentifier: string\n\toptions: StartOptions\n}\n\nexport interface ParsedInput {\n\ttype: 'issue' | 'pr' | 'branch' | 'description' | 'epic'\n\tnumber?: string | number\n\tbranchName?: string\n\toriginalInput: string\n}\n\nexport class StartCommand {\n\tprivate issueTracker: IssueTracker\n\tprivate loomManager: LoomManager | null = null\n\tprivate settingsManager: SettingsManager\n\tprivate providedLoomManager: LoomManager | undefined\n\tprivate githubService: GitHubService | null = null\n\n\tconstructor(\n\t\tissueTracker: IssueTracker,\n\t\tloomManager?: LoomManager,\n\t\t_agentManager?: AgentManager, // Kept for API compatibility\n\t\tsettingsManager?: SettingsManager\n\t) {\n\t\tthis.issueTracker = issueTracker\n\t\tthis.settingsManager = settingsManager ?? new SettingsManager()\n\t\t// Store provided LoomManager for testing, but don't initialize yet\n\t\tthis.providedLoomManager = loomManager\n\n\t\t// Load environment variables first\n\t\tconst envResult = loadEnvIntoProcess()\n\t\tif (envResult.error) {\n\t\t\tgetLogger().debug(`Environment loading warning: ${envResult.error.message}`)\n\t\t}\n\t\tif (envResult.parsed) {\n\t\t\tgetLogger().debug(`Loaded ${Object.keys(envResult.parsed).length} environment variables`)\n\t\t}\n\t}\n\n\t/**\n\t * Get or create a GitHubService instance for PR operations\n\t * Used when the configured issue tracker doesn't support PRs (e.g., Linear)\n\t */\n\tprivate getGitHubService(): GitHubService {\n\t\tthis.githubService ??= new GitHubService()\n\t\treturn this.githubService\n\t}\n\n\t/**\n\t * Initialize LoomManager with the main worktree path\n\t * Uses lazy initialization to ensure we have the correct path\n\t */\n\tprivate async initializeLoomManager(): Promise<LoomManager> {\n\t\tif (this.loomManager) {\n\t\t\treturn this.loomManager\n\t\t}\n\n\t\tif (this.providedLoomManager) {\n\t\t\tthis.loomManager = this.providedLoomManager\n\t\t\treturn this.loomManager\n\t\t}\n\n\t\t// Find main worktree path\n\t\tconst mainWorktreePath = await findMainWorktreePathWithSettings()\n\n\t\t// Load settings to get database configuration\n\t\tconst settings = await this.settingsManager.loadSettings()\n\n\t\t// Create DatabaseManager with NeonProvider and EnvironmentManager\n\t\tconst environmentManager = new EnvironmentManager()\n\t\tconst neonProvider = createNeonProviderFromSettings(settings)\n\t\tconst databaseUrlEnvVarName = settings.capabilities?.database?.databaseUrlEnvVarName ?? 'DATABASE_URL'\n\n\t\tconst databaseManager = new DatabaseManager(neonProvider, environmentManager, databaseUrlEnvVarName)\n\n\t\t// Create BranchNamingService (defaults to Claude-based strategy)\n\t\tconst branchNaming = new DefaultBranchNamingService({ useClaude: true })\n\n\t\tthis.loomManager = new LoomManager(\n\t\t\tnew GitWorktreeManager(mainWorktreePath),\n\t\t\tthis.issueTracker,\n\t\t\tbranchNaming, // Add branch naming service\n\t\t\tenvironmentManager, // Reuse same instance\n\t\t\tnew ClaudeContextManager(),\n\t\t\tnew ProjectCapabilityDetector(),\n\t\t\tnew CLIIsolationManager(),\n\t\t\tthis.settingsManager, // Use same instance with CLI overrides\n\t\t\tdatabaseManager // Add database manager\n\t\t)\n\n\t\treturn this.loomManager\n\t}\n\n\t/**\n\t * Main entry point for the start command\n\t */\n\tpublic async execute(input: StartCommandInput): Promise<StartResult | void> {\n\t\tconst isJsonMode = input.options.json === true\n\n\t\t// Handle --create-only flag: disable all launch components\n\t\tif (input.options.createOnly) {\n\t\t\tinput.options.claude = false\n\t\t\tinput.options.code = false\n\t\t\tinput.options.devServer = false\n\t\t\tinput.options.terminal = false\n\t\t}\n\n\t\ttry {\n\t\t\t// Step 0: Load settings and get configured repo for GitHub operations\n\t\t\tconst initialSettings = await this.settingsManager.loadSettings()\n\n\t\t\t// Skip first-run setup in JSON mode\n\t\t\tif (!isJsonMode && (process.env.FORCE_FIRST_TIME_SETUP === \"true\" || await needsFirstRunSetup())) {\n\t\t\t\tawait launchFirstRunSetup()\n\t\t\t\t// Reload settings and recreate issueTracker if provider changed during setup\n\t\t\t\tconst newSettings = await this.settingsManager.loadSettings()\n\t\t\t\tconst newProvider = newSettings.issueManagement?.provider ?? 'github'\n\t\t\t\tif (newProvider !== this.issueTracker.providerName) {\n\t\t\t\t\tgetLogger().debug(`Reinitializing issue tracker: provider changed to \"${newProvider}\"`)\n\t\t\t\t\tthis.issueTracker = IssueTrackerFactory.create(newSettings)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet repo: string | undefined\n\n\t\t\t// Only get repo if we have multiple remotes (prehook already validated config)\n\t\t\tif (this.issueTracker.providerName === 'github' && (await hasMultipleRemotes())) {\n\t\t\t\t// Only relevant for GitHub - Linear doesn't use repo info\n\t\t\t\trepo = await getConfiguredRepoFromSettings(initialSettings)\n\t\t\t\tgetLogger().info(`Using GitHub repository: ${repo}`)\n\t\t\t}\n\n\t\t\t// Step 0.5: Initialize LoomManager with main worktree path\n\t\t\tconst loomManager = await this.initializeLoomManager()\n\n\t\t\t// Step 0.6: Detect if running from inside an existing loom (for nested loom support)\n\t\t\tlet parentLoom = await this.detectParentLoom(loomManager)\n\n\t\t\t// Step 1: Parse and validate input (pass repo to methods)\n\t\t\tconst parsed = await this.parseInput(input.identifier, repo)\n\n\t\t\t// Step 2: Validate based on type\n\t\t\tawait this.validateInput(parsed, repo)\n\n\t\t\t// Step 2.4: Handle child loom decision\n\t\t\tif (parentLoom) {\n\n\t\t\t\t// Format display message based on parent type\n\t\t\t\tconst parentDisplay = parentLoom.type === 'issue'\n\t\t\t\t\t? `issue #${parentLoom.identifier}`\n\t\t\t\t\t: parentLoom.type === 'pr'\n\t\t\t\t\t? `PR #${parentLoom.identifier}`\n\t\t\t\t\t: `branch ${parentLoom.identifier}`\n\n\t\t\t\t// Check for explicit flag first\n\t\t\t\tif (input.options.childLoom === true) {\n\t\t\t\t\t// --child-loom flag: force child loom (no prompt)\n\t\t\t\t\tgetLogger().info(`Creating as child loom of ${parentDisplay} (--child-loom flag)`)\n\t\t\t\t} else if (input.options.childLoom === false) {\n\t\t\t\t\t// --no-child-loom flag: force independent (no prompt)\n\t\t\t\t\tparentLoom = null\n\t\t\t\t\tgetLogger().info('Creating as independent loom (--no-child-loom flag)')\n\t\t\t\t} else {\n\t\t\t\t\t// No flag: use existing behavior (prompt or error if non-interactive)\n\t\t\t\t\t// JSON mode requires explicit flag\n\t\t\t\t\tif (isJsonMode) {\n\t\t\t\t\t\tthrow new Error('JSON mode requires explicit --child-loom or --no-child-loom flag when running from inside a loom')\n\t\t\t\t\t}\n\t\t\t\t\tlet createAsChild = true // Default for non-interactive\n\t\t\t\t\tif (isInteractiveEnvironment()) {\n\t\t\t\t\t\tcreateAsChild = await promptConfirmation(\n\t\t\t\t\t\t\t`You are not in your main worktree. Create as a child loom of ${parentDisplay}?`,\n\t\t\t\t\t\t\ttrue // Default yes\n\t\t\t\t\t\t)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('Non-interactive environment detected, use either --child-loom or --no-child-loom to specify behavior')\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!createAsChild) {\n\t\t\t\t\t\tparentLoom = null // User declined, proceed as normal loom\n\t\t\t\t\t\tgetLogger().info('Creating as independent loom')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (input.options.childLoom === true) {\n\t\t\t\t// --child-loom flag but not in a parent loom - ignore silently (per requirements)\n\t\t\t\tgetLogger().debug('--child-loom flag provided but not running from inside an existing loom (ignored)')\n\t\t\t}\n\t\t\t// Note: --no-child-loom when no parent is a no-op (already independent)\n\n\t\t\t// Step 2.5: Handle description input - create issue\n\t\t\tif (parsed.type === 'description') {\n\t\t\t\tgetLogger().info('Creating issue from description...')\n\t\t\t\t// Apply first-letter capitalization to title and body\n\t\t\t\tconst title = capitalizeFirstLetter(parsed.originalInput)\n\t\t\t\tconst body = input.options.body ? capitalizeFirstLetter(input.options.body) : \"\"\n\t\t\t\tconst result = await this.issueTracker.createIssue(\n\t\t\t\t\ttitle, // Use capitalized description as title\n\t\t\t\t\tbody // Use capitalized body or empty\n\t\t\t\t)\n\t\t\t\tgetLogger().success(`Created issue #${result.number}: ${result.url}`)\n\t\t\t\t// Update parsed to be an issue type with the new number\n\t\t\t\tparsed.type = 'issue'\n\t\t\t\tparsed.number = result.number\n\t\t\t}\n\n\t\t\t// Step 2.6: Detect epic (issue with child issues) and handle --epic/--no-epic flags\n\t\t\tlet childIssueNumbers: string[] = []\n\t\t\tlet childIssues: Array<{ number: string; title: string; body: string; url: string }> = []\n\t\t\tlet dependencyMap: Record<string, string[]> = {}\n\n\t\t\tif (parsed.type === 'issue' && parsed.number) {\n\t\t\t\tconst settings = await this.settingsManager.loadSettings()\n\t\t\t\tconst epicIssueTracker = IssueTrackerFactory.create(settings)\n\t\t\t\tlet children: Awaited<ReturnType<typeof fetchChildIssues>> = []\n\t\t\t\ttry {\n\t\t\t\t\tchildren = await fetchChildIssues(String(parsed.number), epicIssueTracker, repo)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgetLogger().warn(`Failed to check for child issues: ${error instanceof Error ? error.message : 'Unknown error'}. Proceeding as normal loom.`)\n\t\t\t\t}\n\n\t\t\t\tif (children.length > 0) {\n\t\t\t\t\tchildIssueNumbers = children.map(c => c.id)\n\t\t\t\t\tlet createAsEpic = false\n\n\t\t\t\t\tif (input.options.epic === true) {\n\t\t\t\t\t\t// --epic flag: force epic mode (no prompt)\n\t\t\t\t\t\tcreateAsEpic = true\n\t\t\t\t\t\tgetLogger().info(`Creating as epic loom with ${children.length} child issue(s) (--epic flag)`)\n\t\t\t\t\t} else if (input.options.epic === false) {\n\t\t\t\t\t\t// --no-epic flag: proceed as normal loom (no prompt)\n\t\t\t\t\t\tcreateAsEpic = false\n\t\t\t\t\t\tgetLogger().info('Creating as normal loom (--no-epic flag)')\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// No flag: prompt or error\n\t\t\t\t\t\tif (isJsonMode) {\n\t\t\t\t\t\t\tthrow new Error('JSON mode requires explicit --epic or --no-epic flag when issue has child issues')\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (isInteractiveEnvironment()) {\n\t\t\t\t\t\t\tcreateAsEpic = await promptConfirmation(\n\t\t\t\t\t\t\t\t`This issue has ${children.length} child issue(s). Create as epic loom?`,\n\t\t\t\t\t\t\t\ttrue // Default yes\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new Error('Non-interactive environment detected, use either --epic or --no-epic to specify behavior')\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (createAsEpic) {\n\t\t\t\t\t\tparsed.type = 'epic'\n\n\t\t\t\t\t\t// Fetch rich child issue details and dependency map for epic metadata\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst [details, depMap] = await Promise.all([\n\t\t\t\t\t\t\t\tfetchChildIssueDetails(String(parsed.number), epicIssueTracker, repo),\n\t\t\t\t\t\t\t\tbuildDependencyMap(childIssueNumbers, settings, repo),\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\tchildIssues = details ?? []\n\t\t\t\t\t\t\tdependencyMap = depMap ?? {}\n\t\t\t\t\t\t\tgetLogger().info(`Fetched ${childIssues.length} child issue details and dependency map`)\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Revert to issue type since child data fetch failed\n\t\t\t\t\t\t\t// il spin needs child data to enter swarm mode, so an epic without it would be broken\n\t\t\t\t\t\t\tparsed.type = 'issue'\n\t\t\t\t\t\t\tchildIssueNumbers = []\n\t\t\t\t\t\t\tgetLogger().warn(`Failed to fetch epic child data, reverting to normal loom: ${error instanceof Error ? error.message : String(error)}`)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Not creating as epic, clear child issue numbers\n\t\t\t\t\t\tchildIssueNumbers = []\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// --epic or --no-epic flags are silently ignored when there are no child issues\n\t\t\t}\n\n\t\t\t// Step 2.7: Confirm bypassPermissions mode if applicable\n\t\t\t// Only prompt in interactive mode when Claude is enabled.\n\t\t\t// Skip when: --no-claude (Claude won't launch now), JSON mode (non-interactive).\n\t\t\t// The explicit --one-shot=bypassPermissions flag is sufficient intent.\n\t\t\t// The warning is shown again when Claude launches via 'il spin'.\n\t\t\tif (input.options.oneShot === 'bypassPermissions' && input.options.claude !== false && !isJsonMode) {\n\t\t\t\tconst confirmed = await promptConfirmation(\n\t\t\t\t\t'WARNING: bypassPermissions mode will allow Claude to execute all tool calls without confirmation. ' +\n\t\t\t\t\t'This can be dangerous. Do you want to proceed?'\n\t\t\t\t)\n\t\t\t\tif (!confirmed) {\n\t\t\t\t\tgetLogger().info('Operation cancelled by user')\n\t\t\t\t\tprocess.exit(0)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Step 2.8: Load workflow-specific settings with CLI overrides\n\t\t\tconst cliOverrides = extractSettingsOverrides()\n\t\t\tconst settings = await this.settingsManager.loadSettings(undefined, cliOverrides)\n\t\t\tconst workflowType = parsed.type === 'branch' ? 'regular' : parsed.type === 'epic' ? 'issue' : parsed.type\n\t\t\tconst workflowConfig = settings.workflows?.[workflowType]\n\n\t\t\t// Step 2.9: Extract raw --set arguments and executable path for forwarding to spin\n\t\t\tconst { extractRawSetArguments, getExecutablePath } = await import('../utils/cli-overrides.js')\n\t\t\tconst setArguments = extractRawSetArguments()\n\t\t\tconst executablePath = getExecutablePath()\n\n\t\t\t// Step 3: Log success and create loom\n\t\t\tgetLogger().info(`Validated input: ${this.formatParsedInput(parsed)}`)\n\n\t\t\t// Step 4: Create loom using LoomManager\n\t\t\tconst identifier =\n\t\t\t\tparsed.type === 'branch'\n\t\t\t\t\t? parsed.branchName ?? ''\n\t\t\t\t\t: parsed.number ?? 0\n\n\t\t\t// Apply configuration precedence: CLI flags > workflow config > defaults (true)\n\t\t\tconst enableClaude = input.options.claude ?? workflowConfig?.startAiAgent ?? true\n\t\t\tconst enableCode = input.options.code ?? workflowConfig?.startIde ?? true\n\t\t\tconst enableDevServer = input.options.devServer ?? workflowConfig?.startDevServer ?? true\n\t\t\tconst enableTerminal = input.options.terminal ?? workflowConfig?.startTerminal ?? false\n\n\t\t\tgetLogger().debug('Final workflow config values:', {\n\t\t\t\tenableClaude,\n\t\t\t\tenableCode,\n\t\t\t\tenableDevServer,\n\t\t\t\tenableTerminal,\n\t\t\t})\n\n\t\t\tconst loom = await loomManager.createIloom({\n\t\t\t\ttype: parsed.type,\n\t\t\t\tidentifier,\n\t\t\t\toriginalInput: parsed.originalInput,\n\t\t\t\t...(parentLoom && { parentLoom }),\n\t\t\t\toptions: {\n\t\t\t\t\tenableClaude,\n\t\t\t\t\tenableCode,\n\t\t\t\t\tenableDevServer,\n\t\t\t\t\tenableTerminal,\n\t\t\t\t\t...(input.options.oneShot && { oneShot: input.options.oneShot }),\n\t\t\t\t\t...(input.options.complexity && { complexity: input.options.complexity }),\n\t\t\t\t\t...(setArguments.length > 0 && { setArguments }),\n\t\t\t\t\t...(executablePath && { executablePath }),\n\t\t\t\t\t...(childIssueNumbers.length > 0 && { childIssueNumbers }),\n\t\t\t\t\t...(childIssues.length > 0 && { childIssues }),\n\t\t\t\t\t...(Object.keys(dependencyMap).length > 0 && { dependencyMap }),\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tgetLogger().success(`Created loom: ${loom.id} at ${loom.path}`)\n\n\t\t\t// Set recap complexity if overridden via CLI flag\n\t\t\tif (input.options.complexity) {\n\t\t\t\ttry {\n\t\t\t\t\tconst recapFilePath = resolveRecapFilePath(loom.path)\n\t\t\t\t\tconst recap = await readRecapFile(recapFilePath)\n\t\t\t\t\trecap.complexity = { level: input.options.complexity, reason: 'Overridden via CLI flag', timestamp: new Date().toISOString() }\n\t\t\t\t\tawait writeRecapFile(recapFilePath, recap)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgetLogger().debug(`Failed to set recap complexity: ${error instanceof Error ? error.message : error}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Track loom.created telemetry event\n\t\t\ttry {\n\t\t\t\tconst oneShotMap: Record<string, LoomCreatedProperties['one_shot_mode']> = {\n\t\t\t\t\tnoReview: 'skip-reviews',\n\t\t\t\t\tbypassPermissions: 'yolo',\n\t\t\t\t}\n\t\t\t\tTelemetryService.getInstance().track('loom.created', {\n\t\t\t\t\tsource_type: parsed.type === 'epic' ? 'issue' : parsed.type as LoomCreatedProperties['source_type'],\n\t\t\t\t\ttracker: this.issueTracker.providerName,\n\t\t\t\t\tis_child_loom: !!parentLoom,\n\t\t\t\t\tone_shot_mode: oneShotMap[input.options.oneShot ?? ''] ?? 'default',\n\t\t\t\t\tcomplexity_override: !!input.options.complexity,\n\t\t\t\t\tcreate_only: !!input.options.createOnly,\n\t\t\t\t})\n\t\t\t} catch (error: unknown) {\n\t\t\t\tgetLogger().debug(`Failed to track loom.created telemetry: ${error instanceof Error ? error.message : String(error)}`)\n\t\t\t}\n\n\t\t\tgetLogger().info(` Branch: ${loom.branch}`)\n\t\t\t// Only show port for web projects\n\t\t\tif (loom.capabilities?.includes('web')) {\n\t\t\t\tgetLogger().info(` Port: ${loom.port}`)\n\t\t\t}\n\t\t\tif (loom.issueData?.title) {\n\t\t\t\tgetLogger().info(` Title: ${loom.issueData.title}`)\n\t\t\t}\n\t\t\tif (parsed.type === 'epic') {\n\t\t\t\tgetLogger().info(` Epic: yes (${childIssueNumbers.length} child issue(s))`)\n\t\t\t}\n\n\t\t\t// Return StartResult in JSON mode\n\t\t\tif (isJsonMode) {\n\t\t\t\treturn {\n\t\t\t\t\tid: loom.id,\n\t\t\t\t\tpath: loom.path,\n\t\t\t\t\tbranch: loom.branch,\n\t\t\t\t\ttype: parsed.type,\n\t\t\t\t\tidentifier: loom.identifier,\n\t\t\t\t\t...(loom.port !== undefined && { port: loom.port }),\n\t\t\t\t\t...(loom.issueData?.title && { title: loom.issueData.title }),\n\t\t\t\t\t...(loom.capabilities && { capabilities: loom.capabilities }),\n\t\t\t\t\t...(childIssueNumbers.length > 0 && { childIssueNumbers }),\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tgetLogger().error(`${error.message}`)\n\t\t\t} else {\n\t\t\t\tgetLogger().error('An unknown error occurred')\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n\n\t/**\n\t * Parse input to determine type and extract relevant data\n\t */\n\tprivate async parseInput(identifier: string, repo?: string): Promise<ParsedInput> {\n\t\t// Check if user wants to skip capitalization by prefixing with space\n\t\t// We preserve this for description types so capitalizeFirstLetter() can handle it\n\t\tconst hasLeadingSpace = identifier.startsWith(' ')\n\n\t\t// Handle empty input\n\t\tconst trimmedIdentifier = identifier.trim()\n\t\tif (!trimmedIdentifier) {\n\t\t\tthrow new Error('Missing required argument: identifier')\n\t\t}\n\n\t\t// Check for description: >15 chars AND has spaces (likely a natural language description)\n\t\t// Short inputs with spaces are rejected later as invalid branch names\n\t\tconst spaceCount = (trimmedIdentifier.match(/ /g) ?? []).length\n\t\tif (trimmedIdentifier.length > 15 && spaceCount >= 1) {\n\t\t\t// Preserve leading space if present so capitalizeFirstLetter() can detect the override\n\t\t\treturn {\n\t\t\t\ttype: 'description',\n\t\t\t\toriginalInput: hasLeadingSpace ? ' ' + trimmedIdentifier : trimmedIdentifier,\n\t\t\t}\n\t\t}\n\n\t\t// Check for PR-specific formats: pr/123, PR-123, PR/123, Pr-123 (case-insensitive)\n\t\tconst prPattern = /^pr[/-](\\d+)$/i\n\t\tconst prMatch = trimmedIdentifier.match(prPattern)\n\t\tif (prMatch?.[1]) {\n\t\t\treturn {\n\t\t\t\ttype: 'pr',\n\t\t\t\tnumber: parseInt(prMatch[1], 10),\n\t\t\t\toriginalInput: trimmedIdentifier,\n\t\t\t}\n\t\t}\n\n\t\t// Check for issue identifier patterns using shared utility\n\t\t// - Project key pattern: ENG-123 (requires at least 2 letters before dash)\n\t\t// - Numeric pattern: #123 or 123 (GitHub format)\n\t\tconst identifierMatch = matchIssueIdentifier(trimmedIdentifier)\n\n\t\tif (identifierMatch.type === 'project-key' && identifierMatch.identifier) {\n\t\t\t// Use IssueTracker to validate it exists\n\t\t\tconst detection = await this.issueTracker.detectInputType(\n\t\t\t\ttrimmedIdentifier,\n\t\t\t\trepo\n\t\t\t)\n\n\t\t\tif (detection.type === 'issue' && detection.identifier) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'issue',\n\t\t\t\t\tnumber: detection.identifier, // Keep as string for project key identifiers\n\t\t\t\t\toriginalInput: trimmedIdentifier,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Project key identifier format matched but not found\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find issue matching identifier ${identifierMatch.identifier}`\n\t\t\t)\n\t\t}\n\n\t\t// Check for numeric pattern (could be issue or PR)\n\t\tif (identifierMatch.type === 'numeric' && identifierMatch.identifier) {\n\t\t\tconst number = parseInt(identifierMatch.identifier, 10)\n\n\t\t\t// If issue tracker supports PRs, use it for detection\n\t\t\tif (this.issueTracker.supportsPullRequests) {\n\t\t\t\tconst detection = await this.issueTracker.detectInputType(\n\t\t\t\t\ttrimmedIdentifier,\n\t\t\t\t\trepo\n\t\t\t\t)\n\n\t\t\t\tif (detection.type === 'pr') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: 'pr',\n\t\t\t\t\t\tnumber: detection.identifier ? parseInt(detection.identifier, 10) : number,\n\t\t\t\t\t\toriginalInput: trimmedIdentifier,\n\t\t\t\t\t}\n\t\t\t\t} else if (detection.type === 'issue') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: 'issue',\n\t\t\t\t\t\tnumber: detection.identifier ? parseInt(detection.identifier, 10) : number,\n\t\t\t\t\t\toriginalInput: trimmedIdentifier,\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`Could not find issue or PR #${number}`)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Issue tracker doesn't support PRs (e.g., Linear, Jira)\n\t\t\t\t// Check GitHub first for PR, then fall back to issue tracker for issues\n\t\t\t\tconst githubService = this.getGitHubService()\n\t\t\t\tconst detection = await githubService.detectInputType(trimmedIdentifier, repo)\n\n\t\t\t\tif (detection.type === 'pr') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: 'pr',\n\t\t\t\t\t\tnumber: detection.identifier ? parseInt(detection.identifier, 10) : number,\n\t\t\t\t\t\toriginalInput: trimmedIdentifier,\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Not a GitHub PR - try the configured issue tracker\n\t\t\t\t\t// This allows future trackers with numeric IDs to work naturally\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: 'issue',\n\t\t\t\t\t\tnumber,\n\t\t\t\t\t\toriginalInput: trimmedIdentifier,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Treat as branch name\n\t\treturn {\n\t\t\ttype: 'branch',\n\t\t\tbranchName: trimmedIdentifier,\n\t\t\toriginalInput: trimmedIdentifier,\n\t\t}\n\t}\n\n\t/**\n\t * Validate the parsed input based on its type\n\t */\n\tprivate async validateInput(parsed: ParsedInput, repo?: string): Promise<void> {\n\t\tswitch (parsed.type) {\n\t\t\tcase 'pr': {\n\t\t\t\tif (!parsed.number) {\n\t\t\t\t\tthrow new Error('Invalid PR number')\n\t\t\t\t}\n\n\t\t\t\t// Determine which service to use for PR operations\n\t\t\t\tif (this.issueTracker.supportsPullRequests && this.issueTracker.fetchPR && this.issueTracker.validatePRState) {\n\t\t\t\t\t// Use issue tracker for PR operations (e.g., GitHub)\n\t\t\t\t\tconst pr = await this.issueTracker.fetchPR(parsed.number, repo)\n\t\t\t\t\tawait this.issueTracker.validatePRState(pr)\n\t\t\t\t} else {\n\t\t\t\t\t// Use GitHubService for PR operations when issue tracker doesn't support PRs (e.g., Linear)\n\t\t\t\t\tconst githubService = this.getGitHubService()\n\t\t\t\t\tconst pr = await githubService.fetchPR(parsed.number as number, repo)\n\t\t\t\t\tawait githubService.validatePRState(pr)\n\t\t\t\t}\n\t\t\t\tgetLogger().debug(`Validated PR #${parsed.number}`)\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcase 'issue': {\n\t\t\t\tif (!parsed.number) {\n\t\t\t\t\tthrow new Error('Invalid issue number')\n\t\t\t\t}\n\t\t\t\t// Fetch and validate issue state\n\t\t\t\tconst issue = await this.issueTracker.fetchIssue(parsed.number, repo)\n\t\t\t\tawait this.issueTracker.validateIssueState(issue)\n\t\t\t\tgetLogger().debug(`Validated issue #${parsed.number}`)\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcase 'branch': {\n\t\t\t\tif (!parsed.branchName) {\n\t\t\t\t\tthrow new Error('Invalid branch name')\n\t\t\t\t}\n\t\t\t\t// Validate branch name characters (from bash script line 586)\n\t\t\t\tif (!this.isValidBranchName(parsed.branchName)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Invalid branch name. Use only letters, numbers, hyphens, underscores, and slashes'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tgetLogger().debug(`Validated branch name: ${parsed.branchName}`)\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcase 'description': {\n\t\t\t\t// Description inputs are valid - they will be converted to issues\n\t\t\t\tgetLogger().debug('Detected description input', {\n\t\t\t\t\tlength: parsed.originalInput.length\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tconst unknownType = parsed as { type: string }\n\t\t\t\tthrow new Error(`Unknown input type: ${unknownType.type}`)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Validate branch name format\n\t */\n\tprivate isValidBranchName(branch: string): boolean {\n\t\t// Pattern from bash script line 586\n\t\treturn /^[a-zA-Z0-9/_-]+$/.test(branch)\n\t}\n\n\t/**\n\t * Format parsed input for display\n\t */\n\tprivate formatParsedInput(parsed: ParsedInput): string {\n\t\tswitch (parsed.type) {\n\t\t\tcase 'pr':\n\t\t\t\treturn `PR #${parsed.number}`\n\t\t\tcase 'issue':\n\t\t\t\treturn `Issue #${parsed.number}`\n\t\t\tcase 'epic':\n\t\t\t\treturn `Epic #${parsed.number}`\n\t\t\tcase 'branch':\n\t\t\t\treturn `Branch '${parsed.branchName}'`\n\t\t\tcase 'description':\n\t\t\t\treturn `Description: ${parsed.originalInput.slice(0, 50)}...`\n\t\t\tdefault:\n\t\t\t\treturn 'Unknown input'\n\t\t}\n\t}\n\n\t/**\n\t * Detect if running from inside an existing loom worktree\n\t * Returns parent loom info if detected, null otherwise\n\t */\n\tprivate async detectParentLoom(loomManager: LoomManager): Promise<{\n\t\ttype: 'issue' | 'pr' | 'branch' | 'epic'\n\t\tidentifier: string | number\n\t\tbranchName: string\n\t\tworktreePath: string\n\t\tdatabaseBranch?: string\n\t} | null> {\n\t\ttry {\n\t\t\tconst cwd = process.cwd()\n\t\t\tconst looms = await loomManager.listLooms()\n\n\t\t\tif (!looms) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\t// Get main worktree path to exclude it from valid parents\n\t\t\tconst mainWorktreePath = await findMainWorktreePathWithSettings()\n\n\t\t\t// Find loom containing current directory\n\t\t\t// Fix #2: Add path.sep check to prevent false positives (e.g., issue-123 vs issue-1234)\n\t\t\t// Exclude main worktree from being a valid parent\n\t\t\tconst parentLoom = looms.find(loom => {\n\t\t\t\t// Skip main worktree - it shouldn't be a parent for child looms\n\t\t\t\tif (loom.path === mainWorktreePath) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t\t// Either exact match OR cwd starts with loom.path followed by path separator\n\t\t\t\treturn cwd === loom.path || cwd.startsWith(loom.path + path.sep)\n\t\t\t})\n\t\t\tif (!parentLoom) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tgetLogger().debug(`Detected parent loom: ${parentLoom.type} ${parentLoom.identifier} at ${parentLoom.path}`)\n\n\t\t\tconst result: {\n\t\t\t\ttype: 'issue' | 'pr' | 'branch' | 'epic'\n\t\t\t\tidentifier: string | number\n\t\t\t\tbranchName: string\n\t\t\t\tworktreePath: string\n\t\t\t\tdatabaseBranch?: string\n\t\t\t} = {\n\t\t\t\ttype: parentLoom.type,\n\t\t\t\tidentifier: parentLoom.identifier,\n\t\t\t\tbranchName: parentLoom.branch,\n\t\t\t\tworktreePath: parentLoom.path,\n\t\t\t}\n\n\t\t\t// Only include databaseBranch if it exists (exactOptionalPropertyTypes compatibility)\n\t\t\tif (parentLoom.databaseBranch) {\n\t\t\t\tresult.databaseBranch = parentLoom.databaseBranch\n\t\t\t}\n\n\t\t\t// Try to get database branch from parent's .env file via reverse lookup\n\t\t\tif (!result.databaseBranch) {\n\t\t\t\tconst databaseBranch = await loomManager.getDatabaseBranchForLoom(parentLoom.path)\n\t\t\t\tif (databaseBranch) {\n\t\t\t\t\tresult.databaseBranch = databaseBranch\n\t\t\t\t\tgetLogger().debug(`Detected parent database branch: ${databaseBranch}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result\n\t\t} catch (error) {\n\t\t\t// If detection fails for any reason, just return null (don't break the start workflow)\n\t\t\tgetLogger().debug(`Failed to detect parent loom: ${error instanceof Error ? error.message : 'Unknown error'}`)\n\t\t\treturn null\n\t\t}\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,OAAO,UAAU;AACjB,OAAO,WAAW;AAWlB,eAAe,iBAAkC;AAChD,QAAM,WAAW,MAAM,YAAY;AACnC,MAAI,UAAU;AACb,WAAO,MAAM,wCAAwC,QAAQ,EAAE;AAC/D,WAAO;AAAA,EACR;AACA,QAAM,MAAM,QAAQ,IAAI;AACxB,SAAO,MAAM,+CAA+C,GAAG,EAAE;AACjE,SAAO;AACR;AAWA,eAAsB,qBAAuC;AAC5D,QAAM,cAAc,MAAM,eAAe;AACzC,QAAM,kBAAkB,IAAI,gBAAgB;AAG5C,QAAM,eAAe,MAAM,gBAAgB,oBAAoB,WAAW;AAC1E,MAAI,cAAc;AACjB,WAAO,MAAM,+DAA+D;AAC5E,WAAO;AAAA,EACR;AAEA,Q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