From f72b5793a5c7e7891e4904be73c0bc6bc038fa18 Mon Sep 17 00:00:00 2001 From: T Date: Wed, 27 May 2026 16:34:32 -0600 Subject: system agent definition scaffolding --- src/luarocks_runtime.zig | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/luarocks_runtime.zig') diff --git a/src/luarocks_runtime.zig b/src/luarocks_runtime.zig index b67a8ad..0114b64 100644 --- a/src/luarocks_runtime.zig +++ b/src/luarocks_runtime.zig @@ -37,6 +37,7 @@ const manifest = @import("manifest.zig"); const panto_home = @import("panto_home.zig"); const embedded_luarocks = @import("embedded_luarocks"); const embedded_lua_headers = @import("embedded_lua_headers"); +const embedded_agent = @import("embedded_agent"); const lua_bridge = @import("lua_bridge.zig"); const c = lua_bridge.c; @@ -135,6 +136,7 @@ pub fn bootstrap( try panto_home.ensureDirsExist(layout, io); try stageLuaHeaders(allocator, io, layout); + try stageAgentTree(allocator, io, layout); const lua_wrapper_path = try writeLuaWrapper(allocator, io, layout, panto_executable_path); defer allocator.free(lua_wrapper_path); try writeLuarocksConfig(allocator, io, layout, lua_wrapper_path); @@ -199,6 +201,41 @@ fn stageLuaHeaders( } } +// --------------------------------------------------------------------------- +// Stage the embedded `agent/` tree +// --------------------------------------------------------------------------- + +/// Materialize the binary-embedded `agent/` tree under +/// `$PANTO_HOME/agent/`. Each entry's `path` is relative to the agent +/// root and may include subdirectories (`tools/read.lua` etc.); the +/// parent directory is created lazily as we encounter files inside it. +/// +/// Uses the same `writeIfDifferent` discipline as `stageLuaHeaders`: +/// unchanged files keep their on-disk mtime so downstream consumers +/// (the extension loader's stat-cached searches, future-rocks builds +/// against staged headers) don't see spurious invalidations. +fn stageAgentTree( + allocator: Allocator, + io: Io, + layout: panto_home.Layout, +) !void { + var root = try Io.Dir.cwd().openDir(io, layout.agent_dir, .{}); + defer root.close(io); + + for (embedded_agent.files) |entry| { + // Ensure the file's parent directory exists. `path` is + // forward-slash separated (the generator normalizes that), + // so we can split off the dirname directly. + if (std.fs.path.dirname(entry.path)) |parent| { + root.createDirPath(io, parent) catch |err| switch (err) { + error.PathAlreadyExists => {}, + else => return err, + }; + } + try writeIfDifferent(allocator, io, root, entry.path, entry.contents); + } +} + /// Write `contents` into `dir/name` only if the existing file differs. /// Creates the file if absent. fn writeIfDifferent( -- cgit v1.3