(
argsList: TaskCreateArgs[],
options: TaskCreateManyOptions = {}
)
| 2177 | } |
| 2178 | |
| 2179 | async createMany( |
| 2180 | argsList: TaskCreateArgs[], |
| 2181 | options: TaskCreateManyOptions = {} |
| 2182 | ): Promise<Result<TaskCreateResult[], string>> { |
| 2183 | if (argsList.length === 0) { |
| 2184 | return Ok([]); |
| 2185 | } |
| 2186 | |
| 2187 | // sharedWorkspacePath is set for honored isolation: "none" plans; the entry is persisted |
| 2188 | // pointing at the parent's checkout and startReservedAgentTask reuses it without fork/init. |
| 2189 | const plans: Array< |
| 2190 | TaskLaunchPlan & { status: "queued" | "starting"; sharedWorkspacePath?: string } |
| 2191 | > = []; |
| 2192 | const results: TaskCreateResult[] = []; |
| 2193 | |
| 2194 | await using _lock = await this.mutex.acquire(); |
| 2195 | |
| 2196 | const cfg = this.config.loadConfigOrDefault(); |
| 2197 | const taskSettings = cfg.taskSettings ?? DEFAULT_TASK_SETTINGS; |
| 2198 | let reservedActiveCount = |
| 2199 | this.countActiveAgentTasks(cfg) + (await this.countActiveWorkspaceTurns()); |
| 2200 | |
| 2201 | for (const args of argsList) { |
| 2202 | const parentWorkspaceId = coerceNonEmptyString(args.parentWorkspaceId); |
| 2203 | if (!parentWorkspaceId) return Err("Task.createMany: parentWorkspaceId is required"); |
| 2204 | if (args.kind !== "agent") return Err("Task.createMany: unsupported kind"); |
| 2205 | |
| 2206 | const prompt = coerceNonEmptyString(args.prompt); |
| 2207 | if (!prompt) return Err("Task.createMany: prompt is required"); |
| 2208 | |
| 2209 | const normalizedAgentId = normalizeAgentId(args.agentId ?? args.agentType, ""); |
| 2210 | if (!normalizedAgentId) return Err("Task.createMany: agentId is required"); |
| 2211 | const parsedAgentId = AgentIdSchema.safeParse(normalizedAgentId); |
| 2212 | if (!parsedAgentId.success) { |
| 2213 | return Err(`Task.createMany: invalid agentId (${normalizedAgentId})`); |
| 2214 | } |
| 2215 | const agentId = parsedAgentId.data; |
| 2216 | const agentType = agentId; |
| 2217 | |
| 2218 | let normalizedBestOf: TaskCreateArgs["bestOf"]; |
| 2219 | const bestOf = args.bestOf; |
| 2220 | if (bestOf) { |
| 2221 | const groupId = coerceNonEmptyString(bestOf.groupId); |
| 2222 | if (!groupId) |
| 2223 | return Err("Task.createMany: bestOf.groupId is required when bestOf is provided"); |
| 2224 | if (!Number.isInteger(bestOf.index) || bestOf.index < 0) { |
| 2225 | return Err("Task.createMany: bestOf.index must be a non-negative integer"); |
| 2226 | } |
| 2227 | if (!Number.isInteger(bestOf.total) || bestOf.total < 2) { |
| 2228 | return Err("Task.createMany: bestOf.total must be an integer >= 2"); |
| 2229 | } |
| 2230 | if (bestOf.index >= bestOf.total) { |
| 2231 | return Err("Task.createMany: bestOf.index must be less than bestOf.total"); |
| 2232 | } |
| 2233 | const kind = normalizeTaskGroupKind(bestOf.kind); |
| 2234 | const label = normalizeTaskGroupLabel(bestOf.label); |
| 2235 | if (kind === TASK_GROUP_KIND.VARIANTS && !label) { |
| 2236 | return Err("Task.createMany: bestOf.label is required when bestOf.kind is variants"); |
nothing calls this directly
no test coverage detected