* chore: add regression and user-impact review to the PR workflow The review-pr skill now runs a separate regression pass with impact levels and a repository-specific list of user populations and contract files, the PR template asks authors for a behavior-change table, Code Review Rules in AGENTS.md encode the same checks for automated review, and changesets must name the behavior users lose when a default flips. * chore(agents): stop instructing agents to invoke the review-pr skill The skill is user-triggered only (disable-model-invocation), so AGENTS.md no longer tells agents to run it; the Code Review Rules keep pointing at surfaces.md for the population and contract list. * chore(review): define impact levels by consequence and close inventory gaps Impact levels are now decided in three steps from the change itself (consequence, escape hatch, silent-input upgrade) with changeset and docs kept in the remediation check; escape-hatch wording allows explicit maintainer sign-off; prompt-text rule names the receiving population; one-sided diff evidence is accepted; release and packaging CI, the klient facade, the transcript contract, kosong providers, and all env-var access forms are added to the surfaces inventory.
14 KiB
Repository-level Agent Guide
Reply in the same language as the user.
This is a TypeScript monorepo built for agent-assisted development. Keep the root AGENTS.md limited to hot-path rules: the project map, hard constraints, and workflow requirements — things every task needs to know.
Working Principles
- Think from first principles. Start from real requirements, code facts, and verification results; if the goal is unclear, discuss it with the user first.
- Treat code, not documentation, as the source of truth. Unless the user explicitly says otherwise, do not read ordinary Markdown just to understand the implementation.
- Before making code changes, read the relevant code and the most recent constraints, and follow the nearest
AGENTS.mdin the directory tree. - Keep changes focused. Do not slip in unrelated refactors along the way.
- When committing, do not add any co-author attribution, and do not reveal the identity of the agent in commit messages, PR descriptions, or any explanatory text.
Project Map
apps/kimi-code: the CLI / TUI application. It consumes core capabilities through@moonshot-ai/kimi-code-sdkand must not depend directly on engine packages. When writing or modifying its terminal UI, use thewrite-tuiskill (.agents/skills/write-tui/SKILL.md).- the browser web UI: its source no longer lives in this repo. It is developed in the code-app repo (
apps/web) and shipped as the committed, prebuilt bundleapps/kimi-code/dist-web(gitignored, force-added), synced from code-app withKIMI_CODE_REPO=<this checkout> pnpm run sync:web— sync and commit the bundle in the same change whenever the web UI should ship differently.apps/kimi-code/scripts/check-web-assets.mjsguards packaging against a missing bundle. To hack on the web UI against this repo's server, runpnpm dev:serverhere and point code-app'spnpm dev:webat it viaKIMI_SERVER_URL. apps/vis,apps/vis/server,apps/vis/web: visual debugging tools for sessions and replays.apps/kimi-inspect: web inspector for the kap-server/api/v1/debugRPC surface — workspace/session browser, per-session transcript chat, per-scope Service panels, and the DI unit inspection view. Seeapps/kimi-inspect/AGENTS.md.packages/agent-core-v2: the DI × Scope agent engine (the v2 port behind kap-server). FourLifecycleScopetiers —App/Workspace/Session/Agent(app/scopes.ts) — plus the L3 unit layer (Service/Fiberunits, collection contribution points, the Feature seam insrc/features/); there is no App-level session lifecycle facade — callers composeISessionIndex→IWorkspaceLifecycleService.handlerFor→ the handler.packages/node-sdk: the public TypeScript SDK and harness.packages/kosong: the LLM / provider abstraction layer.packages/kaos: the execution environment and file/process abstractions.packages/oauth: Kimi OAuth and managed auth utilities.packages/telemetry: shared client-side telemetry infrastructure.packages/transcript: the isomorphic transcript rendering data layer — L1 agent-granular store, L2 idempotent operations, L3off/turn/block/deltasubscription granularity, L4 framework-free view registry, plus turn-cursor pagination. Pure TypeScript (browser-safe, no engine imports); the sole owner of the transcript contract types (src/contract/) and the op-batch sequencing contract.packages/kap-server: the Kimi Code server, backed by@moonshot-ai/agent-core-v2; exposes sessions over REST + WebSocket (/api/v1+/api/v1/ws), plus the/api/v1/debug/*reflection RPC surface (--debug-endpoints, loopback bind + bearer auth).packages/remote-control: the Kimi Remote Control tunnel client — registers this machine with the relay and forwards HTTP/WebSocket traffic to the local server, with a machine-wide single-instance lock; consumed by kap-server (the/api/v1/remote-controltoggle) and by the CLI (kimi web --remote-control).packages/klient: the client SDK — a contract-driven facade over agent-core-v2 (global.*/session(id).*/agent(id).*, zod-validated); transport via subpath entry (@moonshot-ai/klient/ipc|memory, both return the sameKlient); also hosts the e2e suites. Seepackages/klient/AGENTS.md.packages/tree-sitter-bash: a pure-TypeScript bash parser (no runtime deps, no wasm);parse(source, { timeoutMs, maxNodes })runs under a deterministic budget and returns a discriminatedParseResult— callers must treat aborted/hasError trees as "cannot analyze" and degrade. Parser only, no safety judgments; see the package README's "Known differences" section.packages/minidb: the embedded JSON document store (MiniDb) behind kap-server's search index — snapshot + WAL persistence with an exclusive write lock, a larger-than-RAM full-text layer, and persistent index generations. Seepackages/minidb/AGENTS.md.
Environment Requirements
- Node.js:
>=24.15.0(from the rootpackage.jsonengines;.nvmrcis24.15.0, used by nvm / fnm / mise to pick the minimum recommended version). - pnpm:
10.33.0(from the rootpackage.jsonpackageManager). pnpm installwill fail when the Node version is not satisfied, because.npmrcsetsengine-strict=true.
Monorepo Workspace Maintenance
pnpm-workspace.yamlis the source of truth for workspace membership, butflake.nixalso contains hardcodedworkspacePathsandworkspaceNameslists.- Whenever you add or remove a workspace package, you MUST update both
pnpm-workspace.yamlandflake.nix— for every package, including leaf / test / e2e packages that nothing depends on.pnpm-workspace.yamluses globs (packages/*,apps/*), so most packages land there automatically;flake.nixis fully manual and is where omissions happen.- Missing a path in
flake.nix'sworkspacePathswill silently drop files from the Nix build'ssrcfileset. - Missing a name in
flake.nix'sworkspaceNameswill breakpnpmConfigHookbecause dependencies for that workspace will not be fetched.
- The automated "Check flake.nix workspace sync" (
scripts/check-nix-workspace.mjs) only validates the transitive dependency closure of@moonshot-ai/kimi-code. A leaf package outside that closure (e.g. an e2e package nobody imports) slips through even when it is missing fromflake.nix. A green check is therefore NOT proof thatflake.nixis fully in sync — keep it updated by hand on every add/remove, do not rely on the check to catch omissions.
General Coding Rules
packages/agent-core-v2,packages/kap-server, andpackages/transcriptare comment-free zones: no comments of any kind — no line/block comments, no JSDoc (not even on exported symbols); the only exception is load-bearing lint-suppression directives (oxlint-disable/eslint-disable), while other tooling directives (@ts-expect-error, …) stay banned. Enforced byscripts/check-no-comments.mjsover.ts/.tsx/.mts/.mjsundersrc//test//scripts/, which runs as part ofpnpm lint.- For optional object properties, pass
undefineddirectly instead of using conditional spread.- YES:
{ user } - NO:
{ ...(user ? { user } : undefined) }
- YES:
- Optional object properties do not need to additionally allow
undefinedin the type.- YES:
interface Options { user?: User } - NO:
interface Options { user?: User | undefined }
- YES:
- Internal methods with only a single parameter should not be turned into options objects just for stylistic uniformity.
- Split functions only along abstraction levels: each function reads as one level of narrative (Step-down Rule), and a wrapper that adds no new abstraction level — especially one with a single call site — is inlined instead of extracted.
- Except for a package's
index.ts, otherindex.tsfiles should preferexport * from './module';. - Do not add too many new test files. Prefer adding tests to the existing test file of the corresponding component or module.
- When a test fails because of a user modification, default to fixing the test first; do not change the implementation to satisfy an old test unless the implementation truly has a bug.
- Do not sacrifice code quality for external compatibility unless the user explicitly asks for it. Breaking changes go through changesets and a
majorbump, gated by the rule below.
Experimental Features
- Gate a not-yet-public feature behind an experimental flag. Flags are env-driven and default off:
KIMI_CODE_EXPERIMENTAL_<NAME>toggles one,KIMI_CODE_EXPERIMENTAL_FLAGenables all. Precedence is per-flag env >[experimental]config > master env > the flag'sdefault. Release by flipping the entry'sdefaulttotrue.packages/agent-core-v2and kap-server modules: there is no central catalog — declare the flag in the owning domain viaregisterFlagDefinitionat import time, then check it withIFlagService.enabled(id).
Where to Update Instructions
- Hard rules that affect almost every task: update the root
AGENTS.md. - Rules that only affect a specific directory: update the nearest sub-directory
AGENTS.md. - Project-map entries stay at 1–2 sentences; deep package docs live in the package's own
AGENTS.md. - Keep instruction updates focused and supported by code facts.
Workflow Requirements
- Prefer
rg/rg --fileswhen reading code. - When designing changes, follow existing boundaries and local patterns first.
- In public text and test data, replace real internal identifiers with neutral placeholders such as
example.com,example.test, andYOUR_API_KEY. Before opening a PR, ask a read-only agent to audit the diff for context-specific internal identifiers. - When creating a PR, use the
write-prskill (.agents/skills/write-pr/SKILL.md) to write the PR description. The PR title must follow Conventional Commit style, e.g.chore: remove legacy format commands. - When an AI agent opens or updates a PR, fill in
.github/pull_request_template.md— link the related issue or explain the problem, then describe what changed. Do not leave placeholder text or submit a generic summary of the diff. - Do not submit vague AI-generated PR text. The human author must understand the change well enough to explain the code, edge cases, and why the approach fits this repository.
- After finishing a task and before submitting a PR, you must run the
gen-changesetsskill (see.agents/skills/gen-changesets/SKILL.md) and generate a changeset under.changeset/according to its rules. - Changesets must strictly follow the rules in
.agents/skills/gen-changesets/SKILL.md: write one short user-facing sentence that states only what changed, and skip any change users cannot perceive. - When generating a changeset, never decide on a
majorbump on your own — stop, explain, and get explicit user confirmation first; default tominor, fall back topatch. See.agents/skills/gen-changesets/SKILL.md. - Prefer importing via
import ... from '#/...', which serves the same purpose asimport ... from '@/...'. - Do not commit throwaway scratch or exploratory files. Never stage:
- Agent working notes or handoff/summary documents (e.g.
HANDOVER-*.md,HANDOFF-*.md,handoff.md). - Throwaway UI/UX prototypes or design mockups (e.g.
*-designs.html,*-mockup.html,*-demo(s).html) at the repo root or under adesign/folder. The only tracked.htmlfiles should be Viteindex.htmlentrypoints. Before committing or opening a PR, rungit statusandgit diff --staged --statand remove anything matching these patterns. Put scratch work under.tmp/(gitignored) instead of the repo root or the source tree.
- Agent working notes or handoff/summary documents (e.g.
Code Review Rules
These rules apply to every pull request review, automated or human. The user populations and contract files they refer to are listed in .agents/skills/review-pr/surfaces.md.
Enumerate changed behavior, not just bugs
Any input that worked before the change — a config key, env var, CLI flag, provider response shape, session written by an older version, client request, or hook payload — must behave the same after it unless the PR declares the change. For every deleted or narrowed branch, condition, default, or prompt sentence, ask who reached it before and where they go now; for every new condition, ask which existing inputs now match it first. Flag a PR that calls a path "unchanged" when its branch condition moved.
A flipped default or removed behavior needs a named loss and an escape hatch
Everyone on the old default is affected. Require the changeset to name the behavior users lose, not only the new default; a config, env, or flag escape hatch or a maintainer's explicit sign-off in the PR; and a test that pins the old behavior for the population that keeps it.
Prompt text is behavior
Editing or deleting sentences under packages/agent-core-v2/src/**/*.md (system prompt, tool descriptions, reminders, overlays, built-in skills) changes agent behavior for every user who receives that prompt. "No test references the sentence" is not evidence of no impact. Require the PR to name the population that receives the text (every session, plan mode, a flag-gated feature such as Tower), what the sentence enforced, who relied on it, and what enforces it now.
Contract files are tripwires
The manifests under packages/agent-core-v2/docs/ (config-manifest.toml, wire-manifest.d.ts, state-manifest.d.ts), packages/kap-server/test/__snapshots__/apiSurface.snapshot.test.ts.snap, packages/node-sdk/src/index.ts, packages/agent-core-v2/src/features/externalHooks/, packages/acp-server/, and apps/kimi-code/src/cli/ are consumed outside this repository: desktop and web in code-app, the VS Code extension, ACP clients such as Zed, SDK users, hook scripts, and headless-output parsers. When they change, require the PR to name the consumers and how data and clients from the previous release keep working.
Ports and refactors carry the old path's feature inventory
When a change replaces or bypasses an existing path, require a list of what the old path did — env vars honored, fallbacks, accepted inputs — and where each item lives in the new path. A silently dropped item is a regression, not a cleanup.
Silent failure outranks a crash
A change that makes the product silently ignore configuration, silently approve or skip an action, or silently drop data is the most severe finding: users get no signal to report.