diff options
| author | T <t@tjp.lol> | 2026-05-26 12:30:31 -0600 |
|---|---|---|
| committer | T <t@tjp.lol> | 2026-05-26 12:57:33 -0600 |
| commit | b4f50c9e82504ff81d3d264ad9136911fffd2e17 (patch) | |
| tree | 83cd4b0cfbe28e2ccc5968d3913e692f34b48f78 /src/main.zig | |
| parent | e65ea596306721d3a2327cf6230e7106db77a414 (diff) | |
extension loading from lua files/directories
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/main.zig b/src/main.zig index 6407611..56ea2ad 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,6 +3,7 @@ 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 extension_loader = @import("extension_loader.zig"); // Shorthand alias for the Lua C API. The bridge module owns the actual // `@cImport`; we re-use it here so the smoke check uses identical types. @@ -12,6 +13,7 @@ test { std.testing.refAllDecls(@This()); _ = lua_bridge; _ = lua_tool; + _ = extension_loader; } const Receiver = panto.provider.Receiver; @@ -225,26 +227,20 @@ pub fn main(init: std.process.Init) !void { // the tool-call loop against a real LLM. try agent.registerTool(ping_tool.tool()); - // Load any Lua extensions specified via `--lua <path>` flags. This is a - // slice-2 manual hook — slice 3 will replace it with directory discovery. - const argv = try init.minimal.args.toSlice(init.arena.allocator()); - var i: usize = 1; - while (i < argv.len) : (i += 1) { - const a = argv[i]; - if (std.mem.eql(u8, a, "--lua")) { - i += 1; - if (i >= argv.len) { - std.log.err("--lua requires a path argument", .{}); - return error.MissingLuaPath; - } - const path = argv[i]; - const n = lua_tool.loadExtension(alloc, &agent.registry, path) catch |err| { - std.log.err("failed to load Lua extension {s}: {t}", .{ path, err }); - return err; - }; - std.log.debug("lua: loaded {d} tool(s) from {s}", .{ n, path }); - } - } + // 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 + // between extensions abort startup. + const n_ext_tools = extension_loader.discoverAndLoad( + alloc, + io, + init.environ_map, + &agent.registry, + ) catch |err| { + std.log.err("extension discovery failed: {t}", .{err}); + return err; + }; + std.log.debug("extensions: {d} tool(s) registered", .{n_ext_tools}); const banner_model: []const u8 = switch (config) { inline else => |c| c.model, |
