summaryrefslogtreecommitdiff
path: root/subagents/paths.lua
diff options
context:
space:
mode:
Diffstat (limited to 'subagents/paths.lua')
-rw-r--r--subagents/paths.lua36
1 files changed, 16 insertions, 20 deletions
diff --git a/subagents/paths.lua b/subagents/paths.lua
index 678e241..8b6d9fa 100644
--- a/subagents/paths.lua
+++ b/subagents/paths.lua
@@ -2,12 +2,13 @@
--
-- Two jobs live here:
--
--- 1. Config-layer discovery. `config_roots("agents")` returns the two
+-- 1. Config-layer discovery. `config_roots("agents")` returns the
-- directories profiles (or workflows) are read from, lowest precedence
--- first: `${XDG_CONFIG_HOME:-$HOME/.config}/panto/<name>` and
--- `<cwd>/.panto/<name>`. A root whose base cannot be resolved (no HOME
--- and no XDG_CONFIG_HOME) is simply omitted, so callers must not assume
--- two entries. `walk` then collects `**/*.<suffix>` beneath a root.
+-- first, as `<layer>/<name>` for every layer the host reports in
+-- `panto.ext.dirs.layers` (base, user, project, local). The host owns
+-- that list, so this file never reads HOME or the XDG variables itself;
+-- a host that reports no layers yields no roots. `walk` then collects
+-- `**/*.<suffix>` beneath a root.
--
-- 2. The child session store. `child_store_dir()` derives
-- `<session_dir>/subagents/<primary session id>` from the host's
@@ -69,24 +70,19 @@ function M.read_file(path)
return data
end
--- User layer first, project layer second: later roots shadow earlier ones.
+-- One root per host layer, in the host's order: later roots shadow earlier
+-- ones. A layer the host could not resolve is simply absent from its list.
function M.config_roots(name)
local roots = {}
- local config_home = os.getenv("XDG_CONFIG_HOME")
- if config_home == nil or config_home == "" then
- local home = os.getenv("HOME")
- if home ~= nil and home ~= "" then
- config_home = home .. "/.config"
- else
- config_home = nil
- end
- end
- if config_home ~= nil then
- roots[#roots + 1] = config_home .. "/panto/" .. name
+ local ok, ext = pcall(host)
+ local layers = ok and type(ext) == "table" and ext.dirs and ext.dirs.layers
+ if type(layers) ~= "table" then
+ return roots
end
- local cwd = M.cwd()
- if cwd ~= nil and cwd ~= "" then
- roots[#roots + 1] = cwd .. "/.panto/" .. name
+ for _, layer in ipairs(layers) do
+ if type(layer) == "table" and type(layer.dir) == "string" and layer.dir ~= "" then
+ roots[#roots + 1] = layer.dir .. "/" .. name
+ end
end
return roots
end