mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
* chore(kimi-code): upgrade pi-tui to 0.78.1 and adapt native helpers
Bump @earendil-works/pi-tui from ^0.74.0 to ^0.78.1. pi-tui 0.75.5 replaced its koffi-based Windows VT input with a bundled native helper, and 0.76.0 added a darwin native helper for Terminal.app Shift+Enter.
- SEA build: teach native-deps to collect pi-tui's per-target .node files, drop the koffi registry, and add a native-file-only collect mode so only package.json + the target .node ship (28 -> 2 files).
- Redirect pi-tui's absolute-path native require() into the native-asset cache through the Module._load hook, and extend the native smoke test to actually load the helper.
- npm package: ship pi-tui's native/ directory so macOS Terminal.app Shift+Enter and Windows Shift+Tab keep working for npm installs.
* chore: add changeset for pi-tui upgrade
* chore: vendor @earendil-works/pi-tui 0.80.2
Fork the upstream pi-tui source into packages/pi-tui for local modification. Pristine snapshot of @earendil-works/pi-tui@0.80.2; the apps/kimi-code dependency on ^0.78.1 from npm is left unchanged.
* feat(kimi-code): integrate vendored @moonshot-ai/pi-tui
Replace the npm @earendil-works/pi-tui dependency with the vendored @moonshot-ai/pi-tui workspace package so the fork can be modified locally.
- Point apps/kimi-code imports and native-deps at @moonshot-ai/pi-tui.
- Make pi-tui source-first (exports -> src, publishConfig.exports -> dist, mirroring node-sdk) and strict-clean: bracket access for process.env / named capture groups, an override modifier, and non-null assertions for noUncheckedIndexedAccess.
- Bump the root tsconfig target to ES2024 and enable allowImportingTsExtensions (needed for pi-tui's /v regex and .ts imports, which node --test requires).
- Add packages/pi-tui to flake.nix workspaces and exclude the vendored source from oxlint.
* fix(pi-tui): export package.json for native asset resolution
The SEA native-asset collector resolves the package root via
require.resolve('@moonshot-ai/pi-tui/package.json'). The vendored
package's exports field only exposed ".", which blocked the
"./package.json" subpath and broke build:native:sea with
ERR_PACKAGE_PATH_NOT_EXPORTED.
* chore(kimi-code): sync pi-tui native prebuilds at build time
Copy packages/pi-tui/native prebuilds into apps/kimi-code/native
during build instead of tracking a manual copy in git. Only the
.node prebuilds are copied (not the C sources); the directory is
now a build artifact covered by .gitignore.
* fix(pi-tui): avoid destructive full redraw during streaming
When the first changed line is above the viewport, the differential
renderer fell back to fullRender(true), which clears scrollback and
yanks the user's viewport. On Windows Terminal this jumps to the
absolute top (microsoft/Terminal#20370).
Clamp the diff to the visible viewport when content length is
unchanged (spinner tick / markdown reflow above the viewport), so
streaming no longer triggers a full redraw in those cases. Length
changes still fall back to fullRender to reset the viewport.
* fix(kimi-code): update pi-tui imports in files merged from main
Two files added on main (effort-selector, plugin-command) still
imported the old @earendil-works/pi-tui package name; point them at
the vendored @moonshot-ai/pi-tui.
* chore(nix): update pnpmDeps hash after lockfile regen
* fix(pi-tui): clamp above-viewport diff even when content shrinks
Previously, when the first changed line was above the viewport and
content length changed (e.g. spinner removed at end of streaming), the
renderer fell back to fullRender(true), which clears scrollback and
yanks the viewport to the absolute top on Windows Terminal.
Always clamp the diff to the visible viewport instead, preserving the
user's scroll position. Stale bytes remain in scrollback but are not
visible.
* fix(kimi-code): keep activity placeholder to avoid streaming shrink
When streaming ends, removing the activity spinner shrank the content
by two rows, which (combined with transient→final code highlighting
above the viewport) triggered a destructive full redraw. Keep a one-row
placeholder in the activity pane when idle so the content does not
fully shrink.
* chore: refine streaming scroll changeset wording
* chore: remove obsolete pi-tui native helpers changeset
* chore: add pi-tui changesets and document the pi-tui changelog rule
Add changesets for the fork integration, package manifest export, and
viewport clamp fix so the vendored pi-tui keeps its own changelog.
Update the gen-changesets skill to treat @moonshot-ai/pi-tui as a
special internal package that lists itself instead of the CLI, with a
separate CLI changeset only when the change is user-visible there.
* chore(nix): update pnpmDeps hash after merging main
* fix(changeset): drop private kimi-code-docs from google-genai changeset
257 lines
8.3 KiB
Nix
257 lines
8.3 KiB
Nix
{
|
|
description = "Kimi Code CLI";
|
|
|
|
inputs = {
|
|
# Pinned to the 25.11 release channel because nixpkgs-unstable currently
|
|
# ships nodejs_24 = 24.14.1, which trips the >= 24.15.0 floor that the
|
|
# native SEA build enforces (see apps/kimi-code/scripts/native/build.mjs).
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
|
|
};
|
|
|
|
outputs =
|
|
{ self, nixpkgs }:
|
|
let
|
|
lib = nixpkgs.lib;
|
|
|
|
systems = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
"x86_64-darwin"
|
|
"aarch64-darwin"
|
|
];
|
|
|
|
forAllSystems =
|
|
f:
|
|
lib.genAttrs systems (
|
|
system:
|
|
f (import nixpkgs {
|
|
inherit system;
|
|
})
|
|
);
|
|
|
|
minNodeVersion = "24.15.0";
|
|
|
|
# Hardcode to Node.js 24.x; fail the evaluation if the pinned nixpkgs
|
|
# does not offer a new enough 24.x.
|
|
nodejsFor =
|
|
pkgs:
|
|
let
|
|
node = pkgs.nodejs_24;
|
|
in
|
|
if lib.versionAtLeast node.version minNodeVersion then
|
|
node
|
|
else
|
|
throw ''
|
|
Kimi Code requires Node.js >= ${minNodeVersion},
|
|
but nixpkgs only offers ${node.version}.
|
|
Pin a newer nixpkgs revision or update minNodeVersion in flake.nix.
|
|
'';
|
|
|
|
pnpmFor =
|
|
pkgs:
|
|
pkgs.pnpm_10.override {
|
|
nodejs = nodejsFor pkgs;
|
|
};
|
|
|
|
# -------------------------------------------------------------------
|
|
# Workspace members (kept in sync with pnpm-workspace.yaml).
|
|
#
|
|
# HARD REQUIREMENT: whenever you add or remove a workspace package,
|
|
# you MUST update both lists below. Missing a path will break the Nix
|
|
# build (src fileset silently drops files); missing a name will break
|
|
# pnpmConfigHook (dependencies for that workspace won't be fetched).
|
|
# -------------------------------------------------------------------
|
|
workspacePaths = [
|
|
./packages/acp-adapter
|
|
./packages/agent-core
|
|
./packages/server
|
|
./packages/server-e2e
|
|
./packages/kaos
|
|
./packages/kimi-migration-legacy
|
|
./packages/kosong
|
|
./packages/migration-legacy
|
|
./packages/node-sdk
|
|
./packages/oauth
|
|
./packages/pi-tui
|
|
./packages/protocol
|
|
./packages/telemetry
|
|
./apps/kimi-code
|
|
./apps/kimi-desktop
|
|
./apps/kimi-web
|
|
./apps/vis
|
|
./apps/vis/server
|
|
./apps/vis/web
|
|
./docs
|
|
];
|
|
|
|
workspaceNames = [
|
|
"@moonshot-ai/acp-adapter"
|
|
"@moonshot-ai/agent-core"
|
|
"@moonshot-ai/server"
|
|
"@moonshot-ai/server-e2e"
|
|
"@moonshot-ai/kaos"
|
|
"@moonshot-ai/kosong"
|
|
"@moonshot-ai/migration-legacy"
|
|
"@moonshot-ai/kimi-code-sdk"
|
|
"@moonshot-ai/kimi-code-oauth"
|
|
"@moonshot-ai/pi-tui"
|
|
"@moonshot-ai/protocol"
|
|
"@moonshot-ai/kimi-telemetry"
|
|
"@moonshot-ai/kimi-code"
|
|
"@moonshot-ai/kimi-desktop"
|
|
"@moonshot-ai/kimi-web"
|
|
"@moonshot-ai/vis"
|
|
"@moonshot-ai/vis-server"
|
|
"@moonshot-ai/vis-web"
|
|
"kimi-code-docs"
|
|
"kimi-migration-legacy"
|
|
];
|
|
in
|
|
{
|
|
packages = forAllSystems (
|
|
pkgs:
|
|
let
|
|
nodejs = nodejsFor pkgs;
|
|
pnpm = pnpmFor pkgs;
|
|
appPackageJson = builtins.fromJSON (builtins.readFile ./apps/kimi-code/package.json);
|
|
nativeTarget =
|
|
if pkgs.stdenv.hostPlatform.isLinux && pkgs.stdenv.hostPlatform.isAarch64 then
|
|
"linux-arm64"
|
|
else if pkgs.stdenv.hostPlatform.isLinux then
|
|
"linux-x64"
|
|
else if pkgs.stdenv.hostPlatform.isDarwin && pkgs.stdenv.hostPlatform.isAarch64 then
|
|
"darwin-arm64"
|
|
else if pkgs.stdenv.hostPlatform.isDarwin then
|
|
"darwin-x64"
|
|
else
|
|
throw "Unsupported Kimi Code native target for ${pkgs.stdenv.hostPlatform.system}";
|
|
|
|
kimi-code = pkgs.stdenv.mkDerivation (finalAttrs: {
|
|
pname = "kimi-code";
|
|
version = appPackageJson.version;
|
|
|
|
src = lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = lib.fileset.unions (
|
|
[
|
|
./build
|
|
./.npmrc
|
|
./.nvmrc
|
|
./package.json
|
|
./pnpm-lock.yaml
|
|
./pnpm-workspace.yaml
|
|
./tsconfig.json
|
|
./vitest.config.ts
|
|
./LICENSE
|
|
]
|
|
++ workspacePaths
|
|
);
|
|
};
|
|
|
|
pnpmWorkspaces = [ "." ] ++ workspaceNames;
|
|
|
|
pnpmDeps = pkgs.fetchPnpmDeps {
|
|
inherit (finalAttrs) pname version src pnpmWorkspaces;
|
|
inherit pnpm;
|
|
fetcherVersion = 3;
|
|
hash = "sha256-o753txNKfBcn/fiJOWFU0lyrSqTUJ/GU1ed1DPVPZ2U=";
|
|
};
|
|
|
|
nativeBuildInputs = [
|
|
nodejs
|
|
pnpm
|
|
(pkgs.pnpmConfigHook.override { inherit pnpm; })
|
|
pkgs.makeWrapper
|
|
]
|
|
# The SEA inject step (postject) invalidates the macOS code
|
|
# signature on the copied Node executable; build.mjs then re-applies
|
|
# an ad-hoc signature via `codesign`. The Nix darwin sandbox does
|
|
# not expose /usr/bin/codesign, so we supply nixpkgs' ad-hoc-only
|
|
# replacement instead.
|
|
++ lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
|
|
pkgs.darwin.sigtool
|
|
];
|
|
|
|
# The SEA binary is produced by `postject`-injecting a blob into a
|
|
# plain Node executable. Stripping rewrites section tables and can
|
|
# invalidate the injected blob's offsets, so leave the binary
|
|
# untouched after the build.
|
|
dontStrip = true;
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
export KIMI_CODE_BUILD_TARGET=${nativeTarget}
|
|
${lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
|
|
# pkgs.darwin.sigtool's codesign supports `--sign -` (ad-hoc)
|
|
# but not the inspection mode (`-dv`) that 05-verify.mjs runs
|
|
# afterwards. Disable the verify step for the Nix build; the
|
|
# release CI keeps it via the unmodified script.
|
|
substituteInPlace apps/kimi-code/scripts/native/build.mjs \
|
|
--replace-fail \
|
|
"await runVerifyStep({ requireGatekeeper: false });" \
|
|
"// runVerifyStep skipped in nix sandbox (sigtool lacks -dv)"
|
|
''}
|
|
# The SEA blob step (scripts/native/02-sea-blob.mjs) embeds the
|
|
# Kimi web assets from apps/kimi-code/dist-web and fails if that
|
|
# directory is missing. Build the web app and stage its assets
|
|
# before producing the native executable.
|
|
pnpm --filter=@moonshot-ai/kimi-web run build
|
|
node apps/kimi-code/scripts/copy-web-assets.mjs
|
|
pnpm --filter=@moonshot-ai/kimi-code run build:native:sea
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
install -Dm755 \
|
|
"apps/kimi-code/dist-native/bin/${nativeTarget}/kimi" \
|
|
"$out/bin/kimi"
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
postInstall = ''
|
|
wrapProgram $out/bin/kimi --prefix PATH : ${lib.makeBinPath [ pkgs.ripgrep pkgs.fd ]}
|
|
'';
|
|
|
|
meta = {
|
|
description = "Kimi Code CLI";
|
|
homepage = "https://github.com/MoonshotAI/kimi-code";
|
|
license = lib.licenses.mit;
|
|
mainProgram = "kimi";
|
|
platforms = systems;
|
|
};
|
|
});
|
|
in
|
|
{
|
|
inherit kimi-code;
|
|
default = kimi-code;
|
|
}
|
|
);
|
|
|
|
apps = forAllSystems (pkgs: {
|
|
kimi-code = {
|
|
type = "app";
|
|
program = "${self.packages.${pkgs.system}.kimi-code}/bin/kimi";
|
|
};
|
|
default = self.apps.${pkgs.system}.kimi-code;
|
|
});
|
|
|
|
devShells = forAllSystems (pkgs: {
|
|
default =
|
|
let
|
|
nodejs = nodejsFor pkgs;
|
|
pnpm = pnpmFor pkgs;
|
|
in
|
|
pkgs.mkShell {
|
|
packages = [
|
|
nodejs
|
|
pnpm
|
|
pkgs.ripgrep
|
|
pkgs.fd
|
|
];
|
|
};
|
|
});
|
|
};
|
|
}
|