nanocoder
nanocoder copied to clipboard
[Feature] Lazy-load yaml (72 modules) and cli-table3 until they are needed
Summary
yaml is imported at startup by utils/frontmatter.ts even when the project has no command, skill or tool files with front matter. cli-table3 is imported by the markdown table parser even when no table is ever shown. Together they load about 78 modules on every start.
Steps to reproduce
pnpm run build- Use a project folder without a
.nanocoder/directory. - From the nanocoder repo root run:
node --input-type=module -e "
import {registerHooks} from 'node:module';
const seen = new Set();
registerHooks({load(url, ctx, next) { seen.add(url); return next(url, ctx); }});
await import('ink');
await import('./dist/app/index.js');
const count = re => [...seen].filter(u => re.test(u)).length;
console.log('yaml:', count(/node_modules\/yaml\//), ' cli-table3:', count(/node_modules\/cli-table3\//));"
Expected behaviour
yaml loads when the first front matter block is parsed. cli-table3 loads when the first table is rendered.
Actual behaviour
yaml: 72 cli-table3: 6
Blocking the edges into them removes 72 and 11 modules from the startup graph.
Environment
- OS: Windows 11 (10.0.26300)
- Node: 22.22.3
- Nanocoder: 1.31.0 (main at be428fc7)
Suggested fix
source/utils/frontmatter.ts:1(import {parse as parseYaml} from 'yaml'): load it on first use insideparseYamlObject. If callers must stay synchronous, usecreateRequire(import.meta.url)('yaml')on first call. Callers:config/project-trust.ts,custom-commands/parser.ts,custom-tools/parser.ts,skills/manifest-parser.ts,subagents/markdown-parser.ts.source/markdown-parser/table-parser.ts:2: loadcli-table3on first table render the same way.- Tests:
source/utils/frontmatter.spec.ts,source/markdown-parser/table-parser.spec.ts.
@addyCooks would like to work on this one