( input: DiscoverWorkflowScriptsInput )
| 31 | * workflows cover the common case. |
| 32 | */ |
| 33 | export async function discoverWorkflowScripts( |
| 34 | input: DiscoverWorkflowScriptsInput |
| 35 | ): Promise<AvailableWorkflow[]> { |
| 36 | const skillNames: SkillName[] = []; |
| 37 | const seen = new Set<string>(); |
| 38 | const addSkill = (descriptor: AgentSkillDescriptor) => { |
| 39 | if (!seen.has(descriptor.name)) { |
| 40 | seen.add(descriptor.name); |
| 41 | skillNames.push(descriptor.name); |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | // Built-ins aren't part of discoverAgentSkills' project/global scan, so seed them first; |
| 46 | // readAgentSkill resolves by precedence (project > global > built-in) when names collide. |
| 47 | getBuiltInSkillDescriptors().forEach(addSkill); |
| 48 | try { |
| 49 | (await discoverAgentSkills(input.runtime, input.workspacePath)).forEach(addSkill); |
| 50 | } catch (error) { |
| 51 | log.warn(`Workflow script discovery: failed to enumerate skills: ${getErrorMessage(error)}`); |
| 52 | } |
| 53 | |
| 54 | const available: AvailableWorkflow[] = []; |
| 55 | for (const skillName of skillNames) { |
| 56 | try { |
| 57 | const resolved = await resolveWorkflowScript({ |
| 58 | scriptPath: `skill://${skillName}/${WORKFLOW_SKILL_ENTRY}`, |
| 59 | runtime: input.runtime, |
| 60 | workspacePath: input.workspacePath, |
| 61 | projectTrusted: input.projectTrusted, |
| 62 | }); |
| 63 | available.push({ |
| 64 | descriptor: buildWorkflowScriptDescriptor(resolved), |
| 65 | scriptPath: resolved.canonicalScriptPath, |
| 66 | args: summarizeWorkflowArgs(parseWorkflowMetadata(resolved.source)) ?? [], |
| 67 | }); |
| 68 | } catch { |
| 69 | // Skip non-workflow skills (no workflow.js), untrusted project skills, AND scripts whose |
| 70 | // arg metadata fails to parse/summarize — keeping the whole body in the per-skill catch so |
| 71 | // one malformed workflow can't abort discovery and hide every other workflow. |
| 72 | continue; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | available.sort((a, b) => a.descriptor.name.localeCompare(b.descriptor.name)); |
| 77 | return available; |
| 78 | } |
no test coverage detected