summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorT <t@tjp.lol>2026-05-26 20:14:37 -0600
committerT <t@tjp.lol>2026-05-27 06:26:36 -0600
commit1f0915edbe0213e8bc134922f10933468d35a172 (patch)
tree11834769555c7037f3393ef8d98bf5841846144a /src/main.zig
parentb788eb05c6d194b91fdc141b6655e61ccaa76ddb (diff)
finish lua runtime makeover
- new multi-tool registration via ToolSource - thread per source-or-standalone-tool - switched to zig 0.16 Io threading interface - cli: include `luv` package and run concurrent lua tools via libuv - one single long-lived lua_State for the whole cli program
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main.zig b/src/main.zig
index 56ea2ad..a752a12 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -2,7 +2,7 @@ const std = @import("std");
const panto = @import("panto");
const ping_tool = @import("ping_tool.zig");
const lua_bridge = @import("lua_bridge.zig");
-const lua_tool = @import("lua_tool.zig");
+const lua_runtime = @import("lua_runtime.zig");
const extension_loader = @import("extension_loader.zig");
// Shorthand alias for the Lua C API. The bridge module owns the actual
@@ -12,7 +12,7 @@ const lua = lua_bridge.c;
test {
std.testing.refAllDecls(@This());
_ = lua_bridge;
- _ = lua_tool;
+ _ = lua_runtime;
_ = extension_loader;
}
@@ -220,13 +220,20 @@ pub fn main(init: std.process.Init) !void {
try conv.addSystemMessage("You are a helpful assistant.");
const prov = try panto.provider.Provider.init(alloc, io, config);
- var agent = panto.agent.Agent.init(alloc, prov);
+ var agent = panto.agent.Agent.init(alloc, io, prov);
defer agent.deinit();
// smoke test: register a trivial built-in tool so we can exercise
// the tool-call loop against a real LLM.
try agent.registerTool(ping_tool.tool());
+ // Spin up the long-lived Lua runtime. All Lua extensions load into
+ // one `lua_State`; module-global state survives across calls. The
+ // runtime registers with the agent as a single `ToolSource` named
+ // `panto-lua`.
+ var rt = try lua_runtime.LuaRuntime.create(alloc);
+ defer rt.deinit();
+
// Discover Lua extensions from $XDG_CONFIG_HOME/panto/extensions (or
// $HOME/.config/panto/extensions) and ./.panto/extensions. Project
// entries shadow user entries with the same name; tool-name collisions
@@ -235,13 +242,17 @@ pub fn main(init: std.process.Init) !void {
alloc,
io,
init.environ_map,
- &agent.registry,
+ rt,
) catch |err| {
std.log.err("extension discovery failed: {t}", .{err});
return err;
};
std.log.debug("extensions: {d} tool(s) registered", .{n_ext_tools});
+ if (n_ext_tools > 0) {
+ try agent.registerToolSource(rt.toolSource());
+ }
+
const banner_model: []const u8 = switch (config) {
inline else => |c| c.model,
};