import { registerHooks } from 'node:module' const STUB = ` const store = globalThis.__factoryStore ??= new Map(); export const packageStorage = () => ({ async get(k) { return store.get(k) ?? null }, async set(k, v) { store.set(k, JSON.stringify(v)) }, }); export const packageContext = { appBasePath: '/apps/factory/' }; export async function credential(key) { if (key === 'model') return { name: 'model', fetch: async () => Response.json({ result: { answers: {} } }) }; throw new Error('credential not mapped'); } export async function credentials() { return [] } export const kody = {}; ` registerHooks({ resolve(spec, ctx, next) { if (spec === 'kody:runtime') return { url: `data:text/javascript,${encodeURIComponent(STUB)}`, shortCircuit: true } if (spec === 'kody:@kody/bugbot') { const code = `export default async function(input) { globalThis.__bugbotInput = input; return globalThis.__bugbotResult ?? { posted: false }; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } if (spec === 'kody:@kody/clef/evaluate') { const code = `export default async function(input) { return globalThis.__clefResult ?? { ok: true, answers: {} }; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } if (spec === 'kody:@kody/github/graphql') { const code = `export default async function() { return { data: { repository: { pullRequest: null } } }; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } if (spec === 'kody:@kody/github/request') { const code = `export default async function() { return {}; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } if (spec === 'kody:@kody/github/pr/set-review-status') { const code = `export default async function() { return {}; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } if (spec === 'kody:@kody/discord/format-report') { const code = `export default function() { return { content: '' }; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } if (spec === 'kody:@kody/discord/post-message') { const code = `export default async function() { return {}; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } if (spec === 'kody:@kody/discord/send-shipped-pr') { const code = `export default async function() { return {}; }` return { url: `data:text/javascript,${encodeURIComponent(code)}`, shortCircuit: true } } return next(spec, ctx) }, }) await import('./bugbot-port.cases.ts')