MCPcopy Create free account
hub / github.com/SethGammon/Citadel / main

Function main

scripts/install-hooks-codex.js:15–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13const VERBOSE = args.includes('--verbose') || args.includes('-v');
14const JSON_OUTPUT = args.includes('--json');
15const PROJECT_ROOT = args.find((a) => !a.startsWith('-')) || process.cwd();
16
17function main() {
18 try {
19 const resolved = reconcileEffectiveConfig(PROJECT_ROOT, { runtime: codexRuntime });
20 if (resolved.receipt.status === 'blocked') {
21 throw new Error(`Harness config blocks hook installation: ${resolved.receipt.errors.join('; ')}`);
22 }
23 const hooksTemplatePath = path.join(CITADEL_ROOT, 'hooks', 'hooks-template.json');
24 const hooksTemplate = JSON.parse(fs.readFileSync(hooksTemplatePath, 'utf8'));
25 const adapterScriptPath = path.join(CITADEL_ROOT, 'hooks_src', 'codex-adapter.js');
26 const outputPath = path.join(PROJECT_ROOT, '.codex', 'hooks.json');
27 const existingHooks = fs.existsSync(outputPath)
28 ? (JSON.parse(fs.readFileSync(outputPath, 'utf8')).hooks || {})
29 : {};
30
31 const result = installCodexHooks({
32 hooksTemplate,
33 adapterScriptPath,
34 existingHooks,
35 outputPath,
36 projectRoot: PROJECT_ROOT,
37 effectiveBundles: resolved.receipt.bundles.effective,
38 });
39
40 if (JSON_OUTPUT) {
41 process.stdout.write(JSON.stringify({
42 outputPath,
43 installed: result.installed,
44 skipped: result.skipped,
45 warnings: result.warnings || [],
46 diagnostics: result.diagnostics || [],
47 outputs: result.outputs || [],
48 machineLocalExcludes: result.machineLocalExcludes || null,
49 effectiveBundles: resolved.receipt.bundles.effective,
50 }, null, 2) + '\n');
51 return;
52 }
53
54 console.log(`Citadel Codex hooks installed to ${outputPath}`);
55 console.log(` ${result.installed.length} Citadel hooks translated for Codex`);
56 console.log(` Product bundles: ${resolved.receipt.bundles.effective.join(', ')}`);
57 if (result.diagnostics?.length) {
58 for (const diagnostic of result.diagnostics) {
59 console.log(` Diagnostic: ${diagnostic.message}`);
60 }
61 }
62 if (result.machineLocalExcludes?.written) {
63 console.log(` Machine-local outputs protected by ${result.machineLocalExcludes.path}`);
64 }
65 if (result.skipped.length > 0) {
66 console.log(` ${result.skipped.length} hook mappings skipped due to missing Codex lifecycle equivalents`);
67 }
68
69 if (VERBOSE) {
70 if (result.installed.length > 0) {
71 console.log('\nInstalled:');
72 for (const entry of result.installed) {

Callers 1

Calls 1

installCodexHooksFunction · 0.85

Tested by

no test coverage detected