0.6 rust重构01

This commit is contained in:
lix-2026
2026-04-14 13:22:29 +08:00
parent 71fb1aee7e
commit 84a8454fa9
401 changed files with 5841 additions and 1512 deletions
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env node
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { execSync } from "node:child_process";
function rootDir() {
try {
return execSync("git rev-parse --show-toplevel", {
cwd: process.cwd(),
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
} catch {
return process.cwd();
}
}
function readStdin() {
try {
return JSON.parse(readFileSync(0, "utf8") || "{}");
} catch {
return {};
}
}
function readJson(path, fallback) {
try {
return JSON.parse(readFileSync(path, "utf8"));
} catch {
return fallback;
}
}
function writeJson(path, value) {
mkdirSync(dirname(path), { recursive: true });
writeFileSync(path, JSON.stringify(value, null, 2), "utf8");
}
const root = rootDir();
const payload = readStdin();
const omx = join(root, ".omx");
mkdirSync(join(omx, "logs"), { recursive: true });
appendFileSync(join(omx, "logs", "hooks.log"), `${new Date().toISOString()} UserPromptSubmit ${JSON.stringify(payload)}\n`, "utf8");
const runtimePath = join(omx, "state", "hook-runtime.json");
const runtime = readJson(runtimePath, {});
writeJson(runtimePath, {
...runtime,
lastPromptAt: new Date().toISOString(),
});
process.stdout.write(JSON.stringify({
continue: true,
hookSpecificOutput: {
hookEventName: "UserPromptSubmit",
additionalContext: "",
},
}));