Something went wrong. Try again.
My version of https://github.com/vercel-labs/fx
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364const std = @import("std");
const Allocator = std.mem.Allocator;
/// Classifies command-shaped tool calls that use captured execution rather/// than a durable terminal session. Historical `run_command` records remain/// presentation-compatible even though that tool is no longer executable.pub fn isToolCall( alloc: Allocator, tool_name: []const u8, arguments_json: []const u8,) Allocator.Error!bool { if (std.mem.eql(u8, tool_name, "run_command")) return true; const legacy_terminal = std.mem.eql(u8, tool_name, "terminal"); const shell = std.mem.eql(u8, tool_name, "shell"); if (!legacy_terminal and !shell) return false;
var parsed = std.json.parseFromSlice(std.json.Value, alloc, arguments_json, .{}) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, else => return false, }; defer parsed.deinit(); if (parsed.value != .object) return false; const action = parsed.value.object.get("action") orelse return false; if (action != .string) return false; if (legacy_terminal) return std.mem.eql(u8, action.string, "exec"); if (!std.mem.eql(u8, action.string, "run")) return false; const tty = parsed.value.object.get("tty") orelse return true; return tty == .null or (tty == .bool and !tty.bool);}
test "captured command classification recognizes shell run and historical records" { const alloc = std.testing.allocator; try std.testing.expect(try isToolCall( alloc, "terminal", "{\"action\":\"exec\",\"command\":\"printf ok\"}", )); try std.testing.expect(!try isToolCall( alloc, "terminal", "{\"action\":\"start\",\"command\":\"printf ok\"}", )); try std.testing.expect(try isToolCall( alloc, "shell", "{\"action\":\"run\",\"command\":\"printf ok\"}", )); try std.testing.expect(!try isToolCall( alloc, "shell", "{\"action\":\"run\",\"command\":\"printf ok\",\"tty\":true}", )); try std.testing.expect(!try isToolCall( alloc, "shell", "{\"action\":\"wait\",\"session_id\":\"shell-1\"}", )); try std.testing.expect(try isToolCall(alloc, "run_command", "{}")); try std.testing.expect(!try isToolCall(alloc, "read_file", "{}")); try std.testing.expect(!try isToolCall(alloc, "terminal", "not-json")); try std.testing.expect(!try isToolCall(alloc, "shell", "not-json"));}