| 1 | import compatibility from './compatibility.json' with { type: 'json' } |
| 2 | |
| 3 | /** |
| 4 | * Service names a plugin may never provide: each is one authority the Rust |
| 5 | * core owns (§4.3 of the design). `tools`, `commands` and `logger` are |
| 6 | * provided by the host root as shims and are refused to plugins for the same |
| 7 | * reason. |
| 8 | */ |
| 9 | export const REFUSED_SERVICES: ReadonlySet<string> = new Set(compatibility.refused_services) |
| 10 | |
| 11 | /** Services the root provides; `inject` of anything else fails activation. */ |
| 12 | export const PROVIDED_SERVICES: ReadonlySet<string> = new Set(Object.values(compatibility.provided_services).flat()) |
| 13 | |
| 14 | const UNPROVIDED_REASONS: ReadonlyArray<readonly [(name: string) => boolean, string]> = [ |
| 15 | [(name) => name.startsWith('@deepseek-ai/dsh-client-'), 'DSH client UI services'], |
| 16 | ] |
| 17 | |
| 18 | const quoted = (names: readonly string[]) => names.map((name) => `\`${name}\``).join(', ') |
| 19 | |
| 20 | export function describeMissingServices(names: readonly string[], { scoped: classifyScoped = true }: { scoped?: boolean } = {}): string { |
| 21 | const absent = names.filter((name) => !classifyScoped || !PROVIDED_SERVICES.has(name)) |
| 22 | const scoped = names.filter((name) => classifyScoped && PROVIDED_SERVICES.has(name)) |
| 23 | const parts: string[] = [] |
| 24 | if (absent.length > 0) { |
| 25 | const owned = absent.filter((name) => REFUSED_SERVICES.has(name)) |
| 26 | const reasons = [...new Set(absent.flatMap((name) => UNPROVIDED_REASONS.filter(([matches]) => matches(name)).map(([, reason]) => reason)))] |
| 27 | parts.push(`${quoted(absent)}, not provided by the Codewhale plugin host in this phase` |
| 28 | + (reasons.length > 0 ? ` (${reasons.join('; ')})` : '') |
| 29 | + (owned.length > 0 ? `; ${quoted(owned)} belong${owned.length === 1 ? 's' : ''} to the Codewhale core and no reviewed bridge exposes ${owned.length === 1 ? 'it' : 'them'} yet` : '')) |
| 30 | } |
| 31 | if (scoped.length > 0) parts.push(`${quoted(scoped)}, provided by the host but unavailable in this scope`) |
| 32 | return parts.join('; ') |
| 33 | } |
| 34 |