agent: clean up and optimize code

- Fix typo in REPL info message.
- Optimize Recorder to avoid unnecessary allocations.
- Simplify field type detection in SlashCommand using stringToEnum.
- Remove unused yellow ANSI constant in Terminal.
- Shorten log message in McpServer.
This commit is contained in:
Adrià Arrufat
2026-05-04 10:51:41 +02:00
parent 03d883b263
commit c0491bd69e
5 changed files with 6 additions and 12 deletions

View File

@@ -280,7 +280,7 @@ fn runOneShot(self: *Self, task: []const u8) bool {
fn runRepl(self: *Self) void {
self.terminal.printInfo("Lightpanda Agent (type '/quit' to exit)");
self.terminal.printInfo("Tab completes/cycles throuch commands; the dim grey ghost shows the first match.");
self.terminal.printInfo("Tab completes/cycles through commands; the dim grey ghost shows the first match.");
log.debug(.app, "tools loaded", .{ .count = self.tools.len });
if (self.ai_client) |ai_client| {
self.terminal.printInfoFmt("Provider: {s}, Model: {s}", .{ @tagName(std.meta.activeTag(ai_client)), self.model });

View File

@@ -100,7 +100,7 @@ pub fn handleToolCall(self: *Self, arena: std.mem.Allocator, req: protocol.Reque
if (args.attachments) |paths| {
for (paths) |p| {
if (!isAttachmentPathSafe(p)) {
log.warn(.mcp, "rejected unsafe attachment path", .{ .path = p });
log.warn(.mcp, "unsafe attachment path", .{ .path = p });
return self.transport.sendError(
id,
.InvalidParams,

View File

@@ -49,9 +49,9 @@ pub fn record(self: *Self, cmd: Command.Command) void {
pub fn recordComment(self: *Self, comment: []const u8) void {
const f = self.file orelse return;
const prefix: []const u8 = if (self.needs_separator) "\n# " else "# ";
const line = std.fmt.allocPrint(self.allocator, "{s}{s}\n", .{ prefix, comment }) catch return;
defer self.allocator.free(line);
_ = f.write(line) catch return;
f.writeAll(prefix) catch return;
f.writeAll(comment) catch return;
f.writeAll("\n") catch return;
self.needs_separator = true;
}

View File

@@ -93,12 +93,7 @@ fn fieldTypeOf(value: std.json.Value) FieldType {
if (value != .object) return .other;
const ty = value.object.get("type") orelse return .other;
if (ty != .string) return .other;
const s = ty.string;
if (std.mem.eql(u8, s, "string")) return .string;
if (std.mem.eql(u8, s, "integer")) return .integer;
if (std.mem.eql(u8, s, "number")) return .number;
if (std.mem.eql(u8, s, "boolean")) return .boolean;
return .other;
return std.meta.stringToEnum(FieldType, ty.string) orelse .other;
}
pub fn findSchema(schemas: []const SchemaInfo, name: []const u8) ?*const SchemaInfo {

View File

@@ -12,7 +12,6 @@ const ansi_bold = "\x1b[1m";
const ansi_dim = "\x1b[2m";
const ansi_cyan = "\x1b[36m";
const ansi_green = "\x1b[32m";
const ansi_yellow = "\x1b[33m";
const ansi_red = "\x1b[31m";
history_path: ?[:0]const u8,