mirror of
https://github.com/hanzoai/mcp.git
synced 2026-10-29 02:55:49 +00:00
- Implement 8 native purpose-built Kai tools in src/tools/kai.ts: - kai_tool_select: shortlist tools & resolve client casing/aliases (bash -> Bash) - kai_next_action: emit executable action with zero-inference fast paths - kai_command_guard: monotonic security policy lattice (allow < ask < deny) - kai_injection_screen: prompt-injection & override screening - kai_log_triage: compiler/test failure categorization & span pinpointing - kai_recover: failure loop breaker & recovery strategy selection - kai_extract: typed discrete dimension extraction - kai_decide: multi-question joint forward pass decisions - Add 15 runnable cookbook recipes in cookbook/ with helper & index runners - Add test suites: test/tools/kai-purpose-built.test.ts (18/18) & test/cookbook.test.ts (15/15) - Support Claude Code CLI transport flags (--allow-path, allowUnknownOption) - Add comprehensive cookbook documentation and client configuration guides
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
/**
|
|
* Recipe 13: Git Operation Security Guard
|
|
*
|
|
* Objective: Protect git repositories by distinguishing safe local inspection commands
|
|
* (git status, git diff) from destructive operations (git push --force, git reset --hard).
|
|
*/
|
|
|
|
import { createRecipeClient, logRecipe, RecipeResult } from "./helper.js";
|
|
|
|
export async function runRecipe13(): Promise<RecipeResult> {
|
|
const client = await createRecipeClient();
|
|
|
|
const commands = [
|
|
{ cmd: "git status --porcelain", expected: "allow" },
|
|
{ cmd: "git diff HEAD~1", expected: "allow" },
|
|
{ cmd: "git reset --hard origin/main", expected: "ask" },
|
|
{ cmd: "git push --force origin main", expected: "ask" }
|
|
];
|
|
|
|
const verdicts: Record<string, string> = {};
|
|
for (const c of commands) {
|
|
const res = await client.callTool("kai_command_guard", {
|
|
command: c.cmd
|
|
});
|
|
verdicts[c.cmd] = res.data.verdict;
|
|
}
|
|
|
|
const success = verdicts["git status --porcelain"] === "allow" &&
|
|
verdicts["git diff HEAD~1"] === "allow" &&
|
|
verdicts["git reset --hard origin/main"] !== "allow" &&
|
|
verdicts["git push --force origin main"] !== "allow";
|
|
|
|
const result: RecipeResult = {
|
|
recipe: "13: Git Destructive Guard",
|
|
tool: "kai_command_guard",
|
|
success,
|
|
output: verdicts,
|
|
explanation: "Safe git queries allowed; destructive force push and hard reset flagged for user approval (ask)."
|
|
};
|
|
|
|
return result;
|
|
}
|
|
|
|
if (process.argv[1]?.endsWith("13-git-destructive-guard.ts")) {
|
|
runRecipe13().then(logRecipe).catch(console.error);
|
|
}
|