Skip to content
nikcli
Docs
Documentation

Source Map

A practical map for finding the real implementation behind CLI commands, API routes, TUI views, mobile flows, providers, plugins, and storage.

Overview

The main runtime lives in packages/nikcli/src. The repo is a Bun monorepo, so related packages also matter: packages/sdk/js for generated client types, packages/plugin for plugin contracts, packages/mobile for the Expo app, packages/web for this docs site, packages/llm for route-based LLM providers, and packages/remote for remote execution support.

This map is meant for tracing behavior from a symptom to the source. Start at the command or route entry, then follow service imports into the domain module.

Top-level entry

packages/nikcli/src/index.ts registers every CLI command with yargs, initializes global directories, initializes logging, sets AGENT=1 and NIKCLI=1, and catches fatal errors for user-facing formatting.

Terminal
bash
bun run --cwd packages/nikcli --conditions=browser src/index.ts --help
bun run --cwd packages/nikcli --conditions=browser src/index.ts serve --help
bun run --cwd packages/nikcli --conditions=browser src/index.ts mcp --help
NeedStart hereThen inspect
Command registrationsrc/index.tssrc/cli/cmd/*.ts
Global pathssrc/@nikcli-ai/util/globalNIKCLI_DATA_DIR, XDG/AppData rules.
Logging@nikcli-ai/util/log--print-logs, --log-level.
Error formattingsrc/cli/error.tsCommand-specific thrown errors.

Runtime domains

Entry

CLI and TUI

src/cli/cmd contains commands. src/cli/cmd/tui contains the OpenTUI/Solid renderer, worker RPC, routes, dialogs, plugins, and contexts.

HTTP

Server

src/server/server.ts owns middleware and route mounting. src/server/httpapi owns classic routes. src/server/httpapi owns typed route groups.

Agent

Sessions

src/session owns session lifecycle, prompt execution, LLM normalization, messages, status, revert, compaction, todo, and stats.

Tools

Extensions

src/plugin, src/mcp, src/connectors, src/skill, and src/tool expose extra capabilities to agents.

CLI command map

Every public command is imported and registered in src/index.ts.

CommandFileDomain
Default TUIcli/cmd/tui/thread.tsWorker RPC, SDK fetch, OpenTUI app.
runcli/cmd/run.tsHeadless prompt execution.
servecli/cmd/serve.tsGeneral HTTP API server.
mobilecli/cmd/mobile.tsMobile host, pairing, token list/revoke.
remotecli/cmd/remote.tsTerminal remote plus optional mobile host.
mcpcli/cmd/mcp.tsMCP config, OAuth, list, debug, logout.
connectorscli/cmd/connectors.tsExternal service config and credentials.
plugin / plugcli/cmd/plug.tsPlugin install, manifest read, config patch.
modelscli/cmd/models.tsProvider/model catalog.
debugcli/cmd/debugConfig, LSP, skill, snapshot, search, file utilities.
routinecli/cmd/routine.tsRoutine CRUD, run, pause, resume.
accountcli/cmd/account.tsLocal account management.

Server map

Server behavior starts in src/server/server.ts. The exact route order matters: share routes, user auth middleware, server auth, CORS, /global, workspace context, /doc, typed bridge, then classic route groups.

FeatureClassic routeTyped route where present
Sessionserver/httpapi/session.tsserver/httpapi/session.ts
Fileserver/httpapi/file.tsserver/httpapi/file.ts
Providerserver/httpapi/provider.tsserver/httpapi/provider.ts
MCPserver/httpapi/mcp.tsserver/httpapi/mcp.ts
Configserver/httpapi/config.tsserver/httpapi/config.ts
Workspaceserver/httpapi/workspace.tsserver/httpapi/workspace.ts
Questionserver/httpapi/question.tsserver/httpapi/question.ts
Permissionserver/httpapi/permission.tsserver/httpapi/permission.ts
Mobileserver/httpapi/mobile.tsClassic only.
Analyticsserver/httpapi/analytics.tsClassic only.

Session and LLM map

NeedFileWhat to look for
Create/list/update/removesession/index.tsSession.Service methods and storage keys.
Prompt executionsession/prompt.tsTool setup, system prompt assembly, request loop.
LLM provider hot pathsession/llm.tsMessage normalization, headers, provider transforms, tool conversion.
Native provider runtimesession/llm/native-runtime.ts@nikcli-ai/llm route-based streaming for supported providers.
Messages and partssession/message-v2.tsMessage/part persistence and retrieval.
Statussession/status.tsBusy, retry, idle state.
Diff and revertsession/summary.ts, session/revert.tsFile diff summaries and revert/unrevert actions.
Statssession/stats.tsToken/cost/session aggregate data.

Storage and config map

Config and storage are separate. Config is resolved from well-known remote config, global files, custom file env, project files, inline env content, and config directories. Storage is durable JSON under Global.Path.data/storage plus SQLite/Drizzle databases under Global.Path.data.

NeedFileNotes
Global paths@nikcli-ai/util/globalXDG/AppData resolution, NIKCLI_DATA_DIR, cache version.
Config loadingconfig/config.tsMerge order, plugin/command/agent loading, legacy tools migration.
Config pathsconfig/paths.tsProject file discovery, directory list, JSONC substitution.
TUI configconfig/tui.ts, config/tui-schema.tsKeybinds, scroll, mouse, layout config.
JSON storedatabase/database.tsRead/write/update/list/transaction, locks, cache, migrations.
SQLitedatabase/database.tsDrizzle client, WAL, migrations, PRAGMAs.

Extension map

Extension typeSourceRuntime hook
Server pluginplugin/index.tsInternal plugins, configured plugins, built-ins, auth hooks, tool hooks, event hooks.
TUI pluginpackages/tui/src/pluginCommand, route, dialog, sidebar, and keybind registration.
MCPmcp/index.tsLocal stdio and remote HTTP/SSE clients converted into agent tools.
Connectorsconnectors/index.ts, connectors/registry.tsExternal service status, health checks, dynamic tools, prompts.
Skillsskill/skill.tsSkill discovery from config directories and external skill folders.
Built-in toolstool/registry.tsModel and flag gated tool set for sessions.

TUI map

The TUI starts in cli/cmd/tui/thread.ts, creates a worker from cli/cmd/tui/worker.ts, then renders packages/tui/src/app.tsx. With no network options it uses direct RPC fetch and event source. With host/port options it starts a real HTTP server and talks through the SDK.

AreaFiles
Route statepackages/tui/src/context/route.tsx
Session routepackages/tui/src/routes/session/index.tsx
Workspace routepackages/tui/src/routes/workspace, routes/changes, routes/tree, routes/git-graph, routes/github
Command palettepackages/tui/src/component/dialog-command.tsx
Remote controlserver/httpapi/tui.ts, packages/tui/src/event.ts
Plugin runtimepackages/tui/src/plugin/runtime.ts, plugin/api.tsx

Mobile map

The Expo app lives in packages/mobile, while the host API lives in packages/nikcli/src/server/httpapi/mobile.ts and helpers under packages/nikcli/src/mobile.

NeedHost sourceApp source
Pairing tokenssrc/mobile/auth.ts, routes/mobile.tspackages/mobile/app/connect.tsx
Session streamingroutes/mobile.tspackages/mobile/hooks/use-session-stream.ts
GitHub repossrc/mobile/github-repo.tspackages/mobile/app/(app)/repos
Routinessrc/mobile/routine.tspackages/mobile/app/(app)/routines
Terminalroutes/mobile.ts, src/ptypackages/mobile/app/(app)/terminal
Settingsroutes/mobile.ts, config/provider/MCP/connectors servicespackages/mobile/app/(app)/settings

Generated and package map

PackagePurposeWhen to inspect
packages/sdk/jsGenerated JavaScript SDK for server APIs.After endpoint contract changes or SDK type failures.
packages/pluginPlugin API package and TUI plugin contracts.When implementing or debugging plugin manifest targets.
packages/llmRoute-based LLM provider package used by native runtime.When provider streaming behavior differs from AI SDK path.
packages/mobileExpo mobile application.When a host route is correct but app behavior differs.
packages/webAstro docs and dashboard pages.When editing docs, dashboard, or public web pages.
packages/remoteRemote execution support.When terminal remote or cloud relay behavior changes.
packages/inferenceInference provider/gateway package.When nikcli-inference provider catalog or routing changes.
packages/http-recorderHTTP recording utilities.When fixture or provider request recording changes.

How to trace a feature

  1. Find the entry: command in src/index.ts, route in server.ts, or UI route in tui/context/route.tsx.
  2. Read the domain service imported by that entry. Route files usually call services from session, provider, config, mcp, connectors, or workspace.
  3. Check config and flags. Many features are enabled by config fields plus environment flags from @nikcli-ai/util/flag.
  4. Check storage. Durable behavior usually writes through Storage.Service or a SQLite helper.
  5. For client behavior, trace generated SDK types in packages/sdk/js/src/httpapi/generated and UI code in packages/mobile or TUI route files.
Terminal
bash
rg -n "route-or-command-name" packages/nikcli/src
rg -n "operationId|HttpApiEndpoint|get\\(|post\\(" packages/nikcli/src/server
rg -n "Config\\.Service|Provider\\.Service|Session\\.Service" packages/nikcli/src

Directory table

DirectoryPurpose
account Local user account records and auth helpers.
acp Agent Client Protocol integration.
agent Agent definitions, prompts, generated agent metadata, and selection.
analytics Usage and session analytics aggregation.
auth Provider and external auth storage used outside connector-specific auth.
background Background task runner and status.
brain Brain scheduler, consolidation, and long-term context features.
bus Event bus definitions used by server, TUI, sessions, MCP, and permissions.
chatbot Slack, Discord, Teams, Google Chat, Linear, and GitHub bot adapters.
cli Yargs command definitions, OpenTUI app, local UI, network helpers.
command Command templates, generated commands, and prompt commands.
config Config schema, path discovery, JSONC parsing, migrations, TUI config.
connectors External service connector status, credentials, tools, and operations.
delegation Background delegation manager and parent/worker ownership.
env Environment read/write helpers for provider code.
file File listing, search, content, status, and time helpers.
filesystem Effect filesystem helpers and compatibility wrappers.
flag Environment flag parsing and dynamic flag getters.
format Formatter detection and execution.
git Git helpers and command wrappers.
global Global data/cache/config/state/log/bin/repo paths and initialization.
ide IDE detection and extension install helpers.
image Image generation provider and model selection.
installation Version, channel, update, and install/runtime metadata.
locale Language, region, timezone, currency, and locale resolution.
lsp Language server registry, lazy clients, diagnostics, symbols, references.
mcp Model Context Protocol clients, OAuth, tools, prompts, resources.
mobile Mobile auth, routines, Expo helpers, GitHub repo import, project detection.
monitor Long-lived process monitoring and cancellation.
permission Permission rules, pending requests, persisted always approvals.
plugin Server plugins, auth plugins, installer, package manifest detection.
project Project detection, instance context, VCS metadata.
provider Provider catalog, auth, AI SDK adapters, model cache, transformations.
pty Pseudo-terminal sessions and websocket I/O.
question Interactive question prompts and replies.
sandbox Sandbox and external directory checks for tool execution.
scheduler Scheduled routine helpers.
server Hono app, route groups, typed HttpApi bridge, proxying, mDNS.
session Session records, messages, prompt execution, summaries, revert, stats.
share Public share creation and public data retrieval.
skill Skill discovery, loading, and prompt material.
snapshot Snapshot and diff tracking for file changes.
storage JSON storage service, locks, migrations, SQLite/Drizzle helpers.
tool Built-in tool registry, definitions, prompts, and execution wrappers.
util Shared utilities such as logs, queues, locks, wildcard, timeout, process helpers.
workspace Workspace records, adaptors, remote/local targets, session proxy.
worktree Git worktree creation, reset, and removal helpers.