iosm-cli 0.2.0 → 0.2.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.
Files changed (90) hide show
  1. package/README.md +58 -47
  2. package/dist/core/agent-teams.d.ts.map +1 -1
  3. package/dist/core/agent-teams.js +38 -11
  4. package/dist/core/agent-teams.js.map +1 -1
  5. package/dist/core/failure-retrospective.d.ts +12 -0
  6. package/dist/core/failure-retrospective.d.ts.map +1 -0
  7. package/dist/core/failure-retrospective.js +115 -0
  8. package/dist/core/failure-retrospective.js.map +1 -0
  9. package/dist/core/project-index/index.d.ts +17 -0
  10. package/dist/core/project-index/index.d.ts.map +1 -0
  11. package/dist/core/project-index/index.js +323 -0
  12. package/dist/core/project-index/index.js.map +1 -0
  13. package/dist/core/project-index/types.d.ts +34 -0
  14. package/dist/core/project-index/types.d.ts.map +1 -0
  15. package/dist/core/project-index/types.js +2 -0
  16. package/dist/core/project-index/types.js.map +1 -0
  17. package/dist/core/sdk.d.ts.map +1 -1
  18. package/dist/core/sdk.js +8 -0
  19. package/dist/core/sdk.js.map +1 -1
  20. package/dist/core/shared-memory.d.ts +46 -0
  21. package/dist/core/shared-memory.d.ts.map +1 -0
  22. package/dist/core/shared-memory.js +253 -0
  23. package/dist/core/shared-memory.js.map +1 -0
  24. package/dist/core/slash-commands.d.ts.map +1 -1
  25. package/dist/core/slash-commands.js +5 -1
  26. package/dist/core/slash-commands.js.map +1 -1
  27. package/dist/core/subagents.js +1 -1
  28. package/dist/core/subagents.js.map +1 -1
  29. package/dist/core/swarm/gates.d.ts +9 -0
  30. package/dist/core/swarm/gates.d.ts.map +1 -0
  31. package/dist/core/swarm/gates.js +65 -0
  32. package/dist/core/swarm/gates.js.map +1 -0
  33. package/dist/core/swarm/index.d.ts +9 -0
  34. package/dist/core/swarm/index.d.ts.map +1 -0
  35. package/dist/core/swarm/index.js +9 -0
  36. package/dist/core/swarm/index.js.map +1 -0
  37. package/dist/core/swarm/locks.d.ts +21 -0
  38. package/dist/core/swarm/locks.d.ts.map +1 -0
  39. package/dist/core/swarm/locks.js +93 -0
  40. package/dist/core/swarm/locks.js.map +1 -0
  41. package/dist/core/swarm/planner.d.ts +16 -0
  42. package/dist/core/swarm/planner.d.ts.map +1 -0
  43. package/dist/core/swarm/planner.js +137 -0
  44. package/dist/core/swarm/planner.js.map +1 -0
  45. package/dist/core/swarm/retry.d.ts +16 -0
  46. package/dist/core/swarm/retry.d.ts.map +1 -0
  47. package/dist/core/swarm/retry.js +32 -0
  48. package/dist/core/swarm/retry.js.map +1 -0
  49. package/dist/core/swarm/scheduler.d.ts +48 -0
  50. package/dist/core/swarm/scheduler.d.ts.map +1 -0
  51. package/dist/core/swarm/scheduler.js +554 -0
  52. package/dist/core/swarm/scheduler.js.map +1 -0
  53. package/dist/core/swarm/spawn.d.ts +16 -0
  54. package/dist/core/swarm/spawn.d.ts.map +1 -0
  55. package/dist/core/swarm/spawn.js +42 -0
  56. package/dist/core/swarm/spawn.js.map +1 -0
  57. package/dist/core/swarm/state-store.d.ts +35 -0
  58. package/dist/core/swarm/state-store.d.ts.map +1 -0
  59. package/dist/core/swarm/state-store.js +106 -0
  60. package/dist/core/swarm/state-store.js.map +1 -0
  61. package/dist/core/swarm/types.d.ts +116 -0
  62. package/dist/core/swarm/types.d.ts.map +1 -0
  63. package/dist/core/swarm/types.js +2 -0
  64. package/dist/core/swarm/types.js.map +1 -0
  65. package/dist/core/system-prompt.d.ts.map +1 -1
  66. package/dist/core/system-prompt.js +3 -2
  67. package/dist/core/system-prompt.js.map +1 -1
  68. package/dist/core/tools/shared-memory.d.ts +23 -0
  69. package/dist/core/tools/shared-memory.d.ts.map +1 -0
  70. package/dist/core/tools/shared-memory.js +134 -0
  71. package/dist/core/tools/shared-memory.js.map +1 -0
  72. package/dist/core/tools/task.d.ts +8 -1
  73. package/dist/core/tools/task.d.ts.map +1 -1
  74. package/dist/core/tools/task.js +664 -123
  75. package/dist/core/tools/task.js.map +1 -1
  76. package/dist/modes/interactive/components/login-dialog.d.ts +1 -0
  77. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  78. package/dist/modes/interactive/components/login-dialog.js +27 -4
  79. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  80. package/dist/modes/interactive/components/subagent-message.d.ts.map +1 -1
  81. package/dist/modes/interactive/components/subagent-message.js +14 -0
  82. package/dist/modes/interactive/components/subagent-message.js.map +1 -1
  83. package/dist/modes/interactive/interactive-mode.d.ts +38 -0
  84. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  85. package/dist/modes/interactive/interactive-mode.js +1362 -31
  86. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  87. package/docs/cli-reference.md +11 -1
  88. package/docs/interactive-mode.md +42 -3
  89. package/docs/orchestration-and-subagents.md +96 -169
  90. package/package.json +4 -3
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAyC,MAAM,6BAA6B,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC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AAS;QAC5D,oBAAoB,EAAE,OAAO,EAAE,IAAI,KAAK,MAAM;KAC9C,CAAC,CAAC;IACH,UAAU,GAAG,OAAO,CAAC;IACrB,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;IAExD,OAAO;QACN,OAAO;QACP,gBAAgB;QAChB,oBAAoB;KACpB,CAAC;AACH,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport { Agent, type AgentMessage, type ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { Message, Model } from \"@mariozechner/pi-ai\";\nimport { getAgentDir, getDocsPath } from \"../config.js\";\nimport { createAskUserTool } from \"./ask-user-tool.js\";\nimport { AgentSession } from \"./agent-session.js\";\nimport { AuthStorage } from \"./auth-storage.js\";\nimport { DEFAULT_THINKING_LEVEL } from \"./defaults.js\";\nimport type { ExtensionRunner, LoadExtensionsResult, ToolDefinition } from \"./extensions/index.js\";\nimport { convertToLlm } from \"./messages.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\nimport { findInitialModel } from \"./model-resolver.js\";\nimport type { ResourceLoader } from \"./resource-loader.js\";\nimport { DefaultResourceLoader } from \"./resource-loader.js\";\nimport { SessionManager } from \"./session-manager.js\";\nimport { SettingsManager } from \"./settings-manager.js\";\nimport { loadCustomSubagents, resolveCustomSubagentReference } from \"./subagents.js\";\nimport { time } from \"./timings.js\";\nimport { patchAgentForParallelTaskExecution } from \"./parallel-task-agent.js\";\nimport {\n\tallTools,\n\tastGrepTool,\n\tbashTool,\n\tcodingTools,\n\tcombyTool,\n\tcreateAstGrepTool,\n\tcreateBashTool,\n\tcreateCodingTools,\n\tcreateCombyTool,\n\tcreateEditTool,\n\tcreateFdTool,\n\tcreateFindTool,\n\tcreateGrepTool,\n\tcreateJqTool,\n\tcreateLsTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateRgTool,\n\tcreateSedTool,\n\tcreateSemgrepTool,\n\tcreateSemanticSearchTool,\n\tcreateTaskTool,\n\tcreateToolsFromNames,\n\tcreateWriteTool,\n\teditTool,\n\tfdTool,\n\tfindTool,\n\tgrepTool,\n\tjqTool,\n\tlsTool,\n\treadOnlyTools,\n\treadTool,\n\trgTool,\n\tsedTool,\n\tsemanticSearchTool,\n\tsemgrepTool,\n\ttodoReadTool,\n\ttodoWriteTool,\n\ttype TaskToolProgress,\n\ttype TaskToolProgressPhase,\n\ttype Tool,\n\ttype ToolName,\n\tyqTool,\n\tcreateYqTool,\n\twriteTool,\n} from \"./tools/index.js\";\nimport { getAgentProfile, type AgentProfileName } from \"./agent-profiles.js\";\n\nexport interface CreateAgentSessionOptions {\n\t/** Working directory for project-local discovery. Default: process.cwd() */\n\tcwd?: string;\n\t/** Global config directory. Default: ~/.iosm/agent */\n\tagentDir?: string;\n\n\t/** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */\n\tauthStorage?: AuthStorage;\n\t/** Model registry. Default: new ModelRegistry(authStorage, agentDir/models.json) */\n\tmodelRegistry?: ModelRegistry;\n\n\t/** Model to use. Default: from settings, else first available */\n\tmodel?: Model<any>;\n\t/** Require explicit model selection by the user; disables automatic model fallback/selection for new sessions. */\n\trequireExplicitModelSelection?: boolean;\n\t/** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */\n\tthinkingLevel?: ThinkingLevel;\n\t/** Models available for cycling (Ctrl+P in interactive mode) */\n\tscopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\n\t/** Built-in tools to use. Default: active profile tools (profile defaults to \"full\"). */\n\ttools?: Tool[];\n\t/** Custom tools to register (in addition to built-in tools). */\n\tcustomTools?: ToolDefinition[];\n\t/** Enable the interactive ask_user clarification tool. Best used in interactive or RPC sessions. */\n\tenableAskUserTool?: boolean;\n\n\t/** Resource loader. When omitted, DefaultResourceLoader is used. */\n\tresourceLoader?: ResourceLoader;\n\n\t/** Session manager. Default: SessionManager.create(cwd) */\n\tsessionManager?: SessionManager;\n\n\t/** Settings manager. Default: SettingsManager.create(cwd, agentDir) */\n\tsettingsManager?: SettingsManager;\n\n\t/**\n\t * Agent profile name. Overrides tools and thinkingLevel with profile defaults.\n\t * Profiles: explore, plan, iosm_analyst, iosm_verifier, cycle_planner, full (default).\n\t */\n\tprofile?: AgentProfileName | string;\n\n\t/**\n\t * Whether to register the Task tool (subagent spawning).\n\t * Default: true for interactive/print sessions; false for subagent sessions to avoid recursion.\n\t */\n\tenableTaskTool?: boolean;\n}\n\n/** Result from createAgentSession */\nexport interface CreateAgentSessionResult {\n\t/** The created session */\n\tsession: AgentSession;\n\t/** Extensions result (for UI context setup in interactive mode) */\n\textensionsResult: LoadExtensionsResult;\n\t/** Warning if session was restored with a different model than saved */\n\tmodelFallbackMessage?: string;\n}\n\n// Re-exports\n\nexport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tSlashCommandInfo,\n\tSlashCommandLocation,\n\tSlashCommandSource,\n\tToolDefinition,\n} from \"./extensions/index.js\";\nexport type { PromptTemplate } from \"./prompt-templates.js\";\nexport type { Skill } from \"./skills.js\";\nexport type { Tool } from \"./tools/index.js\";\n\n\texport {\n\t\tcreateAskUserTool,\n\t\t// Pre-built tools (use process.cwd())\n\t\treadTool,\n\t\tbashTool,\n\t\teditTool,\n\t\twriteTool,\n\t\tgrepTool,\n\t\tfindTool,\n\t\tlsTool,\n\t\trgTool,\n\t\tfdTool,\n\t\tastGrepTool,\n\t\tcombyTool,\n\t\tjqTool,\n\t\tyqTool,\n\t\tsemgrepTool,\n\t\tsedTool,\n\t\tsemanticSearchTool,\n\t\tcodingTools,\n\t\treadOnlyTools,\n\t\tallTools as allBuiltInTools,\n\t\t// Tool factories (for custom cwd)\n\t\tcreateCodingTools,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\t\tcreateWriteTool,\n\t\tcreateGrepTool,\n\t\tcreateFindTool,\n\t\tcreateLsTool,\n\t\tcreateRgTool,\n\t\tcreateFdTool,\n\t\tcreateAstGrepTool,\n\t\tcreateCombyTool,\n\t\tcreateJqTool,\n\t\tcreateYqTool,\n\t\tcreateSemgrepTool,\n\t\tcreateSedTool,\n\t\tcreateSemanticSearchTool,\n\t};\n\n// Helper Functions\n\nfunction getDefaultAgentDir(): string {\n\treturn getAgentDir();\n}\n\nfunction resolveModelBySpecifier(\n\tmodelRegistry: ModelRegistry,\n\tspecifier: string,\n\tpreferredProvider?: string,\n): Model<any> | undefined {\n\tconst raw = specifier.trim();\n\tif (!raw) return undefined;\n\tconst slash = raw.indexOf(\"/\");\n\tif (slash > 0 && slash < raw.length - 1) {\n\t\tconst provider = raw.slice(0, slash);\n\t\tconst modelId = raw.slice(slash + 1);\n\t\treturn modelRegistry.find(provider, modelId);\n\t}\n\n\tconst all = modelRegistry.getAll().filter((candidate) => candidate.id === raw);\n\tif (all.length === 0) return undefined;\n\tif (preferredProvider) {\n\t\tconst preferred = all.find((candidate) => candidate.provider === preferredProvider);\n\t\tif (preferred) return preferred;\n\t}\n\treturn all[0];\n}\n\n/**\n * Create an AgentSession with the specified options.\n *\n * @example\n * ```typescript\n * // Minimal - uses defaults\n * const { session } = await createAgentSession();\n *\n * // With explicit model\n * import { getModel } from '@mariozechner/pi-ai';\n * const { session } = await createAgentSession({\n * model: getModel('anthropic', 'claude-opus-4-5'),\n * thinkingLevel: 'high',\n * });\n *\n * // Continue previous session\n * const { session, modelFallbackMessage } = await createAgentSession({\n * continueSession: true,\n * });\n *\n * // Full control\n * const loader = new DefaultResourceLoader({\n * cwd: process.cwd(),\n * agentDir: getAgentDir(),\n * settingsManager: SettingsManager.create(),\n * });\n * await loader.reload();\n * const { session } = await createAgentSession({\n * model: myModel,\n * tools: [readTool, bashTool],\n * resourceLoader: loader,\n * sessionManager: SessionManager.inMemory(),\n * });\n * ```\n */\nexport async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {\n\tconst cwd = options.cwd ?? process.cwd();\n\tconst agentDir = options.agentDir ?? getDefaultAgentDir();\n\tconst contextProfile = options.profile?.toString().toLowerCase() === \"iosm\" ? \"iosm\" : \"standard\";\n\tlet resourceLoader = options.resourceLoader;\n\n\t// Use provided or create AuthStorage and ModelRegistry\n\tconst authPath = options.agentDir ? join(agentDir, \"auth.json\") : undefined;\n\tconst modelsPath = options.agentDir ? join(agentDir, \"models.json\") : undefined;\n\tconst authStorage = options.authStorage ?? AuthStorage.create(authPath);\n\tconst modelRegistry = options.modelRegistry ?? new ModelRegistry(authStorage, modelsPath);\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst sessionManager = options.sessionManager ?? SessionManager.create(cwd);\n\n\tif (!resourceLoader) {\n\t\tresourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager, contextProfile });\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t}\n\n\t// Check if session has existing data to restore\n\tconst existingSession = sessionManager.buildSessionContext();\n\tconst hasExistingSession = existingSession.messages.length > 0;\n\tconst hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === \"thinking_level_change\");\n\n\tlet model = options.model;\n\tlet modelFallbackMessage: string | undefined;\n\tconst requireExplicitModelSelection = options.requireExplicitModelSelection === true;\n\n\t// If session has data, try to restore model from it\n\tif (!model && hasExistingSession && existingSession.model) {\n\t\tconst restoredModel = modelRegistry.find(existingSession.model.provider, existingSession.model.modelId);\n\t\tif (restoredModel && (await modelRegistry.getApiKey(restoredModel))) {\n\t\t\tmodel = restoredModel;\n\t\t}\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = `Could not restore model ${existingSession.model.provider}/${existingSession.model.modelId}`;\n\t\t}\n\t}\n\n\t// If still no model, use findInitialModel unless explicit selection is required.\n\tif (!model && !requireExplicitModelSelection) {\n\t\tconst result = await findInitialModel({\n\t\t\tscopedModels: options.scopedModels ?? [],\n\t\t\tisContinuing: hasExistingSession,\n\t\t\tdefaultProvider: settingsManager.getDefaultProvider(),\n\t\t\tdefaultModelId: settingsManager.getDefaultModel(),\n\t\t\tdefaultThinkingLevel: settingsManager.getDefaultThinkingLevel(),\n\t\t\tmodelRegistry,\n\t\t});\n\t\tmodel = result.model;\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = `No models available. Use /login or set an API key environment variable. See ${join(getDocsPath(), \"providers.md\")}. Then use /model to select a model.`;\n\t\t} else if (modelFallbackMessage) {\n\t\t\tmodelFallbackMessage += `. Using ${model.provider}/${model.id}`;\n\t\t}\n\t} else if (!model && requireExplicitModelSelection && !hasExistingSession) {\n\t\tmodelFallbackMessage = \"No model selected. Choose one with /model or pass --provider and --model.\";\n\t}\n\n\tlet thinkingLevel = options.thinkingLevel;\n\n\t// If session has data, restore thinking level from it\n\tif (thinkingLevel === undefined && hasExistingSession) {\n\t\tthinkingLevel = hasThinkingEntry\n\t\t\t? (existingSession.thinkingLevel as ThinkingLevel)\n\t\t\t: (settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL);\n\t}\n\n\t// Fall back to settings default\n\tif (thinkingLevel === undefined) {\n\t\tthinkingLevel = settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;\n\t}\n\n\t// Clamp to model capabilities\n\tif (!model || !model.reasoning) {\n\t\tthinkingLevel = \"off\";\n\t}\n\n\t// Apply agent profile: default to \"full\" when no explicit profile is provided.\n\t// This keeps runtime tool availability aligned with UI/profile badges.\n\tconst profile = getAgentProfile(options.profile);\n\tif (profile.name !== \"full\") {\n\t\t// Profile overrides thinking level only when caller did not explicitly pass one\n\t\tif (options.thinkingLevel === undefined && !hasExistingSession) {\n\t\t\tthinkingLevel = profile.thinkingLevel;\n\t\t\t// Re-clamp to model capabilities\n\t\t\tif (!model || !model.reasoning) {\n\t\t\t\tthinkingLevel = \"off\";\n\t\t\t}\n\t\t}\n\t}\n\n\tconst enableTaskTool = options.enableTaskTool !== false; // default true\n\tconst profileToolNames: string[] = [...profile.tools, ...(enableTaskTool ? [\"task\"] : []), \"todo_write\", \"todo_read\"].filter(\n\t\t(n) => n === \"task\" || n in allTools,\n\t);\n\n\tconst initialActiveToolNames: string[] = options.tools\n\t\t? options.tools.map((t) => t.name).filter((n) => n === \"task\" || n in allTools)\n\t\t: profileToolNames;\n\n\tlet agent: Agent;\n\n\t// Create convertToLlm wrapper that filters images if blockImages is enabled (defense-in-depth)\n\tconst convertToLlmWithBlockImages = (messages: AgentMessage[]): Message[] => {\n\t\tconst converted = convertToLlm(messages);\n\t\t// Check setting dynamically so mid-session changes take effect\n\t\tif (!settingsManager.getBlockImages()) {\n\t\t\treturn converted;\n\t\t}\n\t\t// Filter out ImageContent from all messages, replacing with text placeholder\n\t\treturn converted.map((msg) => {\n\t\t\tif (msg.role === \"user\" || msg.role === \"toolResult\") {\n\t\t\t\tconst content = msg.content;\n\t\t\t\tif (Array.isArray(content)) {\n\t\t\t\t\tconst hasImages = content.some((c) => c.type === \"image\");\n\t\t\t\t\tif (hasImages) {\n\t\t\t\t\t\tconst filteredContent = content\n\t\t\t\t\t\t\t.map((c) =>\n\t\t\t\t\t\t\t\tc.type === \"image\" ? { type: \"text\" as const, text: \"Image reading is disabled.\" } : c,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t(c, i, arr) =>\n\t\t\t\t\t\t\t\t\t// Dedupe consecutive \"Image reading is disabled.\" texts\n\t\t\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\t\t\tc.type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\tc.text === \"Image reading is disabled.\" &&\n\t\t\t\t\t\t\t\t\t\ti > 0 &&\n\t\t\t\t\t\t\t\t\t\tarr[i - 1].type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\t(arr[i - 1] as { type: \"text\"; text: string }).text === \"Image reading is disabled.\"\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\treturn { ...msg, content: filteredContent };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn msg;\n\t\t});\n\t};\n\n\tconst extensionRunnerRef: { current?: ExtensionRunner } = {};\n\n\tagent = new Agent({\n\t\tinitialState: {\n\t\t\tsystemPrompt: \"\",\n\t\t\tmodel,\n\t\t\tthinkingLevel,\n\t\t\ttools: [],\n\t\t},\n\t\tconvertToLlm: convertToLlmWithBlockImages,\n\t\tsessionId: sessionManager.getSessionId(),\n\t\ttransformContext: async (messages) => {\n\t\t\tconst runner = extensionRunnerRef.current;\n\t\t\tif (!runner) return messages;\n\t\t\treturn runner.emitContext(messages);\n\t\t},\n\t\tsteeringMode: settingsManager.getSteeringMode(),\n\t\tfollowUpMode: settingsManager.getFollowUpMode(),\n\t\ttransport: settingsManager.getTransport(),\n\t\tthinkingBudgets: settingsManager.getThinkingBudgets(),\n\t\tmaxRetryDelayMs: settingsManager.getRetrySettings().maxDelayMs,\n\t\tgetApiKey: async (provider) => {\n\t\t\t// Use the provider argument from the in-flight request;\n\t\t\t// agent.state.model may already be switched mid-turn.\n\t\t\tconst resolvedProvider = provider || agent.state.model?.provider;\n\t\t\tif (!resolvedProvider) {\n\t\t\t\tthrow new Error(\"No model selected\");\n\t\t\t}\n\t\t\tconst key = await modelRegistry.getApiKeyForProvider(resolvedProvider);\n\t\t\tif (!key) {\n\t\t\t\tconst model = agent.state.model;\n\t\t\t\tconst isOAuth = model && modelRegistry.isUsingOAuth(model);\n\t\t\t\tif (isOAuth) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Authentication failed for \"${resolvedProvider}\". ` +\n\t\t\t\t\t\t\t`Credentials may have expired or network is unavailable. ` +\n\t\t\t\t\t\t\t`Run '/login ${resolvedProvider}' to re-authenticate.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No API key found for \"${resolvedProvider}\". ` +\n\t\t\t\t\t\t`Set an API key environment variable or run '/login ${resolvedProvider}'.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn key;\n\t\t},\n\t});\n\tpatchAgentForParallelTaskExecution(agent);\n\n\t// Restore messages if session has existing data\n\tif (hasExistingSession) {\n\t\tagent.replaceMessages(existingSession.messages);\n\t\tif (!hasThinkingEntry) {\n\t\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t\t}\n\t} else {\n\t\t// Save initial model and thinking level for new sessions so they can be restored on resume\n\t\tif (model) {\n\t\t\tsessionManager.appendModelChange(model.provider, model.id);\n\t\t}\n\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t}\n\n\t// Build Task tool SubagentRunner — spawns isolated sub-sessions without circular imports\n\tconst taskToolRunner = enableTaskTool\n\t\t? async (runnerOptions: {\n\t\t\t\tsystemPrompt: string;\n\t\t\t\ttools: string[];\n\t\t\t\tprompt: string;\n\t\t\t\tcwd: string;\n\t\t\t\tmodelOverride?: string;\n\t\t\t\tsignal?: AbortSignal;\n\t\t\t\tonProgress?: (progress: TaskToolProgress) => void;\n\t\t\t}): Promise<\n\t\t\t\tstring | { output: string; sessionId?: string; stats?: { toolCallsStarted: number; toolCallsCompleted: number; assistantMessages: number } }\n\t\t\t> => {\n\t\t\t\tlet subModel = model;\n\t\t\t\tif (runnerOptions.modelOverride) {\n\t\t\t\t\tconst resolved = resolveModelBySpecifier(\n\t\t\t\t\t\tmodelRegistry,\n\t\t\t\t\t\trunnerOptions.modelOverride,\n\t\t\t\t\t\tmodel?.provider,\n\t\t\t\t\t);\n\t\t\t\t\tif (!resolved) {\n\t\t\t\t\t\tthrow new Error(`Unknown model override: ${runnerOptions.modelOverride}`);\n\t\t\t\t\t}\n\t\t\t\t\tif (!(await modelRegistry.getApiKey(resolved))) {\n\t\t\t\t\t\tthrow new Error(`No API key available for model override: ${resolved.provider}/${resolved.id}`);\n\t\t\t\t\t}\n\t\t\t\t\tsubModel = resolved;\n\t\t\t\t}\n\t\t\t\tconst { session: sub } = await createAgentSession({\n\t\t\t\t\tcwd: runnerOptions.cwd,\n\t\t\t\t\tagentDir,\n\t\t\t\t\tauthStorage,\n\t\t\t\t\tmodelRegistry,\n\t\t\t\t\tmodel: subModel,\n\t\t\t\t\ttools: createToolsFromNames(runnerOptions.cwd, runnerOptions.tools, {\n\t\t\t\t\t\tsemantic: { authStorage, agentDir },\n\t\t\t\t\t}),\n\t\t\t\t\tsessionManager: SessionManager.inMemory(),\n\t\t\t\t\tsettingsManager,\n\t\t\t\t\tenableTaskTool: false, // prevent recursive subagent spawning\n\t\t\t\t});\n\n\t\t\t\t// Apply profile system prompt by appending it to the base after session init\n\t\t\t\tif (runnerOptions.systemPrompt) {\n\t\t\t\t\tconst base = sub.agent.state.systemPrompt;\n\t\t\t\t\tsub.agent.setSystemPrompt(\n\t\t\t\t\t\tbase ? `${base}\\n\\n${runnerOptions.systemPrompt}` : runnerOptions.systemPrompt,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Collect all assistant text from the sub-session\n\t\t\t\tconst chunks: string[] = [];\n\t\t\t\tconst abortSubagent = (): void => {\n\t\t\t\t\tvoid sub.abort();\n\t\t\t\t};\n\t\t\t\tif (runnerOptions.signal?.aborted) {\n\t\t\t\t\tabortSubagent();\n\t\t\t\t\tthrow new Error(\"Operation aborted\");\n\t\t\t\t}\n\t\t\t\trunnerOptions.signal?.addEventListener(\"abort\", abortSubagent, { once: true });\n\t\t\t\tconst progressState = {\n\t\t\t\t\ttoolCallsStarted: 0,\n\t\t\t\t\ttoolCallsCompleted: 0,\n\t\t\t\t\tassistantMessages: 0,\n\t\t\t\t\tactiveTool: undefined as string | undefined,\n\t\t\t\t};\n\t\t\t\tconst trimInline = (value: string, max = 60): string => {\n\t\t\t\t\tconst compact = value.trim().replace(/\\s+/g, \" \");\n\t\t\t\t\treturn compact.length > max ? `${compact.slice(0, Math.max(1, max - 3))}...` : compact;\n\t\t\t\t};\n\t\t\t\tconst summarizeToolTarget = (toolName: string, args: unknown): string => {\n\t\t\t\t\tif (!args || typeof args !== \"object\") return `running ${toolName}`;\n\t\t\t\t\tconst record = args as Record<string, unknown>;\n\t\t\t\t\tconst filePath =\n\t\t\t\t\t\ttypeof record.file_path === \"string\"\n\t\t\t\t\t\t\t? record.file_path\n\t\t\t\t\t\t\t: typeof record.path === \"string\"\n\t\t\t\t\t\t\t\t? record.path\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (filePath) {\n\t\t\t\t\t\treturn `running ${toolName} (${trimInline(filePath, 50)})`;\n\t\t\t\t\t}\n\t\t\t\t\tconst command =\n\t\t\t\t\t\ttypeof record.command === \"string\"\n\t\t\t\t\t\t\t? record.command\n\t\t\t\t\t\t\t: typeof record.cmd === \"string\"\n\t\t\t\t\t\t\t\t? record.cmd\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (command) {\n\t\t\t\t\t\treturn `running ${toolName} (${trimInline(command, 50)})`;\n\t\t\t\t\t}\n\t\t\t\t\treturn `running ${toolName}`;\n\t\t\t\t};\n\t\t\t\tconst emitProgress = (phase: TaskToolProgressPhase, message: string, activeTool?: string): void => {\n\t\t\t\t\tprogressState.activeTool = activeTool;\n\t\t\t\t\trunnerOptions.onProgress?.({\n\t\t\t\t\t\tkind: \"subagent_progress\",\n\t\t\t\t\t\tphase,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tcwd: runnerOptions.cwd,\n\t\t\t\t\t\tactiveTool: progressState.activeTool,\n\t\t\t\t\t\ttoolCallsStarted: progressState.toolCallsStarted,\n\t\t\t\t\t\ttoolCallsCompleted: progressState.toolCallsCompleted,\n\t\t\t\t\t\tassistantMessages: progressState.assistantMessages,\n\t\t\t\t\t});\n\t\t\t\t};\n\t\t\t\temitProgress(\"starting\", \"booting subagent\", undefined);\n\n\t\t\t\ttry {\n\t\t\t\t\tsub.subscribe((event) => {\n\t\t\t\t\t\tif (event.type === \"message_end\" && event.message.role === \"assistant\") {\n\t\t\t\t\t\t\tprogressState.assistantMessages += 1;\n\t\t\t\t\t\t\tfor (const part of event.message.content) {\n\t\t\t\t\t\t\t\tif (part.type === \"text\" && part.text.trim()) {\n\t\t\t\t\t\t\t\t\tchunks.push(part.text.trim());\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (chunks.length > 0) {\n\t\t\t\t\t\t\t\temitProgress(\"responding\", \"drafting response\", undefined);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event.type === \"tool_execution_start\") {\n\t\t\t\t\t\t\tprogressState.toolCallsStarted += 1;\n\t\t\t\t\t\t\tconst toolName = event.toolName ?? \"tool\";\n\t\t\t\t\t\t\temitProgress(\"running\", summarizeToolTarget(toolName, event.args), toolName);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event.type === \"tool_execution_end\") {\n\t\t\t\t\t\t\tprogressState.toolCallsCompleted += 1;\n\t\t\t\t\t\t\tconst toolName = event.toolName ?? \"tool\";\n\t\t\t\t\t\t\tconst nextActive = progressState.activeTool === toolName ? undefined : progressState.activeTool;\n\t\t\t\t\t\t\temitProgress(\"running\", `completed ${toolName}`, nextActive);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tawait sub.prompt(runnerOptions.prompt, { skipIosmAutopilot: true });\n\t\t\t\t\tif (runnerOptions.signal?.aborted) {\n\t\t\t\t\t\tthrow new Error(\"Operation aborted\");\n\t\t\t\t\t}\n\t\t\t\t\temitProgress(\"responding\", \"finalizing response\", undefined);\n\t\t\t\t\tconst sessionId = sub.sessionManager.getSessionId();\n\t\t\t\t\treturn {\n\t\t\t\t\t\toutput: chunks.join(\"\\n\\n\"),\n\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\tstats: {\n\t\t\t\t\t\t\ttoolCallsStarted: progressState.toolCallsStarted,\n\t\t\t\t\t\t\ttoolCallsCompleted: progressState.toolCallsCompleted,\n\t\t\t\t\t\t\tassistantMessages: progressState.assistantMessages,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t} finally {\n\t\t\t\t\trunnerOptions.signal?.removeEventListener(\"abort\", abortSubagent);\n\t\t\t\t\tsub.dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t: undefined;\n\n\tlet sessionRef: AgentSession | undefined;\n\tconst initialCustomSubagents = loadCustomSubagents({ cwd, agentDir });\n\tfor (const diagnostic of initialCustomSubagents.diagnostics) {\n\t\tconsole.warn(`Warning: invalid subagent ${diagnostic.path}: ${diagnostic.message}`);\n\t}\n\tconst taskTool = taskToolRunner\n\t\t? createTaskTool(cwd, taskToolRunner, {\n\t\t\t\tresolveCustomSubagent: (name) => {\n\t\t\t\t\t// Resolve against live on-disk definitions so newly created agents\n\t\t\t\t\t// are immediately callable in the same interactive session.\n\t\t\t\t\tconst current = loadCustomSubagents({ cwd, agentDir });\n\t\t\t\t\tconst resolvedName = resolveCustomSubagentReference(name, current.agents);\n\t\t\t\t\treturn resolvedName ? current.agents.find((agent) => agent.name === resolvedName) : undefined;\n\t\t\t\t},\n\t\t\t\tavailableCustomSubagents: initialCustomSubagents.agents.map((agent) => agent.name),\n\t\t\t\tavailableCustomSubagentHints: initialCustomSubagents.agents.map((agent) => ({\n\t\t\t\t\tname: agent.name,\n\t\t\t\t\tdescription: agent.description,\n\t\t\t\t})),\n\t\t\t\tgetMetaMessages: () => sessionRef?.getMetaMessages() ?? [],\n\t\t\t})\n\t\t: undefined;\n\n\t// Wire in ask_user, task tool, and any caller-supplied custom tools\n\tconst baseCustomTools: ToolDefinition[] = [\n\t\t...(options.customTools ?? []).filter(\n\t\t\t(t) => t.name !== \"ask_user\" && t.name !== \"task\",\n\t\t),\n\t\t...(taskTool ? [taskTool as unknown as ToolDefinition] : []),\n\t];\n\n\tconst customTools: ToolDefinition[] | undefined = options.enableAskUserTool\n\t\t? [\n\t\t\t\t...baseCustomTools.filter((tool) => tool.name !== \"ask_user\"),\n\t\t\t\tcreateAskUserTool() as unknown as ToolDefinition,\n\t\t\t]\n\t\t: baseCustomTools.length > 0\n\t\t\t? baseCustomTools\n\t\t\t: options.customTools;\n\n\tconst session = new AgentSession({\n\t\tagent,\n\t\tsessionManager,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tscopedModels: options.scopedModels,\n\t\tresourceLoader,\n\t\tcustomTools,\n\t\tmodelRegistry,\n\t\tinitialActiveToolNames,\n\t\textensionRunnerRef,\n\t\tsystemPromptSuffix: profile?.systemPromptAppend || undefined,\n\t\tiosmAutopilotEnabled: profile?.name === \"iosm\",\n\t});\n\tsessionRef = session;\n\tconst extensionsResult = resourceLoader.getExtensions();\n\n\treturn {\n\t\tsession,\n\t\textensionsResult,\n\t\tmodelFallbackMessage,\n\t};\n}\n"]}
1
+ {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAyC,MAAM,6BAA6B,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AACrF,O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cAAc;QACd,eAAe;QACf,GAAG;QACH,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,cAAc;QACd,WAAW;QACX,aAAa;QACb,sBAAsB;QACtB,kBAAkB;QAClB,kBAAkB,EAAE,OAAO,EAAE,kBAAkB,IAAI,SAAS;QAC5D,oBAAoB,EAAE,OAAO,EAAE,IAAI,KAAK,MAAM;KAC9C,CAAC,CAAC;IACH,UAAU,GAAG,OAAO,CAAC;IACrB,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;IAExD,OAAO;QACN,OAAO;QACP,gBAAgB;QAChB,oBAAoB;KACpB,CAAC;AACH,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport { Agent, type AgentMessage, type ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { Message, Model } from \"@mariozechner/pi-ai\";\nimport { getAgentDir, getDocsPath } from \"../config.js\";\nimport { createAskUserTool } from \"./ask-user-tool.js\";\nimport { AgentSession } from \"./agent-session.js\";\nimport { AuthStorage } from \"./auth-storage.js\";\nimport { DEFAULT_THINKING_LEVEL } from \"./defaults.js\";\nimport type { ExtensionRunner, LoadExtensionsResult, ToolDefinition } from \"./extensions/index.js\";\nimport { convertToLlm } from \"./messages.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\nimport { findInitialModel } from \"./model-resolver.js\";\nimport type { ResourceLoader } from \"./resource-loader.js\";\nimport { DefaultResourceLoader } from \"./resource-loader.js\";\nimport { SessionManager } from \"./session-manager.js\";\nimport { SettingsManager } from \"./settings-manager.js\";\nimport type { SharedMemoryContext } from \"./shared-memory.js\";\nimport { loadCustomSubagents, resolveCustomSubagentReference } from \"./subagents.js\";\nimport { time } from \"./timings.js\";\nimport { createSharedMemoryReadTool, createSharedMemoryWriteTool } from \"./tools/shared-memory.js\";\nimport { patchAgentForParallelTaskExecution } from \"./parallel-task-agent.js\";\nimport {\n\tallTools,\n\tastGrepTool,\n\tbashTool,\n\tcodingTools,\n\tcombyTool,\n\tcreateAstGrepTool,\n\tcreateBashTool,\n\tcreateCodingTools,\n\tcreateCombyTool,\n\tcreateEditTool,\n\tcreateFdTool,\n\tcreateFindTool,\n\tcreateGrepTool,\n\tcreateJqTool,\n\tcreateLsTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateRgTool,\n\tcreateSedTool,\n\tcreateSemgrepTool,\n\tcreateSemanticSearchTool,\n\tcreateTaskTool,\n\tcreateToolsFromNames,\n\tcreateWriteTool,\n\teditTool,\n\tfdTool,\n\tfindTool,\n\tgrepTool,\n\tjqTool,\n\tlsTool,\n\treadOnlyTools,\n\treadTool,\n\trgTool,\n\tsedTool,\n\tsemanticSearchTool,\n\tsemgrepTool,\n\ttodoReadTool,\n\ttodoWriteTool,\n\ttype TaskToolProgress,\n\ttype TaskToolProgressPhase,\n\ttype Tool,\n\ttype ToolName,\n\tyqTool,\n\tcreateYqTool,\n\twriteTool,\n} from \"./tools/index.js\";\nimport { getAgentProfile, type AgentProfileName } from \"./agent-profiles.js\";\n\nexport interface CreateAgentSessionOptions {\n\t/** Working directory for project-local discovery. Default: process.cwd() */\n\tcwd?: string;\n\t/** Global config directory. Default: ~/.iosm/agent */\n\tagentDir?: string;\n\n\t/** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */\n\tauthStorage?: AuthStorage;\n\t/** Model registry. Default: new ModelRegistry(authStorage, agentDir/models.json) */\n\tmodelRegistry?: ModelRegistry;\n\n\t/** Model to use. Default: from settings, else first available */\n\tmodel?: Model<any>;\n\t/** Require explicit model selection by the user; disables automatic model fallback/selection for new sessions. */\n\trequireExplicitModelSelection?: boolean;\n\t/** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */\n\tthinkingLevel?: ThinkingLevel;\n\t/** Models available for cycling (Ctrl+P in interactive mode) */\n\tscopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\n\t/** Built-in tools to use. Default: active profile tools (profile defaults to \"full\"). */\n\ttools?: Tool[];\n\t/** Custom tools to register (in addition to built-in tools). */\n\tcustomTools?: ToolDefinition[];\n\t/** Enable the interactive ask_user clarification tool. Best used in interactive or RPC sessions. */\n\tenableAskUserTool?: boolean;\n\n\t/** Resource loader. When omitted, DefaultResourceLoader is used. */\n\tresourceLoader?: ResourceLoader;\n\n\t/** Session manager. Default: SessionManager.create(cwd) */\n\tsessionManager?: SessionManager;\n\n\t/** Settings manager. Default: SettingsManager.create(cwd, agentDir) */\n\tsettingsManager?: SettingsManager;\n\n\t/**\n\t * Agent profile name. Overrides tools and thinkingLevel with profile defaults.\n\t * Profiles: explore, plan, iosm_analyst, iosm_verifier, cycle_planner, full (default).\n\t */\n\tprofile?: AgentProfileName | string;\n\n\t/**\n\t * Whether to register the Task tool (subagent spawning).\n\t * Default: true for interactive/print sessions; false for subagent sessions to avoid recursion.\n\t */\n\tenableTaskTool?: boolean;\n}\n\n/** Result from createAgentSession */\nexport interface CreateAgentSessionResult {\n\t/** The created session */\n\tsession: AgentSession;\n\t/** Extensions result (for UI context setup in interactive mode) */\n\textensionsResult: LoadExtensionsResult;\n\t/** Warning if session was restored with a different model than saved */\n\tmodelFallbackMessage?: string;\n}\n\n// Re-exports\n\nexport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tSlashCommandInfo,\n\tSlashCommandLocation,\n\tSlashCommandSource,\n\tToolDefinition,\n} from \"./extensions/index.js\";\nexport type { PromptTemplate } from \"./prompt-templates.js\";\nexport type { Skill } from \"./skills.js\";\nexport type { Tool } from \"./tools/index.js\";\n\n\texport {\n\t\tcreateAskUserTool,\n\t\t// Pre-built tools (use process.cwd())\n\t\treadTool,\n\t\tbashTool,\n\t\teditTool,\n\t\twriteTool,\n\t\tgrepTool,\n\t\tfindTool,\n\t\tlsTool,\n\t\trgTool,\n\t\tfdTool,\n\t\tastGrepTool,\n\t\tcombyTool,\n\t\tjqTool,\n\t\tyqTool,\n\t\tsemgrepTool,\n\t\tsedTool,\n\t\tsemanticSearchTool,\n\t\tcodingTools,\n\t\treadOnlyTools,\n\t\tallTools as allBuiltInTools,\n\t\t// Tool factories (for custom cwd)\n\t\tcreateCodingTools,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\t\tcreateWriteTool,\n\t\tcreateGrepTool,\n\t\tcreateFindTool,\n\t\tcreateLsTool,\n\t\tcreateRgTool,\n\t\tcreateFdTool,\n\t\tcreateAstGrepTool,\n\t\tcreateCombyTool,\n\t\tcreateJqTool,\n\t\tcreateYqTool,\n\t\tcreateSemgrepTool,\n\t\tcreateSedTool,\n\t\tcreateSemanticSearchTool,\n\t};\n\n// Helper Functions\n\nfunction getDefaultAgentDir(): string {\n\treturn getAgentDir();\n}\n\nfunction resolveModelBySpecifier(\n\tmodelRegistry: ModelRegistry,\n\tspecifier: string,\n\tpreferredProvider?: string,\n): Model<any> | undefined {\n\tconst raw = specifier.trim();\n\tif (!raw) return undefined;\n\tconst slash = raw.indexOf(\"/\");\n\tif (slash > 0 && slash < raw.length - 1) {\n\t\tconst provider = raw.slice(0, slash);\n\t\tconst modelId = raw.slice(slash + 1);\n\t\treturn modelRegistry.find(provider, modelId);\n\t}\n\n\tconst all = modelRegistry.getAll().filter((candidate) => candidate.id === raw);\n\tif (all.length === 0) return undefined;\n\tif (preferredProvider) {\n\t\tconst preferred = all.find((candidate) => candidate.provider === preferredProvider);\n\t\tif (preferred) return preferred;\n\t}\n\treturn all[0];\n}\n\n/**\n * Create an AgentSession with the specified options.\n *\n * @example\n * ```typescript\n * // Minimal - uses defaults\n * const { session } = await createAgentSession();\n *\n * // With explicit model\n * import { getModel } from '@mariozechner/pi-ai';\n * const { session } = await createAgentSession({\n * model: getModel('anthropic', 'claude-opus-4-5'),\n * thinkingLevel: 'high',\n * });\n *\n * // Continue previous session\n * const { session, modelFallbackMessage } = await createAgentSession({\n * continueSession: true,\n * });\n *\n * // Full control\n * const loader = new DefaultResourceLoader({\n * cwd: process.cwd(),\n * agentDir: getAgentDir(),\n * settingsManager: SettingsManager.create(),\n * });\n * await loader.reload();\n * const { session } = await createAgentSession({\n * model: myModel,\n * tools: [readTool, bashTool],\n * resourceLoader: loader,\n * sessionManager: SessionManager.inMemory(),\n * });\n * ```\n */\nexport async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {\n\tconst cwd = options.cwd ?? process.cwd();\n\tconst agentDir = options.agentDir ?? getDefaultAgentDir();\n\tconst contextProfile = options.profile?.toString().toLowerCase() === \"iosm\" ? \"iosm\" : \"standard\";\n\tlet resourceLoader = options.resourceLoader;\n\n\t// Use provided or create AuthStorage and ModelRegistry\n\tconst authPath = options.agentDir ? join(agentDir, \"auth.json\") : undefined;\n\tconst modelsPath = options.agentDir ? join(agentDir, \"models.json\") : undefined;\n\tconst authStorage = options.authStorage ?? AuthStorage.create(authPath);\n\tconst modelRegistry = options.modelRegistry ?? new ModelRegistry(authStorage, modelsPath);\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst sessionManager = options.sessionManager ?? SessionManager.create(cwd);\n\n\tif (!resourceLoader) {\n\t\tresourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager, contextProfile });\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t}\n\n\t// Check if session has existing data to restore\n\tconst existingSession = sessionManager.buildSessionContext();\n\tconst hasExistingSession = existingSession.messages.length > 0;\n\tconst hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === \"thinking_level_change\");\n\n\tlet model = options.model;\n\tlet modelFallbackMessage: string | undefined;\n\tconst requireExplicitModelSelection = options.requireExplicitModelSelection === true;\n\n\t// If session has data, try to restore model from it\n\tif (!model && hasExistingSession && existingSession.model) {\n\t\tconst restoredModel = modelRegistry.find(existingSession.model.provider, existingSession.model.modelId);\n\t\tif (restoredModel && (await modelRegistry.getApiKey(restoredModel))) {\n\t\t\tmodel = restoredModel;\n\t\t}\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = `Could not restore model ${existingSession.model.provider}/${existingSession.model.modelId}`;\n\t\t}\n\t}\n\n\t// If still no model, use findInitialModel unless explicit selection is required.\n\tif (!model && !requireExplicitModelSelection) {\n\t\tconst result = await findInitialModel({\n\t\t\tscopedModels: options.scopedModels ?? [],\n\t\t\tisContinuing: hasExistingSession,\n\t\t\tdefaultProvider: settingsManager.getDefaultProvider(),\n\t\t\tdefaultModelId: settingsManager.getDefaultModel(),\n\t\t\tdefaultThinkingLevel: settingsManager.getDefaultThinkingLevel(),\n\t\t\tmodelRegistry,\n\t\t});\n\t\tmodel = result.model;\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = `No models available. Use /login or set an API key environment variable. See ${join(getDocsPath(), \"providers.md\")}. Then use /model to select a model.`;\n\t\t} else if (modelFallbackMessage) {\n\t\t\tmodelFallbackMessage += `. Using ${model.provider}/${model.id}`;\n\t\t}\n\t} else if (!model && requireExplicitModelSelection && !hasExistingSession) {\n\t\tmodelFallbackMessage = \"No model selected. Choose one with /model or pass --provider and --model.\";\n\t}\n\n\tlet thinkingLevel = options.thinkingLevel;\n\n\t// If session has data, restore thinking level from it\n\tif (thinkingLevel === undefined && hasExistingSession) {\n\t\tthinkingLevel = hasThinkingEntry\n\t\t\t? (existingSession.thinkingLevel as ThinkingLevel)\n\t\t\t: (settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL);\n\t}\n\n\t// Fall back to settings default\n\tif (thinkingLevel === undefined) {\n\t\tthinkingLevel = settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;\n\t}\n\n\t// Clamp to model capabilities\n\tif (!model || !model.reasoning) {\n\t\tthinkingLevel = \"off\";\n\t}\n\n\t// Apply agent profile: default to \"full\" when no explicit profile is provided.\n\t// This keeps runtime tool availability aligned with UI/profile badges.\n\tconst profile = getAgentProfile(options.profile);\n\tif (profile.name !== \"full\") {\n\t\t// Profile overrides thinking level only when caller did not explicitly pass one\n\t\tif (options.thinkingLevel === undefined && !hasExistingSession) {\n\t\t\tthinkingLevel = profile.thinkingLevel;\n\t\t\t// Re-clamp to model capabilities\n\t\t\tif (!model || !model.reasoning) {\n\t\t\t\tthinkingLevel = \"off\";\n\t\t\t}\n\t\t}\n\t}\n\n\tconst enableTaskTool = options.enableTaskTool !== false; // default true\n\tconst profileToolNames: string[] = [...profile.tools, ...(enableTaskTool ? [\"task\"] : []), \"todo_write\", \"todo_read\"].filter(\n\t\t(n) => n === \"task\" || n in allTools,\n\t);\n\n\tconst initialActiveToolNames: string[] = options.tools\n\t\t? options.tools.map((t) => t.name).filter((n) => n === \"task\" || n in allTools)\n\t\t: profileToolNames;\n\n\tlet agent: Agent;\n\n\t// Create convertToLlm wrapper that filters images if blockImages is enabled (defense-in-depth)\n\tconst convertToLlmWithBlockImages = (messages: AgentMessage[]): Message[] => {\n\t\tconst converted = convertToLlm(messages);\n\t\t// Check setting dynamically so mid-session changes take effect\n\t\tif (!settingsManager.getBlockImages()) {\n\t\t\treturn converted;\n\t\t}\n\t\t// Filter out ImageContent from all messages, replacing with text placeholder\n\t\treturn converted.map((msg) => {\n\t\t\tif (msg.role === \"user\" || msg.role === \"toolResult\") {\n\t\t\t\tconst content = msg.content;\n\t\t\t\tif (Array.isArray(content)) {\n\t\t\t\t\tconst hasImages = content.some((c) => c.type === \"image\");\n\t\t\t\t\tif (hasImages) {\n\t\t\t\t\t\tconst filteredContent = content\n\t\t\t\t\t\t\t.map((c) =>\n\t\t\t\t\t\t\t\tc.type === \"image\" ? { type: \"text\" as const, text: \"Image reading is disabled.\" } : c,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t(c, i, arr) =>\n\t\t\t\t\t\t\t\t\t// Dedupe consecutive \"Image reading is disabled.\" texts\n\t\t\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\t\t\tc.type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\tc.text === \"Image reading is disabled.\" &&\n\t\t\t\t\t\t\t\t\t\ti > 0 &&\n\t\t\t\t\t\t\t\t\t\tarr[i - 1].type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\t(arr[i - 1] as { type: \"text\"; text: string }).text === \"Image reading is disabled.\"\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\treturn { ...msg, content: filteredContent };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn msg;\n\t\t});\n\t};\n\n\tconst extensionRunnerRef: { current?: ExtensionRunner } = {};\n\n\tagent = new Agent({\n\t\tinitialState: {\n\t\t\tsystemPrompt: \"\",\n\t\t\tmodel,\n\t\t\tthinkingLevel,\n\t\t\ttools: [],\n\t\t},\n\t\tconvertToLlm: convertToLlmWithBlockImages,\n\t\tsessionId: sessionManager.getSessionId(),\n\t\ttransformContext: async (messages) => {\n\t\t\tconst runner = extensionRunnerRef.current;\n\t\t\tif (!runner) return messages;\n\t\t\treturn runner.emitContext(messages);\n\t\t},\n\t\tsteeringMode: settingsManager.getSteeringMode(),\n\t\tfollowUpMode: settingsManager.getFollowUpMode(),\n\t\ttransport: settingsManager.getTransport(),\n\t\tthinkingBudgets: settingsManager.getThinkingBudgets(),\n\t\tmaxRetryDelayMs: settingsManager.getRetrySettings().maxDelayMs,\n\t\tgetApiKey: async (provider) => {\n\t\t\t// Use the provider argument from the in-flight request;\n\t\t\t// agent.state.model may already be switched mid-turn.\n\t\t\tconst resolvedProvider = provider || agent.state.model?.provider;\n\t\t\tif (!resolvedProvider) {\n\t\t\t\tthrow new Error(\"No model selected\");\n\t\t\t}\n\t\t\tconst key = await modelRegistry.getApiKeyForProvider(resolvedProvider);\n\t\t\tif (!key) {\n\t\t\t\tconst model = agent.state.model;\n\t\t\t\tconst isOAuth = model && modelRegistry.isUsingOAuth(model);\n\t\t\t\tif (isOAuth) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Authentication failed for \"${resolvedProvider}\". ` +\n\t\t\t\t\t\t\t`Credentials may have expired or network is unavailable. ` +\n\t\t\t\t\t\t\t`Run '/login ${resolvedProvider}' to re-authenticate.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No API key found for \"${resolvedProvider}\". ` +\n\t\t\t\t\t\t`Set an API key environment variable or run '/login ${resolvedProvider}'.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn key;\n\t\t},\n\t});\n\tpatchAgentForParallelTaskExecution(agent);\n\n\t// Restore messages if session has existing data\n\tif (hasExistingSession) {\n\t\tagent.replaceMessages(existingSession.messages);\n\t\tif (!hasThinkingEntry) {\n\t\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t\t}\n\t} else {\n\t\t// Save initial model and thinking level for new sessions so they can be restored on resume\n\t\tif (model) {\n\t\t\tsessionManager.appendModelChange(model.provider, model.id);\n\t\t}\n\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t}\n\n\t// Build Task tool SubagentRunner — spawns isolated sub-sessions without circular imports\n\tconst taskToolRunner = enableTaskTool\n\t\t? async (runnerOptions: {\n\t\t\t\tsystemPrompt: string;\n\t\t\t\ttools: string[];\n\t\t\t\tprompt: string;\n\t\t\t\tcwd: string;\n\t\t\t\tmodelOverride?: string;\n\t\t\t\tsharedMemoryContext?: SharedMemoryContext;\n\t\t\t\tsignal?: AbortSignal;\n\t\t\t\tonProgress?: (progress: TaskToolProgress) => void;\n\t\t\t}): Promise<\n\t\t\t\tstring | { output: string; sessionId?: string; stats?: { toolCallsStarted: number; toolCallsCompleted: number; assistantMessages: number } }\n\t\t\t> => {\n\t\t\t\tlet subModel = model;\n\t\t\t\tif (runnerOptions.modelOverride) {\n\t\t\t\t\tconst resolved = resolveModelBySpecifier(\n\t\t\t\t\t\tmodelRegistry,\n\t\t\t\t\t\trunnerOptions.modelOverride,\n\t\t\t\t\t\tmodel?.provider,\n\t\t\t\t\t);\n\t\t\t\t\tif (!resolved) {\n\t\t\t\t\t\tthrow new Error(`Unknown model override: ${runnerOptions.modelOverride}`);\n\t\t\t\t\t}\n\t\t\t\t\tif (!(await modelRegistry.getApiKey(resolved))) {\n\t\t\t\t\t\tthrow new Error(`No API key available for model override: ${resolved.provider}/${resolved.id}`);\n\t\t\t\t\t}\n\t\t\t\t\tsubModel = resolved;\n\t\t\t\t}\n\t\t\t\tconst sharedMemoryTools: ToolDefinition[] | undefined = runnerOptions.sharedMemoryContext\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tcreateSharedMemoryWriteTool(runnerOptions.sharedMemoryContext) as unknown as ToolDefinition,\n\t\t\t\t\t\t\tcreateSharedMemoryReadTool(runnerOptions.sharedMemoryContext) as unknown as ToolDefinition,\n\t\t\t\t\t\t]\n\t\t\t\t\t: undefined;\n\t\t\t\tconst { session: sub } = await createAgentSession({\n\t\t\t\t\tcwd: runnerOptions.cwd,\n\t\t\t\t\tagentDir,\n\t\t\t\t\tauthStorage,\n\t\t\t\t\tmodelRegistry,\n\t\t\t\t\tmodel: subModel,\n\t\t\t\t\ttools: createToolsFromNames(runnerOptions.cwd, runnerOptions.tools, {\n\t\t\t\t\t\tsemantic: { authStorage, agentDir },\n\t\t\t\t\t}),\n\t\t\t\t\tcustomTools: sharedMemoryTools,\n\t\t\t\t\tsessionManager: SessionManager.inMemory(),\n\t\t\t\t\tsettingsManager,\n\t\t\t\t\tenableTaskTool: false, // prevent recursive subagent spawning\n\t\t\t\t});\n\n\t\t\t\t// Apply profile system prompt by appending it to the base after session init\n\t\t\t\tif (runnerOptions.systemPrompt) {\n\t\t\t\t\tconst base = sub.agent.state.systemPrompt;\n\t\t\t\t\tsub.agent.setSystemPrompt(\n\t\t\t\t\t\tbase ? `${base}\\n\\n${runnerOptions.systemPrompt}` : runnerOptions.systemPrompt,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Collect all assistant text from the sub-session\n\t\t\t\tconst chunks: string[] = [];\n\t\t\t\tconst abortSubagent = (): void => {\n\t\t\t\t\tvoid sub.abort();\n\t\t\t\t};\n\t\t\t\tif (runnerOptions.signal?.aborted) {\n\t\t\t\t\tabortSubagent();\n\t\t\t\t\tthrow new Error(\"Operation aborted\");\n\t\t\t\t}\n\t\t\t\trunnerOptions.signal?.addEventListener(\"abort\", abortSubagent, { once: true });\n\t\t\t\tconst progressState = {\n\t\t\t\t\ttoolCallsStarted: 0,\n\t\t\t\t\ttoolCallsCompleted: 0,\n\t\t\t\t\tassistantMessages: 0,\n\t\t\t\t\tactiveTool: undefined as string | undefined,\n\t\t\t\t};\n\t\t\t\tconst trimInline = (value: string, max = 60): string => {\n\t\t\t\t\tconst compact = value.trim().replace(/\\s+/g, \" \");\n\t\t\t\t\treturn compact.length > max ? `${compact.slice(0, Math.max(1, max - 3))}...` : compact;\n\t\t\t\t};\n\t\t\t\tconst summarizeToolTarget = (toolName: string, args: unknown): string => {\n\t\t\t\t\tif (!args || typeof args !== \"object\") return `running ${toolName}`;\n\t\t\t\t\tconst record = args as Record<string, unknown>;\n\t\t\t\t\tconst filePath =\n\t\t\t\t\t\ttypeof record.file_path === \"string\"\n\t\t\t\t\t\t\t? record.file_path\n\t\t\t\t\t\t\t: typeof record.path === \"string\"\n\t\t\t\t\t\t\t\t? record.path\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (filePath) {\n\t\t\t\t\t\treturn `running ${toolName} (${trimInline(filePath, 50)})`;\n\t\t\t\t\t}\n\t\t\t\t\tconst command =\n\t\t\t\t\t\ttypeof record.command === \"string\"\n\t\t\t\t\t\t\t? record.command\n\t\t\t\t\t\t\t: typeof record.cmd === \"string\"\n\t\t\t\t\t\t\t\t? record.cmd\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (command) {\n\t\t\t\t\t\treturn `running ${toolName} (${trimInline(command, 50)})`;\n\t\t\t\t\t}\n\t\t\t\t\treturn `running ${toolName}`;\n\t\t\t\t};\n\t\t\t\tconst emitProgress = (phase: TaskToolProgressPhase, message: string, activeTool?: string): void => {\n\t\t\t\t\tprogressState.activeTool = activeTool;\n\t\t\t\t\trunnerOptions.onProgress?.({\n\t\t\t\t\t\tkind: \"subagent_progress\",\n\t\t\t\t\t\tphase,\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tcwd: runnerOptions.cwd,\n\t\t\t\t\t\tactiveTool: progressState.activeTool,\n\t\t\t\t\t\ttoolCallsStarted: progressState.toolCallsStarted,\n\t\t\t\t\t\ttoolCallsCompleted: progressState.toolCallsCompleted,\n\t\t\t\t\t\tassistantMessages: progressState.assistantMessages,\n\t\t\t\t\t});\n\t\t\t\t};\n\t\t\t\temitProgress(\"starting\", \"booting subagent\", undefined);\n\n\t\t\t\ttry {\n\t\t\t\t\tsub.subscribe((event) => {\n\t\t\t\t\t\tif (event.type === \"message_end\" && event.message.role === \"assistant\") {\n\t\t\t\t\t\t\tprogressState.assistantMessages += 1;\n\t\t\t\t\t\t\tfor (const part of event.message.content) {\n\t\t\t\t\t\t\t\tif (part.type === \"text\" && part.text.trim()) {\n\t\t\t\t\t\t\t\t\tchunks.push(part.text.trim());\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (chunks.length > 0) {\n\t\t\t\t\t\t\t\temitProgress(\"responding\", \"drafting response\", undefined);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event.type === \"tool_execution_start\") {\n\t\t\t\t\t\t\tprogressState.toolCallsStarted += 1;\n\t\t\t\t\t\t\tconst toolName = event.toolName ?? \"tool\";\n\t\t\t\t\t\t\temitProgress(\"running\", summarizeToolTarget(toolName, event.args), toolName);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (event.type === \"tool_execution_end\") {\n\t\t\t\t\t\t\tprogressState.toolCallsCompleted += 1;\n\t\t\t\t\t\t\tconst toolName = event.toolName ?? \"tool\";\n\t\t\t\t\t\t\tconst nextActive = progressState.activeTool === toolName ? undefined : progressState.activeTool;\n\t\t\t\t\t\t\temitProgress(\"running\", `completed ${toolName}`, nextActive);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tawait sub.prompt(runnerOptions.prompt, { skipIosmAutopilot: true });\n\t\t\t\t\tif (runnerOptions.signal?.aborted) {\n\t\t\t\t\t\tthrow new Error(\"Operation aborted\");\n\t\t\t\t\t}\n\t\t\t\t\temitProgress(\"responding\", \"finalizing response\", undefined);\n\t\t\t\t\tconst sessionId = sub.sessionManager.getSessionId();\n\t\t\t\t\treturn {\n\t\t\t\t\t\toutput: chunks.join(\"\\n\\n\"),\n\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\tstats: {\n\t\t\t\t\t\t\ttoolCallsStarted: progressState.toolCallsStarted,\n\t\t\t\t\t\t\ttoolCallsCompleted: progressState.toolCallsCompleted,\n\t\t\t\t\t\t\tassistantMessages: progressState.assistantMessages,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t} finally {\n\t\t\t\t\trunnerOptions.signal?.removeEventListener(\"abort\", abortSubagent);\n\t\t\t\t\tsub.dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t: undefined;\n\n\tlet sessionRef: AgentSession | undefined;\n\tconst initialCustomSubagents = loadCustomSubagents({ cwd, agentDir });\n\tfor (const diagnostic of initialCustomSubagents.diagnostics) {\n\t\tconsole.warn(`Warning: invalid subagent ${diagnostic.path}: ${diagnostic.message}`);\n\t}\n\tconst taskTool = taskToolRunner\n\t\t? createTaskTool(cwd, taskToolRunner, {\n\t\t\t\tresolveCustomSubagent: (name) => {\n\t\t\t\t\t// Resolve against live on-disk definitions so newly created agents\n\t\t\t\t\t// are immediately callable in the same interactive session.\n\t\t\t\t\tconst current = loadCustomSubagents({ cwd, agentDir });\n\t\t\t\t\tconst resolvedName = resolveCustomSubagentReference(name, current.agents);\n\t\t\t\t\treturn resolvedName ? current.agents.find((agent) => agent.name === resolvedName) : undefined;\n\t\t\t\t},\n\t\t\t\tavailableCustomSubagents: initialCustomSubagents.agents.map((agent) => agent.name),\n\t\t\t\tavailableCustomSubagentHints: initialCustomSubagents.agents.map((agent) => ({\n\t\t\t\t\tname: agent.name,\n\t\t\t\t\tdescription: agent.description,\n\t\t\t\t})),\n\t\t\t\tgetMetaMessages: () => sessionRef?.getMetaMessages() ?? [],\n\t\t\t})\n\t\t: undefined;\n\n\t// Wire in ask_user, task tool, and any caller-supplied custom tools\n\tconst baseCustomTools: ToolDefinition[] = [\n\t\t...(options.customTools ?? []).filter(\n\t\t\t(t) => t.name !== \"ask_user\" && t.name !== \"task\",\n\t\t),\n\t\t...(taskTool ? [taskTool as unknown as ToolDefinition] : []),\n\t];\n\n\tconst customTools: ToolDefinition[] | undefined = options.enableAskUserTool\n\t\t? [\n\t\t\t\t...baseCustomTools.filter((tool) => tool.name !== \"ask_user\"),\n\t\t\t\tcreateAskUserTool() as unknown as ToolDefinition,\n\t\t\t]\n\t\t: baseCustomTools.length > 0\n\t\t\t? baseCustomTools\n\t\t\t: options.customTools;\n\n\tconst session = new AgentSession({\n\t\tagent,\n\t\tsessionManager,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tscopedModels: options.scopedModels,\n\t\tresourceLoader,\n\t\tcustomTools,\n\t\tmodelRegistry,\n\t\tinitialActiveToolNames,\n\t\textensionRunnerRef,\n\t\tsystemPromptSuffix: profile?.systemPromptAppend || undefined,\n\t\tiosmAutopilotEnabled: profile?.name === \"iosm\",\n\t});\n\tsessionRef = session;\n\tconst extensionsResult = resourceLoader.getExtensions();\n\n\treturn {\n\t\tsession,\n\t\textensionsResult,\n\t\tmodelFallbackMessage,\n\t};\n}\n"]}
@@ -0,0 +1,46 @@
1
+ export type SharedMemoryScope = "run" | "task";
2
+ export type SharedMemoryWriteMode = "set" | "append";
3
+ export interface SharedMemoryWriter {
4
+ taskId?: string;
5
+ delegateId?: string;
6
+ profile?: string;
7
+ }
8
+ export interface SharedMemoryContext {
9
+ rootCwd: string;
10
+ runId: string;
11
+ taskId?: string;
12
+ delegateId?: string;
13
+ profile?: string;
14
+ }
15
+ export interface SharedMemoryReadItem {
16
+ key: string;
17
+ scope: SharedMemoryScope;
18
+ value?: string;
19
+ version: number;
20
+ updatedAt: string;
21
+ writer: SharedMemoryWriter;
22
+ }
23
+ export interface SharedMemoryReadResult {
24
+ runId: string;
25
+ scope: SharedMemoryScope;
26
+ items: SharedMemoryReadItem[];
27
+ totalMatched: number;
28
+ }
29
+ export interface SharedMemoryWriteInput {
30
+ key: string;
31
+ value: string;
32
+ scope: SharedMemoryScope;
33
+ mode: SharedMemoryWriteMode;
34
+ ifVersion?: number;
35
+ }
36
+ export interface SharedMemoryReadInput {
37
+ scope: SharedMemoryScope;
38
+ key?: string;
39
+ prefix?: string;
40
+ limit?: number;
41
+ includeValues?: boolean;
42
+ }
43
+ export declare function getSharedMemoryPath(rootCwd: string, runId: string): string;
44
+ export declare function writeSharedMemory(context: SharedMemoryContext, input: SharedMemoryWriteInput): Promise<SharedMemoryReadItem>;
45
+ export declare function readSharedMemory(context: SharedMemoryContext, input: SharedMemoryReadInput): Promise<SharedMemoryReadResult>;
46
+ //# sourceMappingURL=shared-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-memory.d.ts","sourceRoot":"","sources":["../../src/core/shared-memory.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,CAAC;AAC/C,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,kBAAkB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OA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} from "node:path";
3
+ import lockfile from "proper-lockfile";
4
+ const maxEntryCharsDefault = 4000;
5
+ const maxKeysDefault = 500;
6
+ const historySizeDefault = 1000;
7
+ const lockRetryAttempts = 12;
8
+ const lockRetryDelayMs = 20;
9
+ const maxEntryChars = readBoundedInt(process.env.IOSM_SUBAGENT_SHARED_MEMORY_MAX_ENTRY_CHARS, maxEntryCharsDefault, 64, 20_000);
10
+ const maxKeys = readBoundedInt(process.env.IOSM_SUBAGENT_SHARED_MEMORY_MAX_KEYS, maxKeysDefault, 10, 20_000);
11
+ const historySize = readBoundedInt(process.env.IOSM_SUBAGENT_SHARED_MEMORY_HISTORY_SIZE, historySizeDefault, 10, 50_000);
12
+ function readBoundedInt(raw, fallback, min, max) {
13
+ const parsed = raw ? Number.parseInt(raw, 10) : fallback;
14
+ if (!Number.isInteger(parsed))
15
+ return fallback;
16
+ return Math.max(min, Math.min(max, parsed));
17
+ }
18
+ function delay(ms) {
19
+ return new Promise((resolve) => setTimeout(resolve, ms));
20
+ }
21
+ function normalizeRunId(runId) {
22
+ const trimmed = runId.trim();
23
+ if (!trimmed)
24
+ throw new Error("shared memory requires non-empty run_id context");
25
+ return trimmed;
26
+ }
27
+ function normalizeKey(key) {
28
+ const normalized = key.trim().replace(/\s+/g, " ");
29
+ if (!normalized)
30
+ throw new Error("shared memory key must be non-empty");
31
+ if (normalized.length > 240) {
32
+ throw new Error("shared memory key too long (max 240 chars)");
33
+ }
34
+ return normalized;
35
+ }
36
+ function resolveScopedKey(context, scope, key) {
37
+ const normalizedKey = normalizeKey(key);
38
+ if (scope === "task") {
39
+ if (!context.taskId || !context.taskId.trim()) {
40
+ throw new Error("task-scoped shared memory requires task_id context");
41
+ }
42
+ return `task:${context.taskId.trim()}:${normalizedKey}`;
43
+ }
44
+ return `run:${normalizedKey}`;
45
+ }
46
+ function parseScopedKey(scopedKey) {
47
+ if (scopedKey.startsWith("task:")) {
48
+ const rest = scopedKey.slice("task:".length);
49
+ const split = rest.indexOf(":");
50
+ if (split <= 0) {
51
+ return { scope: "task", key: rest };
52
+ }
53
+ return {
54
+ scope: "task",
55
+ taskId: rest.slice(0, split),
56
+ key: rest.slice(split + 1),
57
+ };
58
+ }
59
+ if (scopedKey.startsWith("run:")) {
60
+ return { scope: "run", key: scopedKey.slice("run:".length) };
61
+ }
62
+ return { scope: "run", key: scopedKey };
63
+ }
64
+ function getSharedMemoryDir(rootCwd) {
65
+ return join(rootCwd, ".iosm", "subagents", "shared-memory");
66
+ }
67
+ export function getSharedMemoryPath(rootCwd, runId) {
68
+ return join(getSharedMemoryDir(rootCwd), `${normalizeRunId(runId)}.json`);
69
+ }
70
+ function createInitialStore(runId) {
71
+ const now = new Date().toISOString();
72
+ return {
73
+ runId,
74
+ createdAt: now,
75
+ updatedAt: now,
76
+ entries: {},
77
+ history: [],
78
+ };
79
+ }
80
+ function readStore(filePath, runId) {
81
+ if (!existsSync(filePath)) {
82
+ return createInitialStore(runId);
83
+ }
84
+ try {
85
+ const parsed = JSON.parse(readFileSync(filePath, "utf8"));
86
+ if (!parsed || typeof parsed !== "object")
87
+ return createInitialStore(runId);
88
+ if (parsed.runId !== runId)
89
+ return createInitialStore(runId);
90
+ if (!parsed.entries || typeof parsed.entries !== "object")
91
+ parsed.entries = {};
92
+ if (!Array.isArray(parsed.history))
93
+ parsed.history = [];
94
+ if (!parsed.createdAt || typeof parsed.createdAt !== "string")
95
+ parsed.createdAt = new Date().toISOString();
96
+ if (!parsed.updatedAt || typeof parsed.updatedAt !== "string")
97
+ parsed.updatedAt = parsed.createdAt;
98
+ return parsed;
99
+ }
100
+ catch {
101
+ return createInitialStore(runId);
102
+ }
103
+ }
104
+ function writeStore(filePath, store) {
105
+ mkdirSync(dirname(filePath), { recursive: true });
106
+ writeFileSync(filePath, `${JSON.stringify(store, null, 2)}\n`, "utf8");
107
+ }
108
+ async function acquireFileLock(filePath) {
109
+ for (let attempt = 1; attempt <= lockRetryAttempts; attempt += 1) {
110
+ try {
111
+ return await lockfile.lock(filePath, { realpath: false });
112
+ }
113
+ catch (error) {
114
+ const code = error && typeof error === "object" && "code" in error ? String(error.code) : "";
115
+ if (code !== "ELOCKED" || attempt >= lockRetryAttempts) {
116
+ throw error;
117
+ }
118
+ await delay(lockRetryDelayMs * attempt);
119
+ }
120
+ }
121
+ throw new Error("failed to acquire shared memory lock");
122
+ }
123
+ async function withLockedStore(context, fn) {
124
+ const runId = normalizeRunId(context.runId);
125
+ const filePath = getSharedMemoryPath(context.rootCwd, runId);
126
+ mkdirSync(dirname(filePath), { recursive: true });
127
+ if (!existsSync(filePath)) {
128
+ writeStore(filePath, createInitialStore(runId));
129
+ }
130
+ const release = await acquireFileLock(filePath);
131
+ try {
132
+ const store = readStore(filePath, runId);
133
+ const value = fn(store, filePath);
134
+ writeStore(filePath, store);
135
+ return value;
136
+ }
137
+ finally {
138
+ await release();
139
+ }
140
+ }
141
+ function trimHistory(store) {
142
+ if (store.history.length <= historySize)
143
+ return;
144
+ store.history = store.history.slice(store.history.length - historySize);
145
+ }
146
+ function writerFromContext(context) {
147
+ return {
148
+ taskId: context.taskId?.trim() || undefined,
149
+ delegateId: context.delegateId?.trim() || undefined,
150
+ profile: context.profile?.trim() || undefined,
151
+ };
152
+ }
153
+ export async function writeSharedMemory(context, input) {
154
+ const normalizedValue = input.value;
155
+ if (normalizedValue.length > maxEntryChars) {
156
+ throw new Error(`shared memory value exceeds ${maxEntryChars} chars`);
157
+ }
158
+ const scopedKey = resolveScopedKey(context, input.scope, input.key);
159
+ return withLockedStore(context, (store) => {
160
+ const now = new Date().toISOString();
161
+ const entriesCount = Object.keys(store.entries).length;
162
+ const previous = store.entries[scopedKey];
163
+ if (!previous && entriesCount >= maxKeys) {
164
+ throw new Error(`shared memory key limit reached (${maxKeys})`);
165
+ }
166
+ if (input.ifVersion !== undefined && previous && previous.version !== input.ifVersion) {
167
+ throw new Error(`shared memory CAS mismatch for key "${input.key}" (expected ${input.ifVersion}, got ${previous.version})`);
168
+ }
169
+ if (input.ifVersion !== undefined && !previous) {
170
+ throw new Error(`shared memory CAS mismatch for key "${input.key}" (expected ${input.ifVersion}, got 0)`);
171
+ }
172
+ const nextValue = input.mode === "append" ? `${previous?.value ?? ""}${normalizedValue}` : normalizedValue;
173
+ if (nextValue.length > maxEntryChars) {
174
+ throw new Error(`shared memory value exceeds ${maxEntryChars} chars after ${input.mode}`);
175
+ }
176
+ const nextVersion = (previous?.version ?? 0) + 1;
177
+ const writer = writerFromContext(context);
178
+ store.entries[scopedKey] = {
179
+ value: nextValue,
180
+ version: nextVersion,
181
+ updatedAt: now,
182
+ writer,
183
+ };
184
+ store.updatedAt = now;
185
+ store.history.push({
186
+ key: normalizeKey(input.key),
187
+ scope: input.scope,
188
+ mode: input.mode,
189
+ version: nextVersion,
190
+ updatedAt: now,
191
+ writer,
192
+ });
193
+ trimHistory(store);
194
+ return {
195
+ key: normalizeKey(input.key),
196
+ scope: input.scope,
197
+ value: nextValue,
198
+ version: nextVersion,
199
+ updatedAt: now,
200
+ writer,
201
+ };
202
+ });
203
+ }
204
+ function matchesScopeAndPrefix(context, scopedKey, scope, key, prefix) {
205
+ const parsed = parseScopedKey(scopedKey);
206
+ if (parsed.scope !== scope)
207
+ return { matched: false, parsed };
208
+ if (scope === "task") {
209
+ const taskId = context.taskId?.trim();
210
+ if (!taskId)
211
+ return { matched: false, parsed };
212
+ if (parsed.taskId !== taskId)
213
+ return { matched: false, parsed };
214
+ }
215
+ if (key) {
216
+ return { matched: parsed.key === key, parsed };
217
+ }
218
+ if (prefix) {
219
+ return { matched: parsed.key.startsWith(prefix), parsed };
220
+ }
221
+ return { matched: true, parsed };
222
+ }
223
+ export async function readSharedMemory(context, input) {
224
+ const normalizedKey = input.key ? normalizeKey(input.key) : undefined;
225
+ const normalizedPrefix = input.prefix ? normalizeKey(input.prefix) : undefined;
226
+ const limit = Math.max(1, Math.min(100, input.limit ?? 20));
227
+ const includeValues = input.includeValues !== false;
228
+ return withLockedStore(context, (store) => {
229
+ const matchedItems = [];
230
+ for (const [scopedKey, entry] of Object.entries(store.entries)) {
231
+ const matched = matchesScopeAndPrefix(context, scopedKey, input.scope, normalizedKey, normalizedPrefix);
232
+ if (!matched.matched)
233
+ continue;
234
+ matchedItems.push({
235
+ key: matched.parsed.key,
236
+ scope: input.scope,
237
+ value: includeValues ? entry.value : undefined,
238
+ version: entry.version,
239
+ updatedAt: entry.updatedAt,
240
+ writer: entry.writer ?? {},
241
+ });
242
+ }
243
+ matchedItems.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
244
+ const sliced = matchedItems.slice(0, limit);
245
+ return {
246
+ runId: store.runId,
247
+ scope: input.scope,
248
+ items: sliced,
249
+ totalMatched: matchedItems.length,
250
+ };
251
+ });
252
+ }
253
+ //# sourceMappingURL=shared-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-memory.js","sourceRoot":"","sources":["../../src/core/shared-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AA2EvC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,oBAAoB,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAChI,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,oCAAoC,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAC7G,MAAM,WAAW,GAAG,cAAc,CAAC,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E,KAAK,CAAC,CAAC;QAC5C,OAAO;YACN,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,MAAM;YACb,YAAY,EAAE,YAAY,CAAC,MAAM;SACjC,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport lockfile from \"proper-lockfile\";\n\nexport type SharedMemoryScope = \"run\" | \"task\";\nexport type SharedMemoryWriteMode = \"set\" | \"append\";\n\nexport interface SharedMemoryWriter {\n\ttaskId?: string;\n\tdelegateId?: string;\n\tprofile?: string;\n}\n\nexport interface SharedMemoryContext {\n\trootCwd: string;\n\trunId: string;\n\ttaskId?: string;\n\tdelegateId?: string;\n\tprofile?: string;\n}\n\ninterface SharedMemoryEntry {\n\tvalue: string;\n\tversion: number;\n\tupdatedAt: string;\n\twriter: SharedMemoryWriter;\n}\n\ninterface SharedMemoryHistoryItem {\n\tkey: string;\n\tscope: SharedMemoryScope;\n\tmode: SharedMemoryWriteMode;\n\tversion: number;\n\tupdatedAt: string;\n\twriter: SharedMemoryWriter;\n}\n\ninterface SharedMemoryStore {\n\trunId: string;\n\tcreatedAt: string;\n\tupdatedAt: string;\n\tentries: Record<string, SharedMemoryEntry>;\n\thistory: SharedMemoryHistoryItem[];\n}\n\nexport interface SharedMemoryReadItem {\n\tkey: string;\n\tscope: SharedMemoryScope;\n\tvalue?: string;\n\tversion: number;\n\tupdatedAt: string;\n\twriter: SharedMemoryWriter;\n}\n\nexport interface SharedMemoryReadResult {\n\trunId: string;\n\tscope: SharedMemoryScope;\n\titems: SharedMemoryReadItem[];\n\ttotalMatched: number;\n}\n\nexport interface SharedMemoryWriteInput {\n\tkey: string;\n\tvalue: string;\n\tscope: SharedMemoryScope;\n\tmode: SharedMemoryWriteMode;\n\tifVersion?: number;\n}\n\nexport interface SharedMemoryReadInput {\n\tscope: SharedMemoryScope;\n\tkey?: string;\n\tprefix?: string;\n\tlimit?: number;\n\tincludeValues?: boolean;\n}\n\nconst maxEntryCharsDefault = 4000;\nconst maxKeysDefault = 500;\nconst historySizeDefault = 1000;\nconst lockRetryAttempts = 12;\nconst lockRetryDelayMs = 20;\n\nconst maxEntryChars = readBoundedInt(process.env.IOSM_SUBAGENT_SHARED_MEMORY_MAX_ENTRY_CHARS, maxEntryCharsDefault, 64, 20_000);\nconst maxKeys = readBoundedInt(process.env.IOSM_SUBAGENT_SHARED_MEMORY_MAX_KEYS, maxKeysDefault, 10, 20_000);\nconst historySize = readBoundedInt(process.env.IOSM_SUBAGENT_SHARED_MEMORY_HISTORY_SIZE, historySizeDefault, 10, 50_000);\n\nfunction readBoundedInt(raw: string | undefined, fallback: number, min: number, max: number): number {\n\tconst parsed = raw ? Number.parseInt(raw, 10) : fallback;\n\tif (!Number.isInteger(parsed)) return fallback;\n\treturn Math.max(min, Math.min(max, parsed));\n}\n\nfunction delay(ms: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction normalizeRunId(runId: string): string {\n\tconst trimmed = runId.trim();\n\tif (!trimmed) throw new Error(\"shared memory requires non-empty run_id context\");\n\treturn trimmed;\n}\n\nfunction normalizeKey(key: string): string {\n\tconst normalized = key.trim().replace(/\\s+/g, \" \");\n\tif (!normalized) throw new Error(\"shared memory key must be non-empty\");\n\tif (normalized.length > 240) {\n\t\tthrow new Error(\"shared memory key too long (max 240 chars)\");\n\t}\n\treturn normalized;\n}\n\nfunction resolveScopedKey(context: SharedMemoryContext, scope: SharedMemoryScope, key: string): string {\n\tconst normalizedKey = normalizeKey(key);\n\tif (scope === \"task\") {\n\t\tif (!context.taskId || !context.taskId.trim()) {\n\t\t\tthrow new Error(\"task-scoped shared memory requires task_id context\");\n\t\t}\n\t\treturn `task:${context.taskId.trim()}:${normalizedKey}`;\n\t}\n\treturn `run:${normalizedKey}`;\n}\n\nfunction parseScopedKey(scopedKey: string): { scope: SharedMemoryScope; key: string; taskId?: string } {\n\tif (scopedKey.startsWith(\"task:\")) {\n\t\tconst rest = scopedKey.slice(\"task:\".length);\n\t\tconst split = rest.indexOf(\":\");\n\t\tif (split <= 0) {\n\t\t\treturn { scope: \"task\", key: rest };\n\t\t}\n\t\treturn {\n\t\t\tscope: \"task\",\n\t\t\ttaskId: rest.slice(0, split),\n\t\t\tkey: rest.slice(split + 1),\n\t\t};\n\t}\n\tif (scopedKey.startsWith(\"run:\")) {\n\t\treturn { scope: \"run\", key: scopedKey.slice(\"run:\".length) };\n\t}\n\treturn { scope: \"run\", key: scopedKey };\n}\n\nfunction getSharedMemoryDir(rootCwd: string): string {\n\treturn join(rootCwd, \".iosm\", \"subagents\", \"shared-memory\");\n}\n\nexport function getSharedMemoryPath(rootCwd: string, runId: string): string {\n\treturn join(getSharedMemoryDir(rootCwd), `${normalizeRunId(runId)}.json`);\n}\n\nfunction createInitialStore(runId: string): SharedMemoryStore {\n\tconst now = new Date().toISOString();\n\treturn {\n\t\trunId,\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t\tentries: {},\n\t\thistory: [],\n\t};\n}\n\nfunction readStore(filePath: string, runId: string): SharedMemoryStore {\n\tif (!existsSync(filePath)) {\n\t\treturn createInitialStore(runId);\n\t}\n\ttry {\n\t\tconst parsed = JSON.parse(readFileSync(filePath, \"utf8\")) as SharedMemoryStore;\n\t\tif (!parsed || typeof parsed !== \"object\") return createInitialStore(runId);\n\t\tif (parsed.runId !== runId) return createInitialStore(runId);\n\t\tif (!parsed.entries || typeof parsed.entries !== \"object\") parsed.entries = {};\n\t\tif (!Array.isArray(parsed.history)) parsed.history = [];\n\t\tif (!parsed.createdAt || typeof parsed.createdAt !== \"string\") parsed.createdAt = new Date().toISOString();\n\t\tif (!parsed.updatedAt || typeof parsed.updatedAt !== \"string\") parsed.updatedAt = parsed.createdAt;\n\t\treturn parsed;\n\t} catch {\n\t\treturn createInitialStore(runId);\n\t}\n}\n\nfunction writeStore(filePath: string, store: SharedMemoryStore): void {\n\tmkdirSync(dirname(filePath), { recursive: true });\n\twriteFileSync(filePath, `${JSON.stringify(store, null, 2)}\\n`, \"utf8\");\n}\n\nasync function acquireFileLock(filePath: string): Promise<() => Promise<void>> {\n\tfor (let attempt = 1; attempt <= lockRetryAttempts; attempt += 1) {\n\t\ttry {\n\t\t\treturn await lockfile.lock(filePath, { realpath: false });\n\t\t} catch (error) {\n\t\t\tconst code = error && typeof error === \"object\" && \"code\" in error ? String(error.code) : \"\";\n\t\t\tif (code !== \"ELOCKED\" || attempt >= lockRetryAttempts) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tawait delay(lockRetryDelayMs * attempt);\n\t\t}\n\t}\n\tthrow new Error(\"failed to acquire shared memory lock\");\n}\n\nasync function withLockedStore<T>(\n\tcontext: SharedMemoryContext,\n\tfn: (store: SharedMemoryStore, filePath: string) => T,\n): Promise<T> {\n\tconst runId = normalizeRunId(context.runId);\n\tconst filePath = getSharedMemoryPath(context.rootCwd, runId);\n\tmkdirSync(dirname(filePath), { recursive: true });\n\tif (!existsSync(filePath)) {\n\t\twriteStore(filePath, createInitialStore(runId));\n\t}\n\tconst release = await acquireFileLock(filePath);\n\ttry {\n\t\tconst store = readStore(filePath, runId);\n\t\tconst value = fn(store, filePath);\n\t\twriteStore(filePath, store);\n\t\treturn value;\n\t} finally {\n\t\tawait release();\n\t}\n}\n\nfunction trimHistory(store: SharedMemoryStore): void {\n\tif (store.history.length <= historySize) return;\n\tstore.history = store.history.slice(store.history.length - historySize);\n}\n\nfunction writerFromContext(context: SharedMemoryContext): SharedMemoryWriter {\n\treturn {\n\t\ttaskId: context.taskId?.trim() || undefined,\n\t\tdelegateId: context.delegateId?.trim() || undefined,\n\t\tprofile: context.profile?.trim() || undefined,\n\t};\n}\n\nexport async function writeSharedMemory(\n\tcontext: SharedMemoryContext,\n\tinput: SharedMemoryWriteInput,\n): Promise<SharedMemoryReadItem> {\n\tconst normalizedValue = input.value;\n\tif (normalizedValue.length > maxEntryChars) {\n\t\tthrow new Error(`shared memory value exceeds ${maxEntryChars} chars`);\n\t}\n\tconst scopedKey = resolveScopedKey(context, input.scope, input.key);\n\n\treturn withLockedStore(context, (store) => {\n\t\tconst now = new Date().toISOString();\n\t\tconst entriesCount = Object.keys(store.entries).length;\n\t\tconst previous = store.entries[scopedKey];\n\t\tif (!previous && entriesCount >= maxKeys) {\n\t\t\tthrow new Error(`shared memory key limit reached (${maxKeys})`);\n\t\t}\n\t\tif (input.ifVersion !== undefined && previous && previous.version !== input.ifVersion) {\n\t\t\tthrow new Error(`shared memory CAS mismatch for key \"${input.key}\" (expected ${input.ifVersion}, got ${previous.version})`);\n\t\t}\n\t\tif (input.ifVersion !== undefined && !previous) {\n\t\t\tthrow new Error(`shared memory CAS mismatch for key \"${input.key}\" (expected ${input.ifVersion}, got 0)`);\n\t\t}\n\n\t\tconst nextValue = input.mode === \"append\" ? `${previous?.value ?? \"\"}${normalizedValue}` : normalizedValue;\n\t\tif (nextValue.length > maxEntryChars) {\n\t\t\tthrow new Error(`shared memory value exceeds ${maxEntryChars} chars after ${input.mode}`);\n\t\t}\n\t\tconst nextVersion = (previous?.version ?? 0) + 1;\n\t\tconst writer = writerFromContext(context);\n\t\tstore.entries[scopedKey] = {\n\t\t\tvalue: nextValue,\n\t\t\tversion: nextVersion,\n\t\t\tupdatedAt: now,\n\t\t\twriter,\n\t\t};\n\t\tstore.updatedAt = now;\n\t\tstore.history.push({\n\t\t\tkey: normalizeKey(input.key),\n\t\t\tscope: input.scope,\n\t\t\tmode: input.mode,\n\t\t\tversion: nextVersion,\n\t\t\tupdatedAt: now,\n\t\t\twriter,\n\t\t});\n\t\ttrimHistory(store);\n\n\t\treturn {\n\t\t\tkey: normalizeKey(input.key),\n\t\t\tscope: input.scope,\n\t\t\tvalue: nextValue,\n\t\t\tversion: nextVersion,\n\t\t\tupdatedAt: now,\n\t\t\twriter,\n\t\t};\n\t});\n}\n\nfunction matchesScopeAndPrefix(\n\tcontext: SharedMemoryContext,\n\tscopedKey: string,\n\tscope: SharedMemoryScope,\n\tkey: string | undefined,\n\tprefix: string | undefined,\n): { matched: boolean; parsed: ReturnType<typeof parseScopedKey> } {\n\tconst parsed = parseScopedKey(scopedKey);\n\tif (parsed.scope !== scope) return { matched: false, parsed };\n\tif (scope === \"task\") {\n\t\tconst taskId = context.taskId?.trim();\n\t\tif (!taskId) return { matched: false, parsed };\n\t\tif (parsed.taskId !== taskId) return { matched: false, parsed };\n\t}\n\tif (key) {\n\t\treturn { matched: parsed.key === key, parsed };\n\t}\n\tif (prefix) {\n\t\treturn { matched: parsed.key.startsWith(prefix), parsed };\n\t}\n\treturn { matched: true, parsed };\n}\n\nexport async function readSharedMemory(\n\tcontext: SharedMemoryContext,\n\tinput: SharedMemoryReadInput,\n): Promise<SharedMemoryReadResult> {\n\tconst normalizedKey = input.key ? normalizeKey(input.key) : undefined;\n\tconst normalizedPrefix = input.prefix ? normalizeKey(input.prefix) : undefined;\n\tconst limit = Math.max(1, Math.min(100, input.limit ?? 20));\n\tconst includeValues = input.includeValues !== false;\n\n\treturn withLockedStore(context, (store) => {\n\t\tconst matchedItems: SharedMemoryReadItem[] = [];\n\t\tfor (const [scopedKey, entry] of Object.entries(store.entries)) {\n\t\t\tconst matched = matchesScopeAndPrefix(context, scopedKey, input.scope, normalizedKey, normalizedPrefix);\n\t\t\tif (!matched.matched) continue;\n\t\t\tmatchedItems.push({\n\t\t\t\tkey: matched.parsed.key,\n\t\t\t\tscope: input.scope,\n\t\t\t\tvalue: includeValues ? entry.value : undefined,\n\t\t\t\tversion: entry.version,\n\t\t\t\tupdatedAt: entry.updatedAt,\n\t\t\t\twriter: entry.writer ?? {},\n\t\t\t});\n\t\t}\n\n\t\tmatchedItems.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));\n\t\tconst sliced = matchedItems.slice(0, limit);\n\t\treturn {\n\t\t\trunId: store.runId,\n\t\t\tscope: input.scope,\n\t\t\titems: sliced,\n\t\t\ttotalMatched: matchedItems.length,\n\t\t};\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"slash-commands.d.ts","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;AAE/D,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,mBAAmB,CAqFrE,CAAC"}
1
+ {"version":3,"file":"slash-commands.d.ts","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;AAE/D,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,mBAAmB,CA0FrE,CAAC"}
@@ -6,7 +6,11 @@ export const BUILTIN_SLASH_COMMANDS = [
6
6
  },
