engrm 0.4.1 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ // hooks/codex-stop.ts
4
+ import { spawn } from "node:child_process";
5
+ import { dirname, join } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ var thisDir = dirname(fileURLToPath(import.meta.url));
8
+ var delegatePath = join(thisDir, "stop.ts");
9
+ async function readStdin() {
10
+ const chunks = [];
11
+ for await (const chunk of process.stdin) {
12
+ chunks.push(typeof chunk === "string" ? chunk : Buffer.from(chunk).toString());
13
+ }
14
+ return chunks.join("");
15
+ }
16
+ async function main() {
17
+ const input = await readStdin();
18
+ const isBun = process.execPath.endsWith("bun");
19
+ const childArgs = isBun ? ["run", delegatePath] : [delegatePath];
20
+ const child = spawn(process.execPath, childArgs, {
21
+ stdio: ["pipe", "pipe", "pipe"]
22
+ });
23
+ if (input.length > 0) {
24
+ child.stdin.write(input);
25
+ }
26
+ child.stdin.end();
27
+ let stdout = "";
28
+ let stderr = "";
29
+ child.stdout.on("data", (chunk) => {
30
+ stdout += chunk.toString();
31
+ });
32
+ child.stderr.on("data", (chunk) => {
33
+ stderr += chunk.toString();
34
+ });
35
+ const exitCode = await new Promise((resolve, reject) => {
36
+ child.on("error", reject);
37
+ child.on("close", (code) => resolve(code ?? 1));
38
+ });
39
+ const messages = [stdout.trim(), stderr.trim()].filter(Boolean);
40
+ const systemMessage = messages.length > 0 ? messages.join(`
41
+ `) : null;
42
+ if (exitCode === 0) {
43
+ console.log(JSON.stringify({
44
+ continue: true,
45
+ ...systemMessage ? { systemMessage } : {}
46
+ }));
47
+ process.exit(0);
48
+ }
49
+ console.log(JSON.stringify({
50
+ continue: true,
51
+ ...systemMessage ? { systemMessage: `Engrm stop hook failed:
52
+ ${systemMessage}` } : {}
53
+ }));
54
+ process.exit(0);
55
+ }
56
+ main().catch((error) => {
57
+ console.log(JSON.stringify({
58
+ continue: true,
59
+ systemMessage: `Engrm stop hook failed: ${error instanceof Error ? error.message : String(error)}`
60
+ }));
61
+ process.exit(0);
62
+ });