(files: ReadonlyMap<string, string>)
| 41 | export const validToolKey = (key: string): boolean => /^[a-z0-9][a-z0-9-]*$/.test(key); |
| 42 | |
| 43 | export const discover = (files: ReadonlyMap<string, string>): DiscoverResult | PublishError => { |
| 44 | const diagnostics: FileDiagnostic[] = []; |
| 45 | const tools: DiscoveredTool[] = []; |
| 46 | const skipped: SkippedArtifact[] = []; |
| 47 | const seen = new Set<string>(); |
| 48 | |
| 49 | for (const [path] of files) { |
| 50 | if (path === "executor.json") continue; |
| 51 | const tool = toolKeyFromPath(path); |
| 52 | if (tool) { |
| 53 | const name = tool; |
| 54 | if (seen.has(name)) { |
| 55 | diagnostics.push({ path, message: `duplicate tool identity: ${name}` }); |
| 56 | } else { |
| 57 | seen.add(name); |
| 58 | tools.push({ name, entry: path }); |
| 59 | } |
| 60 | continue; |
| 61 | } |
| 62 | if (path.startsWith("tools/")) { |
| 63 | diagnostics.push({ path, message: "file does not match the expected layout for tools/" }); |
| 64 | continue; |
| 65 | } |
| 66 | if (isReservedArtifactPath(path)) skipped.push({ path, reason: "not supported yet" }); |
| 67 | } |
| 68 | |
| 69 | if (diagnostics.length > 0) { |
| 70 | return new PublishError({ |
| 71 | message: `discover found ${diagnostics.length} problem(s)`, |
| 72 | stage: "discover", |
| 73 | diagnostics, |
| 74 | }); |
| 75 | } |
| 76 | return { tools, skipped }; |
| 77 | }; |
no test coverage detected