@@ -13,6 +13,7 @@ import mcpp.config;
1313import mcpp.fetcher;
1414import mcpp.fetcher.progress;
1515import mcpp.manifest;
16+ import mcpp.pm.compat;
1617import mcpp.pm.resolver;
1718import mcpp.scaffold;
1819import mcpp.ui;
@@ -39,11 +40,9 @@ fetch_template_package(const mcpp::scaffold::TemplateSpec& spec) {
3940
4041 // Namespace candidates mirror dependency lookup: index root first,
4142 // then the compat namespace.
42- std::string ns;
4343 std::optional<std::string> lua;
4444 for (std::string cand : {std::string{}, std::string{" compat" }}) {
4545 if (auto l = fetcher.read_xpkg_lua (cand, spec.pkg )) {
46- ns = cand;
4746 lua = std::move (*l);
4847 break ;
4948 }
@@ -54,16 +53,28 @@ fetch_template_package(const mcpp::scaffold::TemplateSpec& spec) {
5453 " (check the name, or run `mcpp index update`)" , spec.pkg ));
5554 }
5655
56+ // The filename hit alone does not carry the namespace: a bare spec
57+ // like "llmapi" finds pkgs/l/llmapi.lua even though the descriptor
58+ // declares `namespace = "mcpplibs"`, and xlings resolves install
59+ // targets by the descriptor's qualified name. Derive the structured
60+ // (namespace, shortName) from the descriptor fields.
61+ auto coords = mcpp::pm::compat::descriptor_coordinates (
62+ spec.pkg ,
63+ mcpp::manifest::extract_xpkg_namespace (*lua),
64+ mcpp::manifest::extract_xpkg_name (*lua));
65+ const std::string& ns = coords.namespace_ ;
66+ const std::string& shortName = coords.shortName ;
67+
5768 std::string version = spec.version ;
5869 if (version.empty ()) {
59- auto v = mcpp::pm::resolve_semver (ns, spec. pkg , " *" , fetcher);
70+ auto v = mcpp::pm::resolve_semver (ns, shortName , " *" , fetcher);
6071 if (!v) return std::unexpected (v.error ());
6172 version = *v;
6273 }
6374
64- auto installed = fetcher.install_path (ns, spec. pkg , version);
75+ auto installed = fetcher.install_path (ns, shortName , version);
6576 if (!installed) {
66- auto fq = ns.empty () ? spec. pkg : std::format (" {}.{}" , ns, spec. pkg );
77+ auto fq = ns.empty () ? shortName : std::format (" {}.{}" , ns, shortName );
6778 mcpp::ui::info (" Downloading" , std::format (" {} v{}" , fq, version));
6879 mcpp::fetcher::InstallProgressHandler progress;
6980 std::vector<std::string> targets{ std::format (" {}@{}" , fq, version) };
@@ -72,7 +83,7 @@ fetch_template_package(const mcpp::scaffold::TemplateSpec& spec) {
7283 " fetch '{}@{}': {}" , fq, version, r.error ().message ));
7384 if (r->exitCode != 0 ) return std::unexpected (std::format (
7485 " fetch '{}@{}' failed (exit {})" , fq, version, r->exitCode ));
75- installed = fetcher.install_path (ns, spec. pkg , version);
86+ installed = fetcher.install_path (ns, shortName , version);
7687 if (!installed) return std::unexpected (std::format (
7788 " package '{}@{}' install path missing after fetch" , fq, version));
7889 }
@@ -94,7 +105,7 @@ fetch_template_package(const mcpp::scaffold::TemplateSpec& spec) {
94105 return std::unexpected (std::format (
95106 " package '{}@{}' has no mcpp.toml" , spec.pkg , version));
96107 }
97- return FetchedTemplatePackage{root, spec. pkg , version};
108+ return FetchedTemplatePackage{root, shortName , version};
98109}
99110
100111void print_template_listing (const FetchedTemplatePackage& pkg,
0 commit comments