From 5d701742887f5fcb869363aeeb4d8ec70b4d5b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Mon, 11 May 2026 13:11:39 +0200 Subject: [PATCH] terminal: replace linenoise with isocline Replaces the linenoise library with isocline for improved REPL functionality. Updates build scripts and moves completion state from global variables into the Terminal struct. --- build.zig | 10 +- build.zig.zon | 8 +- src/agent/Agent.zig | 2 +- src/agent/Terminal.zig | 286 ++++++++++++----------------------------- 4 files changed, 90 insertions(+), 216 deletions(-) diff --git a/build.zig b/build.zig index eabf5fbf..9a9e6c25 100644 --- a/build.zig +++ b/build.zig @@ -88,7 +88,7 @@ pub fn build(b: *Build) !void { try linkCurl(b, mod, enable_tsan); try linkHtml5Ever(b, mod); linkZenai(b, mod); - linkLinenoise(b, mod); + linkIsocline(b, mod); break :blk mod; }; @@ -1005,11 +1005,11 @@ fn linkZenai(b: *Build, mod: *Build.Module) void { mod.addImport("zenai", dep.module("zenai")); } -fn linkLinenoise(b: *Build, mod: *Build.Module) void { - const dep = b.dependency("linenoise", .{}); - mod.addIncludePath(dep.path("")); +fn linkIsocline(b: *Build, mod: *Build.Module) void { + const dep = b.dependency("isocline", .{}); + mod.addIncludePath(dep.path("include")); mod.addCSourceFile(.{ - .file = dep.path("linenoise.c"), + .file = dep.path("src/isocline.c"), }); } diff --git a/build.zig.zon b/build.zig.zon index 5ec074d6..d0509464 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -34,10 +34,6 @@ .url = "https://github.com/allyourcodebase/sqlite3/archive/8f840560eae88ab66668c6827c64ffbd0d74ef37.tar.gz", .hash = "sqlite3-3.51.0-DMxLWssOAABZ8cAvU_LfBIbp0kZjm824PU8sSLXpEDdr", }, - .linenoise = .{ - .url = "https://github.com/antirez/linenoise/archive/refs/tags/2.0.tar.gz", - .hash = "N-V-__8AAJ4HAgCX79UDBfNwhqAqUVoGC44ib6UYa18q6oa_", - }, .zenai = .{ .url = "git+https://github.com/lightpanda-io/zenai.git#fb7d356617dcf7559c2d47d56b73d9b082f81b9b", .hash = "zenai-0.0.0-iOY_VOebAwA19L7IyQKx8CJRDbNwf75jN_nJ_F3OFD8m", @@ -46,6 +42,10 @@ .url = "https://ftp.gnu.org/gnu/libidn/libidn2-2.3.8.tar.gz", .hash = "N-V-__8AABGOuAC_dhAN07kfoP4dycCFi8Bka4O-tuhriNH8", }, + .isocline = .{ + .url = "https://github.com/daanx/isocline/archive/refs/tags/v1.1.0.tar.gz", + .hash = "N-V-__8AAAO9EgA-gjVR9Uf87fpOT--TBHVEvafXa3yRa0HY", + }, }, .paths = .{""}, } diff --git a/src/agent/Agent.zig b/src/agent/Agent.zig index 16011af7..e71bde4c 100644 --- a/src/agent/Agent.zig +++ b/src/agent/Agent.zig @@ -228,7 +228,7 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Self self.cmd_executor = CommandExecutor.init(allocator, tool_executor, &self.terminal); - Terminal.setSlashSchemas(slash_schemas); + self.terminal.setSlashSchemas(slash_schemas); return self; } diff --git a/src/agent/Terminal.zig b/src/agent/Terminal.zig index 716945ce..e0c780c1 100644 --- a/src/agent/Terminal.zig +++ b/src/agent/Terminal.zig @@ -5,7 +5,7 @@ const Config = lp.Config; const SlashCommand = @import("SlashCommand.zig"); const Spinner = @import("Spinner.zig"); const c = @cImport({ - @cInclude("linenoise.h"); + @cInclude("isocline.h"); }); const Self = @This(); @@ -35,62 +35,70 @@ verbosity: Verbosity, repl_arena: ?std.heap.ArenaAllocator, stderr_is_tty: bool, spinner: Spinner, +/// Schemas the completer uses to render `/slash` arg hints. Empty until +/// `setSlashSchemas` is called. +slash_schemas: []const SlashCommand.SchemaInfo = &.{}, -const CommandInfo = struct { name: [:0]const u8, hint: [:0]const u8 }; +const CommandInfo = struct { name: [:0]const u8 }; const commands = [_]CommandInfo{ - .{ .name = "GOTO", .hint = " " }, - .{ .name = "CLICK", .hint = " ''" }, - .{ .name = "TYPE", .hint = " '' ''" }, - .{ .name = "WAIT", .hint = " ''" }, - .{ .name = "SCROLL", .hint = " [x] [y]" }, - .{ .name = "HOVER", .hint = " ''" }, - .{ .name = "SELECT", .hint = " '' ''" }, - .{ .name = "CHECK", .hint = " '' [true|false]" }, - .{ .name = "TREE", .hint = "" }, - .{ .name = "MARKDOWN", .hint = "" }, - .{ .name = "EXTRACT", .hint = " ''" }, - .{ .name = "EVAL", .hint = " '