Skip to content

feat: headless api mode - #851

Open
AryanNandanwar wants to merge 4 commits into
Nano-Collective:mainfrom
AryanNandanwar:feature/headless-api-mode
Open

feat: headless api mode#851
AryanNandanwar wants to merge 4 commits into
Nano-Collective:mainfrom
AryanNandanwar:feature/headless-api-mode

Conversation

@AryanNandanwar

@AryanNandanwar AryanNandanwar commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Refs #810

Description

Defer ink and @/app loading in cli.tsx until the interactive TUI branch so --acp (and other non-TUI paths) no longer pay the Ink/App module-graph cost at startup. Extract a framework-free parseContextLimit() for --context-max, add ACP startup metrics to the quality benchmark, refresh the baseline, and correct ACP vs legacy --vscode docs.

Related to #810 — first step toward Headless API Mode. --acp already runs the Ink-free ACP server; this PR removes the remaining CLI-level cost of resolving Ink/App before that branch is taken.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Docs-only or internal chores need no changeset (or run pnpm changeset --empty to note that intentionally).

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Focused coverage used for this change:

  • pnpm run test:ava source/cli.spec.ts source/app/utils/app-util.spec.ts source/app/utils/handlers/context-max-handler.spec.ts source/acp/acp-capabilities.spec.ts
  • pnpm run test:types && pnpm run test:format && pnpm run test:lint
  • pnpm run build && pnpm run test:benchmark (confirms acp_module_count / acp_boot_ms_approx)

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Manual smoke checks:

  • node dist/cli.js --json --acp run "hi" rejects with --json cannot be combined with --acp
  • node dist/cli.js --acp --provider … --model … starts the ACP server (no Ink TUI)
  • ACP module-URL capture shows no dist/app/App.js / dist/app/index.js

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

@will-lamerton

will-lamerton commented Aug 13, 2026

Copy link
Copy Markdown
Member

Thanks for this @AryanNandanwar , the core change is right and the win is bigger than the description suggests. I measured the module graph before/after on the built dist:

  • --acp: 612 -> 427 modules
  • --plain run: 597 -> 411 modules
  • copilot login: 593 -> 11 modules

So the eager Promise.all at the top of main() was costing every non-TUI path, not just ACP. Worth calling that out in the description.

A few things before this can go in:

  1. pnpm test:knip fails, which is a required check. parseContextLimit at source/app/utils/handlers/context-max-handler.ts:15 is now an unused re-export once app-util.ts points at the new module. Deleting that export line should do it.

  2. Please drop the benchmarks/baseline.json changes from this PR. audit_high_vulns: 2 → 17 is a security signal that shouldn't get absorbed by a startup-cost change, and the wall-clock numbers (interactive_boot_ms_approx 606 → 1415, first_render_ms_approx 549 → 1127) are machine-dependent, so committing them makes the baseline less useful for everyone else. The stale counters are worth refreshing, just as a separate chore PR.

  3. This doesn't fully bypass Ink. source/custom-tools/formatter.tsx imports ink directly and is pulled in by the tool registry, so --acp and --plain still load all 54 Ink modules plus React. Could you switch Closes #810 to Refs #810 and reword the changeset to patch? Splitting the formatters out of tool registration is the follow-up that would actually close it, happy to open an issue for that.

Minor: a spec next to the new source/utils/parse-context-limit.ts would be good, right now it's only covered transitively through app-util.spec.ts.

pnpm test:types and the focused specs both pass on my end.

@AryanNandanwar
AryanNandanwar force-pushed the feature/headless-api-mode branch from 6154dfe to c4e7200 Compare August 13, 2026 19:08
@AryanNandanwar

Copy link
Copy Markdown
Contributor Author

Hey @will-lamerton , I've made the required changes. Changed the PR Description to Refs instead of closes.
I'd be happy to work on the Ink import in formatter as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants