Add evidence-backed investigation workflows

This commit is contained in:
morluto
2026-07-12 21:12:18 +00:00
parent 4110a4d717
commit 4ff4c11a00
178 changed files with 26320 additions and 1222 deletions
@@ -0,0 +1,55 @@
import fs from "node:fs";
import { log, statusMatrix } from "isomorphic-git";
export type ReferenceSourceVcsInfo =
| { readonly kind: "git"; readonly head: string; readonly dirty: boolean }
| { readonly kind: "none"; readonly head: null; readonly dirty: null }
| { readonly kind: "unknown"; readonly head: null; readonly dirty: null };
/**
* Read Git metadata for a directory using isomorphic-git.
*
* No git subprocess or network is used; only the local `.git` object store is read.
*/
export const readReferenceSourceVcs = async (
root: string,
): Promise<ReferenceSourceVcsInfo> => {
try {
const commits = await log({
fs,
dir: root,
ref: "HEAD",
depth: 1,
cache: {},
});
if (commits.length === 0)
return { kind: "unknown", head: null, dirty: null };
const head = commits[0]?.oid;
if (head === undefined) return { kind: "unknown", head: null, dirty: null };
let dirty = false;
try {
const matrix = await statusMatrix({
fs,
dir: root,
ref: head,
cache: {},
});
for (const row of matrix) {
const [, headStatus, workdirStatus, stageStatus] = row;
if (headStatus !== 1 || workdirStatus !== 1 || stageStatus !== 1) {
dirty = true;
break;
}
}
} catch {
dirty = true;
}
return { kind: "git", head, dirty };
} catch {
return { kind: "none", head: null, dirty: null };
}
};