I wanted to type /open src/mail.ts into a terminal and have a coding assistant display the file. Ink, a library that renders React components in the terminal, can draw an input field and preview pane. But when I press Enter, who opens the file? Gemini CLI puts its command-line interface in packages/cli and its core logic in packages/core. The documentation says the UI passes input to the core. My follow-up question was “using network socket like frontend/backend?”1
What happens in two TypeScript packages when I press Enter?
Consider just the UI’s part in opening a file. Suppose a package called agent-core exports a readSource function that reads text from a path on disk. The UI command handler could do this:
import { readSource } from 'agent-core';
// 在处理 /open 的异步函数内,path 是用户提交的文件路径。
const text = await readSource(path);
setPreview(text);
When the CLI starts, Node.js, the JavaScript runtime, also loads the imported code. The UI and core run inside this single running program, or process.
flowchart LR
subgraph proc["同一个 Node.js 进程"]
ui["CLI 包:命令输入与文件预览"]
core["核心包:readSource 读取文件"]
ui -->|"传入路径 src/mail.ts"| core
core -->|"返回文件文本"| ui
end
The diagram shows the hypothetical /open example above. When I press Enter, await waits for the read to finish, then the interface displays the file with setPreview(text).
Submitting a message is a real Gemini CLI example. In August 2025 the CLI package declared @google/gemini-cli-core as a local file:../core dependency. When a user submitted input, the UI’s useGeminiStream called geminiClient.sendMessageStream(...) on an existing client object, obtained a stream of events and processed them as they arrived. That method call is where the UI hands input to the core. The network comes into play later, when the core sends a request to the remote model. I look for these two places separately in the source.2
Do I need to run a service to search code with Python?
A different requirement got me thinking about Python. With /open, I already know the filename. If I just ask “find the code that sends invitation emails,” the assistant must find the file first. Indexing the code and retrieving relevant snippets for the model to read, as Cursor does, is one form of retrieval-augmented generation (RAG). Many indexing tools I know use Python, so I asked how Gemini CLI and Cline find code and whether the core should also be written in Python.1
Take the same question: “Where is the first email to a new colleague generated?” Suppose the function is called sendInvitation and the source never uses the words “first email.” A semantic index converts snippets to numeric vectors in advance and retrieves candidates by similarity of meaning at query time. Another approach starts with literal clues in directories, filenames or code and opens files as it goes. Here is how the tools I studied in August 2025 differed.
| Product or version at the time | Built-in semantic index of the codebase? | How would it find the invitation email? |
|---|---|---|
| Cursor 1.2 | Yes. The July release notes describe an update to the embedding model for semantic codebase search.3 | Search for “the first email to a new colleague,” then open the candidate functions and inspect them. |
| Cline, August 13 source | No prebuilt semantic codebase index. In May the author explained the design choice to explore a repository on demand.4 | Look through directories or use search_files for a clue such as invite, then follow imports and calls to the function that actually sends the email. |
| Gemini CLI, August 13 source | The built-in tools provided no semantic codebase index. The core registered tools to list directories, match filename patterns, search content and read files.5 | Use glob to find mail-related files, use search_file_content with a regular expression for sendInvitation, and continue reading from the paths and line numbers returned. |
Gemini CLI’s model client already had generateEmbedding(texts), which could return vectors for a batch of texts. To answer “which snippet is closest to my question?”, the application would still have to select snippets, store vectors and file locations, update them after code changes, and query with the question vector. This distinction also informs my choice of language. The terminal and core can stay in TypeScript. If I already have a suitable Python retriever, that one tool is all I need to integrate.5
Suppose I already have search.py and this terminal program is its only consumer. Node can run spawn('python3', ['search.py']) and manage it as a child process. Each process has its own memory. Node writes a line of text to the child’s standard input (stdin), Python writes results to its standard output (stdout), and Node reads them at the other end. The operating system connects the two ends locally. These pipes provide interprocess communication (IPC).6
Suppose I want to search for “send invitation email” and then open the matching file. Tracing the operation shows which two steps need the pipe.
sequenceDiagram
participant UI as Ink 界面
participant Core as TypeScript 核心
participant Py as Python 子进程
Note over UI,Core: 同一个 Node.js 进程
UI->>Core: 调用搜索函数,传入“发邀请邮件”
Core->>Py: stdin 写入搜索词
Py-->>Core: stdout 返回 src/mail.ts 第 18 行
Core->>Core: readSource 读取命中文件
Core-->>UI: 返回文本,显示命中行
This is a hypothetical retriever. Between entering a search term and previewing the file, only the two arrows between the core and Python cross a process boundary.
The two ends agree on what travels through the pipe. For example, each message can occupy one line of structured text in JSON. Node writes {"query":"发邀请邮件"} (“send invitation email”), and Python returns {"matches":[{"path":"src/mail.ts","line":18}]}. This example handles one request at a time. The receiver waits for a newline before processing the message, so it can reconstruct the JSON even if a single line arrives in two chunks. Python can send debugging logs to standard error (stderr), reserving standard output for results. If several applications later need to share a persistent index service, give it an HTTP address and have each application send requests there.
This also reminded me of calling C from Python. There, a foreign function interface (FFI) specifies how to pass arguments and call a function compiled from another language. Here I start a Python program, and the two ends just need to agree on a message format.
If pipes already work, when do I need MCP?
Suppose I want a second coding assistant to call search.py. It needs to know the tool’s name, which arguments it accepts and how to recognize the result. Our two custom JSON lines only have those meanings for the two programs I wrote. The Model Context Protocol (MCP) defines shared message formats for tool discovery and invocation. After initializing a connection, the client on the assistant’s side can send tools/list for tool names and parameter descriptions, then tools/call to invoke its choice.7
Locally, these protocol messages can still travel over standard input and output. For a tool running as an independent service, the June 2025 MCP specification also defines an HTTP transport. Adding MCP support to an existing Python retriever can start with a tiny adapter: receive a tool request, extract the search term, call the existing search function, and wrap the matches in the response the protocol specifies. For initialization and matching requests to responses, see the full sequence of an MCP tool call.7
If I only want to read and write one file, does the root need a package.json?
I eventually narrowed the first iteration to TypeScript, Ink and file I/O. Setting up an empty directory, I initially asked what dependencies to install, even whether I needed Vite, a build tool I often used for web pages. The assistant’s template added another layer: separate CLI and core packages, plus an npm project at the root. During setup I hit newWorkspaces.some is not a function. Even if the packages really had to be separate, I asked, “each project has a package json is fine” — why did the root need another one?1
| What do I want to separate? | Possible layout | How the UI opens a file |
|---|---|---|
| UI code and file-reading code | One package and one package.json, with src/ui and src/core inside | Import the function by relative path |
| Independent dependency declarations for CLI and core | Two packages, each with its own manifest. The CLI can declare a local dependency with file:../core | Once core is installed and its entry point ready, import the function by package name |
| Install and manage both packages from the repository root | The root manifest tells npm where the child packages are with "workspaces": ["packages/*"]. Each still keeps its own manifest | npm links local packages during installation. The CLI imports the function by package name |
All three layouts allow the UI and core to run in the same process. The root manifest takes on an extra job in the third: npm reads the workspace list there to find both packages during one install. The first layout is enough to run an Ink preview from an empty directory.8
Once I have chosen workspaces, how do I diagnose newWorkspaces.some is not a function?
The original conversation preserved the error message. An empty directory is enough to test one possible cause. Running npm pkg set 'workspaces=["packages/*"]' can give npm a string that looks like an array. Calling the array method .some() on it fails, possibly before npm even writes the manifest. First open the root package.json. If the field is absent or its value is a string, write a real array and preserve the other fields. Here is a minimal root manifest. In an existing project only that field needs changing.8
{ "workspaces": ["packages/*"] }
If starting from an empty manifest, npm pkg set --json 'workspaces=["packages/*"]' also tells npm to parse the value as JSON. Assuming packages/cli and packages/core already have manifests with distinct name values, run the following three steps from the root. The first should print true. After installation the last should print both package names. This checks both the data type and whether npm recognized the directories.9
node -p "Array.isArray(require('./package.json').workspaces)"
npm install
npm pkg get name --workspaces
My TypeScript prototype eventually used the third layout. In the initial commit on August 25, the root manifest declared packages/*, the CLI package depended on React and Ink, and the development command used tsx to run the terminal entry point. At that point the entry point only displayed Hello CLI world 👋. That verified two small things: npm managed the packages and Ink displayed a component in the terminal. Starting it that way required no Vite. For keeping a dropped path in the input and waiting for Enter to open it, see designing the terminal input field. For how much of the open, edit, preview and write cycle actually worked, see file operations and diff previews in the prototype.10
References
Footnotes
-
Cai, B. (n.d.). A TypeScript terminal UI, a Python core, and npm workspaces [private conversation]. ChatGPT. The short quotations come from the follow-up on passing input from
packages/clitopackages/coreand the final question about the root package manifest. ↩ ↩2 ↩3 -
Google Gemini CLI contributors. (2025, August 13). CLI package and useGeminiStream [source code]. GitHub. CLI dependency on the local core and Ink, Submit input and receive an event stream, Handle individual events. ↩
-
Cursor. (2025, July 3). Agent Planning, Better Context & Faster Tab (1.2). Cursor Changelog. New embedding model for semantic codebase search. ↩
-
Baumann, N. (2025, May 27). Why Cline Doesn’t Index Your Codebase (And Why That’s a Good Thing). Cline. The author discusses reading on demand and following references. Cline contributors. (2025, August 13). ToolExecutor [source code]. GitHub. Execute a file-content search. ↩
-
Google Gemini CLI contributors. (2025, August 13). Core tool registry, file system tools, and model client [source code and documentation distributed with the release]. GitHub. Built-in tool registry and external tool discovery, Inputs and outputs for filename and content search, Interface for generating text vectors. ↩ ↩2
-
Node.js contributors. (2025). Child process (v22.18.0). Node.js documentation. Creating child processes and default pipes. ↩
-
Model Context Protocol contributors. (2025, June 18). Model Context Protocol specification. Model Context Protocol. Listing and calling tools, stdio 和 Streamable HTTP. ↩ ↩2
-
npm. (n.d.). Workspaces and package.json (CLI v10). npm Docs. Defining workspaces and linking at install time, Declaring local path dependencies. ↩ ↩2
-
npm. (n.d.). npm pkg (CLI v10). npm Docs. Parse input as JSON, Read fields from each workspace. During editing I reproduced the error in an empty project with npm 11.9.0 and verified the fix. The original conversation did not retain the manifest from before the error. ↩
-
Cai, B. (2025, August 25). open-vibe-coder-js [private Git repository]. Root,
packages/cliandpackages/coremanifests at commit03bd8c1. Seepackages/cli/src/index.tsxfor terminal output. ↩