mirror of
https://github.com/hanzoai/mcp.git
synced 2026-10-29 01:50:03 +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
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
/**
|
|
* Recipe 03: Shell Command Security Gate
|
|
*
|
|
* Objective: Screen shell commands before execution using deterministic security policy
|
|
* joined with Kai's calibrated risk assessment on the monotonic lattice: allow < ask < deny.
|
|
*/
|
|
|
|
import { createRecipeClient, logRecipe, RecipeResult } from "./helper.js";
|
|
|
|
export async function runRecipe03(): Promise<RecipeResult> {
|
|
const client = await createRecipeClient();
|
|
|
|
// Test dangerous command that must be denied by deterministic policy
|
|
const dangerousCmd = "rm -rf / --no-preserve-root";
|
|
const dangerousRes = await client.callTool("kai_command_guard", {
|
|
command: dangerousCmd,
|
|
policy: "allow"
|
|
});
|
|
|
|
// Test safe development command
|
|
const safeCmd = "cargo test -p parser -- --nocapture";
|
|
const safeRes = await client.callTool("kai_command_guard", {
|
|
command: safeCmd,
|
|
policy: "allow"
|
|
});
|
|
|
|
const result: RecipeResult = {
|
|
recipe: "03: Shell Command Security Gate",
|
|
tool: "kai_command_guard",
|
|
success: dangerousRes.data.verdict === "deny" && safeRes.data.verdict === "allow",
|
|
latency_ms: (dangerousRes.latency_ms || 0) + (safeRes.latency_ms || 0),
|
|
output: {
|
|
dangerous: dangerousRes.data,
|
|
safe: safeRes.data
|
|
},
|
|
explanation: "Dangerous rm -rf / blocked with 'deny' via deterministic policy; cargo test allowed."
|
|
};
|
|
|
|
return result;
|
|
}
|
|
|
|
if (process.argv[1]?.endsWith("03-shell-command-security-gate.ts")) {
|
|
runRecipe03().then(logRecipe).catch(console.error);
|
|
}
|