From 52b2ca78aed7950af27d4865aee65da781514a99 Mon Sep 17 00:00:00 2001 From: T Date: Sun, 26 Apr 2026 11:09:37 -0600 Subject: Initial work, and name change to pantograph --- src/main.zig | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main.zig (limited to 'src') diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..1356bdc --- /dev/null +++ b/src/main.zig @@ -0,0 +1,59 @@ +const std = @import("std"); +const libpanto = @import("libpanto"); + +pub fn main() !void { + const config = libpanto.config.Config.fromEnv() catch |err| switch (err) { + error.MissingApiKey => { + std.debug.print("panto: PANTO_API_KEY environment variable is required\n", .{}); + return; + }, + }; + + var debug_allocator = std.heap.DebugAllocator(.{}).init; + defer _ = debug_allocator.deinit(); + const alloc = debug_allocator.allocator(); + + var conv = libpanto.conversation.Conversation.init(alloc); + defer conv.deinit(); + + try conv.addSystemMessage("You are a helpful assistant."); + + const io = std.Io.Threaded.global_single_threaded.io(); + + var stdout_buffer: [4096]u8 = undefined; + var stdout_file = std.Io.File.stdout().writer(io, &stdout_buffer); + const stdout = &stdout_file.interface; + + var stdin_buffer: [4096]u8 = undefined; + var stdin_file = std.Io.File.stdin().reader(io, &stdin_buffer); + const stdin = &stdin_file.interface; + + try stdout.print("panto — model: {s}\n> ", .{config.model}); + try stdout_file.flush(); + + while (true) { + const line = stdin.takeDelimiter('\n') catch |err| { + std.debug.print("Read error: {}\n", .{err}); + return; + }; + if (line) |text| { + if (text.len == 0) { + try stdout.print("> ", .{}); + try stdout_file.flush(); + continue; + } + // Copy the line since the reader buffer may be reused + const owned = try alloc.dupe(u8, text); + defer alloc.free(owned); + try conv.addUserMessage(owned); + // TODO: call agent.runStep() once provider is implemented + try stdout.print("(streaming not yet implemented)\n> ", .{}); + try stdout_file.flush(); + } else { + // EOF (Ctrl+D) + try stdout.print("\n", .{}); + try stdout_file.flush(); + break; + } + } +} -- cgit v1.3