From 69a1ee138bb78ad4663fe2d9e58678f7b0d07b74 Mon Sep 17 00:00:00 2001 From: t Date: Tue, 23 Jun 2026 09:38:23 -0600 Subject: ponytail simplifications to panto cli and lua extensiosn --- src/panto_home.zig | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'src/panto_home.zig') diff --git a/src/panto_home.zig b/src/panto_home.zig index 5d111d6..bc715f0 100644 --- a/src/panto_home.zig +++ b/src/panto_home.zig @@ -1,10 +1,10 @@ -//! Filesystem layout resolution for `$PANTO_HOME` and the per-Lua +//! Filesystem layout resolution for the panto data home and the per-Lua //! version rocks tree. //! -//! $PANTO_HOME = $XDG_DATA_HOME/panto -//! (or $HOME/.local/share/panto if XDG_DATA_HOME unset) +//! data home = $XDG_DATA_HOME/panto +//! (or $HOME/.local/share/panto if XDG_DATA_HOME unset) //! -//! $PANTO_HOME/ +//! data home/ //! rocks/ //! lua-5.4.7/ ← current tree //! include/ ← Lua headers staged by bootstrap @@ -28,18 +28,18 @@ const Io = std.Io; /// fields are owned by the same allocator passed to `resolve`. pub const Layout = struct { allocator: Allocator, - /// `$PANTO_HOME` itself. + /// The panto data home. home: []u8, - /// `$PANTO_HOME/agent/` — the "base" extension/tool tree, + /// `/agent/` — the "base" extension/tool tree, /// populated at bootstrap from files embedded into the panto /// binary. Searched after user/project layers for tools and /// extensions; project shadows user shadows base. agent_dir: []u8, - /// `$PANTO_HOME/auth/` — persisted provider auth tokens, one + /// `/auth/` — persisted provider auth tokens, one /// `.json` per OAuth session. Files are written owner-only; /// treat them like passwords. auth_dir: []u8, - /// `$PANTO_HOME/rocks/lua-/` — the versioned tree. + /// `/rocks/lua-/` — the versioned tree. tree: []u8, /// `/include/` — where Lua headers are staged. include_dir: []u8, @@ -74,17 +74,15 @@ pub const Layout = struct { }; /// Resolve every path the runtime cares about. Environment-driven: -/// - `PANTO_HOME` (explicit override) /// - `XDG_DATA_HOME` (XDG default) /// - `HOME` (fallback) /// -/// Returns `error.NoHomeDirectory` if none of those are available and -/// no `PANTO_HOME` was set. +/// Returns `error.NoHomeDirectory` if neither is available. pub fn resolve( allocator: Allocator, environ_map: *const std.process.Environ.Map, ) !Layout { - const home = try resolveHome(allocator, environ_map); + const home = try homePath(allocator, environ_map); errdefer allocator.free(home); const agent_dir = try std.fs.path.join(allocator, &.{ home, "agent" }); @@ -140,15 +138,12 @@ pub fn resolve( }; } -/// Resolve `$PANTO_HOME` honoring overrides in the documented order. +/// Resolve the panto data home. Returns owned bytes. /// Returns owned bytes. -fn resolveHome( +pub fn homePath( allocator: Allocator, environ_map: *const std.process.Environ.Map, ) ![]u8 { - if (environ_map.get("PANTO_HOME")) |explicit| { - return allocator.dupe(u8, explicit); - } if (environ_map.get("XDG_DATA_HOME")) |xdg| { return std.fs.path.join(allocator, &.{ xdg, "panto" }); } @@ -184,20 +179,6 @@ fn makePathRecursive(io: Io, path: []const u8) !void { const testing = std.testing; -test "resolve: PANTO_HOME explicit override wins" { - var env: std.process.Environ.Map = .init(testing.allocator); - defer env.deinit(); - try env.put("PANTO_HOME", "/tmp/some/home"); - try env.put("XDG_DATA_HOME", "/should/be/ignored"); - - var layout = try resolve(testing.allocator, &env); - defer layout.deinit(); - - try testing.expectEqualStrings("/tmp/some/home", layout.home); - try testing.expect(std.mem.indexOf(u8, layout.tree, "/tmp/some/home/rocks/lua-") != null); - try testing.expect(std.mem.endsWith(u8, layout.share_lua_dir, "/share/lua/" ++ manifest.lua_short_version)); -} - test "resolve: XDG_DATA_HOME is honored before HOME" { var env: std.process.Environ.Map = .init(testing.allocator); defer env.deinit(); -- cgit v1.3