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
+3
View File
@@ -0,0 +1,3 @@
{
"hooks": {}
}
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env node
import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
import { 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 {};
}
}
const payload = readStdin();
const root = rootDir();
mkdirSync(join(root, ".omx", "logs"), { recursive: true });
const exitCode =
typeof payload?.tool_output?.exit_code === "number"
? payload.tool_output.exit_code
: typeof payload?.exit_code === "number"
? payload.exit_code
: null;
const status = exitCode ?? "unknown";
const isExplicitBashFailure = payload?.tool_name === "Bash" && exitCode !== null && exitCode !== 0;
appendFileSync(
join(root, ".omx", "logs", "hooks.log"),
`${new Date().toISOString()} PostToolUse status=${status} ${JSON.stringify(payload)}\n`,
"utf8",
);
process.stdout.write(JSON.stringify({
continue: true,
hookSpecificOutput: {
hookEventName: "PostToolUse",
additionalContext: isExplicitBashFailure ? "OMX noticed a failing Bash command. Check the team inbox or diagnostics." : "",
},
}));
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env node
import { readFileSync } from "node:fs";
function readStdin() {
try {
return JSON.parse(readFileSync(0, "utf8") || "{}");
} catch {
return {};
}
}
const payload = readStdin();
const command = JSON.stringify(payload).toLowerCase();
const blocked = [
"rm -rf /",
"mkfs",
"dd if=",
"shutdown",
"reboot",
"poweroff",
"git reset --hard",
];
if (blocked.some((token) => command.includes(token))) {
process.stdout.write(JSON.stringify({
decision: "block",
reason: "OMX safety hook blocked an obviously destructive command.",
}));
process.exit(0);
}
process.stdout.write(JSON.stringify({
continue: true,
hookSpecificOutput: {
hookEventName: "PreToolUse",
},
}));
+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()} SessionStart ${JSON.stringify(payload)}\n`, "utf8");
const runtimePath = join(omx, "state", "hook-runtime.json");
const runtime = readJson(runtimePath, {});
writeJson(runtimePath, {
...runtime,
lastSessionStartAt: new Date().toISOString(),
});
process.stdout.write(JSON.stringify({
continue: true,
hookSpecificOutput: {
hookEventName: "SessionStart",
additionalContext: "",
},
}));
+54
View File
@@ -0,0 +1,54 @@
#!/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()} Stop ${JSON.stringify(payload)}\n`, "utf8");
const runtimePath = join(omx, "state", "hook-runtime.json");
const runtime = readJson(runtimePath, {});
writeJson(runtimePath, {
...runtime,
lastStopAt: new Date().toISOString(),
});
process.stdout.write(JSON.stringify({
continue: true,
}));
+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: "",
},
}));