Files
pi/scripts/issues/source-hooks.mjs
Mario Zechner 5a10492690 feat: add local issue triage tool in scripts/issues
Syncs issues with gh, triages new ones with a pi-durable agent (category, duplicates, summary, p0/p1/none suggestion), and serves a web UI for decisions.
2026-10-09 17:12:26 +00:00

31 lines
1.3 KiB
JavaScript

// Resolve workspace packages to their TypeScript sources, so the triage tool runs without building packages.
// A package without a "source" export condition (pi-ai) resolves to dist/*.js; this maps it to src/*.ts.
import { existsSync, realpathSync } from "node:fs";
import { fileURLToPath, pathToFileURL } from "node:url";
const DIST_JS = /(\/(?:packages|node_modules\/@earendil-works)\/[^/]+)\/dist\/(.+)\.js$/;
function toSource(url) {
if (!url?.startsWith("file:")) return undefined;
const path = fileURLToPath(url);
if (path.includes("/node_modules/") && !path.includes("/node_modules/@earendil-works/")) return undefined;
if (!DIST_JS.test(path)) return undefined;
const source = path.replace(DIST_JS, "$1/src/$2.ts");
if (!existsSync(source)) return undefined;
// Real path: Node refuses to strip types under node_modules.
return pathToFileURL(realpathSync(source)).href;
}
export async function resolve(specifier, context, nextResolve) {
let result;
try {
result = await nextResolve(specifier, context);
} catch (error) {
const source = toSource(error?.url);
if (source) return { url: source, format: "module-typescript", shortCircuit: true };
throw error;
}
const source = toSource(result.url);
return source ? { url: source, format: "module-typescript", shortCircuit: true } : result;
}