feat: implement native hooks runtime

This commit is contained in:
jb
2026-09-01 16:43:46 -04:00
parent 3a9e61c22d
commit 73fa3299bf
59 changed files with 3392 additions and 8 deletions
@@ -0,0 +1,8 @@
import type { VerificationPolicy } from "pi-native-hooks/policy";
const manifests = new Set(["package.json", "package-lock.json", "tsconfig.json"]);
const behavior = (path: string) => /^(extensions|scripts|services|skills|config)\//.test(path) || manifests.has(path);
const types = (path: string) => /\.tsx?$/.test(path) || manifests.has(path);
export default { kind: "verification", id: "harness-tools-verification", project: { matches: (project) => project.packageName === "harness-tools" }, requirements: [
{ id: "tests", command: "npm test", cwd: "project-root", affects: behavior },
{ id: "typecheck", command: "npm run typecheck", cwd: "project-root", affects: types },
] } satisfies VerificationPolicy;
@@ -0,0 +1,8 @@
import type { VerificationPolicy } from "pi-native-hooks/policy";
const manifests = new Set(["package.json", "package-lock.json", "tsconfig.json"]);
const behavior = (path: string) => /^(extensions|src|tests|examples|skills)\//.test(path) || manifests.has(path);
const types = (path: string) => /\.tsx?$/.test(path) || manifests.has(path);
export default { kind: "verification", id: "pi-native-hooks-verification", project: { matches: (project) => project.packageName === "pi-native-hooks" }, requirements: [
{ id: "tests", command: "npm test", cwd: "project-root", affects: behavior },
{ id: "typecheck", command: "npm run typecheck", cwd: "project-root", affects: types },
] } satisfies VerificationPolicy;
@@ -0,0 +1,7 @@
import type { DiagnosticPolicy } from "pi-native-hooks/policy";
const ruleIds = new Set(["typescript-no-dynamic-import-ts", "typescript-no-dynamic-import-tsx"]);
export default {
kind: "diagnostic", id: "typescript-no-dynamic-import", analyzerKeys: ["ast-grep:personal"],
appliesTo: (_project, paths) => paths.some((path) => /\.tsx?$/.test(path)),
evaluate: (analysis) => (analysis.get("ast-grep:personal")?.findings ?? []).filter((finding) => ruleIds.has(finding.ruleId)).map((finding) => ({ policyId: "typescript-no-dynamic-import", ruleId: finding.ruleId, path: finding.path, line: finding.range.start.line, column: finding.range.start.column, message: finding.message, guidance: "Prefer a static import unless lazy loading, code splitting, an optional dependency, or runtime module selection is intentional.", exception: `Use ast-grep-ignore: ${finding.ruleId} -- <short rationale> for an intentional dynamic import.`, matchedTextHash: finding.matchedTextHash })),
} satisfies DiagnosticPolicy;
@@ -0,0 +1,7 @@
import type { DiagnosticPolicy } from "pi-native-hooks/policy";
const ruleIds = new Set(["typescript-no-non-null-assertion-ts", "typescript-no-non-null-assertion-tsx"]);
export default {
kind: "diagnostic", id: "typescript-no-non-null-assertion", analyzerKeys: ["ast-grep:personal"],
appliesTo: (_project, paths) => paths.some((path) => /\.tsx?$/.test(path)),
evaluate: (analysis) => (analysis.get("ast-grep:personal")?.findings ?? []).filter((finding) => ruleIds.has(finding.ruleId)).map((finding) => ({ policyId: "typescript-no-non-null-assertion", ruleId: finding.ruleId, path: finding.path, line: finding.range.start.line, column: finding.range.start.column, message: finding.message, guidance: "Prefer a guard, refinement, assertion function, or corrected type.", exception: `Use ast-grep-ignore: ${finding.ruleId} -- <short rationale> when the invariant is intentional.`, matchedTextHash: finding.matchedTextHash })),
} satisfies DiagnosticPolicy;