7
7
  {
8
8
  name: "orchestrate",
9
- description: "Run orchestrated subagents: /orchestrate (--parallel|--sequential) --agents N [--max-parallel N] [--profile <name>|--profiles p1,p2] [--cwd p1,p2] [--locks l1,l2] [--worktree] [--depends 2>1,3>2] <task>",
9
+ description: "Manual legacy multi-agent orchestration: /orchestrate (--parallel|--sequential) --agents N ... <task>",
10
+ },
11
+ {
12
+ name: "swarm",
13
+ description: "Recommended multi-agent orchestration runtime for complex/risky tasks: /swarm run <task> | /swarm from-singular <run-id> --option <1|2|3> | /swarm watch|retry|resume",
10
14
  },
11
15
  {
12
16
  name: "agents",
@@ -1 +1 @@
1
- {"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,sBAAsB,GAAuC;IACzE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,0EAA0E,EAAE;IACzG;QACC,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,0FAA0F;KACvG;IACD;QACC,IAAI,EAAE,aAAa;QACnB,WAAW,EACV,4MAA4M;KAC7M;IACD;QACC,IAAI,EAAE,QAAQ;QACd,WAAW,EACV,qHAAqH;KACtH;IACD,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,qDAAqD,EAAE;IAC7F;QACC,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,yGAAyG;KACtH;IACD,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,gEAAgE,EAAE;IACpG,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,0EAA0E,EAAE;IAChH,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE;IACvD,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,oEAAoE,EAAE;IACzG,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAA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AAE,wBAAwB,EAAE;IAC5D,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,6BAA6B,EAAE;IAC/D,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,2CAA2C,EAAE;IAC1E,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,yCAAyC,EAAE;IACxE,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,oEAAoE,EAAE;IACpG,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE;IACjD,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mDAAmD,EAAE;IACpF,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE;IACnD,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE;IAChD,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,sCAAsC,EAAE;IACxE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,4BAA4B,EAAE;IAC7D,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gDAAgD,EAAE;IACjF,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE;CAC1C,CAAC","sourcesContent":["export type SlashCommandSource = \"extension\" | \"prompt\" | \"skill\";\n\nexport type SlashCommandLocation = \"user\" | \"project\" | \"path\";\n\nexport interface SlashCommandInfo {\n\tname: string;\n\tdescription?: string;\n\tsource: SlashCommandSource;\n\tlocation?: SlashCommandLocation;\n\tpath?: string;\n}\n\nexport interface BuiltinSlashCommand {\n\tname: string;\n\tdescription: string;\n}\n\nexport const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [\n\t{ name: \"init\", description: \"Initialize iosm.yaml and .iosm scaffold in current (or target) directory\" },\n\t{\n\t\tname: \"iosm\",\n\t\tdescription: \"Run IOSM auto-improvement loop: /iosm [target-index] [--max-iterations N] [--force-init]\",\n\t},\n\t{\n\t\tname: \"orchestrate\",\n\t\tdescription:\n\t\t\t\"Run orchestrated subagents: /orchestrate (--parallel|--sequential) --agents N [--max-parallel N] [--profile <name>|--profiles p1,p2] [--cwd p1,p2] [--locks l1,l2] [--worktree] [--depends 2>1,3>2] <task>\",\n\t},\n\t{\n\t\tname: \"agents\",\n\t\tdescription:\n\t\t\t\"Interactive agent menu: browse/use/create/edit/delete custom agents and inspect source precedence from .iosm/agents\",\n\t},\n\t{ name: \"subagent-runs\", description: \"List recent subagent runs from .iosm/subagents/runs\" },\n\t{\n\t\tname: \"subagent-resume\",\n\t\tdescription: \"Resume from prior subagent output: /subagent-resume [run-id] [extra instructions] (picker when omitted)\",\n\t},\n\t{ name: \"team-runs\", description: \"List recent team orchestration runs from .iosm/subagents/teams\" },\n\t{ name: \"team-status\", description: \"Show a team run status: /team-status [team-run-id] (picker when omitted)\" },\n\t{ name: \"cycle-list\", description: \"List IOSM cycles\" },\n\t{ name: \"cycle-plan\", description: \"Plan a new IOSM cycle: /cycle-plan [--id <id>] [--force] <goal...>\" },\n\t{ name: \"cycle-status\", description: \"Show IOSM cycle completeness and gates: /cycle-status [cycle-id]\" },\n\t{ name: \"cycle-report\", description: \"Show IOSM cycle report JSON: /cycle-report [cycle-id]\" },\n\t{\n\t\tname: \"mcp\",\n\t\tdescription:\n\t\t\t\"MCP server manager: /mcp (interactive UI), /mcp add <name> ..., /mcp list, /mcp tools [name], /mcp enable|disable|remove <name>\",\n\t},\n\t{\n\t\tname: \"memory\",\n\t\tdescription:\n\t\t\t\"Memory manager: /memory (interactive), /memory <text>, /memory edit <index> <text>, /memory rm <index>\",\n\t},\n\t{\n\t\tname: \"semantic\",\n\t\tdescription:\n\t\t\t\"Semantic search manager: /semantic (interactive UI), /semantic setup|auto-index|status|index|rebuild|query <text> [--top-k N]\",\n\t},\n\t{\n\t\tname: \"contract\",\n\t\tdescription:\n\t\t\t\"Engineering contract manager: /contract (interactive field editor), /contract show|edit|clear --scope <project|session>\",\n\t},\n\t{\n\t\tname: \"singular\",\n\t\tdescription:\n\t\t\t\"Feature feasibility analyzer: /singular <request> (builds implementation options and recommendations)\",\n\t},\n\t{ name: \"settings\", description: \"Open settings menu\" },\n\t{\n\t\tname: \"permissions\",\n\t\tdescription:\n\t\t\t\"Permission controls: /permissions (interactive menu) or /permissions [ask|auto|yolo|status|hooks] and /permissions [allow|deny] [list|add|remove] <tool:match>\",\n\t},\n\t{ name: \"yolo\", description: \"Toggle permission prompts: /yolo [on|off|status]\" },\n\t{ name: \"model\", description: \"Select model (provider-first selector UI)\" },\n\t{ name: \"scoped-models\", description: \"Enable/disable models for Ctrl+P cycling\" },\n\t{ name: \"export\", description: \"Export session to HTML file: /export [output-path] (wizard when omitted)\" },\n\t{ name: \"share\", description: \"Share session as a secret GitHub gist\" },\n\t{ name: \"copy\", description: \"Copy last agent message to clipboard\" },\n\t{ name: \"name\", description: \"Set session display name\" },\n\t{ name: \"session\", description: \"Show session info and stats\" },\n\t{\n\t\tname: \"doctor\",\n\t\tdescription: \"Run runtime diagnostics (model/auth/MCP/CLI tools/hooks/paths) with optional interactive fixes\",\n\t},\n\t{ name: \"checkpoint\", description: \"Create/list checkpoints for safe rollback\" },\n\t{ name: \"rollback\", description: \"Rollback session tree to a checkpoint (picker when omitted)\" },\n\t{ name: \"changelog\", description: \"Show changelog entries\" },\n\t{ name: \"hotkeys\", description: \"Show all keyboard shortcuts\" },\n\t{ name: \"fork\", description: \"Create a new fork from a previous message\" },\n\t{ name: \"tree\", description: \"Navigate session tree (switch branches)\" },\n\t{ name: \"login\", description: \"Authenticate with provider (OAuth incl. Qwen + OpenRouter API key)\" },\n\t{ name: \"auth\", description: \"Alias for /login\" },\n\t{ name: \"logout\", description: \"Remove saved provider credentials (OAuth/API key)\" },\n\t{ name: \"new\", description: \"Start a new session\" },\n\t{ name: \"clear\", description: \"Alias for /new\" },\n\t{ name: \"compact\", description: \"Manually compact the session context\" },\n\t{ name: \"resume\", description: \"Resume a different session\" },\n\t{ name: \"reload\", description: \"Reload extensions, skills, prompts, and themes\" },\n\t{ name: \"quit\", description: \"Quit iosm\" },\n];\n"]}
1
+ {"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../../src/core/slash-commands.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,sBAAsB,GAAuC;IACzE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,0EAA0E,EAAE;IACzG;QACC,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,0FAA0F;KACvG;IACD;QACC,IAAI,EAAE,aAAa;QACnB,WAAW,EACV,uGAAuG;KACxG;IACD;QACC,IAAI,EAAE,OAAO;QACb,WAAW,EACV,uKAAuK;KACxK;IACD;QACC,IAAI,EAAE,QAAQ;QACd,WAAW,EACV,qHAAqH;KACtH;IACD,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,qDAAqD,EAAE;IAC7F;QACC,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,yGAAyG;KACtH;IACD,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,gEAAgE,EAAE;IACpG,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,0EAA0E,EAAE;IAChH,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE;IACvD,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,oEAAoE,EAAE;IACzG,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,kEAAkE,EAAE;IACzG,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,uDAAuD,EAAE;IAC9F;QACC,IAAI,EAAE,KAAK;QACX,WAAW,EACV,iIAAiI;KAClI;IACD;QACC,IAAI,EAAE,QAAQ;QACd,WAAW,EACV,wGAAwG;KACzG;IACD;QACC,IAAI,EAAE,UAAU;QAChB,WAAW,EACV,+HAA+H;KAChI;IACD;QACC,IAAI,EAAE,UAAU;QAChB,WAAW,EACV,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,EAAE,WAAW,EAAE,kBAAkB,EAAE;IACjD,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mDAAmD,EAAE;IACpF,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE;IACnD,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE;IAChD,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,sCAAsC,EAAE;IACxE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,4BAA4B,EAAE;IAC7D,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gDAAgD,EAAE;IACjF,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE;CAC1C,CAAC","sourcesContent":["export type SlashCommandSource = \"extension\" | \"prompt\" | \"skill\";\n\nexport type SlashCommandLocation = \"user\" | \"project\" | \"path\";\n\nexport interface SlashCommandInfo {\n\tname: string;\n\tdescription?: string;\n\tsource: SlashCommandSource;\n\tlocation?: SlashCommandLocation;\n\tpath?: string;\n}\n\nexport interface BuiltinSlashCommand {\n\tname: string;\n\tdescription: string;\n}\n\nexport const BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [\n\t{ name: \"init\", description: \"Initialize iosm.yaml and .iosm scaffold in current (or target) directory\" },\n\t{\n\t\tname: \"iosm\",\n\t\tdescription: \"Run IOSM auto-improvement loop: /iosm [target-index] [--max-iterations N] [--force-init]\",\n\t},\n\t{\n\t\tname: \"orchestrate\",\n\t\tdescription:\n\t\t\t\"Manual legacy multi-agent orchestration: /orchestrate (--parallel|--sequential) --agents N ... <task>\",\n\t},\n\t{\n\t\tname: \"swarm\",\n\t\tdescription:\n\t\t\t\"Recommended multi-agent orchestration runtime for complex/risky tasks: /swarm run <task> | /swarm from-singular <run-id> --option <1|2|3> | /swarm watch|retry|resume\",\n\t},\n\t{\n\t\tname: \"agents\",\n\t\tdescription:\n\t\t\t\"Interactive agent menu: browse/use/create/edit/delete custom agents and inspect source precedence from .iosm/agents\",\n\t},\n\t{ name: \"subagent-runs\", description: \"List recent subagent runs from .iosm/subagents/runs\" },\n\t{\n\t\tname: \"subagent-resume\",\n\t\tdescription: \"Resume from prior subagent output: /subagent-resume [run-id] [extra instructions] (picker when omitted)\",\n\t},\n\t{ name: \"team-runs\", description: \"List recent team orchestration runs from .iosm/subagents/teams\" },\n\t{ name: \"team-status\", description: \"Show a team run status: /team-status [team-run-id] (picker when omitted)\" },\n\t{ name: \"cycle-list\", description: \"List IOSM cycles\" },\n\t{ name: \"cycle-plan\", description: \"Plan a new IOSM cycle: /cycle-plan [--id <id>] [--force] <goal...>\" },\n\t{ name: \"cycle-status\", description: \"Show IOSM cycle completeness and gates: /cycle-status [cycle-id]\" },\n\t{ name: \"cycle-report\", description: \"Show IOSM cycle report JSON: /cycle-report [cycle-id]\" },\n\t{\n\t\tname: \"mcp\",\n\t\tdescription:\n\t\t\t\"MCP server manager: /mcp (interactive UI), /mcp add <name> ..., /mcp list, /mcp tools [name], /mcp enable|disable|remove <name>\",\n\t},\n\t{\n\t\tname: \"memory\",\n\t\tdescription:\n\t\t\t\"Memory manager: /memory (interactive), /memory <text>, /memory edit <index> <text>, /memory rm <index>\",\n\t},\n\t{\n\t\tname: \"semantic\",\n\t\tdescription:\n\t\t\t\"Semantic search manager: /semantic (interactive UI), /semantic setup|auto-index|status|index|rebuild|query <text> [--top-k N]\",\n\t},\n\t{\n\t\tname: \"contract\",\n\t\tdescription:\n\t\t\t\"Engineering contract manager: /contract (interactive field editor), /contract show|edit|clear --scope <project|session>\",\n\t},\n\t{\n\t\tname: \"singular\",\n\t\tdescription:\n\t\t\t\"Feature feasibility analyzer: /singular <request> (builds implementation options and recommendations)\",\n\t},\n\t{ name: \"settings\", description: \"Open settings menu\" },\n\t{\n\t\tname: \"permissions\",\n\t\tdescription:\n\t\t\t\"Permission controls: /permissions (interactive menu) or /permissions [ask|auto|yolo|status|hooks] and /permissions [allow|deny] [list|add|remove] <tool:match>\",\n\t},\n\t{ name: \"yolo\", description: \"Toggle permission prompts: /yolo [on|off|status]\" },\n\t{ name: \"model\", description: \"Select model (provider-first selector UI)\" },\n\t{ name: \"scoped-models\", description: \"Enable/disable models for Ctrl+P cycling\" },\n\t{ name: \"export\", description: \"Export session to HTML file: /export [output-path] (wizard when omitted)\" },\n\t{ name: \"share\", description: \"Share session as a secret GitHub gist\" },\n\t{ name: \"copy\", description: \"Copy last agent message to clipboard\" },\n\t{ name: \"name\", description: \"Set session display name\" },\n\t{ name: \"session\", description: \"Show session info and stats\" },\n\t{\n\t\tname: \"doctor\",\n\t\tdescription: \"Run runtime diagnostics (model/auth/MCP/CLI tools/hooks/paths) with optional interactive fixes\",\n\t},\n\t{ name: \"checkpoint\", description: \"Create/list checkpoints for safe rollback\" },\n\t{ name: \"rollback\", description: \"Rollback session tree to a checkpoint (picker when omitted)\" },\n\t{ name: \"changelog\", description: \"Show changelog entries\" },\n\t{ name: \"hotkeys\", description: \"Show all keyboard shortcuts\" },\n\t{ name: \"fork\", description: \"Create a new fork from a previous message\" },\n\t{ name: \"tree\", description: \"Navigate session tree (switch branches)\" },\n\t{ name: \"login\", description: \"Authenticate with provider (OAuth incl. Qwen + OpenRouter API key)\" },\n\t{ name: \"auth\", description: \"Alias for /login\" },\n\t{ name: \"logout\", description: \"Remove saved provider credentials (OAuth/API key)\" },\n\t{ name: \"new\", description: \"Start a new session\" },\n\t{ name: \"clear\", description: \"Alias for /new\" },\n\t{ name: \"compact\", description: \"Manually compact the session context\" },\n\t{ name: \"resume\", description: \"Resume a different session\" },\n\t{ name: \"reload\", description: \"Reload extensions, skills, prompts, and themes\" },\n\t{ name: \"quit\", description: \"Quit iosm\" },\n];\n"]}