mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-01 20:44:53 +00:00
* feat(kimi-inspect): add web inspector for kap-server /api/v2 surface - new apps/kimi-inspect app: connect screen (server URL + optional bearer token, persisted in localStorage, deep-linkable via ?url=/?token=), workspace/session browser sidebar, per-session chat view, and live Service panels with data and trigger buttons for Session/Agent scopes - built on @moonshot-ai/klient (HTTP for calls, /api/v2/ws for events); Vite dev server proxies /api to a running kap-server - register the workspace in AGENTS.md project map and flake.nix workspacePaths/workspaceNames * fix(kimi-inspect): align dependency versions with the workspace (sherif) * feat: dev /api/v1/debug RPC surface and kimi-inspect channel rework - kimi-inspect: replace @moonshot-ai/klient with an in-app old-klient-style channel layer (service-bound IChannel, HTTP ProxyChannel, shared /api/v2/ws socket with ref-counted event listens), typed by agent-core-v2 interfaces; /channels descriptors + serviceByName keep every wire protocol loaded 1:1 - kimi-inspect: local server auto-discovery (Vite middleware over the kap-server instance registry + home token), zero-config startup connect, and a header switcher for runtime server switching - kap-server: wire the dormant --debug-endpoints flag to a new whitelist-free /api/v1/debug dispatcher (every scoped service callable), gated to loopback binds; repo dev scripts pass the flag - kimi-inspect: probe the debug surface at connect, falling back to /api/v2 on servers without it - tests: channel + discovery unit tests in kimi-inspect; debug RPC and loopback-gating coverage in the kap-server rpc/debugNonloopback suites * chore(changesets): ignore @moonshot-ai/kimi-inspect The private dev app never ships, so it should never appear in a changeset. Add it to the changeset config ignore list (next to vis*) and note the rule in the gen-changesets skill.
11 KiB
11 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@moonshot-ai/agent-core. When writing or modifying its terminal UI, use thewrite-tuiskill (.agents/skills/write-tui/SKILL.md).apps/kimi-web: the browser web UI, a peer to the TUI. Vue 3 + Vite + vue-i18n; talks to the server over REST + WebSocket under/api/v1. It must not depend on@moonshot-ai/agent-core(wire types are re-implemented locally). Debug against the two engines via the rootpnpm dev:v1/pnpm dev:v2backend scripts — the dev Sidebar shows the active backend and switches it at runtime. Seeapps/kimi-web/AGENTS.md.apps/vis,apps/vis/server,apps/vis/web: visual debugging tools for sessions and replays.apps/kimi-inspect: web inspector for the v2 (kap-server)/api/v2surface — workspace/session browser, per-session chat, and live Service panels (data + trigger buttons) for the Session and Agent scopes. Built on its own old-klient-style channel layer (src/channel/: the VS CodeProxyChannelmodel — service-boundIChannel, HTTPProxyChannelfor calls routed to/api/v2,WsChannelover the shared/api/v2/wssocket for events), typed byagent-core-v2Service interfaces;GET {rpcBasePath}/channelsloads every wire protocol 1:1 — probing/api/v1/debugfirst (dev, whitelist-free) and falling back to/api/v2. The Vite dev server proxies/apito a running kap-server (KIMI_SERVER_URL, defaulthttp://127.0.0.1:58627) and exposesGET /__inspect/servers(vite/serverDiscovery.ts), which scans the local kap-server instance registry (~/.kimi-code/server/instances+ legacylock) and the home token so the app can zero-config auto-connect and switch servers from the header dropdown at runtime.packages/agent-core: the unified agent engine, including Agent, Session, profile, skills, tools, plan, permission, background, records, the in-process DI service layer (src/services/), and other core capabilities.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/kap-server: the Kimi Code server, backed by the DI × Scope agent engine (@moonshot-ai/agent-core-v2). Exposes sessions over REST + WebSocket (/api/v1and the native/api/v2RPC surface); bootstrapped fromsrc/start.tsand consumed byapps/kimi-code. With--debug-endpointson a loopback bind it additionally mounts/api/v1/debug/*— the same reflection dispatcher as/api/v2but without the channel whitelist (every scoped Service callable,src/transport/registerDebugRoutes.ts); internal only, repo dev scripts pass the flag.packages/klient: the client SDK — a contract-driven facade over agent-core-v2 with aggregatedglobal.*/session(id).*/agent(id).*methods, zod validation on every call, and klient-level typed event forwarding. Transport is chosen once at creation via subpath entry (@moonshot-ai/klient/http|ipc|memory); all three return the sameKlient. The package also hosts the e2e suites: dual-backend session/agent suites (test/e2e/dual/, in-memory + in-process server),/api/v2wire tests (test/e2e/v2/), the legacy/api/v1live suites (test/e2e/legacy/), and the docker e2e runner (pnpm --filter @moonshot-ai/klient docker:e2e). Seepackages/klient/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
- 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.
- Except for a package's
index.ts, otherindex.tsfiles should preferexport * from './module';. - The
Agentclass inpackages/agent-core/src/agentmust be usable on its own. The constructor must not force the caller to create aSessioninstance, nor require anagentIdorsession. It may accept an optionalsessionIdas a request-config hint — for example mapped to the provider'sprompt_cache_key— but the instance must not holdsessionId, and must not depend on the Session lifecycle, metadata, or parent/child relationship logic. - 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. Add the flag to the registry at
packages/agent-core/src/flags/registry.ts, then check it withflags.enabled('my-feature'). Flags are env-driven and default off:KIMI_CODE_EXPERIMENTAL_<NAME>toggles one,KIMI_CODE_EXPERIMENTAL_FLAGenables all. Release by flipping the entry'sdefaulttotrue.
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. - 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, 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. - When generating a changeset, never decide on a
majorbump on your own. When you judge a change to meet the major criteria (breaking changes, incompatible user configuration, renamed or removed commands/arguments, changed behavior semantics, etc.), you must stop and explain it to the user and ask for confirmation. Only writemajorafter the user has explicitly agreed. Otherwise default tominor(and fall back topatchifminoris unclear). See the "Hard rule: confirm with the user before writingmajor" section in.agents/skills/gen-changesets/SKILL.mdfor details. - 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.