This monorepo contains two main packages: @google/gemini-cli
and @google/gemini-cli-core
.
@google/gemini-cli
This is the main package for the Gemini CLI. It is responsible for the user interface, command parsing, and all other user-facing functionality.
When this package is published, it is bundled into a single executable file. This bundle includes all of the package’s dependencies, including @google/gemini-cli-core
. This means that whether a user installs the package with npm install -g @google/gemini-cli
or runs it directly with npx @google/gemini-cli
, they are using this single, self-contained executable.
@google/gemini-cli-core
This package contains the core logic for interacting with the Gemini API. It is responsible for making API requests, handling authentication, and managing the local cache.
This package is not bundled. When it is published, it is published as a standard Node.js package with its own dependencies. This allows it to be used as a standalone package in other projects, if needed. All transpiled js code in the dist
folder is included in the package.
This project follows a structured release process to ensure that all packages are versioned and published correctly. The process is designed to be as automated as possible.
Releases are managed through the release.yml GitHub Actions workflow. To perform a manual release for a patch or hotfix:
v0.2.1
).main
).true
to test the workflow without publishing, or set to false
to perform a live release.In addition to manual releases, this project has an automated nightly release process to provide the latest “bleeding edge” version for testing and development.
Every night at midnight UTC, the Release workflow runs automatically on a schedule. It performs the following steps:
main
branch.preflight
checks and integration tests.v0.2.1-nightly.20230101
).nightly
dist-tag.If any step in the nightly workflow fails, it will automatically create a new issue in the repository with the labels bug
and nightly-failure
. The issue will contain a link to the failed workflow run for easy debugging.
To install the latest nightly build, use the @nightly
tag:
npm install -g @google/gemini-cli@nightly
We also run a Google cloud build called release-docker.yml. Which publishes the sandbox docker to match your release. This will also be moved to GH and combined with the main release file once service account permissions are sorted out.
After the workflow has successfully completed, you can monitor its progress in the GitHub Actions tab. Once complete, you should:
release/vX.Y.Z
branch to main
.package.json
files) and merge it. This keeps the version in main
up-to-date.After pushing a new release smoke testing should be performed to ensure that the packages are working as expected. This can be done by installing the packages locally and running a set of tests to ensure that they are functioning correctly.
npx -y @google/gemini-cli@latest --version
to validate the push worked as expected if you were not doing a rc or dev tagnpx -y @google/gemini-cli@<release tag> --version
to validate the tag pushed appropriatelynpm uninstall @google/gemini-cli && npm uninstall -g @google/gemini-cli && npm cache clean --force && npm install @google/gemini-cli@<version>
The above pattern for creating patch or hotfix releases from current or older commits leaves the repository in the following state:
vX.Y.Z-patch.1
): This tag correctly points to the original commit on main
that contains the stable code you intended to release. This is crucial. Anyone checking
out this tag gets the exact code that was published.release-vX.Y.Z-patch.1
): This branch contains one new commit on top of the
tagged commit. That new commit only contains the version number change in package.json
(and other related files like package-lock.json).This separation is good. It keeps your main branch history clean of release-specific version bumps until you decide to merge them.
This is the critical decision, and it depends entirely on the nature of the release.
You almost always want to merge the release-<tag>
branch back into main
for any
stable patch or hotfix release.
You typically do not merge release branches for pre-releases back into main
.
If you need to test the release process without actually publishing to NPM or creating a public GitHub release, you can trigger the workflow manually from the GitHub UI.
dry_run
option checked (true
).This will run the entire release process but will skip the npm publish
and gh release create
steps. You can inspect the workflow logs to ensure everything is working as expected.
It is crucial to test any changes to the packaging and publishing process locally before committing them. This ensures that the packages will be published correctly and that they will work as expected when installed by a user.
To validate your changes, you can perform a dry run of the publishing process. This will simulate the publishing process without actually publishing the packages to the npm registry.
npm_package_version=9.9.9 SANDBOX_IMAGE_REGISTRY="registry" SANDBOX_IMAGE_NAME="thename" npm run publish:npm --dry-run
This command will do the following:
You can then inspect the generated tarballs to ensure that they contain the correct files and that the package.json
files have been updated correctly. The tarballs will be created in the root of each package’s directory (e.g., packages/cli/google-gemini-cli-0.1.6.tgz
).
By performing a dry run, you can be confident that your changes to the packaging process are correct and that the packages will be published successfully.
The main goal of the release process is to take the source code from the packages/ directory, build it, and assemble a
clean, self-contained package in a temporary bundle
directory at the root of the project. This bundle
directory is what
actually gets published to NPM.
Here are the key stages:
Stage 1: Pre-Release Sanity Checks and Versioning
Stage 2: Building the Source Code
Stage 3: Assembling the Final Publishable Package
This is the most critical stage where files are moved and transformed into their final state for publishing. A temporary
bundle
folder is created at the project root to house the final package contents.
package.json
is Transformed:
bundle
/ directory.bundle
/package.jsonbundle
/gemini.js (or a
similar name).bundle
directory.bundle
/README.mdbundle
/LICENSEbundle
/Stage 4: Publishing to NPM
bundle
directory.bundle
directory, only the files we carefully assembled in Stage 3 are uploaded
to the NPM registry. This prevents any source code, test files, or development configurations from being accidentally
published, resulting in a clean and minimal package for users.Summary of File Flow
graph TD
subgraph "Source Files"
A["packages/core/src/*.ts<br/>packages/cli/src/*.ts"]
B["packages/cli/package.json"]
C["README.md<br/>LICENSE<br/>packages/cli/src/utils/*.sb"]
end
subgraph "Process"
D(Build)
E(Transform)
F(Assemble)
G(Publish)
end
subgraph "Artifacts"
H["Bundled JS"]
I["Final package.json"]
J["bundle/"]
end
subgraph "Destination"
K["NPM Registry"]
end
A --> D --> H
B --> E --> I
C --> F
H --> F
I --> F
F --> J
J --> G --> K
This process ensures that the final published artifact is a purpose-built, clean, and efficient representation of the project, rather than a direct copy of the development workspace.
This project uses NPM Workspaces to manage the packages within this monorepo. This simplifies development by allowing us to manage dependencies and run scripts across multiple packages from the root of the project.
The root package.json
file defines the workspaces for this project:
{
"workspaces": ["packages/*"]
}
This tells NPM that any folder inside the packages
directory is a separate package that should be managed as part of the workspace.
npm install
from the root of the project will install all dependencies for all packages in the workspace and link them together. This means you don’t need to run npm install
in each package’s directory.npm install
, NPM will automatically create symlinks between the packages. This means that when you make changes to one package, the changes are immediately available to other packages that depend on it.--workspace
flag. For example, to run the build
script in the cli
package, you can run npm run build --workspace @google/gemini-cli
.