Skip to content

Commit 5f9f20e

Browse files
authored
fix: native module resolution breaks validation loop for ha:pdf (#111)
* fix: native module resolution breaks validation loop for ha:pdf The module resolution loop checked only Object.keys(newSources) to decide whether to continue resolving. Native modules (like ha:ziplib) have no .js source — only module.json metadata — so the loop broke early with valid=false and an empty errors array, producing the cryptic 'Validation failed: •' message. Root cause: ha:pdf imports ha:ziplib (native). The resolution loop loaded ziplib.json but not ziplib.js (doesn't exist). Since newSources was empty, it broke out of the loop before passing the JSON metadata to the validator. The validator then couldn't confirm ziplib was resolved, returning valid=false with no errors. Fix: check all three sources (newSources, newModuleJsons, newDtsSources) before deciding nothing was found. This allows native module metadata to flow through and lets the validator recognise them as resolved. Applied to both register_handler and register_module validation loops. Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * fix: address PR #111 review feedback — clarify comment wording - Changed 'no ha:/host: prefix' to 'missing ha: or host: prefix' to avoid confusion with the slash character - Note: registerModuleImpl loop doesn't have the early-break pattern so it was never affected by the bug (commit message corrected) Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> --------- Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent c6ed248 commit 5f9f20e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/agent/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,13 @@ async function validateHandlerCode(
12201220
moduleJsons: newModuleJsons,
12211221
} = loadModuleFilesForValidator(validation.missingSources, pluginManager);
12221222

1223-
if (Object.keys(newSources).length === 0) {
1223+
if (
1224+
Object.keys(newSources).length === 0 &&
1225+
Object.keys(newModuleJsons).length === 0 &&
1226+
Object.keys(newDtsSources).length === 0
1227+
) {
1228+
// No new sources, module metadata, or type definitions found.
1229+
// Check if any specifiers are missing a ha: or host: prefix.
12241230
const unresolvable = validation.missingSources.filter(
12251231
(s) => !s.startsWith("ha:") && !s.startsWith("host:"),
12261232
);
@@ -1401,7 +1407,12 @@ const registerHandlerTool = defineTool("register_handler", {
14011407

14021408
// If we couldn't resolve ANY of the missing sources, generate helpful errors
14031409
// This happens when imports use wrong prefixes (e.g., "pptx" instead of "ha:pptx")
1404-
if (Object.keys(newSources).length === 0) {
1410+
// Native modules have module.json but no .js source — check all three.
1411+
if (
1412+
Object.keys(newSources).length === 0 &&
1413+
Object.keys(newModuleJsons).length === 0 &&
1414+
Object.keys(newDtsSources).length === 0
1415+
) {
14051416
const unresolvable = validation.missingSources.filter(
14061417
(s) => !s.startsWith("ha:") && !s.startsWith("host:"),
14071418
);

0 commit comments

Comments
 (0)