Files
openclaw/scripts/copy-hook-metadata.ts
T
Josh Avant a042125170 fix(memory): preserve provenance across dreaming (#126489)
* fix(memory): preserve provenance across dreaming

* fix(build): preserve bundled hook metadata

* refactor(build): remove obsolete directory helper

* test(memory): align provenance fixtures

* test(memory): type consolidation run options

* test(memory): register write provenance siblings

* fix(memory): preserve legacy provenance registration

* fix(memory): make provenance provider-independent

* fix(memory): canonicalize provenance workspace keys

* fix(memory): keep provenance mutation host-private

* fix(build): track runtime postbuild implementations

* fix(build): verify bundled hook metadata outputs
2026-08-20 17:58:31 -07:00

61 lines
2.0 KiB
TypeScript

#!/usr/bin/env tsx
/**
* Copy HOOK.md files from src/hooks/bundled to dist/bundled
*/
import fs from "node:fs";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { logVerboseCopy, resolveBuildCopyContext } from "./lib/copy-assets.ts";
const context = resolveBuildCopyContext(import.meta.url);
type CopyHookMetadataParams = {
rootDir?: string;
fs?: typeof fs;
verbose?: boolean;
};
function listHookMetadataFiles(rootDir: string, fsImpl: typeof fs) {
const sourceRoot = path.join(rootDir, "src", "hooks", "bundled");
if (!fsImpl.existsSync(sourceRoot)) {
return [];
}
return fsImpl
.readdirSync(sourceRoot, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => ({
source: path.join(sourceRoot, entry.name, "HOOK.md"),
target: path.join(rootDir, "dist", "bundled", entry.name, "HOOK.md"),
}))
.filter(({ source }) => fsImpl.existsSync(source));
}
export function listHookMetadataOutputs(params: CopyHookMetadataParams = {}): string[] {
const rootDir = params.rootDir ?? context.projectRoot;
const fsImpl = params.fs ?? fs;
return listHookMetadataFiles(rootDir, fsImpl).map(({ target }) =>
path.relative(rootDir, target).replaceAll(path.sep, "/"),
);
}
export function copyHookMetadata(params: CopyHookMetadataParams = {}): number {
const rootDir = params.rootDir ?? context.projectRoot;
const fsImpl = params.fs ?? fs;
let copiedCount = 0;
for (const { source, target } of listHookMetadataFiles(rootDir, fsImpl)) {
fsImpl.mkdirSync(path.dirname(target), { recursive: true });
fsImpl.copyFileSync(source, target);
copiedCount += 1;
if (params.verbose) {
logVerboseCopy(context, `Copied ${path.basename(path.dirname(target))}/HOOK.md`);
}
}
return copiedCount;
}
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
const copiedCount = copyHookMetadata({ verbose: true });
console.log(`${context.prefix} Copied ${copiedCount} hook metadata files.`);
}