nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] Lazy-load yaml (72 modules) and cli-table3 until they are needed

Open addyCooks opened this issue 1 month ago • 1 comments

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

  1. pnpm run build
  2. Use a project folder without a .nanocoder/ directory.
  3. 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 inside parseYamlObject. If callers must stay synchronous, use createRequire(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: load cli-table3 on first table render the same way.
  • Tests: source/utils/frontmatter.spec.ts, source/markdown-parser/table-parser.spec.ts.

addyCooks avatar Oct 18 '26 06:10 addyCooks

@addyCooks would like to work on this one

Srinidhi444 avatar Oct 18 '26 06:10 Srinidhi444