mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-09-03 23:00:22 +00:00
Compare commits
No commits in common. "main" and "@moonshot-ai/kimi-code@0.37.1" have entirely different histories.
main
...
@moonshot-
1689 changed files with 47492 additions and 92295 deletions
70
.agents/skills/agent-core-dev/SKILL.md
Normal file
70
.agents/skills/agent-core-dev/SKILL.md
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
---
|
||||||
|
name: agent-core-dev
|
||||||
|
description: Use when developing in packages/agent-core-v2 (the DI × Scope agent engine) — adding or modifying a domain Service, choosing a LifecycleScope, wiring DI dependencies, splitting a domain across scopes, owning or migrating a config section, gating behavior behind an experimental flag, raising coded errors, working on the permission system, writing DI/Scope tests, porting business logic from agent-core (v1) to v2, triaging a main-branch commit against v2, or exposing a v2 domain over server-v2 while keeping the /api/v1 wire contract compatible with released clients. Self-contained guide organized by development stage (orient → design → implement → test → verify) plus align workflows for v1→v2 migration, main-branch commit triage, and server-v2 wire exposure; each file carries the rules, examples, and red lines for its step.
|
||||||
|
---
|
||||||
|
|
||||||
|
# agent-core-dev
|
||||||
|
|
||||||
|
> Develop `packages/agent-core-v2` by lifecycle stage. This skill is **self-contained**: every rule, recipe, and red line lives in the stage files below — it does not delegate to `packages/agent-core-v2/docs/`.
|
||||||
|
|
||||||
|
`agent-core-v2` is the new agent engine built on the **DI × Scope** architecture (a port of `packages/agent-core`). Everything resolves through the container: a service declares an **identity**, its **dependencies**, and a **lifetime**; the container decides construction, singleton-per-scope, ordering, and disposal. The stage files restate the rules in imperative form so you can work without reading the source docs.
|
||||||
|
|
||||||
|
## Lifecycle at a glance
|
||||||
|
|
||||||
|
```text
|
||||||
|
Orient → Design → Implement → Test → Verify
|
||||||
|
│ │ │ │ │
|
||||||
|
│ │ │ │ └─ lint:imports · typecheck · test · dep graph · red lines
|
||||||
|
│ │ │ └─ test.md
|
||||||
|
│ │ └─ implement.md (+ errors.md · flags.md · permission.md)
|
||||||
|
│ └─ design.md
|
||||||
|
└─ orient.md
|
||||||
|
```
|
||||||
|
|
||||||
|
Stages are ordered but not strictly linear: a test failure (stage 4) that reveals a wrong scope sends you back to design (stage 2); a `CyclicDependencyError` sends you to `design.md` §dependency-direction and `implement.md` §cycles.
|
||||||
|
|
||||||
|
## Workflows
|
||||||
|
|
||||||
|
End-to-end procedures that span the stages. Reach for these before reading the stage files individually.
|
||||||
|
|
||||||
|
- [Align (port `agent-core` → `agent-core-v2`)](align.md): split a v1 class into semantic units, fix each unit's domain / scope / Service / dependencies, then migrate the logic and tests. Use when the task is "move feature X from v1 to v2" or "port `IXxxService` to v2".
|
||||||
|
- [Commit align (triage a `main` commit against v2)](commit-align.md): given one `main` commit hash + a short note, find the v1 logic it changed, check whether v2 already has the corresponding implementation, bucket it (aligned / partial / missing / not-applicable), and recommend a minimal fix. Use in the `kimi-code-v2`-catching-up-to-`main` phase, for one commit at a time; escalate to [align.md](align.md) if the gap is a whole domain.
|
||||||
|
- [Server align (expose `agent-core-v2` over `server-v2`)](server-align.md): wire a v2 domain into `packages/kap-server` over `/api/v2` (native) and `/api/v1` (v1-compatible mirror), keep the wire schema byte-compatible with the established v1 contract by sharing the `@moonshot-ai/protocol` schema, and isolate v1-only behavior in a `<domain>Legacy` edge adapter instead of distorting the native v2 Service. Use when the task is "expose the new v2 Service on the server", "add a route to the `/api/v1` surface", or "keep server-v2 wire-compatible with released v1 clients".
|
||||||
|
|
||||||
|
## Stages
|
||||||
|
|
||||||
|
- [Stage 1 — Orient](orient.md): the DI black box (identity / dependencies / lifetime), the four `LifecycleScope` tiers and visibility, and the no-comment convention. Read before touching business code.
|
||||||
|
- [Stage 2 — Design a service](design.md): pick a scope, split a domain across scopes, choose a calling style (direct call vs event vs hook), and direct dependencies. Decide *where things live and who knows whom* before coding.
|
||||||
|
- Topic: [Domain boundaries vs Scope](domain-boundaries.md) — keep `session` / `agent` / `turn` from becoming god objects; data-ownership test and their split conclusions.
|
||||||
|
- Topic: [Persistence layering](persistence.md) — the three-layer `Store → Storage → backend` model, naming Stores by access pattern, and which layer business code should depend on.
|
||||||
|
- Topic: [Edge exposure — `resource:action` + WS events](edge-exposure.md) — which Services are exposed over `/api/v2` (per-scope action map) and which events stream over WS; what to wrap in a facade.
|
||||||
|
- [Stage 3 — Implement](implement.md): the standard Service recipe and the DI building blocks — interface + identity, constructor injection, scoped registration, `Disposable`, eager vs delayed, `invokeFunction`, `createInstance`, child scopes, and the cycle-refactor playbook.
|
||||||
|
- Topic: [Service authoring](service-authoring.md) — file layout, naming, contract vs impl contents, interface style, constructor/field conventions, events, multi-Service domains, comment rules.
|
||||||
|
- Topic: [Config](config.md) — the section-registry model, App vs Session split, owning a config section, the TOML format, and the env overlay.
|
||||||
|
- Topic: [Errors](errors.md) — co-located `XxxError`, the central code registry, wire serialization, boundary translation.
|
||||||
|
- Topic: [Flags](flags.md) — `registerFlagDefinition`, `IFlagService.enabled(id)`, the `[experimental]` config section, resolution precedence.
|
||||||
|
- Topic: [Permission](permission.md) — risk-only chain-of-responsibility kernel, harness constraints and product reviews as domain `onBeforeExecuteTool` veto listeners (`veto` / `allow` / `pass` / cold `waitUntil` factories), shared `toolApproval` round-trip, policy registry + composer, `modes`/`agentTypes` metadata, `resolveExecution`/`accesses`.
|
||||||
|
- Topic: [Telemetry](telemetry.md) — emitting events via `ITelemetryService`, context propagation, and appender destinations (`ConsoleAppender` / `CloudAppender`).
|
||||||
|
- [Stage 4 — Test](test.md): resolve the system under test by interface, pick `TestInstantiationService` vs `createScopedTestHost`, shared stubs, service groups, teardown.
|
||||||
|
- [Stage 5 — Verify & submit](verify.md): `lint:imports`, `typecheck`, `test`, and the pre-submit checklist.
|
||||||
|
|
||||||
|
## How to use this skill
|
||||||
|
|
||||||
|
Jump to the stage you are in and read that one file; each is self-contained and ends with its own red lines. Skim the global red lines below before submitting — they catch most mistakes across every stage. The repo's source of truth remains the code in `packages/agent-core-v2/src/`; this skill codifies the same rules so you do not have to re-derive them.
|
||||||
|
|
||||||
|
## Global red lines
|
||||||
|
|
||||||
|
Invariants that hold across every stage. Each is expanded in the stage file noted.
|
||||||
|
|
||||||
|
1. No `new` on a class whose constructor carries `@IService` deps — inject with `@IX` or `accessor.get(IX)`. (implement.md)
|
||||||
|
2. `@IX` decorates constructor parameters only; parameter order depends on construction (static-first for `createInstance`, `@IX`-first for scoped services). (service-authoring.md)
|
||||||
|
3. Both interface and impl carry `_serviceBrand`; the `createDecorator` name is globally unique. (implement.md)
|
||||||
|
4. Parent scope never depends on child scope — short-lived may inject long-lived, never the reverse. (orient.md)
|
||||||
|
5. No cyclic dependencies — refactor (extract a third Service / use an event / re-scope); activation timing does not break dependency cycles. (design.md, implement.md)
|
||||||
|
6. `ServicesAccessor` is valid only during `invokeFunction` — never stash it for async use. (implement.md)
|
||||||
|
7. Scope follows state identity — no `Map<sessionId, …>` at `App` to fake per-session state. (design.md)
|
||||||
|
8. Foundational layers never know upstream ones; business code never depends on the edge layer (`gateway`/`rpc`). (design.md)
|
||||||
|
9. Throw coded errors; register codes centrally; branch on `code` across the wire, never `instanceof`. (errors.md)
|
||||||
|
10. Gate unreleased behavior behind a flag contributed via `registerFlagDefinition` and resolved through `IFlagService.enabled(id)`; no ad-hoc env toggles. (flags.md)
|
||||||
|
11. Tests resolve the SUT by interface; shared stubs live under `test/`, never `src/`. (test.md)
|
||||||
|
12. Config is the preference registry: only preferences that are persistable, schema'd, and user/operator-facing go in `IConfigService`. Domain-specific config (including env-only operational toggles) goes through `registerConfigSection` + `envOverlay`. Facts → `IBootstrapService`, and host invocation arguments (CLI flags, host identity headers, prompt identity) → `BootstrapInput.args` / `IBootstrapService.args` — never new per-domain runtime-options services; domain runtime state (cron/flags/model) never goes onto `IBootstrapService`; session state → Session scope; constants → code. Business domains never call `IBootstrapService.getEnv()` directly. (config.md)
|
||||||
235
.agents/skills/agent-core-dev/align.md
Normal file
235
.agents/skills/agent-core-dev/align.md
Normal file
|
|
@ -0,0 +1,235 @@
|
||||||
|
# Subskill — Align (port `agent-core` → `agent-core-v2`)
|
||||||
|
|
||||||
|
Port business logic from `packages/agent-core` (v1) into `packages/agent-core-v2` (v2) by **splitting semantics, then fixing the domain, scope, Service, and dependency relationships**, and finally migrating the logic and tests.
|
||||||
|
|
||||||
|
Use this when the task is "move feature X from v1 to v2", "port `IXxxService` to v2", or "align a v1 domain with the v2 architecture". It complements the stage files: orient / design / implement / test explain the *target* architecture; this file explains how to get there *from v1*.
|
||||||
|
|
||||||
|
## The one-paragraph mental model
|
||||||
|
|
||||||
|
v1 is a **VSCode-style singleton container**: services self-register with `registerSingleton`, resolve as singleton-per-container, and have no explicit lifetime tier — so a single `ISessionService` / `IToolService` tends to accumulate global, per-session, and per-agent state in one class. v2 is a **DI × Scope tree**: every service binds to one of `App` / `Session` / `Agent`, and a domain with state at several lifetimes is split into several Services. Porting is therefore **not** a file copy — it is "find each lifetime of state hiding in the v1 class, give each its own v2 Service at the right scope, then re-wire the dependencies".
|
||||||
|
|
||||||
|
## v1 → v2 at a glance
|
||||||
|
|
||||||
|
| Concern | v1 (`agent-core`) | v2 (`agent-core-v2`) |
|
||||||
|
|---|---|---|
|
||||||
|
| Registration | `registerSingleton(IX, X, InstantiationType.Delayed)` | `registerScopedService(LifecycleScope.X, IX, X, ScopeActivation.OnDemand, 'domain')` |
|
||||||
|
| DI import | `from '../../di'` | `from '#/_base/di/scope'` / `'#/_base/di/instantiation'` / `'#/_base/di/lifecycle'` |
|
||||||
|
| Lifetime | implicit singleton-per-container | explicit `LifecycleScope` (App/Workspace/Session/Agent) — see orient.md |
|
||||||
|
| Domain granularity | coarse (`session`, `tool`, `loop`) | fine, split by scope + responsibility |
|
||||||
|
| Test import | `from '@moonshot-ai/agent-core/di/test'` | `from '#/_base/di/test'` |
|
||||||
|
| Resolve SUT in tests | `ix.createInstance(Impl)` (common) | `ix.get(IX)` by interface — see test.md |
|
||||||
|
| Scope tests | none | `createScopedTestHost` — see test.md |
|
||||||
|
| Errors | `from '../../errors'` (central `KimiError`, `ErrorCodes`) | `from '#/_base/errors'` + domain co-located `XxxError` — see errors.md |
|
||||||
|
| Flags | `flags/` (process-global `FlagResolver`) | `flag/` (App-scope `IFlagService`) — see flags.md |
|
||||||
|
| Permission | `agent/permission/` (hardcoded chain) | `permission*` (registry + composer) — see permission.md |
|
||||||
|
|
||||||
|
## The align workflow
|
||||||
|
|
||||||
|
```text
|
||||||
|
Read v1 → Semantic split → Map domain → Assign scope → Shape Services
|
||||||
|
→ Direct dependencies → Port logic → Port tests → Verify
|
||||||
|
```
|
||||||
|
|
||||||
|
Each step below states the goal and the concrete action, then points to the stage file that goes deeper. Do them in order; a later step often sends you back to an earlier one (a scope that does not fit means the semantic split was wrong).
|
||||||
|
|
||||||
|
### 1. Read v1
|
||||||
|
|
||||||
|
**Goal:** build an accurate inventory of what the v1 code actually owns. Read the v1 *source*, not v1 docs.
|
||||||
|
|
||||||
|
Actions:
|
||||||
|
|
||||||
|
- Locate the v1 entry: contract (`<domain>/<domain>.ts`) + impl (`<domain>/<domain>Service.ts`), plus any helpers under the same folder.
|
||||||
|
- Inventory three things from the impl:
|
||||||
|
- **State** — every field / `Map` / cache the class holds. For each, note its *identity* (global? keyed by `sessionId`? by `agentId`?).
|
||||||
|
- **Behavior** — every public method; group them by which state they touch.
|
||||||
|
- **Dependencies** — every `@IFoo` constructor injection and every cross-domain relative import (`from '../<other>/...'`).
|
||||||
|
- Note the v1 registration line (`registerSingleton(...)`) and any `services.set(IX, ...)` overrides at bootstrap (these reveal runtime static args or prebuilt instances the port must preserve).
|
||||||
|
|
||||||
|
Do not start splitting yet — an accurate inventory prevents the common mistake of porting the class shape instead of the semantics.
|
||||||
|
|
||||||
|
### 2. Semantic split
|
||||||
|
|
||||||
|
**Goal:** break one v1 class into independent semantic units, each owning state at exactly one lifetime. This is the heart of the port.
|
||||||
|
|
||||||
|
Method — for each piece of state from the inventory, ask:
|
||||||
|
|
||||||
|
1. **What is it keyed by?** nothing → a global unit; `sessionId` → a per-session unit; `agentId` → a per-agent unit.
|
||||||
|
2. **When should it die?** with the process / the session / the agent. State that must outlive its neighbors is a different unit.
|
||||||
|
3. **Which methods touch only this state?** they travel with the unit.
|
||||||
|
|
||||||
|
Worked example — v1 `ISessionService` (one class, ~600 lines) holds:
|
||||||
|
|
||||||
|
- a global index of all sessions → **global** unit → v2 `sessionStore` (`ISessionStore`, App);
|
||||||
|
- this session's metadata → **per-session** unit → v2 `sessionMetaStore` (`ISessionMetaStore`, Session);
|
||||||
|
- this session's activity / status → **per-session** unit → v2 `sessionActivity`;
|
||||||
|
- this session's context projection → **per-session** unit → v2 `sessionContext`;
|
||||||
|
- child-agent lifecycle driven by a session → **per-session** unit → v2 `agentLifecycle`; create/close/archive/fork of the session itself → **per-workspace** unit → v2 `sessionLifecycle` (Workspace, one per live workspace handler).
|
||||||
|
|
||||||
|
A v1 class that maps cleanly to one v1 decorator often becomes **three to five** v2 Services. That is expected and correct — do not try to keep the v1 class shape.
|
||||||
|
|
||||||
|
Red lines:
|
||||||
|
|
||||||
|
- If two pieces of state have different identities, they belong in different units — do not keep them together "because v1 did".
|
||||||
|
- Do not split by method count or file aesthetics; split by state identity (design.md §3).
|
||||||
|
- If a unit has no mutable state (pure behavior), defer its scope decision to step 4 (it is pulled down by its shortest-lived dependency).
|
||||||
|
|
||||||
|
### 3. Map to v2 domain
|
||||||
|
|
||||||
|
**Goal:** assign each semantic unit to a v2 domain — an existing one if it fits, a new one only if none does.
|
||||||
|
|
||||||
|
Actions:
|
||||||
|
|
||||||
|
- Search v2 `src/` for an existing domain that owns the same responsibility. Prefer joining an existing domain over creating a new one.
|
||||||
|
- If creating a domain, name it after the responsibility (camelCase folder, e.g. `sessionActivity`), not after the v1 file.
|
||||||
|
- Keep a domain's public surface to one contract file (`<domain>.ts`) plus its impl(s).
|
||||||
|
|
||||||
|
Reference mapping (a **starting point**, not gospel — verify against the current v2 `src/`, which is the source of truth):
|
||||||
|
|
||||||
|
| v1 location | v2 domain(s) |
|
||||||
|
|---|---|
|
||||||
|
| `services/session/`, `session/` | `session`, `sessionStore`, `sessionMetaStore`, `sessionActivity`, `sessionContext`, `agentLifecycle` |
|
||||||
|
| `services/tool/`, `tools/`, `agent/tool/` | `toolRegistry`, `toolStore`, `toolExecutor`, `tooldedup`, `userTool` |
|
||||||
|
| `loop/`, `agent/` (turn loop) | `loop`, `llmRequester`, `llmRequestLog`, `turn` |
|
||||||
|
| `agent/context/`, `agent/compaction/` | `contextMemory`, `contextProjector`, `contextSize`, `fullCompaction`, `dynamicInjector` |
|
||||||
|
| `agent/permission/` | `permission`, `permissionMode`, `permissionPolicy`, `permissionRules`, `approval`, `externalHooks` |
|
||||||
|
| `agent/goal/`, `agent/plan/`, `agent/swarm/`, `agent/cron/`, `agent/background/` | `goal`, `plan`, `swarm`, `cron`, `background`, `subagentHost` |
|
||||||
|
| `services/config/`, `agent/config/` | `config` |
|
||||||
|
| `services/event/`, `base/common/event` | `event`, `eventBus` |
|
||||||
|
| `services/logger/`, `logging/` | `log` |
|
||||||
|
| `services/fileStore/` | `filestore`, `blobStore` |
|
||||||
|
| `services/fs/`, `services/workspace/` | `fs`, `workspace` |
|
||||||
|
| `services/auth/`, `services/oauth/` | `auth` |
|
||||||
|
| `services/environment/` | `environment` |
|
||||||
|
| `services/terminal/` | `terminal` |
|
||||||
|
| `services/question/`, `services/approval/` | `question`, `approval` |
|
||||||
|
| `services/prompt/`, `agent/injection/` | `prompt`, `dynamicInjector` |
|
||||||
|
| `services/mcp/`, `mcp/` | `mcp` |
|
||||||
|
| `plugin/`, `profile/`, `skill/` | `plugin`, `profile`, `skill` |
|
||||||
|
| `rpc/`, `services/coreProcess/` | `rpc`, `gateway` |
|
||||||
|
| `di/` | `_base/di` |
|
||||||
|
| `errors/`, `errors.ts` | `_base/errors` + co-located domain errors |
|
||||||
|
| `flags/` | `flag` |
|
||||||
|
| `telemetry.ts` | `telemetry` |
|
||||||
|
| `agent/records/` | (records split) — verify in v2 `src/` |
|
||||||
|
|
||||||
|
When the table says "verify", or when v1 and v2 have diverged, **read the v2 `src/` tree and decide from the code** — do not invent a mapping.
|
||||||
|
|
||||||
|
### 4. Assign scope
|
||||||
|
|
||||||
|
For each semantic unit, fix its `LifecycleScope` from the identity you found in step 2. Follow design.md §2 verbatim:
|
||||||
|
|
||||||
|
- global → `App`; per `sessionId` → `Session`; per `agentId` → `Agent`.
|
||||||
|
- Stateless unit → default to `App`, pulled down only by a shorter-lived dependency.
|
||||||
|
- Self-check: "when this scope is disposed, should this state disappear with it?"
|
||||||
|
|
||||||
|
This is the decision v1 never had to make — get it right before writing any v2 code, because the scope is fixed at registration and changing it later ripples through every consumer.
|
||||||
|
|
||||||
|
### 5. Shape Services
|
||||||
|
|
||||||
|
Decide the Service shape per unit, following design.md §3:
|
||||||
|
|
||||||
|
- A unit that owns **one instance's** state → a single per-instance Service (`ISessionXxx` / `IAgentXxx`).
|
||||||
|
- A unit that owns a **global view plus per-instance** state → split into an `App` registry/factory (`XxxStore` / `XxxRegistry` / `XxxCatalog`) **and** a per-instance Service. The `App` half creates or locates the per-instance half.
|
||||||
|
- Do not pre-split a unit that has state at only one lifetime.
|
||||||
|
|
||||||
|
Most consumers inject the per-instance Service; inject the `App` factory only for genuine cross-instance management.
|
||||||
|
|
||||||
|
### 6. Direct dependencies
|
||||||
|
|
||||||
|
Re-wire the dependencies you inventoried in step 1, now across the new v2 Services. Follow design.md §4–§5:
|
||||||
|
|
||||||
|
- **Calling style** — need a result / I orchestrate → direct call (`@IX` injection); stating a fact → event; ordered participation that may veto → hook.
|
||||||
|
- **Scope direction** — a Service may inject only its own scope or an ancestor. If an `App` Service needs something from a `Session` Service, the dependency is backwards: re-scope or invert into an event.
|
||||||
|
- **Domain direction** — foundational layers must not know upstream ones. A cycle means a v1 relative import is now pointing the wrong way; extract a third Service or invert the notification into an event.
|
||||||
|
- **Durable facts** — state changes that must be recorded / replayed / projected across agents go on the wire (`wireRecord`), not a direct call alone.
|
||||||
|
|
||||||
|
Run `lint:imports` (verify.md) as soon as the dependencies compile — it catches v1 imports and kosong boundary violations early.
|
||||||
|
|
||||||
|
### 7. Port the business logic
|
||||||
|
|
||||||
|
Move the behavior into the shaped v2 Services, applying the mechanical conversions below. Follow implement.md for the recipe.
|
||||||
|
|
||||||
|
**Registration:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// v1
|
||||||
|
import { InstantiationType, registerSingleton } from '../../di';
|
||||||
|
registerSingleton(IXxxService, XxxService, InstantiationType.Delayed);
|
||||||
|
|
||||||
|
// v2
|
||||||
|
import { LifecycleScope } from '#/app/scopes';
|
||||||
|
import { ScopeActivation, registerScopedService } from '#/_base/di/scope';
|
||||||
|
registerScopedService(LifecycleScope.Session, IXxxService, XxxService, ScopeActivation.OnDemand, 'xxx');
|
||||||
|
```
|
||||||
|
|
||||||
|
**Imports:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// v1
|
||||||
|
import { createDecorator, Disposable, IInstantiationService } from '../../di';
|
||||||
|
import { KimiError, ErrorCodes } from '../../errors';
|
||||||
|
|
||||||
|
// v2
|
||||||
|
import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
|
||||||
|
import { Disposable } from '#/_base/di/lifecycle';
|
||||||
|
import { IInstantiationService } from '#/_base/di/instantiation';
|
||||||
|
import { KimiError, type ErrorCode } from '#/_base/errors';
|
||||||
|
```
|
||||||
|
|
||||||
|
**Constructor injection** — unchanged in shape (`@IX` on constructor params, service params after static params). Verify each dependency is resolvable from the new scope (step 6).
|
||||||
|
|
||||||
|
**Errors** — move any shared error into a co-located `XxxError extends KimiError` with a registered `code` (errors.md). Do not keep throwing v1's central error codes from a v2 domain.
|
||||||
|
|
||||||
|
**Flags** — replace any `FlagResolver` / env check with `IFlagService.enabled(id)`; contribute new flags from the owning domain's `flag.ts` via `registerFlagDefinition` (flags.md).
|
||||||
|
|
||||||
|
**Events** — v1's `Emitter` / `Event` from `base/common/event` maps to v2's `event` / `eventBus` domains. Read existing v2 usage in neighboring domains and match it; do not import v1's `Emitter`.
|
||||||
|
|
||||||
|
**Runtime static args / prebuilt instances** — if v1 bootstrap did `services.set(IX, new SyncDescriptor(C, [bag]))` or set a prebuilt instance, preserve that behavior at the v2 composition root (the scope that owns the Service). Do not silently drop it.
|
||||||
|
|
||||||
|
Red lines:
|
||||||
|
|
||||||
|
- Do not copy a v1 file and "fix imports". Re-split first (steps 2–6); a straight copy carries v1's implicit-singleton assumptions into v2 and creates the `Map<sessionId, …>`-at-`App` anti-pattern.
|
||||||
|
- Do not leave v1 relative imports (`from '../x/...'`) in v2 — use the `#/...` alias.
|
||||||
|
- Do not preserve a v1 behavior just because it exists; if the split reveals it was a workaround for the missing scope tree, drop it.
|
||||||
|
|
||||||
|
### 8. Port the tests
|
||||||
|
|
||||||
|
Convert v1 tests to the v2 harness, following test.md:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// v1
|
||||||
|
import { TestInstantiationService } from '@moonshot-ai/agent-core/di/test';
|
||||||
|
const svc = ix.createInstance(XxxService, 'static-arg');
|
||||||
|
|
||||||
|
// v2
|
||||||
|
import { createServices } from '#/_base/di/test';
|
||||||
|
// in additionalServices:
|
||||||
|
reg.define(IXxxService, XxxService);
|
||||||
|
// in the test body:
|
||||||
|
const svc = ix.get(IXxxService);
|
||||||
|
```
|
||||||
|
|
||||||
|
- Resolve the SUT by interface (`ix.get(IX)`), never `new` a `@IService`-carrying impl, and prefer `ix.get(IX)` over `ix.createInstance(Impl)`.
|
||||||
|
- Move shared stubs into `test/<domain>/stubs.ts`; import by relative path, never `#/...`.
|
||||||
|
- If the port introduced scope-layer behavior, add a `createScopedTestHost` test that asserts resolution from the correct scope (with `_clearScopedRegistryForTests()` + explicit re-registration in `beforeEach`).
|
||||||
|
- Keep v1's behavioral assertions where they still describe observable behavior; delete assertions that only checked v1's internal class shape.
|
||||||
|
|
||||||
|
## Migration checklist
|
||||||
|
|
||||||
|
Before submitting a port:
|
||||||
|
|
||||||
|
- [ ] Every piece of v1 state landed in a v2 Service whose scope matches its identity (no `Map<sessionId, …>` at `App`).
|
||||||
|
- [ ] Each v1 dependency now points in the right scope direction; `lint:imports` passes.
|
||||||
|
- [ ] Registrations use `registerScopedService` with an explicit scope and domain name; no `registerSingleton` remains.
|
||||||
|
- [ ] Imports use the `#/...` alias; no v1 relative (`../../di`, `../../errors`) imports remain.
|
||||||
|
- [ ] Errors are co-located coded errors; flags go through `IFlagService`.
|
||||||
|
- [ ] Tests resolve the SUT by interface; scope behavior is asserted via `createScopedTestHost`; teardown goes through one `DisposableStore`.
|
||||||
|
- [ ] v1 bootstrap overrides (`services.set(...)`) are preserved at the v2 composition root.
|
||||||
|
|
||||||
|
## Red lines (this subskill)
|
||||||
|
|
||||||
|
- Porting is semantic splitting, not file copying — never preserve a v1 class shape in v2.
|
||||||
|
- Decide scope from state identity before writing v2 code; the scope is fixed at registration.
|
||||||
|
- Verify the domain mapping against current v2 `src/`; the table here is a starting point, not authority.
|
||||||
|
- One Service owns state at exactly one lifetime; split global-view + per-instance into registry + per-instance.
|
||||||
|
- A dependency cycle introduced by the port means a v1 import is now backwards — refactor it; activation timing cannot break the cycle.
|
||||||
155
.agents/skills/agent-core-dev/close-vs-dispose.md
Normal file
155
.agents/skills/agent-core-dev/close-vs-dispose.md
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
# Topic — Close vs Dispose
|
||||||
|
|
||||||
|
How to shut down a scoped service in `agent-core-v2`: when `dispose()` is enough, when to add an async `close()`, and where cancellation / abort belongs. Read this before putting business shutdown logic into a `Disposable`.
|
||||||
|
|
||||||
|
## The one-sentence rule
|
||||||
|
|
||||||
|
> **`close()` is async business shutdown; `dispose()` is synchronous resource cleanup.**
|
||||||
|
|
||||||
|
`close()` finishes a domain's work: stop in-flight operations, apply shutdown policy, flush persistence, release async resources. `dispose()` releases object resources: event subscriptions, timers, hook registrations, and child disposables.
|
||||||
|
|
||||||
|
## Why they must stay separate
|
||||||
|
|
||||||
|
`IDisposable.dispose()` is synchronous:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface IDisposable {
|
||||||
|
dispose(): void;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The container calls it during scope teardown. Disposal order is deterministic (orient.md): child scopes first, then reverse construction order within a scope. Nothing awaits a Promise returned from `dispose()`.
|
||||||
|
|
||||||
|
Business shutdown is usually async. It may need to:
|
||||||
|
|
||||||
|
- stop in-flight tasks and wait for settlement;
|
||||||
|
- decide policy (`kill` vs `keepAliveOnExit` vs `markLost`);
|
||||||
|
- flush write queues and persistence;
|
||||||
|
- emit final records / events / telemetry;
|
||||||
|
- close sockets, child processes, or external clients.
|
||||||
|
|
||||||
|
If that logic lives in `dispose()`, it becomes fire-and-forget: the scope keeps tearing down, dependencies may be disposed immediately afterward, and the async continuation can run against a half-dead object graph.
|
||||||
|
|
||||||
|
## What `close()` owns
|
||||||
|
|
||||||
|
Add `close(): Promise<void>` when a service owns async shutdown work:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface IXxxService {
|
||||||
|
readonly _serviceBrand: undefined;
|
||||||
|
close(reason?: string): Promise<void>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
A good `close()`:
|
||||||
|
|
||||||
|
- is idempotent — repeated calls return the same Promise or no-op;
|
||||||
|
- is called by lifecycle code **before** `scope.dispose()`;
|
||||||
|
- rejects new work after it starts;
|
||||||
|
- applies shutdown policy explicitly;
|
||||||
|
- awaits the work it starts;
|
||||||
|
- leaves `dispose()` with only synchronous cleanup.
|
||||||
|
|
||||||
|
Sketch:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
class XxxService extends Disposable implements IXxxService {
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
private closed = false;
|
||||||
|
|
||||||
|
async close(reason = 'scope closed'): Promise<void> {
|
||||||
|
if (this.closed) return;
|
||||||
|
this.closed = true;
|
||||||
|
|
||||||
|
await this.stopInFlightWork(reason);
|
||||||
|
await this.flushPersistence();
|
||||||
|
}
|
||||||
|
|
||||||
|
override dispose(): void {
|
||||||
|
this.closed = true;
|
||||||
|
// synchronous cleanup only: clear timers, remove listeners, release handles.
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`flush()` is different from `close()`: `flush()` persists buffered state while the service stays open; `close()` is terminal.
|
||||||
|
|
||||||
|
## What `dispose()` owns
|
||||||
|
|
||||||
|
`dispose()` releases resources owned by the object instance:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
class WSBroadcastService extends Disposable implements IWSBroadcastService {
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
|
||||||
|
constructor(@IEventService event: IEventService) {
|
||||||
|
super();
|
||||||
|
this._register(event.subscribe(() => { /* … */ }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `dispose()` to:
|
||||||
|
|
||||||
|
- `_register(...)` event subscriptions and hook registrations;
|
||||||
|
- clear timers;
|
||||||
|
- remove signal listeners;
|
||||||
|
- dispose child `IDisposable`s;
|
||||||
|
- detach from synchronous handles.
|
||||||
|
|
||||||
|
`dispose()` must be idempotent and should avoid throwing. If `close()` was already called, `dispose()` should be a no-op for business work and only clean resources.
|
||||||
|
|
||||||
|
## Where abort / cancellation belongs
|
||||||
|
|
||||||
|
Cancellation is not the same thing as graceful shutdown.
|
||||||
|
|
||||||
|
For an operation-scoped object, a cancellation trigger can be disposed:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const tokenSource = new CancellationTokenSource();
|
||||||
|
store.add(toDisposable(() => tokenSource.cancel()));
|
||||||
|
```
|
||||||
|
|
||||||
|
This is fine when the contract is **fire-and-forget cancel**: the operation observes the token and settles asynchronously; disposal does not wait for completion.
|
||||||
|
|
||||||
|
For a manager/service that owns many tasks and their state, do not use `dispose()` as the graceful abort path. Expose `stop()` / `stopAll()` / `close()` and let lifecycle code await the one it needs.
|
||||||
|
|
||||||
|
Background-specific rule: a `background`-style service may use `AbortController` internally to propagate cancellation to process / agent / question tasks, but manager shutdown belongs in `close()` or explicit `stopAll()`. `dispose()` may best-effort abort controllers only as a safety net; it must not be the mechanism that decides terminal status, persistence, or notifications.
|
||||||
|
|
||||||
|
## Decision tree
|
||||||
|
|
||||||
|
```text
|
||||||
|
What does the service own?
|
||||||
|
│
|
||||||
|
├─ only event subscriptions / timers / disposable handles?
|
||||||
|
│ └─ extend Disposable; no close() needed.
|
||||||
|
│
|
||||||
|
├─ async work, in-flight tasks, persistence buffers, sockets, child processes?
|
||||||
|
│ └─ add close(): Promise<void>; call it before scope.dispose().
|
||||||
|
│
|
||||||
|
├─ a single operation that callers may cancel?
|
||||||
|
│ └─ expose an AbortSignal / CancellationToken or a fire-and-forget cancel handle.
|
||||||
|
│
|
||||||
|
└─ both async shutdown and disposable resources?
|
||||||
|
└─ close() for business shutdown; dispose() for resource cleanup.
|
||||||
|
```
|
||||||
|
|
||||||
|
## VSCode parallel
|
||||||
|
|
||||||
|
VSCode uses the same split:
|
||||||
|
|
||||||
|
- `src/vs/base/common/lifecycle.ts` — `IDisposable.dispose(): void` for synchronous cleanup.
|
||||||
|
- `src/vs/base/parts/storage/common/storage.ts` — `close(): Promise<void>` flushes and closes the database.
|
||||||
|
- `src/vs/base/common/cancellation.ts` — `CancellationTokenSource.dispose(true)` / `cancelOnDispose()` cancels operation-scoped work without awaiting it.
|
||||||
|
|
||||||
|
The lesson is not "never cancel in dispose". It is: **disposal may trigger cancellation for a scoped operation, but service shutdown policy stays in an explicit async close path.**
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- Do not put business shutdown in `dispose()` — `dispose()` is synchronous and is not awaited.
|
||||||
|
- Do not `await` inside `dispose()`.
|
||||||
|
- Do not rely on `dispose()` to flush persistence, emit final events, wait for tasks, or send notifications.
|
||||||
|
- Add `close(): Promise<void>` for async shutdown and call it before `scope.dispose()`.
|
||||||
|
- Keep `close()` and `dispose()` idempotent; `dispose()` after `close()` must be safe.
|
||||||
|
- Use disposal as a cancellation trigger only for operation-scoped work, not as a manager/service shutdown policy.
|
||||||
78
.agents/skills/agent-core-dev/commit-align.md
Normal file
78
.agents/skills/agent-core-dev/commit-align.md
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
# Subskill — Commit align (triage a `main` commit against v2)
|
||||||
|
|
||||||
|
Context: you are on the `kimi-code-v2` branch, in the phase of catching it up to **new commits that landed on `main`**. Those commits change `packages/agent-core` (v1); the job is to decide, for one commit at a time, whether v2 (`packages/agent-core-v2`) already has the corresponding logic — and if not, what the minimal fix is.
|
||||||
|
|
||||||
|
Use this when the user hands you **one commit hash plus a short description** ("look at `<commit>` — it fixed the steering race"). It is the small, per-commit sibling of [align.md](align.md): `align.md` ports a whole v1 domain into v2; this file triages a single `main` commit and says *port / adapt / skip*. If the triage reveals a whole missing domain, stop and switch to [align.md](align.md).
|
||||||
|
|
||||||
|
## The one-paragraph mental model
|
||||||
|
|
||||||
|
A `main` commit edits v1's singleton-container code. The same behavior in v2 lives behind a scoped Service, so a commit lands in one of four buckets: **already-aligned** (v2 has it, possibly by construction), **partial** (v2 has a nearby version whose semantics drift), **missing** (v2 has nothing), or **not-applicable** (the v2 architecture removed the very problem the commit fixes). Your output is a bucket assignment plus evidence, then a fix sized to that bucket — never a blind port of the diff.
|
||||||
|
|
||||||
|
## The workflow
|
||||||
|
|
||||||
|
```text
|
||||||
|
Read the commit + the user's note → Locate the v1 logic → Map to a v2 domain
|
||||||
|
→ Check v2 for a corresponding implementation → Bucket it → Recommend a fix → Verify
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1. Read the commit and the note
|
||||||
|
|
||||||
|
**Goal:** know exactly what changed in v1 and *why*. The user's one-liner gives the intent; the diff gives the facts.
|
||||||
|
|
||||||
|
Actions:
|
||||||
|
|
||||||
|
- Inspect the change scoped to v1: `git show <commit> -- packages/agent-core` (and `--stat` first to see the blast radius).
|
||||||
|
- From the diff, list: touched files, changed functions/methods, and the observable behavior delta (before → after).
|
||||||
|
- Reconcile with the user's note: is this a bugfix, a semantic correction, new behavior, or a refactor? The *why* decides whether v2 even needs the change.
|
||||||
|
|
||||||
|
Do not skim the user's sentence and guess — the diff is the spec for what "aligned" means here.
|
||||||
|
|
||||||
|
### 2. Locate the v1 logic
|
||||||
|
|
||||||
|
Pin the change to a v1 place: the contract (`<domain>/<domain>.ts`) + impl (`<domain>/<domain>Service.ts`), or the helper/handler the commit touched. Note which state it reads/writes and which other v1 services it calls — this is the same inventory as [align.md](align.md) §1, scoped to the commit's footprint.
|
||||||
|
|
||||||
|
### 3. Map to a v2 domain
|
||||||
|
|
||||||
|
Use the v1 → v2 domain table in [align.md](align.md) §3 as a starting point, then **verify against the current `packages/agent-core-v2/src/` tree** — it is the source of truth. Identify the candidate v2 Service(s) that would own this behavior, and their `LifecycleScope`.
|
||||||
|
|
||||||
|
### 4. Check v2 and assign a bucket
|
||||||
|
|
||||||
|
Search the candidate domain in v2 (Grep the method name, the state field, the error code). For each piece of the commit's behavior delta, decide:
|
||||||
|
|
||||||
|
- **Already-aligned** — v2 produces the same observable result (sometimes for free, because the v2 design never had the bug). Cite the v2 file:line.
|
||||||
|
- **Partial** — v2 has a near miss: same method, different guard/ordering/error; or the state lives at a different scope. Name the exact drift.
|
||||||
|
- **Missing** — no v2 Service owns this behavior. Confirm it is a single-Service gap, not a whole-domain gap (latter → [align.md](align.md)).
|
||||||
|
- **Not-applicable** — the v2 architecture removed the condition the commit fixes (e.g. the scope tree already serializes what v1 patched with a lock). Explain why, so a reviewer trusts the skip.
|
||||||
|
|
||||||
|
Every claim needs a citation (`path:line`) on both sides; "I couldn't find it" is a finding only after you name where you looked.
|
||||||
|
|
||||||
|
### 5. Recommend a fix (sized to the bucket)
|
||||||
|
|
||||||
|
- **Already-aligned** — say so and stop; reference the v2 location. No code change.
|
||||||
|
- **Partial** — propose the smallest edit that closes the drift: which Service, which method, which guard. Stay inside v2 rules — scope/domain direction, no `Map<sessionId, …>` at `App` (see [align.md](align.md) §6–§7 red lines).
|
||||||
|
- **Missing** — sketch the port at commit granularity: target domain + scope, the Service/method to add or extend, the dependency direction, and which [align.md](align.md) §7 conversions apply (registration, `#/…` imports, co-located coded error, `IFlagService` for any gate). If it needs a new scope or a wire change, flag it.
|
||||||
|
- **Not-applicable** — recommend no v2 change, but call out any test worth adding so the gap stays closed.
|
||||||
|
|
||||||
|
Keep the recommendation to the commit's footprint. If it keeps growing, that is the signal to hand off to [align.md](align.md) for a full domain port.
|
||||||
|
|
||||||
|
### 6. Verify
|
||||||
|
|
||||||
|
Point at the checks that cover the fix, per [verify.md](verify.md): `lint:imports`, `typecheck`, and the relevant `test`. Note the expected outcome rather than asserting you ran it if you did not.
|
||||||
|
|
||||||
|
## Output shape
|
||||||
|
|
||||||
|
When triaging, answer in this order so the user can act on it directly:
|
||||||
|
|
||||||
|
1. **Commit + intent** — one line restating what the commit changed and why (from the note + diff).
|
||||||
|
2. **v1 location** — file(s) and the behavior delta.
|
||||||
|
3. **v2 status** — one of the four buckets, with `path:line` evidence on both sides.
|
||||||
|
4. **Recommendation** — the concrete fix (or the justified skip), scoped to the commit; name the target Service / scope / dependency direction.
|
||||||
|
5. **Verify** — which checks should pass, and whether to escalate to [align.md](align.md).
|
||||||
|
|
||||||
|
## Red lines (this subskill)
|
||||||
|
|
||||||
|
- Read the diff and the note before judging v2; never infer "aligned" from the description alone.
|
||||||
|
- Do not copy a v1 diff into v2. Decide the bucket first; a bugfix commit often maps to **not-applicable** because the v2 design already removed the defect.
|
||||||
|
- Cite `path:line` on both sides. A recommendation without evidence is a guess.
|
||||||
|
- Stay in the commit's footprint. Growing scope means "switch to [align.md](align.md)", not "keep porting here".
|
||||||
|
- Do not break v2 invariants to chase v1 parity — scope direction, domain direction, and no `Map<sessionId, …>` at `App` still hold ([align.md](align.md) red lines).
|
||||||
312
.agents/skills/agent-core-dev/config.md
Normal file
312
.agents/skills/agent-core-dev/config.md
Normal file
|
|
@ -0,0 +1,312 @@
|
||||||
|
# Topic — Config
|
||||||
|
|
||||||
|
How the `config` domain works and how a domain owns its configuration section. Covers the section-registry model, the App vs Session split, the TOML on-disk format, and the recipe for adding or migrating a config section.
|
||||||
|
|
||||||
|
The `config` domain is a thin registry + loader: it does **not** know the shape of any individual section. Each domain owns the schema (and, where needed, the TOML transform) for the config it consumes, contributes the section (statically at module load via `registerConfigSection`, or at runtime as a `ConfigSectionContribution` collection record), and reads it through `IConfigService`. There is no whole-config object passed around.
|
||||||
|
|
||||||
|
## What belongs in Config
|
||||||
|
|
||||||
|
`IConfigService` is the **preference registry**: it holds values a user or
|
||||||
|
operator *chooses*, each with a schema and a default, that *can* be persisted to
|
||||||
|
`config.toml`. It is not a grab-bag for every value a domain needs. Before
|
||||||
|
registering a section, classify the value along three axes — **decision-maker**,
|
||||||
|
**preference vs fact**, **mutability / persistence**:
|
||||||
|
|
||||||
|
| Type | Decision-maker | Preference/Fact | Persisted? | Examples | Home |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| User preference | user | preference | ✅ config.toml | model, theme, log level | **Config** |
|
||||||
|
| Operational override | operator/deployer | preference | ❌ env / flag | `KIMI_MODEL_*`, `KIMI_LOG_*` | **Config** (env overlay) |
|
||||||
|
| Per-run intent | invoker | preference | ❌ ephemeral | CLI `--model`, `--config` | **Config** (Memory layer) |
|
||||||
|
| Host fact | host | fact | ❌ | platform, CI, proxy, home dir | **Bootstrap** |
|
||||||
|
| Derived convention | code | fact (derived) | ❌ | `configPath`, `logsDir` | **Bootstrap / code** |
|
||||||
|
| Session runtime state | session/agent | state | ✅ session meta | active model, plan mode | **Session scope** |
|
||||||
|
| Tuning constant | developer | preference | ❌ compile-time | retry backoffs, buffer sizes | **code** |
|
||||||
|
|
||||||
|
A value belongs in Config **iff** it satisfies all of:
|
||||||
|
|
||||||
|
1. **Preference** — a choice among valid values, not an observed fact.
|
||||||
|
2. **Persistable** — it *can* be written to `config.toml`, even when a given
|
||||||
|
value arrives via env or CLI.
|
||||||
|
3. **Schema + default** — registerable as a section with validation.
|
||||||
|
4. **User- or operator-facing** — meaningful to set as a preference.
|
||||||
|
|
||||||
|
If it fails any rule, it is not Config:
|
||||||
|
|
||||||
|
- **Fact** (CI, platform, proxy, `HOME`) → a structured fact on
|
||||||
|
`IBootstrapService` (the startup snapshot), not Config.
|
||||||
|
- **Derived convention** (`configPath`, `logsDir`) → `IBootstrapService` / code.
|
||||||
|
- **Session runtime state** (active model, plan mode) → a Session-scoped
|
||||||
|
service in the owning domain (e.g. `IProfileService`), not `config`.
|
||||||
|
- **Tuning constant** (retry config, buffer sizes) → domain code; promote to
|
||||||
|
Config only when it becomes user-tunable.
|
||||||
|
|
||||||
|
**`IBootstrapService` is domain-agnostic.** It holds only generic facts shared by
|
||||||
|
all domains — the env bag, resolved paths, and host facts (`platform`, `arch`,
|
||||||
|
`cwd`, `osHomeDir`, `isCI`, …) — plus the host's process-level invocation
|
||||||
|
arguments in `args` (explicit `agentFiles` / `skillDirs`, `requestHeaders`,
|
||||||
|
prompt identity). `args` mirrors VS Code's `NativeParsedArgs` on the
|
||||||
|
environment service: the host states them once via `BootstrapInput.args` at
|
||||||
|
the composition root, and downstream services read them from
|
||||||
|
`IBootstrapService.args` instead of through per-domain runtime-options
|
||||||
|
services (do not add new `IXxxRuntimeOptions` services or seed functions for
|
||||||
|
host parameters). What must **never** land on `IBootstrapService` is state
|
||||||
|
tied to a specific upper domain (no `cron`, no `flags`, no feature-specific
|
||||||
|
fields): that couples the foundational layer to an upstream one.
|
||||||
|
|
||||||
|
Any value that belongs to a specific domain — including env-only operational
|
||||||
|
toggles (`KIMI_CRON_*`, `KIMI_CODE_EXPERIMENTAL_*`), model parameters, or feature
|
||||||
|
flags — goes through **Config registration**: the owning domain registers a
|
||||||
|
section with a declarative `envBindings` map (and a `stripEnv` when the value must
|
||||||
|
not be persisted) and reads it via `config.get(...)`. Each config value declares
|
||||||
|
an optional env binding (`{ field: 'ENV_VAR' }`, with optional `parse`/`default`);
|
||||||
|
IConfig resolves each field by `env > config.toml > default` automatically. This
|
||||||
|
keeps every domain's config in one registry and keeps Bootstrap free of upstream
|
||||||
|
knowledge.
|
||||||
|
|
||||||
|
Operational env overrides and per-run intent live *inside* Config as layers over
|
||||||
|
the same persistable key: `model` can be set in `config.toml`, via `KIMI_MODEL_*`,
|
||||||
|
or via CLI `--model`. They are not separate abstractions — see "Reads vs writes"
|
||||||
|
and "Layered resolution" below.
|
||||||
|
|
||||||
|
Env access is encapsulated: business domains read `config.get(...)` or structured
|
||||||
|
`IBootstrapService` facts; only the `config` domain reads the raw env bag (from
|
||||||
|
`IBootstrapService`) to build its overlays. Business domains must not call
|
||||||
|
`IBootstrapService.getEnv()` directly.
|
||||||
|
|
||||||
|
## Layered resolution
|
||||||
|
|
||||||
|
`IConfigService` resolves a key by precedence across layers, lowest to highest:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Default registered defaultValue (and code constants promoted to a section)
|
||||||
|
↓
|
||||||
|
User config.toml (persisted user preferences)
|
||||||
|
↓
|
||||||
|
Operational env overlay (e.g. KIMI_MODEL_*, KIMI_CODE_EXPERIMENTAL_*)
|
||||||
|
↓
|
||||||
|
Memory per-run intent (CLI flags); never persisted; highest
|
||||||
|
```
|
||||||
|
|
||||||
|
`set(domain, patch, target?)` writes the `User` layer (persisted) by default;
|
||||||
|
pass `ConfigTarget.Memory` for a per-run override that is never written to disk.
|
||||||
|
`inspect(domain)` reports the value at each layer.
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
- `src/app/config/config.ts` — `IConfigRegistry` / `IConfigService` tokens, `ConfigSection`, `ConfigEffectiveOverlay`, event types.
|
||||||
|
- `src/app/config/configService.ts` — `ConfigRegistry` + `ConfigService` impl; self-registers at App scope. The registry is also the fold of the `ConfigSectionContribution` collection: it drains the module-level contributions at construction, then refolds incrementally (`added` → `registerSection`, `removed` → `unregisterSection`).
|
||||||
|
- `src/app/config/configSectionContributions.ts` — the `ConfigSectionContribution` collection token (the runtime channel: a unit contributes with `this.provide(ConfigSectionContribution, …)`) plus the module-level `registerConfigSection` collector (the static channel, import = register).
|
||||||
|
- `src/app/config/configOverlayContributions.ts` — the module-level `registerConfigOverlay` collector for `ConfigEffectiveOverlay`s (drained at construction like the sections).
|
||||||
|
- `src/app/config/toml.ts` — generic snake_case ↔ camelCase machinery plus the registry-aware `transformTomlData` / `applySectionToToml` entry points. Per-domain normalization lives in the section owner's `configSection.ts` (registered as `fromToml` / `toToml`); this module stays free of any other domain's semantics.
|
||||||
|
- `src/kosong/model/thinking.ts` (owner domain, not `config`) — the `resolveThinkingEffort` helper and the authoritative `ThinkingConfig` type (the `thinking` section itself registers from `src/app/kosongConfig/configSection.ts`).
|
||||||
|
- `src/app/config/configPure.ts` — `isPlainObject`, `deepMerge`, `omitUndefined`, `describeUnknownError`.
|
||||||
|
|
||||||
|
A domain that owns a section keeps the schema in its own `configSection.ts` (e.g. `src/app/flag/flag.ts` for `experimental`, `src/agent/loop/configSection.ts` for `loopControl`). Exception: kosong-owned sections (`providers`, `models`, `thinking`) — kosong is a pure, persistence-free abstraction layer that defines only the types (`src/kosong/{provider,model}`); the section constants, the zod schemas (re-derived from those types and compile-time pinned via `AssertExact<Equal<z.infer<typeof Schema>, Type>>`, see `_base/utils/typeEquality.ts`), the registrations, env bindings, and TOML transforms all live in the persistence wrapper `src/app/kosongConfig/configSection.ts`. (`modelCatalog` has no kosong-side type at all — its section is fully self-contained in `app/kosongConfig`, types derived from the schema.) A cross-section env overlay (e.g. the `KIMI_MODEL_*` synthesis in `src/app/kosongConfig/envOverlay.ts`) lives in the wrapper too and is registered via module-level `registerConfigOverlay`. The session subagent domain owns two sections in `src/session/subagent/configSection.ts`: `[subagent]` (`timeout_ms` on disk) and `[secondary_model]` (`default_model` plus the `[secondary_model.models]` pool, with a lone legacy v1 `model` key honored as a fallback default below `default_model`); neither carries a cross-section overlay. Cross-field pool validation (default present / in-pool / every key resolvable) runs at session creation in `subagentModelsValidationService.ts`, not in the schema. The two-way sync between config sections and kosong's in-memory registries is owned by `IKosongConfigService` (`src/app/kosongConfig/kosongConfigService.ts`).
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
- `IConfigRegistry` / `IConfigService` — **App** scope, process-global. One registry of sections; one loader reading `~/.kimi-code/config.toml` (path from `IBootstrapService.configPath`).
|
||||||
|
|
||||||
|
All config reads go through `IConfigService` (global config). Per-session runtime state (active model, thinking level, etc.) lives in the owning Session-scoped service (e.g. `IProfileService`), not in `config`.
|
||||||
|
|
||||||
|
## The section-registry model
|
||||||
|
|
||||||
|
A config section is identified by a camelCase domain key (`'providers'`, `'thinking'`, `'loopControl'`). Each section has:
|
||||||
|
|
||||||
|
- `schema?: ConfigSchema<T>` — zod schema used to validate the value (absent ⇒ passthrough).
|
||||||
|
- `defaultValue?: T` — filled when the file has no value for the domain.
|
||||||
|
- `merge?: ConfigMerge<T>` — how `set(domain, patch)` combines base + patch (default `deepMerge`).
|
||||||
|
- `fromToml?: ConfigFromToml` — read-path transform (snake_case file value → in-memory shape). Defaults to a plain key-casing pass; owners register one when the on-disk shape needs custom normalization (record key preservation, nested object conversion, array entries, key renames, reshapes).
|
||||||
|
- `toToml?: ConfigToToml` — write-path transform (in-memory value → snake_case file value). Defaults to a plain camelCase→snake_case key mapping.
|
||||||
|
|
||||||
|
Two contribution channels:
|
||||||
|
|
||||||
|
- **Static (import = register)** — the owning domain calls `registerConfigSection(domain, schema, options)` at the top level of its `configSection.ts`; `ConfigRegistry` drains the collected contributions when it is constructed. Every in-repo section uses this channel.
|
||||||
|
- **Runtime (collection record)** — a unit contributes `this.provide(ConfigSectionContribution, { domain, schema, options })` (e.g. a feature assembled through `IFeatureManager`); the `ConfigRegistry` fold registers the section when the record lands and unregisters it when the record is withdrawn (provider disposed). User TOML values survive a withdrawal — they just stop being validated and effective.
|
||||||
|
|
||||||
|
Ownership rules:
|
||||||
|
|
||||||
|
- **One owner per section.** `registerSection` throws if a domain is registered twice — the static channel fails fast when `ConfigRegistry` drains it; a conflicting runtime record is reported through `onUnexpectedError` and the first registration wins (the fold is an event path and never throws).
|
||||||
|
- **The domain that consumes a config owns its schema.** This is what keeps `config` from depending on its consumers: `config` must not import `externalHooks` / `permissionRules` / `provider` / `kosong` / etc. for a section's schema. If a schema needs a domain's types, the schema lives in that domain.
|
||||||
|
- **Demand-driven.** Do not register sections for config that no domain reads yet; a section appears (with its schema in the owning domain) only when a consumer appears.
|
||||||
|
|
||||||
|
## Env bindings
|
||||||
|
|
||||||
|
A section can declare how its fields are read from environment variables, so the
|
||||||
|
value resolves through `config.get(...)` rather than ad-hoc `process.env` reads.
|
||||||
|
Declare the bindings with `envBindings(schema, { … })` — the field names are
|
||||||
|
type-checked against the schema (no magic strings), and nested schemas recurse:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
registerConfigSection('thinking', ThinkingConfigSchema, {
|
||||||
|
env: envBindings(ThinkingConfigSchema, {
|
||||||
|
effort: 'KIMI_MODEL_THINKING_EFFORT',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// nested / record section — outer key is a runtime constant, inner fields are
|
||||||
|
// checked against the value schema:
|
||||||
|
registerConfigSection('providers', ProvidersSectionSchema, {
|
||||||
|
env: envBindings(ProvidersSectionSchema, {
|
||||||
|
[ENV_MODEL_PROVIDER_KEY]: envBindings(ProviderConfigSchema, {
|
||||||
|
apiKey: 'KIMI_MODEL_API_KEY',
|
||||||
|
type: 'KIMI_MODEL_PROVIDER_TYPE',
|
||||||
|
baseUrl:'KIMI_MODEL_BASE_URL',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
stripEnv: stripProvidersEnv,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Each field is an `EnvBinding` — a string (env var name) or
|
||||||
|
`{ env, deprecatedEnv?, parse?, default? }`. IConfig resolves every field by
|
||||||
|
`env > config.toml > default`, sets it on the effective value, and validates the
|
||||||
|
section. Empty nested entries (no field resolved) are omitted, so a synthetic
|
||||||
|
entry like `__kimi_env__` only appears when at least one of its env vars is set.
|
||||||
|
When `deprecatedEnv` is set and `env` itself is absent or fails `parse`, the
|
||||||
|
deprecated var still supplies the value and a warning diagnostic is reported —
|
||||||
|
use it to rename an env var without breaking existing setups.
|
||||||
|
|
||||||
|
`stripEnv(value, raw?, getEnv?)` removes env-derived fields before `set`/`replace`
|
||||||
|
persists, so env overrides never leak into `config.toml`. `raw` is the section's
|
||||||
|
env-free camelCase base (already `fromToml`-normalized), and `getEnv` reads the
|
||||||
|
live env bag. For fields that are **both
|
||||||
|
user-persistable and env-overridable**, register
|
||||||
|
`stripEnv: stripEnvBoundFields(sectionEnvBindings)` (from `#/app/config/config`)
|
||||||
|
— it derives the guard from the same bindings the read path uses: while a
|
||||||
|
field's env var resolves to a value, writes restore the field's raw-base value
|
||||||
|
(or drop it) instead of persisting an echoed env value; an env value that
|
||||||
|
fails the binding's `parse` owns nothing, so writes pass through. Env-only
|
||||||
|
fields/sections need no env check — strip them unconditionally (e.g. thinking's
|
||||||
|
`forcedEffort`, cron's whole-section `() => undefined`).
|
||||||
|
|
||||||
|
Business domains read `config.get('section')`; they never read env directly, and
|
||||||
|
never write their own env-merge logic.
|
||||||
|
|
||||||
|
## Add a config section (recipe)
|
||||||
|
|
||||||
|
1. Define the schema in the owning domain, e.g. `src/<domain>/configSection.ts`:
|
||||||
|
```ts
|
||||||
|
export const MY_SECTION = 'mySection';
|
||||||
|
export const MySectionSchema = z.object({ /* ... */ });
|
||||||
|
export type MySection = z.infer<typeof MySectionSchema>;
|
||||||
|
```
|
||||||
|
2. Register it at the top level of the same module (import = register):
|
||||||
|
```ts
|
||||||
|
// src/<domain>/configSection.ts
|
||||||
|
import { registerConfigSection } from '#/app/config/configSectionContributions';
|
||||||
|
|
||||||
|
registerConfigSection(MY_SECTION, MySectionSchema, { defaultValue: {} });
|
||||||
|
```
|
||||||
|
`ConfigRegistry` drains module-level contributions when it is constructed, so the section exists before any consumer resolves `IConfigService` — no owning Service needs to be constructed first. Make sure `src/index.ts` imports the leaf so the top-level call runs.
|
||||||
|
3. (Runtime variant) a dynamically loaded unit (e.g. one assembled through `IFeatureManager`) contributes the section as a collection record instead:
|
||||||
|
```ts
|
||||||
|
this.provide(ConfigSectionContribution, { domain: MY_SECTION, schema: MySectionSchema, options: { defaultValue: {} } });
|
||||||
|
```
|
||||||
|
The `ConfigRegistry` fold registers it incrementally and unregisters it when the unit is retracted (user TOML values survive) — see "Late registration".
|
||||||
|
4. Read it anywhere via `IConfigService`:
|
||||||
|
```ts
|
||||||
|
constructor(@IConfigService private readonly config: IConfigService) {}
|
||||||
|
// ...
|
||||||
|
const value = this.config.get<MySection>(MY_SECTION);
|
||||||
|
```
|
||||||
|
5. React to edits by subscribing `IConfigService.onDidChange` and filtering on `e.domain === MY_SECTION` (see `FlagService`).
|
||||||
|
6. Write it only through `IConfigService.set(domain, patch)` (merge) or `.replace(domain, value)` (wholesale). Never write `config.toml` directly.
|
||||||
|
|
||||||
|
## Reads vs writes
|
||||||
|
|
||||||
|
Data flow is one-way by default — reading config never touches the file:
|
||||||
|
|
||||||
|
```text
|
||||||
|
config.toml ──load──▶ IConfigService.effective ──get──▶ services read
|
||||||
|
▲ │
|
||||||
|
└──────── IConfigService.set/replace ◀──── only on explicit writes
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Read path** (startup, every service): `config.toml` is loaded into `IConfigService` once; services read via `get()`. This path **never writes the file**.
|
||||||
|
- **Write path** (rare): `config.toml` is rewritten only when something explicitly calls `IConfigService.set/replace`. The only production writers today are provider CRUD (`ProviderService.set/delete`, e.g. provisioning a provider after OAuth login).
|
||||||
|
|
||||||
|
**Runtime service state is not config.** Mutating a service at runtime does **not** rewrite `config.toml`:
|
||||||
|
|
||||||
|
- `ProfileService.configure(...)` / `update(...)` / `setModel(...)` / `setThinking(...)` only change **in-memory** fields and append to the session **wireRecord** (for replay). They never call `IConfigService.set`.
|
||||||
|
- Switching model or thinking level mid-session is session runtime state, not a config edit — the user's `config.toml` is left untouched.
|
||||||
|
|
||||||
|
So `configure(...)` never overwrites the local file. Treat `config.toml` as the user's static config; runtime overrides live in memory and the session record.
|
||||||
|
|
||||||
|
## Late registration
|
||||||
|
|
||||||
|
`ConfigService` loads in its constructor (first `get(IConfigService)`). Static sections are drained before that, but a runtime-contributed section (a `ConfigSectionContribution` record) can register at any later moment. To keep validation and defaults correct:
|
||||||
|
|
||||||
|
- `IConfigRegistry` emits `onDidRegisterSection` whenever a section is registered (and `onDidUnregisterSection` when a runtime record is withdrawn).
|
||||||
|
- `ConfigService` subscribes and, on registration, re-validates the already-loaded raw value for that domain, applies the default if the raw value is absent, re-runs the env overlay, and fires `onDidChange` if the effective value changed. On unregistration it devalidates the domain — `get(domain)` falls back to the raw value.
|
||||||
|
- Before a section is registered, `get(domain)` returns the raw (transformed, unvalidated) value; consumers that need validated values should read after the section lands, or react to `onDidChange`.
|
||||||
|
|
||||||
|
This means registration order is never a correctness concern — you do not need an eager bootstrap.
|
||||||
|
|
||||||
|
## TOML on-disk format
|
||||||
|
|
||||||
|
`config.toml` stores keys in **snake_case**; in-memory values are **camelCase**. `ConfigService` converts both ways by dispatching to each section's registered transform:
|
||||||
|
|
||||||
|
- **Read**: `transformTomlData(fileData, registry)` maps each top-level key to a domain and applies that domain's `fromToml` hook (or a plain key-casing pass when none is registered). Owner domains register their own normalization — e.g. provider `oauth`/`env`/`customHeaders`, permission `deny/allow/ask` → `rules`, `experimental` keys preserved verbatim. When a section registers after the initial load, `ConfigService` re-applies its `fromToml` against the preserved snake_case raw value (see "Late registration"), so registration order is never a correctness concern.
|
||||||
|
- **Write**: `applySectionToToml(rawSnake, domain, value, registry)` applies the domain's `toToml` hook (or a plain camelCase→snake_case mapping) into a raw clone of the file, preserving unknown top-level keys and unknown sub-fields (lossless round-trip).
|
||||||
|
|
||||||
|
`ConfigService` keeps four views:
|
||||||
|
|
||||||
|
- `rawSnake` — snake_case clone of the file; the write base, never carries the env overlay.
|
||||||
|
- `raw` — camelCase, env-free; the read/set/replace base.
|
||||||
|
- `validated` — validated `raw`, env-free; the base every live env re-application starts from, so a degraded or removed env value falls back to the file instead of a stale overlay.
|
||||||
|
- `effective` — `validated` plus the env overlay, recomputed on load/set; `get()`/`getAll()` re-apply the overlay on a fresh `validated` copy per read rather than caching it.
|
||||||
|
|
||||||
|
### Renaming config keys and env vars (deprecations)
|
||||||
|
|
||||||
|
Renames are declared once on the section, never hand-rolled in `fromToml`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
registerSection(MY_SECTION, MySectionSchema, {
|
||||||
|
deprecations: [{ key: 'old_key', replacement: 'new_key' }], // snake_case, on-disk
|
||||||
|
env: envBindings(MySectionSchema, {
|
||||||
|
newKey: { env: 'KIMI_NEW_KEY', deprecatedEnv: 'KIMI_OLD_KEY', parse },
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- A deprecated TOML key is **ignored** (its value no longer applies — the schema only knows the new key) and reports a warning `ConfigDiagnostic` while present; the file is never rewritten, so the warning is the migration guide. Diagnostics are recomputed on every load/reload and surface to clients via `IConfigService.diagnostics()` and `onDidChangeDiagnostics` (kap-server republishes them as the global `event.config.warning` WS event).
|
||||||
|
- A deprecated env var still **resolves** as a fallback (new var first), with the same warning treatment, and `stripEnvBoundFields` treats it as env-owned for writes.
|
||||||
|
- See `src/agent/loop/configSection.ts` for a worked example (`max_retries_per_step` → `max_attempts_per_step`).
|
||||||
|
|
||||||
|
### `KIMI_MODEL_*` env overlay
|
||||||
|
|
||||||
|
When `KIMI_MODEL_NAME` is set, the `kosongConfig` wrapper's `kimiModelEnvOverlay` (`src/app/kosongConfig/envOverlay.ts`) injects a reserved model alias (`__kimi_env_model__`) into `effective`, points `defaultModel` at it, and merges the request `modelOverrides`; the reserved provider (`__kimi_env__`) comes from the `providers` section env bindings. The overlay is registered via module-level `registerConfigOverlay` and applied **only to `effective`**, never to `rawSnake`, so it is never persisted. Its `strip` (plus the providers section `stripEnv`) is the final guard so a caller that read `effective` (with the overlay) cannot write the reserved entries or the shell API key back to disk. `config` itself only runs registered overlays — it does not know the `KIMI_MODEL_*` semantics.
|
||||||
|
|
||||||
|
## Owner-owned sections
|
||||||
|
|
||||||
|
`config` holds no monolithic config schema and no whole-config object. Every section is owned by the domain that consumes it: the schema (and any `fromToml` / `toToml` normalization and `stripEnv`) lives in that domain's `configSection.ts`, and the domain contributes it via module-level `registerConfigSection` (or a runtime `ConfigSectionContribution` record). Cross-section env behavior (e.g. `KIMI_MODEL_*`) lives in an owner-registered `ConfigEffectiveOverlay` (module-level `registerConfigOverlay`). To add a section, follow "Add a config section" above in the owning domain — never add schema or normalization to `config` itself.
|
||||||
|
|
||||||
|
## Ownership map (generated)
|
||||||
|
|
||||||
|
The authoritative, always-current list of registered sections — rendered in the on-disk `config.toml` shape, with owner file, scope, defaults, env bindings, and schema fields — is generated from the live registry:
|
||||||
|
|
||||||
|
- `packages/agent-core-v2/docs/config-manifest.toml` (checked in; do not edit by hand).
|
||||||
|
- Regenerate with `pnpm --filter @moonshot-ai/agent-core-v2 gen:config-manifest` (add `--check` for a freshness check; `test/app/config/configManifest.test.ts` enforces it in CI).
|
||||||
|
|
||||||
|
`config` must not import from any of these owner domains; that is the whole reason the schemas, TOML normalization, and env overlays live with their owners.
|
||||||
|
|
||||||
|
## Scope & dependencies
|
||||||
|
|
||||||
|
- `config` is a low-level capability: domains that own sections import `config` (for `IConfigRegistry` / `IConfigService`), never the reverse — section schemas live in the owning domain.
|
||||||
|
- Cross-domain type sharing for a config type: prefer importing the type from the owning domain over re-declaring it (e.g. `plugin` imports `McpServerConfig` from the MCP config schema).
|
||||||
|
- `IConfigRegistry` / `IConfigService` are **App**. Agent scope services may inject App services via ancestor lookup.
|
||||||
|
- `config` never imports a higher domain and holds no section schemas of its own; if a section needs a type from another domain, that schema lives in that domain.
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- One owner per section: a duplicate static registration throws when `ConfigRegistry` drains it; a conflicting runtime record is logged (`onUnexpectedError`) and the first registration wins.
|
||||||
|
- `config` never imports the domains that consume it — keep section schemas in the owning domain.
|
||||||
|
- Config is the **preference registry**: register only values that are preferences, persistable, schema'd, and user/operator-facing. Facts → `IBootstrapService`; session state → Session scope; constants → code.
|
||||||
|
- Business domains read `config.get(...)` or structured `IBootstrapService` facts; never call `IBootstrapService.getEnv()` directly — only `config` reads the raw env bag to build overlays.
|
||||||
|
- Keep `IBootstrapService` domain-agnostic: host invocation arguments (CLI flags, host identity headers, prompt identity) go into `BootstrapInput.args` / `IBootstrapService.args` — never into new per-domain runtime-options services; domain runtime state (cron, flags, model params, …) never goes onto `IBootstrapService` at all. Domain-specific config goes through `registerConfigSection` + `envBindings`, read via `config.get(...)`.
|
||||||
|
- Do not pass a whole config bag via options; read each section through `IConfigService`. There is no `KimiConfig` object — config is a registry of owner-owned sections.
|
||||||
|
- `config.toml` is snake_case on disk, camelCase in memory — never write camelCase keys to disk, and never write to `config.toml` except through `IConfigService.set/replace`.
|
||||||
|
- Reading config / calling `configure(...)` / switching model at runtime must not rewrite `config.toml`; runtime state lives in memory and the session wireRecord, not the file.
|
||||||
|
- Never persist env overlays (`__kimi_env__` / `__kimi_env_model__` / shell API key / experimental env); overlays live only in `effective` / `Memory`.
|
||||||
|
- Runtime contribution (a `ConfigSectionContribution` record from a unit at any scope) is fine — the late-registration mechanism keeps validation correct; the static channel needs no eager bootstrap (import = register, drained at `ConfigRegistry` construction).
|
||||||
289
.agents/skills/agent-core-dev/design.md
Normal file
289
.agents/skills/agent-core-dev/design.md
Normal file
|
|
@ -0,0 +1,289 @@
|
||||||
|
# Stage 2 — Design a service
|
||||||
|
|
||||||
|
Decide *where things live and who knows whom* before writing code. Every rule here derives from two questions:
|
||||||
|
|
||||||
|
1. **What is the identity of the state it owns?** → decides the **Scope**.
|
||||||
|
2. **Who owns the decision, and who needs the result?** → decides the **calling style** and **dependency direction**.
|
||||||
|
|
||||||
|
## 1. What a Service is
|
||||||
|
|
||||||
|
A Service = a bundle of **state** + a set of **behaviors**, bound to a **lifetime**.
|
||||||
|
|
||||||
|
- **Behavior** is almost free — the same logic runs anywhere, so it does not by itself decide a scope.
|
||||||
|
- **State** pins a Service to a scope. State has an **identity** (what it is keyed by) and a **lifetime** (when it is born, when it dies).
|
||||||
|
- **Dependencies / calling style** answer a different question: who controls whom, and who knows whom.
|
||||||
|
|
||||||
|
## 2. Choosing a scope
|
||||||
|
|
||||||
|
> Scope = the identity + lifetime of the owned state.
|
||||||
|
|
||||||
|
| Scope | State identity (keyed by) | Lifetime |
|
||||||
|
|---|---|---|
|
||||||
|
| `App` | none (single global instance) | the process |
|
||||||
|
| `Workspace` | `workspaceId` | one workspace handler (materialized once per workspace, never closed — dies with the process) |
|
||||||
|
| `Session` | `sessionId` | one session |
|
||||||
|
| `Agent` | `agentId` | one agent |
|
||||||
|
|
||||||
|
### Decision tree
|
||||||
|
|
||||||
|
**Q1. Does it own mutable state?**
|
||||||
|
|
||||||
|
- No (pure behavior) → jump to Q3.
|
||||||
|
- Yes → Q2.
|
||||||
|
|
||||||
|
**Q2. What is the identity of that state?**
|
||||||
|
|
||||||
|
- one global instance → **`App`**
|
||||||
|
- one per workspace (shared by every session of that workspace) → **`Workspace`**
|
||||||
|
- one per session → **`Session`**
|
||||||
|
- one per agent → **`Agent`**
|
||||||
|
- a mix (a global registry *and* per-instance state) → **split it** (see §3).
|
||||||
|
|
||||||
|
**Q3 (stateless). What is the shortest-lived dependency it must inject?**
|
||||||
|
|
||||||
|
A stateless Service is pulled *down* by its shortest-lived dependency: if it injects an `Agent`-scoped Service, it cannot be `App`. Among the scopes that still satisfy every dependency, **default to the longest-lived one** (usually `App`) to maximize reuse. Push it down only when it must inject a shorter-lived Service, or when you want to limit its visibility.
|
||||||
|
|
||||||
|
### The core anti-pattern (a litmus test)
|
||||||
|
|
||||||
|
> **Do not store per-session state in a `Map<sessionId, …>` inside an `App` Service.**
|
||||||
|
|
||||||
|
This is the tell-tale sign of "should have been `Session`-scoped but was parked at `App`". Consequences: nobody cleans the entry up when the session ends (leak); every consumer threads `sessionId` around (loss of type safety); it cannot inject `Session`/`Agent`-scoped collaborators.
|
||||||
|
|
||||||
|
### One-sentence self-check
|
||||||
|
|
||||||
|
> "When this scope is disposed, should this state disappear with it?"
|
||||||
|
>
|
||||||
|
> - Yes → the scope is right.
|
||||||
|
> - It must outlive the scope → too short; move up one tier.
|
||||||
|
> - It should be one-per-unit but is shared → too long; move down one tier.
|
||||||
|
|
||||||
|
## Scope is not a domain
|
||||||
|
|
||||||
|
Scope answers **lifetime and visibility**. Domain answers **responsibility and data ownership**. A Service registered at `Session` or `Agent` scope is not automatically part of the `session` or `agent` domain, and an entity Service must not be named `I{Scope}EntityService` just because its data is scoped that way.
|
||||||
|
|
||||||
|
Use the data-ownership test and the `session` / `agent` / `turn` split conclusions in [domain-boundaries.md](domain-boundaries.md) before naming a Service or adding `I{Domain}EntityService`.
|
||||||
|
|
||||||
|
## 3. Multi-Scope splitting
|
||||||
|
|
||||||
|
> One Service owns state at exactly one identity / lifetime. If a domain owns state at several lifetimes, split it along those boundaries — one Service per lifetime.
|
||||||
|
|
||||||
|
The standard split is "global registry / factory" + "per-instance":
|
||||||
|
|
||||||
|
| Tier | Role | Naming tends to |
|
||||||
|
|---|---|---|
|
||||||
|
| `App` | global registry / catalog / factory — knows "all of them" and how to create one | `XxxStore` / `XxxRegistry` / `XxxCatalog` |
|
||||||
|
| `Workspace` / `Session` / `Agent` | one instance — only the state of "this one" | `XxxService` / `IWorkspaceXxx` / `ISessionXxx` / `IAgentXxx` |
|
||||||
|
|
||||||
|
Canonical splits in the codebase:
|
||||||
|
|
||||||
|
- **`records`** — `ISessionStore` (`App`) + `ISessionMetaStore` (`Session`) + `IAgentRecords` (`Agent`).
|
||||||
|
- **`config`** — `IConfigRegistry` / `IConfigService` (`App`).
|
||||||
|
- **`kosong`** — `IProtocolHandlerRegistry` (`App`) + `IProviderManager` (`Session`). Generation is driven by `ILLMRequester` (`Agent`) in the `llmRequester` domain.
|
||||||
|
- **`tool`** — `IToolDefinitionRegistry` (`App`) + `IToolService` (`Agent`).
|
||||||
|
|
||||||
|
Split when the domain genuinely has both a global view and per-instance state. Do **not** split when state lives at only one lifetime (e.g. purely `App` like `log`; purely `Agent` like `prompt`). Do not pre-split for symmetry.
|
||||||
|
|
||||||
|
After the split, the `App` Service usually plays the **factory**; most consumers inject the **per-instance** Service. Inject the `App` factory only when you genuinely need cross-instance management.
|
||||||
|
|
||||||
|
## 4. Choosing a calling style
|
||||||
|
|
||||||
|
Three mechanisms answer three different questions:
|
||||||
|
|
||||||
|
| Mechanism | Nature | Coupling | Returns a value? | Consumers |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| **Direct call** | command: A tells B to do | A → B | yes | one (known) |
|
||||||
|
| **Event** | fact: A announces "X happened" | both depend only on the bus | no | zero / one / many (unknown) |
|
||||||
|
| **Hook** (`onWill` / `onDid`, `OrderedHookSlot`) | participation: observers step into an operation, in order | both depend only on the bus | can observe / veto | many, but ordered |
|
||||||
|
|
||||||
|
### Decision tree
|
||||||
|
|
||||||
|
**Q1. Does A need a return value from B?** → Yes: **direct call**. Events cannot return a value (request/reply over events is an anti-pattern).
|
||||||
|
|
||||||
|
**Q2. Is B's reaction part of A's responsibility, or B's own concern?**
|
||||||
|
|
||||||
|
- A's responsibility *includes* B's behavior (A orchestrates B) → **direct call**. E.g. `session` drives `agentLifecycle`; `loop` drives `llmRequester` / `toolExecutor`.
|
||||||
|
- B's reaction is B's own concern, A merely states a fact → **event**. E.g. `flag` reacts to `config.onDidChange`.
|
||||||
|
|
||||||
|
**Q3. How many consumers?**
|
||||||
|
|
||||||
|
- exactly one, known → **direct call**.
|
||||||
|
- zero / one / many, producer should not know → **event**.
|
||||||
|
|
||||||
|
**Q4. Would a direct A→B call create a cycle or violate scope direction?** → A *consequence check*, not a primary reason. Decide by Q1–Q3 first; do not turn a genuine direct call into an event just to break a cycle.
|
||||||
|
|
||||||
|
**Q5. Is this fact part of the durable record / replay / cross-agent projection?** → Yes: **emit it on the wire** (`wireRecord`). State changes that must be recorded, replayed, or synchronized across agents are projected onto the wire, not handled by a direct call alone (`permission.set_mode`, `goal.create/update/clear`, `plan_mode.enter/exit`). The wire is the *durable record*, not the live notification channel.
|
||||||
|
|
||||||
|
### One-sentence rule
|
||||||
|
|
||||||
|
> "I am telling you to do this, and I may need the result" → **direct call.**
|
||||||
|
> "I am announcing that something happened; react if you care" → **event.**
|
||||||
|
> "I am announcing something, and you may step in, in order, possibly to veto" → **hook.**
|
||||||
|
|
||||||
|
### As extension points (open-closed)
|
||||||
|
|
||||||
|
The three mechanisms above are also where a domain accepts new behavior without being edited. When adding a scenario would otherwise require changing this domain's `if/else`, expose the right extension point instead:
|
||||||
|
|
||||||
|
| Need | Extension point | Typical scope |
|
||||||
|
|---|---|---|
|
||||||
|
| Register a new implementation / definition | a **registry / catalog** the domain queries | `App` |
|
||||||
|
| React to a fact the domain announces | an **event** on the bus | the announcing scope |
|
||||||
|
| Step into an operation in order / veto | a **hook** (`onWill`/`onDid`, `OrderedHookSlot`) | the owning scope |
|
||||||
|
| Swap a backend (File ↔ DB ↔ S3) | a **Store / Storage token** at the byte layer (see persistence.md) | `App` (composition root) |
|
||||||
|
|
||||||
|
The standard shape of a "registry / catalog the domain queries" row is an L3 contribution point: the target domain owns a `collection<T>` token, contributors call `this.provide(token, record)` from a unit, and a fold service in the target domain injects the `CollectionView` (incremental `onDidChange`; provider death withdraws the record). The four in-repo seams are `ConfigSectionContribution` → `ConfigRegistry`, `AgentToolContribution` → `AgentToolActivationService`, `AgentProfileContribution` → `IAgentProfileRegistry`, and `WireModelContribution` → `WireService` (file-level pointers: `packages/agent-core-v2/AGENTS.md` §Units and contribution points).
|
||||||
|
|
||||||
|
Closed-for-modification means: the domain's own file is not where new scenarios branch. If a new scenario forces an edit here, an extension point is missing or misplaced.
|
||||||
|
|
||||||
|
## 5. Dependency direction
|
||||||
|
|
||||||
|
Two layers are involved:
|
||||||
|
|
||||||
|
- **Scope direction**: short-lived → long-lived, **enforced by the container** (see orient.md).
|
||||||
|
- **Domain direction**: which domain may depend on which — **a matter of judgment**, not enforced by the container.
|
||||||
|
|
||||||
|
> **A depends on B iff A needs B's data or behavior to do its own job.**
|
||||||
|
|
||||||
|
Add one anti-rot heuristic to keep the graph from collapsing into a clique:
|
||||||
|
|
||||||
|
> **Do not let a more foundational / more-reused Service come to know a more specific / more-upstream one.**
|
||||||
|
|
||||||
|
Once a foundational component knows about an upstream scenario, it can no longer be reused by other scenarios and will almost always create a cycle.
|
||||||
|
|
||||||
|
### The boundaries of this repo
|
||||||
|
|
||||||
|
`agent-core-v2` has no mechanical domain-layer numbering — dependency direction is the judgment rule above, applied per domain. What remains enforceable is a small set of specific boundaries (`lint:imports`, `scripts/check-import-boundaries.mjs`):
|
||||||
|
|
||||||
|
- v2 never imports v1 (`@moonshot-ai/agent-core`).
|
||||||
|
- The kosong subtree keeps its strict internal order (`contract ← protocol ← provider/model`, purity bans, the `provider/bases` registration boundary).
|
||||||
|
|
||||||
|
Two standing red lines on top of that:
|
||||||
|
|
||||||
|
- The **base substrate** (`_base`, errors, wire types) never depends on any business domain.
|
||||||
|
- Business logic never depends on the **edge** (`gateway`, `rpc`, the `*Legacy` v1 adapters) — business code should not know REST / WebSocket exist.
|
||||||
|
- A cycle means knowledge was placed backwards: extract a third, more foundational Service, or invert the "notification" half into an event.
|
||||||
|
|
||||||
|
> Capability → orchestrator (e.g. `prompt → turn`) is allowed and present in this repo; the real red line is *inverted reuse* — a foundational / lower Service depending on a specific / upper one.
|
||||||
|
|
||||||
|
> When a Service is meant to be reached over the wire (`/api/v2`, WS), see [edge-exposure.md](edge-exposure.md) for the per-scope `resource:action` map, which Services may be exposed directly vs wrapped in a facade, and how events stream.
|
||||||
|
|
||||||
|
## 6. New-Service checklist
|
||||||
|
|
||||||
|
1. **What does it remember, and what is the state's identity?** → pick the scope (§2).
|
||||||
|
2. **What is the shortest-lived dependency it must inject?** → the scope cannot be longer than that.
|
||||||
|
3. **Does it own state at both a global and a per-instance lifetime?** → if yes, split Multi-Scope (§3).
|
||||||
|
4. **For each collaborator: am I commanding it, notifying it, or letting it participate?** → pick the calling style (§4).
|
||||||
|
5. **Does each dependency arrow make a more foundational thing know a more specific thing?** → if yes, invert it (§5).
|
||||||
|
|
||||||
|
## 7. Render the placement tree
|
||||||
|
|
||||||
|
After the checklist, render the result as a plaintext tree — the deliverable reviewers read. Keep it in the design doc or PR description.
|
||||||
|
|
||||||
|
```text
|
||||||
|
domain: `<name>` (owning scope: <Scope>)
|
||||||
|
├─ serves (who uses me) tag = HOW they reach me
|
||||||
|
│ ├─ (inject) <ConsumerDomain> @<Scope> — <what they use me for>
|
||||||
|
│ └─ (accessor) <ConsumerDomain> @<Scope> — <what they use me for>
|
||||||
|
├─ exposes (interfaces I provide, by scope)
|
||||||
|
│ ├─ App : <IXxxRegistry> — <role>
|
||||||
|
│ ├─ Workspace : <IWorkspaceXxx> — <role>
|
||||||
|
│ ├─ Session : <ISessionXxx> — <role>
|
||||||
|
│ └─ Agent : <IAgentXxx> — <role>
|
||||||
|
└─ depends (what I inject) tag = calling style
|
||||||
|
└─ <DepDomain> @<Scope> direct/event/hook — <what for>
|
||||||
|
```
|
||||||
|
|
||||||
|
Conventions:
|
||||||
|
|
||||||
|
- List **only real interfaces**; write `—` for a scope with no exposed interface. Most domains are single-scope — do not invent symmetry.
|
||||||
|
- On `depends`, tag each arrow with its calling style: `direct`, `event`, or `hook`.
|
||||||
|
- On `serves`, tag each consumer with its **access mechanism**, grouped `inject` first then `accessor`:
|
||||||
|
- `inject` — a descendant or peer scope DI-injects me. Resolved by the container; lifetime-safe.
|
||||||
|
- `accessor` — an ancestor or edge scope borrows me through `IScopeHandle.accessor.get(...)`. Valid only while this scope lives; never cache the result; must run before the child scope is disposed. See the cross-scope borrow diagram below.
|
||||||
|
- An empty `(inject)` group with a non-empty `(accessor)` group is a signal: the interface is currently an edge / lifecycle command surface — check it is not leaking internals.
|
||||||
|
- A consumer is upstream of you. If you cannot name one business consumer, the domain may be dead or mis-scoped.
|
||||||
|
|
||||||
|
### Cross-scope borrow diagram
|
||||||
|
|
||||||
|
When a domain has `accessor` consumers, draw the reverse-direction borrow next to the tree so it is never mistaken for injection:
|
||||||
|
|
||||||
|
```text
|
||||||
|
App scope
|
||||||
|
<AncestorService> ──holds──► IScopeHandle(<id>)
|
||||||
|
│
|
||||||
|
│ accessor.get(<IMyService>)
|
||||||
|
│ └── resolve runs inside the child scope
|
||||||
|
▼
|
||||||
|
<Child> scope (<id>)
|
||||||
|
<MyService> ← the interface lives here
|
||||||
|
```
|
||||||
|
|
||||||
|
Read it as:
|
||||||
|
|
||||||
|
- `──holds──►` = the ancestor owns a handle to the child scope (it stores the key, not the service). DI allows this.
|
||||||
|
- `accessor.get(...)` = a **runtime borrow**, not a dependency edge. It must cross an `IScopeHandle`, run on demand, never be cached, and finish before the child scope is disposed.
|
||||||
|
|
||||||
|
Worked example — `sessionLifecycle`:
|
||||||
|
|
||||||
|
```text
|
||||||
|
domain: `sessionLifecycle` (owning scope: Workspace)
|
||||||
|
├─ serves (who uses me)
|
||||||
|
│ ├─ (inject) — (none)
|
||||||
|
│ └─ (accessor)
|
||||||
|
│ ├─ sessionLegacy @App(edge) — v1-compatible create/fork/archive/…
|
||||||
|
│ └─ gateway / rpc @App(edge) — native v2 session lifecycle actions
|
||||||
|
├─ exposes (interfaces I provide, by scope)
|
||||||
|
│ ├─ Workspace : ISessionLifecycleService — owns this workspace's live session scope tree
|
||||||
|
│ ├─ Session : — — (per-session state lives in sessionMetadata / agentLifecycle / …)
|
||||||
|
│ └─ Agent : — — (per-agent state lives in agentLifecycle)
|
||||||
|
└─ depends (what I inject)
|
||||||
|
├─ workspaceContext @Workspace seed — handler identity + persistence scope
|
||||||
|
├─ bootstrap @App direct — addresses session storage
|
||||||
|
├─ hostEnvironment @App direct — gates scope creation on the probe
|
||||||
|
├─ sessionIndex @App direct — persisted read model for cold resumes
|
||||||
|
├─ storage @App direct — atomic docs + append logs
|
||||||
|
├─ workspaceDirs / workspaceSkillCatalog / workspaceMcp / …
|
||||||
|
│ @Workspace direct — the handler's shared resource services
|
||||||
|
└─ event @App direct — broadcasts session-level facts (e.g. archived)
|
||||||
|
```
|
||||||
|
|
||||||
|
Cross-scope borrow for `sessionLifecycle`:
|
||||||
|
|
||||||
|
```text
|
||||||
|
App scope
|
||||||
|
WorkspaceLifecycleService ──holds──► IScopeHandle(workspaceId) (one per live handler)
|
||||||
|
│
|
||||||
|
│ accessor.get(ISessionLifecycleService)
|
||||||
|
│ └── resolve runs inside the Workspace scope
|
||||||
|
▼
|
||||||
|
Workspace scope (workspaceId)
|
||||||
|
SessionLifecycleService ──holds──► IScopeHandle(sessionId)
|
||||||
|
│
|
||||||
|
│ accessor.get(ISessionMetadata) …
|
||||||
|
│ └── resolve runs inside the Session scope
|
||||||
|
▼
|
||||||
|
Session scope (sessionId)
|
||||||
|
sessionMetadata / agentLifecycle / … ← per-session services live here
|
||||||
|
```
|
||||||
|
|
||||||
|
How the three lenses shaped it:
|
||||||
|
|
||||||
|
- **Scope (§2)** → the live registry of one workspace's session scopes is per-handler, so it is Workspace-scoped; the process-wide handler registry lives in the App-scoped `workspaceLifecycle`; per-session data stays in Session-scoped services, reached through the handle's `accessor`.
|
||||||
|
- **Dependency direction (§5)** → `sessionLifecycle` is consumed by the edge via `accessor` borrows; it never imports the edge. Every downward arrow lands on a peer or a more foundational Service.
|
||||||
|
- **Extension points (§4)** → new per-session behavior plugs into the Session-scoped services (`sessionMetadata`, `agentLifecycle`, `sessionActivity`); new transports stay at the edge. Neither edits `sessionLifecycle`.
|
||||||
|
|
||||||
|
For a multi-scope split, the `exposes` block fills more than one scope — see the `records` pattern in §3.
|
||||||
|
|
||||||
|
## Red lines (this stage)
|
||||||
|
|
||||||
|
- Scope is not a domain; ownership follows write authority and invariants, not read consumption.
|
||||||
|
- Do not create `I{Scope}EntityService` bundles (`IAgentEntityService`, `ISessionEntityService`) that re-merge multiple domains.
|
||||||
|
- No `Map<sessionId, …>` at `App` to fake per-session state.
|
||||||
|
- Scope follows state identity; stateless Services are pulled down by their shortest-lived dependency, otherwise default to `App`.
|
||||||
|
- Do not pre-split a domain that has state at only one lifetime.
|
||||||
|
- Need a result / I orchestrate → direct call; stating a fact → event; ordered participation / may veto → hook.
|
||||||
|
- Foundational layers never know upstream ones; business code never depends on the edge layer.
|
||||||
|
- A cycle means knowledge is placed backwards — refactor, do not route around it.
|
||||||
|
- Render the placement tree with real interfaces only — never pad an empty scope for symmetry.
|
||||||
|
- Tag `serves` consumers with `inject` / `accessor`; an empty `inject` group is a signal to check the interface is not leaking internals.
|
||||||
|
- An `accessor` consumer is a runtime borrow across a scope boundary, not DI injection — never cache the result and finish before the child scope disposes.
|
||||||
|
- A `serves` list with no business consumer (or only edge consumers) signals a dead or leaking interface.
|
||||||
203
.agents/skills/agent-core-dev/domain-boundaries.md
Normal file
203
.agents/skills/agent-core-dev/domain-boundaries.md
Normal file
|
|
@ -0,0 +1,203 @@
|
||||||
|
# Topic — Domain boundaries vs Scope
|
||||||
|
|
||||||
|
How to keep `agent-core-v2` from recreating a god object after splitting one. Read this before naming a Service, adding an `I{Domain}EntityService`, or deciding whether data belongs to `session`, `agent`, or `turn`.
|
||||||
|
|
||||||
|
## The one-sentence rule
|
||||||
|
|
||||||
|
> **Scope is a lifetime and visibility boundary; a domain is a responsibility and data-ownership boundary.**
|
||||||
|
|
||||||
|
A Service registered at `LifecycleScope.Session` or `LifecycleScope.Agent` is **not automatically in the `session` or `agent` domain**. Scope says when an instance is born, when it dies, and who can see it. Domain says which business responsibility it owns and which data it is allowed to mutate.
|
||||||
|
|
||||||
|
## Definitions
|
||||||
|
|
||||||
|
| Term | Meaning |
|
||||||
|
|---|---|
|
||||||
|
| **Scope** | Lifetime / visibility tier. Current code registers Services at `App`, `Session`, or `Agent`. |
|
||||||
|
| **Domain** | A cohesive business responsibility with its own model, invariants, and write authority. |
|
||||||
|
| **Entity** | Data with identity and lifecycle, usually suitable for `get/list/create/update/delete` semantics. |
|
||||||
|
| **Aggregate** | A consistency boundary: the owner that enforces invariants over a cluster of data. |
|
||||||
|
| **Read model / projection** | Derived data built for queries; it may be shaped like a domain, but it is not the write authority. |
|
||||||
|
| **Runtime state** | Ephemeral data that dies with its scope; it should not be forced into an entity store. |
|
||||||
|
|
||||||
|
## The data-ownership test
|
||||||
|
|
||||||
|
Do not ask "does Session / Agent / Turn use this data?". Most data is used by several of them. Ask these instead:
|
||||||
|
|
||||||
|
1. **What is the data's identity?** `sessionId`, `agentId`, `turnId`, `taskId`, `workspaceId`, `providerName`, or something else?
|
||||||
|
2. **Who is the only writer?** The writer is usually the owner. Readers and projectors are not owners.
|
||||||
|
3. **Who enforces the invariants?** The domain that decides valid transitions owns the model.
|
||||||
|
4. **What is the authoritative source?** Atomic document, append-log / event stream, blob, query projection, config, or runtime memory?
|
||||||
|
5. **Can it be named without `Session` / `Agent` / `Turn`?** If yes, it probably deserves its own domain.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
- `PermissionRules` are Agent-scoped, but `permission` owns rule changes and evaluation.
|
||||||
|
- `BackgroundTask` is spawned by an Agent, but `background` owns task state and output.
|
||||||
|
- `ContextMessage` is consumed by the Agent loop, but `contextMemory` / `wireRecord` owns history and replay.
|
||||||
|
- `SessionMeta` is about a Session, but it is owned by `sessionMetadata`, not by a broad `session` data bag.
|
||||||
|
|
||||||
|
## Persistence models are not all entity CRUD
|
||||||
|
|
||||||
|
Before introducing `I{Domain}EntityService`, classify the persistence model:
|
||||||
|
|
||||||
|
| Persistence model | Use when | Examples |
|
||||||
|
|---|---|---|
|
||||||
|
| **Atomic document** | One typed document per key | `SessionMeta`, `config.toml` |
|
||||||
|
| **Append-log / event-sourced** | The authoritative record is "what happened" | `wireRecord`, `contextMemory`, `goal`, `plan`, `permission` transitions |
|
||||||
|
| **Blob / key-value** | Large or content-addressed bytes | media offload, blob store |
|
||||||
|
| **Indexed query / read model** | Derived, queryable view | `sessionIndex`, future `IQueryStore` projections |
|
||||||
|
| **Registry / catalog** | Global or scoped known items | `workspace`, `toolRegistry` |
|
||||||
|
| **Ephemeral runtime state** | No durable entity | active turn handle, pending interactions, terminal handles |
|
||||||
|
|
||||||
|
See [persistence.md](persistence.md) for the `Store → Storage → backend` rules. A domain EntityService is a business facade over those stores; it is not a replacement for the store layer.
|
||||||
|
|
||||||
|
## Naming consequence
|
||||||
|
|
||||||
|
Do not name Services after a scope or a god-object-shaped concept:
|
||||||
|
|
||||||
|
- ❌ `IAgentEntityService`
|
||||||
|
- ❌ `IAgentDataService`
|
||||||
|
- ❌ `ISessionEntityService`
|
||||||
|
- ❌ `ITurnEntityService` that bundles context, tools, permissions, and telemetry
|
||||||
|
|
||||||
|
Name Services after the real owning domain:
|
||||||
|
|
||||||
|
- ✅ `ISessionMetadata`
|
||||||
|
- ✅ `ISessionIndex`
|
||||||
|
- ✅ `IAgentLifecycleService`
|
||||||
|
- ✅ `ITurnService`
|
||||||
|
- ✅ `IBackgroundTaskEntityService`
|
||||||
|
- ✅ `ICronTaskEntityService`
|
||||||
|
- ✅ `IPermissionRulesService`
|
||||||
|
|
||||||
|
`Session` and `Agent` are valid scope names. They are usually **not** good data-owner names.
|
||||||
|
|
||||||
|
## Split conclusion — `session`
|
||||||
|
|
||||||
|
`session` is both a Scope and a narrow Domain. Keep the Domain small.
|
||||||
|
|
||||||
|
The `session` domain owns only Session-level identity, metadata, lifecycle commands, and Session-level read views:
|
||||||
|
|
||||||
|
| Concern | Owner | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| `sessionId`, `workspaceId`, `sessionDir`, `metaScope` | `sessionContext` | Seeded facts; no IO |
|
||||||
|
| `SessionMeta` | `sessionMetadata` | Durable atomic document; entity-like |
|
||||||
|
| Open session scope registry | `sessionLifecycle` | Workspace-scope live handles, one registry per workspace handler (the process-wide handler registry is `workspaceLifecycle`); not the persisted entity table |
|
||||||
|
| Session commands such as `archive()` | `session` | Orchestrates metadata, agent teardown, and events |
|
||||||
|
| Persisted session list / get / count | `sessionIndex` | Backend-neutral read model |
|
||||||
|
| Running / idle / awaiting status | `sessionActivity` | Derived from interactions and active turns; owns no state |
|
||||||
|
|
||||||
|
`session` must not reabsorb these:
|
||||||
|
|
||||||
|
| Data | Real owner |
|
||||||
|
|---|---|
|
||||||
|
| Agent instances / handles | `agentLifecycle` |
|
||||||
|
| Turns | `turn` |
|
||||||
|
| Context messages | `contextMemory` / `wireRecord` |
|
||||||
|
| Tool state | `toolStore` / `tool` |
|
||||||
|
| Permission rules / mode | `permission` |
|
||||||
|
| Profile / model | `profile` |
|
||||||
|
| Goal / Plan | `goal` / `plan` |
|
||||||
|
| Background tasks | `background` |
|
||||||
|
| Cron tasks | `cron` |
|
||||||
|
| Pending approvals / questions | `interaction` / `approval` / `question` |
|
||||||
|
| Workspace | `workspace` |
|
||||||
|
| Provider / config | `provider` / `config` |
|
||||||
|
|
||||||
|
Entity-service conclusion for `session`:
|
||||||
|
|
||||||
|
- ✅ `ISessionMetadata` is already an entity-document Service.
|
||||||
|
- ✅ `ISessionIndex` is a query/read-model Service.
|
||||||
|
- ❌ Do not create a broad `ISessionEntityService` that owns agents, turns, records, interactions, logs, workspace, and config.
|
||||||
|
|
||||||
|
## Split conclusion — `agent`
|
||||||
|
|
||||||
|
`agent` is primarily a Scope and composition boundary, not a large data Domain.
|
||||||
|
|
||||||
|
Strictly, the `agent` domain owns only Agent-instance concerns:
|
||||||
|
|
||||||
|
| Concern | Owner | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| Agent instance identity / handle | `agentLifecycle` | Owns live Agent scope handles |
|
||||||
|
| Agent creation / removal | `agentLifecycle` | Lifecycle, not a data bag |
|
||||||
|
| Parent / child relationship | `session` / `agentLifecycle` depending on current code | Do not duplicate it into a new Agent data service |
|
||||||
|
| Active turn reference | `turn` | Turn is its own domain even though it is Agent-scoped |
|
||||||
|
|
||||||
|
Many Agent-scoped Services are **not** in the `agent` domain:
|
||||||
|
|
||||||
|
| Data / capability | Real owner | Persistence model |
|
||||||
|
|---|---|---|
|
||||||
|
| Wire records | `wireRecord` | Append-log |
|
||||||
|
| Context messages | `contextMemory` | Event-sourced through `wireRecord` |
|
||||||
|
| Profile / model config | `profile` | Config + wire records |
|
||||||
|
| Tool definitions / registry | `toolRegistry` | Runtime registry |
|
||||||
|
| Tool mutable state | `toolStore` | Wire records |
|
||||||
|
| Permission mode / rules | `permissionMode` / `permissionRules` | Wire records + config |
|
||||||
|
| Goal | `goal` | Wire records |
|
||||||
|
| Plan | `plan` | Wire records + plan file |
|
||||||
|
| Skill activation | `skill` | Wire records |
|
||||||
|
| Background tasks | `background` | Task records / output logs, candidate for entity service |
|
||||||
|
| Cron tasks | `cron` | Task records, candidate for entity service |
|
||||||
|
|
||||||
|
Entity-service conclusion for `agent`:
|
||||||
|
|
||||||
|
- ✅ Keep `IAgentLifecycleService` for Agent instance lifecycle.
|
||||||
|
- ✅ If a persisted Agent identity registry is ever needed, name it after that narrow concern, e.g. `IAgentInstanceRegistry`.
|
||||||
|
- ❌ Do not create `IAgentEntityService` or `IAgentDataService` that bundles profile, records, tools, permission, goal, plan, background, cron, and turn.
|
||||||
|
|
||||||
|
## Split conclusion — `turn`
|
||||||
|
|
||||||
|
`turn` is a Domain, but it is **not** currently a separate `LifecycleScope` in code; `ITurnService` is registered at `Agent` scope.
|
||||||
|
|
||||||
|
`turn` owns one execution round's runtime state and turn-level facts:
|
||||||
|
|
||||||
|
| Concern | Owner | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| Active `Turn` handle | `turn` | `id`, `abortController`, `ready`, `result` |
|
||||||
|
| Turn id allocation | `turn` | Restored from `turn.prompt` records and `context.append_loop_event` turn ids |
|
||||||
|
| Turn lifecycle hooks | `turn` | `onLaunched`, `onEnded`, `beforeStep`, `afterStep` |
|
||||||
|
| `turn.started` / `turn.ended` live events | `turn` | Live event stream |
|
||||||
|
|
||||||
|
`turn` must not own these:
|
||||||
|
|
||||||
|
| Data / capability | Real owner |
|
||||||
|
|---|---|
|
||||||
|
| Prompt and context messages | `contextMemory` |
|
||||||
|
| Append-only record log mechanics | `wireRecord` |
|
||||||
|
| Step loop | `loop` |
|
||||||
|
| Tool execution | `toolExecutor` / `tool` |
|
||||||
|
| Permission decisions | `permission` |
|
||||||
|
| External hook policy | `externalHooks` |
|
||||||
|
| Telemetry pipeline | `telemetry` |
|
||||||
|
| Event transport | `eventSink` |
|
||||||
|
|
||||||
|
Entity-service conclusion for `turn`:
|
||||||
|
|
||||||
|
- ✅ Keep `ITurnService` as a runtime orchestrator.
|
||||||
|
- ✅ Add a Turn read model / projection only if history queries are needed.
|
||||||
|
- ❌ Do not create `ITurnEntityService` with `create/update/delete/list` over a turn table as the authoritative model.
|
||||||
|
|
||||||
|
## Migration recipe
|
||||||
|
|
||||||
|
When moving data out of a v1 god object or reviewing a proposed EntityService:
|
||||||
|
|
||||||
|
1. **Name the data without using `Session`, `Agent`, or `Turn`.** If you cannot, the domain is probably unclear.
|
||||||
|
2. **Find the writer.** The exclusive writer is the likely owner.
|
||||||
|
3. **Find the invariant.** The Service that rejects invalid transitions owns the model.
|
||||||
|
4. **Classify the persistence model.** Atomic document, append-log, blob, query projection, registry, or runtime-only.
|
||||||
|
5. **Pick the Service shape.**
|
||||||
|
- Entity document / record → `I{Domain}EntityService` or domain-specific CRUD Service.
|
||||||
|
- Event-sourced → behavior Service + `wireRecord` record types + optional projection.
|
||||||
|
- Derived query → read-model Service, not a write authority.
|
||||||
|
- Runtime-only → scoped Service with no entity store.
|
||||||
|
6. **Choose the Scope by state identity.** Scope follows what the state is keyed by; it does not decide the domain name.
|
||||||
|
7. **Render the placement tree** from [design.md §7](design.md#7-render-the-placement-tree).
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- Scope is not a domain. `Session` / `Agent` scopes do not make data `session` / `agent` owned.
|
||||||
|
- Ownership follows write authority and invariants, not read consumption.
|
||||||
|
- Do not create `I{Scope}EntityService` bundles (`IAgentEntityService`, `ISessionEntityService`, `ITurnEntityService`) that re-merge multiple domains.
|
||||||
|
- Event-sourced domains keep behavior Services and append-log records; do not replace them with arbitrary CRUD.
|
||||||
|
- Read models may be shaped like a domain, but they are projections, not write authorities.
|
||||||
|
- A dependency is not ownership. A Service may inject another domain without owning that domain's data.
|
||||||
183
.agents/skills/agent-core-dev/edge-exposure.md
Normal file
183
.agents/skills/agent-core-dev/edge-exposure.md
Normal file
|
|
@ -0,0 +1,183 @@
|
||||||
|
# Edge exposure — `resource:action` + WS events
|
||||||
|
|
||||||
|
How a domain's Services become the wire surface (`/api/v2`) and WebSocket events. This is a **design-time** decision: which Services are exposed, under what public `resource:action` name, and which events stream.
|
||||||
|
|
||||||
|
The transport (`/api/v2` over HTTP + WS) lives in the **edge** layer (`gateway`/`rpc`/`transport`). It borrows business Services by interface; business code never imports it.
|
||||||
|
|
||||||
|
## 1. The edge model
|
||||||
|
|
||||||
|
Four scopes, four URL shapes, one dispatcher:
|
||||||
|
|
||||||
|
```text
|
||||||
|
GET|POST /api/v2/:sa Core
|
||||||
|
GET|POST /api/v2/workspace/:workspace_id/:sa Workspace
|
||||||
|
GET|POST /api/v2/session/:session_id/:sa Session
|
||||||
|
GET|POST /api/v2/session/:session_id/agent/:agent_id/:sa Agent
|
||||||
|
```
|
||||||
|
|
||||||
|
`:sa` is a single path segment of the form `<resource>:<action>` (e.g.
|
||||||
|
`sessions:list`, `session:read`, `profile:getModel`).
|
||||||
|
|
||||||
|
- `:resource` is a **public** name (`sessions`, `session`, `profile`), never an internal domain token (`ISessionMetadata`).
|
||||||
|
- `:action` is the method. `GET` for reads, `POST` for writes.
|
||||||
|
- Body = the method's single argument (JSON), omitted for no-arg.
|
||||||
|
- Response = the project envelope `{ code, msg, data, request_id, details? }`.
|
||||||
|
- The dispatcher resolves the **scope** from the URL, the **Service** from an `actionMap`, calls the method, wraps the result.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// actionMap — the allowlist; hides internal domain names.
|
||||||
|
const actionMap = {
|
||||||
|
core: { 'sessions:list': { service: ISessionIndex, method: 'list' }, ... },
|
||||||
|
workspace: { 'skills:list': { service: IWorkspaceSkillCatalog, method: 'list' }, ... },
|
||||||
|
session: { 'session:read': { service: ISessionMetadata, method: 'read' }, ... },
|
||||||
|
agent: { 'profile:getModel': { service: IProfileService, method: 'getModel' }, ... },
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
The `actionMap` is the single allowlist: only mapped `resource:action` pairs are callable; unknown → `40001`.
|
||||||
|
|
||||||
|
## 2. What may be exposed directly
|
||||||
|
|
||||||
|
A Service method is directly exposable iff **all** hold:
|
||||||
|
|
||||||
|
1. Args are JSON-serializable (no live objects, `AbortSignal`, callbacks, resumer fns).
|
||||||
|
2. Return is JSON-serializable data or `void` (no `IScopeHandle`, `Turn`, `IProcess`, `AsyncIterable`, `IDisposable`, `Event`).
|
||||||
|
3. Errors are `KimiError` (coded).
|
||||||
|
4. It is a command/query, not a factory, stream, byte-store, or sink.
|
||||||
|
|
||||||
|
If any fail → add a wire-safe orchestration method to the owning domain Service (e.g. `IAgentPromptService.submit` settles `{turn_id}` instead of returning the live `PromptHandle`) or compose several domain Services at the edge — kap-server's `routes/prompts.ts` is the reference for edge-side composition.
|
||||||
|
|
||||||
|
## 3. Per-scope `resource:action` map
|
||||||
|
|
||||||
|
Read = `GET`, write = `POST`. `sid` = `session_id`, `aid` = `agent_id`.
|
||||||
|
|
||||||
|
### Core (`/api/v2/:resource:action`)
|
||||||
|
|
||||||
|
| resource | action | Service.method | verb |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `sessions` | `listRecent` | ISessionIndex.listRecent | GET |
|
||||||
|
| `sessions` | `get` | ISessionIndex.get | GET |
|
||||||
|
| `sessions` | `count` | ISessionIndex.count | GET |
|
||||||
|
| `workspaces` | `list` | IWorkspaceService.list | GET |
|
||||||
|
| `workspaces` | `get` | IWorkspaceService.get | GET |
|
||||||
|
| `workspaces` | `createOrTouch` | IWorkspaceService.createOrTouch | POST |
|
||||||
|
| `workspaces` | `update` | IWorkspaceService.update | POST |
|
||||||
|
| `workspaces` | `delete` | IWorkspaceService.delete | POST |
|
||||||
|
| `config` | `get` / `getAll` / `inspect` | IConfigService.* | GET |
|
||||||
|
| `config` | `set` / `replace` / `reload` | IConfigService.* | POST |
|
||||||
|
| `providers` | `list` / `get` | IProviderService.* | GET |
|
||||||
|
| `providers` | `set` / `delete` | IProviderService.* | POST |
|
||||||
|
| `oauth` | `startLogin` / `cancelLogin` / `logout` | IOAuthService.* | POST |
|
||||||
|
| `oauth` | `getFlow` / `status` | IOAuthService.* | GET |
|
||||||
|
| `auth` | `summarize` | IAuthSummaryService.summarize | GET |
|
||||||
|
| `auth` | `ensureReady` | IAuthSummaryService.ensureReady | POST |
|
||||||
|
| `flags` | `snapshot` / `enabled` / `explain` / `explainAll` | IFlagService.* | GET |
|
||||||
|
| `fs` | `browse` / `home` | IHostFolderBrowser.* | GET |
|
||||||
|
| `meta` | `getEnv` / `detect` | IBootstrapService.* | GET |
|
||||||
|
|
||||||
|
### Session (`/api/v2/session/:sid/:resource:action`)
|
||||||
|
|
||||||
|
| resource | action | Service.method | verb |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `session` | `read` | ISessionMetadata.read | GET |
|
||||||
|
| `session` | `update` | ISessionMetadata.update | POST |
|
||||||
|
| `session` | `setTitle` | ISessionMetadata.setTitle | POST |
|
||||||
|
| `session` | `setArchived` | ISessionMetadata.setArchived | POST |
|
||||||
|
| `session` | `status` | ISessionActivity.status | GET |
|
||||||
|
| `session` | `isIdle` | ISessionActivity.isIdle | GET |
|
||||||
|
| `session` | `archive` | ISessionLifecycleService.archive | POST |
|
||||||
|
| `approvals` | `listPending` | IApprovalService.listPending | GET |
|
||||||
|
| `approvals` | `decide` | IApprovalService.decide | POST |
|
||||||
|
| `questions` | `listPending` | IQuestionService.listPending | GET |
|
||||||
|
| `questions` | `answer` | IQuestionService.answer | POST |
|
||||||
|
| `interactions` | `listPending` | IInteractionService.listPending | GET |
|
||||||
|
| `interactions` | `respond` | IInteractionService.respond | POST |
|
||||||
|
| `workspace` | `workDir` / `additionalDirs` / `resolve` | ISessionWorkspaceContext.* | GET |
|
||||||
|
|
||||||
|
### Agent (`/api/v2/session/:sid/agent/:aid/:resource:action`)
|
||||||
|
|
||||||
|
| resource | action | Service.method | verb |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `goal` | `get` | IGoalService.getGoal | GET |
|
||||||
|
| `goal` | `create` / `pause` / `resume` / `cancel` | IGoalService.* | POST |
|
||||||
|
| `plan` | `status` | IPlanService.status | GET |
|
||||||
|
| `plan` | `enter` / `exit` / `cancel` / `clear` | IPlanService.* | POST |
|
||||||
|
| `tasks` | `list` / `get` / `readOutput` | IBackgroundService.* | GET |
|
||||||
|
| `tasks` | `stop` / `detach` | IBackgroundService.* | POST |
|
||||||
|
| `usage` | `status` | IUsageService.status | GET |
|
||||||
|
| `context` | `status` | IAgentTokenCountingService.get | GET |
|
||||||
|
| `swarm` | `isActive` | ISwarmService.isActive | GET |
|
||||||
|
| `swarm` | `enter` / `exit` | ISwarmService.* | POST |
|
||||||
|
| `permission` | `getMode` | IPermissionModeService.mode | GET |
|
||||||
|
| `permission` | `setMode` | IPermissionModeService.setMode | POST |
|
||||||
|
| `permissionRules` | `list` | IPermissionRulesService.rules | GET |
|
||||||
|
| `permissionRules` | `addRules` | IPermissionRulesService.addRules | POST |
|
||||||
|
| `profile` | `get` / `getModel` / `getSystemPrompt` / `getActiveToolNames` | IProfileService.* | GET |
|
||||||
|
| `profile` | `setModel` / `setThinking` | IProfileService.* | POST |
|
||||||
|
| `messages` | `list` | IContextMemory.get | GET |
|
||||||
|
| `messages` | `splice` | IContextMemory.splice | POST |
|
||||||
|
| `toolStore` | `get` / `data` | IToolStoreService.* | GET |
|
||||||
|
| `toolStore` | `set` | IToolStoreService.set | POST |
|
||||||
|
| `mcp` | `list` | IMcpService.list | GET |
|
||||||
|
| `mcp` | `reconnect` | IMcpService.reconnect | POST |
|
||||||
|
| `tools` | `list` | IToolRegistry.list | GET |
|
||||||
|
|
||||||
|
## 4. Facade-needed (wrap before exposing)
|
||||||
|
|
||||||
|
These fail §2 and must be wrapped in a facade that takes ids and returns data:
|
||||||
|
|
||||||
|
| Service | Why not direct | Facade shape |
|
||||||
|
|---|---|---|
|
||||||
|
| ISessionLifecycleService | returns `IScopeHandle` | `sessions.create` / `fork` / `close` / `archive` → wire Session |
|
||||||
|
| IAgentPromptService / IAgentTurnService | returns `Turn` handle | `prompts.submit` / `steer` / `abort` / `undo` |
|
||||||
|
| ILLMRequester | `AsyncIterable` stream | stream over WS, not RPC |
|
||||||
|
| ISubagentHost | `SubagentHandle` | `subagents.spawn` / `resume` → info |
|
||||||
|
| IProcessRunner | `IProcess` streams | terminal (separate WS protocol) |
|
||||||
|
| Storage / Store (IFileSystemStorageService / IAppendLogStore / IAtomicDocumentStore / IBlobStore) | bytes / streams | not for RPC |
|
||||||
|
| IAgentFileSystem | `withCwd` handle | `fs.read` / `write` → text/bytes |
|
||||||
|
| IExternalHooksService | server-side outbound | not exposed |
|
||||||
|
| IWireRecord | write-ahead log | internal |
|
||||||
|
|
||||||
|
## 5. WS events
|
||||||
|
|
||||||
|
A single WebSocket endpoint multiplexes RPC `call`s and event `listen`s over a JSON protocol (the lean counterpart of VSCode's `IMessagePassingProtocol`, carrying the same safety features — see §6):
|
||||||
|
|
||||||
|
```text
|
||||||
|
WS /api/v2/ws
|
||||||
|
```
|
||||||
|
|
||||||
|
Client → server: `hello` (auth), `call` (scope + `resource:action` + arg), `cancel`, `listen` (scope + event), `unlisten`, `pong`.
|
||||||
|
Server → client: `ready`, `result`, `error`, `event`, `ping`.
|
||||||
|
|
||||||
|
`call` reuses the same dispatcher as the HTTP routes (scope + `actionMap`). `listen` subscribes to an `Event<T>` source and forwards each emission as an `event` message, keyed by the client-chosen `id`.
|
||||||
|
|
||||||
|
The `eventMap` binds a public event name to the scope's `Event` source (analogous to the `actionMap`):
|
||||||
|
|
||||||
|
| Scope | event | Source |
|
||||||
|
|---|---|---|
|
||||||
|
| Core | `events` | `IEventService.subscribe` (process-wide `DomainEvent` bus) |
|
||||||
|
| Agent | `events` | `IEventSink.on` (per-agent `AgentEvent` stream) |
|
||||||
|
|
||||||
|
Session-level `onDidChange` sources (metadata / interactions) carry no payload today, so they are not exposed until there is a concrete consumer.
|
||||||
|
|
||||||
|
Safety / reliability (carried over from `packages/server/src/ws/connection.ts` and VSCode's `ChannelServer`):
|
||||||
|
|
||||||
|
- request ids + active-request table — `cancel` / `unlisten` disposes them;
|
||||||
|
- heartbeat — `ping` every 30s, `pong` timeout 10s → `terminate`;
|
||||||
|
- schema validation — invalid frames are dropped, not fatal;
|
||||||
|
- graceful close — dispose listeners, cancel pending, reject in-flight calls;
|
||||||
|
- no stack traces over the wire;
|
||||||
|
- non-serializable event payloads are dropped, never fatal.
|
||||||
|
|
||||||
|
Cursor / replay / resync for events is a future addition (a separate `call` before `listen`); the raw stream is the foundation.
|
||||||
|
|
||||||
|
## 6. Red lines (edge exposure)
|
||||||
|
|
||||||
|
- Never expose an internal domain token (`ISessionMetadata`) as a URL segment — use a public `resource` name + `action`.
|
||||||
|
- Never expose a method that returns a handle / stream / bytes / disposable — wrap in a facade.
|
||||||
|
- Never expose a method that takes a live object / `AbortSignal` / callback / resumer fn — wrap in a facade.
|
||||||
|
- Session / Agent Services are reached by `accessor.get` with the id from the URL — never cache the result; finish before the scope disposes.
|
||||||
|
- The `actionMap` is the allowlist — only mapped `resource:action` pairs are callable; unknown → `40001`.
|
||||||
|
- Events stream over WS (`listen`), never RPC (`call`).
|
||||||
|
- Business code never imports the edge (`gateway` / `rpc` / `transport`) — the edge borrows business Services by interface.
|
||||||
|
- Read = `GET`, write = `POST`; do not overload `POST` for reads when caching / browser-friendliness matters.
|
||||||
40
.agents/skills/agent-core-dev/errors.md
Normal file
40
.agents/skills/agent-core-dev/errors.md
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Topic — Errors
|
||||||
|
|
||||||
|
Error infrastructure for agent-core-v2: base classes, the per-domain code contract, wire serialization, and the conventions domains follow when raising errors. The package-level reference is `packages/agent-core-v2/docs/errors.md`; this topic summarizes the hot-path rules.
|
||||||
|
|
||||||
|
Base classes and serialization are **centralized** in `_base/errors`; error **codes** are **decentralized** — each domain owns an `errors.ts` that self-registers its codes and metadata, and the `src/errors.ts` facade aggregates them into the unified `ErrorCodes` const.
|
||||||
|
|
||||||
|
## Where things live
|
||||||
|
|
||||||
|
- `src/_base/errors/errors.ts`: base classes — `Error2`, `ExpectedError`, `ErrorNoTelemetry`, `BugIndicatingError`, `NotImplementedError`, plus `isError2` and `unwrapErrorCause`.
|
||||||
|
- `src/_base/errors/codes.ts`: the `ErrorDomain` contract, the registry (`registerErrorDomain` / `errorInfo` / `isErrorCode`), and `CoreErrors` (`internal`, `not_implemented`). The `ErrorCode` union type is derived by `#/errors` from the aggregated domain definitions.
|
||||||
|
- `src/_base/errors/serialize.ts`: `ErrorPayload`, `isCodedError`, `toErrorPayload`, `fromErrorPayload`. Wire-facing names (`KimiErrorPayload`, `toKimiErrorPayload`) mirror the protocol and are kept as-is.
|
||||||
|
- `src/_base/errors/unexpectedError.ts`: `onUnexpectedError` / `setUnexpectedErrorHandler` (global handler).
|
||||||
|
- `src/<domain>/errors.ts`: the domain's `XxxErrors` descriptor (codes + retryable list + per-code info overrides), self-registered on import.
|
||||||
|
- `src/errors.ts`: the **facade** — imports every domain's `errors.ts`, builds `ErrorCodes`, re-exports the primitives. Throw sites import from here.
|
||||||
|
|
||||||
|
## Conventions (hard rules)
|
||||||
|
|
||||||
|
- **Throw a coded error, not a bare string.** `throw new Error2(ErrorCodes.X, …)`. Bare `new Error` only for unreachable guards; `BugIndicatingError` for caller bugs; `NotImplementedError('feature')` for stubs.
|
||||||
|
- **Define codes in the owning domain**, in `<domain>/errors.ts` as an `XxxErrors` descriptor (`satisfies ErrorDomain` + `registerErrorDomain`), then wire it into the facade. Never add domain codes to `_base/errors`.
|
||||||
|
- **One `code` per failure mode.** Codes read `domain.reason`. The valid code strings are derived from the aggregated domain definitions (`ErrorCode` in `#/errors` is computed from the `ErrorCodes` aggregate): **add new codes to the owning domain's `errors.ts`** — registration throws on cross-domain collisions. Renaming/removing a code is a major.
|
||||||
|
- **Translate foreign errors at the boundary.** Provider/HTTP, fs, MCP errors are re-thrown as the owning domain's coded error. `_base/errors` never imports a business domain.
|
||||||
|
- **Translation is idempotent and cause-preserving.** Translators (`toHostFsError`, `toStorageIoError`) pass through an already-translated error and always keep the original as `cause`.
|
||||||
|
- **`details` is structured and JSON-serializable; `message` is a short human sentence.** Paths/errnos/scope/key go into `details`, not the message.
|
||||||
|
- **Cancellation passes through untranslated** (`UserCancellationError` from `_base/utils/abort`) — apply only at boundaries that can actually see cancellation; do not sprinkle the check everywhere.
|
||||||
|
- **Classify wrapped errors via `unwrapErrorCause`** — errno/status predicates test the unwrapped cause, not the coded wrapper.
|
||||||
|
- **Branch on `code`, never `instanceof`, across the wire.** In-process, `instanceof Error2` / `isCodedError` are fine.
|
||||||
|
|
||||||
|
## Reference tiers
|
||||||
|
|
||||||
|
- `os.fs` — `HostFsError` via `toHostFsError` (`os/interface/hostFsErrors.ts`): errno → `os.fs.*`, details `{ path, op, errno?, syscall? }`.
|
||||||
|
- `os.process` — `HostProcessError`: `spawn_failed` / `kill_failed`, raw error as `cause`.
|
||||||
|
- `storage` — `StorageError` (`persistence/interface/storage.ts`): `not_found` / `decode_failed` / `corrupted` / `io_failed` (retryable) / `locked` (retryable). ENOENT keeps absence semantics, never an error. A locked query store throws `storage.locked`; consumers catch it explicitly and fall back — no silent no-op degradation.
|
||||||
|
- `wire` — `WireError` (`wire/errors.ts`): `DuplicateOpError`, `CycleError`, and `wire.unknown_record` (replay skips unknown records, reports via `onUnexpectedError`, returns `{ unknownRecords }`).
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- Throw a coded error with a `code`, not a bare string (except unreachable guards / `BugIndicatingError` / `NotImplementedError`).
|
||||||
|
- Codes live in the owning domain's `errors.ts` and self-register; new codes land in the owning domain first.
|
||||||
|
- Translate foreign errors at the owning domain's boundary, idempotently, with `cause` and structured `details`; `_base/errors` never imports a business domain.
|
||||||
|
- Branch on `code` across the wire, never `instanceof`.
|
||||||
108
.agents/skills/agent-core-dev/flags.md
Normal file
108
.agents/skills/agent-core-dev/flags.md
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
# Topic — Flags
|
||||||
|
|
||||||
|
Experimental feature-flag gating for agent-core-v2 — an App-scope `IFlagService` resolver plus a writable `IFlagRegistry` catalog that domains contribute their flags to, backed by the `[experimental]` config section.
|
||||||
|
|
||||||
|
Gate not-yet-public features behind `IFlagService.enabled(id)`, per the repository hard rule that unreleased behavior must be flag-gated. v1 was a process-global `FlagResolver` singleton over a central `FLAG_DEFINITIONS` array; v2 is a scoped DI service whose flag definitions are registered **decentrally** by each owning domain — there is no central catalog to edit.
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
- `src/app/flag/flagRegistry.ts` — `IFlagRegistry` token + `FlagDefinitionInput` / `FlagId` / `FlagSurface` types + `registerFlagDefinition` / `getContributedFlags` (import-time contribution queue).
|
||||||
|
- `src/app/flag/flagRegistryService.ts` — `FlagRegistryService` impl; in-memory catalog seeded from import-time contributions; App scope.
|
||||||
|
- `src/app/flag/flag.ts` — `IFlagService` token + resolver types (`ExperimentalFlagMap`, `ExperimentalFlagConfig`, `ExperimentalFlagSource`, `ExperimentalFeatureState`) + `EXPERIMENTAL_SECTION` (`experimental`) / `ExperimentalConfigSchema` (zod) + the module-level `registerConfigSection(EXPERIMENTAL_SECTION, …)` call that owns the section.
|
||||||
|
- `src/app/flag/flagService.ts` — `FlagService` impl + `MASTER_ENV` (`KIMI_CODE_EXPERIMENTAL_FLAG`); reads definitions from `IFlagRegistry` and overrides from `IConfigService`; self-registers at App scope.
|
||||||
|
- `src/app/flag/index.ts` — **removed (no barrel)**; `src/index.ts` imports the `flag` leafs precisely instead (e.g. `import './app/flag/flagService'`).
|
||||||
|
- `src/<domain>/flag.ts` — each domain that owns a flag declares it here and calls `registerFlagDefinition` at the module top level (e.g. `src/agent/toolSelect/flag.ts`). The directory already names the domain, so the file is just `flag.ts`.
|
||||||
|
|
||||||
|
## Public surface
|
||||||
|
|
||||||
|
- `IFlagService` (DI token, App scope): `enabled(id)`, `explain(id)`, `snapshot()`, `enabledIds()`, `explainAll()`, `setConfigOverrides(overrides)`, `registry`.
|
||||||
|
- `IFlagRegistry` (DI token, App scope): `register(definition)`, `get(id)`, `list()` — writable catalog. `register` is the **runtime** path (tests, dynamic registration); `IFlagService.registry` exposes the same instance for hosts/UI to enumerate flags without resolving them.
|
||||||
|
- `registerFlagDefinition(definition)` — the **import-time** path. Domains call this from their `flag.ts` top level; contributions are queued and drained by `FlagRegistryService` when it is instantiated.
|
||||||
|
- `FlagService` / `FlagRegistryService`: exported for tests and hosts that construct them directly.
|
||||||
|
|
||||||
|
## Resolution precedence
|
||||||
|
|
||||||
|
Highest wins; env is read live on every call (nothing cached):
|
||||||
|
|
||||||
|
1. Master env `KIMI_CODE_EXPERIMENTAL_FLAG` truthy → every flag on.
|
||||||
|
2. Per-feature `def.env` (e.g. `KIMI_CODE_EXPERIMENTAL_MY_FEATURE`) → forces on/off.
|
||||||
|
3. `[experimental]` config section per-flag override.
|
||||||
|
4. Registry `default`.
|
||||||
|
|
||||||
|
`explain(id)` returns the winning `source` (`master-env` | `env` | `config` | `default`) plus the effective `configValue`. `explain(id)` returns `undefined` (and `enabled(id)` returns `false`) for an id that no domain has registered.
|
||||||
|
|
||||||
|
## Config integration
|
||||||
|
|
||||||
|
- The flag domain owns the `[experimental]` section: `src/app/flag/flag.ts` registers it at module load via `registerConfigSection(EXPERIMENTAL_SECTION, ExperimentalConfigSchema, { fromToml, toToml })` (import = register, drained by `ConfigRegistry` at construction); `FlagService` reads overrides from `IConfigService`.
|
||||||
|
- It subscribes `IConfigService.onDidChange` and refreshes overrides whenever the `experimental` domain changes, so config edits apply live.
|
||||||
|
- `ConfigRegistry.registerSection` throws if a domain is registered twice — `experimental` is owned exclusively by the flag domain.
|
||||||
|
- `setConfigOverrides(overrides)` is an imperative escape hatch for tests and hosts without an `IConfigService`; hosts on `IConfigService` should set the `[experimental]` section instead.
|
||||||
|
|
||||||
|
Config shape:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[experimental]
|
||||||
|
my_feature = false
|
||||||
|
```
|
||||||
|
|
||||||
|
Keys are intentionally loose (`z.record(z.string(), z.boolean())`), so obsolete flags stay inert config.
|
||||||
|
|
||||||
|
## Add a flag
|
||||||
|
|
||||||
|
Declare the definition in the owning domain's `flag.ts` and call `registerFlagDefinition` at the module top level. There is no central catalog to edit.
|
||||||
|
|
||||||
|
`src/<domain>/flag.ts`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { type FlagDefinitionInput, registerFlagDefinition } from '#/app/flag/flagRegistry';
|
||||||
|
|
||||||
|
export const myFeatureFlag: FlagDefinitionInput = {
|
||||||
|
id: 'my_feature',
|
||||||
|
title: 'My feature',
|
||||||
|
description: '...',
|
||||||
|
env: 'KIMI_CODE_EXPERIMENTAL_MY_FEATURE',
|
||||||
|
default: false,
|
||||||
|
surface: 'both',
|
||||||
|
};
|
||||||
|
|
||||||
|
registerFlagDefinition(myFeatureFlag);
|
||||||
|
```
|
||||||
|
|
||||||
|
Then ensure the package entry `src/index.ts` imports the flag leaf precisely so the top-level call runs at import time — there is no `src/<domain>/index.ts` barrel:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// src/index.ts
|
||||||
|
import './<domain>/flag';
|
||||||
|
```
|
||||||
|
|
||||||
|
`src/index.ts` imports every domain's leaf files precisely (one line per leaf), so the contribution runs during bootstrap, before any scope is created — and therefore before any consumer resolves `IFlagService`.
|
||||||
|
|
||||||
|
- `env` must start with `KIMI_CODE_EXPERIMENTAL_`, be unique, and not equal `KIMI_CODE_EXPERIMENTAL_FLAG`.
|
||||||
|
- `id` must not be `flag`. A duplicate `id` throws when `FlagRegistryService` drains the contributions.
|
||||||
|
- `FlagId` is `string`, not a literal union: with no central catalog there is nothing to derive it from, so `enabled()` has no compile-time typo-checking. Cover gated behavior with tests instead.
|
||||||
|
- `surface`: `core` | `tui` | `both` (documentation/grouping only; not used in resolution).
|
||||||
|
|
||||||
|
## Consume a flag
|
||||||
|
|
||||||
|
Inject `IFlagService` and gate on it. It is resolvable from any scope (App ancestor):
|
||||||
|
|
||||||
|
```ts
|
||||||
|
constructor(@IFlagService private readonly flags: IFlagService) {}
|
||||||
|
// ...
|
||||||
|
if (!this.flags.enabled('my_feature')) return;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Layering & scope
|
||||||
|
|
||||||
|
- Domain `flag` imports only `config` downward.
|
||||||
|
- It cannot live in `_base`: registering/reading the config section requires importing `config`, and `_base` is pure infrastructure that must not know any business domain.
|
||||||
|
- Scope: `IFlagRegistry` and `IFlagService` are both `App`. Env + config are process-global inputs, so there is no per-session/agent state. Flag definitions are contributed at **import time** (top-level `registerFlagDefinition` calls), so they are queued before any scope is created and drained when `FlagRegistryService` is first instantiated — before `IFlagService` is first resolved.
|
||||||
|
- Tests build `FlagService` + `FlagRegistryService` directly with a real `ConfigRegistry`/`ConfigService` and an injected env map, then `register` the flags they exercise.
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- Gate unreleased behavior behind a registered flag; no ad-hoc env toggles.
|
||||||
|
- Contribute each flag from the **owning domain's** `flag.ts` (`src/<domain>/flag.ts`) via a top-level `registerFlagDefinition` call; there is no central catalog to edit. The directory names the domain, so the file is just `flag.ts`.
|
||||||
|
- `env` must start with `KIMI_CODE_EXPERIMENTAL_`, be unique, and not equal `KIMI_CODE_EXPERIMENTAL_FLAG`; `id` must not be `flag`.
|
||||||
|
- `FlagId` is `string` (decentralized registration) — do not reintroduce a central `FLAG_DEFINITIONS` array or a derived literal union.
|
||||||
|
- `flag` lives at `App` scope — never in `_base`, never per-session.
|
||||||
295
.agents/skills/agent-core-dev/implement.md
Normal file
295
.agents/skills/agent-core-dev/implement.md
Normal file
|
|
@ -0,0 +1,295 @@
|
||||||
|
# Stage 3 — Implement
|
||||||
|
|
||||||
|
Write the contract leaf, implementation leaf (with its registration), and the package-entry lines that load them. Each section below introduces one DI building block as you need it. Source lives in `src/_base/di/`.
|
||||||
|
|
||||||
|
## Standard recipe for a new `IXxxService`
|
||||||
|
|
||||||
|
1. **Contract leaf** — `src/<domain>/<domain>.ts`: interface (with `_serviceBrand`) + `createDecorator` identity.
|
||||||
|
2. **Impl leaf** — `src/<domain>/<domain>Service.ts`: class with `@IX` constructor deps; top-level `registerScopedService(scope, IX, Impl, activation, '<domain>')`. The fourth argument is activation; the fifth is the domain.
|
||||||
|
3. **Entry** — `src/index.ts`: load each leaf precisely — `export * from './<domain>/<domain>';` for the contract and `import './<domain>/<domain>Service';` for the impl (importing the impl runs the registration). **No `src/<domain>/index.ts` barrel.**
|
||||||
|
4. **Tests** — see test.md.
|
||||||
|
|
||||||
|
There is **no central wiring file**: bindings live in each domain's impl file and are collected through import side effects.
|
||||||
|
|
||||||
|
## §1 Interface + identity (a global service, no deps)
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// greet/greet.ts
|
||||||
|
import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
|
||||||
|
|
||||||
|
export interface IGreeter {
|
||||||
|
readonly _serviceBrand: undefined; // type marker: tells DI "this is a service"
|
||||||
|
hello(): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const IGreeter: ServiceIdentifier<IGreeter> = createDecorator<IGreeter>('greeter');
|
||||||
|
```
|
||||||
|
|
||||||
|
`createDecorator(name)` produces a `ServiceIdentifier` that is three things at once: a runtime key, a parameter decorator, and a compile-time carrier of the `IGreeter` type.
|
||||||
|
|
||||||
|
> **The identity name is globally unique.** `createDecorator` caches by `name`; two domains using the same string collide and share one identity.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// greet/greetService.ts
|
||||||
|
import { LifecycleScope } from '#/app/scopes';
|
||||||
|
import { registerScopedService, ScopeActivation } from '#/_base/di/scope';
|
||||||
|
import { IGreeter } from './greet';
|
||||||
|
|
||||||
|
export class Greeter implements IGreeter {
|
||||||
|
declare readonly _serviceBrand: undefined; // mirrors the interface marker
|
||||||
|
hello(): string { return 'hi'; }
|
||||||
|
}
|
||||||
|
|
||||||
|
registerScopedService(
|
||||||
|
LifecycleScope.App, // lifetime: process-wide
|
||||||
|
IGreeter, // identity
|
||||||
|
Greeter, // implementation
|
||||||
|
ScopeActivation.OnScopeCreated, // construct when the App scope is created
|
||||||
|
'greet', // domain name (for diagnostics)
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
The scope a class binds to is an **intrinsic property of the class**, decided at the registration point, not the call site.
|
||||||
|
|
||||||
|
The impl's top-level `registerScopedService` runs as soon as the module is imported. There is no `greet/index.ts` barrel — instead, add the leafs to the package entry `src/index.ts`, one line per leaf:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// src/index.ts
|
||||||
|
export * from './greet/greet';
|
||||||
|
import './greet/greetService'; // this import runs registerScopedService
|
||||||
|
```
|
||||||
|
|
||||||
|
Anyone can now `accessor.get(IGreeter)` the single global instance.
|
||||||
|
|
||||||
|
## §2 Constructor injection (your service uses others)
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export class SessionMetadata extends Disposable implements ISessionMetadata {
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@ISessionContext private readonly ctx: ISessionContext,
|
||||||
|
@IAtomicDocumentStore private readonly store: IAtomicDocumentStore,
|
||||||
|
@ILogService private readonly log: ILogService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`@ISessionContext` records "parameter 0 needs `ISessionContext`" on the class metadata; the container fills it when constructing.
|
||||||
|
|
||||||
|
Three inviolable constraints:
|
||||||
|
|
||||||
|
1. **Do not `new` a class with `@IService` deps** — `new` bypasses registration, scope, and the singleton cache. Inject with `@IX` or `accessor.get(IX)`.
|
||||||
|
2. **`@IX` decorates constructor parameters only.** Decorating a field/method throws at runtime.
|
||||||
|
3. **Parameter order depends on how the object is built** — for `createInstance` non-singletons, static params come first (see §7); for scoped services, `@IX` params are conventionally first and any static params need defaults. See service-authoring.md §constructor-conventions.
|
||||||
|
|
||||||
|
Consumers resolve by interface and never import the impl class:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const meta = accessor.get(ISessionMetadata); // type is ISessionMetadata
|
||||||
|
```
|
||||||
|
|
||||||
|
> If you need "a config" rather than "a service", model it as a service (e.g. `IConfigService`) and inject it. If you need a per-turn, parameterized, non-singleton object, see §7.
|
||||||
|
|
||||||
|
## §3 Scoped registration (not global)
|
||||||
|
|
||||||
|
Swap the `scope` argument to bind to a different tier. Use `ScopeActivation.OnDemand` when the service should be constructed only on its first `get()`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
registerScopedService(
|
||||||
|
LifecycleScope.Session,
|
||||||
|
ISessionMetadata,
|
||||||
|
SessionMetadata,
|
||||||
|
ScopeActivation.OnDemand,
|
||||||
|
'sessionMetadata',
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
Remember the visibility rule from orient.md: a service may inject services from its own scope or any ancestor; never from a descendant.
|
||||||
|
|
||||||
|
## §4 Releasing resources (`Disposable`)
|
||||||
|
|
||||||
|
For a service that subscribes to events, starts timers, or holds handles:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Disposable } from '#/_base/di/lifecycle';
|
||||||
|
|
||||||
|
export class WSBroadcastService extends Disposable implements IWSBroadcastService {
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
|
||||||
|
constructor(@IEventService event: IEventService) {
|
||||||
|
super();
|
||||||
|
this._register(event.subscribe(() => { /* … */ })); // collect child resources
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Extend `Disposable`, collect any `IDisposable` with `this._register(d)` (event subscriptions, `toDisposable(fn)`, etc.).
|
||||||
|
- The container calls `dispose()` automatically when the service is torn down; child resources release in turn.
|
||||||
|
- Disposal order is deterministic (orient.md): child scopes first; within a scope the Ledger (`src/_base/lifecycle/`) tears entries down in strict reverse registration order, serially — `Disposable` / `DisposableStore` delegate to it.
|
||||||
|
- Extend `Service` (from `#/_base/di/service`) instead when the unit needs capability calls on `this` (`provide` / `effect` / `on` / `get` / `ref`) — e.g. contributing a record to a `collection` token. `Service` extends `Disposable` (so `_register` is unchanged) and adds the two-phase construction protocol: `provide` / `on` / `effect` calls inside the constructor are buffered and flushed by the kernel after `Reflect.construct`; `get` / `ref` throw inside the constructor — dependencies stay constructor parameters. A manually `new`ed `Service` has no capabilities: every capability call throws.
|
||||||
|
|
||||||
|
## §5 Scope activation
|
||||||
|
|
||||||
|
`ScopeActivation` is the only construction-timing choice for scoped services:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export enum ScopeActivation {
|
||||||
|
OnScopeCreated = 0,
|
||||||
|
OnDemand = 1,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Default: construct the real instance while the App scope is created.
|
||||||
|
registerScopedService(
|
||||||
|
LifecycleScope.App,
|
||||||
|
ILogService,
|
||||||
|
LogService,
|
||||||
|
ScopeActivation.OnScopeCreated,
|
||||||
|
'log',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Construct the real instance on the first get(IScopeRegistry).
|
||||||
|
registerScopedService(
|
||||||
|
LifecycleScope.App,
|
||||||
|
IScopeRegistry,
|
||||||
|
ScopeRegistry,
|
||||||
|
ScopeActivation.OnDemand,
|
||||||
|
'gateway',
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
`ScopeActivation.OnScopeCreated` is the default fourth argument. Scope creation activates every registration using this mode, after constructing its dependencies. An eager constructor failure no longer fails scope creation: the unit lands in sticky `Failed` — scope creation succeeds, resolving the unit rethrows its error, and an explicit `update()` reloads it (see the bootstrap note below). Use it for ordinary services and for constructor side effects that must exist when the scope becomes ready.
|
||||||
|
|
||||||
|
`ScopeActivation.OnDemand` stores the descriptor without constructing the service. The first `get()` constructs and caches the real instance directly; later `get()` calls return that same instance. Use it only when construction should wait until the service is actually requested.
|
||||||
|
|
||||||
|
Both modes use the same dependency graph and reject cycles with `CyclicDependencyError`.
|
||||||
|
|
||||||
|
The complete registration signature is `registerScopedService(scope, id, ctor, activation = ScopeActivation.OnScopeCreated, domain?)`: activation is the fourth argument and domain is the fifth.
|
||||||
|
|
||||||
|
**Bootstrap shares the dynamic provide path.** Scope creation (`Scope.createApp` / `Scope.createChild` / `createScopedChildHandle` in `src/_base/di/scope.ts`) submits the scope kind's entire `registerScopedService` batch as ONE cascade transaction via `provideAll`: every token registers before the activation wave runs, so **registration order never matters**, and untracked transitive `createInstance` resolutions succeed inside the batch. A seed occupying a token (the `extra` tuple in `ScopeOptions`) overrides the static registration for that token. `activateScopeServices` is gone — there is no separate static activation path.
|
||||||
|
|
||||||
|
## §6 Using a service inside a plain function (`invokeFunction`)
|
||||||
|
|
||||||
|
When you do not want a new class and just need a service once, or when you expose a `ServicesAccessor` to the outside:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const accessor: ServicesAccessor = {
|
||||||
|
get: <T>(id: ServiceIdentifier<T>): T => instantiation.invokeFunction((a) => a.get(id)),
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
`invokeFunction(fn)` hands `fn` a `ServicesAccessor` valid **only during that call**.
|
||||||
|
|
||||||
|
> **The accessor is valid only during the invocation.** Calling `accessor.get()` after `invokeFunction` returns throws `"service accessor is only valid during the invocation"`. Do not stash it for async use — inject the service in the constructor (§2) if you need it long-term.
|
||||||
|
|
||||||
|
## §7 Creating a non-singleton object with deps (`createInstance`)
|
||||||
|
|
||||||
|
For a per-turn executor that also has `@IService` deps:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
class TurnRunner {
|
||||||
|
constructor(
|
||||||
|
private readonly input: string, // static param: passed by caller
|
||||||
|
private readonly turn: number, // static param: passed by caller
|
||||||
|
@ILogService private readonly log: ILogService, // service param: injected by container
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const runner = instantiation.createInstance(TurnRunner, 'hello', 1);
|
||||||
|
```
|
||||||
|
|
||||||
|
Static params come first (you pass them), service params follow (the container fills them), then `Reflect.construct` builds the instance. This object is **not** placed in any scope's singleton cache — every call is a fresh instance — and it is not tracked as a cascade unit either: `createInstance` products are cascade-exempt leaves that no cascade tears down or rebuilds; their owner disposes them.
|
||||||
|
|
||||||
|
> This is why service params must follow static params **for `createInstance`**: the container sorts by the parameter positions recorded via `@IX`. `_serviceBrand` lets the compiler tell the two kinds apart. Scoped services built by `registerScopedService` follow a different convention (`@IX` params first, optional static params after) — see service-authoring.md §constructor-conventions.
|
||||||
|
|
||||||
|
## §8 Spawning a child scope / child container
|
||||||
|
|
||||||
|
For a service that "starts a new session / agent" and needs a child scope, inject `IInstantiationService` itself (every container binds itself as `IInstantiationService`):
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export class ScopeRegistry implements IScopeRegistry {
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
|
||||||
|
constructor(@IInstantiationService private readonly instantiation: IInstantiationService) {}
|
||||||
|
|
||||||
|
createSession(opts: CreateSessionOptions): Promise<IScopeHandle> {
|
||||||
|
const collection = new ServiceCollection();
|
||||||
|
for (const entry of getScopedServiceDescriptors(LifecycleScope.Session)) {
|
||||||
|
collection.set(entry.id, entry.descriptor); // collect Session-tier descriptors
|
||||||
|
}
|
||||||
|
const child = this.instantiation.createChild(collection); // spawn child container
|
||||||
|
const accessor: ServicesAccessor = {
|
||||||
|
get: <T>(id: ServiceIdentifier<T>): T => child.invokeFunction((a) => a.get(id)),
|
||||||
|
};
|
||||||
|
const handle: IScopeHandle = { id: opts.sessionId, kind: LifecycleScope.Session, accessor };
|
||||||
|
this.sessions.set(opts.sessionId, handle);
|
||||||
|
return Promise.resolve(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Key points:
|
||||||
|
|
||||||
|
- `getScopedServiceDescriptors(scope)` returns every descriptor registered at that tier; load them into a `ServiceCollection`.
|
||||||
|
- `instantiation.createChild(collection)` builds a child container whose parent pointer is the current container — so the child resolves upward to `App` services (the visibility rule).
|
||||||
|
- Expose the child to the outside by wrapping it in a `ServicesAccessor` via `invokeFunction` (§6).
|
||||||
|
|
||||||
|
> Higher-level code usually calls `Scope.createChild(kind, id)` (it does the "filter descriptors + build child" for you, then submits the whole batch through `provideAll` as one cascade transaction — see §5). Drop to the manual `ServiceCollection` form only when you need explicit control; to change bindings on an already-created container, prefer `provide` / `unprovide` / `update` over rebuilding a collection. Before the static batch lands, the scope-creation point runs the kernel's `ScopeUnits` fold (`_base/di/scopeUnits.ts` — materializes the recipes contributed to `ScopeUnits(kind)` as per-scope units) and then the `ScopeOptions.assemble` hook — the session domain uses the hook to construct its seed-adapter units (`session/sessionSeed/sessionSeedAdapters.ts`) so their provided tokens exist before the session services activate.
|
||||||
|
|
||||||
|
## §9 Cyclic dependencies (forbidden — refactor)
|
||||||
|
|
||||||
|
Business rule: **no cyclic dependencies.** The container rejects them; the correct response is to refactor, not to make it run.
|
||||||
|
|
||||||
|
### The container rejects synchronous cycles
|
||||||
|
|
||||||
|
If A needs B while being created and B needs A while being created, the container throws `CyclicDependencyError` with a `path` like `['A', 'B', 'A']`. Self-cycles (A depends on itself) are also rejected. This is a protection mechanism telling you the two services' responsibilities are mis-drawn.
|
||||||
|
|
||||||
|
### Why cycles are disallowed
|
||||||
|
|
||||||
|
- Scope layering makes normal dependencies a DAG (Agent → Session → Workspace → App, resolving upward); a cycle is almost always a design smell.
|
||||||
|
- "Making the cycle happen to work" turns construction order into an implicit contract — hard to debug.
|
||||||
|
|
||||||
|
v2's stance: **the dependency graph must be acyclic.**
|
||||||
|
|
||||||
|
### How to refactor (in priority order)
|
||||||
|
|
||||||
|
1. **Extract a third service C.** Move the part A and B both need into C; let A and B both depend on C instead of each other. The most common fix.
|
||||||
|
2. **Decouple with an event.** If A only needs to know about a change in B, have B emit via `IEventService` and A subscribe, rather than A holding a reference to B.
|
||||||
|
3. **Re-partition scope.** One of them may belong at a different tier — moving it makes the cycle disappear.
|
||||||
|
|
||||||
|
### Activation does not break cycles
|
||||||
|
|
||||||
|
Both `ScopeActivation.OnScopeCreated` and `ScopeActivation.OnDemand` construct through the same synchronous dependency graph. Changing activation cannot make a cycle valid. On `CyclicDependencyError`, refactor per the above.
|
||||||
|
|
||||||
|
## Interface cheat sheet
|
||||||
|
|
||||||
|
| Interface | Section | Role |
|
||||||
|
|---|---|---|
|
||||||
|
| `createDecorator<T>(name)` → `ServiceIdentifier<T>` | §1 | identity (runtime key + compile-time type + param decorator) |
|
||||||
|
| `@IService` | §2, §7 | declare a dependency on a constructor param |
|
||||||
|
| `registerScopedService(scope, id, ctor, activation, domain)` | §1, §3, §5 | bind an impl to a lifetime tier and construction time |
|
||||||
|
| `ServicesAccessor.get(IX)` | §2, §6 | resolve an instance by interface |
|
||||||
|
| `IInstantiationService.invokeFunction(fn, …)` | §6, §8 | obtain a temporary accessor inside a function |
|
||||||
|
| `IInstantiationService.createInstance(ctor, …args)` | §7 | build a non-singleton object with deps injected |
|
||||||
|
| `IInstantiationService.createChild(collection)` | §8 | spawn a child container |
|
||||||
|
| `getScopedServiceDescriptors(scope)` | §8 | retrieve all descriptors registered at a tier |
|
||||||
|
| `Disposable` / `DisposableStore` / `IDisposable` | §4 | resource management and disposal |
|
||||||
|
| `Scope` / `LifecycleScope` | §3, §8 | the lifetime tree |
|
||||||
|
| `ScopeActivation` | §3, §5 | choose scope-created or first-`get()` construction |
|
||||||
|
| `Service` (`_base/di/service`) | §4 | unit base class — `this.provide/effect/on/get/ref` capabilities, two-phase construction |
|
||||||
|
| `collection<T>(name)` / `CollectionView<T>` (`_base/di/collection`) | §4 | contribution-point token + the fold's live view (provider death withdraws the record) |
|
||||||
|
| `SyncDescriptor` | (tests / low-level) | package a constructor + static args into a pending descriptor |
|
||||||
|
|
||||||
|
> Legacy export (not used in v2, just recognize it): `refineServiceDecorator` is a VS Code leftover DI helper. v2 src/test has zero references; always use `registerScopedService`.
|
||||||
|
|
||||||
|
## Red lines (this stage)
|
||||||
|
|
||||||
|
- No `new` on a class whose constructor carries `@IService` deps — inject or `accessor.get(IX)`.
|
||||||
|
- `@IX` decorates constructor params only; parameter order depends on construction (static-first for `createInstance`, `@IX`-first for scoped services — see service-authoring.md).
|
||||||
|
- Both interface and impl carry `_serviceBrand`; the `createDecorator` name is globally unique.
|
||||||
|
- `ServicesAccessor` is valid only during `invokeFunction` — never stash it for async use.
|
||||||
|
- No cyclic dependencies — refactor (extract / event / re-scope); activation does not change cycle detection.
|
||||||
77
.agents/skills/agent-core-dev/orient.md
Normal file
77
.agents/skills/agent-core-dev/orient.md
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
# Stage 1 — Orient
|
||||||
|
|
||||||
|
Understand the DI × Scope black box and the file conventions before touching business code.
|
||||||
|
|
||||||
|
## The DI black box
|
||||||
|
|
||||||
|
When writing business code you declare three things; the container handles the rest (when to construct, whether it is the same instance, ordering, disposal):
|
||||||
|
|
||||||
|
- **Who am I** — an identity that is both a runtime key and a compile-time type.
|
||||||
|
- **Whom do I need** — the dependencies that provide my capabilities.
|
||||||
|
- **How long do I live** — which lifetime tier I belong to.
|
||||||
|
|
||||||
|
Classes talk only to interfaces and never care how an implementation is constructed.
|
||||||
|
|
||||||
|
## The four `LifecycleScope` tiers
|
||||||
|
|
||||||
|
Lifetimes form a tree, from longest to shortest:
|
||||||
|
|
||||||
|
```text
|
||||||
|
App process-wide, single global instance
|
||||||
|
└── Workspace one workspace handler (a materialized workspace root)
|
||||||
|
└── Session one session
|
||||||
|
└── Agent one agent
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// src/app/scopes.ts — the business layer declares the tiers and their order;
|
||||||
|
// the DI kernel only knows opaque string kinds plus the declared topology.
|
||||||
|
export enum LifecycleScope {
|
||||||
|
App = 'app',
|
||||||
|
Workspace = 'workspace',
|
||||||
|
Session = 'session',
|
||||||
|
Agent = 'agent',
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Later in the topology = shorter life = closer to a leaf.
|
||||||
|
- "Singleton" means **one per scope**: `ILogService` is global once; each `Session` scope has its own `ISessionMetadata`.
|
||||||
|
- `kind` must advance along the declared topology in the parent→child direction.
|
||||||
|
|
||||||
|
### Visibility rule
|
||||||
|
|
||||||
|
A child scope sees its ancestors; a parent never sees its children. Resolution walks *up* the tree:
|
||||||
|
|
||||||
|
- ✅ An `Agent` service injects a `Session` or `App` service (found upward).
|
||||||
|
- ❌ An `App` service injects a `Session` service (the parent does not look down, and the child may not exist yet).
|
||||||
|
|
||||||
|
> **Short-lived may inject long-lived; never the reverse.** The tree structure enforces this — it is not a matter of discipline.
|
||||||
|
|
||||||
|
### Disposal order
|
||||||
|
|
||||||
|
Deterministic: **child scopes die first; within one scope, teardown runs in strict reverse registration order, one entry at a time.** The mechanism is the Ledger (`src/_base/lifecycle/`): ordered effect bookkeeping, dual-track (sync + async disposers), serial reverse-order teardown (never parallel), with the teardown reason (`'scope-close' | 'cascade' | 'unload'`) passed through to every disposer. `Disposable` / `DisposableStore` (`src/_base/di/lifecycle.ts`) delegate to it — "reverse construction order" is a Ledger property, not a container convention. Business code declares which tier it lives in and never disposes by hand.
|
||||||
|
|
||||||
|
## Dynamic DI: units and cascades
|
||||||
|
|
||||||
|
Registration is not the end of the story. Every unit a container tracks — static registrations and runtime `provide`s alike — lives in a small state machine owned by the scope's cascade engine (`src/_base/di/cascadeEngine.ts`, one per scope container, orchestrating tree-wide). Vocabulary you will meet in errors, tests, and the debug surface:
|
||||||
|
|
||||||
|
- **Unit states** — `Pending → Activating → Active`, plus `Unloading` during teardown and a sticky `Failed`. A construction failure parks the unit in `Failed` with no auto-retry: resolving it rethrows its error; an explicit `update()` reloads it.
|
||||||
|
- **Waiting area** — a unit whose declared dependencies are missing sits `Pending` and auto-activates when they arrive, including cross-scope wake-up when an ancestor gains the token. An `ondemand` unit counts as available: consumers pull it transitively at materialization.
|
||||||
|
- **Cascade transaction** — every `provide` / `unprovide` / `update` runs as one tree-wide transaction: contagion set from the persistent dependency graph (instance edges, child→parent across scopes) → abort hook → global reverse-topo teardown → apply the change → waiting-area recheck fixpoint → history ring. Static bootstrap shares this path: scope creation submits the kind's whole registration batch as one `provideAll`, so registration order never matters.
|
||||||
|
|
||||||
|
## Import boundaries
|
||||||
|
|
||||||
|
There is no domain-layer numbering — a domain may import any other domain, guided by the dependency-direction judgment in design.md. The only mechanically enforced import boundaries are (`lint:imports`, `scripts/check-import-boundaries.mjs`):
|
||||||
|
|
||||||
|
- v2 never imports v1 (`@moonshot-ai/agent-core` or any subpath).
|
||||||
|
- The kosong subtree (`src/kosong/{contract,protocol,provider,model}`) keeps its strict internal order (`contract ← protocol ← provider/model`), purity bans (no SDKs in `contract`/`protocol`), and the `provider/bases` registration boundary.
|
||||||
|
|
||||||
|
## Comment convention
|
||||||
|
|
||||||
|
`packages/agent-core-v2/AGENTS.md` bans comments: no file headers, no section banners, no statement-level narration — the code is the source of truth. The only exception is JSDoc attached to exported symbols, which flows into the generated `.d.ts` and the consumers' IDE hover. Tooling directives (`eslint-disable`, `@ts-expect-error`, …) are banned too: fix the underlying lint/type problem instead, and put negative type-safety cases in compiler-asserted fixtures. Scope is carried by the filename: `workspace*.ts` = Workspace, `session*.ts` = Session, `agent*.ts` = Agent, no prefix = App (see service-authoring.md).
|
||||||
|
|
||||||
|
## Red lines (this stage)
|
||||||
|
|
||||||
|
- Import via the `#/...` alias (mapped to `src/`); never reach into another domain's internals by relative path.
|
||||||
|
- Short-lived may inject long-lived; never the reverse.
|
||||||
|
- No comments — not file headers, not beside statements; exported-symbol JSDoc is the only exception.
|
||||||
213
.agents/skills/agent-core-dev/permission.md
Normal file
213
.agents/skills/agent-core-dev/permission.md
Normal file
|
|
@ -0,0 +1,213 @@
|
||||||
|
# Topic — Permission
|
||||||
|
|
||||||
|
The target design for the agent-core permission system. Read this when touching `permission`, `permissionMode`, `permissionRules`, or when adding a new permission dimension.
|
||||||
|
|
||||||
|
> **The permission system should be a composable, registrable chain of responsibility (a microkernel).** The kernel only runs the chain in order, first hit wins; concrete permission dimensions (policies) are contributed by their owning Domain Services through a registry; tools only declare standardized resource access (`accesses`) in `resolveExecution`, and generic dimensions consume that metadata.
|
||||||
|
>
|
||||||
|
> **The chain adjudicates risk only.** A policy node answers "how dangerous is this call, and may the user override that judgment?" — its `ask`/`deny` outcomes are always user-overridable. **Harness constraints are not permissions**: a mechanism that limits the agent for its own correctness (plan-mode write guard, AgentSwarm batch exclusivity, btw side-question fork, goal budget rejection) produces a hard deny with no ask channel and no per-call user exemption. Those live in their owning domains as `onBeforeExecuteTool` veto listeners that call `event.veto(...)` (precedent: `goalService.ts`'s budget/stale rejection). Product reviews (plan review, goal-start review) are likewise not permissions: the owning domain intercepts its tool with a cold `event.waitUntil(factory)` and drives the shared `IAgentToolApprovalService` round-trip itself, so the review only starts once no other listener vetoed the call.
|
||||||
|
>
|
||||||
|
> **Do not introduce Casbin** — the hard part here is *decision behavior* (continuations, side effects, RPC, state machines), not "match + scalar decision".
|
||||||
|
|
||||||
|
## 1. Problem definition
|
||||||
|
|
||||||
|
The permission system answers one question: **for each tool call, in the current agent and current mode — allow / deny / ask the user?** Three traits shape the architecture:
|
||||||
|
|
||||||
|
1. **Decisions carry behavior.** Returning `ask` is not an enum value — it is a workflow with an RPC round-trip, hooks, telemetry, state writes, and a continuation; returning `deny` may be the result of running an external hook.
|
||||||
|
2. **Heterogeneous policies.** Some check a tool-name set, some count same-batch `AgentSwarm` calls, some run a hook, some inspect the plan state machine — no uniform `(sub, obj, act)` shape.
|
||||||
|
3. **Multi-agent × multi-mode × external extension.** Different agents / modes need different permissions, and outsiders (org admins, plugins) must contribute rules or behavior in a decoupled way.
|
||||||
|
|
||||||
|
## 2. Current state (v1) at a glance
|
||||||
|
|
||||||
|
Code lives in `packages/agent-core/src/agent/permission/`.
|
||||||
|
|
||||||
|
- **Architecture: ordered chain of responsibility, first hit wins.** `PermissionManager` holds `PermissionPolicy[]`; evaluation iterates in order, the first non-`undefined` result wins.
|
||||||
|
- **`PermissionPolicyResult` is a behavior bundle, not a scalar:** `approve` (with `executionMetadata`), `deny` (with `message`), or `ask` (with `resolveApproval` / `resolveError` continuations).
|
||||||
|
- **11 dimensions, 19 policies**, hardcoded in `policies/index.ts#createPermissionDecisionPolicies()`. Order is a high-to-low safety cascade: external force → structural deny → state-machine deny → static deny → mode allow → session-memory allow → static ask → static allow → flow allow → sensitive-path ask → default allow → fallback ask.
|
||||||
|
- **Resource-access declaration:** tools declare accessed resources in `resolveExecution(input)` via `accesses` (`ToolAccesses`, currently `file` and `all`); generic dimensions read `context.execution.accesses`.
|
||||||
|
|
||||||
|
### v1 pain points the target design fixes
|
||||||
|
|
||||||
|
1. The chain is hardcoded — outsiders cannot contribute.
|
||||||
|
2. `mode` is an `if` inside each policy (`YoloModeApprove` / `AutoModeApprove` self-guard).
|
||||||
|
3. No per-agent chain entry point (only scattered `agent.type === 'sub'` checks).
|
||||||
|
4. No external extension point beyond the single `PreToolUse` hook slot.
|
||||||
|
|
||||||
|
## 3. Why not Casbin
|
||||||
|
|
||||||
|
- **`policy_effect` is unusable** — composition here is a fixed, intentionally hardcoded safety cascade; the real complexity lives in each policy's `evaluate` behavior, which a Casbin expression cannot absorb. Externally tunable safety knobs are already exposed via `mode` + allow/deny/ask rules.
|
||||||
|
- **Flexible priority is unusable** — there is no plugin injection point, no multi-subject/RBAC, and a fixed subject (agent/user), so priority collisions do not arise. Casbin's `(sub, obj, act)`, `g()`, and domains would idle.
|
||||||
|
- **Fundamental mismatch: decisions are not scalars.** `enforce()` maps a request to an effect; agent-core decisions are behavior bundles (continuations, side effects, synthesized results). Even if Casbin computed `ask`, the surrounding behavior would still need to be rewritten — Casbin would degrade to an enum generator.
|
||||||
|
- **When Casbin becomes worth it:** when the hard part is matching semantics itself — role inheritance, domain isolation, ABAC expressions, policies loaded from a DB. Not before.
|
||||||
|
|
||||||
|
## 4. Design-pattern placement
|
||||||
|
|
||||||
|
Permission orchestration is a layered combination, not a single pattern:
|
||||||
|
|
||||||
|
| Layer | Pattern | Role |
|
||||||
|
|---|---|---|
|
||||||
|
| Runtime decision | **Chain of Responsibility** | multiple candidates in order; first hit wins, rest short-circuit |
|
||||||
|
| Single handler | **Strategy** | each policy is an interchangeable "permission adjudication" algorithm |
|
||||||
|
| Assembly / external extension | **Plugin / Microkernel** | minimal kernel + explicit extension points + pluggable policies |
|
||||||
|
| Landing support | **Registry + Factory** | collect plugins; assemble the chain per `(agent, mode)` on demand |
|
||||||
|
|
||||||
|
Casbin = single Strategy + data-driven. This design = multiple Strategies + chain-of-responsibility composition. Behavior-heavy systems must choose the latter — behavior cannot be flattened into data rows.
|
||||||
|
|
||||||
|
## 5. Target design
|
||||||
|
|
||||||
|
### 5.1 Core principles
|
||||||
|
|
||||||
|
1. **The chain encodes "permission dimensions", not "tools".** Adding a tool does not lengthen the chain; only adding a dimension adds a node.
|
||||||
|
2. **Two contribution paths:** high-frequency trivial specifics go through the **data path** (rules); low-frequency new dimensions with behavior go through the **code path** (policies).
|
||||||
|
3. **Guard/review off-chain, risk on-chain:** harness constraints and product reviews ship with their owning domain as `onBeforeExecuteTool` veto listeners (§5.4); risk dimensions contributed by a domain self-register as chain policies in DI, mirroring v2's "domain self-registers tools".
|
||||||
|
4. **Tools declare resources; generic dimensions consume them:** bash/write/read only declare `accesses`; file/security dimensions judge centrally.
|
||||||
|
|
||||||
|
### 5.2 Core abstractions
|
||||||
|
|
||||||
|
```ts
|
||||||
|
type Phase =
|
||||||
|
| 'guard' | 'user-deny' | 'mode' | 'session'
|
||||||
|
| 'user-ask' | 'default' | 'fallback';
|
||||||
|
|
||||||
|
interface PermissionPolicyEntry {
|
||||||
|
name: string;
|
||||||
|
phase: Phase;
|
||||||
|
modes?: PermissionMode[]; // declare which modes this applies in (no more in-evaluate if)
|
||||||
|
agentTypes?: AgentType[];
|
||||||
|
factory: (accessor: ServicesAccessor) => PermissionPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// App scope — collects every domain's registration
|
||||||
|
interface IPermissionPolicyRegistry {
|
||||||
|
register(entry: PermissionPolicyEntry): IDisposable;
|
||||||
|
list(): readonly PermissionPolicyEntry[];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`PermissionPolicyService` (Agent scope) changes from a hardcoded list to "assemble by `(agent, mode)`":
|
||||||
|
|
||||||
|
```ts
|
||||||
|
this.policies = registry.list()
|
||||||
|
.filter(e => !e.modes || e.modes.includes(mode))
|
||||||
|
.filter(e => !e.agentTypes || e.agentTypes.includes(agentType))
|
||||||
|
.sort(byPhaseThenRegistrationOrder)
|
||||||
|
.map(e => e.factory(accessor));
|
||||||
|
```
|
||||||
|
|
||||||
|
Key points:
|
||||||
|
|
||||||
|
- `modes` / `agentTypes` are **declarations** — they lift the `if (mode !== 'yolo') return` out of `YoloModeApprove` into metadata.
|
||||||
|
- `factory`, not `instance`: a node may depend on agent-scoped services (mode, rules) and must be instantiated in the Agent scope — symmetric to `IToolDefinitionRegistry` (App) storing factories and `IToolService` (Agent) instantiating tools.
|
||||||
|
- **Different `(agent, mode)` produce differently-shaped chains** — under yolo the ask/fallback phases are physically filtered out.
|
||||||
|
|
||||||
|
### 5.3 Two contribution paths
|
||||||
|
|
||||||
|
| What is being added | Path | Chain length |
|
||||||
|
|---|---|---|
|
||||||
|
| New tool, new org rule, new user preference ("deny `Bash(curl *)`") | **Data path**: add a `PermissionRule` to an existing node | unchanged |
|
||||||
|
| New cross-cutting behavior (custom approval UI, audit log, new mode) | **Code path**: register a new policy node | +1 |
|
||||||
|
|
||||||
|
Most growth goes through the data path — node count is bounded by "kinds of behavior"; rule count grows with specifics (rule matching is a cheap Set/glob).
|
||||||
|
|
||||||
|
### 5.4 Domain dimensions: guard/review via the executor veto event, policy registration for risk
|
||||||
|
|
||||||
|
**Harness constraints and product reviews no longer live on the chain.** A domain that owns one registers an `onBeforeExecuteTool` veto listener and adjudicates through the event:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// src/plan/planService.ts — constructor
|
||||||
|
constructor(@IAgentToolExecutorService executor, ...) {
|
||||||
|
executor.onBeforeExecuteTool((event) => this.guardToolExecution(event));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- The veto event carries no id and no ordering contract. Listeners answer with `event.veto(result)` (first one wins, ends adjudication), `event.allow()` (final pass, ends everything including the permission gate's own listener), `event.pass(metadata)` (pass with an `executionMetadata` trace, ends nothing), or `event.waitUntil(factory)` (defer to a cold factory).
|
||||||
|
- **Guard** (hard deny): call `event.veto(denyToolExecution(toolApproval.formatDenyMessage(...)))`. An immediate veto suppresses every pending `waitUntil` factory, so a deny can never be preceded by someone else's approval prompt.
|
||||||
|
- **Review** (product approval): intercept the tool with `event.waitUntil(() => ...requestToolApproval(event, ask, origin))`. The factory is cold — the executor only invokes it after every listener ran without a veto or an allow, so the review's Interaction starts only once the call is otherwise clear to proceed; abstain (no statement) for every case you do not review so user rules still apply.
|
||||||
|
- **Plain allow**: do NOT `allow()` casually — prefer putting the tool in `default-tool-approve`'s whitelist so user deny/ask rules keep their precedence; reserve `allow()` for cases like the plan-file write guard that must bypass even the permission chain.
|
||||||
|
|
||||||
|
**Risk dimensions contributed by a domain still go through the chain** (the registry path below): a domain whose state changes the *risk* verdict registers its policy via `IPermissionPolicyRegistry`, mirroring v2's "domain self-registers tools". A complex domain may register a single **composite** node externally and run a small internal chain, hiding its internal order from the global chain.
|
||||||
|
|
||||||
|
### 5.5 Tools declare resources at runtime (`resolveExecution` / `accesses`)
|
||||||
|
|
||||||
|
In `resolveExecution(input)`, before execution, declare accessed resources with the `ToolAccesses.*` builders:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
resolveExecution(args: WriteInput): ToolExecution {
|
||||||
|
const path = resolvePathAccessPath(args.path, { kaos, workspace, operation: 'write' });
|
||||||
|
return {
|
||||||
|
accesses: ToolAccesses.writeFile(path), // declares: write this file
|
||||||
|
approvalRule: literalRulePattern(this.name, path),
|
||||||
|
matchesRule: (ruleArgs) => matchesPathRuleSubject(ruleArgs, path, ...),
|
||||||
|
execute: () => this.execution(args, path),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Current resource types:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
type ToolResourceAccess =
|
||||||
|
| { kind: 'file'; operation: 'read'|'write'|'readwrite'|'search'; path: string; recursive?: boolean }
|
||||||
|
| { kind: 'all' }; // non-enumerable side effects (pessimistic, globally exclusive)
|
||||||
|
```
|
||||||
|
|
||||||
|
Two complementary channels:
|
||||||
|
|
||||||
|
- **Enumerable resources** (write/read/edit/grep/glob) → use `accesses`; generic file dimensions cover them automatically.
|
||||||
|
- **Non-enumerable resources** (bash running arbitrary commands) → do not declare `accesses`; use the `matchesRule` DSL (e.g. `Bash(rm *)` globs by command string).
|
||||||
|
|
||||||
|
**kaos's role:** kaos is the execution-environment abstraction (fs/process/pathClass) used by the file dimension for path normalization and judgment — it is **not** the permission-dimension abstraction itself. Permission semantics live one layer above kaos, at "file access".
|
||||||
|
|
||||||
|
**v2 evolution:** extend the `ToolResourceAccess` union so non-file resources can be declared structurally:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
type ToolResourceAccess =
|
||||||
|
| { kind: 'file'; operation: FileOp; path: string; recursive?: boolean }
|
||||||
|
| { kind: 'network'; operation: 'connect'; host: string }
|
||||||
|
| { kind: 'shell'; command: string }
|
||||||
|
| { kind: 'datastore'; operation: 'read'|'write'; table: string }
|
||||||
|
| { kind: 'all' };
|
||||||
|
```
|
||||||
|
|
||||||
|
Each new resource kind can pair with a generic dimension that consumes it; tools always only **declare**.
|
||||||
|
|
||||||
|
### 5.6 Dimension ownership
|
||||||
|
|
||||||
|
| Dimension | Owner | Type |
|
||||||
|
|---|---|---|
|
||||||
|
| external hook veto | `externalHooks` domain | generic |
|
||||||
|
| tool-batch exclusivity | `swarm` domain — `onBeforeExecuteTool` veto listener | harness constraint (off-chain) |
|
||||||
|
| plan-mode write guard | `plan` domain — `onBeforeExecuteTool` veto listener | harness constraint (off-chain) |
|
||||||
|
| plan review | `plan` domain — same listener's `waitUntil` + `toolApproval` | product review (off-chain) |
|
||||||
|
| goal-start review | `goal` domain — veto listener's `waitUntil` + `toolApproval` | product review (off-chain) |
|
||||||
|
| goal budget / stale rejection | `goal` domain — `onBeforeExecuteTool` veto listener | harness constraint (off-chain) |
|
||||||
|
| btw tool disablement | `btw` domain — veto listener on the fork | harness constraint (off-chain) |
|
||||||
|
| runtime-mode posture (auto/yolo) | `permissionMode` domain (chain nodes, pending the level×routing split) | generic |
|
||||||
|
| static config rules | `permissionRules` domain | generic (data path) |
|
||||||
|
| session approval memory | `permissionRules` domain | generic |
|
||||||
|
| sensitive / special paths | generic "file-access/security" dimension | generic (consumes `accesses`) |
|
||||||
|
| tool intrinsic risk | core permission (`default-tool-approve`) | generic (consumes tool declarations) |
|
||||||
|
| workspace write trust | generic "file-access/security" dimension | generic (consumes `accesses`) |
|
||||||
|
| fallback | core permission | generic |
|
||||||
|
| approval round-trip | `toolApproval` domain — shared by gate asks and domain reviews | infrastructure |
|
||||||
|
|
||||||
|
Pattern: **harness constraints and reviews ship with their owning domain as `onBeforeExecuteTool` veto listeners; risk dimensions ship as chain policies (self-registered once the registry lands); generic dimensions register centrally and apply across tools via the declared `accesses`.**
|
||||||
|
|
||||||
|
## 6. Evolution path
|
||||||
|
|
||||||
|
Incremental, not big-bang:
|
||||||
|
|
||||||
|
1. ~~**Sink domain dimensions.**~~ **Done** — plan guard/review, goal-start review, swarm batch exclusivity, and btw deny-all moved out of the chain into their owning domains as `onBeforeExecuteTool` veto listeners (immediate `veto` / `allow` / `pass` statements plus cold `waitUntil` factories for approval round-trips); the shared approval round-trip was extracted to `IAgentToolApprovalService`; `registerPolicy` was removed (btw was its only production user). The chain now holds 12 risk-adjudication nodes only.
|
||||||
|
2. **Level × routing split.** Separate "risk level" (read-only / read-write / yolo posture — what `yolo-mode-approve` really is) from "interaction routing" (what `auto-mode-approve` / `auto-mode-ask-user-question-deny` really are: route permission asks and reviews without the user). The routing layer lands on the `session/approval` broker; the three remaining mode policies leave the chain here.
|
||||||
|
3. **Registry + Composer.** Replace the hardcoded `new`s in `PermissionPolicyService` with reads from `IPermissionPolicyRegistry`; lift mode guards into `modes` metadata. Chain shape becomes selectable per `(agent, mode)` and externally extensible.
|
||||||
|
4. **(On demand) extend resource types.** When non-file resources (network/DB/shell) need structural dimensions, extend the `ToolResourceAccess` union.
|
||||||
|
5. **(On demand) swap the matching kernel for Casbin.** Only when external rules genuinely need RBAC/ABAC semantics, swap the data-path rule-matching kernel for Casbin. Not before.
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- Do not introduce Casbin — decisions are behavior bundles, not scalar effects.
|
||||||
|
- The chain adjudicates risk only. A node whose deny/ask the user cannot per-call exempt is a harness constraint: implement it as an `onBeforeExecuteTool` veto listener in the owning domain (`event.veto(...)` / `event.allow()`), never as a chain policy.
|
||||||
|
- Product reviews (plan/goal) are not permissions either: the owning domain intercepts its tool with a cold `event.waitUntil(factory)` and drives `IAgentToolApprovalService` itself; the gate only handles chain asks.
|
||||||
|
- The chain encodes dimensions, not tools: a new tool must not lengthen the chain.
|
||||||
|
- New specifics go through the data path (rules); only new risk behavior goes through the code path (a policy node).
|
||||||
|
- Tools only declare `accesses`; generic dimensions consume them. kaos is the execution environment, not the permission abstraction.
|
||||||
|
- Use `factory` (Agent-scope instantiation), not `instance`, for registered policies.
|
||||||
204
.agents/skills/agent-core-dev/persistence.md
Normal file
204
.agents/skills/agent-core-dev/persistence.md
Normal file
|
|
@ -0,0 +1,204 @@
|
||||||
|
# Topic — Persistence layering
|
||||||
|
|
||||||
|
How business code persists data in `agent-core-v2`: the three-layer model (`Store → Storage → backend`), the naming rules for each layer, and how to decide which layer a domain should depend on. Read this before adding any persistence to a domain.
|
||||||
|
|
||||||
|
A domain `I{Domain}EntityService` is a business facade over these layers, not a replacement for them. Before naming or bundling EntityServices by `session` / `agent` / `turn`, read [domain-boundaries.md](domain-boundaries.md).
|
||||||
|
|
||||||
|
## The three-layer model
|
||||||
|
|
||||||
|
Persistence is split into three layers, each hiding one kind of change:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Business Service
|
||||||
|
│ inject
|
||||||
|
▼
|
||||||
|
┌────────────────────────────────────────┐
|
||||||
|
│ Store (semantic layer) │ ← access-pattern facade
|
||||||
|
│ IAppendLogStore / IAtomicDocumentStore│ append-log / atomic-doc / blob
|
||||||
|
└────────────────────────────────────────┘
|
||||||
|
│ inject
|
||||||
|
▼
|
||||||
|
┌────────────────────────────────────────┐
|
||||||
|
│ Storage (byte layer) │ ← byte primitives
|
||||||
|
│ IFileSystemStorageService │ read/write/append/list/delete
|
||||||
|
└────────────────────────────────────────┘
|
||||||
|
│ implements
|
||||||
|
▼
|
||||||
|
┌────────────────────────────────────────┐
|
||||||
|
│ Backend (deployment-specific) │ ← File / Postgres / Redis / S3
|
||||||
|
│ FileStorageService / PostgresStorage │
|
||||||
|
└────────────────────────────────────────┘
|
||||||
|
│ uses
|
||||||
|
▼
|
||||||
|
┌────────────────────────────────────────┐
|
||||||
|
│ Platform primitives │ ← hostFs / dbClient / redisClient
|
||||||
|
└────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
Each layer hides exactly one concern:
|
||||||
|
|
||||||
|
| Layer | Hides | Business code sees |
|
||||||
|
|---|---|---|
|
||||||
|
| **Store** | how an access pattern works (append-log reads, atomic-doc serialization) | "append this record" / "save this document" |
|
||||||
|
| **Storage** | byte primitives (atomic write, ordered append, prefix list) | `read/write/append/list/delete` over `(scope, key)` |
|
||||||
|
| **Backend** | deployment environment (file vs DB vs Redis vs S3) | nothing — chosen at the composition root |
|
||||||
|
|
||||||
|
## The one-sentence rule
|
||||||
|
|
||||||
|
> **Business code expresses *what* to store or fetch, never *how* to store it.**
|
||||||
|
|
||||||
|
If business code contains any "how to persist" detail, it has punched through the layer it should depend on:
|
||||||
|
|
||||||
|
| Business code contains | It has punched through | Depend on instead |
|
||||||
|
|---|---|---|
|
||||||
|
| `INSERT INTO …` / `SELECT …` | Storage + backend | a Store |
|
||||||
|
| file paths / `rename` / `fsync` | Storage | Storage or a Store |
|
||||||
|
| `JSON.parse` / `JSON.stringify` | Store (serialization) | `IAtomicDocumentStore` |
|
||||||
|
| append offsets / sequential cursors | Store (log semantics) | `IAppendLogStore` |
|
||||||
|
| `hash(data)` used as a key | Store (blob semantics) | `IBlobStore` |
|
||||||
|
| `pathe.join / relative / basename` on `homeDir` etc. | Bootstrap (path layout) | `IBootstrapService.scope(...)` / scope contexts |
|
||||||
|
| only `read/write/list/delete` on bytes | nothing — this is the byte layer | `IFileSystemStorageService` directly ✅ |
|
||||||
|
|
||||||
|
## Where scopes come from — `IBootstrapService` and scope contexts
|
||||||
|
|
||||||
|
Business code **never assembles scope strings from paths**. Scope strings come from three places:
|
||||||
|
|
||||||
|
1. **`IBootstrapService.scope(name)`** — well-known top-level scopes (`'config' | 'sessions' | 'blobs' | 'store' | 'logs' | 'cache' | 'credentials'`). App-scope, deployment-agnostic contract.
|
||||||
|
2. **`ISessionContext.scope(subKey?)`** — persistence scope rooted at the current session; `scope('agents/main')` etc.
|
||||||
|
3. **`IAgentScopeContext.scope(subKey?)`** — persistence scope rooted at the current agent; `scope('cron')`, `scope('blobs')` etc.
|
||||||
|
|
||||||
|
The bootstrap layer decides how each semantic scope maps to concrete addressing. In the file deployment, `FileBootstrapService` reads a `ResolvedEnvironment` (the paths bag) and returns homeDir-relative scopes; a server deployment could bind a different `IBootstrapService` implementation that maps `'sessions'` to a DB table without any business change.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// ❌ Wrong — path arithmetic on homeDir/sessionDir leaks the file layout
|
||||||
|
const scope = relative(bootstrap.homeDir, join(session.sessionDir, 'agents', agentId, 'cron'));
|
||||||
|
|
||||||
|
// ✅ Right — the agent already knows its own scope root
|
||||||
|
const scope = agentCtx.scope('cron');
|
||||||
|
```
|
||||||
|
|
||||||
|
Absolute paths (`sessionDir`, `agentHomedir`) are still available on `IBootstrapService` for the very small number of legacy APIs that expose on-disk paths (session log rotation, background task tail file). Prefer scope strings; ask before adding a new absolute-path caller.
|
||||||
|
|
||||||
|
## Which layer to depend on — decision tree
|
||||||
|
|
||||||
|
```text
|
||||||
|
Need to persist
|
||||||
|
│
|
||||||
|
├─ read-whole / write-whole, JSON-serializable?
|
||||||
|
│ └─ IAtomicDocumentStore
|
||||||
|
│
|
||||||
|
├─ append-only writes / sequential reads, independent records?
|
||||||
|
│ └─ IAppendLogStore
|
||||||
|
│
|
||||||
|
├─ large object, addressed by content hash?
|
||||||
|
│ └─ IBlobStore
|
||||||
|
│
|
||||||
|
├─ custom byte layout (index / cache / binary) that read/write/list cover?
|
||||||
|
│ └─ IFileSystemStorageService directly
|
||||||
|
│
|
||||||
|
├─ new, reusable access semantics (multi-field query / time-range / graph)?
|
||||||
|
│ └─ add a new Store; business depends on the Store
|
||||||
|
│
|
||||||
|
└─ business-specific, trivial, one or two lines?
|
||||||
|
└─ IFileSystemStorageService directly; if it grows, extract a private Store
|
||||||
|
```
|
||||||
|
|
||||||
|
## Naming — Store by access pattern, not by business
|
||||||
|
|
||||||
|
A Store abstracts an **access pattern**, not a business data type. Name it after the pattern so its reusability is obvious from the name.
|
||||||
|
|
||||||
|
| Access pattern | Store name | Backend examples |
|
||||||
|
|---|---|---|
|
||||||
|
| append-log (append / sequential read) | `IAppendLogStore` | `FileAppendLogStore` / `PostgresAppendLogStore` |
|
||||||
|
| atomic-document (read/write whole) | `IAtomicDocumentStore` | `FileDocumentStore` / `RedisDocumentStore` |
|
||||||
|
| blob (hash-addressed large object) | `IBlobStore` | `FileBlobStore` / `S3BlobStore` |
|
||||||
|
|
||||||
|
**Do not name a generic Store after a business concept.** `IRecordStore` / `IConfigStore` make a reusable access pattern look like a private store for one feature. Any domain that needs an append-log uses `IAppendLogStore`; any domain that needs an atomic document uses `IAtomicDocumentStore`.
|
||||||
|
|
||||||
|
**Exception — business-specific Stores are named after the business.** When a Store captures one domain's unique query semantics (not a generic access pattern), name it after the domain:
|
||||||
|
|
||||||
|
```text
|
||||||
|
ISessionIndex query / enumerate sessions by workspace ← business-specific
|
||||||
|
```
|
||||||
|
|
||||||
|
Test: is the Store's semantics a *generic access pattern* (append-log / atomic-doc / blob) or *one domain's unique query*? Generic → name by pattern; unique → name by domain.
|
||||||
|
|
||||||
|
## Storage — a filesystem-specific byte layer
|
||||||
|
|
||||||
|
The byte layer is a single `IFileSystemStorageService` interface (read / readStream / write / append / list / delete / watch / flush / close). As the name says, it is **filesystem-specific**: it exposes the two irreducible durable primitives a local filesystem implements optimally — atomic whole-value replacement (`write`, via tmp + rename) and ordered durable extension (`append`, via `open('a')`). The node-fs Store backends (`AppendLogStore`, `JsonAtomicDocumentStore`, `BlobStoreService`) are built on it.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface IFileSystemStorageService {
|
||||||
|
read(scope: string, key: string): Promise<Uint8Array | undefined>;
|
||||||
|
readStream(scope: string, key: string): AsyncIterable<Uint8Array>;
|
||||||
|
write(scope: string, key: string, data: Uint8Array, options?: { atomic?: boolean }): Promise<void>;
|
||||||
|
append(scope: string, key: string, data: Uint8Array, options?: { durable?: boolean }): Promise<void>;
|
||||||
|
list(scope: string, prefix?: string): Promise<readonly string[]>;
|
||||||
|
delete(scope: string, key: string): Promise<void>;
|
||||||
|
watch?(scope: string, key: string): Event<void>;
|
||||||
|
flush(): Promise<void>;
|
||||||
|
close(): Promise<void>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Two backends implement it today, both bound at the composition root:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Production — local filesystem rooted at homeDir
|
||||||
|
collection.set(IFileSystemStorageService, new FileStorageService(homeDir));
|
||||||
|
|
||||||
|
// Tests — in-memory backend seeded by the test harness
|
||||||
|
collection.set(IFileSystemStorageService, new InMemoryStorageService());
|
||||||
|
```
|
||||||
|
|
||||||
|
**Non-filesystem backends (Postgres, S3, Redis) do not implement this interface.** Atomic-rename and byte-append have no native equivalent in those stores, so they implement the **Store** interfaces directly via their own clients instead:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Server profile — append-logs on Postgres, atomic documents on Redis.
|
||||||
|
// Each Store is backed by a native client; IFileSystemStorageService is not involved.
|
||||||
|
collection.set(IAppendLogStore, new PostgresAppendLogStore(db, 'records'));
|
||||||
|
collection.set(IAtomicDocumentStore, new RedisDocumentStore(redis, 'config'));
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the `scope` parameter to express **business namespace** within a backend. Do not overload `scope` to route backends — bind a different Store implementation at the composition root instead.
|
||||||
|
|
||||||
|
## Store `acquire(scope, key)` — flush-on-dispose handle
|
||||||
|
|
||||||
|
Stores that buffer writes expose an `acquire(scope, key)` handle so a business can flush them on disposal:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface IAppendLogStore {
|
||||||
|
// …
|
||||||
|
/**
|
||||||
|
* Acquire a disposable handle for `(scope, key)`. Register it with your
|
||||||
|
* `Disposable` (via `this._register(...)`); when you are disposed, pending
|
||||||
|
* appends for that log are flushed. The shared store itself is not disposed.
|
||||||
|
*/
|
||||||
|
acquire(scope: string, key: string): IDisposable;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`IAppendLogStore.acquire` flushes the log's pending appends on dispose — it exists because `append` is fire-and-forget. `IAtomicDocumentStore.acquire` is a no-op today (atomic documents are durable on write) and exists for interface symmetry. Businesses that do not need flush-on-dispose simply do not call `acquire`.
|
||||||
|
|
||||||
|
## When the byte layer does not apply
|
||||||
|
|
||||||
|
`IFileSystemStorageService` covers only the local-filesystem byte primitives. It is not a universal storage abstraction:
|
||||||
|
|
||||||
|
- **Non-filesystem backends** (Postgres / S3 / Redis) implement the **Store** interfaces directly via native clients — they never implement `IFileSystemStorageService`.
|
||||||
|
- **Blobs** are a Store-level interface (`IBlobStore`) with their own backends; the node-fs `BlobStoreService` sits on `IFileSystemStorageService`, but an `S3BlobStore` would not.
|
||||||
|
- **A backend has a fast primitive the Store interface cannot express** (e.g. Postgres `COPY`) → as an exception, extend that backend's Store implementation directly. This is an exception, not the default.
|
||||||
|
|
||||||
|
## Platform primitives are deployment-coupled, not core abstractions
|
||||||
|
|
||||||
|
`hostFs` (local filesystem) is a **platform primitive** used only by local backends (`FileStorageService`, `LocalFileSystemBackend`, `LocalSkillCatalog`, `HostFolderBrowser`). It is **not** a core abstraction and must not appear in business-domain dependency graphs. A server deployment swaps those backends for DB / S3 implementations and never registers `hostFs`.
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- Business code never contains "how to persist" details (serialization / paths / SQL / append offsets) — if it does, drop a layer.
|
||||||
|
- Business code never assembles scope strings from paths (`pathe.join / relative / basename` on `homeDir` / `sessionDir` / …). Use `IBootstrapService.scope(name)` for well-known scopes, `ISessionContext.scope(subKey?)` for session-rooted scopes, and `IAgentScopeContext.scope(subKey?)` for agent-rooted scopes.
|
||||||
|
- Name generic Stores by access pattern (`IAppendLogStore` / `IAtomicDocumentStore` / `IBlobStore`), never by business concept (`IRecordStore` / `IConfigStore`).
|
||||||
|
- Business-specific Stores (unique query semantics) are named after the domain (`ISessionIndex`).
|
||||||
|
- `IFileSystemStorageService` is the filesystem byte-layer interface; non-filesystem backends implement the **Store** interfaces directly. Route backends by binding a different Store implementation at the composition root, not by overloading `scope`.
|
||||||
|
- `hostFs` is a local-only platform primitive; business domains must not import `node:fs` or `hostFs` directly.
|
||||||
|
- Only the file-backed bootstrap (`FileBootstrapService`) and file backends import `pathe`; business domains do not.
|
||||||
|
- Do not create a pass-through `Store` that only forwards `read/write` — a Store must hide a real access-pattern concern, or it is noise; use `IFileSystemStorageService` directly instead.
|
||||||
253
.agents/skills/agent-core-dev/server-align.md
Normal file
253
.agents/skills/agent-core-dev/server-align.md
Normal file
|
|
@ -0,0 +1,253 @@
|
||||||
|
# Subskill — Server align (expose `agent-core-v2` over `server-v2`)
|
||||||
|
|
||||||
|
Wire a v2 domain into `packages/kap-server`, and — when the endpoint is part of the established `/api/v1` wire contract — keep the wire shape **byte-for-byte compatible** with what released v1 clients expect. This is the server-side counterpart of [align.md](align.md): `align.md` ports v1 *business logic* into v2; this file exposes the v2 result over HTTP / WS, reusing the v1 wire contract where it already exists.
|
||||||
|
|
||||||
|
Use this when the task is "expose the new v2 Service on the server", "add a `/sessions/:sid/...` route to the `/api/v1` surface", or "keep server-v2 speaking the same `/api/v1` contract released clients rely on".
|
||||||
|
|
||||||
|
## The one-paragraph mental model
|
||||||
|
|
||||||
|
`server-v2` serves **two HTTP surfaces** off the same `agent-core-v2` scope tree:
|
||||||
|
|
||||||
|
- **`/api/v2/:sa`** — the native v2 RPC surface, driven by the `actionMap` allowlist (`packages/kap-server/src/transport/actionMap.ts`). One `resource:action` segment maps to one `Service.method`. New v2-native capabilities land here. See [edge-exposure.md](edge-exposure.md).
|
||||||
|
- **`/api/v1/...`** — the v1-compatible surface, hand-written routes in `packages/kap-server/src/routes/*.ts` that **implement the established v1 wire contract path-for-path and schema-for-schema**, mounted by `registerApiV1Routes.ts`. This surface IS the v1 contract now (the legacy v1 server is gone); it exists so existing v1 clients keep working against server-v2 unchanged.
|
||||||
|
|
||||||
|
The two surfaces can point at **different Services** for the same feature. v2's native `IAgentPromptService` serves `/api/v2`; a v1-shaped `IAgentPromptService` serves `/api/v1`. Keeping them separate is what lets v2's domain design stay clean while the wire stays compatible.
|
||||||
|
|
||||||
|
## Decision: which surface?
|
||||||
|
|
||||||
|
```text
|
||||||
|
Is the endpoint part of the established /api/v1 wire contract (protocol schema
|
||||||
|
+ released-client expectation)?
|
||||||
|
├─ YES → /api/v1 mirror route (this file, §schema-fidelity + §legacy-service).
|
||||||
|
│ Reuse the protocol schema; add a LegacyService if v2 semantics diverge.
|
||||||
|
└─ NO → /api/v2 native action (edge-exposure.md).
|
||||||
|
Add to actionMap, wrapping in a facade if the method fails §2 there.
|
||||||
|
```
|
||||||
|
|
||||||
|
A feature often needs **both**: the v1 mirror so old clients keep working, and the v2 action so new clients get the cleaner shape. Do them as two routes / two action-map entries over the same scope tree.
|
||||||
|
|
||||||
|
## The server-align workflow
|
||||||
|
|
||||||
|
```text
|
||||||
|
Pick surface → Read the v1 route (if any) → Reuse / add the protocol schema
|
||||||
|
→ Choose native Service vs LegacyService → Wire the route / actionMap entry
|
||||||
|
→ Map errors → Test against the v1 wire shape → Verify
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1. Pick the surface
|
||||||
|
|
||||||
|
Apply the decision above. For a v1-matched endpoint, the **spec** is the protocol schema plus the existing mirror routes:
|
||||||
|
|
||||||
|
- `packages/kap-server/src/protocol/rest-<resource>.ts` — the wire schema you must match.
|
||||||
|
- `packages/kap-server/src/routes/<resource>.ts` — the file you are writing (create it if missing); sibling route files show the conventions.
|
||||||
|
|
||||||
|
The protocol schema is the source of truth. Do not re-derive the wire shape from memory or from the v2 domain model.
|
||||||
|
|
||||||
|
### 2. Reuse (or add) the protocol schema
|
||||||
|
|
||||||
|
The wire schema lives in **`packages/kap-server/src/protocol`** under `rest-<resource>.ts` (e.g. `promptSubmissionSchema`, `promptListResponseSchema`, `configResponseSchema`) — or in the owning `agent-core-v2` domain contract when the engine's service speaks the shape. Every `/api/v1` route in `packages/kap-server` imports from it — that single import is what guarantees the server speaks the same shape released clients expect.
|
||||||
|
|
||||||
|
Actions:
|
||||||
|
|
||||||
|
- **Schema already in protocol** → import it in the server-v2 route and use it in `defineRoute` (`body`, `success.data`, error `dataSchema` / `detailsSchema`). Do **not** re-declare the schema inline in server-v2.
|
||||||
|
- **Schema missing** → add it to `packages/kap-server/src/protocol/rest-<resource>.ts` first (or to the owning v2 domain contract if its service speaks the shape), then consume it from the route. The shared schema is the source of truth; server-v2 never re-declares a v1 wire schema inline.
|
||||||
|
- **Schema exists but only v1 uses it** → keep it in `packages/kap-server/src/protocol` and import it into server-v2; do not fork a copy.
|
||||||
|
|
||||||
|
#### Schema-fidelity rule (the hard rule)
|
||||||
|
|
||||||
|
For a `/api/v1` endpoint, the request and response schemas **must be the established protocol schema** (or a strict superset):
|
||||||
|
|
||||||
|
- ✅ **Adding** an optional field is allowed (`field: z.string().optional()`). Old clients ignore it; new clients may send it.
|
||||||
|
- ❌ **Renaming** a field, **changing** its type, **tightening** its validation, or **changing its meaning** is a wire break — do not do it in a mirror route. If the v2 domain genuinely needs a different shape, that shape belongs on `/api/v2`, not on the `/api/v1` mirror.
|
||||||
|
- ❌ Re-declaring the schema inline in server-v2 (even if it "looks identical") is forbidden — it drifts. One schema, one home: the owning `agent-core-v2` domain contract or `packages/kap-server/src/protocol`.
|
||||||
|
|
||||||
|
Self-check: "would a released v1 client get a byte-identical envelope from `packages/kap-server` for this request?" If you cannot answer yes from the shared schema, the route is wrong.
|
||||||
|
|
||||||
|
### 3. Choose native Service vs LegacyService
|
||||||
|
|
||||||
|
Resolve the v2 Service that will back the route. Two cases:
|
||||||
|
|
||||||
|
**Case A — the v2 native Service already matches the v1 contract.** Use it directly. Most data/command Services (`IConfigService`, `IWorkspaceService`, `IApprovalService`, `IQuestionService`, `IFileStore`, …) land here: the route is a thin adapter that resolves the scope, calls the method, and wraps the result. Examples: `routes/config.ts`, `routes/messages.ts`, `routes/questions.ts`, `routes/files.ts`.
|
||||||
|
|
||||||
|
**Case B — the v1 contract needs behavior that would distort the v2 domain.** Introduce a **`*LegacyService`** — an edge adapter that implements the v1 contract **on top of** the v2 native Service, leaving the native Service untouched. The v2 native Service keeps serving `/api/v2`; the LegacyService serves `/api/v1`.
|
||||||
|
|
||||||
|
Reach for a LegacyService when **any** hold:
|
||||||
|
|
||||||
|
- The v1 endpoint carries state the v2 domain deliberately dropped (e.g. a FIFO queue, a `prompt_id`, idempotent `abort`/`steer`, auto-start-next).
|
||||||
|
- The v1 method returns a handle/stream that v2 wraps differently, and the v1 clients expect the old envelope shape.
|
||||||
|
- Matching v1 would force a `Map<sessionId, …>`-at-`App` anti-pattern or a scope/domain-direction violation into the native Service (see [align.md](align.md) red lines).
|
||||||
|
- The native Service's error set / return type would have to grow v1-only branches.
|
||||||
|
|
||||||
|
Do **not** put v1 quirks into the native v2 Service "to keep the route simple". That is the conflict this rule exists to prevent: the native Service serves the v2 architecture; the LegacyService serves the wire contract.
|
||||||
|
|
||||||
|
#### LegacyService recipe
|
||||||
|
|
||||||
|
A LegacyService is a normal v2 Service (service-authoring.md) with one extra convention: its contract is shaped by the **protocol** types, not by the v2 domain model.
|
||||||
|
|
||||||
|
```text
|
||||||
|
packages/agent-core-v2/src/<domain>Legacy/
|
||||||
|
├── <domain>Legacy.ts ← contract: protocol-typed interface + decorator
|
||||||
|
├── <domain>LegacyService.ts ← impl: delegates to the native v2 Service(s)
|
||||||
|
└── errors.ts ← v1-compatible error codes (KimiError codes)
|
||||||
|
```
|
||||||
|
|
||||||
|
Skeleton (matches `prompt/`):
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// prompt.ts — contract shaped by the v1 wire schema (kap-server/src/protocol)
|
||||||
|
import type { PromptSubmitResult, PromptSubmission } from '../../protocol/rest-prompt';
|
||||||
|
import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
|
||||||
|
|
||||||
|
export interface IAgentPromptService {
|
||||||
|
readonly _serviceBrand: undefined;
|
||||||
|
submit(body: PromptSubmission): Promise<PromptSubmitResult>;
|
||||||
|
// ...the rest of the v1 contract, typed by protocol
|
||||||
|
}
|
||||||
|
export const IAgentPromptService: ServiceIdentifier<IAgentPromptService> =
|
||||||
|
createDecorator<IAgentPromptService>('agentPromptLegacyService');
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// promptService.ts — impl delegates to the native v2 Service
|
||||||
|
import { LifecycleScope } from '#/app/scopes';
|
||||||
|
import { ScopeActivation, registerScopedService } from '#/_base/di/scope';
|
||||||
|
|
||||||
|
constructor(@IAgentPromptService private readonly prompt: IAgentPromptService /*, ... */) {}
|
||||||
|
// submit() builds v2-native input, calls the native Service, projects the result
|
||||||
|
// back into the protocol PromptSubmitResult.
|
||||||
|
|
||||||
|
registerScopedService(
|
||||||
|
LifecycleScope.Agent, // scope = the lifetime of the legacy state
|
||||||
|
IAgentPromptService,
|
||||||
|
AgentPromptLegacyService,
|
||||||
|
ScopeActivation.OnDemand,
|
||||||
|
'prompt',
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
Conventions:
|
||||||
|
|
||||||
|
- **Name** the domain `<domain>Legacy` and the interface with the scope prefix, `I<Scope><Domain>LegacyService` (e.g. `prompt` / `IAgentPromptService`), per service-authoring.md.
|
||||||
|
- **Role is carried by the name** — `<domain>Legacy` marks it as an `edge adapter`; the v1 contract it implements and the native v2 Service it leaves untouched stay evident from its delegation targets (see `prompt.ts`).
|
||||||
|
- **Scope** = the lifetime of the *legacy* state it holds (the `prompt` queue is per-agent → `LifecycleScope.Agent`). Apply [orient.md](orient.md) / [design.md](design.md) normally — a LegacyService is not exempt from scope rules.
|
||||||
|
- **Delegate, do not duplicate** business logic. The LegacyService translates the v1 contract into native-Service calls and translates results back; the real work stays in the native Service.
|
||||||
|
- **Contract types come from the v1 wire schema homes** (the owning v2 domain contract or `kap-server/src/protocol`), so the interface cannot drift from the wire shape.
|
||||||
|
|
||||||
|
### 4. Wire the route / actionMap entry
|
||||||
|
|
||||||
|
**For `/api/v1` (mirror):** add a route file under `packages/kap-server/src/routes/<resource>.ts` using `defineRoute`, then register it in `registerApiV1Routes.ts`. Resolve the scope from the URL (`session_id` → Session scope, agent → Agent scope via `IAgentLifecycleService.getHandle`), then `accessor.get(IX)` the native or Legacy Service. Match the established verbs, paths (`:sid` / `{session_id}`), and `parseActionSuffix` actions (`:steer`, `:abort`) exactly — sibling routes under `packages/kap-server/src/routes/` are the reference.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const route = defineRoute(
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/sessions/{session_id}/prompts',
|
||||||
|
body: promptSubmissionSchema, // ← from kap-server/src/protocol
|
||||||
|
params: sessionIdParamSchema,
|
||||||
|
success: { data: promptSubmitResultSchema }, // ← from kap-server/src/protocol
|
||||||
|
errors: {
|
||||||
|
[ErrorCode.SESSION_NOT_FOUND]: {},
|
||||||
|
[ErrorCode.SESSION_BUSY]: {},
|
||||||
|
[ErrorCode.PROMPT_ALREADY_COMPLETED]: { dataSchema: z.object({ aborted: z.literal(false) }) },
|
||||||
|
},
|
||||||
|
operationId: 'submitPrompt',
|
||||||
|
tags: ['prompts'],
|
||||||
|
},
|
||||||
|
async (req, reply) => {
|
||||||
|
try {
|
||||||
|
const result = await resolveLegacy(core, req.params.session_id).submit(req.body);
|
||||||
|
reply.send(okEnvelope(result, req.id));
|
||||||
|
} catch (error) {
|
||||||
|
sendMappedError(reply, req.id, error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
app.post(route.path, route.options, route.handler);
|
||||||
|
```
|
||||||
|
|
||||||
|
**For `/api/v2` (native):** add a `resource:action` entry to `actionMap` ([edge-exposure.md](edge-exposure.md) §3). If the method fails the direct-exposure rules (returns a handle / stream / bytes, takes a live object), add a wire-safe orchestration method to the owning domain Service first — as `prompts:submit` maps to `IAgentPromptService.submit`, which settles `{turn_id}` engine-side instead of returning the live `PromptHandle`.
|
||||||
|
|
||||||
|
### 5. Map errors
|
||||||
|
|
||||||
|
The route translates domain `KimiError` codes into protocol `ErrorCode` numbers. Two registries must stay in sync:
|
||||||
|
|
||||||
|
- **Domain code** — register in `agent-core-v2/src/errors.ts` (`ErrorCodes`) and throw from the Service (errors.md). Co-located domain errors go in `<domain>Legacy/errors.ts` (e.g. `prompt.not_found`, `session.busy`).
|
||||||
|
- **Wire code** — register the matching number in `packages/kap-server/src/protocol/error-codes.ts` and reference it in the route's `errors` map and `sendMappedError`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
function sendMappedError(reply, requestId, err) {
|
||||||
|
if (isKimiError(err)) {
|
||||||
|
switch (err.code) {
|
||||||
|
case 'session.not_found':
|
||||||
|
case 'agent.not_found':
|
||||||
|
return reply.send(errEnvelope(ErrorCode.SESSION_NOT_FOUND, err.message, requestId));
|
||||||
|
case 'prompt.not_found':
|
||||||
|
return reply.send(errEnvelope(ErrorCode.PROMPT_NOT_FOUND, err.message, requestId));
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reply.send(errEnvelope(ErrorCode.INTERNAL_ERROR, String(err), requestId));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Match the v1 route's status codes and idempotent-conflict envelopes (e.g. `prompt.already_completed` → `40903` with `{ data: { aborted: false } }`). The error envelope is part of the wire contract — it is covered by the same schema-fidelity rule.
|
||||||
|
|
||||||
|
### 6. Test against the v1 wire shape
|
||||||
|
|
||||||
|
Add a `packages/kap-server/test/<resource>.test.ts` that boots the server and hits the route. Assert on the **envelope + protocol shape**, not on the v2 domain internals:
|
||||||
|
|
||||||
|
- success envelope `{ code: 0, data: <protocol shape>, request_id }`;
|
||||||
|
- each declared error envelope `{ code: <ErrorCode>, msg, data, request_id }`;
|
||||||
|
- the fields v1 clients read are present with the same names/types.
|
||||||
|
|
||||||
|
Where the route mirrors v1, the test is the regression guard for the schema-fidelity rule: if someone drifts the protocol schema or the projection, this test breaks.
|
||||||
|
|
||||||
|
### 7. Verify
|
||||||
|
|
||||||
|
- `pnpm -C packages/kap-server test` — server routes green.
|
||||||
|
- `pnpm -C packages/kap-server test` — server routes green (incl. any wire-schema guards).
|
||||||
|
- `pnpm -C packages/agent-core-v2 test` — native + Legacy Service tests green.
|
||||||
|
- `pnpm -C packages/agent-core-v2 run lint:imports` — the import boundaries (v1 ban, kosong subtree) still hold for a LegacyService.
|
||||||
|
- `pnpm -C packages/klient test` (optionally with `KIMI_SERVER_URL` for the live legacy suites) when a v1 parity scenario exists.
|
||||||
|
|
||||||
|
## Worked example — porting v1 `/sessions/:sid/prompts`
|
||||||
|
|
||||||
|
This is the reference alignment (commits `feat(server-v2): port v1 /sessions/:sid/prompts routes`, `feat(server-v2): return turn ids for prompt actions`). It shows all three decisions at once.
|
||||||
|
|
||||||
|
**The mismatch.** v1 `IPromptService` is a per-agent *scheduler*: it owns a FIFO queue, assigns `prompt_id`s, supports `steer`/`abort`, and auto-starts the next queued prompt when a turn settles. v2's native `IAgentPromptService` is a *turn driver*: a submission *is* a turn, there is no queue and no `prompt_id`. Forcing the queue into the v2 native Service would distort the v2 domain.
|
||||||
|
|
||||||
|
**The split.**
|
||||||
|
|
||||||
|
- `/api/v2` keeps the native shape — `prompts:submit` / `steer` / `undo` / `clear` / `cancel` map to the domain Services (`IAgentPromptService.submit` / `submitSteer`, `IAgentConversationUndoService.undo`, `IAgentLoopService.cancelFromUser`) in `actionMap`.
|
||||||
|
- `/api/v1` gets an `AgentPromptLegacyService` (`prompt/`, `LifecycleScope.Agent`) that re-implements the v1 scheduler — queue, `prompt_id`, steer/abort, auto-start-next — **on top of** the native `IAgentPromptService`. The `/api/v1` routes consume the LegacyService.
|
||||||
|
|
||||||
|
**The schema.** Both surfaces import `promptSubmissionSchema` / `promptSubmitResultSchema` / `promptListResponseSchema` / `promptSteerRequestSchema` / `promptSteerResultSchema` / `promptAbortResponseSchema` from the shared v1 wire schemas (see `packages/kap-server/src/protocol`). The `/api/v1` and `/api/v2` routes are therefore compatible with released clients by construction; the LegacyService projects v2 turn results back into those protocol shapes.
|
||||||
|
|
||||||
|
**The errors.** v1 codes (`prompt.not_found`, `session.busy`, `prompt.already_completed`) are registered in `agent-core-v2` (`prompt/errors.ts`) and in `packages/kap-server/src/protocol` (`error-codes.ts`), then mapped in the route's `sendMappedError` — including the idempotent `prompt.already_completed` → `40903 { data: { aborted: false } }`.
|
||||||
|
|
||||||
|
**The lesson.** When the v1 contract and the v2 domain disagree, add an adapter (LegacyService) at the edge; do not let the wire contract leak into the native domain. The two surfaces share the protocol schema but not the Service.
|
||||||
|
|
||||||
|
## Migration checklist
|
||||||
|
|
||||||
|
Before submitting a server-align change:
|
||||||
|
|
||||||
|
- [ ] Surface chosen deliberately: `/api/v1` mirror for a v1-matched endpoint, `/api/v2` for a new native capability (both if needed).
|
||||||
|
- [ ] For a `/api/v1` mirror, the route matches the established v1 contract (protocol schema + sibling routes) path-for-path, verb-for-verb, action-for-action.
|
||||||
|
- [ ] Request and response schemas come from their owning home (the `agent-core-v2` domain contract or `packages/kap-server/src/protocol`); no inline re-declaration in server-v2.
|
||||||
|
- [ ] Existing schema fields are unchanged in name, type, and semantics; only optional fields added (if any).
|
||||||
|
- [ ] Native v2 Service left clean; v1-only behavior isolated in a `<domain>Legacy` / `I<Domain>LegacyService` edge adapter when the semantics diverge.
|
||||||
|
- [ ] LegacyService registered with the correct `LifecycleScope` and named as the `<domain>Legacy` edge adapter preserving the native Service.
|
||||||
|
- [ ] Domain error codes registered in `agent-core-v2`; wire codes registered in `packages/kap-server/src/protocol`; route maps them in `sendMappedError`, matching v1's status codes and idempotent envelopes.
|
||||||
|
- [ ] Route resolves the scope from the URL by `accessor.get(IX)`; no cached scope; finishes before disposal.
|
||||||
|
- [ ] Tests assert the wire envelope + protocol shape; wire-shape guards added/updated where the route mirrors v1.
|
||||||
|
- [ ] `lint:imports` passes; the LegacyService did not invert scope direction.
|
||||||
|
|
||||||
|
## Red lines (this subskill)
|
||||||
|
|
||||||
|
- One wire schema, one home: the owning `agent-core-v2` domain contract or `packages/kap-server/src/protocol`. Never re-declare a v1 wire schema inline in server-v2.
|
||||||
|
- A `/api/v1` mirror route must keep every existing schema field's name, type, and semantics; only optional additions are allowed. A different shape belongs on `/api/v2`, not on the mirror.
|
||||||
|
- Do not distort the native v2 Service to satisfy a v1 quirk — add a `<domain>Legacy` edge adapter instead. The native Service serves the v2 architecture; the LegacyService serves the wire contract.
|
||||||
|
- A LegacyService is still a v2 Service: it follows scope, domain-direction, and DI rules. "Edge adapter" describes its role, not an exemption.
|
||||||
|
- The established wire schema (in its owning home — the `agent-core-v2` domain contract or `packages/kap-server/src/protocol`) plus the existing mirror routes are the spec for a `/api/v1` route — match them; do not re-derive the wire shape from the v2 domain model or from memory.
|
||||||
|
- Register every new error code in **both** `agent-core-v2` and `packages/kap-server/src/protocol/error-codes.ts`; an unmapped code is a wire break.
|
||||||
|
- Events stream over WS (`listen`), never over the REST mirror; do not invent REST polling for something v1 pushed as an event.
|
||||||
353
.agents/skills/agent-core-dev/service-authoring.md
Normal file
353
.agents/skills/agent-core-dev/service-authoring.md
Normal file
|
|
@ -0,0 +1,353 @@
|
||||||
|
# Topic — Service authoring
|
||||||
|
|
||||||
|
How to write a Service in `packages/agent-core-v2`: file layout, naming, what goes in the contract vs the impl, interface style, constructor / field conventions, events, multi-Service domains, and the comment rules. This is the day-to-day reference for stage 3 (implement.md covers the DI *mechanics*; this file covers the *authoring details*).
|
||||||
|
|
||||||
|
## File layout
|
||||||
|
|
||||||
|
One folder per domain, **camelCase**: `session/`, `sessionActivity/`, `contextMemory/`, `toolDedup/`. Inside, six kinds of files:
|
||||||
|
|
||||||
|
```text
|
||||||
|
<domain>/
|
||||||
|
├── <name>.ts ← interface file: exactly one IXxx + its createDecorator + the types it owns
|
||||||
|
├── <name>Service.ts ← impl file: exactly one class + exactly one registerScopedService(...)
|
||||||
|
├── <concern>.ts ← pure function(s): no Service suffix, no class, no registration
|
||||||
|
├── <targetDomain>.ts ← contribution file (common): registers into another domain's extension point
|
||||||
|
├── <what>.contrib.ts ← contribution file (uncommon / ad-hoc)
|
||||||
|
└── <domain>.types.ts ← shared types that no single interface owns
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Strictly one service per file.** An interface file holds exactly one injectable interface and exactly one `createDecorator(...)`; an impl file holds exactly one service implementation class and exactly one `registerScopedService(...)`. No exceptions for "tightly-coupled" groups: even same-scope collaborators each get their own `<name>.ts` + `<name>Service.ts` pair.
|
||||||
|
- **Scope is in the filename.** `workspace*.ts` = Workspace, `session*.ts` = Session, `agent*.ts` = Agent, no scope prefix = App (see [Naming](#naming)).
|
||||||
|
- A domain therefore has as many impl files as it has services (e.g. `logService.ts` for the App `ILogService`, `sessionLogService.ts` for the Session `ISessionLogService`). See [Multi-Service domains](#multi-service-domains).
|
||||||
|
|
||||||
|
The package entry `src/index.ts` imports and `export *`s every domain's leaf files precisely (one line per leaf), so importing the package still runs every `registerScopedService(...)` side effect — exactly as the old per-domain barrels did.
|
||||||
|
|
||||||
|
## Naming
|
||||||
|
|
||||||
|
### Interfaces and classes
|
||||||
|
|
||||||
|
| Artifact | Rule | Example |
|
||||||
|
|---|---|---|
|
||||||
|
| Interface | `I` + scope prefix + PascalCase domain + role suffix. Scope prefix: `Workspace` / `Session` / `Agent` / none (= App). Role suffix is usually `Service`. | `IWorkspaceDirs`, `ISessionLogService`, `IAgentLoopService`, `ILogService` (App) |
|
||||||
|
| Class | the interface name minus the leading `I`, plus `Service` if it does not already end in `Service`; `implements` the interface | `SessionLogService implements ISessionLogService`, `AppendLogStoreService implements IAppendLogStore` |
|
||||||
|
| Decorator string | lowerCamelCase of the interface name minus the leading `I`; **globally unique and stable** (it surfaces in `CyclicDependencyError.path` and "no service registered" errors) | `createDecorator<ISessionLogService>('sessionLogService')` |
|
||||||
|
| Model / non-service types | PascalCase, no `I` prefix | `SessionMeta`, `LogEntry`, `ConfigSection` |
|
||||||
|
|
||||||
|
The scope prefix makes a service's lifetime readable from its name. App services carry **no** prefix (App is the default, longest-lived tier); Workspace, Session and Agent services always carry `Workspace` / `Session` / `Agent`. The prefix applies to the interface, the class, and therefore the file names.
|
||||||
|
|
||||||
|
> Do **not** use the scope prefix to re-merge domains by lifetime. `IAgentEntityService`, `IAgentDataService`, and `ISessionEntityService` are still banned — the prefix marks lifetime, the rest of the name must still be the real owning domain (`IBackgroundTaskEntityService`, `ISessionMetadata`, `IPermissionRulesService`). See [domain-boundaries.md](domain-boundaries.md).
|
||||||
|
|
||||||
|
### File names
|
||||||
|
|
||||||
|
File names derive from the interface / class names so that scope and role are visible in the tree:
|
||||||
|
|
||||||
|
| File kind | Rule | Example (interface → file) |
|
||||||
|
|---|---|---|
|
||||||
|
| Interface file | interface name minus leading `I`, minus trailing `Service` if present; acronym-aware lowerCamelCase | `ISessionLogService` → `sessionLog.ts`; `IAppendLogStore` → `appendLogStore.ts`; `ILogService` → `log.ts` |
|
||||||
|
| Impl file | the class name; acronym-aware lowerCamelCase | `SessionLogService` → `sessionLogService.ts`; `AppendLogStoreService` → `appendLogStoreService.ts` |
|
||||||
|
| Pure-function file | the function / concern name; no `Service` suffix | `formatLogEntry.ts`, `levelEnabled.ts` |
|
||||||
|
| Contribution file (common) | the **target** domain name | `config.ts` (registers a config section), `tool.ts`, `flag.ts` |
|
||||||
|
| Contribution file (uncommon) | `<what>.contrib.ts` | `slackWebhook.contrib.ts` |
|
||||||
|
| Shared-types file | `<domain>.types.ts` | `log.types.ts` |
|
||||||
|
| Errors file | `<name>.errors.ts` | `appendLogStore.errors.ts` |
|
||||||
|
|
||||||
|
Acronym-aware lowerCamelCase lowercases a leading acronym as a group: `ILLMRequester` → `llmRequester.ts`, `IWSGateway` → `wsGateway.ts`, `IOAuthToolkit` → `oauthToolkit.ts`, `IMcpServerService` → `mcpServerService.ts`.
|
||||||
|
|
||||||
|
Because the impl class always ends in `Service` and the interface file never does, the two files of one service never collide — even for `Store` / `Registry` / `Resolver` interfaces (`IAppendLogStore` → `appendLogStore.ts` + `appendLogStoreService.ts`).
|
||||||
|
|
||||||
|
## The contract file (`<domain>.ts`)
|
||||||
|
|
||||||
|
Holds the public surface of the domain. A typical contract:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
/**
|
||||||
|
* `greet` domain (Ln) — one-line role.
|
||||||
|
*
|
||||||
|
* Defines the `Greeting` model and the `IGreeter` used by … Bound at … scope.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
|
||||||
|
|
||||||
|
export interface Greeting { // model — no _serviceBrand
|
||||||
|
readonly message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IGreeter { // injectable service — carries _serviceBrand
|
||||||
|
readonly _serviceBrand: undefined;
|
||||||
|
hello(): Greeting;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const IGreeter: ServiceIdentifier<IGreeter> =
|
||||||
|
createDecorator<IGreeter>('greeter');
|
||||||
|
```
|
||||||
|
|
||||||
|
What belongs here:
|
||||||
|
|
||||||
|
- **Model types** (`type` / `interface`) the domain exposes — `SessionMeta`, `LogEntry`, `ConfigSection`.
|
||||||
|
- **Service interface(s)** — the contract consumers depend on.
|
||||||
|
- **Decorator(s)** — one `createDecorator` per injectable service.
|
||||||
|
- **Helper types and pure functions** tightly bound to the contract — e.g. option bags, `satisfies`-checked seeds, predicate functions like `levelEnabled`.
|
||||||
|
|
||||||
|
### Which interfaces carry `_serviceBrand`
|
||||||
|
|
||||||
|
Only interfaces used as a **DI token** carry `readonly _serviceBrand: undefined`. Everything else does not:
|
||||||
|
|
||||||
|
- ✅ Service interface resolved via `@IX` / `accessor.get(IX)` → carries `_serviceBrand`.
|
||||||
|
- ❌ Base interface extended by a service (e.g. `ILogger` extended by `ILogService`) → no `_serviceBrand`.
|
||||||
|
- ❌ Plain model / data interface (`LogEntry`, `SessionMeta`) → no `_serviceBrand`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface ILogger { // base interface — no brand
|
||||||
|
info(message: string): void;
|
||||||
|
}
|
||||||
|
export interface ILogService extends ILogger { // DI token — branded
|
||||||
|
readonly _serviceBrand: undefined;
|
||||||
|
setLevel(level: LogLevel): void;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Interface style
|
||||||
|
|
||||||
|
- **Sync methods** return a concrete type; **async methods** return `Promise<T>`. Do not wrap a sync return in `Promise`.
|
||||||
|
- **Readonly fields** for immutable exposed state: `readonly ready: Promise<void>`, `readonly modelAlias: string | undefined`.
|
||||||
|
- **Optional members** with `?`: `flush?(): Promise<void>`, `close?(): Promise<void>`.
|
||||||
|
- **Generics** where the caller supplies the shape: `get<T = unknown>(domain: string): T`.
|
||||||
|
- **Extend** a base interface to share method groups: `interface ILogService extends ILogger`.
|
||||||
|
- **Events** as `readonly onDid…` / `onWill…` properties typed `Event<T>` — see [Events](#events).
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface IConfigService {
|
||||||
|
readonly _serviceBrand: undefined;
|
||||||
|
readonly ready: Promise<void>;
|
||||||
|
readonly onDidChange: Event<ConfigChangedEvent>;
|
||||||
|
get<T = unknown>(domain: string): T;
|
||||||
|
set(domain: string, patch: unknown): Promise<void>;
|
||||||
|
reload(): Promise<void>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## The impl file (`<domain>Service.ts`)
|
||||||
|
|
||||||
|
Holds the concrete class(es) and the top-level registration. A typical impl:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
/**
|
||||||
|
* `greet` domain (Ln) — `IGreeter` implementation.
|
||||||
|
*
|
||||||
|
* … collaborators as roles ("logs through `log`") … Bound at App scope.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { LifecycleScope } from '#/app/scopes';
|
||||||
|
import { ScopeActivation, registerScopedService } from '#/_base/di/scope';
|
||||||
|
import { ILogService } from '#/log';
|
||||||
|
|
||||||
|
import { type Greeting, IGreeter } from './greet';
|
||||||
|
|
||||||
|
export class Greeter implements IGreeter {
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
|
||||||
|
constructor(@ILogService private readonly log: ILogService) {}
|
||||||
|
|
||||||
|
hello(): Greeting {
|
||||||
|
this.log.info('hello');
|
||||||
|
return { message: 'hi' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerScopedService(LifecycleScope.App, IGreeter, Greeter, ScopeActivation.OnScopeCreated, 'greet');
|
||||||
|
```
|
||||||
|
|
||||||
|
What belongs here:
|
||||||
|
|
||||||
|
- **Imports** — `LifecycleScope` + `ScopeActivation` + `registerScopedService` from `'#/_base/di/scope'`; collaborators via the `#/<domain>` alias; the contract's types + decorator via a relative `./<domain>` import.
|
||||||
|
- **Class** — `XxxService implements IXxxService`, with `declare readonly _serviceBrand: undefined`.
|
||||||
|
- **Helper classes / functions** used only by this impl (e.g. a built-in writer, an `extractError` helper) — co-located in the same file.
|
||||||
|
- **Top-level `registerScopedService(...)`** — one per Service the file owns; importing the impl file runs the registration.
|
||||||
|
|
||||||
|
Base class: extend `Service` (from `#/_base/di/service`) when the unit needs capability calls on `this` — `provide` / `effect` / `on` / `get` / `ref` (e.g. contributing a record to a `collection` token). `Service` extends `Disposable`, so `_register` keeps working; constructor-time `provide` / `on` / `effect` calls are buffered and flushed by the kernel after construction, while `get` / `ref` throw inside the constructor (dependencies stay constructor parameters). Otherwise extend `Disposable` — both are full DI units; a service whose own members collide with the `Service` vocabulary (`name` / `state` / `config` / `get`) must stay on `Disposable` (leave a NOTE comment saying so).
|
||||||
|
|
||||||
|
## Constructor conventions
|
||||||
|
|
||||||
|
- Declare every dependency with `@IX` on a constructor parameter.
|
||||||
|
- Use `private readonly` (or `protected readonly`) to store a used dependency as a field.
|
||||||
|
- For an injected dependency the class does **not** directly use (e.g. passed through, or only needed to force construction order), drop the visibility modifier and prefix with `_`: `@IEventService _event: IEventService`.
|
||||||
|
- Service parameters and static parameters may both appear; the ordering rule depends on how the object is created — see below.
|
||||||
|
|
||||||
|
### Parameter order: scoped service vs `createInstance`
|
||||||
|
|
||||||
|
- **`registerScopedService` services** — the container injects only the `@IX` parameters; any static parameters must have defaults and are left at their default when the container builds the instance. Order is therefore not enforced by the container, but the common style is **`@IX` parameters first, optional static parameters after**:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
constructor(
|
||||||
|
@ILogWriterService protected readonly writer: ILogWriterService,
|
||||||
|
private readonly bound: LogContext = {},
|
||||||
|
level: LogLevel = 'info',
|
||||||
|
) {}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **`createInstance` objects** (non-singletons built with `instantiation.createInstance(Ctor, …staticArgs)`) — static parameters **must come first**, service parameters after, because the caller passes the static prefix positionally:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
constructor(
|
||||||
|
private readonly input: string, // static — passed by caller
|
||||||
|
@ILogService private readonly log: ILogService, // service — injected
|
||||||
|
) {}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Factory methods
|
||||||
|
|
||||||
|
A scoped Service may expose a factory method that returns a **new** instance of itself (or a related class) with extra context bound — e.g. `ILogger.child(ctx)` returns `new LogService(this.writer, { …this.bound, …ctx }, this._level)`. This is not a DI violation: it is an explicit factory, not a request for the container to build a Service. Do not use it to circumvent scope or singleton semantics.
|
||||||
|
|
||||||
|
## Fields and state
|
||||||
|
|
||||||
|
- `private readonly` for fields set once at construction (injected deps, derived config).
|
||||||
|
- `private _name` (underscore prefix) for mutable private state: `private _level: LogLevel`.
|
||||||
|
- `readonly` public fields only for immutable exposed state; prefer a getter (`get level()`) when the value can change.
|
||||||
|
- Keep state minimal — a Service owns only the state that matches its scope's identity (design.md §2). Anything else belongs in a different Service.
|
||||||
|
|
||||||
|
### Runtime state goes into the per-scope state container
|
||||||
|
|
||||||
|
Workspace/Session/Agent-scope Services register their runtime state into the scope's state container (`IWorkspaceStateService` / `ISessionStateService` / `IAgentStateService`, all over `_base`'s `StateRegistry`) instead of holding it in bare instance fields, so per-scope state lives in one observable place (`snapshot()` / `onDidChange`) and dies with the scope. Reference: `session/interaction/interactionService.ts`.
|
||||||
|
|
||||||
|
- Declare keys in the domain file and export them: `export const interactionPendingKey = defineState<Map<string, Pending>>('interaction.pending', () => new Map())` — `<domain>.<field>` naming, factory initializers.
|
||||||
|
- Inject `@ISessionStateService private readonly states` (or the Agent token) and `this.states.register(key)` per key at the top of the constructor.
|
||||||
|
- Replace the field with accessors: a getter for collections only mutated in place (`this.foo.add(...)` keeps working — the container stores references, never clones); add a setter routed through `states.set` for reassigned scalars. Call sites stay unchanged.
|
||||||
|
- Values must be plain data: scalars, arrays, and literal objects/Maps/Sets built from them. Never register class instances, resource handles (disposables, abort controllers, Promise locks), or objects holding service references — the regression precedent: one registry key whose class instances reached the whole DI graph deep-copied to hundreds of MB on `snapshot()` and OOM-killed the server. This means registries whose entries carry resources (the tool registry, the task map, prompt queues) stay as instance fields alongside Emitters, hook slots, disposable slots, waiter arrays, caches, and queue instances.
|
||||||
|
- `snapshot()` additionally recurses plain data only: values with a custom prototype collapse to a `'(ClassName)'` marker — a `_base`-level backstop, not a license to register resource-bearing values.
|
||||||
|
- Durable, replayable state does NOT belong here — it stays on wire Models. The container is memory-only.
|
||||||
|
|
||||||
|
## Events
|
||||||
|
|
||||||
|
v2 has two distinct event mechanisms. Pick by audience:
|
||||||
|
|
||||||
|
### `Event<T>` / `Emitter` — typed property on a Service
|
||||||
|
|
||||||
|
Use when a Service exposes a typed event its consumers subscribe to. Lives in `'#/_base/event'`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// contract
|
||||||
|
import type { Event } from '#/_base/event';
|
||||||
|
export interface IConfigService {
|
||||||
|
readonly onDidChange: Event<ConfigChangedEvent>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// impl
|
||||||
|
import { Emitter, type Event } from '#/_base/event';
|
||||||
|
export class ConfigService extends Disposable implements IConfigService {
|
||||||
|
private readonly _onDidChange = this._register(new Emitter<ConfigChangedEvent>());
|
||||||
|
readonly onDidChange: Event<ConfigChangedEvent> = this._onDidChange.event;
|
||||||
|
|
||||||
|
private notify(changed: ConfigChangedEvent): void {
|
||||||
|
this._onDidChange.fire(changed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Conventions:
|
||||||
|
|
||||||
|
- Back the public `Event<T>` with a private `Emitter<T>`, registered with `this._register(...)` so it disposes with the Service.
|
||||||
|
- Naming: `onDid…` for "happened" (past tense, after the fact); `onWill…` for "about to happen" (may allow `waitUntil` participation / veto — see `AsyncEmitter` / `IWaitUntil` in `'#/_base/event'`).
|
||||||
|
- A service must be constructed before consumers can subscribe to its events. Use the default `OnScopeCreated` activation when subscriptions must be available as soon as the scope is ready.
|
||||||
|
|
||||||
|
### `IEventService` — global pub-sub bus
|
||||||
|
|
||||||
|
Use to broadcast protocol events across domains. Lives in `'#/event'`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface IEventService {
|
||||||
|
readonly _serviceBrand: undefined;
|
||||||
|
publish(event: ProtocolEvent): void;
|
||||||
|
subscribe(handler: (event: ProtocolEvent) => void): IDisposable;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Inject `@IEventService` and `publish(...)`; `subscribe(...)` returns an `IDisposable` to register with `this._register(...)`. This is the bus for "a fact happened, react if you care" (design.md §4) — not for typed per-Service events.
|
||||||
|
|
||||||
|
## Multi-Service domains
|
||||||
|
|
||||||
|
A domain may define several Services. Each Service gets its own pair of files regardless of scope or coupling:
|
||||||
|
|
||||||
|
- **One pair per Service** → `<name>.ts` for the contract + `<name>Service.ts` for the implementation.
|
||||||
|
- **Different scopes** → the scope prefix in the Service name makes this obvious (`logService.ts` for App `ILogService`, `sessionLogService.ts` for Session `ISessionLogService`).
|
||||||
|
- **Same interface, multiple role tokens** (e.g. `IAtomicDocumentStore` and `IAtomicTomlDocumentStore` share one interface type but are distinct DI tokens) → each token is its own Service identity and must be registered and resolved independently.
|
||||||
|
|
||||||
|
There is no `index.ts` barrel: consumers import each contract/impl from its precise leaf path (e.g. `import { ILogService } from '#/log/log'`), never the domain directory.
|
||||||
|
|
||||||
|
## No barrel — the package entry loads leafs precisely
|
||||||
|
|
||||||
|
A domain has **no `index.ts` barrel**. Its files are the contract leaf (`<name>.ts`) and the impl leaf (`<name>Service.ts`), and consumers import the precise file — never the directory:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { IGreeter, type Greeting } from '#/greet/greet';
|
||||||
|
```
|
||||||
|
|
||||||
|
Self-registration is unchanged: `greetService.ts` keeps its top-level `registerScopedService(...)`. The package entry `src/index.ts` loads the domain's leafs precisely — `export *` for the contract, a side-effect `import` for the impl — one line per leaf:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// src/index.ts
|
||||||
|
export * from './greet/greet';
|
||||||
|
import './greet/greetService';
|
||||||
|
```
|
||||||
|
|
||||||
|
Importing the package therefore fires every `register*` side effect, exactly as the old per-domain barrels did. When you add a new domain, write the contract + impl leafs (with their top-level `register*`), then add the leaf path(s) to `src/index.ts`. **Do not create an `index.ts`.**
|
||||||
|
|
||||||
|
- Load the impl file too — its top-level `registerScopedService(...)` only runs when the module is imported.
|
||||||
|
- `export *` helper modules only if they are part of the domain's public surface.
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
|
||||||
|
- **No comments** (orient.md): no file headers, no statement-level narration; the only exception is JSDoc attached to exported symbols.
|
||||||
|
- **Methods and fields carry no comments by default.** Well-named identifiers and types say *what*; the code is the source of truth for *how*.
|
||||||
|
- Write an inline comment only when the *why* is non-obvious (a hidden constraint, a subtle invariant, a workaround). One short line.
|
||||||
|
- For unimplemented stubs, throw `NotImplementedError('feature')` rather than `throw new Error('TODO: …')` (errors.md).
|
||||||
|
|
||||||
|
## Complete minimal example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// greet/greet.ts
|
||||||
|
import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
|
||||||
|
|
||||||
|
export interface Greeting { readonly message: string; }
|
||||||
|
|
||||||
|
export interface IGreeter {
|
||||||
|
readonly _serviceBrand: undefined;
|
||||||
|
hello(): Greeting;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const IGreeter: ServiceIdentifier<IGreeter> = createDecorator<IGreeter>('greeter');
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// greet/greetService.ts
|
||||||
|
import { LifecycleScope } from '#/app/scopes';
|
||||||
|
import { ScopeActivation, registerScopedService } from '#/_base/di/scope';
|
||||||
|
import { type Greeting, IGreeter } from './greet';
|
||||||
|
|
||||||
|
export class Greeter implements IGreeter {
|
||||||
|
declare readonly _serviceBrand: undefined;
|
||||||
|
hello(): Greeting { return { message: 'hi' }; }
|
||||||
|
}
|
||||||
|
|
||||||
|
registerScopedService(LifecycleScope.App, IGreeter, Greeter, ScopeActivation.OnScopeCreated, 'greet');
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// src/index.ts
|
||||||
|
export * from './greet/greet';
|
||||||
|
import './greet/greetService';
|
||||||
|
```
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- One folder per domain, camelCase; one service per file pair: contract `<name>.ts` + impl `<name>Service.ts`; **no `index.ts` barrel** — `src/index.ts` loads each leaf file precisely.
|
||||||
|
- Exactly one injectable interface and one `createDecorator(...)` per contract file.
|
||||||
|
- Exactly one service implementation class and one `registerScopedService(...)` per impl file.
|
||||||
|
- `IXxxService` / `XxxService` naming; decorator string is lowerCamelCase, globally unique, and stable.
|
||||||
|
- Name Services by owning domain, never by scope (`IAgentEntityService`, `ISessionEntityService`).
|
||||||
|
- `_serviceBrand` only on interfaces used as a DI token — never on base interfaces or plain models.
|
||||||
|
- Sync methods return concrete types, async return `Promise<T>`; do not `Promise`-wrap sync work.
|
||||||
|
- `createInstance` objects put static parameters before service parameters; scoped services put `@IX` parameters first (static params need defaults).
|
||||||
|
- Never `new` a `@IService`-carrying Service — except inside an explicit factory method, which is not a DI request.
|
||||||
|
- Events: typed per-Service event → `Event<T>`/`Emitter` from `'#/_base/event'`; cross-domain broadcast → `IEventService` from `'#/event'`.
|
||||||
|
- `src/index.ts` must import/export every leaf file (including the impl) so each `register*` side effect runs.
|
||||||
|
- No comments by default (orient.md); stubs throw `NotImplementedError`.
|
||||||
97
.agents/skills/agent-core-dev/telemetry.md
Normal file
97
.agents/skills/agent-core-dev/telemetry.md
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
# Topic — Telemetry
|
||||||
|
|
||||||
|
Telemetry infrastructure for agent-core-v2: how business services emit events, how context propagates, and how events reach a destination through appenders.
|
||||||
|
|
||||||
|
Telemetry is a **layer-1 root** domain (alongside `log`): the facade lives at `App` scope (a per-Agent ambient context service is bound at `Agent` scope), stateless, with no business-domain dependencies. It is a thin facade — enrichment, batching, and transport belong to the appenders, not to this layer.
|
||||||
|
|
||||||
|
## Where things live
|
||||||
|
|
||||||
|
- `src/app/telemetry/telemetry.ts`: contract — `ITelemetryService` (facade), `ITelemetryAppender` (destination), `TelemetryProperties`, `nullTelemetryAppender`, and `TelemetryServiceOptions`.
|
||||||
|
- `src/app/telemetry/events.ts`: event registry — `telemetryEventDefinitions` pairs every business event's property type with review metadata (owner / purpose / per-property comment); the single source of truth for `track2`. Agent-scope events register with `defineAgentTelemetryEvent<P>` and compose the ambient `AgentTelemetryEventContext` (`agent_id`) into their wire schema; all other events register with `defineTelemetryEvent<P>`.
|
||||||
|
- `src/app/telemetry/telemetryService.ts`: `TelemetryService` impl + `registerScopedService(LifecycleScope.App, …)`.
|
||||||
|
- `src/app/telemetry/agentTelemetryContext.ts` + `agentTelemetryContextService.ts`: `IAgentTelemetryContextService` — Agent-scoped mutable request context (`mode` / `provider_type` / `protocol` / `turn_id` / `trace_id`) snapshot into turn telemetry at launch. Agent identity (`agent_id`) is not part of it — identity is bound by the Agent-scoped `ITelemetryService` view.
|
||||||
|
- `src/app/telemetry/consoleAppender.ts`: `ConsoleAppender` — echoes events to a log function (dev / debug).
|
||||||
|
- `src/app/telemetry/cloudAppender.ts`: `CloudAppender` — sanitizes + PII-cleans properties, batches + enriches + posts to the telemetry endpoint.
|
||||||
|
- `src/app/telemetry/cloudTransport.ts`: `CloudTransport` — HTTP transport behind `CloudAppender`.
|
||||||
|
- `src/app/telemetry/privacy.ts`: outbound PII redaction (`cleanTelemetryProperties`) — URLs, emails, tokens, and absolute file paths become `<REDACTED: ...>` labels; `node_modules/` tails are kept.
|
||||||
|
|
||||||
|
## Emitting events (business services)
|
||||||
|
|
||||||
|
Inject `ITelemetryService` and call `track2` with a registered event:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { ITelemetryService } from '#/app/telemetry/telemetry';
|
||||||
|
|
||||||
|
constructor(@ITelemetryService private readonly telemetry: ITelemetryService) {}
|
||||||
|
|
||||||
|
this.telemetry.track2('cron_fired', { task_id: taskId, coalesced_count: 0, stale: false, buffered: false, recurring: true });
|
||||||
|
```
|
||||||
|
|
||||||
|
`track2` is checked against the registry in `events.ts` at compile time: the event name must be a key of `telemetryEventDefinitions`, and the properties must match the registered interface exactly (extra or missing keys are compile errors). **New events must be registered first** — add a properties interface, then register it with `defineAgentTelemetryEvent<P>({ owner, comment, properties })` when every emission path goes through an Agent-scoped `ITelemetryService` view, or `defineTelemetryEvent<P>` otherwise (including events with any non-Agent emission path, e.g. `image_compress` from the kap-server prompt routes), documenting every property. For agent-scope events the registered interface is the business payload only: ambient `agent_id` is declared once in `AgentTelemetryEventContext` and composed into the wire schema, so it must not appear in the payload or at call sites. Naming: snake_case for events and properties, unit suffixes (`_ms` / `_count` / `_bytes`), no user content or file paths; `test/app/telemetry/events.test.ts` enforces the conventions. The low-level `track` remains for appender plumbing and tests only.
|
||||||
|
|
||||||
|
`TelemetryService.track` merges the bound context into the properties and fans the event out to every registered appender. A single throwing appender is isolated via `onUnexpectedError` and never blocks the rest.
|
||||||
|
|
||||||
|
### Context (sessionId / agent_id / turn_id)
|
||||||
|
|
||||||
|
The root service carries a bound context (`sessionId`) that is merged into every event, and each Agent scope gets its own telemetry view seeded with `agent_id` (by `agentLifecycle`), so Agent-scoped services emit their identity without call-site plumbing. Mutable per-agent request context (`mode` / `provider_type` / `protocol` / `turn_id` / `trace_id`) lives in `IAgentTelemetryContextService` and is snapshot into a per-turn view at turn launch. Derive a scoped view with `withContext`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const child = telemetry.withContext({ agent_id: 'agent-0' });
|
||||||
|
child.track2('tool_call', { turn_id: 1, tool_call_id: 'c1', tool_name: 'bash', outcome: 'success', duration_ms: 12 }); // wire carries sessionId + agent_id
|
||||||
|
```
|
||||||
|
|
||||||
|
`withContext(patch)` returns a lightweight forwarding view: transport state (appenders, enabled flag) stays with the root, so later `addAppender` / `setEnabled` calls apply to every view, and per-call properties override bound context on key collision. `setContext(patch)` on the root mutates the root context and propagates to appenders that implement `setContext`; on a view it mutates only that view's own context.
|
||||||
|
|
||||||
|
## Appenders (destinations)
|
||||||
|
|
||||||
|
An appender is the destination an event is fanned out to. It is **not a DI Service** — it is a plain object implementing `ITelemetryAppender`, held by `TelemetryService`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export interface ITelemetryAppender {
|
||||||
|
track(event: string, properties?: TelemetryProperties): void;
|
||||||
|
withContext?(patch: TelemetryContextPatch): ITelemetryAppender;
|
||||||
|
setContext?(patch: TelemetryContextPatch): void;
|
||||||
|
flush?(): Promise<void> | void;
|
||||||
|
shutdown?(): Promise<void> | void;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Built-in appenders:
|
||||||
|
|
||||||
|
- `ConsoleAppender` — `[telemetry] <event> <json>` to a log function (default `console.log`); options `prefix` / `pretty` / `log`.
|
||||||
|
- `CloudAppender` — batches events, enriches with common context (`app_name` / `version` / `platform` / …), and posts to `https://telemetry-logs.kimi.com/v1/event` through `CloudTransport` (Bearer auth, retry, on-disk fallback). Options: `homeDir` / `deviceId` / `sessionId?` / `appName` / `version` / `uiMode?` / `model?` / `getAccessToken?` / `endpoint?` / `flushThreshold?` / `flushIntervalMs?`.
|
||||||
|
|
||||||
|
### Registering appenders (bootstrap)
|
||||||
|
|
||||||
|
Appenders are added after the App scope exists, by resolving the service and calling `addAppender`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const app = createAppScope();
|
||||||
|
const telemetry = app.accessor.get(ITelemetryService);
|
||||||
|
|
||||||
|
telemetry.addAppender(new ConsoleAppender({ prefix: '[dev]' })); // dev echo
|
||||||
|
telemetry.addAppender(new CloudAppender({ // production
|
||||||
|
homeDir, deviceId, sessionId,
|
||||||
|
appName: 'kimi-code', version, uiMode: 'shell', model,
|
||||||
|
getAccessToken: () => auth.getCachedAccessToken(KIMI_CODE_PROVIDER_NAME),
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
|
||||||
|
`addAppender` returns an `IDisposable` that removes the appender when disposed. `setAppender(appender)` resets to a single appender (mainly for tests). `removeAppender(appender)` drops one.
|
||||||
|
|
||||||
|
> There is no production bootstrap wired yet — `TelemetryService` defaults to `[nullTelemetryAppender]`, so `track(...)` is a no-op until `addAppender` is called at startup.
|
||||||
|
|
||||||
|
## Lifecycle
|
||||||
|
|
||||||
|
- `setEnabled(false)` drops `track` (service-level switch); `setEnabled(true)` resumes. `flush` / `shutdown` are unaffected by the switch.
|
||||||
|
- `flush()` / `shutdown()` fan out to all appenders concurrently; a single rejecting appender is swallowed. Await `shutdown()` before process exit so buffered events (e.g. in `CloudAppender`) are sent.
|
||||||
|
|
||||||
|
## Red lines (this topic)
|
||||||
|
|
||||||
|
- Business services depend only on `ITelemetryService` — never import an appender class.
|
||||||
|
- Telemetry is layer-1 root: do not inject any business-domain service into it, and keep the facade at `App` scope (only the ambient context service binds at `Agent`).
|
||||||
|
- Appenders are plain `ITelemetryAppender` objects, not DI Services — register them with `addAppender`, never via `registerScopedService`.
|
||||||
|
- `track` is fire-and-forget and must not throw; appender `track` must be synchronous — buffer and send asynchronously via `flush` / `shutdown`.
|
||||||
|
- Await `telemetry.shutdown()` before process exit when a buffering appender is registered.
|
||||||
|
- Keep event names stable; register every business event in `events.ts` and emit via `track2` — properties must be JSON-serializable primitives (non-primitives are dropped with a warning by `CloudAppender`).
|
||||||
|
- Agent identity is ambient: agent-scope events go through `defineAgentTelemetryEvent` and get `agent_id` from the scoped telemetry view — do not pass `agent_id` at business call sites (per-event identities such as `subagent_created` and the cron events are the exception).
|
||||||
270
.agents/skills/agent-core-dev/test.md
Normal file
270
.agents/skills/agent-core-dev/test.md
Normal file
|
|
@ -0,0 +1,270 @@
|
||||||
|
# Stage 4 — Test
|
||||||
|
|
||||||
|
Exercise the **same path production uses**: a service is reached by its interface through the container, its `@IService` dependencies are resolved from the container, and — where the scope layer matters — through the scope tree. Tests that `new` a service and paper over its constructor with hand-rolled objects bypass that path and let the `registerScopedService(IX → Impl)` binding rot untested.
|
||||||
|
|
||||||
|
`@IService` parameter decorators run under vitest (the build uses `experimentalDecorators`), so fixtures declare dependencies exactly like production code. There is **no** `param()` helper, no manual `(Id as …)(Ctor, '', 0)`, and no capturing `accessor` inside a constructor to synchronously `.get()` a peer.
|
||||||
|
|
||||||
|
## The one rule
|
||||||
|
|
||||||
|
**Resolve the system under test by its interface, through the container. Never call `new` on a production service whose constructor carries `@IService` dependencies.**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// ✅ resolve by interface — the IX → Sut binding is exercised
|
||||||
|
ix.set(IMessageService, new SyncDescriptor(MessageService));
|
||||||
|
const svc = ix.get(IMessageService);
|
||||||
|
|
||||||
|
// ❌ construct the implementation directly — the registration is never run
|
||||||
|
const svc = new MessageService(stubContext);
|
||||||
|
```
|
||||||
|
|
||||||
|
Resolving by interface is what makes `registerScopedService(ISut, Sut, …)` part of the test. Constructing the class directly (or via `ix.createInstance(Sut)`) tests the class in isolation but leaves the binding, the scope layer, and the delayed/eager flag unverified.
|
||||||
|
|
||||||
|
Pure functions, value objects, and services with **no** `@IService` dependencies may be constructed directly.
|
||||||
|
|
||||||
|
The only other exception is a test that genuinely needs **two independent instances** of the same service with different dependencies (e.g. constructing two `TurnService`s with different `ILoopRunner`s). A singleton-per-container resolution cannot produce both, so `ix.createInstance(Impl)` is acceptable there — annotate it with a comment explaining why.
|
||||||
|
|
||||||
|
## Two harnesses
|
||||||
|
|
||||||
|
Pick the harness by *whether the scope layer is part of what you are testing*.
|
||||||
|
|
||||||
|
| Under test | Harness | Resolve the SUT with |
|
||||||
|
|---|---|---|
|
||||||
|
| A single service's behavior (unit) | `TestInstantiationService` (flat) | `ix.get(ISut)` after `ix.set(ISut, new SyncDescriptor(Sut))` |
|
||||||
|
| Cross-scope wiring, or which layer a service lives in | `createScopedTestHost` (scope tree) | `host.<scope>.accessor.get(ISut)` |
|
||||||
|
|
||||||
|
### Unit harness — `TestInstantiationService`
|
||||||
|
|
||||||
|
Default for domain service unit tests. It is an `InstantiationService` that also implements `ServicesAccessor` (so you can `ix.get(...)` directly) and owns sinon (so `dispose()` restores stubs).
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||||
|
import { DisposableStore } from '#/_base/di/lifecycle';
|
||||||
|
import { createServices } from '#/_base/di/test';
|
||||||
|
import type { TestInstantiationService } from '#/_base/di/test';
|
||||||
|
import { registerRecordsServices } from '../records/stubs';
|
||||||
|
|
||||||
|
describe('XxxService', () => {
|
||||||
|
let disposables: DisposableStore;
|
||||||
|
let ix: TestInstantiationService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
disposables = new DisposableStore();
|
||||||
|
ix = createServices(disposables, {
|
||||||
|
base: [registerRecordsServices],
|
||||||
|
additionalServices: (reg) => {
|
||||||
|
reg.define(IContextService, ContextService); // 1. real collaborator, by interface
|
||||||
|
reg.define(IXxxService, XxxService); // 2. system under test, by interface
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
afterEach(() => disposables.dispose());
|
||||||
|
|
||||||
|
it('does the thing', () => {
|
||||||
|
const svc = ix.get(IXxxService); // 3. resolve by interface
|
||||||
|
expect(svc.thing()).toBe('…');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
`createServices` builds the container from domain **service groups** plus per-test overrides (see Service groups). Reach for `ix.stub(...)` / `ix.set(...)` directly only inside an `it` when a single test needs to swap a registration:
|
||||||
|
|
||||||
|
- whole service, partial object: `ix.stub(IId, { method() { return … } })`;
|
||||||
|
- single method: `ix.stub(IId, 'method', value)` returns a sinon stub; `ix.spy(IId, 'method')` returns a spy;
|
||||||
|
- a prebuilt instance or descriptor: `ix.set(IId, instance)` / `ix.set(IId, new SyncDescriptor(Impl))`;
|
||||||
|
- when a collaborator's behavior must vary per test, model it as a `Test*Service` subclass whose methods read suite-scoped `let` variables rather than rebuilding the container each test.
|
||||||
|
|
||||||
|
### Scope harness — `createScopedTestHost`
|
||||||
|
|
||||||
|
Reach for this only when *which layer a service lives in* is itself the thing being asserted, or when the SUT reads from parent/child scopes. It builds the real `Scope` tree and resolves through it.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { beforeEach, describe, expect, it } from 'vitest';
|
||||||
|
import { LifecycleScope } from '#/app/scopes';
|
||||||
|
import {
|
||||||
|
ScopeActivation,
|
||||||
|
_clearScopedRegistryForTests,
|
||||||
|
registerScopedService,
|
||||||
|
} from '#/_base/di/scope';
|
||||||
|
import { createScopedTestHost, stubPair } from '#/_base/di/test';
|
||||||
|
|
||||||
|
describe('XxxService (scoped)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
_clearScopedRegistryForTests();
|
||||||
|
registerScopedService(
|
||||||
|
LifecycleScope.Agent,
|
||||||
|
IXxxService,
|
||||||
|
XxxService,
|
||||||
|
ScopeActivation.OnDemand,
|
||||||
|
'xxx',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves from the Agent scope with ancestor deps injected', () => {
|
||||||
|
const host = createScopedTestHost([stubPair(ILogService, stubLog())]);
|
||||||
|
const agent = host.child(LifecycleScope.Agent, 'main');
|
||||||
|
const svc = agent.accessor.get(IXxxService); // by interface
|
||||||
|
expect(svc.thing()).toBe('…');
|
||||||
|
host.dispose();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Always `_clearScopedRegistryForTests()` and re-register explicitly in `beforeEach`. Do not rely on a production module's top-level `registerScopedService(...)` side effect: import order then becomes part of the test, and another suite's `_clearScopedRegistryForTests()` can wipe it.
|
||||||
|
|
||||||
|
## Register the SUT by interface
|
||||||
|
|
||||||
|
Whichever harness you use, the SUT is registered under its interface (`ix.set(IX, new SyncDescriptor(Impl))` or `registerScopedService(scope, IX, Impl, …)`) and resolved by that interface. This is non-negotiable: it is the only thing that keeps the production registration honest.
|
||||||
|
|
||||||
|
A test that does `ix.createInstance(Impl)` is testing the class, not the service. Convert those (see Migration).
|
||||||
|
|
||||||
|
## Shared stubs
|
||||||
|
|
||||||
|
Hand-rolled stubs (`noopLog`, `noneEvent`, `unusedRecords`, …) must not be copied between test files. Each domain that owns a frequently-stubbed interface exports a stub from a `stubs.ts` **in the `test/` tree**, never from `src/`:
|
||||||
|
|
||||||
|
```text
|
||||||
|
test/log/stubs.ts → stubLog() / stubLogger()
|
||||||
|
test/turn/stubs.ts → stubTurn()
|
||||||
|
test/records/stubs.ts → stubAgentRecords()
|
||||||
|
test/environment/stubs.ts → stubEnvironment()
|
||||||
|
```
|
||||||
|
|
||||||
|
All test support lives under `test/` so test-only code stays out of the production source tree. Because `tsdown` builds from `src/index.ts`, anything under `test/` is unreachable from the entry and is never bundled into `dist/`.
|
||||||
|
|
||||||
|
Conventions:
|
||||||
|
|
||||||
|
- export a **factory** (`stubXxx()`), not a shared singleton, so tests cannot leak state through a stub;
|
||||||
|
- name it `stub<Interface>` — e.g. `stubAgentRecords`;
|
||||||
|
- the stub satisfies the full interface so the compiler, not a cast, guarantees it stays in sync;
|
||||||
|
- import it with a **relative path** — `./stubs` from the same domain's tests, `../<domain>/stubs` from another domain. Never import stubs from `#/…` (that alias is for production `src/`) and never import one test file from another;
|
||||||
|
- a `stubs.ts` may import its domain's production types via `#/<domain>/…`.
|
||||||
|
|
||||||
|
If a stub is needed by two test files, it belongs in that domain's `test/<domain>/stubs.ts`.
|
||||||
|
|
||||||
|
## Service groups
|
||||||
|
|
||||||
|
Most unit tests stub the same handful of collaborators (`ILogService`, `IAgentRecords`, `IConfigService`, `ITelemetryService`, …). Rather than repeat `ix.stub(...)` lines in every `beforeEach`, each domain exports a `register*Services` function from its `stubs.ts` that registers the default test doubles for that domain:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// test/log/stubs.ts
|
||||||
|
export function registerLogServices(reg: ServiceRegistration): void {
|
||||||
|
reg.defineInstance(ILogService, stubLog());
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`createServices(disposables, { base, additionalServices })` composes them:
|
||||||
|
|
||||||
|
- `base` — an ordered list of service groups. Each group's registrations are deduped (first writer wins), so groups supply safe defaults without clobbering each other.
|
||||||
|
- `additionalServices` — applied after `base`. Registrations here **overwrite** any base default, so a test can swap a stub for a spy, register the system under test, or supply a one-off collaborator.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
ix = createServices(disposables, {
|
||||||
|
base: [registerLogServices, registerConfigServices, registerRecordsServices],
|
||||||
|
additionalServices: (reg) => {
|
||||||
|
reg.definePartialInstance(IAgentKaos, {}); // one-off collaborator
|
||||||
|
reg.define(IAgentRecords, spyRecords); // override a base default
|
||||||
|
reg.define(IXxxService, XxxService); // system under test
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
`ServiceRegistration` offers three verbs:
|
||||||
|
|
||||||
|
- `define(id, Ctor)` — lazy `SyncDescriptor`; the service is instantiated on first resolve. Use for real collaborators and the system under test.
|
||||||
|
- `defineInstance(id, instance)` — a fully-built instance (a fake such as `stubLog()`, or `new ConfigRegistry()`).
|
||||||
|
- `definePartialInstance(id, { ... })` — a partial mock; only the supplied members are provided. Use for collaborators the test does not exercise.
|
||||||
|
|
||||||
|
Conventions:
|
||||||
|
|
||||||
|
- a group registers the domain's services **as dependencies** (a fake, or a `{}` partial when no fake exists yet). When a service is the system under test, the test registers the real implementation via `additionalServices` and does not rely on the group's default for it;
|
||||||
|
- keep groups small and domain-local. A service that is almost always the system under test, or that every consumer configures differently, should not have a group — register it inline via `additionalServices`;
|
||||||
|
- import groups with a **relative path** (`../<domain>/stubs`), never from `#/…`.
|
||||||
|
|
||||||
|
`createServices` defaults to `strict: false` (missing dependencies warn rather than throw), matching `new TestInstantiationService()`. Pass `strict: true` to surface unregistered `@IService` dependencies.
|
||||||
|
|
||||||
|
## Declaring dependencies
|
||||||
|
|
||||||
|
Always use `@IService` constructor decorators — in fixtures and in production services alike.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// ✅
|
||||||
|
class Consumer {
|
||||||
|
constructor(@IGreeter private readonly greeter: IGreeter) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ❌ no param() helper, no inline cast
|
||||||
|
class Consumer {
|
||||||
|
constructor(private readonly greeter: IGreeter) {}
|
||||||
|
}
|
||||||
|
param(IGreeter, Consumer, 0);
|
||||||
|
```
|
||||||
|
|
||||||
|
Because the decorator runs when the class is defined, the `createDecorator` identifier must be initialized **before** the class that uses it. Declare the identifier, then the class:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const IDep = createDecorator<IDep>('dep');
|
||||||
|
class Consumer {
|
||||||
|
constructor(@IDep private readonly dep: IDep) {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For two services that depend on each other (a cycle), declare both identifiers first, then both classes, so neither class references an uninitialized binding.
|
||||||
|
|
||||||
|
Declare fixtures at module top, interface + decorator + implementation co-located, and keep `_serviceBrand` on the interface when it represents a real service — `GetLeadingNonServiceArgs` relies on the brand to tell service parameters apart from static ones. Pure throwaway fixtures may omit `_serviceBrand`.
|
||||||
|
|
||||||
|
## Lifecycle / teardown
|
||||||
|
|
||||||
|
One `DisposableStore` per suite. Add the **container** and any event subscriptions to it; dispose in `afterEach`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
beforeEach(() => { disposables = new DisposableStore(); /* … */ });
|
||||||
|
afterEach(() => disposables.dispose());
|
||||||
|
```
|
||||||
|
|
||||||
|
Do **not** add the system-under-test itself to the store. `TestInstantiationService` disposes every service it creates when the container is disposed, so `ix.get(IX)` instances are cleaned up automatically via `disposables.add(ix)`. Wrapping the SUT in `disposables.add(...)` would double-dispose it. For the same reason, do not call `svc.dispose()` at the end of a test unless you are asserting something about disposal itself.
|
||||||
|
|
||||||
|
Scope-host tests call `host.dispose()` in `afterEach` (or at the end of the `it`). Route teardown through the store so ordering is deterministic and nothing leaks when a test fails mid-way.
|
||||||
|
|
||||||
|
## Cascade: asserting unit state
|
||||||
|
|
||||||
|
The cascade engine's test vocabulary lives in two files: `test/_base/di/cascade.test.ts` (the mechanism matrix, including cross-scope orchestration) and `test/_base/di/provide.test.ts` (provide/unprovide semantics).
|
||||||
|
|
||||||
|
- **Assert unit states, not internals.** Every container exposes its engine as `container.cascade`: `stateOf(IX)` → `'Pending' | 'Activating' | 'Active' | 'Unloading' | 'Failed'`; `failureOf(IX)` → the sticky error of a `Failed` unit; `pendingSnapshot()` → the waiting-area contents.
|
||||||
|
- **The waiting area parks units with unregistered dependencies** — a unit whose declared deps are missing stays `Pending` (no throw), so a test must seed the full dependency chain. Example: a root→agent chain with no session container must seed the session-scope dependency explicitly — `ix.set(ISessionStateService, new SessionStateService())` in `test/session/agentLifecycle/agentLifecycle.test.ts` — or the dependent unit never activates.
|
||||||
|
- **Eager activation failure is sticky `Failed`, not a scope-creation throw.** Assert state + rethrow: `expect(ix.cascade.stateOf(IX)).toBe('Failed')`, then `expect(() => ix.invokeFunction((a) => a.get(IX))).toThrow(…)`. Do not expect scope/host creation itself to throw for a failing eager constructor.
|
||||||
|
|
||||||
|
## Assertions and naming
|
||||||
|
|
||||||
|
- One behavior per `it`; describe observable behavior (`child shadows parent registration`), not implementation (`calls _getOrCreateServiceInstance`).
|
||||||
|
- For cycles, assert `CyclicDependencyError` and its `path` array (e.g. `['A', 'B', 'A']`), not merely `toThrow`.
|
||||||
|
- For disposal order, capture events in an array and assert the sequence (`['C', 'B', 'A']` — children before parents).
|
||||||
|
|
||||||
|
## Migrating existing tests
|
||||||
|
|
||||||
|
Most legacy tests build the SUT with `ix.createInstance(Impl)`. Converting one is mechanical:
|
||||||
|
|
||||||
|
1. import the interface (`IX`) and the descriptor;
|
||||||
|
2. register the SUT by interface — `reg.define(IX, Impl)` inside `additionalServices` (or `ix.set(IX, new SyncDescriptor(Impl))`);
|
||||||
|
3. replace `ix.createInstance(Impl)` with `ix.get(IX)`;
|
||||||
|
4. drop the `disposables.add(...)` wrapper around the SUT and any trailing `svc.dispose()` — the container disposes it;
|
||||||
|
5. replace any hand-rolled collaborator object with the domain's shared stub or service group (or add one to `test/<domain>/stubs.ts` if it does not exist);
|
||||||
|
6. delete now-unused imports.
|
||||||
|
|
||||||
|
Before / after:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// before
|
||||||
|
const svc = ix.createInstance(MessageService);
|
||||||
|
|
||||||
|
// after — registration in beforeEach additionalServices
|
||||||
|
reg.define(IMessageService, MessageService);
|
||||||
|
// after — resolution in the test body
|
||||||
|
const svc = ix.get(IMessageService);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Red lines (this stage)
|
||||||
|
|
||||||
|
- Resolve the SUT by interface — never `new` a production service with `@IService` deps; prefer `ix.get(IX)` over `ix.createInstance(Impl)`.
|
||||||
|
- Shared stubs live in `test/<domain>/stubs.ts` (never `src/`); import by relative path, never `#/...`.
|
||||||
|
- Scope tests call `_clearScopedRegistryForTests()` and re-register explicitly in `beforeEach`; do not rely on production import-order side effects.
|
||||||
|
- One `DisposableStore` per suite; add the container, dispose in `afterEach`; do not add the SUT itself.
|
||||||
|
- Declare fixture dependencies with `@IService`; initialize `createDecorator` identifiers before the classes that use them.
|
||||||
32
.agents/skills/agent-core-dev/verify.md
Normal file
32
.agents/skills/agent-core-dev/verify.md
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Stage 5 — Verify & submit
|
||||||
|
|
||||||
|
Run the guards and re-scan the red lines before submitting.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
Run from the package (or with `--filter @moonshot-ai/agent-core-v2`):
|
||||||
|
|
||||||
|
- `pnpm --filter @moonshot-ai/agent-core-v2 lint:imports` — import-boundary guard (`scripts/check-import-boundaries.mjs`). Catches v1 imports (`@moonshot-ai/agent-core`) and kosong subtree violations.
|
||||||
|
- `pnpm --filter @moonshot-ai/agent-core-v2 typecheck` — `tsc -p tsconfig.json --noEmit`.
|
||||||
|
- `pnpm --filter @moonshot-ai/agent-core-v2 test` — `vitest run`.
|
||||||
|
|
||||||
|
## Changesets (when the change ships through the CLI)
|
||||||
|
|
||||||
|
If the change is user-facing and ships through the CLI, generate a changeset with the repository's `gen-changesets` skill (root `AGENTS.md` workflow). `agent-core-v2` is an internal package; if its change enters the CLI bundle, the changeset lists `@moonshot-ai/kimi-code` and describes the real change — do not present an internal-only change as a user-facing feature. Never write a `major` bump without explicit user confirmation.
|
||||||
|
|
||||||
|
## Pre-submit checklist
|
||||||
|
|
||||||
|
Walk the stages you touched and confirm:
|
||||||
|
|
||||||
|
- **Design** — scope follows state identity; no `Map<sessionId, …>` at `App`; dependency arrows do not make a foundational layer know an upstream one; no cycle was routed around.
|
||||||
|
- **Implement** — no `new` on `@IService`-carrying classes; `@IX` on constructor params only (service params after static params); interface + impl carry `_serviceBrand`; decorator names unique; coded errors only; flags for unreleased behavior.
|
||||||
|
- **Test** — SUT resolved by interface; stubs under `test/`; scope tests re-register after `_clearScopedRegistryForTests()`; teardown through one `DisposableStore`.
|
||||||
|
- **Files** — no comments (exported-symbol JSDoc excepted); registration runs from the impl file's top level; the new domain is exported from `src/index.ts`.
|
||||||
|
|
||||||
|
Then re-read the [global red lines](SKILL.md#global-red-lines) once — they catch most cross-stage mistakes in a single scan.
|
||||||
|
|
||||||
|
## Red lines (this stage)
|
||||||
|
|
||||||
|
- Do not skip `lint:imports` — it is the only automated check for the v1-import ban and the kosong subtree rules.
|
||||||
|
- Do not list internal packages in a changeset when the change enters the CLI bundle — list `@moonshot-ai/kimi-code` and describe the real change.
|
||||||
|
- Never write a `major` changeset without explicit user confirmation.
|
||||||
21
.agents/skills/agent-core-review/SKILL.md
Normal file
21
.agents/skills/agent-core-review/SKILL.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
---
|
||||||
|
name: agent-core-review
|
||||||
|
description: Use ONLY for code review and test write/review guidance in `packages/agent-core-v2` (the DI × Scope agent engine). Does NOT apply to the legacy `packages/agent-core` or to any other package — for those, do not load this skill. Groups the review and testing lenses used for agent-core-v2 — `slop` (single-level-of-abstraction / layered error-handling review, invoked only on explicit request) and `test` (contract-driven per-test rules for both authoring and reviewing tests). Apply the sub-skill that matches the task; do not apply `slop` unprompted.
|
||||||
|
has-sub-skill: true
|
||||||
|
---
|
||||||
|
|
||||||
|
# kc-review
|
||||||
|
|
||||||
|
> **Scope: `packages/agent-core-v2` only.** These lenses are calibrated for the v2 engine (DI × Scope). Do not apply them to the legacy `packages/agent-core` or to other packages.
|
||||||
|
|
||||||
|
A bundle of the lenses used when reviewing or testing `packages/agent-core-v2`. Each sub-skill is self-contained; invoke the one that matches the task.
|
||||||
|
|
||||||
|
## Sub-skills
|
||||||
|
|
||||||
|
- **`slop/`** — Single Level of Abstraction & layered error handling. A *review dimension*: a function should read as a straight-line description of its own layer, with errors handled above or below. The agent reports detections and measurements, not severity grades. **Invoke only when the user explicitly asks for this lens** — do not apply it unprompted to general reviews or refactors.
|
||||||
|
- **`test/`** — Per-test rules behind "test the contract / responsibility, not the implementation," serving two modes. **Write mode:** author a test — one behavior per `it`, drive through the public surface, stub only the true external boundary, control time/config via documented knobs, keep tests clear, isolated, and refactor-resilient (CCCR). **Review mode:** audit existing tests against the same rules and report findings with `file:line`. Use when writing, modifying, or reviewing tests, or when asked how to write a good single test.
|
||||||
|
|
||||||
|
## Routing
|
||||||
|
|
||||||
|
- Reviewing code structure / abstraction layers / where error handling belongs → `slop` (only on explicit request).
|
||||||
|
- Writing or modifying tests, reviewing test quality, or advising on a single test → `test`.
|
||||||
133
.agents/skills/agent-core-review/slop/SKILL.md
Normal file
133
.agents/skills/agent-core-review/slop/SKILL.md
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
---
|
||||||
|
name: slop
|
||||||
|
description: Invoke only when the user explicitly asks to review code through the "single level of abstraction / layered error handling" lens — a function does only its own layer's business logic while errors are handled above or below. The agent reports detections, raw-count measurements, and move directions. Apply only when the user explicitly requests this lens.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Single Level of Abstraction & Layered Error Handling
|
||||||
|
|
||||||
|
North star: **a function should read as a straight-line description of what its own layer does. Anything that is not that — input validation, error handling, error-to-response translation, logging, retries, low-level mechanics — belongs to a layer above or below, not inline.**
|
||||||
|
|
||||||
|
This is a review dimension, not a hard rule. See "Exemption checklist" at the end.
|
||||||
|
|
||||||
|
## Scope of this skill — detect and measure
|
||||||
|
|
||||||
|
The agent applying this lens is a **sensor**. Its one job is to report *whether* a function mixes levels and *by how much*; deciding *how serious* it is belongs downstream. Severity labels (`Block` / `Request changes` / `Nit`) compress a continuous quantity into an uncalibrated three-point scale and are the main source of review-to-review variance, so they are produced downstream — by a deterministic rubric, anchored examples, or a human — from the facts the agent reports.
|
||||||
|
|
||||||
|
The agent's output is exactly these four things:
|
||||||
|
|
||||||
|
- **Detection (yes/no):** does this statement / block / function violate a rule of the lens?
|
||||||
|
- **Measurement (raw factual counts only):** mechanically countable quantities — body size, control-flow keywords, named syntactic shapes (see "Quantify"). Anything that first requires classifying a line (core/foreign, happy/error, high/low level) is recorded under detection, not here.
|
||||||
|
- **Direction (where it moves):** for each foreign concern, the destination layer — push **down** into a value / parser / infra helper, or push **up** into the edge handler.
|
||||||
|
- **Exemption flags:** which items, if any, hit the exemption checklist — recorded, not weighed.
|
||||||
|
|
||||||
|
Severity grades, merge/block verdicts, and "is splitting worth it" calls live downstream, derived from the four items above.
|
||||||
|
|
||||||
|
## When to use
|
||||||
|
|
||||||
|
Apply this lens only when the user asks for it explicitly (for example "用单一抽象层次审视一下", "check whether this function does too much", "errors should be handled above/below, right?"). Leave general reviews and refactors to other lenses unless the user names this one.
|
||||||
|
|
||||||
|
## The principle
|
||||||
|
|
||||||
|
One function, one level of abstraction, one responsibility. Three mutually reinforcing rules:
|
||||||
|
|
||||||
|
1. **Single Level of Abstraction (SLAP).** Every statement inside a function sits at the same conceptual level. High-level intent ("reserve inventory, charge payment, create the order") must not be interleaved with low-level mechanics (building headers, escaping strings, opening sockets, parsing bytes). If some lines read as "what" and others as "how", they belong in different functions.
|
||||||
|
2. **Error handling is its own concern (Clean Code).** A function either does the work or handles the error — not both. Business logic describes the happy path and *signals* failure (throw or return a result); the catch, mapping, logging, and recovery live in a dedicated handler, usually one layer up. Prefer exceptions / result types over threaded check-and-return ladders that interrupt the main flow.
|
||||||
|
3. **Separation of concerns by layer.** Each layer owns exactly one kind of knowledge: low-level code knows formats and protocols; mid-level code knows business rules; edge code knows the outside world (HTTP / CLI / UI). A function that knows two of these at once is leaking a layer.
|
||||||
|
|
||||||
|
The combined test: **could you explain this function to someone without using the word "and"?** If the explanation is "it reserves stock AND validates the email format AND maps the error to a status code AND logs to metrics", it is doing more than its layer's job.
|
||||||
|
|
||||||
|
Concerns that usually do **not** belong in a business function:
|
||||||
|
|
||||||
|
- Format / range / null validation that a lower value or parser could guarantee once.
|
||||||
|
- Mapping domain failures to an external protocol (status code, exit code, UI message) — that is the edge layer's job.
|
||||||
|
- Catch-and-swallow, retry loops, backoff, timeout, circuit breaking around a single call — infrastructure, push down.
|
||||||
|
- Cross-cutting telemetry / log / metric noise woven through every step — extract or push to a wrapper.
|
||||||
|
- Check-and-return ladders that occupy more space than the business core — replace with signal + a handler above.
|
||||||
|
|
||||||
|
## Methodology — fixing a function that violates it
|
||||||
|
|
||||||
|
Work top-down. Never start by shuffling lines.
|
||||||
|
|
||||||
|
1. **Name the level.** In one sentence, write what this function is for at its own layer. If you cannot, the function has no clear level — split before polishing.
|
||||||
|
2. **Classify every statement.** Tag each line or block as: **core** (this layer's business), **down** (a detail a lower abstraction should own), **up** (a concern an upper / edge layer should own), or **cross-cutting** (log / metric / retry). Unlabeled lines are where the mess hides — do not "just leave them".
|
||||||
|
3. **Decide down vs. up for each foreign item.**
|
||||||
|
- Push **down** when it is a guarantee a lower building block can provide: a value that can only be constructed valid, a parser that returns a typed result, an infra helper that already retries. The business function then assumes validity and stays clean.
|
||||||
|
- Push **up** when it is about translating or reacting to failure for the outside world: status codes, messages, exit codes, aggregation of many errors. The edge layer catches once and maps; business code just signals.
|
||||||
|
- Rule of thumb: if removing it would change what the business rule says, it is core and stays; if removing it only changes how a failure is reported or a detail is computed, it moves.
|
||||||
|
4. **Extract, do not interleave.** Pull each foreign concern into its own named function or layer. Keep the original function as a readable sequence of same-level calls. For error handling specifically, separate the work body from the recovery body into distinct functions so neither clutters the other.
|
||||||
|
5. **Signal, do not handle, in the middle.** Mid-layer business functions throw / return and let the right layer react. Do not catch-and-log-and-continue in business code unless continuing is itself the business rule.
|
||||||
|
6. **Re-read for level.** After the moves, every remaining line should be explainable at the same altitude. If not, repeat from step 1.
|
||||||
|
|
||||||
|
Keep the change minimal: move the smallest thing that restores the level. Do not invent abstractions, frameworks, or generic "handler" machinery beyond what the function actually needs. Three straight-line, same-level calls beat a premature pipeline.
|
||||||
|
|
||||||
|
## Review method — applying the lens to a diff
|
||||||
|
|
||||||
|
Read each changed or touched function and, for each check, record only: **the hit (yes/no) plus evidence (`file:line`)**, and — where the check points at a construct — a raw factual count from "Quantify".
|
||||||
|
|
||||||
|
1. **Altitude check.** Are all lines at the same level of abstraction? Record each place where a "what" line is immediately followed by a "how" block (or vice versa) inside the same function, with `file:line`.
|
||||||
|
2. **Happy-path check.** Can you read the business intent top to bottom without stepping through error branches? Record whether error handling sits inline between business steps (yes/no + `file:line`), supported by raw counts from "Quantify" (e.g. number of `catch` clauses, `continue` statements).
|
||||||
|
3. **Ownership check.** For each validation, catch, mapping, log, retry: is this layer the rightful owner, or is it borrowed from above / below? Record each borrowed item with `file:line` and its destination (down / up), using the rules from the methodology.
|
||||||
|
4. **Layer-leak check.** Does a business function mention an external protocol (status code, exit code, UI text, wire field)? Does an edge function contain a business rule? Record each leak candidate with `file:line` and whether it names an *external* protocol or an *internal* domain shape.
|
||||||
|
5. **Explanation test.** Describe the function in one sentence with no "and". Record whether "and" was needed; if so, list the proposed split as candidate moves (down / up).
|
||||||
|
|
||||||
|
### Quantify — report only raw factual counts
|
||||||
|
|
||||||
|
Report only quantities that can be counted **mechanically from the text**. Anything that first requires classifying a line (core vs foreign, happy-path vs error-handling, high-level vs low-level) is recorded under detection (the five checks above) as evidence, not as a number here.
|
||||||
|
|
||||||
|
Report, per function:
|
||||||
|
|
||||||
|
- **Body size** — lines and/or statements of the function body; state the basis (e.g. "statements, excluding lone braces").
|
||||||
|
- **Control-flow keywords (raw counts)** — `if`, `continue`, early `return`, `throw`, `try` / `catch` / `finally`, `await`, loops (`for` / `while` / `.forEach`).
|
||||||
|
- **Named syntactic shapes a check points at** — when a check cites a construct, count it verbatim and name the exact token: e.g. number of object literals, string literals, `.trim()` calls, `.length` reads, `origin.` property reads, spread `[...x]` operations.
|
||||||
|
- **Recovery presence (raw)** — number of `catch` clauses, and number of log / metric calls inside them.
|
||||||
|
|
||||||
|
Quantities that embed a prior classification — out-of-level vs core counts, guard-to-core ratios, happy-path vs error-handling volume, "repeated boundary checks a lower layer could guarantee once", "low-level literals in a high-level flow" — are captured as evidence under the relevant check (`file:line` + the verbatim tokens). A downstream rubric derives any ratio from those raw facts.
|
||||||
|
|
||||||
|
### Red flags
|
||||||
|
|
||||||
|
Record each as evidence (yes/no + `file:line`); these are candidates, not verdicts:
|
||||||
|
|
||||||
|
- A body that is mostly check-and-return / check-and-throw ladders around a thin core.
|
||||||
|
- A recovery block that logs, maps, and returns inline, sitting next to business steps.
|
||||||
|
- A function that both computes a value and decides how that value's failure is shown to the user.
|
||||||
|
- Low-level literals (byte offsets, header strings, format codes) inside a high-level workflow.
|
||||||
|
- A name that needs "And" / "Or" / "With" to be honest, or a name so vague ("handle", "process", "do") that it hides multiple levels.
|
||||||
|
- Catch-and-swallow that hides a failure the caller needed to see.
|
||||||
|
- Defensive null / format checks repeated at every call site instead of guaranteed once at the boundary.
|
||||||
|
|
||||||
|
### Severity grading belongs downstream
|
||||||
|
|
||||||
|
The agent's facts (detections, raw counts, directions, exemptions) feed a downstream grade; the agent reports those facts and stops there. Grades compress a continuous quantity into an uncalibrated three-point scale and are exactly where identical evidence gets labeled differently across runs. Grading happens above the agent:
|
||||||
|
|
||||||
|
- A **deterministic rubric** — a versioned threshold table over the raw counts from "Quantify"; or
|
||||||
|
- **Anchored examples** — the reviewer judges relative to repo-known reference functions rather than against an absolute adjective like "materially"; or
|
||||||
|
- A **human**, for items that land near a threshold boundary.
|
||||||
|
|
||||||
|
If a downstream consumer still asks the agent for a grade, the agent returns the underlying facts and the threshold band it would fall under, with `confidence: low` on boundary cases; the grade itself is produced downstream.
|
||||||
|
|
||||||
|
### How to report findings
|
||||||
|
|
||||||
|
Report **evidence + direction**. Lead with the location and the level, then the proposed move. Prefer "this block is one level lower than the rest of the function (`file:line`) — move it **down** into X" over "this is ugly" or "this is a request-changes". The destination layer (down into a value / parser / infra helper, or up into the edge handler) is the actionable output and the deliverable. Attach the "Quantify" numbers and any exemption flags to each finding.
|
||||||
|
|
||||||
|
## Exemption checklist
|
||||||
|
|
||||||
|
This is a lens, not a law. For each foreign concern, check whether any exemption below applies and **record the hit (yes/no) plus the reason**. The agent records exemptions as facts; a recorded exemption is then used downstream to cap the grade (e.g. to `Nit`) deterministically.
|
||||||
|
|
||||||
|
- **Tiny function:** the function is small enough that splitting would add indirection with no reader benefit.
|
||||||
|
- **Foreign concern is the single job:** the "foreign" concern is in fact the function's one purpose — a dedicated error mapper, a validator, an infra wrapper, or an index-bookkeeping helper whose low-level arithmetic *is* its level.
|
||||||
|
- **Atomicity / correctness / performance:** the steps genuinely must stay together (e.g. a re-check after an `await` to guard state that may have changed).
|
||||||
|
- **Edge-translator role:** an edge / handler function whose job is to translate an external event into internal indices; naming the wire fields is its job.
|
||||||
|
|
||||||
|
Keep a split that would make the code harder to read as a recorded candidate for downstream review. When the evidence lands on an exemption boundary, record both sides and set `confidence: low`.
|
||||||
|
|
||||||
|
## Output contract
|
||||||
|
|
||||||
|
Return, per function, items 1–5 only:
|
||||||
|
|
||||||
|
1. **Level statement** — one sentence: what the function is for at its own layer.
|
||||||
|
2. **Per-check results** — for each of the five review checks: `hit: yes/no`, evidence `file:line`, and (only where the check points at a construct) a raw factual count.
|
||||||
|
3. **Measurements** — the raw factual counts from "Quantify".
|
||||||
|
4. **Exemptions** — checklist hits (yes/no + reason).
|
||||||
|
5. **Proposed moves** — for each foreign concern: `file:line` → destination (down into X / up into Y). This is the actionable deliverable.
|
||||||
|
|
||||||
|
Severity grades, block/merge verdicts, and "worth splitting" calls live downstream, derived from items 1–4. When a consumer asks for a label, hand back items 1–4 and the threshold band, with `confidence: low` on boundary cases.
|
||||||
115
.agents/skills/agent-core-review/test/SKILL.md
Normal file
115
.agents/skills/agent-core-review/test/SKILL.md
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
---
|
||||||
|
name: test
|
||||||
|
description: Use when writing or reviewing tests, or when asked how to write a good single test. Encodes the per-test rules behind the "test the contract / responsibility, not the implementation" principle — name and structure one behavior per `it`, drive through the public surface, stub only true external boundaries, control time and config via documented knobs, and keep tests clear, isolated, and refactor-resilient. The same rules drive both authoring (write mode) and auditing existing tests (review mode).
|
||||||
|
---
|
||||||
|
|
||||||
|
# Tests — write & review
|
||||||
|
|
||||||
|
Per-test rules that operationalize one principle: **test the contract / responsibility, not the implementation**. This is the how-to for a single `it`, and the lens for reviewing one.
|
||||||
|
|
||||||
|
## Two modes, one rule set
|
||||||
|
|
||||||
|
- **Write mode** — authoring a test. Apply the rules below to produce it.
|
||||||
|
- **Review mode** — auditing an existing test or test diff. Apply the same rules as a checklist; report each violation with `file:line`, the rule it breaks, and the fix. See "Review mode" near the end.
|
||||||
|
|
||||||
|
The rules are identical in both modes — only the posture changes (produce vs. audit).
|
||||||
|
|
||||||
|
## Test contract, not implementation
|
||||||
|
|
||||||
|
- Drive the system through its **public control plane** and assert on **observable effects** (returned values, persisted state, emitted events, injected messages), never on source details.
|
||||||
|
- Resolve collaborators through their contract — the interface plus its identifier — not the module that binds a concrete implementation.
|
||||||
|
- Do not reach into private fields or add backdoors "for testing". If you feel the need, the seam is wrong — fix the design, not the test.
|
||||||
|
|
||||||
|
## One behavior per `it`
|
||||||
|
|
||||||
|
Each `it` covers exactly one responsibility / scenario. If the name needs "and", split it.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
it('returns 401 when the caller is unauthorized', ...);
|
||||||
|
it('does not double-fire when the same tick repeats', ...);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Name and structure
|
||||||
|
|
||||||
|
- `describe('<slice> (<responsibilities>)'` — name the **responsibility**, not the class.
|
||||||
|
- An `it(...)` reads as a sentence, but it must still encode three things — the **behavior / method**, the **state or condition**, and the **expected outcome**: `it('<behavior> when <condition>, <outcome>')`. A name like `does X when Y` with no result is too vague to fail usefully.
|
||||||
|
- Use spaces, not the Java-style `method_state_outcome` underscores — that convention exists only because Java test methods cannot contain spaces. A string-named test reads fine as a sentence.
|
||||||
|
- Good: `it('returns 401 when the caller is unauthorized')` · `it('advances the cursor and does not double-fire on a repeat tick')`
|
||||||
|
- Bad: `it('works')` · `it('handles auth correctly')` — no condition, no outcome
|
||||||
|
- Arrange / Act / Assert. A short `// Given` `// When` `// Then` is fine when it aids reading; do not paste it mechanically on trivial tests.
|
||||||
|
|
||||||
|
## Build a small rig
|
||||||
|
|
||||||
|
When several tests share setup, write a factory (`rig()`, `createHost()`, whatever fits the codebase) that returns the **smallest surface the test needs**. Tests reach into the rig; they do not rebuild the world each time. Keep the rig dumb: wiring only, no assertions.
|
||||||
|
|
||||||
|
## Stub only the real external boundary
|
||||||
|
|
||||||
|
Default to real collaborators wired the way production wires them. Stub the **minimum seam** that is genuinely external:
|
||||||
|
|
||||||
|
- A remote / model / service boundary — spy on the contract method (the interface), and capture what the system sends across it. Do not stand up the real external thing.
|
||||||
|
- Network / other-process boundaries — stub at the boundary, not the internals.
|
||||||
|
- Time, timers, jitter — use the documented control knobs the system exposes (env, an injected clock, a manual tick). Do **not** use fake timers or real `setTimeout` to drive time.
|
||||||
|
- Env / config knobs are usually snapshotted at bootstrap — set them **before** building the system under test, and restore them in `afterEach`.
|
||||||
|
|
||||||
|
## Keep tests DAMP and keep cause next to effect
|
||||||
|
|
||||||
|
- DAMP over DRY: use **literal expected values** in assertions; do not compute the expectation with the same logic as the code under test.
|
||||||
|
- Keep the key preconditions inside the `it` (or its rig), where the reader can see cause next to effect. Reserve `beforeEach` for cross-cutting plumbing (env snapshot, cleanup), not for hiding the scenario's setup.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Good — the expected value is a literal the reader can check.
|
||||||
|
expect(discount).toBe(15);
|
||||||
|
// Bad — re-derives the expectation; mirrors the implementation.
|
||||||
|
expect(discount).toBe(price * rate);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Assert only what is relevant
|
||||||
|
|
||||||
|
Assert the effect that proves the contract. Use matchers / partial-object matching to ignore incidental fields. Do not assert internal counters, call orders, or shapes the user cannot rely on.
|
||||||
|
|
||||||
|
## Isolate and clean up (no flakes)
|
||||||
|
|
||||||
|
Every test must be hermetic and order-independent. In `afterEach`:
|
||||||
|
|
||||||
|
- restore every mock / spy
|
||||||
|
- restore every env var you touched (snapshot in `beforeEach`)
|
||||||
|
- dispose the host / container and reset its reference
|
||||||
|
|
||||||
|
No dependence on wall-clock time, run order, or leftover on-disk state — give each scenario its own isolated identity / workspace when state persists.
|
||||||
|
|
||||||
|
## Quality bar: CCCR
|
||||||
|
|
||||||
|
Before finishing, check each test against:
|
||||||
|
|
||||||
|
- **Clarity** — a stranger can tell what broke from the failure message alone.
|
||||||
|
- **Completeness** — covers the responsibility's success, error, and boundary paths.
|
||||||
|
- **Conciseness** — no duplicate or speculative cases; one scenario per `it`.
|
||||||
|
- **Resilience** — survives an internal refactor with no test change (because it asserts contract, not implementation).
|
||||||
|
|
||||||
|
## Per-file scenario header
|
||||||
|
|
||||||
|
Start each test file with a short header comment: the **scenario**, the **responsibilities** asserted, the **wiring** (which collaborators are real vs. the single stubbed boundary), and how to run it.
|
||||||
|
|
||||||
|
## Review mode — auditing existing tests
|
||||||
|
|
||||||
|
Apply the rules above as a checklist against each test in scope (a file, a diff, or a named `it`). For every hit, report `file:line` + the rule it breaks + the fix; do not rewrite unless asked. Lead with the contract question: *what observable behavior does this test prove, and would it survive a refactor?*
|
||||||
|
|
||||||
|
Check, in order:
|
||||||
|
|
||||||
|
1. **Contract, not implementation** — asserts observable effects, not private fields, call order, or internal shapes the user cannot rely on.
|
||||||
|
2. **One behavior per `it`** — the name carries behavior + condition + outcome; "and" in the name means a split is owed.
|
||||||
|
3. **Boundary discipline** — only the true external seam is stubbed; time is driven by documented knobs, not fake timers / real `setTimeout`.
|
||||||
|
4. **DAMP expectations** — expected values are literals, not re-derived by the code under test's logic.
|
||||||
|
5. **Isolation** — mocks / spies / env / host restored in `afterEach`; no wall-clock, run-order, or leftover on-disk dependence.
|
||||||
|
6. **CCCR read-through** — Clarity, Completeness (success / error / boundary), Conciseness, Resilience.
|
||||||
|
|
||||||
|
Report findings as evidence + fix, e.g. "`foo.test.ts:42` asserts on `service.internalMap` (contract) — assert the returned value instead." If a test passes the lens, say so briefly; silence on a rule means it held.
|
||||||
|
|
||||||
|
## Quick checklist (write & review)
|
||||||
|
|
||||||
|
- Resolved through the contract; no concrete-impl import
|
||||||
|
- One behavior per `it`; name carries behavior + condition + outcome; AAA
|
||||||
|
- Stubbed only the true external seam; time via knobs, not fake timers
|
||||||
|
- Literal expectations; relevant assertions only
|
||||||
|
- Mocks / env / host restored in `afterEach`; hermetic, no flakes
|
||||||
|
- CCCR read-through done
|
||||||
|
|
@ -15,6 +15,7 @@ Current publishable packages:
|
||||||
|
|
||||||
All other workspace packages are private internal packages, are not published to npm, and are excluded via `ignore` in `.changeset/config.json`:
|
All other workspace packages are private internal packages, are not published to npm, and are excluded via `ignore` in `.changeset/config.json`:
|
||||||
|
|
||||||
|
- `@moonshot-ai/acp-adapter`
|
||||||
- `@moonshot-ai/agent-core`
|
- `@moonshot-ai/agent-core`
|
||||||
- `@moonshot-ai/kaos`
|
- `@moonshot-ai/kaos`
|
||||||
- `@moonshot-ai/kimi-code-oauth`
|
- `@moonshot-ai/kimi-code-oauth`
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Deliver background question answers to the agent directly instead of via a saved output file.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Fix background questions being cancelled as soon as the agent finishes its turn.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": minor
|
|
||||||
---
|
|
||||||
|
|
||||||
Remind the model of its context budget before automatic compaction, and after compaction point it at the session's event log for exact details.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Subagent final messages are no longer bounced back for expansion when they are under 200 characters.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Show a warning after switching to Ask When Needed or Never Ask mode.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Fix print mode (`kimi -p`) ignoring the `KIMI_DISABLE_TELEMETRY` environment variable.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Resuming a subagent by its agent id now works after the session is reopened in a new process; the resumed subagent follows the current permission mode and is matched by its own profile in permission rules.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Tower mode (experimental, `KIMI_CODE_EXPERIMENTAL_TOWER=1`): fix tower mode never starting when enabled through `[experimental] tower = true` in `config.toml` instead of the environment variable. When tower mode cannot be enabled, the error now names the actual blocker — the disabled experiment, a required restart, or the owning session. When another live session owns the workspace tower, the message also names the owning session's title alongside its id. /tower now also works in a directory that is not a git repository — it runs git init and commits what is there (an empty initial commit for empty directories).
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
"@moonshot-ai/kimi-code": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Remove the /dance Easter egg hint from the TUI tips rotation.
|
|
||||||
9
.github/ISSUE_TEMPLATE/1-bug-report.yml
vendored
9
.github/ISSUE_TEMPLATE/1-bug-report.yml
vendored
|
|
@ -13,7 +13,7 @@ body:
|
||||||
|
|
||||||
Please try to include as much information as possible.
|
Please try to include as much information as possible.
|
||||||
|
|
||||||
If you plan to submit a fix: check the Contribution box below and wait for a maintainer's `/approve` comment in this issue before opening a PR.
|
If you plan to submit a fix: link this issue in your PR. Small, reproducible bugs can go straight to a PR; for broader or uncertain fixes, wait for maintainer feedback first.
|
||||||
|
|
||||||
- type: input
|
- type: input
|
||||||
id: version
|
id: version
|
||||||
|
|
@ -65,10 +65,3 @@ body:
|
||||||
attributes:
|
attributes:
|
||||||
label: Additional information
|
label: Additional information
|
||||||
description: Is there anything else you think we should know?
|
description: Is there anything else you think we should know?
|
||||||
|
|
||||||
- type: checkboxes
|
|
||||||
id: willing-to-pr
|
|
||||||
attributes:
|
|
||||||
label: Contribution
|
|
||||||
options:
|
|
||||||
- label: I am willing to submit a PR for this bug fix myself (please wait for maintainer approval in this issue first)
|
|
||||||
|
|
|
||||||
2
.github/ISSUE_TEMPLATE/2-feature-request.yml
vendored
2
.github/ISSUE_TEMPLATE/2-feature-request.yml
vendored
|
|
@ -11,7 +11,7 @@ body:
|
||||||
Before you submit a feature:
|
Before you submit a feature:
|
||||||
1. Search existing issues for similar features. If you find one, 👍 it rather than opening a new one.
|
1. Search existing issues for similar features. If you find one, 👍 it rather than opening a new one.
|
||||||
2. The Kimi Code team will try to balance the varying needs of the community when prioritizing or rejecting new features. Please understand that not all features will be accepted.
|
2. The Kimi Code team will try to balance the varying needs of the community when prioritizing or rejecting new features. Please understand that not all features will be accepted.
|
||||||
3. Do not open a feature PR. External feature PRs are not accepted — features are discussed and decided in this issue; if accepted, the team will implement it or explicitly invite you to contribute.
|
3. Do not open a feature PR until maintainers have had a chance to respond here. PRs without prior discussion may be closed without review.
|
||||||
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: feature
|
id: feature
|
||||||
|
|
|
||||||
73
.github/ISSUE_TEMPLATE/3-bug-report-zh-cn.yml
vendored
73
.github/ISSUE_TEMPLATE/3-bug-report-zh-cn.yml
vendored
|
|
@ -1,73 +0,0 @@
|
||||||
name: Bug 报告
|
|
||||||
description: 报告需要修复的问题
|
|
||||||
labels:
|
|
||||||
- bug
|
|
||||||
- needs triage
|
|
||||||
body:
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
感谢你提交 bug 报告!这能帮助 Kimi Code 变得更好。
|
|
||||||
|
|
||||||
请确认你正在运行最新版本的 Kimi Code CLI——你遇到的问题可能已经被修复。
|
|
||||||
|
|
||||||
请尽量提供完整的信息。
|
|
||||||
|
|
||||||
如果你打算提交修复:勾选下方 Contribution 选项,并等待维护者在本 issue 中以 `/approve` 评论批准后再提 PR。
|
|
||||||
|
|
||||||
- type: input
|
|
||||||
id: version
|
|
||||||
attributes:
|
|
||||||
label: 你运行的 Kimi Code 版本是?
|
|
||||||
description: 复制 `kimi --version` 或 `/version` 的输出
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: input
|
|
||||||
id: plan
|
|
||||||
attributes:
|
|
||||||
label: 你使用的是哪个开放平台/订阅?
|
|
||||||
description: 运行 `/login` 时选择的那个
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: input
|
|
||||||
id: model
|
|
||||||
attributes:
|
|
||||||
label: 你使用的是哪个模型?
|
|
||||||
description: 底部状态栏可见,如 `kimi-k2.6`、`kimi-for-coding` 等
|
|
||||||
- type: input
|
|
||||||
id: platform
|
|
||||||
attributes:
|
|
||||||
label: 你的电脑平台是?
|
|
||||||
description: |
|
|
||||||
macOS 和 Linux:复制 `uname -mprs` 的输出
|
|
||||||
Windows:在 PowerShell 中运行 `"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"` 并复制输出
|
|
||||||
- type: textarea
|
|
||||||
id: actual
|
|
||||||
attributes:
|
|
||||||
label: 你遇到了什么问题?
|
|
||||||
description: 请包含完整的错误信息和提示词(隐去隐私信息)。如可能,请提供文本而非截图。
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
id: steps
|
|
||||||
attributes:
|
|
||||||
label: 复现步骤?
|
|
||||||
description: 说明 bug 并给出可复现的代码片段。如适用,请提供 session id 和上下文用量。
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
id: expected
|
|
||||||
attributes:
|
|
||||||
label: 期望的行为是什么?
|
|
||||||
description: 如可能,请提供文本而非截图。
|
|
||||||
- type: textarea
|
|
||||||
id: notes
|
|
||||||
attributes:
|
|
||||||
label: 补充信息
|
|
||||||
description: 还有什么想让我们知道的?
|
|
||||||
- type: checkboxes
|
|
||||||
id: willing-to-pr
|
|
||||||
attributes:
|
|
||||||
label: Contribution
|
|
||||||
options:
|
|
||||||
- label: 我愿意自己提交修复此 bug 的 PR(请先等待维护者在本 issue 中批准)
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
name: 功能建议
|
|
||||||
description: 为 Kimi Code 提议新功能
|
|
||||||
labels:
|
|
||||||
- enhancement
|
|
||||||
body:
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Kimi Code 缺少你想要的某个功能?欢迎在这里提议。
|
|
||||||
|
|
||||||
提交功能建议前:
|
|
||||||
1. 先搜索已有 issue,如有类似功能,点 👍 而不是新开 issue。
|
|
||||||
2. Kimi Code 团队会在排序或拒绝新功能时尽量平衡社区的不同需求,请理解并非所有功能都会被接受。
|
|
||||||
3. 不要提交 feature PR。不接受外部功能 PR——功能在本 issue 中讨论和决定;如被接受,由团队实现或明确邀请你来贡献。
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
id: feature
|
|
||||||
attributes:
|
|
||||||
label: 你希望看到什么功能?
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
id: notes
|
|
||||||
attributes:
|
|
||||||
label: 补充信息
|
|
||||||
description: 还有什么想让我们知道的?
|
|
||||||
7
.github/pull_request_template.md
vendored
7
.github/pull_request_template.md
vendored
|
|
@ -1,14 +1,13 @@
|
||||||
<!--
|
<!--
|
||||||
Thank you for your contribution to Kimi Code!
|
Thank you for your contribution to Kimi Code!
|
||||||
External PRs are accepted for approved bug fixes only: link an issue that a maintainer has approved (an `/approve` comment). External feature PRs are not accepted.
|
Please open an issue before sending a feature PR — PRs without prior discussion may be closed without review.
|
||||||
外部 PR 仅接受获批准的 bug 修复:请链接维护者已批准(`/approve` 评论)的 issue;不接受外部 feature PR。
|
|
||||||
|
|
||||||
See https://github.com/MoonshotAI/kimi-code/blob/main/CONTRIBUTING.md for more.
|
See https://github.com/MoonshotAI/kimi-code/blob/main/CONTRIBUTING.md for more.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
## Related Issue
|
## Related Issue
|
||||||
|
|
||||||
<!-- Link the issue this change came from. External PRs must link an issue approved by a maintainer (an `/approve` comment) — PRs without one may be closed. -->
|
<!-- Link the issue this feature came from. If there is no issue, explain the problem in the next section instead. -->
|
||||||
|
|
||||||
Resolve #(issue_number)
|
Resolve #(issue_number)
|
||||||
|
|
||||||
|
|
@ -23,7 +22,7 @@ Resolve #(issue_number)
|
||||||
## Checklist
|
## Checklist
|
||||||
|
|
||||||
- [ ] I have read the [CONTRIBUTING](https://github.com/MoonshotAI/kimi-code/blob/main/CONTRIBUTING.md) document.
|
- [ ] I have read the [CONTRIBUTING](https://github.com/MoonshotAI/kimi-code/blob/main/CONTRIBUTING.md) document.
|
||||||
- [ ] I have linked a related issue (external PRs: the issue must have a maintainer's `/approve`).
|
- [ ] I have linked a related issue, or explained the problem above.
|
||||||
- [ ] I have added tests that prove my feature works.
|
- [ ] I have added tests that prove my feature works.
|
||||||
- [ ] Ran `gen-changesets` skill, or this PR needs no changeset.
|
- [ ] Ran `gen-changesets` skill, or this PR needs no changeset.
|
||||||
- [ ] Ran `gen-docs` skill, or this PR needs no doc update.
|
- [ ] Ran `gen-docs` skill, or this PR needs no doc update.
|
||||||
|
|
|
||||||
177
.github/workflows/vscode-publish.yml
vendored
177
.github/workflows/vscode-publish.yml
vendored
|
|
@ -1,177 +0,0 @@
|
||||||
name: Publish VS Code extension
|
|
||||||
|
|
||||||
# 把 0.7.3 手动发版流程固化成 CI 流水线:
|
|
||||||
#
|
|
||||||
# pnpm install → package:platform(全 6 平台)→ package:verify
|
|
||||||
# → extension host 冒烟(xvfb)→ publish:vsix → publish:ovsx
|
|
||||||
#
|
|
||||||
# 触发语义(参照 kimi-code-app 仓 desktop release.yml 的判定方式):
|
|
||||||
# 只在"本次 push 改动了 apps/vscode/package.json 的 version"时发布,
|
|
||||||
# 即 changesets 版本 PR("ci: release packages")合入后自动触发;
|
|
||||||
# 普通 PR 合入不会改变版本号,不会发布。版本号比较以 push 事件的
|
|
||||||
# before SHA 为基准(git show),可覆盖一次 push 含多个 commit 的情况,
|
|
||||||
# 不依赖工作区状态。workflow_dispatch 为手动兜底,
|
|
||||||
# 跳过版本号变化检查,直接走后续幂等闸门。
|
|
||||||
#
|
|
||||||
# 幂等(两道保险,可安全重跑,失败即停不自动重试):
|
|
||||||
# 1. 发布前逐平台核验 VS Marketplace(vsce show)与 Open VSX(REST)
|
|
||||||
# 线上版本:6 个 targetPlatform(darwin/linux/win32 × x64/arm64)
|
|
||||||
# 全部在线才跳过对应发布步骤;任一平台缺失(如上次部分发布失败)
|
|
||||||
# 即放行给发布步骤补齐,重跑可补齐;
|
|
||||||
# 2. 发布脚本自身带 --skip-duplicate(vsce)/ already-exists 跳过(ovsx)。
|
|
||||||
#
|
|
||||||
# 前置条件:仓库管理员需先配置 secrets VSCE_PAT / OVSX_PAT,
|
|
||||||
# 未配置时 publish 步骤会失败,属预期。
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
name: Publish VSIX to marketplaces
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.repository_owner == 'MoonshotAI'
|
|
||||||
timeout-minutes: 90
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
with:
|
|
||||||
fetch-depth: 0 # 需要按 push 事件的 before SHA 取旧版本号比较
|
|
||||||
|
|
||||||
- name: Setup pnpm
|
|
||||||
uses: pnpm/action-setup@v6
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v6
|
|
||||||
with:
|
|
||||||
node-version-file: .nvmrc
|
|
||||||
cache: pnpm
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
- name: Resolve publish gate
|
|
||||||
id: gate
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
EVENT_NAME: ${{ github.event_name }}
|
|
||||||
BEFORE_SHA: ${{ github.event.before }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
pkg="apps/vscode/package.json"
|
|
||||||
version="$(node -p "require('./${pkg}').version")"
|
|
||||||
echo "version=${version}" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "extension version: ${version}"
|
|
||||||
|
|
||||||
if [ "${EVENT_NAME}" = "workflow_dispatch" ]; then
|
|
||||||
echo "manual dispatch — skipping version-change check"
|
|
||||||
else
|
|
||||||
# 以 push 事件的 before SHA 为比较基准(覆盖多 commit 的单次 push)。
|
|
||||||
# before 为空或全 0(如新分支首推)时无法比较,prev 视为空 →
|
|
||||||
# 判定版本变化放行 —— 宁可多查一次线上闸门,不可漏发。
|
|
||||||
prev=""
|
|
||||||
if [ -n "${BEFORE_SHA}" ] && [ -n "${BEFORE_SHA//0/}" ]; then
|
|
||||||
if git show "${BEFORE_SHA}:${pkg}" > /tmp/prev-vscode-pkg.json 2> /dev/null; then
|
|
||||||
prev="$(node -p "require('/tmp/prev-vscode-pkg.json').version")"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "push event has no usable before SHA ('${BEFORE_SHA}') — treating as a version change"
|
|
||||||
fi
|
|
||||||
if [ "${prev}" = "${version}" ]; then
|
|
||||||
echo "apps/vscode version unchanged in this push (${version}) — nothing to publish"
|
|
||||||
echo "should_publish=false" >> "$GITHUB_OUTPUT"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
echo "version changed ${prev:-<none>} -> ${version} — release push"
|
|
||||||
fi
|
|
||||||
echo "should_publish=true" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
# 线上闸门:逐平台核验,6 个 targetPlatform 全部在线才跳过对应市场;
|
|
||||||
# 任一平台缺失即放行给 publish 步骤幂等补齐。
|
|
||||||
# fail-closed:查询失败视为未发布 → 放行,交给 publish 步骤决定成败。
|
|
||||||
platforms="darwin-x64 darwin-arm64 linux-x64 linux-arm64 win32-x64 win32-arm64"
|
|
||||||
|
|
||||||
ovsx_missing=""
|
|
||||||
for target in ${platforms}; do
|
|
||||||
if ! curl -fsS -o /dev/null "https://open-vsx.org/api/moonshot-ai/kimi-code/${target}/${version}"; then
|
|
||||||
ovsx_missing="${ovsx_missing} ${target}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if [ -z "${ovsx_missing}" ]; then
|
|
||||||
echo "${version} is fully on Open VSX (all 6 platforms) — publish:ovsx will be skipped"
|
|
||||||
echo "ovsx_published=true" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "Open VSX missing platform(s):${ovsx_missing} — publish:ovsx will run to backfill"
|
|
||||||
echo "ovsx_published=false" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if pnpm --filter kimi-code exec vsce show moonshot-ai.kimi-code --json \
|
|
||||||
| node -e "const v=process.argv[1];const want=process.argv[2].split(' ');let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{const j=JSON.parse(d);const got=new Set((j.versions||[]).filter(x=>x.version===v).map(x=>x.targetPlatform||''));const missing=want.filter(p=>!got.has(p));if(missing.length){console.error('VS Marketplace missing platform(s): '+missing.join(' '));process.exit(1)}process.exit(0)})" "${version}" "${platforms}"; then
|
|
||||||
echo "${version} is fully on VS Marketplace (all 6 platforms) — publish:vsix will be skipped"
|
|
||||||
echo "vsix_published=true" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "vsix_published=false" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Check publish secrets
|
|
||||||
if: steps.gate.outputs.should_publish == 'true'
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
VSCE_PAT: ${{ secrets.VSCE_PAT }}
|
|
||||||
OVSX_PAT: ${{ secrets.OVSX_PAT }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
missing=()
|
|
||||||
[ -z "${VSCE_PAT:-}" ] && missing+=(VSCE_PAT)
|
|
||||||
[ -z "${OVSX_PAT:-}" ] && missing+=(OVSX_PAT)
|
|
||||||
if [ "${#missing[@]}" -gt 0 ]; then
|
|
||||||
echo "::error::missing repository secrets: ${missing[*]} — a repo admin must configure them before publishing"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Package all platform VSIX
|
|
||||||
if: steps.gate.outputs.should_publish == 'true'
|
|
||||||
run: pnpm --filter kimi-code run package:platform
|
|
||||||
|
|
||||||
- name: Verify VSIX packages
|
|
||||||
if: steps.gate.outputs.should_publish == 'true'
|
|
||||||
run: pnpm --filter kimi-code run package:verify
|
|
||||||
|
|
||||||
- name: Upload VSIX artifacts
|
|
||||||
if: steps.gate.outputs.should_publish == 'true'
|
|
||||||
uses: actions/upload-artifact@v7
|
|
||||||
with:
|
|
||||||
name: kimi-code-vsix-${{ steps.gate.outputs.version }}
|
|
||||||
path: apps/vscode/artifacts/vsix/*.vsix
|
|
||||||
retention-days: 14
|
|
||||||
|
|
||||||
- name: Install extension-host smoke dependencies
|
|
||||||
if: steps.gate.outputs.should_publish == 'true'
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y xvfb libgtk-3-0 libgbm1 libasound2t64
|
|
||||||
|
|
||||||
- name: Extension host smoke test
|
|
||||||
if: steps.gate.outputs.should_publish == 'true'
|
|
||||||
# 1.100.0 即 package.json engines.vscode 下限,与 0.7.3 手动发版的冒烟口径一致
|
|
||||||
run: xvfb-run -a pnpm --filter kimi-code run test:extension-host -- --version 1.100.0
|
|
||||||
|
|
||||||
- name: Publish to VS Marketplace
|
|
||||||
if: steps.gate.outputs.should_publish == 'true' && steps.gate.outputs.vsix_published != 'true'
|
|
||||||
env:
|
|
||||||
VSCE_PAT: ${{ secrets.VSCE_PAT }}
|
|
||||||
run: pnpm --filter kimi-code run publish:vsix
|
|
||||||
|
|
||||||
- name: Publish to Open VSX
|
|
||||||
if: steps.gate.outputs.should_publish == 'true' && steps.gate.outputs.ovsx_published != 'true'
|
|
||||||
env:
|
|
||||||
OVSX_PAT: ${{ secrets.OVSX_PAT }}
|
|
||||||
run: pnpm --filter kimi-code run publish:ovsx
|
|
||||||
12
AGENTS.md
12
AGENTS.md
|
|
@ -19,14 +19,14 @@ This is a TypeScript monorepo built for agent-assisted development. Keep the roo
|
||||||
- `apps/vis`, `apps/vis/server`, `apps/vis/web`: visual debugging tools for sessions and replays.
|
- `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/debug` RPC surface — workspace/session browser, per-session transcript chat, per-scope Service panels, and the DI unit inspection view. See `apps/kimi-inspect/AGENTS.md`.
|
- `apps/kimi-inspect`: web inspector for the kap-server `/api/v1/debug` RPC surface — workspace/session browser, per-session transcript chat, per-scope Service panels, and the DI unit inspection view. See `apps/kimi-inspect/AGENTS.md`.
|
||||||
- `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. See `packages/agent-core/AGENTS.md`.
|
- `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. See `packages/agent-core/AGENTS.md`.
|
||||||
- `packages/agent-core-v2`: the DI × Scope agent engine (the v2 port behind kap-server). Four `LifecycleScope` tiers — `App` / `Workspace` / `Session` / `Agent` (`app/scopes.ts`) — plus the L3 unit layer (`Service`/`Fiber` units, collection contribution points, the Feature seam in `src/features/`); there is no App-level session lifecycle facade — callers compose `ISessionIndex` → `IWorkspaceLifecycleService.handlerFor` → the handler.
|
- `packages/agent-core-v2`: the DI × Scope agent engine (the v2 port behind kap-server). Four `LifecycleScope` tiers — `App` / `Workspace` / `Session` / `Agent` (`app/scopes.ts`) — plus the L3 unit layer (`Service`/`Fiber` units, collection contribution points, the Feature seam in `src/features/`); there is no App-level session lifecycle facade — callers compose `ISessionIndex` → `IWorkspaceLifecycleService.handlerFor` → the handler. See `packages/agent-core-v2/AGENTS.md` and use the `agent-core-dev` skill (`.agents/skills/agent-core-dev/SKILL.md`) when developing here.
|
||||||
- `packages/node-sdk`: the public TypeScript SDK and harness.
|
- `packages/node-sdk`: the public TypeScript SDK and harness.
|
||||||
- `packages/kosong`: the LLM / provider abstraction layer.
|
- `packages/kosong`: the LLM / provider abstraction layer.
|
||||||
- `packages/kaos`: the execution environment and file/process abstractions.
|
- `packages/kaos`: the execution environment and file/process abstractions.
|
||||||
- `packages/oauth`: Kimi OAuth and managed auth utilities.
|
- `packages/oauth`: Kimi OAuth and managed auth utilities.
|
||||||
- `packages/telemetry`: shared client-side telemetry infrastructure.
|
- `packages/telemetry`: shared client-side telemetry infrastructure.
|
||||||
- `packages/transcript`: the isomorphic transcript rendering data layer — L1 agent-granular store, L2 idempotent operations, L3 `off/turn/block/delta` subscription 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/transcript`: the isomorphic transcript rendering data layer — L1 agent-granular store, L2 idempotent operations, L3 `off/turn/block/delta` subscription 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. See `packages/transcript/AGENTS.md`.
|
||||||
- `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/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). See `packages/kap-server/AGENTS.md`.
|
||||||
- `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 same `Klient`); also hosts the e2e suites. See `packages/klient/AGENTS.md`.
|
- `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 same `Klient`); also hosts the e2e suites. See `packages/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 discriminated `ParseResult` — 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/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 discriminated `ParseResult` — 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. See `packages/minidb/AGENTS.md`.
|
- `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. See `packages/minidb/AGENTS.md`.
|
||||||
|
|
@ -48,7 +48,7 @@ This is a TypeScript monorepo built for agent-assisted development. Keep the roo
|
||||||
|
|
||||||
## General Coding Rules
|
## General Coding Rules
|
||||||
|
|
||||||
- `packages/agent-core-v2`, `packages/kap-server`, and `packages/transcript` are 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 by `scripts/check-no-comments.mjs` over `.ts`/`.tsx`/`.mts`/`.mjs` under `src/`/`test/`/`scripts/`, which runs as part of `pnpm lint`.
|
- `packages/agent-core-v2`, `packages/kap-server`, and `packages/transcript` are comment-free zones: no line/block comments; the exceptions are JSDoc attached to exported symbols and load-bearing lint-suppression directives (`oxlint-disable` / `eslint-disable`), while other tooling directives (`@ts-expect-error`, …) stay banned. Enforced by `scripts/check-no-comments.mjs`, which runs as part of `pnpm lint`.
|
||||||
- For optional object properties, pass `undefined` directly instead of using conditional spread.
|
- For optional object properties, pass `undefined` directly instead of using conditional spread.
|
||||||
- YES: `{ user }`
|
- YES: `{ user }`
|
||||||
- NO: `{ ...(user ? { user } : undefined) }`
|
- NO: `{ ...(user ? { user } : undefined) }`
|
||||||
|
|
@ -63,9 +63,9 @@ This is a TypeScript monorepo built for agent-assisted development. Keep the roo
|
||||||
|
|
||||||
## Experimental Features
|
## 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_FLAG` enables all. Precedence is per-flag env > `[experimental]` config > master env > the flag's `default`. Release by flipping the entry's `default` to `true`.
|
- 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_FLAG` enables all. Release by flipping the entry's `default` to `true`.
|
||||||
- `packages/agent-core` (v1): add the flag to the central registry at `packages/agent-core/src/flags/registry.ts`, then check it with `flags.enabled('my-feature')`.
|
- `packages/agent-core` (v1): add the flag to the central registry at `packages/agent-core/src/flags/registry.ts`, then check it with `flags.enabled('my-feature')`.
|
||||||
- `packages/agent-core-v2` and kap-server modules: there is no central catalog — declare the flag in the owning domain via `registerFlagDefinition` at import time, then check it with `IFlagService.enabled(id)`. Current search-index-separation flags: `persistence_minidb_readmodel` (session read model, default on) and `search_worker` (global search worker host, default on).
|
- `packages/agent-core-v2` and kap-server modules: there is no central catalog — declare the flag in the owning domain via `registerFlagDefinition` at import time (see `packages/agent-core-v2/docs/flag.md`), then check it with `IFlagService.enabled(id)`. Current search-index-separation flags: `persistence_minidb_readmodel` (session read model, default on) and `search_worker` (global search worker host, default on).
|
||||||
|
|
||||||
## Where to Update Instructions
|
## Where to Update Instructions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
# Contributing to kimi-code
|
# Contributing to kimi-code
|
||||||
|
|
||||||
[中文版](CONTRIBUTING.zh-CN.md)
|
|
||||||
|
|
||||||
Thanks for taking the time to contribute! This project moves quickly, and thoughtful contributions from the community are what keep it sharp. The guide below walks you through how we work so your PR has the best chance of landing smoothly.
|
Thanks for taking the time to contribute! This project moves quickly, and thoughtful contributions from the community are what keep it sharp. The guide below walks you through how we work so your PR has the best chance of landing smoothly.
|
||||||
|
|
||||||
## Before You Start
|
## Before You Start
|
||||||
|
|
@ -12,25 +10,27 @@ We hold AI-assisted contributions to the same standard as hand-written ones. **Y
|
||||||
|
|
||||||
We only merge PRs aligned with the roadmap. Drive-by refactors without context are unlikely to land.
|
We only merge PRs aligned with the roadmap. Drive-by refactors without context are unlikely to land.
|
||||||
|
|
||||||
**External PRs are accepted for approved bug fixes only.** Open an issue first and wait for a maintainer to approve it with an `/approve` comment, then link that issue in your PR. PRs without an approved linked issue may be closed without review; once the issue is approved, ask a maintainer to reopen your PR.
|
**Discuss first** — open an issue before coding. PRs without prior discussion may be closed without review:
|
||||||
|
|
||||||
**Discuss first** — open an issue before coding:
|
- New features or user-visible behavior changes (regardless of size)
|
||||||
|
|
||||||
- Bug fixes, including small or typo-level ones: open a bug issue and wait for a maintainer's `/approve` before opening the PR
|
|
||||||
- New features or user-visible behavior changes (regardless of size): external feature PRs are not accepted — features are discussed and decided in issues, and accepted features are implemented by the team or by explicit maintainer invitation
|
|
||||||
- Refactors or other changes larger than ~100 lines
|
- Refactors or other changes larger than ~100 lines
|
||||||
- Public API or compatibility changes
|
- Public API or compatibility changes
|
||||||
|
- Bug fixes where the cause or fix approach is still unclear
|
||||||
|
|
||||||
|
**Can open a PR directly** — link an existing issue when there is one:
|
||||||
|
|
||||||
|
- Clear, reproducible bug fixes with a focused diff
|
||||||
|
- Typos, documentation-only changes, and small CI/build fixes
|
||||||
|
- Small changes that clearly match an existing issue or maintainer request
|
||||||
|
|
||||||
## Project Layout
|
## Project Layout
|
||||||
|
|
||||||
This is a pnpm monorepo. The most relevant entry points are:
|
This is a pnpm monorepo. The most relevant entry points are:
|
||||||
|
|
||||||
- `apps/kimi-code` — CLI / TUI
|
- `apps/kimi-code` — CLI / TUI
|
||||||
- `apps/vscode` — VS Code extension
|
- `apps/vis` — session replay & debugging visualizer
|
||||||
- `apps/vis` — session debug visualizer
|
|
||||||
- `packages/node-sdk` — public TypeScript SDK (`@moonshot-ai/kimi-code-sdk`)
|
- `packages/node-sdk` — public TypeScript SDK (`@moonshot-ai/kimi-code-sdk`)
|
||||||
- `packages/agent-core-v2` — the agent engine (v2, DI Scope architecture); `packages/agent-core` is v1 and being phased out
|
- `packages/agent-core`, `kosong`, `kaos`, `oauth`, `telemetry` — internal engine packages
|
||||||
- `packages/klient`, `kap-server`, `protocol`, `transcript`, `kosong`, `kaos`, `oauth`, `telemetry` — internal engine packages
|
|
||||||
- `docs/` — VitePress bilingual docs site
|
- `docs/` — VitePress bilingual docs site
|
||||||
|
|
||||||
For the full project map, see [AGENTS.md](AGENTS.md).
|
For the full project map, see [AGENTS.md](AGENTS.md).
|
||||||
|
|
@ -84,7 +84,9 @@ This repo uses [changesets](https://github.com/changesets/changesets) to manage
|
||||||
|
|
||||||
## Pull Requests
|
## Pull Requests
|
||||||
|
|
||||||
Every PR opens with the [PR template](.github/pull_request_template.md). PR titles must follow [Conventional Commits](#commit-convention); CI runs `pnpm lint`, `pnpm typecheck`, and `pnpm test` on every PR. Update user-facing docs in `docs/` when behavior changes — use the `gen-docs` skill when working with coding agents.
|
Use the [PR template](.github/pull_request_template.md) when opening a feature pull request.
|
||||||
|
|
||||||
|
PR titles must follow [Conventional Commits](#commit-convention); CI runs `pnpm lint`, `pnpm typecheck`, and `pnpm test` on every PR. Update user-facing docs in `docs/` when behavior changes — use the `gen-docs` skill when working with coding agents.
|
||||||
|
|
||||||
## Code Style
|
## Code Style
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,102 +0,0 @@
|
||||||
# 为 kimi-code 贡献代码
|
|
||||||
|
|
||||||
[English version](CONTRIBUTING.md)
|
|
||||||
|
|
||||||
感谢你花时间参与贡献!这个项目迭代很快,离不开社区认真的贡献。下面的指南介绍我们的工作方式,帮助你的 PR 顺利合入。
|
|
||||||
|
|
||||||
## 开始之前
|
|
||||||
|
|
||||||
Kimi Code 对 CLI/TUI 行为、agent 工作流和公开 API 已有自己的主张。如果你的改动会改变这些方向,请先开 issue 对齐,再投入时间写 PR。
|
|
||||||
|
|
||||||
我们对 AI 辅助贡献与手写代码一视同仁。**你应该理解自己提交的内容**——改了什么、边界情况下表现如何、为什么适合这个代码库。如果你解释不清楚,这个 PR 就还没准备好接受评审。
|
|
||||||
|
|
||||||
我们只合入与路线图一致的 PR。缺乏上下文背景的顺手重构很难被接受。
|
|
||||||
|
|
||||||
**外部 PR 仅接受获批准的 bug 修复。** 先开 issue,等待维护者以 `/approve` 评论明确批准,然后在 PR 中链接该 issue。没有已批准关联 issue 的 PR 可能会不经评审直接关闭;issue 获批后,可联系维护者重开你的 PR。
|
|
||||||
|
|
||||||
**先讨论**——写代码前先开 issue:
|
|
||||||
|
|
||||||
- bug 修复(包括小的、错别字级别的):先开 bug issue,等待维护者 `/approve` 后再提 PR
|
|
||||||
- 新功能或用户可见的行为变更(无论大小):不接受外部 feature PR——功能在 issue 中讨论和决定,被接受的功能由团队实现,或由维护者明确邀请你贡献
|
|
||||||
- 重构或其他超过约 100 行的改动
|
|
||||||
- 公开 API 或兼容性变更
|
|
||||||
|
|
||||||
## 项目结构
|
|
||||||
|
|
||||||
本仓库是 pnpm monorepo,最常用的入口:
|
|
||||||
|
|
||||||
- `apps/kimi-code` — CLI / TUI
|
|
||||||
- `apps/vscode` — VS Code 插件
|
|
||||||
- `apps/vis` — 会话调试可视化工具
|
|
||||||
- `packages/node-sdk` — 公开 TypeScript SDK(`@moonshot-ai/kimi-code-sdk`)
|
|
||||||
- `packages/agent-core-v2` — 当前的 agent 引擎(v2,DI Scope 架构);`packages/agent-core` 为 v1,正在逐步废弃
|
|
||||||
- `packages/klient`、`kap-server`、`protocol`、`transcript`、`kosong`、`kaos`、`oauth`、`telemetry` — 内部引擎包
|
|
||||||
- `docs/` — VitePress 双语文档站
|
|
||||||
|
|
||||||
完整项目地图见 [AGENTS.md](AGENTS.md)。
|
|
||||||
|
|
||||||
## 开发环境
|
|
||||||
|
|
||||||
前置要求:Node.js >= 24.15.0、pnpm 10.33.0、Git。
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git clone https://github.com/MoonshotAI/kimi-code.git
|
|
||||||
cd kimi-code
|
|
||||||
pnpm install
|
|
||||||
```
|
|
||||||
|
|
||||||
常用脚本:
|
|
||||||
|
|
||||||
- `pnpm dev:cli` — 开发模式运行 CLI
|
|
||||||
- `pnpm test` — 运行测试(vitest)
|
|
||||||
- `pnpm typecheck` — TypeScript 检查(注意:会先构建各包)
|
|
||||||
- `pnpm lint` — oxlint
|
|
||||||
- `pnpm lint:fix` — oxlint 自动修复
|
|
||||||
- `pnpm build` — 构建全部包
|
|
||||||
|
|
||||||
## 提交规范
|
|
||||||
|
|
||||||
所有 commit 和 PR 标题必须遵循 [Conventional Commits](https://www.conventionalcommits.org/)。
|
|
||||||
|
|
||||||
| 类型 | 用途 | 示例 |
|
|
||||||
|----------|------------------------------------------|----------------------------------------|
|
|
||||||
| feat | 新功能 | feat(agent-core): add tool dedup |
|
|
||||||
| fix | bug 修复 | fix(tui): correct status bar alignment |
|
|
||||||
| docs | 仅文档 | docs: clarify install instructions |
|
|
||||||
| chore | 工具 / 杂务 | chore: bump dependencies |
|
|
||||||
| refactor | 无行为变更的内部重构 | refactor(kosong): extract retry helper |
|
|
||||||
| test | 新增或改进测试 | test(agent-core): cover skill resolver |
|
|
||||||
| ci | CI / 构建流水线变更 | ci: cache pnpm store |
|
|
||||||
| build | 构建系统 / 产物变更 | build(native): add win32-arm64 target |
|
|
||||||
| perf | 性能优化 | perf(session): batch event flushes |
|
|
||||||
| style | 仅格式化(无逻辑变更) | style: apply oxlint --fix |
|
|
||||||
|
|
||||||
PR 标题由 `pr-title-checker` 工作流强制校验——不合规的标题会阻止合并。
|
|
||||||
|
|
||||||
## Changesets
|
|
||||||
|
|
||||||
本仓库使用 [changesets](https://github.com/changesets/changesets) 管理版本与发布。
|
|
||||||
|
|
||||||
- 每个影响发布产物(代码、行为、公开 API)的 PR **必须**包含 changeset。
|
|
||||||
- 仅文档、仅测试或仅 CI 的 PR 可以不加。
|
|
||||||
- 用 `pnpm changeset` 生成并按提示操作(涉及哪些包、什么 bump 级别)。
|
|
||||||
- 包选择与 bump 级别的仓库约定见 `.changeset/README.md`。在本仓库使用编程 agent 时,使用 `gen-changesets` 技能。
|
|
||||||
|
|
||||||
## Pull Requests
|
|
||||||
|
|
||||||
PR 会自动套用 [PR 模板](.github/pull_request_template.md)。PR 标题必须遵循 [Conventional Commits](#提交规范);每个 PR 的 CI 会运行 `pnpm lint`、`pnpm typecheck` 和 `pnpm test`。行为变更时请同步更新 `docs/` 下的用户文档——使用编程 agent 时使用 `gen-docs` 技能。
|
|
||||||
|
|
||||||
## 代码风格
|
|
||||||
|
|
||||||
- 全仓库 TypeScript。
|
|
||||||
- 使用 `oxlint`(配置见 `.oxlintrc.json`)。
|
|
||||||
- 用 `pnpm lint:fix` 自动格式化。
|
|
||||||
- lint 规则未覆盖的风格选择,跟随周边现有写法。
|
|
||||||
|
|
||||||
## 报告安全问题
|
|
||||||
|
|
||||||
发现安全问题?请查看 [SECURITY.md](SECURITY.md),不要开公开 issue。
|
|
||||||
|
|
||||||
## 许可证
|
|
||||||
|
|
||||||
向本仓库贡献即表示你同意你的贡献按 [MIT 许可证](LICENSE) 授权。
|
|
||||||
232
GOAL.md
Normal file
232
GOAL.md
Normal file
|
|
@ -0,0 +1,232 @@
|
||||||
|
# Goal 功能拆分
|
||||||
|
|
||||||
|
本文把 agent-core 中 goal mode 的能力拆成三部分:
|
||||||
|
|
||||||
|
1. 核心工作流:没有它就不能运行 goal。
|
||||||
|
2. 统计 / token 数限制:让 goal 可度量、可限额、可审计。
|
||||||
|
3. 用户交互相关:让用户可以安全启动、理解、控制和恢复 goal。
|
||||||
|
|
||||||
|
## 1. 核心工作流
|
||||||
|
|
||||||
|
核心工作流是 goal mode 的运行骨架。它负责创建结构化目标、维护状态机、把普通 turn 串成自治多轮执行,并让模型用机器可读状态结束或停放目标。
|
||||||
|
|
||||||
|
### 目标状态
|
||||||
|
|
||||||
|
同一个 main agent 同时最多只有一个当前 goal。goal 不是普通聊天文本,而是 runtime 持有的结构化状态,至少包含目标、可选完成标准、当前状态、停止原因和运行统计。
|
||||||
|
|
||||||
|
状态分为四类:
|
||||||
|
|
||||||
|
- `active`:正在被 goal driver 推进。只有这个状态会自动运行下一轮。
|
||||||
|
- `paused`:暂停但保留目标。通常来自用户暂停、中断、进程恢复后降级、provider 或 runtime 错误。可以恢复。
|
||||||
|
- `blocked`:目标遇到真实阻塞但保留目标。通常来自模型判断需要外部输入、目标无法按当前表述完成、预算达到、prompt hook 阻止。可以恢复。
|
||||||
|
- `complete`:瞬时完成状态。runtime 发出完成事件后立即清除 goal,不长期持久化。
|
||||||
|
|
||||||
|
没有 `cancelled` 状态。取消就是清除 goal,并提醒模型忽略之前关于该目标的 active reminder。
|
||||||
|
|
||||||
|
### 创建和替换
|
||||||
|
|
||||||
|
创建 goal 时,runtime 需要校验目标不能为空、不能过长。已有 active、paused 或 blocked goal 时,默认拒绝创建新 goal,防止静默覆盖。只有用户或调用方明确要求替换时,才先清除旧 goal,再创建新 goal。
|
||||||
|
|
||||||
|
新 goal 创建后进入 `active`,写入持久记录,并发出 goal 更新事件。
|
||||||
|
|
||||||
|
### 多轮驱动
|
||||||
|
|
||||||
|
goal driver 的职责是把一个 active goal 推进成连续的普通 turn:
|
||||||
|
|
||||||
|
- turn 开始时如果 goal 已经是 `active`,进入 goal driver。
|
||||||
|
- 普通 turn 中如果模型创建了 goal,或把 paused/blocked goal 恢复成 active,当前 turn 结束后 goal driver 接管继续执行。
|
||||||
|
- driver 每次只运行一个普通 turn。
|
||||||
|
- 每个 turn 结束后读取 goal 状态。
|
||||||
|
- goal 仍是 `active` 时,runtime 自动追加 continuation prompt 并启动下一轮。
|
||||||
|
- goal 变成 `paused`、`blocked` 或被清除时,driver 停止。
|
||||||
|
|
||||||
|
模型如果不调用状态更新工具,且 goal 仍是 active,runtime 会继续下一轮。模型不能只靠自然语言说“完成了”来结束 goal,必须给出结构化状态信号。
|
||||||
|
|
||||||
|
### Goal 注入
|
||||||
|
|
||||||
|
每个 goal turn 的边界,runtime 会把当前 goal 状态注入上下文。注入内容包括:
|
||||||
|
|
||||||
|
- 当前正在 goal mode。
|
||||||
|
- 目标和完成标准是什么。
|
||||||
|
- 目标文本是用户提供的数据,不能覆盖 system/developer 指令、工具 schema、权限规则或 host 控制。
|
||||||
|
- 当前状态和进度。
|
||||||
|
- 模型应该做简短自审,然后推进一个连贯工作切片。
|
||||||
|
- 简单、已完成、不可能、不安全、矛盾的目标,应在同一轮内直接标记 complete 或 blocked。
|
||||||
|
- 只有全部要求完成、验证通过、没有下一步有用动作时,才能标记 complete。
|
||||||
|
- 外部条件或用户输入阻塞时,应标记 blocked。
|
||||||
|
- 不要只做了计划、总结、第一版或部分结果就标记 complete。
|
||||||
|
|
||||||
|
goal 注入只在 turn / continuation 边界做,不在每个 model step 都做,避免上下文重复膨胀,也有利于 prompt cache。
|
||||||
|
|
||||||
|
paused 和 blocked goal 的注入更轻:
|
||||||
|
|
||||||
|
- paused:提醒模型目标存在但当前不应自治推进,除非用户明确要求继续。
|
||||||
|
- blocked:提醒模型目标被阻塞且当前不自治推进,除非用户要求处理或恢复。
|
||||||
|
|
||||||
|
### Continuation prompt
|
||||||
|
|
||||||
|
当 goal 仍是 active,runtime 会追加一个系统触发输入,含义相当于“继续朝当前 active goal 工作”。它不只是简单续跑,还要求模型每轮重新判断:
|
||||||
|
|
||||||
|
- 是否已经完成。
|
||||||
|
- 是否遇到真实阻塞。
|
||||||
|
- 是否应该只推进一个合理切片后继续下一轮。
|
||||||
|
- 是否应该避免发散或启动无关工作。
|
||||||
|
- 除非真实阻塞,否则不要向用户要输入。
|
||||||
|
|
||||||
|
### 完成、阻塞和暂停
|
||||||
|
|
||||||
|
模型通过结构化状态更新控制 goal 生命周期:
|
||||||
|
|
||||||
|
- `complete`:目标已满足,runtime 发出完成事件并清除 goal。
|
||||||
|
- `blocked`:遇到真实阻塞,runtime 保留 goal 并停止自治推进。
|
||||||
|
- `paused`:暂时放下 goal,runtime 保留 goal 并停止自治推进。
|
||||||
|
- `active`:恢复 paused 或 blocked goal。
|
||||||
|
|
||||||
|
状态更新工具的输入应保持窄,只表达机器状态。完成总结或阻塞原因由模型随后给用户说明。
|
||||||
|
|
||||||
|
当模型标记 complete 后,runtime 应再给模型一次收尾机会,生成简短最终回复,说明 goal 已完成、主要做了什么、跑了什么验证。
|
||||||
|
|
||||||
|
当模型标记 blocked 后,runtime 应再给模型一次收尾机会,说明具体阻塞、需要什么输入或变化才能继续。
|
||||||
|
|
||||||
|
如果当前 turn 已经没有 step 预算,不应为了收尾总结强行再跑一步,避免把“没法写总结”变成 turn 失败。
|
||||||
|
|
||||||
|
### 错误停车
|
||||||
|
|
||||||
|
goal mode 把技术运行失败视为可恢复停车:
|
||||||
|
|
||||||
|
- 用户中断当前 turn:goal 变 paused。
|
||||||
|
- provider rate limit:goal 变 paused。
|
||||||
|
- provider 连接错误、认证错误、API 错误:goal 变 paused。
|
||||||
|
- 模型配置错误:goal 变 paused。
|
||||||
|
- runtime 异常:goal 变 paused。
|
||||||
|
- provider safety filter:goal 变 paused。
|
||||||
|
|
||||||
|
业务、规则或外部条件阻塞则变 blocked:
|
||||||
|
|
||||||
|
- prompt hook 阻止目标。
|
||||||
|
- 模型判断无法继续。
|
||||||
|
- 预算达到。
|
||||||
|
- 需要用户或外部系统提供新条件。
|
||||||
|
|
||||||
|
### 持久化和恢复
|
||||||
|
|
||||||
|
goal 的创建、更新、完成、阻塞、清除应写入可恢复记录。session 恢复时,runtime 用记录重建 goal。
|
||||||
|
|
||||||
|
恢复时如果发现 goal 原来是 active,不应自动继续跑,而是降级为 paused。因为旧进程中的 active turn 不可能还活着,自动继续会造成重启后偷偷消耗资源。
|
||||||
|
|
||||||
|
paused 和 blocked 原样保留。complete 理论上不长期存在,因为完成后会清除。
|
||||||
|
|
||||||
|
fork session 时不继承源 session 的 goal,并提醒模型不要继续源 session 的旧目标。
|
||||||
|
|
||||||
|
## 2. 统计 / token 数限制
|
||||||
|
|
||||||
|
这一部分让 goal 可度量、可限额、可审计。没有它,goal 仍然可以运行,但不可控。
|
||||||
|
|
||||||
|
### 运行统计
|
||||||
|
|
||||||
|
goal 统计包括:
|
||||||
|
|
||||||
|
- continuation turn 数。
|
||||||
|
- token 数。
|
||||||
|
- active wall-clock 时间。
|
||||||
|
|
||||||
|
统计只在 goal 是 `active` 时增长。paused 和 blocked 期间不继续计数。
|
||||||
|
|
||||||
|
turn 统计在每个 goal turn 准备运行时增加,因此模型在某一轮里标记 complete 时,这一轮也计入最终统计。
|
||||||
|
|
||||||
|
token 统计在 model step 结束后累计。没有 active goal 时,不记入 goal。token 统计应以静默更新为主,不应每一步都刷 UI。
|
||||||
|
|
||||||
|
时间统计只计算 active pursuit 时间。进入 active 时开启计时区间,离开 active 时折算进累计时间;pause/resume 会形成新的 active 区间。
|
||||||
|
|
||||||
|
### 预算
|
||||||
|
|
||||||
|
goal 预算包括:
|
||||||
|
|
||||||
|
- turn budget。
|
||||||
|
- token budget。
|
||||||
|
- wall-clock budget。
|
||||||
|
|
||||||
|
默认没有预算。只有用户明确给出硬限制时才设置,例如“最多 20 轮”“不超过 500k token”“30 分钟内”。模糊表达如“尽快”“别花太久”不能设置预算,模型也不能自行发明预算。
|
||||||
|
|
||||||
|
时间预算需要合理范围。过短或过长应拒绝。turn 和 token 预算应规范化为正整数。
|
||||||
|
|
||||||
|
### 预算硬停
|
||||||
|
|
||||||
|
预算检查应发生在 goal turn 开始前和结束后。token budget 还应在 model step 后触发停止,避免超额后继续下一步。
|
||||||
|
|
||||||
|
一旦达到预算,runtime 应直接把 goal 标记为 blocked,原因是配置预算已达到。这个 blocked 仍可恢复,但如果预算不变,恢复后可能立刻再次 blocked。
|
||||||
|
|
||||||
|
### 预算引导和最终统计
|
||||||
|
|
||||||
|
当预算未接近时,模型提示应鼓励稳定推进。当任一预算达到 75% 以上时,提示应转为收敛,避免启动新的可选工作。
|
||||||
|
|
||||||
|
complete 和 blocked 的最终回复提示应包含 worked turns、elapsed time、tokens used 等统计信息。UI 事件也应带当前 snapshot 和变化类型。
|
||||||
|
|
||||||
|
telemetry 可以记录 goal 创建、预算设置、continuation、状态变化、清除等事件,但不应包含目标文本、停止原因等敏感内容。
|
||||||
|
|
||||||
|
## 3. 用户交互相关
|
||||||
|
|
||||||
|
这一部分让用户可以安全启动、理解、控制和恢复 goal。没有它,runtime 仍可能运行,但交互体验和安全边界不足。
|
||||||
|
|
||||||
|
### 生命周期控制
|
||||||
|
|
||||||
|
用户可以直接控制 goal:
|
||||||
|
|
||||||
|
- 创建。
|
||||||
|
- 查看。
|
||||||
|
- 暂停。
|
||||||
|
- 恢复。
|
||||||
|
- 取消。
|
||||||
|
|
||||||
|
这些操作可以不经过模型 turn。pause 把 active goal 变 paused;resume 把 paused 或 blocked goal 变 active;cancel 直接清除当前 goal。
|
||||||
|
|
||||||
|
resume 会清除旧停止原因,表示开始新的尝试。paused/blocked goal 不会因为用户发普通消息就自动继续。
|
||||||
|
|
||||||
|
### 模型发起 goal 的确认
|
||||||
|
|
||||||
|
模型可以代表用户创建 goal,但只有在用户明确要求启动 goal、自治工作,或宿主 goal-intake 提示要求时才应该这样做。普通请求不能被模型擅自升级成 goal。
|
||||||
|
|
||||||
|
模型发起 CreateGoal 时,非 auto 权限模式下应触发用户确认。确认菜单允许用户选择本次 goal 的运行权限模式。用户拒绝则 goal 不创建。
|
||||||
|
|
||||||
|
`GetGoal`、`SetGoalBudget`、`UpdateGoal` 只改 goal runtime 状态,默认可以更容易批准。真正写文件、跑 shell、访问敏感路径等仍走普通权限系统。
|
||||||
|
|
||||||
|
### 暂停、阻塞和取消后的提示
|
||||||
|
|
||||||
|
paused goal 的上下文提示应说明目标存在但当前不应继续做,除非用户明确要求继续。
|
||||||
|
|
||||||
|
blocked goal 的上下文提示应说明目标被阻塞且当前不自治推进,可以在用户要求时帮助解阻,否则正常处理当前请求。
|
||||||
|
|
||||||
|
cancel 后应追加提醒,让模型忽略旧 goal 的 active reminder,避免旧上下文诱导模型继续已经取消的目标。
|
||||||
|
|
||||||
|
### 完成和阻塞的用户回复
|
||||||
|
|
||||||
|
complete 后,goal 被清除,模型应给用户一条简短完成总结,说明完成了什么、做了什么验证。
|
||||||
|
|
||||||
|
blocked 后,goal 保留,模型应给用户一条简短阻塞说明,说明具体阻塞和继续所需输入、权限、外部条件或变更。
|
||||||
|
|
||||||
|
### Tool 暴露和隔离
|
||||||
|
|
||||||
|
goal 工具只给 main agent。subagent 不应直接创建、恢复、结束主 goal。
|
||||||
|
|
||||||
|
没有 goal 时,模型不应看到 `UpdateGoal` 和 `SetGoalBudget`。有 goal 时才暴露这些控制工具。
|
||||||
|
|
||||||
|
goal ID 不应暴露给模型,因为它只是 runtime/UI 内部标识,没有用户语义。
|
||||||
|
|
||||||
|
### 辅助写 goal
|
||||||
|
|
||||||
|
`write-goal` 类能力用于帮助用户把粗糙意图整理成适合 goal mode 的完成契约。好的 goal 应明确:
|
||||||
|
|
||||||
|
- end state:什么条件必须变成真。
|
||||||
|
- proof:用什么可观察证据证明完成。
|
||||||
|
- boundaries:工作范围和禁止触碰的内容。
|
||||||
|
- loop:如何迭代推进。
|
||||||
|
- stop rule:什么情况下停止并报告,而不是强行继续。
|
||||||
|
|
||||||
|
预算是 opt-in,不应默认加入,也不应把 turn cap 写进目标文本。
|
||||||
|
|
||||||
|
### UI 和会话语义
|
||||||
|
|
||||||
|
goal 创建、暂停、恢复、阻塞、完成、清除都应发出 goal updated 事件。lifecycle 变化和 completion 变化应区分。completion 是一次终局事件,然后 snapshot 变 null。blocked/paused 保留 snapshot,UI 可以继续展示可恢复 goal。
|
||||||
|
|
||||||
|
session 恢复时,active goal 会变 paused,避免重启后自动继续。fork session 时不继承 goal,并提醒模型不要继续源 session 的目标。
|
||||||
|
|
||||||
|
|
@ -1,333 +1,5 @@
|
||||||
# @moonshot-ai/kimi-code
|
# @moonshot-ai/kimi-code
|
||||||
|
|
||||||
## 0.40.1
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#3469](https://github.com/MoonshotAI/kimi-code/pull/3469) [`979baad`](https://github.com/MoonshotAI/kimi-code/commit/979baad8597aa1760917752b3663f1eb4e40eeb0) Thanks [@sailist](https://github.com/sailist)! - Fix the condition for showing the kimi-cli migration prompt.
|
|
||||||
|
|
||||||
## 0.40.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- [#3434](https://github.com/MoonshotAI/kimi-code/pull/3434) [`ae7a6dc`](https://github.com/MoonshotAI/kimi-code/commit/ae7a6dc6fb56cde119f0ac1512649a52c19ef7e8) Thanks [@sailist](https://github.com/sailist)! - The `kimi acp` subcommand no longer honors `KIMI_CODE_LEGACY_FLAG`; it always runs on the default agent engine.
|
|
||||||
|
|
||||||
- [#3334](https://github.com/MoonshotAI/kimi-code/pull/3334) [`971a8b2`](https://github.com/MoonshotAI/kimi-code/commit/971a8b24c172912f100eaa9a88625387086b327b) Thanks [@7Sageer](https://github.com/7Sageer)! - The subagent model pool (`[secondary_model]`) is enabled by default in every launch mode and remains opt-out via `KIMI_CODE_EXPERIMENTAL_SECONDARY_MODEL=0` or `[experimental] secondary-model = false`.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Added a Plugins panel to Settings for browsing the plugin marketplace and installing, enabling, disabling, and removing plugins.
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#3444](https://github.com/MoonshotAI/kimi-code/pull/3444) [`b4ae7f8`](https://github.com/MoonshotAI/kimi-code/commit/b4ae7f875dddcc40878c8d48d29bce02727dd87c) Thanks [@sailist](https://github.com/sailist)! - Remove the workspace restriction on the Bash tool's cwd parameter.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Added a code wrap toggle to the diff panel and streamlined its header.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed new content not appearing after auto-compaction (stuck at "Requesting…" above the divider); output after the compaction point now renders below the divider.
|
|
||||||
|
|
||||||
- [#3392](https://github.com/MoonshotAI/kimi-code/pull/3392) [`616d510`](https://github.com/MoonshotAI/kimi-code/commit/616d51045dbb7c3949c05713d4a0273c74dd07fc) Thanks [@7Sageer](https://github.com/7Sageer)! - Preserve comments, key order, and formatting in config.toml when configuration values are updated.
|
|
||||||
|
|
||||||
- [#3348](https://github.com/MoonshotAI/kimi-code/pull/3348) [`9d2304c`](https://github.com/MoonshotAI/kimi-code/commit/9d2304c23ca30c781b1a39540971dcaef085a500) Thanks [@liukx0205](https://github.com/liukx0205)! - Fix models and providers transiently disappearing when config.toml is saved non-atomically by an external editor while the daemon reloads it.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: The connecting splash screen now shows the current loading stage and the reason when the connection fails.
|
|
||||||
|
|
||||||
- [#3290](https://github.com/MoonshotAI/kimi-code/pull/3290) [`4b9888b`](https://github.com/MoonshotAI/kimi-code/commit/4b9888b73db5937f86c65d1880c44f5326acd69d) Thanks [@sailist](https://github.com/sailist)! - Block dangerous shell commands such as shutdown, reboot, or rm -rf in Auto mode, and always ask before running them in Manual and YOLO modes; disable the guard with `[permission] dangerous_command_guard = false` or `KIMI_CODE_DANGEROUS_COMMAND_GUARD=false`.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed queued or steered messages being unexpectedly retracted by pressing Esc after they start running.
|
|
||||||
|
|
||||||
- [#3421](https://github.com/MoonshotAI/kimi-code/pull/3421) [`9c37feb`](https://github.com/MoonshotAI/kimi-code/commit/9c37feb473cddb0b8bfe2552ad481f83f83fe6d0) Thanks [@sailist](https://github.com/sailist)! - Make session forks much faster.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Show a refresh button in the right-sidebar file preview when the previewed file is edited mid-turn.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed the server-side attachment notice text leaking into your own message bubble after sending a file.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed misaligned content in the composer attachment tooltip.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed messages sent with Ctrl+S while the agent is running disappearing after a page reload.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed sessions occasionally stuck showing "working" after a message is appended mid-turn.
|
|
||||||
|
|
||||||
- [#3377](https://github.com/MoonshotAI/kimi-code/pull/3377) [`58b74cf`](https://github.com/MoonshotAI/kimi-code/commit/58b74cfeab157483eef8a9e4ed8f4b683eecb34d) Thanks [@chengluyu](https://github.com/chengluyu)! - Fix duplicate user messages in transcript clients.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed the first pinyin letter being committed as English text in Chinese IMEs after enabling goal or plan mode.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed sessions occasionally stuck showing "working" long after the reply had completed.
|
|
||||||
|
|
||||||
- [#3427](https://github.com/MoonshotAI/kimi-code/pull/3427) [`442b563`](https://github.com/MoonshotAI/kimi-code/commit/442b56391bd8f1cdc65bb0bab2b6a57c786ec871) Thanks [@sailist](https://github.com/sailist)! - Honor explicit `[experimental]` config entries over the `KIMI_CODE_EXPERIMENTAL_FLAG` master switch, so a flag set to `false` in `config.toml` stays off; per-feature `KIMI_CODE_EXPERIMENTAL_<NAME>` variables still override both.
|
|
||||||
|
|
||||||
- [#3412](https://github.com/MoonshotAI/kimi-code/pull/3412) [`7bc5b20`](https://github.com/MoonshotAI/kimi-code/commit/7bc5b2027cd80e19dcacf43ed92aad749964a9e3) Thanks [@7Sageer](https://github.com/7Sageer)! - Send the forked-subagent context notice as a system reminder.
|
|
||||||
|
|
||||||
- [#3415](https://github.com/MoonshotAI/kimi-code/pull/3415) [`82bf0a8`](https://github.com/MoonshotAI/kimi-code/commit/82bf0a8dd283da1c25d3eb83c44e310d2bcbdee1) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Parse `git status --porcelain` with `-z` so non-ASCII paths are no longer mangled into bogus quoted directory segments.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Pressing Tab in the @ file menu completes the highlighted candidate's name into the input while keeping the menu open for further filtering.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Support activating multiple skills from a single message.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Background task notification cards now show a "Sent from background · bash" source line and a single "status: task description" body line.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Background task notification cards now label the sender as "Sent from background (Bash) / (Agent)".
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Superseded @ file searches are now cancelled promptly during fast typing, reducing background load.
|
|
||||||
|
|
||||||
- [#3371](https://github.com/MoonshotAI/kimi-code/pull/3371) [`9e88152`](https://github.com/MoonshotAI/kimi-code/commit/9e881528a89945a373002b0b229f91735e8f2c4f) Thanks [@tpoisonooo](https://github.com/tpoisonooo)! - Fix prompts remaining queued forever after reopening a session.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed manually typed > quote blocks in messages being misrendered as quote annotations; they now render as plain text.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed messages rejected by the server sometimes showing no failure toast.
|
|
||||||
|
|
||||||
- [#3425](https://github.com/MoonshotAI/kimi-code/pull/3425) [`ceb5153`](https://github.com/MoonshotAI/kimi-code/commit/ceb51535efa58d9a9eaa176140ec64959d980c53) Thanks [@sailist](https://github.com/sailist)! - Add the `kimi session list` command to list sessions from the command line.
|
|
||||||
|
|
||||||
- [#3390](https://github.com/MoonshotAI/kimi-code/pull/3390) [`76c1a7a`](https://github.com/MoonshotAI/kimi-code/commit/76c1a7a347ca0bfae68f85d8d4d69d73671c0403) Thanks [@Grapedge](https://github.com/Grapedge)! - Simplify the built-in system prompt.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Selecting a skill from the slash menu now inserts the same skill pill as the @ menu.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed stale steered-message bubbles lingering after a transcript refresh.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed the file-change summary card appearing too early when a turn is steered while still running.
|
|
||||||
|
|
||||||
- [#3436](https://github.com/MoonshotAI/kimi-code/pull/3436) [`0f39b2c`](https://github.com/MoonshotAI/kimi-code/commit/0f39b2cf3aa7b83f7049f922f9babf4b36092ddc) Thanks [@wbxl2000](https://github.com/wbxl2000)! - Fix idle sessions briefly showing a "Working" state when opened in desktop and web clients.
|
|
||||||
|
|
||||||
- [#3346](https://github.com/MoonshotAI/kimi-code/pull/3346) [`ece9618`](https://github.com/MoonshotAI/kimi-code/commit/ece96185e93742db4771de83147f709f22ca6130) Thanks [@tpoisonooo](https://github.com/tpoisonooo)! - Tower mode (experimental, `KIMI_CODE_EXPERIMENTAL_TOWER=1`): spawned workers now start from the base checkout's uncommitted changes instead of missing them, and TowerMerge refuses to merge while the checkout still holds those changes uncommitted. Also, a new session can now enter tower mode after the previous owning session stopped without exiting, instead of being refused while that session stays open. Tower mode now stays on after tower teardown; turn it off explicitly with /tower off. Tower mode is now mutually exclusive with plan mode and swarm mode: entering any one of them exits the others.
|
|
||||||
|
|
||||||
- [#3399](https://github.com/MoonshotAI/kimi-code/pull/3399) [`c3bf6f9`](https://github.com/MoonshotAI/kimi-code/commit/c3bf6f9d2d9d9de53a86052193c038b324eebeca) Thanks [@tpoisonooo](https://github.com/tpoisonooo)! - Tower mode (experimental, `KIMI_CODE_EXPERIMENTAL_TOWER=1`): the agent can no longer enter tower mode on its own — turn it on with /tower on, or with /tower <base-branch> (also in the web UI) to pin the local branch missions merge back into; a missing base branch is created from the current checkout (uncommitted changes committed onto it as a labeled WIP snapshot) and the workspace is initialized or rebased to it immediately, refusing with guidance while missions are open. Tower agents that die (failed, timed out, killed, or lost) are recorded in the tower protocol — TowerStatus marks them in the roster and warns about missions whose owner died, with a resume hint — and the tower's console instructions now require summarizing every worker's deliverables per mission before teardown.
|
|
||||||
|
|
||||||
- [#3454](https://github.com/MoonshotAI/kimi-code/pull/3454) [`913a242`](https://github.com/MoonshotAI/kimi-code/commit/913a24228beaad4bcd0a9c9ee704999b0d617ad4) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Fixed the context usage ring not refreshing after compaction; session usage now updates live from transcript metadata.
|
|
||||||
|
|
||||||
- [#3391](https://github.com/MoonshotAI/kimi-code/pull/3391) [`5f0aa7f`](https://github.com/MoonshotAI/kimi-code/commit/5f0aa7f6d61c1ce5e26f11852375fc7fd94db27b) Thanks [@7Sageer](https://github.com/7Sageer)! - Default the workspace trust prompt selection to "Trust this folder" instead of "Don't trust".
|
|
||||||
|
|
||||||
- [#3366](https://github.com/MoonshotAI/kimi-code/pull/3366) [`9619277`](https://github.com/MoonshotAI/kimi-code/commit/961927739ef34819d67d76fa5870cbe4ba7a01ff) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Use the Unicode ellipsis "…" in user-facing TUI and VS Code webview text.
|
|
||||||
|
|
||||||
- [#3405](https://github.com/MoonshotAI/kimi-code/pull/3405) [`630a11d`](https://github.com/MoonshotAI/kimi-code/commit/630a11db51ab0ac422cae6a10580b62c1ae8e05f) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Download compressed native update artifacts and decompress them while staging.
|
|
||||||
|
|
||||||
## 0.39.1
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Fix the command tool row rendering noticeably taller than other tool rows.
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Fix the first IME (or keyboard) character being silently swallowed after clicking the placeholder text in an empty composer.
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Fix switching the permission mode in one session changing it for every session; the permission mode is now scoped per session.
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Fix flickering and broken interactions in the image and video attachment preview popovers.
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Fix attachments in a newly created session still showing as uploading after the upload has finished.
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Render the rich composer placeholder outside the editor, fixing the first typed/IME character being swallowed.
|
|
||||||
|
|
||||||
- [#3307](https://github.com/MoonshotAI/kimi-code/pull/3307) [`0310f22`](https://github.com/MoonshotAI/kimi-code/commit/0310f223daf9596ac403e94c7224ce2f744951c3) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Increase the request timeout for `kimi update`.
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Unify right-side panel headers and give the OpenIn menu a file mode (copy absolute path, editor picker, full-path tooltip).
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Fix signed-in users without a usable model being wrongly asked to sign in (and getting stuck there on web); the send gate now offers picking or configuring a model instead.
|
|
||||||
|
|
||||||
- [#3333](https://github.com/MoonshotAI/kimi-code/pull/3333) [`8f43674`](https://github.com/MoonshotAI/kimi-code/commit/8f43674b902213f876359d82fa3831f485e3e82b) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: Fix startup getting stuck on "Connecting…" for a long time when the account has many workspaces.
|
|
||||||
|
|
||||||
- [#3328](https://github.com/MoonshotAI/kimi-code/pull/3328) [`dc6028d`](https://github.com/MoonshotAI/kimi-code/commit/dc6028dc6b5c9464039f16cfe38de6ba90a68b72) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Fixed skill instructions injected by the Skill tool showing up as ordinary user messages in the rebuilt transcript.
|
|
||||||
|
|
||||||
- [#3292](https://github.com/MoonshotAI/kimi-code/pull/3292) [`23921e9`](https://github.com/MoonshotAI/kimi-code/commit/23921e9f2c5a50f66ad5616554fac8565772919d) Thanks [@7Sageer](https://github.com/7Sageer)! - When a session resumes, the assistant is warned that background tasks from the previous session may still be running.
|
|
||||||
|
|
||||||
## 0.39.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- [#3034](https://github.com/MoonshotAI/kimi-code/pull/3034) [`f0a6094`](https://github.com/MoonshotAI/kimi-code/commit/f0a609487fb835371c608cde101a6ff544c3c33e) Thanks [@sailist](https://github.com/sailist)! - Add Remote Control as an experimental feature for accessing a local web session remotely. Enable it with `KIMI_CODE_EXPERIMENTAL_REMOTE_CONTROL=1`, then run `kimi rc`, `kimi web --remote-control`, or `/remote-control` to start it.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the slash-command and @-mention panels failing to open on mobile — both panels and the + menu are now grab-handle bottom sheets on small screens.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Add a flat/by-workspace tab to the mobile session list.
|
|
||||||
|
|
||||||
- [#3296](https://github.com/MoonshotAI/kimi-code/pull/3296) [`df9e858`](https://github.com/MoonshotAI/kimi-code/commit/df9e8583882bc0fbc8ff824fc1c627c9bdbc315b) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Revamp the right sidebar as a multi-tab panel.
|
|
||||||
|
|
||||||
- [#3007](https://github.com/MoonshotAI/kimi-code/pull/3007) [`f6736d7`](https://github.com/MoonshotAI/kimi-code/commit/f6736d7c0de609d44ed1cb761cfe9f195c4d94fb) Thanks [@7Sageer](https://github.com/7Sageer)! - Add an optional `fork` parameter to subagent and swarm tools that starts the subagent with a snapshot of the calling agent's conversation history; set `KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK=1` or `subagent_fork = true` under `[experimental]` in config.toml to enable it.
|
|
||||||
|
|
||||||
- [#3296](https://github.com/MoonshotAI/kimi-code/pull/3296) [`df9e858`](https://github.com/MoonshotAI/kimi-code/commit/df9e8583882bc0fbc8ff824fc1c627c9bdbc315b) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Allow moving a running foreground Bash command or subagent to the background via the "Move to background" button on the running card.
|
|
||||||
|
|
||||||
- [#3099](https://github.com/MoonshotAI/kimi-code/pull/3099) [`0f44537`](https://github.com/MoonshotAI/kimi-code/commit/0f44537c13e7c32b9189e20af7c894c34704be5b) Thanks [@wbxl2000](https://github.com/wbxl2000)! - Add experimental tower mode for multi-agent orchestration; set `KIMI_CODE_EXPERIMENTAL_TOWER=1`, then run `/tower on` and `/tower <objective>` to start.
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#3241](https://github.com/MoonshotAI/kimi-code/pull/3241) [`1dc34b4`](https://github.com/MoonshotAI/kimi-code/commit/1dc34b46de62a6aa0e308a71d824ecb7487b1374) Thanks [@tpoisonooo](https://github.com/tpoisonooo)! - Silence the MaxListenersExceededWarning that could appear during long agent turns with many parallel tool calls.
|
|
||||||
|
|
||||||
- [#3166](https://github.com/MoonshotAI/kimi-code/pull/3166) [`d4e0ad4`](https://github.com/MoonshotAI/kimi-code/commit/d4e0ad4b2d04d676b6d139ee320ea162289d3f4b) Thanks [@liruifengv](https://github.com/liruifengv)! - web: fix thinking blocks in the subagent detail panel being stuck expanded and not collapsible.
|
|
||||||
|
|
||||||
- [#3139](https://github.com/MoonshotAI/kimi-code/pull/3139) [`381142a`](https://github.com/MoonshotAI/kimi-code/commit/381142aff1d165f4bf67327035afec81ab4f656b) Thanks [@sailist](https://github.com/sailist)! - Fix sessions failing to archive when their workspace folder no longer exists.
|
|
||||||
|
|
||||||
- [#3034](https://github.com/MoonshotAI/kimi-code/pull/3034) [`f0a6094`](https://github.com/MoonshotAI/kimi-code/commit/f0a609487fb835371c608cde101a6ff544c3c33e) Thanks [@sailist](https://github.com/sailist)! - Fix messages sent from one web client not appearing on other clients connected to the same session.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix pressing Esc to cancel an IME candidate also closing the BTW side chat.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the composer not receiving focus after opening the BTW side chat via the shortcut or /btw.
|
|
||||||
|
|
||||||
- [#3212](https://github.com/MoonshotAI/kimi-code/pull/3212) [`a664226`](https://github.com/MoonshotAI/kimi-code/commit/a664226bf2244a232fd778064e2f1edf7691d268) Thanks [@sailist](https://github.com/sailist)! - Preserve the active session and its selected model when logging out of a provider.
|
|
||||||
|
|
||||||
- [#3136](https://github.com/MoonshotAI/kimi-code/pull/3136) [`e9a99e5`](https://github.com/MoonshotAI/kimi-code/commit/e9a99e5ec6843b590c44c63c3d604702c24b1bca) Thanks [@wbxl2000](https://github.com/wbxl2000)! - Add the Tencent CloudBase plugin to the curated marketplace.
|
|
||||||
|
|
||||||
- [#3296](https://github.com/MoonshotAI/kimi-code/pull/3296) [`df9e858`](https://github.com/MoonshotAI/kimi-code/commit/df9e8583882bc0fbc8ff824fc1c627c9bdbc315b) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Improve code block interaction and rendering.
|
|
||||||
|
|
||||||
- [#3296](https://github.com/MoonshotAI/kimi-code/pull/3296) [`df9e858`](https://github.com/MoonshotAI/kimi-code/commit/df9e8583882bc0fbc8ff824fc1c627c9bdbc315b) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Improve composer interaction, including the presentation of file, folder, and media attachments.
|
|
||||||
|
|
||||||
- [#3152](https://github.com/MoonshotAI/kimi-code/pull/3152) [`3090c1c`](https://github.com/MoonshotAI/kimi-code/commit/3090c1c4821df5e901c8d92dc9b77341fa16747a) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix composer toolbar buttons squeezing and overlapping each other in very narrow windows.
|
|
||||||
|
|
||||||
- [#3154](https://github.com/MoonshotAI/kimi-code/pull/3154) [`54bb49e`](https://github.com/MoonshotAI/kimi-code/commit/54bb49e138ad8a2c6e20008b4ea32a3917cc7b1a) Thanks [@Grapedge](https://github.com/Grapedge)! - Fix the latest reply disappearing from the transcript after a scheduled cron reminder fires.
|
|
||||||
|
|
||||||
- [#3034](https://github.com/MoonshotAI/kimi-code/pull/3034) [`f0a6094`](https://github.com/MoonshotAI/kimi-code/commit/f0a609487fb835371c608cde101a6ff544c3c33e) Thanks [@sailist](https://github.com/sailist)! - Remove the `--allow-remote-terminals` flag from `kimi web`; PTY terminal routes now stay available on loopback binds only.
|
|
||||||
|
|
||||||
- [#3183](https://github.com/MoonshotAI/kimi-code/pull/3183) [`2adc6a1`](https://github.com/MoonshotAI/kimi-code/commit/2adc6a1c6e1adeb696b0edc00a77ef90c54c8218) Thanks [@sailist](https://github.com/sailist)! - Fix ACP session regressions: Bash, Grep, and Glob failing when the editor does not support terminal command execution, session creation failing with stdio MCP servers, and reopening a closed session failing with an internal error.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix memory usage growing steadily after repeatedly switching sessions and toggling the side chat and subagent panels.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix unsent composer attachments such as images being lost after switching sessions on the new-session page.
|
|
||||||
|
|
||||||
- [#3296](https://github.com/MoonshotAI/kimi-code/pull/3296) [`df9e858`](https://github.com/MoonshotAI/kimi-code/commit/df9e8583882bc0fbc8ff824fc1c627c9bdbc315b) Thanks [@liruifengv](https://github.com/liruifengv)! - Fix known issues.
|
|
||||||
|
|
||||||
- [#3294](https://github.com/MoonshotAI/kimi-code/pull/3294) [`21f7ef6`](https://github.com/MoonshotAI/kimi-code/commit/21f7ef64f0851504227617f4501bf8359031d9a5) Thanks [@liruifengv](https://github.com/liruifengv)! - Fix sign-in briefly showing a device-code-expired error after a successful authorization.
|
|
||||||
|
|
||||||
- [#3152](https://github.com/MoonshotAI/kimi-code/pull/3152) [`3090c1c`](https://github.com/MoonshotAI/kimi-code/commit/3090c1c4821df5e901c8d92dc9b77341fa16747a) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix long question text in question cards being truncated with an ellipsis instead of wrapping.
|
|
||||||
|
|
||||||
- [#3206](https://github.com/MoonshotAI/kimi-code/pull/3206) [`4d5147b`](https://github.com/MoonshotAI/kimi-code/commit/4d5147ba5da6267f52b10416469f275138fa51ce) Thanks [@sailist](https://github.com/sailist)! - Fix repeated server crashes when resuming a session that was interrupted in the middle of a turn.
|
|
||||||
|
|
||||||
- [#3159](https://github.com/MoonshotAI/kimi-code/pull/3159) [`ea0626a`](https://github.com/MoonshotAI/kimi-code/commit/ea0626ad48ee318045a22490d52c86be7d086033) Thanks [@pvzheroes125](https://github.com/pvzheroes125)! - Prevent AskUserQuestion from starting background tasks when task controls are unavailable.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Remove the redundant parenthesized domain from the login entry card titles.
|
|
||||||
|
|
||||||
- [#3234](https://github.com/MoonshotAI/kimi-code/pull/3234) [`74d9bd1`](https://github.com/MoonshotAI/kimi-code/commit/74d9bd132e0b056e7d40235070b94bd7d3f4d5f2) Thanks [@xpzouying](https://github.com/xpzouying)! - Send MCP structuredContent to the model only when the tool result has no usable content, avoiding duplicate tool output.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the send and stop button icons rendering too small in the mobile composer.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Present the mobile model picker as a bottom sheet consistent with the other mobile drawers.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the oversized appearance theme cards in the mobile first-run wizard.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Temporarily remove the custom-provider entry from the mobile first-run wizard.
|
|
||||||
|
|
||||||
- [#3152](https://github.com/MoonshotAI/kimi-code/pull/3152) [`3090c1c`](https://github.com/MoonshotAI/kimi-code/commit/3090c1c4821df5e901c8d92dc9b77341fa16747a) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Improve mobile UI styling.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix tool-call rows alternating heights on mobile by unifying them to the compact row height.
|
|
||||||
|
|
||||||
- [#3152](https://github.com/MoonshotAI/kimi-code/pull/3152) [`3090c1c`](https://github.com/MoonshotAI/kimi-code/commit/3090c1c4821df5e901c8d92dc9b77341fa16747a) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Collapse the composer model picker to an icon when space is tight; hovering still shows the model and reasoning effort.
|
|
||||||
|
|
||||||
- [#3152](https://github.com/MoonshotAI/kimi-code/pull/3152) [`3090c1c`](https://github.com/MoonshotAI/kimi-code/commit/3090c1c4821df5e901c8d92dc9b77341fa16747a) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the composer permission mode label being hidden even when there is enough space.
|
|
||||||
|
|
||||||
- [#3219](https://github.com/MoonshotAI/kimi-code/pull/3219) [`d1a46db`](https://github.com/MoonshotAI/kimi-code/commit/d1a46db94efe5ed74ad2b665abdb8d697723b81f) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Show the /plugins marketplace catalog as soon as it loads, with latest-version lookups running in the background.
|
|
||||||
|
|
||||||
- [#3002](https://github.com/MoonshotAI/kimi-code/pull/3002) [`d723cc4`](https://github.com/MoonshotAI/kimi-code/commit/d723cc47ee43e5ca3c3c4ec2473f205d44acede2) Thanks [@7Sageer](https://github.com/7Sageer)! - Respect workspace trust and configuration readiness when managing MCP servers.
|
|
||||||
|
|
||||||
- [#3191](https://github.com/MoonshotAI/kimi-code/pull/3191) [`ee53d84`](https://github.com/MoonshotAI/kimi-code/commit/ee53d84fb0d0c1aa023e219b640dfa8faf6c0d38) Thanks [@7Sageer](https://github.com/7Sageer)! - Fix subagents bound to a configured secondary model ignoring its default thinking effort.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix mismatched left and right margins in the sidebar session list, and show the scrollbar only while hovering or scrolling.
|
|
||||||
|
|
||||||
- [#3164](https://github.com/MoonshotAI/kimi-code/pull/3164) [`41a75ad`](https://github.com/MoonshotAI/kimi-code/commit/41a75adfc7a56c2006c93c0b6089cf4457bce20d) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Fix the context usage bar in /usage and the footer showing a stale percentage after the context size or model changes.
|
|
||||||
|
|
||||||
- [#3198](https://github.com/MoonshotAI/kimi-code/pull/3198) [`496bb6c`](https://github.com/MoonshotAI/kimi-code/commit/496bb6ce4e555c11304074c31312c01edf4d773a) Thanks [@sailist](https://github.com/sailist)! - Add a dedicated `[swarm] timeout_ms` config option (or the `KIMI_CODE_SWARM_TIMEOUT_MS` env var) for AgentSwarm subagent timeouts, which no longer follow `[subagent] timeout_ms`.
|
|
||||||
|
|
||||||
- [#3152](https://github.com/MoonshotAI/kimi-code/pull/3152) [`3090c1c`](https://github.com/MoonshotAI/kimi-code/commit/3090c1c4821df5e901c8d92dc9b77341fa16747a) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Restyle background task notifications as a lighter notice that shows the task summary, output files, and output preview directly.
|
|
||||||
|
|
||||||
- [#3239](https://github.com/MoonshotAI/kimi-code/pull/3239) [`6595955`](https://github.com/MoonshotAI/kimi-code/commit/6595955b31a6d03fa5ea702141c7e2c0f00ba050) Thanks [@wbxl2000](https://github.com/wbxl2000)! - Fix foreground subagents being reported as background tasks on the task list.
|
|
||||||
|
|
||||||
- [#3227](https://github.com/MoonshotAI/kimi-code/pull/3227) [`4b04492`](https://github.com/MoonshotAI/kimi-code/commit/4b044926e3ca4bc98916128a9fb4ce2b2906cc4f) Thanks [@7Sageer](https://github.com/7Sageer)! - Save oversized tool output within safety limits for later inspection, report omitted MCP content, and retain partial assistant responses when streams fail.
|
|
||||||
|
|
||||||
- [#3102](https://github.com/MoonshotAI/kimi-code/pull/3102) [`2f12469`](https://github.com/MoonshotAI/kimi-code/commit/2f124693017b100346ae2a4928e7bf67dc679ddb) Thanks [@wbxl2000](https://github.com/wbxl2000)! - Fix the cold transcript rebuild splitting a turn at background-task completion notices; they now fold into the current turn like the live stream does.
|
|
||||||
|
|
||||||
- [#3271](https://github.com/MoonshotAI/kimi-code/pull/3271) [`75c94c4`](https://github.com/MoonshotAI/kimi-code/commit/75c94c4a0e87be084a14096dee2118dfa420a4af) Thanks [@sailist](https://github.com/sailist)! - Fix attached images disappearing from the user message while the agent is working.
|
|
||||||
|
|
||||||
- [#3278](https://github.com/MoonshotAI/kimi-code/pull/3278) [`b17bd61`](https://github.com/MoonshotAI/kimi-code/commit/b17bd61cefba3ea0aef5c61d5cd1085c8cfde065) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Fix the "manually stopped" state lingering after undoing the interrupted turn.
|
|
||||||
|
|
||||||
- [#3157](https://github.com/MoonshotAI/kimi-code/pull/3157) [`491ebd0`](https://github.com/MoonshotAI/kimi-code/commit/491ebd050f421de231fc4c91cdb51f7c100db649) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the reset-time hint in the sidebar usage panel being ellipsized even when there is enough room.
|
|
||||||
|
|
||||||
- [#2200](https://github.com/MoonshotAI/kimi-code/pull/2200) [`30e7f62`](https://github.com/MoonshotAI/kimi-code/commit/30e7f62d2c2c2fdaef785c544a47d0ade3e9788f) Thanks [@wszqkzqk](https://github.com/wszqkzqk)! - Fix file tools and shell working directories failing to resolve Git Bash paths such as /c/Users or /tmp on Windows.
|
|
||||||
|
|
||||||
- [#3281](https://github.com/MoonshotAI/kimi-code/pull/3281) [`7de7b18`](https://github.com/MoonshotAI/kimi-code/commit/7de7b18ee95e65d6627f884194d7dc97d77114a2) Thanks [@sailist](https://github.com/sailist)! - Fix sessions failing to resume when their session journal was truncated or corrupted, for example after a full disk.
|
|
||||||
|
|
||||||
## 0.38.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- [#2862](https://github.com/MoonshotAI/kimi-code/pull/2862) [`3d77620`](https://github.com/MoonshotAI/kimi-code/commit/3d7762003a4a35cbeb8571d471c6898a006152e6) Thanks [@liruifengv](https://github.com/liruifengv)! - Support two OAuth login methods — kimi.ai and kimi.com.
|
|
||||||
|
|
||||||
- [#3060](https://github.com/MoonshotAI/kimi-code/pull/3060) [`8440801`](https://github.com/MoonshotAI/kimi-code/commit/8440801de47ddae29224430048e1228b80cde370) Thanks [@chengluyu](https://github.com/chengluyu)! - Add the WaitFor tool: the agent can now wait for a background task to finish within the current turn instead of ending the turn and being re-invoked.
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Label inline subagent cards in the message stream with their foreground or background mode.
|
|
||||||
|
|
||||||
- [#3121](https://github.com/MoonshotAI/kimi-code/pull/3121) [`3899079`](https://github.com/MoonshotAI/kimi-code/commit/3899079a2c851bd0b3f1cbf1d3d2fd9026fc6abb) Thanks [@7Sageer](https://github.com/7Sageer)! - Fix config.toml entries being lost when the file had a syntax error or was edited outside the app.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Add copy buttons next to the server version and server address in settings.
|
|
||||||
|
|
||||||
- [#3119](https://github.com/MoonshotAI/kimi-code/pull/3119) [`a34d02a`](https://github.com/MoonshotAI/kimi-code/commit/a34d02a64f9b1526ec84e161d8c377654b413624) Thanks [@wbxl2000](https://github.com/wbxl2000)! - Add 13 data sources to the official Kimi Datasource plugin — Chinese government data (NDA/NBS) and standards (GB/HB/DB/TT), eight international organization datasets (WHO, FAO, UNSD, ECB, Eurostat, UNICEF, OECD, FRED), Xinhua Finance, and Caixin. Update the plugin from the Official tab in /plugins.
|
|
||||||
|
|
||||||
- [#3096](https://github.com/MoonshotAI/kimi-code/pull/3096) [`67fbcdf`](https://github.com/MoonshotAI/kimi-code/commit/67fbcdf1ba7dceeebb58875b3b7c81b4b30cf0de) Thanks [@sailist](https://github.com/sailist)! - Edit and Write now require reading an existing file before modifying it, and reject the write when the file changed on disk since it was last read.
|
|
||||||
|
|
||||||
- [#3101](https://github.com/MoonshotAI/kimi-code/pull/3101) [`d96b4a0`](https://github.com/MoonshotAI/kimi-code/commit/d96b4a0149f3ddf3d4910cc6eb87366dbb130ede) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - Stop retrying requests blocked by the provider content filter; the filter notice now shows immediately.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Keep empty workspace groups visible in the legacy sidebar after their last session is archived.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Hide button hover tooltips outside a menu while the menu is open.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Keep the model picker menu on the workspace home within the viewport.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the workspace group title showing untranslated text in the search dialog.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix the settings dialog dropdown list being clipped by the scroll area, and lock the content behind it while the list is open.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Keep the slash command and @ mention panels on the workspace home within the viewport.
|
|
||||||
|
|
||||||
- [#3052](https://github.com/MoonshotAI/kimi-code/pull/3052) [`6595a69`](https://github.com/MoonshotAI/kimi-code/commit/6595a6989a68163e10a85c8edf1726b30d6d2c2b) Thanks [@RealKai42](https://github.com/RealKai42)! - Fix 422 errors from some OpenAI-compatible providers when a conversation includes tool calls.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Prevent text selection in the sidebar user menu and its plan usage submenu.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix slow session list loading when there are many workspaces.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Auto-open the browser authorization page after choosing a login region, redesign the authorization waiting page, and refresh the login state as soon as the window regains focus instead of waiting for the poll.
|
|
||||||
|
|
||||||
- [#3083](https://github.com/MoonshotAI/kimi-code/pull/3083) [`571bcc2`](https://github.com/MoonshotAI/kimi-code/commit/571bcc2f751f02a37b0475b074a1e859c7fc4368) Thanks [@7Sageer](https://github.com/7Sageer)! - Fix the missing OAuth authenticate tool for remote MCP servers that require login.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Upgrade the @ mention menu: file and skill candidates are merged and ranked by match quality, file search is faster, with path-fragment matching and hit highlighting.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Round menu items concentric with their menu frames.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Add a Pin action to the chat header more-menu to pin the current session to the sidebar pinned section.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Allow dragging the divider between the pinned section and the session list to resize both areas, with fade hints at the edges when the pinned section scrolls.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Improve the prompt queue interaction, with per-row steer and send.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Add kimi.com and kimi.ai OAuth login entries, and switch update and help links to the site matching the current login.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Remove sessions archived from another client from the session list immediately, without a manual refresh.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Label the timestamp at the bottom of the session menu as last active and tighten that row's padding.
|
|
||||||
|
|
||||||
- [#3054](https://github.com/MoonshotAI/kimi-code/pull/3054) [`cfc3350`](https://github.com/MoonshotAI/kimi-code/commit/cfc335048378d3708666e11959c8d34507a1d659) Thanks [@Grapedge](https://github.com/Grapedge)! - Collapse long `!` shell command output instead of flooding the transcript. Press ctrl+o to expand or collapse it together with tool output.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Fix misaligned action buttons between the sidebar section headers and the session rows.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Remove the skill-activated card from skill activation messages.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Make skill-activation turns undoable so they can be withdrawn and resent.
|
|
||||||
|
|
||||||
- [#3012](https://github.com/MoonshotAI/kimi-code/pull/3012) [`ca87c58`](https://github.com/MoonshotAI/kimi-code/commit/ca87c58e6205ddf0638e5d737a5f8e939e2132b9) Thanks [@sailist](https://github.com/sailist)! - Sub-agents no longer spawn their own sub-agents by default; custom agent profiles can still allow it explicitly.
|
|
||||||
|
|
||||||
- [#3005](https://github.com/MoonshotAI/kimi-code/pull/3005) [`be8e017`](https://github.com/MoonshotAI/kimi-code/commit/be8e017597b83142282d7e6640076368bf244eae) Thanks [@wbxl2000](https://github.com/wbxl2000)! - Fix background agent rows that could not be stopped right after they appeared, and stray rows left behind when an agent failed to start.
|
|
||||||
|
|
||||||
- [#3046](https://github.com/MoonshotAI/kimi-code/pull/3046) [`f13f379`](https://github.com/MoonshotAI/kimi-code/commit/f13f3790448f64448c76a415500041443ae754e6) Thanks [@7Sageer](https://github.com/7Sageer)! - Fix the model being directed to unavailable tools when it encounters an image or binary file.
|
|
||||||
|
|
||||||
- [#3108](https://github.com/MoonshotAI/kimi-code/pull/3108) [`05f2ad5`](https://github.com/MoonshotAI/kimi-code/commit/05f2ad5ddad1addf10ead6f5274554ca10cde1f4) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: clearing a goal now removes it from the transcript view instead of leaving the stale goal displayed.
|
|
||||||
|
|
||||||
- [#3108](https://github.com/MoonshotAI/kimi-code/pull/3108) [`05f2ad5`](https://github.com/MoonshotAI/kimi-code/commit/05f2ad5ddad1addf10ead6f5274554ca10cde1f4) Thanks [@kimi-agent-bot](https://github.com/kimi-agent-bot)! - web: attachments sent with a prompt now appear in the live transcript immediately instead of only after a reload.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Tighten the row height and spacing of the account menu and its submenus to match the standard menu density.
|
|
||||||
|
|
||||||
- [#3135](https://github.com/MoonshotAI/kimi-code/pull/3135) [`2c5415f`](https://github.com/MoonshotAI/kimi-code/commit/2c5415f930db3edef3e79a4e88c4ee74af123600) Thanks [@liruifengv](https://github.com/liruifengv)! - web: Give WaitFor tool calls a dedicated quiet-line display showing completed tasks, wait timeouts, and how many tasks are still running.
|
|
||||||
|
|
||||||
## 0.37.2
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [#3061](https://github.com/MoonshotAI/kimi-code/pull/3061) [`5c661f4`](https://github.com/MoonshotAI/kimi-code/commit/5c661f4610f36481dbf2f9598aa63f49004e4980) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: the subagent detail panel now keeps the working process fully expanded and drops the end-of-turn timestamp footer.
|
|
||||||
|
|
||||||
- [#3061](https://github.com/MoonshotAI/kimi-code/pull/3061) [`5c661f4`](https://github.com/MoonshotAI/kimi-code/commit/5c661f4610f36481dbf2f9598aa63f49004e4980) Thanks [@wbxl2000](https://github.com/wbxl2000)! - web: Settings gains a Lab tab with a multi-tab sidebar toggle (off by default); when enabled, the sidebar shows the Open / Done / Workspaces tabs.
|
|
||||||
|
|
||||||
## 0.37.1
|
## 0.37.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
13
apps/kimi-code/dist-web/assets/DesignSystemView-DYlavtYR.js
Normal file
13
apps/kimi-code/dist-web/assets/DesignSystemView-DYlavtYR.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
import{bQ as A,M as H,aU as b,bE as V,az as J,aL as O,s as Q,v as R,I as F,bJ as G,bL as K,aw as L,H as W,bb as Z,bB as ee,g as te,au as le,T as ae,as as B,bR as ne}from"./index--0t1wzw_.js";var k=(h,E,e)=>new Promise((o,p)=>{var i=a=>{try{d(e.next(a))}catch(c){p(c)}},y=a=>{try{d(e.throw(a))}catch(c){p(c)}},d=a=>a.done?o(a.value):Promise.resolve(a.value).then(i,y);d((e=e.apply(h,E)).next())});const oe=["id"],ie=["data-placement"],ue=A(H({__name:"Tooltip",props:{visible:{type:Boolean},anchorEl:{},content:{},placement:{},offset:{},originX:{},originY:{},id:{},isDark:{type:[Boolean,null]}},setup(h){var E;const e=h,o=b(null),p=b(null),i=b({transform:"translate3d(0px, 0px, 0px)",left:"0px",top:"0px"}),y=b({}),d=b((E=e.placement)!=null?E:"top"),a=b(!1);let c=null,$=null,T=null,C=null,w=null,s=0;function X(){return C?Promise.resolve(C):(w||(w=ne(()=>import("./floating-ui.dom-xGUaHE3m.js"),[]).then(l=>(C=l,l)).catch(l=>{throw w=null,l})),w)}function D(){c&&(c(),c=null),$=null,T=null}function P(l){return k(this,null,function*(){const t=e.anchorEl,n=o.value;if(!e.visible||!t||!n||$===t&&T===n)return;const{autoUpdate:r}=yield X();l()&&e.visible&&e.anchorEl===t&&o.value===n&&(D(),$=t,T=n,c=r(t,n,()=>{N().catch(()=>{_()})}))})}function N(){return k(this,null,function*(){var l,t;const n=e.anchorEl,r=o.value;if(!e.visible||!n||!r)return!1;const{arrow:u,computePosition:m,flip:v,offset:f,shift:x}=yield X();if(!e.visible||e.anchorEl!==n||o.value!==r)return!1;const g=[f((l=e.offset)!=null?l:6),v(),x({padding:6}),...p.value?[u({element:p.value,padding:4})]:[]],{x:S,y:j,placement:Y,middlewareData:z}=yield m(n,r,{placement:(t=e.placement)!=null?t:"top",middleware:g,strategy:"fixed"});if(!e.visible||e.anchorEl!==n||o.value!==r)return!1;if(i.value.transform=`translate3d(${Math.round(S)}px, ${Math.round(j)}px, 0)`,i.value.left="0px",i.value.top="0px",d.value=Y,z.arrow&&p.value){const{x:I,y:U}=z.arrow,q={top:"bottom",bottom:"top",left:"right",right:"left"}[Y.split("-")[0]];y.value={left:I!=null?`${I}px`:"",top:U!=null?`${U}px`:"",[q]:"-3px"}}return!0})}function _(){var l,t;const n=e.anchorEl,r=o.value;if(!n||!r)return!1;const u=n.getBoundingClientRect(),m=r.getBoundingClientRect(),v=(l=e.offset)!=null?l:6,f=(t=e.placement)!=null?t:"top";let x=u.left,g=u.top;return f==="bottom"?g=u.bottom+v:f==="left"?x=u.left-m.width-v:f==="right"?x=u.right+v:g=u.top-m.height-v,i.value.transform=`translate3d(${Math.round(Math.max(0,x))}px, ${Math.round(Math.max(0,g))}px, 0)`,i.value.left="0px",i.value.top="0px",d.value=f,y.value={},!0}V(()=>e.visible,l=>k(null,null,function*(){const t=++s;if(l){if(a.value=!1,yield B(),t!==s||!e.visible)return;if(e.anchorEl&&o.value)try{const n=e.anchorEl,r=o.value,u=n.getBoundingClientRect();if(!(yield N())||t!==s||!e.visible||e.anchorEl!==n||o.value!==r)return;const m=i.value.transform;if(e.originX!=null&&e.originY!=null){const v=Math.abs(Number(e.originX)-u.left),f=Math.abs(Number(e.originY)-u.top);if(Math.hypot(v,f)>120){if(i.value.transform=`translate3d(${Math.round(e.originX)}px, ${Math.round(e.originY)}px, 0)`,yield B(),t!==s||!e.visible||(a.value=!0,yield B(),t!==s||!e.visible))return;i.value.transform=m}else a.value=!0}else a.value=!0;yield P(()=>t===s)}catch{if(t!==s||!e.visible)return;if(a.value=_(),e.anchorEl&&o.value)try{yield P(()=>t===s)}catch{}}else a.value=!0}else a.value=!1,D()}));let M=0;return V([()=>e.anchorEl,()=>e.placement,()=>e.content],()=>k(null,null,function*(){const l=++M;if(e.visible&&e.anchorEl&&o.value){if(yield B(),l!==M||!e.visible||!e.anchorEl||!o.value)return;try{const t=yield N();if(l!==M||!e.visible||!e.anchorEl||!o.value)return;t||_()}catch{_()}yield P(()=>l===M)}})),J(()=>{s+=1,D()}),(l,t)=>(O(),Q(ae,{to:"body"},[R("div",{class:le(["markstream-vue",{dark:h.isDark}])},[F(te,{name:"tooltip",appear:""},{default:G(()=>[K(R("div",{id:e.id,ref_key:"tooltip",ref:o,style:L({position:"fixed",left:i.value.left,top:i.value.top,transform:i.value.transform,visibility:a.value?"visible":"hidden",pointerEvents:a.value?void 0:"none"}),class:"tooltip-element",role:"tooltip"},[W(Z(h.content)+" ",1),R("div",{ref_key:"arrowEl",ref:p,class:"tooltip-arrow","data-placement":d.value,style:L(y.value)},null,12,ie)],12,oe),[[ee,h.visible]])]),_:1})],2)]))}}),[["__scopeId","data-v-c606ee4c"]]);export{ue as default};
|
import{bQ as A,M as H,aU as b,bE as V,az as J,aL as O,s as Q,v as R,I as F,bJ as G,bL as K,aw as L,H as W,bb as Z,bB as ee,g as te,au as le,T as ae,as as B,bR as ne}from"./index-BdL5hCoZ.js";var k=(h,E,e)=>new Promise((o,p)=>{var i=a=>{try{d(e.next(a))}catch(c){p(c)}},y=a=>{try{d(e.throw(a))}catch(c){p(c)}},d=a=>a.done?o(a.value):Promise.resolve(a.value).then(i,y);d((e=e.apply(h,E)).next())});const oe=["id"],ie=["data-placement"],ue=A(H({__name:"Tooltip",props:{visible:{type:Boolean},anchorEl:{},content:{},placement:{},offset:{},originX:{},originY:{},id:{},isDark:{type:[Boolean,null]}},setup(h){var E;const e=h,o=b(null),p=b(null),i=b({transform:"translate3d(0px, 0px, 0px)",left:"0px",top:"0px"}),y=b({}),d=b((E=e.placement)!=null?E:"top"),a=b(!1);let c=null,$=null,T=null,C=null,w=null,s=0;function X(){return C?Promise.resolve(C):(w||(w=ne(()=>import("./floating-ui.dom-xGUaHE3m.js"),[]).then(l=>(C=l,l)).catch(l=>{throw w=null,l})),w)}function D(){c&&(c(),c=null),$=null,T=null}function P(l){return k(this,null,function*(){const t=e.anchorEl,n=o.value;if(!e.visible||!t||!n||$===t&&T===n)return;const{autoUpdate:r}=yield X();l()&&e.visible&&e.anchorEl===t&&o.value===n&&(D(),$=t,T=n,c=r(t,n,()=>{N().catch(()=>{_()})}))})}function N(){return k(this,null,function*(){var l,t;const n=e.anchorEl,r=o.value;if(!e.visible||!n||!r)return!1;const{arrow:u,computePosition:m,flip:v,offset:f,shift:x}=yield X();if(!e.visible||e.anchorEl!==n||o.value!==r)return!1;const g=[f((l=e.offset)!=null?l:6),v(),x({padding:6}),...p.value?[u({element:p.value,padding:4})]:[]],{x:S,y:j,placement:Y,middlewareData:z}=yield m(n,r,{placement:(t=e.placement)!=null?t:"top",middleware:g,strategy:"fixed"});if(!e.visible||e.anchorEl!==n||o.value!==r)return!1;if(i.value.transform=`translate3d(${Math.round(S)}px, ${Math.round(j)}px, 0)`,i.value.left="0px",i.value.top="0px",d.value=Y,z.arrow&&p.value){const{x:I,y:U}=z.arrow,q={top:"bottom",bottom:"top",left:"right",right:"left"}[Y.split("-")[0]];y.value={left:I!=null?`${I}px`:"",top:U!=null?`${U}px`:"",[q]:"-3px"}}return!0})}function _(){var l,t;const n=e.anchorEl,r=o.value;if(!n||!r)return!1;const u=n.getBoundingClientRect(),m=r.getBoundingClientRect(),v=(l=e.offset)!=null?l:6,f=(t=e.placement)!=null?t:"top";let x=u.left,g=u.top;return f==="bottom"?g=u.bottom+v:f==="left"?x=u.left-m.width-v:f==="right"?x=u.right+v:g=u.top-m.height-v,i.value.transform=`translate3d(${Math.round(Math.max(0,x))}px, ${Math.round(Math.max(0,g))}px, 0)`,i.value.left="0px",i.value.top="0px",d.value=f,y.value={},!0}V(()=>e.visible,l=>k(null,null,function*(){const t=++s;if(l){if(a.value=!1,yield B(),t!==s||!e.visible)return;if(e.anchorEl&&o.value)try{const n=e.anchorEl,r=o.value,u=n.getBoundingClientRect();if(!(yield N())||t!==s||!e.visible||e.anchorEl!==n||o.value!==r)return;const m=i.value.transform;if(e.originX!=null&&e.originY!=null){const v=Math.abs(Number(e.originX)-u.left),f=Math.abs(Number(e.originY)-u.top);if(Math.hypot(v,f)>120){if(i.value.transform=`translate3d(${Math.round(e.originX)}px, ${Math.round(e.originY)}px, 0)`,yield B(),t!==s||!e.visible||(a.value=!0,yield B(),t!==s||!e.visible))return;i.value.transform=m}else a.value=!0}else a.value=!0;yield P(()=>t===s)}catch{if(t!==s||!e.visible)return;if(a.value=_(),e.anchorEl&&o.value)try{yield P(()=>t===s)}catch{}}else a.value=!0}else a.value=!1,D()}));let M=0;return V([()=>e.anchorEl,()=>e.placement,()=>e.content],()=>k(null,null,function*(){const l=++M;if(e.visible&&e.anchorEl&&o.value){if(yield B(),l!==M||!e.visible||!e.anchorEl||!o.value)return;try{const t=yield N();if(l!==M||!e.visible||!e.anchorEl||!o.value)return;t||_()}catch{_()}yield P(()=>l===M)}})),J(()=>{s+=1,D()}),(l,t)=>(O(),Q(ae,{to:"body"},[R("div",{class:le(["markstream-vue",{dark:h.isDark}])},[F(te,{name:"tooltip",appear:""},{default:G(()=>[K(R("div",{id:e.id,ref_key:"tooltip",ref:o,style:L({position:"fixed",left:i.value.left,top:i.value.top,transform:i.value.transform,visibility:a.value?"visible":"hidden",pointerEvents:a.value?void 0:"none"}),class:"tooltip-element",role:"tooltip"},[W(Z(h.content)+" ",1),R("div",{ref_key:"arrowEl",ref:p,class:"tooltip-arrow","data-placement":d.value,style:L(y.value)},null,12,ie)],12,oe),[[ee,h.visible]])]),_:1})],2)]))}}),[["__scopeId","data-v-c606ee4c"]]);export{ue as default};
|
||||||
|
|
@ -1 +1 @@
|
||||||
import{g as p,r as u,d as a}from"./chunk-MOJQB5TN-DcgqWRh_.js";import{p as f}from"./chunk-JWPE2WC7-C7S97jLg.js";import{_ as n,l as o}from"./mermaid.core-CqiFQExc.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-DEnbetzx.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},F={parser:R,db:a,renderer:u,styles:p};export{F as diagram};
|
import{g as p,r as u,d as a}from"./chunk-MOJQB5TN-CC2YIE_t.js";import{p as f}from"./chunk-JWPE2WC7-DYhWNXPR.js";import{_ as n,l as o}from"./mermaid.core-cXaFT3ek.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-BRNWksTk.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},F={parser:R,db:a,renderer:u,styles:p};export{F as diagram};
|
||||||
1
apps/kimi-code/dist-web/assets/arc-CddDuEjz.js
Normal file
1
apps/kimi-code/dist-web/assets/arc-CddDuEjz.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
import{G as ln,H as un,I as N,J as I,K as J,L as an,M as y,N as tn,O as j,P as _,Q as rn,R as o,S as on,T as sn,V as fn}from"./mermaid.core-cXaFT3ek.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,q,O,v,R,K,u){var D=q-l,i=O-h,n=K-v,d=u-R,a=d*D-n*i;if(!(a*a<y))return a=(n*(h-R)-d*(l-v))/a,[l+a*D,h+a*i]}function W(l,h,q,O,v,R,K){var u=l-q,D=h-O,i=(K?R:-R)/j(u*u+D*D),n=i*D,d=-i*u,a=l+n,s=h+d,f=q+n,c=O+d,L=(a+f)/2,t=(s+c)/2,m=f-a,g=c-s,A=m*m+g*g,T=v-R,P=a*c-f*s,E=(g<0?-1:1)*j(on(0,T*T*A-P*P)),G=(P*g-m*E)/A,H=(-P*m-g*E)/A,w=(P*g+m*E)/A,p=(-P*m+g*E)/A,x=G-L,e=H-t,r=w-L,M=p-t;return x*x+e*e>r*r+M*M&&(G=w,H=p),{cx:G,cy:H,x01:-n,y01:-d,x11:G*(v/T-1),y11:H*(v/T-1)}}function hn(){var l=cn,h=yn,q=J(0),O=null,v=gn,R=dn,K=mn,u=null,D=ln(i);function i(){var n,d,a=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-an,c=R.apply(this,arguments)-an,L=rn(c-f),t=c>f;if(u||(u=n=D()),s<a&&(d=s,s=a,a=d),!(s>y))u.moveTo(0,0);else if(L>tn-y)u.moveTo(s*N(f),s*I(f)),u.arc(0,0,s,f,c,!t),a>y&&(u.moveTo(a*N(c),a*I(c)),u.arc(0,0,a,c,f,t));else{var m=f,g=c,A=f,T=c,P=L,E=L,G=K.apply(this,arguments)/2,H=G>y&&(O?+O.apply(this,arguments):j(a*a+s*s)),w=_(rn(s-a)/2,+q.apply(this,arguments)),p=w,x=w,e,r;if(H>y){var M=sn(H/a*I(G)),z=sn(H/s*I(G));(P-=M*2)>y?(M*=t?1:-1,A+=M,T-=M):(P=0,A=T=(f+c)/2),(E-=z*2)>y?(z*=t?1:-1,m+=z,g-=z):(E=0,m=g=(f+c)/2)}var Q=s*N(m),V=s*I(m),B=a*N(T),C=a*I(T);if(w>y){var F=s*N(g),U=s*I(g),X=a*N(A),Y=a*I(A),S;if(L<un)if(S=pn(Q,V,X,Y,F,U,B,C)){var Z=Q-S[0],$=V-S[1],k=F-S[0],b=U-S[1],nn=1/I(fn((Z*k+$*b)/(j(Z*Z+$*$)*j(k*k+b*b)))/2),en=j(S[0]*S[0]+S[1]*S[1]);p=_(w,(a-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}E>y?x>y?(e=W(X,Y,Q,V,s,x,t),r=W(F,U,B,C,s,x,t),u.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),u.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(u.moveTo(Q,V),u.arc(0,0,s,m,g,!t)):u.moveTo(Q,V),!(a>y)||!(P>y)?u.lineTo(B,C):p>y?(e=W(B,C,F,U,a,-p,t),r=W(Q,V,X,Y,a,-p,t),u.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?u.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,a,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),u.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):u.arc(0,0,a,T,A,t)}if(u.closePath(),n)return u=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +R.apply(this,arguments))/2-un/2;return[N(d)*n,I(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:J(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:J(+n),i):h},i.cornerRadius=function(n){return arguments.length?(q=typeof n=="function"?n:J(+n),i):q},i.padRadius=function(n){return arguments.length?(O=n==null?null:typeof n=="function"?n:J(+n),i):O},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:J(+n),i):v},i.endAngle=function(n){return arguments.length?(R=typeof n=="function"?n:J(+n),i):R},i.padAngle=function(n){return arguments.length?(K=typeof n=="function"?n:J(+n),i):K},i.context=function(n){return arguments.length?(u=n??null,i):u},i}export{hn as d};
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
import{P as ln,Q as an,R as j,S,T as W,V as un,W as y,X as tn,Y as C,$ as _,a0 as rn,a1 as o,a2 as on,a3 as sn,a4 as fn}from"./mermaid.core-CqiFQExc.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,E,q,v,R,X,a){var I=E-l,i=q-h,n=X-v,d=a-R,u=d*I-n*i;if(!(u*u<y))return u=(n*(h-R)-d*(l-v))/u,[l+u*I,h+u*i]}function L(l,h,E,q,v,R,X){var a=l-E,I=h-q,i=(X?R:-R)/C(a*a+I*I),n=i*I,d=-i*a,u=l+n,s=h+d,f=E+n,c=q+d,Y=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,A=m*m+g*g,T=v-R,P=u*c-f*s,O=(g<0?-1:1)*C(on(0,T*T*A-P*P)),Q=(P*g-m*O)/A,V=(-P*m-g*O)/A,w=(P*g+m*O)/A,p=(-P*m+g*O)/A,x=Q-Y,e=V-t,r=w-Y,$=p-t;return x*x+e*e>r*r+$*$&&(Q=w,V=p),{cx:Q,cy:V,x01:-n,y01:-d,x11:Q*(v/T-1),y11:V*(v/T-1)}}function hn(){var l=cn,h=yn,E=W(0),q=null,v=gn,R=dn,X=mn,a=null,I=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=R.apply(this,arguments)-un,Y=rn(c-f),t=c>f;if(a||(a=n=I()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(Y>tn-y)a.moveTo(s*j(f),s*S(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*j(c),u*S(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,A=f,T=c,P=Y,O=Y,Q=X.apply(this,arguments)/2,V=Q>y&&(q?+q.apply(this,arguments):C(u*u+s*s)),w=_(rn(s-u)/2,+E.apply(this,arguments)),p=w,x=w,e,r;if(V>y){var $=sn(V/u*S(Q)),F=sn(V/s*S(Q));(P-=$*2)>y?($*=t?1:-1,A+=$,T-=$):(P=0,A=T=(f+c)/2),(O-=F*2)>y?(F*=t?1:-1,m+=F,g-=F):(O=0,m=g=(f+c)/2)}var z=s*j(m),B=s*S(m),G=u*j(T),H=u*S(T);if(w>y){var J=s*j(g),K=s*S(g),M=u*j(A),N=u*S(A),D;if(Y<an)if(D=pn(z,B,M,N,J,K,G,H)){var U=z-D[0],Z=B-D[1],k=J-D[0],b=K-D[1],nn=1/S(fn((U*k+Z*b)/(C(U*U+Z*Z)*C(k*k+b*b)))/2),en=C(D[0]*D[0]+D[1]*D[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}O>y?x>y?(e=L(M,N,z,B,s,x,t),r=L(J,K,G,H,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(z,B),a.arc(0,0,s,m,g,!t)):a.moveTo(z,B),!(u>y)||!(P>y)?a.lineTo(G,H):p>y?(e=L(G,H,J,K,u,-p,t),r=L(z,B,M,N,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,A,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +R.apply(this,arguments))/2-an/2;return[j(d)*n,S(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:W(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:W(+n),i):h},i.cornerRadius=function(n){return arguments.length?(E=typeof n=="function"?n:W(+n),i):E},i.padRadius=function(n){return arguments.length?(q=n==null?null:typeof n=="function"?n:W(+n),i):q},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:W(+n),i):v},i.endAngle=function(n){return arguments.length?(R=typeof n=="function"?n:W(+n),i):R},i.padAngle=function(n){return arguments.length?(X=typeof n=="function"?n:W(+n),i):X},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1 +0,0 @@
|
||||||
import{U as a,O as n}from"./mermaid.core-CqiFQExc.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
|
|
||||||
1
apps/kimi-code/dist-web/assets/channel-iWyrnKRM.js
Normal file
1
apps/kimi-code/dist-web/assets/channel-iWyrnKRM.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
import{U as a,C as n}from"./mermaid.core-cXaFT3ek.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
|
||||||
|
|
@ -1 +1 @@
|
||||||
import{_ as i}from"./mermaid.core-CqiFQExc.js";var r=class{constructor(t){this.init=t,this.records=this.init()}static{i(this,"ImperativeState")}reset(){this.records=this.init()}};export{r as I};
|
import{_ as i}from"./mermaid.core-cXaFT3ek.js";var r=class{constructor(t){this.init=t,this.records=this.init()}static{i(this,"ImperativeState")}reset(){this.records=this.init()}};export{r as I};
|
||||||
|
|
@ -1 +1 @@
|
||||||
import{_ as i,d as l,N as d,j as o}from"./mermaid.core-CqiFQExc.js";var x=i((r,t)=>{const e=r.append("rect");if(e.attr("x",t.x),e.attr("y",t.y),e.attr("fill",t.fill),e.attr("stroke",t.stroke),e.attr("width",t.width),e.attr("height",t.height),t.name&&e.attr("name",t.name),t.rx&&e.attr("rx",t.rx),t.ry&&e.attr("ry",t.ry),t.attrs!==void 0)for(const s in t.attrs)e.attr(s,t.attrs[s]);return t.class&&e.attr("class",t.class),e},"drawRect"),p=i((r,t)=>{const e={x:t.startx,y:t.starty,width:t.stopx-t.startx,height:t.stopy-t.starty,fill:t.fill,stroke:t.stroke,class:"rect"};x(r,e).lower()},"drawBackgroundRect"),y=i((r,t)=>{const e=t.text.replace(d," "),s=r.append("text");s.attr("x",t.x),s.attr("y",t.y),s.attr("class","legend"),s.style("text-anchor",t.anchor),t.class&&s.attr("class",t.class);const a=s.append("tspan");return a.attr("x",t.x+t.textMargin*2),a.text(e),s},"drawText"),m=i((r,t,e,s)=>{const a=r.append("image");a.attr("x",t),a.attr("y",e);const n=o.sanitizeUrl(s);a.attr("xlink:href",n)},"drawImage"),g=i((r,t,e,s)=>{const a=r.append("use");a.attr("x",t),a.attr("y",e);const n=o.sanitizeUrl(s);a.attr("xlink:href",`#${n}`)},"drawEmbeddedImage"),h=i(()=>({x:0,y:0,width:100,height:100,fill:"#EDF2AE",stroke:"#666",anchor:"start",rx:0,ry:0}),"getNoteRect"),f=i(()=>({x:0,y:0,width:100,height:100,"text-anchor":"start",style:"#666",textMargin:0,rx:0,ry:0,tspan:!0}),"getTextObj"),w=i(()=>{let r=l(".mermaidTooltip");return r.empty()&&(r=l("body").append("div").attr("class","mermaidTooltip").style("opacity",0).style("position","absolute").style("text-align","center").style("max-width","200px").style("padding","2px").style("font-size","12px").style("background","#ffffde").style("border","1px solid #333").style("border-radius","2px").style("pointer-events","none").style("z-index","100")),r},"createTooltip");export{p as a,f as b,g as c,x as d,m as e,w as f,h as g,y as h};
|
import{_ as i,d as l,n as d,j as o}from"./mermaid.core-cXaFT3ek.js";var x=i((r,t)=>{const e=r.append("rect");if(e.attr("x",t.x),e.attr("y",t.y),e.attr("fill",t.fill),e.attr("stroke",t.stroke),e.attr("width",t.width),e.attr("height",t.height),t.name&&e.attr("name",t.name),t.rx&&e.attr("rx",t.rx),t.ry&&e.attr("ry",t.ry),t.attrs!==void 0)for(const s in t.attrs)e.attr(s,t.attrs[s]);return t.class&&e.attr("class",t.class),e},"drawRect"),p=i((r,t)=>{const e={x:t.startx,y:t.starty,width:t.stopx-t.startx,height:t.stopy-t.starty,fill:t.fill,stroke:t.stroke,class:"rect"};x(r,e).lower()},"drawBackgroundRect"),y=i((r,t)=>{const e=t.text.replace(d," "),s=r.append("text");s.attr("x",t.x),s.attr("y",t.y),s.attr("class","legend"),s.style("text-anchor",t.anchor),t.class&&s.attr("class",t.class);const a=s.append("tspan");return a.attr("x",t.x+t.textMargin*2),a.text(e),s},"drawText"),m=i((r,t,e,s)=>{const a=r.append("image");a.attr("x",t),a.attr("y",e);const n=o.sanitizeUrl(s);a.attr("xlink:href",n)},"drawImage"),g=i((r,t,e,s)=>{const a=r.append("use");a.attr("x",t),a.attr("y",e);const n=o.sanitizeUrl(s);a.attr("xlink:href",`#${n}`)},"drawEmbeddedImage"),h=i(()=>({x:0,y:0,width:100,height:100,fill:"#EDF2AE",stroke:"#666",anchor:"start",rx:0,ry:0}),"getNoteRect"),f=i(()=>({x:0,y:0,width:100,height:100,"text-anchor":"start",style:"#666",textMargin:0,rx:0,ry:0,tspan:!0}),"getTextObj"),w=i(()=>{let r=l(".mermaidTooltip");return r.empty()&&(r=l("body").append("div").attr("class","mermaidTooltip").style("opacity",0).style("position","absolute").style("text-align","center").style("max-width","200px").style("padding","2px").style("font-size","12px").style("background","#ffffde").style("border","1px solid #333").style("border-radius","2px").style("pointer-events","none").style("z-index","100")),r},"createTooltip");export{p as a,f as b,g as c,x as d,m as e,w as f,h as g,y as h};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import{_ as e}from"./mermaid.core-CqiFQExc.js";var l=e(()=>`
|
import{_ as e}from"./mermaid.core-cXaFT3ek.js";var l=e(()=>`
|
||||||
/* Font Awesome icon styling - consolidated */
|
/* Font Awesome icon styling - consolidated */
|
||||||
.label-icon {
|
.label-icon {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
import{_ as i}from"./mermaid.core-CqiFQExc.js";function t(c,e){c.accDescr&&e.setAccDescription?.(c.accDescr),c.accTitle&&e.setAccTitle?.(c.accTitle),c.title&&e.setDiagramTitle?.(c.title)}i(t,"populateCommonDb");export{t as p};
|
import{_ as i}from"./mermaid.core-cXaFT3ek.js";function t(c,e){c.accDescr&&e.setAccDescription?.(c.accDescr),c.accTitle&&e.setAccTitle?.(c.accTitle),c.title&&e.setDiagramTitle?.(c.title)}i(t,"populateCommonDb");export{t as p};
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
import{_ as a,e as w,l as x}from"./mermaid.core-CqiFQExc.js";var d=a((e,t,i,r)=>{e.attr("class",i);const{width:o,height:h,x:n,y:c}=u(e,t);w(e,h,o,r);const s=l(n,c,o,h,t);e.attr("viewBox",s),x.debug(`viewBox configured: ${s} with padding: ${t}`)},"setupViewPortForSVG"),u=a((e,t)=>{const i=e.node()?.getBBox()||{width:0,height:0,x:0,y:0};return{width:i.width+t*2,height:i.height+t*2,x:i.x,y:i.y}},"calculateDimensionsWithPadding"),l=a((e,t,i,r,o)=>`${e-o} ${t-o} ${i} ${r}`,"createViewBox");export{d as s};
|
import{_ as a,e as w,l as x}from"./mermaid.core-cXaFT3ek.js";var d=a((e,t,i,r)=>{e.attr("class",i);const{width:o,height:h,x:n,y:c}=u(e,t);w(e,h,o,r);const s=l(n,c,o,h,t);e.attr("viewBox",s),x.debug(`viewBox configured: ${s} with padding: ${t}`)},"setupViewPortForSVG"),u=a((e,t)=>{const i=e.node()?.getBBox()||{width:0,height:0,x:0,y:0};return{width:i.width+t*2,height:i.height+t*2,x:i.x,y:i.y}},"calculateDimensionsWithPadding"),l=a((e,t,i,r,o)=>`${e-o} ${t-o} ${i} ${r}`,"createViewBox");export{d as s};
|
||||||
|
|
@ -1 +1 @@
|
||||||
import{_ as a,d as o}from"./mermaid.core-CqiFQExc.js";var d=a((t,e)=>{let n;return e==="sandbox"&&(n=o("#i"+t)),(e==="sandbox"?o(n.nodes()[0].contentDocument.body):o("body")).select(`[id="${t}"]`)},"getDiagramElement");export{d as g};
|
import{_ as a,d as o}from"./mermaid.core-cXaFT3ek.js";var d=a((t,e)=>{let n;return e==="sandbox"&&(n=o("#i"+t)),(e==="sandbox"?o(n.nodes()[0].contentDocument.body):o("body")).select(`[id="${t}"]`)},"getDiagramElement");export{d as g};
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-Ci6LL3n4.js";import{_ as i}from"./mermaid.core-CqiFQExc.js";import"./chunk-5VM5RSS4-BRWxG5tM.js";import"./chunk-XXDRQBXY-4LplLZkT.js";import"./chunk-VR4S4FIN-DW1NNlBr.js";import"./chunk-32BRIVSS-mfMW4-bV.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var f={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{f as diagram};
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-CfSRFy1I.js";import{_ as i}from"./mermaid.core-cXaFT3ek.js";import"./chunk-5VM5RSS4-KnT0i4wx.js";import"./chunk-XXDRQBXY-oeuDpJ1n.js";import"./chunk-VR4S4FIN-Co_Tl-Vk.js";import"./chunk-32BRIVSS-OEA_sg25.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var f={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{f as diagram};
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-Ci6LL3n4.js";import{_ as i}from"./mermaid.core-CqiFQExc.js";import"./chunk-5VM5RSS4-BRWxG5tM.js";import"./chunk-XXDRQBXY-4LplLZkT.js";import"./chunk-VR4S4FIN-DW1NNlBr.js";import"./chunk-32BRIVSS-mfMW4-bV.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var f={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{f as diagram};
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-CfSRFy1I.js";import{_ as i}from"./mermaid.core-cXaFT3ek.js";import"./chunk-5VM5RSS4-KnT0i4wx.js";import"./chunk-XXDRQBXY-oeuDpJ1n.js";import"./chunk-VR4S4FIN-Co_Tl-Vk.js";import"./chunk-32BRIVSS-OEA_sg25.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var f={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{f as diagram};
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
||||||
import{c as O,w as I,a as J,f as P,b as E,s as A}from"./chunk-RYQCIY6F-DRHEFBXE.js";import{_ as w,am as v,an as D,ao as H,ap as Y,l,c as _,aq as W,ar as $,ag as j,as as q,ah as R,af as F,at as z,au as K,av as G}from"./mermaid.core-CqiFQExc.js";import{G as Q}from"./graph-DOmOIIwC.js";import{l as U}from"./layout-D-LzfAck.js";import"./map-DxJ2ADlA.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var C=w((s,t,g)=>Math.max(t,Math.min(g,s)),"clamp"),B=w((s="TB")=>{switch(s){case"BT":return"bottom";case"LR":return"right";case"RL":return"left";case"TB":default:return"top"}},"getDefaultSelfLoopSide"),V=w(s=>s==="flowchart"||s==="flowchart-v2"||s==="stateDiagram","shouldMergeSelfLoopSegments"),Z=w((s,t,g,m,c)=>{const o=[],r=new Set;if(g.forEach(({start:i,end:n})=>{i!==m&&r.add(i),n!==m&&r.add(n)}),r.forEach(i=>{const n=s.node(i);typeof n?.x=="number"&&typeof n?.y=="number"&&o.push(n)}),o.length===0&&g.forEach(({edge:i})=>{(i.points??[]).forEach(n=>{typeof n?.x=="number"&&typeof n?.y=="number"&&o.push(n)})}),o.length===0)return B(c);const f=o.reduce((i,n)=>({x:i.x+n.x/o.length,y:i.y+n.y/o.length}),{x:0,y:0}),h=f.x-t.x,a=f.y-t.y;return Math.abs(h)>Math.abs(a)?h>0?"right":"left":Math.abs(a)>0?a>0?"bottom":"top":B(c)},"getSelfLoopSide"),ee=w((s,t="top",g=0,m=0)=>{const c=s.x,o=s.y-g,r=s.width/2,f=s.height/2,h=Math.max(36,Math.min(100,s.width*.8)),a=C(Math.max(m,s.width*.35),36,h),i=C(Math.min(s.width,s.height)*.45,24,48);switch(t){case"bottom":{const n=o+f;return[{x:c-a/2,y:n},{x:c-a/2,y:n+i},{x:c+a/2,y:n+i},{x:c+a/2,y:n}]}case"right":{const n=c+r;return[{x:n,y:o-a/2},{x:n+i,y:o-a/2},{x:n+i,y:o+a/2},{x:n,y:o+a/2}]}case"left":{const n=c-r;return[{x:n,y:o-a/2},{x:n-i,y:o-a/2},{x:n-i,y:o+a/2},{x:n,y:o+a/2}]}case"top":default:{const n=o-f;return[{x:c-a/2,y:n},{x:c-a/2,y:n-i},{x:c+a/2,y:n-i},{x:c+a/2,y:n}]}}},"getSelfLoopPoints"),te=w((s,t,g="top",m=0,c={})=>{const r=s.x,f=s.y-m,h=c.width??0,a=c.height??0;switch(g){case"bottom":return{x:r,y:Math.max(...t.map(i=>i.y))+a/2+4};case"right":return{x:Math.max(...t.map(i=>i.x))+h/2+4,y:f};case"left":return{x:Math.min(...t.map(i=>i.x))-h/2-4,y:f};case"top":default:return{x:r,y:Math.min(...t.map(i=>i.y))-a/2-4}}},"getSelfLoopLabelPosition"),ne=w((s,t=0,{mergeSelfLoops:g=!0}={})=>{const m=new Map,c=[],o=s.graph()?.rankdir;return s.edges().forEach(r=>{const f=s.edge(r);if(g&&f.selfLoop){const h=f.selfLoop.id;m.has(h)||m.set(h,[]),m.get(h).push({edge:f,start:r.v,end:r.w})}else c.push({edge:f,start:r.v,end:r.w})}),m.forEach(r=>{if(r.length!==3){r.forEach(L=>c.push(L));return}r.sort((L,d)=>L.edge.selfLoop.order-d.edge.selfLoop.order);const[f,h,a]=r,i=f.edge.originalEdge??h.edge.originalEdge??a.edge.originalEdge??h.edge,n=s.node(i.start);if(!n){r.forEach(L=>c.push(L));return}const p={width:h.edge.width,height:h.edge.height},y=Z(s,n,r,i.start,o),X=ee(n,y,t,p.width??0),S=te(n,X,y,t,p),b={...h.edge,...i,id:i.id,points:X,start:i.start,end:i.end,x:S.x,y:S.y,width:p.width,height:p.height,labelStyle:h.edge.labelStyle,fromCluster:f.edge.fromCluster??h.edge.fromCluster??a.edge.fromCluster,toCluster:f.edge.toCluster??h.edge.toCluster??a.edge.toCluster};delete b.selfLoop,delete b.originalEdge,c.push({edge:b,start:b.start,end:b.end})}),c},"getEdgesToRender"),T=w(async(s,t,g,m,c,o)=>{l.warn("Graph in recursive render:XAX",I(t),c);const r=t.graph().rankdir;l.trace("Dir in recursive render - dir:",r);const f=s.insert("g").attr("class","root");t.nodes()?l.info("Recursive render XXX",t.nodes()):l.info("No nodes found for",t),t.edges().length>0&&l.info("Recursive edges",t.edge(t.edges()[0]));const h=f.insert("g").attr("class","clusters"),a=f.insert("g").attr("class","edgePaths"),i=f.insert("g").attr("class","edgeLabels"),n=f.insert("g").attr("class","nodes"),p=V(g);await Promise.all(t.nodes().map(async function(d){const e=t.node(d);if(c!==void 0){const u=JSON.parse(JSON.stringify(c.clusterData));l.trace(`Setting data for parent cluster XXX
|
import{c as O,w as I,a as J,f as P,b as E,s as A}from"./chunk-RYQCIY6F-CdbRlOAH.js";import{_ as w,am as v,an as D,ao as H,ap as Y,l,c as _,aq as W,ar as $,ag as j,as as q,ah as R,af as F,at as z,au as K,av as G}from"./mermaid.core-cXaFT3ek.js";import{G as Q}from"./graph-DOmOIIwC.js";import{l as U}from"./layout-D-LzfAck.js";import"./map-DxJ2ADlA.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var C=w((s,t,g)=>Math.max(t,Math.min(g,s)),"clamp"),B=w((s="TB")=>{switch(s){case"BT":return"bottom";case"LR":return"right";case"RL":return"left";case"TB":default:return"top"}},"getDefaultSelfLoopSide"),V=w(s=>s==="flowchart"||s==="flowchart-v2"||s==="stateDiagram","shouldMergeSelfLoopSegments"),Z=w((s,t,g,m,c)=>{const o=[],r=new Set;if(g.forEach(({start:i,end:n})=>{i!==m&&r.add(i),n!==m&&r.add(n)}),r.forEach(i=>{const n=s.node(i);typeof n?.x=="number"&&typeof n?.y=="number"&&o.push(n)}),o.length===0&&g.forEach(({edge:i})=>{(i.points??[]).forEach(n=>{typeof n?.x=="number"&&typeof n?.y=="number"&&o.push(n)})}),o.length===0)return B(c);const f=o.reduce((i,n)=>({x:i.x+n.x/o.length,y:i.y+n.y/o.length}),{x:0,y:0}),h=f.x-t.x,a=f.y-t.y;return Math.abs(h)>Math.abs(a)?h>0?"right":"left":Math.abs(a)>0?a>0?"bottom":"top":B(c)},"getSelfLoopSide"),ee=w((s,t="top",g=0,m=0)=>{const c=s.x,o=s.y-g,r=s.width/2,f=s.height/2,h=Math.max(36,Math.min(100,s.width*.8)),a=C(Math.max(m,s.width*.35),36,h),i=C(Math.min(s.width,s.height)*.45,24,48);switch(t){case"bottom":{const n=o+f;return[{x:c-a/2,y:n},{x:c-a/2,y:n+i},{x:c+a/2,y:n+i},{x:c+a/2,y:n}]}case"right":{const n=c+r;return[{x:n,y:o-a/2},{x:n+i,y:o-a/2},{x:n+i,y:o+a/2},{x:n,y:o+a/2}]}case"left":{const n=c-r;return[{x:n,y:o-a/2},{x:n-i,y:o-a/2},{x:n-i,y:o+a/2},{x:n,y:o+a/2}]}case"top":default:{const n=o-f;return[{x:c-a/2,y:n},{x:c-a/2,y:n-i},{x:c+a/2,y:n-i},{x:c+a/2,y:n}]}}},"getSelfLoopPoints"),te=w((s,t,g="top",m=0,c={})=>{const r=s.x,f=s.y-m,h=c.width??0,a=c.height??0;switch(g){case"bottom":return{x:r,y:Math.max(...t.map(i=>i.y))+a/2+4};case"right":return{x:Math.max(...t.map(i=>i.x))+h/2+4,y:f};case"left":return{x:Math.min(...t.map(i=>i.x))-h/2-4,y:f};case"top":default:return{x:r,y:Math.min(...t.map(i=>i.y))-a/2-4}}},"getSelfLoopLabelPosition"),ne=w((s,t=0,{mergeSelfLoops:g=!0}={})=>{const m=new Map,c=[],o=s.graph()?.rankdir;return s.edges().forEach(r=>{const f=s.edge(r);if(g&&f.selfLoop){const h=f.selfLoop.id;m.has(h)||m.set(h,[]),m.get(h).push({edge:f,start:r.v,end:r.w})}else c.push({edge:f,start:r.v,end:r.w})}),m.forEach(r=>{if(r.length!==3){r.forEach(L=>c.push(L));return}r.sort((L,d)=>L.edge.selfLoop.order-d.edge.selfLoop.order);const[f,h,a]=r,i=f.edge.originalEdge??h.edge.originalEdge??a.edge.originalEdge??h.edge,n=s.node(i.start);if(!n){r.forEach(L=>c.push(L));return}const p={width:h.edge.width,height:h.edge.height},y=Z(s,n,r,i.start,o),X=ee(n,y,t,p.width??0),S=te(n,X,y,t,p),b={...h.edge,...i,id:i.id,points:X,start:i.start,end:i.end,x:S.x,y:S.y,width:p.width,height:p.height,labelStyle:h.edge.labelStyle,fromCluster:f.edge.fromCluster??h.edge.fromCluster??a.edge.fromCluster,toCluster:f.edge.toCluster??h.edge.toCluster??a.edge.toCluster};delete b.selfLoop,delete b.originalEdge,c.push({edge:b,start:b.start,end:b.end})}),c},"getEdgesToRender"),T=w(async(s,t,g,m,c,o)=>{l.warn("Graph in recursive render:XAX",I(t),c);const r=t.graph().rankdir;l.trace("Dir in recursive render - dir:",r);const f=s.insert("g").attr("class","root");t.nodes()?l.info("Recursive render XXX",t.nodes()):l.info("No nodes found for",t),t.edges().length>0&&l.info("Recursive edges",t.edge(t.edges()[0]));const h=f.insert("g").attr("class","clusters"),a=f.insert("g").attr("class","edgePaths"),i=f.insert("g").attr("class","edgeLabels"),n=f.insert("g").attr("class","nodes"),p=V(g);await Promise.all(t.nodes().map(async function(d){const e=t.node(d);if(c!==void 0){const u=JSON.parse(JSON.stringify(c.clusterData));l.trace(`Setting data for parent cluster XXX
|
||||||
Node.id = `,d,`
|
Node.id = `,d,`
|
||||||
data=`,u.height,`
|
data=`,u.height,`
|
||||||
Parent cluster`,c.height),t.setNode(c.id,u),t.parent(d)||(l.trace("Setting parent",d,c.id),t.setParent(d,c.id,u))}if(l.info("(Insert) Node XXX"+d+": "+JSON.stringify(t.node(d))),e?.clusterNode){l.info("Cluster identified XBX",d,e.width,t.node(d));const{ranksep:u,nodesep:x}=t.graph();e.graph.setGraph({...e.graph.graph(),ranksep:u+25,nodesep:x});const N=await T(n,e.graph,g,m,t.node(d),o),M=N.elem;W(e,M),e.diff=N.diff||0,l.info("New compound node after recursive render XAX",d,"width",e.width,"height",e.height),$(M,e)}else t.children(d).length>0?(l.trace("Cluster - the non recursive path XBX",d,e.id,e,e.width,"Graph:",t),l.trace(P(e.id,t)),E.set(e.id,{id:P(e.id,t),node:e})):(l.trace("Node - the non recursive path XAX",d,n,t.node(d),r),await j(n,t.node(d),{config:o,dir:r}))})),await w(async()=>{const d=t.edges().map(async function(e){const u=t.edge(e.v,e.w,e.name);if(l.info("Edge "+e.v+" -> "+e.w+": "+JSON.stringify(e)),l.info("Edge "+e.v+" -> "+e.w+": ",e," ",JSON.stringify(t.edge(e))),l.info("Fix",E,"ids:",e.v,e.w,"Translating: ",E.get(e.v),E.get(e.w)),p&&u.selfLoop){if(u.selfLoop.order!==1)return;const x=u.id;u.id=u.selfLoop.id,await G(i,u),u.id=x;return}await G(i,u)});await Promise.all(d)},"processEdges")(),l.info("Graph before layout:",JSON.stringify(I(t))),l.info("############################################# XXX"),l.info("### Layout ### XXX"),l.info("############################################# XXX"),U(t),l.info("Graph after layout:",JSON.stringify(I(t)));let X=0,{subGraphTitleTotalMargin:S}=q(o);await Promise.all(A(t).map(async function(d){const e=t.node(d);if(l.info("Position XBX => "+d+": ("+e.x,","+e.y,") width: ",e.width," height: ",e.height),e?.clusterNode)e.y+=S,l.info("A tainted cluster node XBX1",d,e.id,e.width,e.height,e.x,e.y,t.parent(d)),E.get(e.id).node=e,R(e);else if(t.children(d).length>0){l.info("A pure cluster node XBX1",d,e.id,e.x,e.y,e.width,e.height,t.parent(d)),e.height+=S,t.node(e.parentId);const u=e?.padding/2||0,x=e?.labelBBox?.height||0,N=x-u||0;l.debug("OffsetY",N,"labelHeight",x,"halfPadding",u),await F(h,e),E.get(e.id).node=e}else{const u=t.node(e.parentId);e.y+=S/2,l.info("A regular node XBX1 - using the padding",e.id,"parent",e.parentId,e.width,e.height,e.x,e.y,"offsetY",e.offsetY,"parent",u,u?.offsetY,e),R(e)}}));const b=S/2;return ne(t,b,{mergeSelfLoops:p}).forEach(function({edge:d,start:e,end:u}){l.info("Edge "+e+" -> "+u+": "+JSON.stringify(d),d),d.points.forEach(k=>k.y+=b);const x=t.node(e),N=t.node(u),M=z(a,d,E,g,x,N,m);K(d,M)}),t.nodes().forEach(function(d){const e=t.node(d);l.info(d,e.type,e.diff),e.isGroup&&(X=e.diff)}),l.warn("Returning from recursive render XAX",f,X),{elem:f,diff:X}},"recursiveRender"),le=w(async(s,t)=>{const g=new Q({multigraph:!0,compound:!0}).setGraph({rankdir:s.direction,nodesep:s.config?.nodeSpacing||s.config?.flowchart?.nodeSpacing||s.nodeSpacing,ranksep:s.config?.rankSpacing||s.config?.flowchart?.rankSpacing||s.rankSpacing,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}}),m=t.select("g");v(m,s.markers,s.type,s.diagramId),D(),H(),Y(),O(),s.nodes.forEach(o=>{g.setNode(o.id,{...o}),o.parentId&&g.setParent(o.id,o.parentId)}),l.debug("Edges:",s.edges),s.edges.forEach(o=>{if(o.start===o.end){const r=o.start,f=r+"---"+r+"---1",h=r+"---"+r+"---2",a=g.node(r);g.setNode(f,{domId:f,id:f,parentId:a.parentId,labelStyle:"",label:"",padding:0,shape:"labelRect",style:"",width:10,height:10}),g.setParent(f,a.parentId),g.setNode(h,{domId:h,id:h,parentId:a.parentId,labelStyle:"",padding:0,shape:"labelRect",label:"",style:"",width:10,height:10}),g.setParent(h,a.parentId);const i=structuredClone(o),n=structuredClone(o),p=structuredClone(o),y=structuredClone(o);n.originalEdge=i,n.selfLoop={id:i.id,order:0},p.originalEdge=i,p.selfLoop={id:i.id,order:1},y.originalEdge=i,y.selfLoop={id:i.id,order:2},n.label="",n.arrowTypeEnd="none",n.endLabelLeft="",n.endLabelRight="",n.startLabelLeft="",n.id=r+"-cyclic-special-1",p.startLabelRight="",p.startLabelLeft="",p.endLabelLeft="",p.endLabelRight="",p.arrowTypeStart="none",p.arrowTypeEnd="none",p.id=r+"-cyclic-special-mid",y.label="",y.startLabelRight="",y.startLabelLeft="",y.arrowTypeStart="none",a.isGroup&&(n.fromCluster=r,y.toCluster=r),y.id=r+"-cyclic-special-2",y.arrowTypeStart="none",g.setEdge(r,f,n,r+"-cyclic-special-0"),g.setEdge(f,h,p,r+"-cyclic-special-1"),g.setEdge(h,r,y,r+"-cyclic-special-2")}else g.setEdge(o.start,o.end,{...o},o.id)}),l.warn("Graph at first:",JSON.stringify(I(g))),J(g),l.warn("Graph after XAX:",JSON.stringify(I(g)));const c=_();await T(m,g,s.type,s.diagramId,void 0,c)},"render");export{ne as getEdgesToRender,le as render};
|
Parent cluster`,c.height),t.setNode(c.id,u),t.parent(d)||(l.trace("Setting parent",d,c.id),t.setParent(d,c.id,u))}if(l.info("(Insert) Node XXX"+d+": "+JSON.stringify(t.node(d))),e?.clusterNode){l.info("Cluster identified XBX",d,e.width,t.node(d));const{ranksep:u,nodesep:x}=t.graph();e.graph.setGraph({...e.graph.graph(),ranksep:u+25,nodesep:x});const N=await T(n,e.graph,g,m,t.node(d),o),M=N.elem;W(e,M),e.diff=N.diff||0,l.info("New compound node after recursive render XAX",d,"width",e.width,"height",e.height),$(M,e)}else t.children(d).length>0?(l.trace("Cluster - the non recursive path XBX",d,e.id,e,e.width,"Graph:",t),l.trace(P(e.id,t)),E.set(e.id,{id:P(e.id,t),node:e})):(l.trace("Node - the non recursive path XAX",d,n,t.node(d),r),await j(n,t.node(d),{config:o,dir:r}))})),await w(async()=>{const d=t.edges().map(async function(e){const u=t.edge(e.v,e.w,e.name);if(l.info("Edge "+e.v+" -> "+e.w+": "+JSON.stringify(e)),l.info("Edge "+e.v+" -> "+e.w+": ",e," ",JSON.stringify(t.edge(e))),l.info("Fix",E,"ids:",e.v,e.w,"Translating: ",E.get(e.v),E.get(e.w)),p&&u.selfLoop){if(u.selfLoop.order!==1)return;const x=u.id;u.id=u.selfLoop.id,await G(i,u),u.id=x;return}await G(i,u)});await Promise.all(d)},"processEdges")(),l.info("Graph before layout:",JSON.stringify(I(t))),l.info("############################################# XXX"),l.info("### Layout ### XXX"),l.info("############################################# XXX"),U(t),l.info("Graph after layout:",JSON.stringify(I(t)));let X=0,{subGraphTitleTotalMargin:S}=q(o);await Promise.all(A(t).map(async function(d){const e=t.node(d);if(l.info("Position XBX => "+d+": ("+e.x,","+e.y,") width: ",e.width," height: ",e.height),e?.clusterNode)e.y+=S,l.info("A tainted cluster node XBX1",d,e.id,e.width,e.height,e.x,e.y,t.parent(d)),E.get(e.id).node=e,R(e);else if(t.children(d).length>0){l.info("A pure cluster node XBX1",d,e.id,e.x,e.y,e.width,e.height,t.parent(d)),e.height+=S,t.node(e.parentId);const u=e?.padding/2||0,x=e?.labelBBox?.height||0,N=x-u||0;l.debug("OffsetY",N,"labelHeight",x,"halfPadding",u),await F(h,e),E.get(e.id).node=e}else{const u=t.node(e.parentId);e.y+=S/2,l.info("A regular node XBX1 - using the padding",e.id,"parent",e.parentId,e.width,e.height,e.x,e.y,"offsetY",e.offsetY,"parent",u,u?.offsetY,e),R(e)}}));const b=S/2;return ne(t,b,{mergeSelfLoops:p}).forEach(function({edge:d,start:e,end:u}){l.info("Edge "+e+" -> "+u+": "+JSON.stringify(d),d),d.points.forEach(k=>k.y+=b);const x=t.node(e),N=t.node(u),M=z(a,d,E,g,x,N,m);K(d,M)}),t.nodes().forEach(function(d){const e=t.node(d);l.info(d,e.type,e.diff),e.isGroup&&(X=e.diff)}),l.warn("Returning from recursive render XAX",f,X),{elem:f,diff:X}},"recursiveRender"),le=w(async(s,t)=>{const g=new Q({multigraph:!0,compound:!0}).setGraph({rankdir:s.direction,nodesep:s.config?.nodeSpacing||s.config?.flowchart?.nodeSpacing||s.nodeSpacing,ranksep:s.config?.rankSpacing||s.config?.flowchart?.rankSpacing||s.rankSpacing,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}}),m=t.select("g");v(m,s.markers,s.type,s.diagramId),D(),H(),Y(),O(),s.nodes.forEach(o=>{g.setNode(o.id,{...o}),o.parentId&&g.setParent(o.id,o.parentId)}),l.debug("Edges:",s.edges),s.edges.forEach(o=>{if(o.start===o.end){const r=o.start,f=r+"---"+r+"---1",h=r+"---"+r+"---2",a=g.node(r);g.setNode(f,{domId:f,id:f,parentId:a.parentId,labelStyle:"",label:"",padding:0,shape:"labelRect",style:"",width:10,height:10}),g.setParent(f,a.parentId),g.setNode(h,{domId:h,id:h,parentId:a.parentId,labelStyle:"",padding:0,shape:"labelRect",label:"",style:"",width:10,height:10}),g.setParent(h,a.parentId);const i=structuredClone(o),n=structuredClone(o),p=structuredClone(o),y=structuredClone(o);n.originalEdge=i,n.selfLoop={id:i.id,order:0},p.originalEdge=i,p.selfLoop={id:i.id,order:1},y.originalEdge=i,y.selfLoop={id:i.id,order:2},n.label="",n.arrowTypeEnd="none",n.endLabelLeft="",n.endLabelRight="",n.startLabelLeft="",n.id=r+"-cyclic-special-1",p.startLabelRight="",p.startLabelLeft="",p.endLabelLeft="",p.endLabelRight="",p.arrowTypeStart="none",p.arrowTypeEnd="none",p.id=r+"-cyclic-special-mid",y.label="",y.startLabelRight="",y.startLabelLeft="",y.arrowTypeStart="none",a.isGroup&&(n.fromCluster=r,y.toCluster=r),y.id=r+"-cyclic-special-2",y.arrowTypeStart="none",g.setEdge(r,f,n,r+"-cyclic-special-0"),g.setEdge(f,h,p,r+"-cyclic-special-1"),g.setEdge(h,r,y,r+"-cyclic-special-2")}else g.setEdge(o.start,o.end,{...o},o.id)}),l.warn("Graph at first:",JSON.stringify(I(g))),J(g),l.warn("Graph after XAX:",JSON.stringify(I(g)));const c=_();await T(m,g,s.type,s.diagramId,void 0,c)},"render");export{ne as getEdgesToRender,le as render};
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
||||||
import{p as B}from"./chunk-JWPE2WC7-C7S97jLg.js";import{_ as b,A as u,D as $,e as C,l as m,b as S,a as D,n as T,o as P,g as z,s as A,y as E,B as F,p as W}from"./mermaid.core-CqiFQExc.js";import{p as _}from"./cynefin-VYW2F7L2-DEnbetzx.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var N=F.packet,w=class{constructor(){this.packet=[],this.setAccTitle=S,this.getAccTitle=D,this.setDiagramTitle=T,this.getDiagramTitle=P,this.getAccDescription=z,this.setAccDescription=A}static{b(this,"PacketDB")}getConfig(){const t=u({...N,...E().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){W(),this.packet=[]}},L=1e4,M=b((t,e)=>{B(t,e);let r=-1,o=[],n=1;const{bitsPerRow:l}=e.getConfig();for(let{start:a,end:i,bits:d,label:c}of t.blocks){if(a!==void 0&&i!==void 0&&i<a)throw new Error(`Packet block ${a} - ${i} is invalid. End must be greater than start.`);if(a??=r+1,a!==r+1)throw new Error(`Packet block ${a} - ${i??a} is not contiguous. It should start from ${r+1}.`);if(d===0)throw new Error(`Packet block ${a} is invalid. Cannot have a zero bit field.`);for(i??=a+(d??1)-1,d??=i-a+1,r=i,m.debug(`Packet block ${a} - ${r} with label ${c}`);o.length<=l+1&&e.getPacket().length<L;){const[p,s]=Y({start:a,end:i,bits:d,label:c},n,l);if(o.push(p),p.end+1===n*l&&(e.pushWord(o),o=[],n++),!s)break;({start:a,end:i,bits:d,label:c}=s)}}e.pushWord(o)},"populate"),Y=b((t,e,r)=>{if(t.start===void 0)throw new Error("start should have been set during first phase");if(t.end===void 0)throw new Error("end should have been set during first phase");if(t.start>t.end)throw new Error(`Block start ${t.start} is greater than block end ${t.end}.`);if(t.end+1<=e*r)return[t,void 0];const o=e*r-1,n=e*r;return[{start:t.start,end:o,label:t.label,bits:o-t.start},{start:n,end:t.end,label:t.label,bits:t.end-n}]},"getNextFittingBlock"),v={parser:{yy:void 0},parse:b(async t=>{const e=await _("packet",t),r=v.parser?.yy;if(!(r instanceof w))throw new Error("parser.parser?.yy was not a PacketDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");m.debug(e),M(e,r)},"parse")},I=b((t,e,r,o)=>{const n=o.db,l=n.getConfig(),{rowHeight:a,paddingY:i,bitWidth:d,bitsPerRow:c}=l,p=n.getPacket(),s=n.getDiagramTitle(),h=a+i,g=h*(p.length+1)-(s?0:a),k=d*c+2,f=$(e);f.attr("viewBox",`0 0 ${k} ${g}`),C(f,g,k,l.useMaxWidth);for(const[x,y]of p.entries())O(f,y,x,l);f.append("text").text(s).attr("x",k/2).attr("y",g-h/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),O=b((t,e,r,{rowHeight:o,paddingX:n,paddingY:l,bitWidth:a,bitsPerRow:i,showBits:d})=>{const c=t.append("g"),p=r*(o+l)+l;for(const s of e){const h=s.start%i*a+1,g=(s.end-s.start+1)*a-n;if(c.append("rect").attr("x",h).attr("y",p).attr("width",g).attr("height",o).attr("class","packetBlock"),c.append("text").attr("x",h+g/2).attr("y",p+o/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(s.label),!d)continue;const k=s.end===s.start,f=p-2;c.append("text").attr("x",h+(k?g/2:0)).attr("y",f).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",k?"middle":"start").text(s.start),k||c.append("text").attr("x",h+g).attr("y",f).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(s.end)}},"drawWord"),j={draw:I},G={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},H=b(({packet:t}={})=>{const e=u(G,t);return`
|
import{p as B}from"./chunk-JWPE2WC7-DYhWNXPR.js";import{_ as b,B as u,F as $,e as C,l as m,b as S,a as D,o as T,p as z,g as F,s as P,z as E,D as A,q as W}from"./mermaid.core-cXaFT3ek.js";import{p as _}from"./cynefin-VYW2F7L2-BRNWksTk.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var N=A.packet,w=class{constructor(){this.packet=[],this.setAccTitle=S,this.getAccTitle=D,this.setDiagramTitle=T,this.getDiagramTitle=z,this.getAccDescription=F,this.setAccDescription=P}static{b(this,"PacketDB")}getConfig(){const t=u({...N,...E().packet});return t.showBits&&(t.paddingY+=10),t}getPacket(){return this.packet}pushWord(t){t.length>0&&this.packet.push(t)}clear(){W(),this.packet=[]}},L=1e4,M=b((t,e)=>{B(t,e);let r=-1,o=[],n=1;const{bitsPerRow:l}=e.getConfig();for(let{start:a,end:i,bits:d,label:c}of t.blocks){if(a!==void 0&&i!==void 0&&i<a)throw new Error(`Packet block ${a} - ${i} is invalid. End must be greater than start.`);if(a??=r+1,a!==r+1)throw new Error(`Packet block ${a} - ${i??a} is not contiguous. It should start from ${r+1}.`);if(d===0)throw new Error(`Packet block ${a} is invalid. Cannot have a zero bit field.`);for(i??=a+(d??1)-1,d??=i-a+1,r=i,m.debug(`Packet block ${a} - ${r} with label ${c}`);o.length<=l+1&&e.getPacket().length<L;){const[p,s]=Y({start:a,end:i,bits:d,label:c},n,l);if(o.push(p),p.end+1===n*l&&(e.pushWord(o),o=[],n++),!s)break;({start:a,end:i,bits:d,label:c}=s)}}e.pushWord(o)},"populate"),Y=b((t,e,r)=>{if(t.start===void 0)throw new Error("start should have been set during first phase");if(t.end===void 0)throw new Error("end should have been set during first phase");if(t.start>t.end)throw new Error(`Block start ${t.start} is greater than block end ${t.end}.`);if(t.end+1<=e*r)return[t,void 0];const o=e*r-1,n=e*r;return[{start:t.start,end:o,label:t.label,bits:o-t.start},{start:n,end:t.end,label:t.label,bits:t.end-n}]},"getNextFittingBlock"),v={parser:{yy:void 0},parse:b(async t=>{const e=await _("packet",t),r=v.parser?.yy;if(!(r instanceof w))throw new Error("parser.parser?.yy was not a PacketDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");m.debug(e),M(e,r)},"parse")},I=b((t,e,r,o)=>{const n=o.db,l=n.getConfig(),{rowHeight:a,paddingY:i,bitWidth:d,bitsPerRow:c}=l,p=n.getPacket(),s=n.getDiagramTitle(),h=a+i,g=h*(p.length+1)-(s?0:a),k=d*c+2,f=$(e);f.attr("viewBox",`0 0 ${k} ${g}`),C(f,g,k,l.useMaxWidth);for(const[x,y]of p.entries())O(f,y,x,l);f.append("text").text(s).attr("x",k/2).attr("y",g-h/2).attr("dominant-baseline","middle").attr("text-anchor","middle").attr("class","packetTitle")},"draw"),O=b((t,e,r,{rowHeight:o,paddingX:n,paddingY:l,bitWidth:a,bitsPerRow:i,showBits:d})=>{const c=t.append("g"),p=r*(o+l)+l;for(const s of e){const h=s.start%i*a+1,g=(s.end-s.start+1)*a-n;if(c.append("rect").attr("x",h).attr("y",p).attr("width",g).attr("height",o).attr("class","packetBlock"),c.append("text").attr("x",h+g/2).attr("y",p+o/2).attr("class","packetLabel").attr("dominant-baseline","middle").attr("text-anchor","middle").text(s.label),!d)continue;const k=s.end===s.start,f=p-2;c.append("text").attr("x",h+(k?g/2:0)).attr("y",f).attr("class","packetByte start").attr("dominant-baseline","auto").attr("text-anchor",k?"middle":"start").text(s.start),k||c.append("text").attr("x",h+g).attr("y",f).attr("class","packetByte end").attr("dominant-baseline","auto").attr("text-anchor","end").text(s.end)}},"drawWord"),j={draw:I},q={byteFontSize:"10px",startByteColor:"black",endByteColor:"black",labelColor:"black",labelFontSize:"12px",titleColor:"black",titleFontSize:"14px",blockStrokeColor:"black",blockStrokeWidth:"1",blockFillColor:"#efefef"},G=b(({packet:t}={})=>{const e=u(q,t);return`
|
||||||
.packetByte {
|
.packetByte {
|
||||||
font-size: ${e.byteFontSize};
|
font-size: ${e.byteFontSize};
|
||||||
}
|
}
|
||||||
|
|
@ -21,4 +21,4 @@ import{p as B}from"./chunk-JWPE2WC7-C7S97jLg.js";import{_ as b,A as u,D as $,e a
|
||||||
stroke-width: ${e.blockStrokeWidth};
|
stroke-width: ${e.blockStrokeWidth};
|
||||||
fill: ${e.blockFillColor};
|
fill: ${e.blockFillColor};
|
||||||
}
|
}
|
||||||
`},"styles"),J={parser:v,get db(){return new w},renderer:j,styles:H};export{J as diagram};
|
`},"styles"),J={parser:v,get db(){return new w},renderer:j,styles:G};export{J as diagram};
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import{I as X}from"./chunk-2Q5K7J3B-CdhiweKX.js";import{p as O}from"./chunk-JWPE2WC7-C7S97jLg.js";import{n as G,b as Y,s as P,o as j,g as F,a as Z,_ as f,A,l as D,D as q,e as U,y as N,p as J,i as K,ai as Q,B as ee,aj as te}from"./mermaid.core-CqiFQExc.js";import{p as ne}from"./cynefin-VYW2F7L2-DEnbetzx.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var E=/[─━│┃└┗├┣]/,S=/[└┗├┣]/,re=/[─━]/,V=/^[\s│┃]+$/,$=/^\s*(title[\t ]|accTitle[\t ]*:|accDescr[\t ]*[:{])/,k=/^\s*%%/,ie=" ";function L(n){return n.some(e=>E.test(e))}f(L,"isBoxDrawingFormat");function _(n){for(const e of n){const t=S.exec(e);if(t?.index&&t.index>0)return t.index}return 4}f(_,"inferSegmentWidth");function M(n,e){return n.replace(/\bline\s+(\d+)\b/gi,(t,r)=>{const i=parseInt(r,10),a=e.get(i);return a?`line ${a}`:t})}f(M,"remapErrorLines");function R(n){const e=n.split(`
|
import{I as X}from"./chunk-2Q5K7J3B-BGw8VEOT.js";import{p as O}from"./chunk-JWPE2WC7-DYhWNXPR.js";import{o as G,b as Y,s as F,p as P,g as j,a as q,_ as f,B as A,l as D,F as Z,e as U,z as N,q as J,i as K,ai as Q,D as ee,aj as te}from"./mermaid.core-cXaFT3ek.js";import{p as ne}from"./cynefin-VYW2F7L2-BRNWksTk.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var E=/[─━│┃└┗├┣]/,S=/[└┗├┣]/,re=/[─━]/,V=/^[\s│┃]+$/,$=/^\s*(title[\t ]|accTitle[\t ]*:|accDescr[\t ]*[:{])/,k=/^\s*%%/,ie=" ";function L(n){return n.some(e=>E.test(e))}f(L,"isBoxDrawingFormat");function _(n){for(const e of n){const t=S.exec(e);if(t?.index&&t.index>0)return t.index}return 4}f(_,"inferSegmentWidth");function M(n,e){return n.replace(/\bline\s+(\d+)\b/gi,(t,r)=>{const i=parseInt(r,10),a=e.get(i);return a?`line ${a}`:t})}f(M,"remapErrorLines");function R(n){const e=n.split(`
|
||||||
`),t=new Map;let r=-1;for(const[s,o]of e.entries())if(o.trim()==="treeView-beta"){r=s;break}if(r===-1)return{text:n,lineMap:t};const i=[];for(let s=r+1;s<e.length;s++){const o=e[s];o.trim()===""||k.test(o)||$.test(o)||V.test(o)||i.push(o.replace(/\t/g," "))}if(!L(i))return{text:n,lineMap:t};const a=_(i),c=[];let l=0;for(let s=0;s<=r;s++)c.push(e[s]),l++,t.set(l,s+1);for(let s=r+1;s<e.length;s++){const o=e[s],h=o.trim(),p=s+1;if(h===""){c.push(o),l++,t.set(l,p);continue}if(k.test(o)){c.push(o),l++,t.set(l,p);continue}if($.test(o)){c.push(o),l++,t.set(l,p);continue}if(V.test(o))continue;const d=o.replace(/\t/g," "),w=S.exec(d);if(w?.index!==void 0){const g=w.index,m=Math.round(g/a)+1;let u=g+1;for(;u<d.length&&re.test(d[u]);)u++;for(;u<d.length&&d[u]===" ";)u++;const v=d.slice(u).trimEnd();if(!v)throw new Error(`Line ${p}: Empty node — expected a filename or directory name after the box-drawing prefix`);const W=ie.repeat(m);c.push(W+v),l++,t.set(l,p)}else{if(/^[\s─━│┃└┗├┣]+$/.test(d))continue;if(E.test(d))c.push(o),l++,t.set(l,p);else{if(/^\s+/.test(d))throw new Error(`Line ${p}: Unexpected indentation without box-drawing characters. In box-drawing format, use ├── or └── prefixes for indented nodes.`);c.push(o),l++,t.set(l,p)}}}return{text:c.join(`
|
`),t=new Map;let r=-1;for(const[s,o]of e.entries())if(o.trim()==="treeView-beta"){r=s;break}if(r===-1)return{text:n,lineMap:t};const i=[];for(let s=r+1;s<e.length;s++){const o=e[s];o.trim()===""||k.test(o)||$.test(o)||V.test(o)||i.push(o.replace(/\t/g," "))}if(!L(i))return{text:n,lineMap:t};const a=_(i),c=[];let l=0;for(let s=0;s<=r;s++)c.push(e[s]),l++,t.set(l,s+1);for(let s=r+1;s<e.length;s++){const o=e[s],h=o.trim(),p=s+1;if(h===""){c.push(o),l++,t.set(l,p);continue}if(k.test(o)){c.push(o),l++,t.set(l,p);continue}if($.test(o)){c.push(o),l++,t.set(l,p);continue}if(V.test(o))continue;const d=o.replace(/\t/g," "),w=S.exec(d);if(w?.index!==void 0){const g=w.index,m=Math.round(g/a)+1;let u=g+1;for(;u<d.length&&re.test(d[u]);)u++;for(;u<d.length&&d[u]===" ";)u++;const v=d.slice(u).trimEnd();if(!v)throw new Error(`Line ${p}: Empty node — expected a filename or directory name after the box-drawing prefix`);const W=ie.repeat(m);c.push(W+v),l++,t.set(l,p)}else{if(/^[\s─━│┃└┗├┣]+$/.test(d))continue;if(E.test(d))c.push(o),l++,t.set(l,p);else{if(/^\s+/.test(d))throw new Error(`Line ${p}: Unexpected indentation without box-drawing characters. In box-drawing format, use ├── or └── prefixes for indented nodes.`);c.push(o),l++,t.set(l,p)}}}return{text:c.join(`
|
||||||
`),lineMap:t}}f(R,"preprocessBoxDrawing");var x=new X(()=>({cnt:1,stack:[{id:0,level:-1,name:"/",nodeType:"directory",children:[]}]})),oe=f(()=>{x.reset(),J()},"clear"),se=f(()=>x.records.stack[0],"getRoot"),ae=f(()=>x.records.cnt,"getCount"),ce=ee.treeView,le=f(()=>A(ce,N().treeView),"getConfig"),de=f((n,e,t,r,i,a)=>{for(;n<=x.records.stack[x.records.stack.length-1].level;)x.records.stack.pop();const c={id:x.records.cnt++,level:n,name:e,nodeType:t,icon:i,cssClass:r,description:a,children:[]};x.records.stack[x.records.stack.length-1].children.push(c),x.records.stack.push(c)},"addNode"),he={clear:oe,addNode:de,getRoot:se,getCount:ae,getConfig:le,getAccTitle:Z,getAccDescription:F,getDiagramTitle:j,setAccDescription:P,setAccTitle:Y,setDiagramTitle:G},I=he,pe=f(n=>{O(n,I);for(const e of n.nodes){const t=typeof e.indent=="number"?e.indent:0;let r=e.name;const i=r.endsWith("/");i&&(r=r.slice(0,-1));const a=i?"directory":"file",c=e.classAnnotation||void 0,l=e.iconAnnotation,s=l!==void 0?l||"none":void 0,o=e.descAnnotation||void 0,h=o?K(o,N()):void 0;I.addNode(t,r,a,c,s,h)}},"populate"),fe={parse:f(async n=>{const{text:e,lineMap:t}=R(n);try{const r=await ne("treeView",e);D.debug(r),pe(r)}catch(r){throw t.size>0&&r instanceof Error&&(r.message=M(r.message,t)),r}},"parse")},b={prefix:"mermaid-treeview",height:24,width:24,icons:{folder:{body:'<path fill="currentColor" d="M10.59 4.59A2 2 0 0 0 9.17 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.17z"/>'},file:{body:'<path fill="currentColor" fill-rule="evenodd" d="M6 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8.83a2 2 0 0 0-.59-1.42l-4.82-4.82A2 2 0 0 0 13.17 2H6Zm7.5 1.9l4.6 4.6h-3.6a1 1 0 0 1-1-1V3.9Z" clip-rule="evenodd"/>'}}};function H(n,e){const t=e?.filenameIcons?.[n];if(t)return t;const r=n.lastIndexOf(".");if(r>0){const i=n.substring(r).toLowerCase(),a=e?.extensionIcons;return a?.[i]??a?.[i.slice(1)]}}f(H,"detectIcon");function C(n,e){return n.includes(":")?n:n in b.icons||!e?`${b.prefix}:${n}`:`${e}:${n}`}f(C,"qualifyIcon");function B(n,e){if(n.icon!=="none"){if(n.icon)return C(n.icon,e.defaultIconPack);if(e.showIcons){if(n.nodeType==="file"){const t=H(n.name,e);if(t==="none")return;if(t)return C(t,e.defaultIconPack)}return`${b.prefix}:${n.nodeType==="directory"?"folder":"file"}`}}}f(B,"getNodeIcon");te([{name:b.prefix,icons:b}]);var y=14,ge=4,ue=16,z=f((n,e)=>`tv-icon-${n}-${e.replace(/[^\w-]/g,"-")}`,"iconSymbolId"),we=f(async(n,e,t,r)=>{const i=new Set,a=f(s=>{const o=B(s,t);o&&i.add(o),s.children.forEach(a)},"collect");if(a(e),i.size===0)return;const c=await Promise.all([...i].map(async s=>({icon:s,svg:await Q(s,{height:y,width:y})}))),l=n.append("defs");for(const{icon:s,svg:o}of c)l.append("g").attr("id",z(r,s)).html(o)},"injectIconDefs"),me=f((n,e,t,r,i,a)=>{const c=r.append("g");let l="treeView-node-label";t.nodeType==="directory"&&(l+=" treeView-node-dir"),t.cssClass&&(l+=` ${t.cssClass}`);const s=y+ge,o=B(t,i),h=o!==void 0;o&&c.append("use").attr("xlink:href",`#${z(a,o)}`).attr("x",n+i.paddingX).attr("y",e+i.paddingY).attr("class","treeView-node-icon");const p=c.append("text").text(t.name).attr("dominant-baseline","middle").attr("class",l),{height:d,width:w}=p.node().getBBox(),g=d+i.paddingY*2,m=n+i.paddingX+(h?s:0);p.attr("x",m),p.attr("y",e+g/2);const u=m+w,v=w+i.paddingX*2+(h?s:0);return t.BBox={x:n,y:e,width:v,height:g},t.cssClass?.split(/\s+/).includes("highlight")&&c.insert("rect",":first-child").attr("x",n).attr("y",e+1).attr("width",0).attr("height",g-2).attr("rx",3).attr("class","treeView-highlight-bg"),{node:t,nodeGroup:c,labelRightEdge:u,centerY:e+g/2}},"positionLabel"),T=f((n,e,t,r,i,a)=>n.append("line").attr("x1",e).attr("y1",t).attr("x2",r).attr("y2",i).attr("stroke-width",a).attr("class","treeView-node-line"),"positionLine"),xe=f((n,e,t,r)=>{let i=0,a=0;const c=[],l=f((h,p,d,w)=>{const g=w*(d.rowIndent+d.paddingX),m=me(g,i,p,h,d,r);c.push(m);const{height:u,width:v}=p.BBox;T(h,g-d.rowIndent,i+u/2,g,i+u/2,d.lineThickness),a=Math.max(a,g+v),i+=u},"drawNode"),s=f((h,p=0)=>{l(n,h,t,p),h.children.forEach(m=>{s(m,p+1)});const{x:d,y:w,height:g}=h.BBox;if(h.children.length){const{y:m,height:u}=h.children[h.children.length-1].BBox;T(n,d+t.paddingX,w+g,d+t.paddingX,m+u/2+t.lineThickness/2,t.lineThickness)}},"processNode");s(e);const o=c.filter(h=>h.node.description);if(o.length>0){const p=Math.max(...c.map(d=>d.labelRightEdge))+ue;for(const d of o){const g=d.nodeGroup.append("text").text(d.node.description).attr("dominant-baseline","middle").attr("class","treeView-node-description").attr("x",p).attr("y",d.centerY).node().getBBox();a=Math.max(a,p+g.width+t.paddingX)}}for(const h of c)if(h.node.cssClass?.split(/\s+/).includes("highlight")){const p=h.nodeGroup.select(".treeView-highlight-bg");if(!p.empty()){const d=a-h.node.BBox.x+8;p.attr("width",d),a=Math.max(a,h.node.BBox.x+d+2)}}return{totalHeight:i,totalWidth:a}},"drawTree"),ve=f(async(n,e,t,r)=>{D.debug(`Rendering treeView diagram
|
`),lineMap:t}}f(R,"preprocessBoxDrawing");var x=new X(()=>({cnt:1,stack:[{id:0,level:-1,name:"/",nodeType:"directory",children:[]}]})),oe=f(()=>{x.reset(),J()},"clear"),se=f(()=>x.records.stack[0],"getRoot"),ae=f(()=>x.records.cnt,"getCount"),ce=ee.treeView,le=f(()=>A(ce,N().treeView),"getConfig"),de=f((n,e,t,r,i,a)=>{for(;n<=x.records.stack[x.records.stack.length-1].level;)x.records.stack.pop();const c={id:x.records.cnt++,level:n,name:e,nodeType:t,icon:i,cssClass:r,description:a,children:[]};x.records.stack[x.records.stack.length-1].children.push(c),x.records.stack.push(c)},"addNode"),he={clear:oe,addNode:de,getRoot:se,getCount:ae,getConfig:le,getAccTitle:q,getAccDescription:j,getDiagramTitle:P,setAccDescription:F,setAccTitle:Y,setDiagramTitle:G},I=he,pe=f(n=>{O(n,I);for(const e of n.nodes){const t=typeof e.indent=="number"?e.indent:0;let r=e.name;const i=r.endsWith("/");i&&(r=r.slice(0,-1));const a=i?"directory":"file",c=e.classAnnotation||void 0,l=e.iconAnnotation,s=l!==void 0?l||"none":void 0,o=e.descAnnotation||void 0,h=o?K(o,N()):void 0;I.addNode(t,r,a,c,s,h)}},"populate"),fe={parse:f(async n=>{const{text:e,lineMap:t}=R(n);try{const r=await ne("treeView",e);D.debug(r),pe(r)}catch(r){throw t.size>0&&r instanceof Error&&(r.message=M(r.message,t)),r}},"parse")},b={prefix:"mermaid-treeview",height:24,width:24,icons:{folder:{body:'<path fill="currentColor" d="M10.59 4.59A2 2 0 0 0 9.17 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.17z"/>'},file:{body:'<path fill="currentColor" fill-rule="evenodd" d="M6 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8.83a2 2 0 0 0-.59-1.42l-4.82-4.82A2 2 0 0 0 13.17 2H6Zm7.5 1.9l4.6 4.6h-3.6a1 1 0 0 1-1-1V3.9Z" clip-rule="evenodd"/>'}}};function z(n,e){const t=e?.filenameIcons?.[n];if(t)return t;const r=n.lastIndexOf(".");if(r>0){const i=n.substring(r).toLowerCase(),a=e?.extensionIcons;return a?.[i]??a?.[i.slice(1)]}}f(z,"detectIcon");function C(n,e){return n.includes(":")?n:n in b.icons||!e?`${b.prefix}:${n}`:`${e}:${n}`}f(C,"qualifyIcon");function B(n,e){if(n.icon!=="none"){if(n.icon)return C(n.icon,e.defaultIconPack);if(e.showIcons){if(n.nodeType==="file"){const t=z(n.name,e);if(t==="none")return;if(t)return C(t,e.defaultIconPack)}return`${b.prefix}:${n.nodeType==="directory"?"folder":"file"}`}}}f(B,"getNodeIcon");te([{name:b.prefix,icons:b}]);var y=14,ge=4,ue=16,H=f((n,e)=>`tv-icon-${n}-${e.replace(/[^\w-]/g,"-")}`,"iconSymbolId"),we=f(async(n,e,t,r)=>{const i=new Set,a=f(s=>{const o=B(s,t);o&&i.add(o),s.children.forEach(a)},"collect");if(a(e),i.size===0)return;const c=await Promise.all([...i].map(async s=>({icon:s,svg:await Q(s,{height:y,width:y})}))),l=n.append("defs");for(const{icon:s,svg:o}of c)l.append("g").attr("id",H(r,s)).html(o)},"injectIconDefs"),me=f((n,e,t,r,i,a)=>{const c=r.append("g");let l="treeView-node-label";t.nodeType==="directory"&&(l+=" treeView-node-dir"),t.cssClass&&(l+=` ${t.cssClass}`);const s=y+ge,o=B(t,i),h=o!==void 0;o&&c.append("use").attr("xlink:href",`#${H(a,o)}`).attr("x",n+i.paddingX).attr("y",e+i.paddingY).attr("class","treeView-node-icon");const p=c.append("text").text(t.name).attr("dominant-baseline","middle").attr("class",l),{height:d,width:w}=p.node().getBBox(),g=d+i.paddingY*2,m=n+i.paddingX+(h?s:0);p.attr("x",m),p.attr("y",e+g/2);const u=m+w,v=w+i.paddingX*2+(h?s:0);return t.BBox={x:n,y:e,width:v,height:g},t.cssClass?.split(/\s+/).includes("highlight")&&c.insert("rect",":first-child").attr("x",n).attr("y",e+1).attr("width",0).attr("height",g-2).attr("rx",3).attr("class","treeView-highlight-bg"),{node:t,nodeGroup:c,labelRightEdge:u,centerY:e+g/2}},"positionLabel"),T=f((n,e,t,r,i,a)=>n.append("line").attr("x1",e).attr("y1",t).attr("x2",r).attr("y2",i).attr("stroke-width",a).attr("class","treeView-node-line"),"positionLine"),xe=f((n,e,t,r)=>{let i=0,a=0;const c=[],l=f((h,p,d,w)=>{const g=w*(d.rowIndent+d.paddingX),m=me(g,i,p,h,d,r);c.push(m);const{height:u,width:v}=p.BBox;T(h,g-d.rowIndent,i+u/2,g,i+u/2,d.lineThickness),a=Math.max(a,g+v),i+=u},"drawNode"),s=f((h,p=0)=>{l(n,h,t,p),h.children.forEach(m=>{s(m,p+1)});const{x:d,y:w,height:g}=h.BBox;if(h.children.length){const{y:m,height:u}=h.children[h.children.length-1].BBox;T(n,d+t.paddingX,w+g,d+t.paddingX,m+u/2+t.lineThickness/2,t.lineThickness)}},"processNode");s(e);const o=c.filter(h=>h.node.description);if(o.length>0){const p=Math.max(...c.map(d=>d.labelRightEdge))+ue;for(const d of o){const g=d.nodeGroup.append("text").text(d.node.description).attr("dominant-baseline","middle").attr("class","treeView-node-description").attr("x",p).attr("y",d.centerY).node().getBBox();a=Math.max(a,p+g.width+t.paddingX)}}for(const h of c)if(h.node.cssClass?.split(/\s+/).includes("highlight")){const p=h.nodeGroup.select(".treeView-highlight-bg");if(!p.empty()){const d=a-h.node.BBox.x+8;p.attr("width",d),a=Math.max(a,h.node.BBox.x+d+2)}}return{totalHeight:i,totalWidth:a}},"drawTree"),ve=f(async(n,e,t,r)=>{D.debug(`Rendering treeView diagram
|
||||||
`+n);const i=r.db,a=i.getRoot(),c=i.getConfig(),l=q(e);await we(l,a,c,e);const s=l.append("g");s.attr("class","tree-view");const{totalHeight:o,totalWidth:h}=xe(s,a,c,e);l.attr("viewBox",`-${c.lineThickness/2} 0 ${h} ${o}`),U(l,o,h,c.useMaxWidth)},"draw"),be={draw:ve},Ie=be,Ce={labelFontSize:"16px",labelColor:"black",lineColor:"black",iconColor:"#546e7a",descriptionColor:"#6a9955",highlightBg:"rgba(255, 193, 7, 0.15)",highlightStroke:"#ffc107"},ye=f(({treeView:n})=>{const{labelFontSize:e,labelColor:t,lineColor:r,iconColor:i,descriptionColor:a,highlightBg:c,highlightStroke:l}=A(Ce,n);return`
|
`+n);const i=r.db,a=i.getRoot(),c=i.getConfig(),l=Z(e);await we(l,a,c,e);const s=l.append("g");s.attr("class","tree-view");const{totalHeight:o,totalWidth:h}=xe(s,a,c,e);l.attr("viewBox",`-${c.lineThickness/2} 0 ${h} ${o}`),U(l,o,h,c.useMaxWidth)},"draw"),be={draw:ve},Ie=be,Ce={labelFontSize:"16px",labelColor:"black",lineColor:"black",iconColor:"#546e7a",descriptionColor:"#6a9955",highlightBg:"rgba(255, 193, 7, 0.15)",highlightStroke:"#ffc107"},ye=f(({treeView:n})=>{const{labelFontSize:e,labelColor:t,lineColor:r,iconColor:i,descriptionColor:a,highlightBg:c,highlightStroke:l}=A(Ce,n);return`
|
||||||
.treeView-node-label {
|
.treeView-node-label {
|
||||||
font-size: ${e};
|
font-size: ${e};
|
||||||
fill: ${t};
|
fill: ${t};
|
||||||
41
apps/kimi-code/dist-web/assets/diagram-WEI45ONY-Br-kwRXz.js
Normal file
41
apps/kimi-code/dist-web/assets/diagram-WEI45ONY-Br-kwRXz.js
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
import{p as k}from"./chunk-JWPE2WC7-DYhWNXPR.js";import{s as R,g as F,p as I,o as _,a as D,b as E,_ as c,F as z,q as P,B as y,z as C,D as G,l as B,W,e as V}from"./mermaid.core-cXaFT3ek.js";import{p as H}from"./cynefin-VYW2F7L2-BRNWksTk.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var m={showLegend:!0,ticks:5,max:null,min:0,graticule:"circle"},w={axes:[],curves:[],options:m},x=structuredClone(w),j=G.radar,q=c(()=>y({...j,...C().radar}),"getConfig"),b=c(()=>x.axes,"getAxes"),N=c(()=>x.curves,"getCurves"),U=c(()=>x.options,"getOptions"),X=c(a=>{x.axes=a.map(t=>({name:t.name,label:t.label??t.name}))},"setAxes"),Y=c(a=>{x.curves=a.map(t=>({name:t.name,label:t.label??t.name,entries:Z(t.entries)}))},"setCurves"),Z=c(a=>{if(a[0].axis==null)return a.map(e=>e.value);const t=b();if(t.length===0)throw new Error("Axes must be populated before curves for reference entries");return t.map(e=>{const r=a.find(s=>s.axis?.$refText===e.name);if(r===void 0)throw new Error("Missing entry for axis "+e.label);return r.value})},"computeCurveEntries"),J=c(a=>{const t=a.reduce((e,r)=>(e[r.name]=r,e),{});x.options={showLegend:t.showLegend?.value??m.showLegend,ticks:t.ticks?.value??m.ticks,max:t.max?.value??m.max,min:t.min?.value??m.min,graticule:t.graticule?.value??m.graticule}},"setOptions"),K=c(()=>{P(),x=structuredClone(w)},"clear"),$={getAxes:b,getCurves:N,getOptions:U,setAxes:X,setCurves:Y,setOptions:J,getConfig:q,clear:K,setAccTitle:E,getAccTitle:D,setDiagramTitle:_,getDiagramTitle:I,getAccDescription:F,setAccDescription:R},Q=c(a=>{k(a,$);const{axes:t,curves:e,options:r}=a;$.setAxes(t),$.setCurves(e),$.setOptions(r)},"populate"),tt={parse:c(async a=>{const t=await H("radar",a);B.debug(t),Q(t)},"parse")},et=c((a,t,e,r)=>{const s=r.db,i=s.getAxes(),l=s.getCurves(),n=s.getOptions(),o=s.getConfig(),d=s.getDiagramTitle(),p=z(t),u=at(p,o),g=n.max??Math.max(...l.map(f=>Math.max(...f.entries))),h=n.min,v=Math.min(o.width,o.height)/2;rt(u,i,v,n.ticks,n.graticule),st(u,i,v,o),A(u,i,l,h,g,n.graticule,o),T(u,l,n.showLegend,o),u.append("text").attr("class","radarTitle").text(d).attr("x",0).attr("y",-o.height/2-o.marginTop)},"draw"),at=c((a,t)=>{const e=t.width+t.marginLeft+t.marginRight,r=t.height+t.marginTop+t.marginBottom,s={x:t.marginLeft+t.width/2,y:t.marginTop+t.height/2};return V(a,r,e,t.useMaxWidth??!0),a.attr("viewBox",`0 0 ${e} ${r}`).attr("overflow","visible"),a.append("g").attr("transform",`translate(${s.x}, ${s.y})`)},"drawFrame"),rt=c((a,t,e,r,s)=>{if(s==="circle")for(let i=0;i<r;i++){const l=e*(i+1)/r;a.append("circle").attr("r",l).attr("class","radarGraticule")}else if(s==="polygon"){const i=t.length;for(let l=0;l<r;l++){const n=e*(l+1)/r,o=t.map((d,p)=>{const u=2*p*Math.PI/i-Math.PI/2,g=n*Math.cos(u),h=n*Math.sin(u);return`${g},${h}`}).join(" ");a.append("polygon").attr("points",o).attr("class","radarGraticule")}}},"drawGraticule"),st=c((a,t,e,r)=>{const s=t.length;for(let i=0;i<s;i++){const l=t[i].label,n=2*i*Math.PI/s-Math.PI/2,o=Math.cos(n),d=Math.sin(n);a.append("line").attr("x1",0).attr("y1",0).attr("x2",e*r.axisScaleFactor*o).attr("y2",e*r.axisScaleFactor*d).attr("class","radarAxisLine");const p=o>.01?"start":o<-.01?"end":"middle",u=d>.01?"hanging":d<-.01?"auto":"central",g=4;a.append("text").text(l).attr("x",e*r.axisLabelFactor*o+g*o).attr("y",e*r.axisLabelFactor*d+g*d).attr("text-anchor",p).attr("dominant-baseline",u).attr("class","radarAxisLabel")}},"drawAxes");function A(a,t,e,r,s,i,l){const n=t.length,o=Math.min(l.width,l.height)/2;e.forEach((d,p)=>{if(d.entries.length!==n)return;const u=d.entries.map((g,h)=>{const v=2*Math.PI*h/n-Math.PI/2,f=M(g,r,s,o),S=f*Math.cos(v),O=f*Math.sin(v);return{x:S,y:O}});i==="circle"?a.append("path").attr("d",L(u,l.curveTension)).attr("class",`radarCurve-${p}`):i==="polygon"&&a.append("polygon").attr("points",u.map(g=>`${g.x},${g.y}`).join(" ")).attr("class",`radarCurve-${p}`)})}c(A,"drawCurves");function M(a,t,e,r){const s=Math.min(Math.max(a,t),e);return r*(s-t)/(e-t)}c(M,"relativeRadius");function L(a,t){const e=a.length;let r=`M${a[0].x},${a[0].y}`;for(let s=0;s<e;s++){const i=a[(s-1+e)%e],l=a[s],n=a[(s+1)%e],o=a[(s+2)%e],d={x:l.x+(n.x-i.x)*t,y:l.y+(n.y-i.y)*t},p={x:n.x-(o.x-l.x)*t,y:n.y-(o.y-l.y)*t};r+=` C${d.x},${d.y} ${p.x},${p.y} ${n.x},${n.y}`}return`${r} Z`}c(L,"closedRoundCurve");function T(a,t,e,r){if(!e)return;const s=(r.width/2+r.marginRight)*3/4,i=-(r.height/2+r.marginTop)*3/4,l=20;t.forEach((n,o)=>{const d=a.append("g").attr("transform",`translate(${s}, ${i+o*l})`);d.append("rect").attr("width",12).attr("height",12).attr("class",`radarLegendBox-${o}`),d.append("text").attr("x",16).attr("y",0).attr("class","radarLegendText").text(n.label)})}c(T,"drawLegend");var nt={draw:et},ot=c((a,t)=>{let e="";for(let r=0;r<a.THEME_COLOR_LIMIT;r++){const s=a[`cScale${r}`];e+=`
|
||||||
|
.radarCurve-${r} {
|
||||||
|
color: ${s};
|
||||||
|
fill: ${s};
|
||||||
|
fill-opacity: ${t.curveOpacity};
|
||||||
|
stroke: ${s};
|
||||||
|
stroke-width: ${t.curveStrokeWidth};
|
||||||
|
}
|
||||||
|
.radarLegendBox-${r} {
|
||||||
|
fill: ${s};
|
||||||
|
fill-opacity: ${t.curveOpacity};
|
||||||
|
stroke: ${s};
|
||||||
|
}
|
||||||
|
`}return e},"genIndexStyles"),it=c(a=>{const t=W(),e=C(),r=y(t,e.themeVariables),s=y(r.radar,a);return{themeVariables:r,radarOptions:s}},"buildRadarStyleOptions"),lt=c(({radar:a}={})=>{const{themeVariables:t,radarOptions:e}=it(a);return`
|
||||||
|
.radarTitle {
|
||||||
|
font-size: ${t.fontSize};
|
||||||
|
color: ${t.titleColor};
|
||||||
|
dominant-baseline: hanging;
|
||||||
|
text-anchor: middle;
|
||||||
|
}
|
||||||
|
.radarAxisLine {
|
||||||
|
stroke: ${e.axisColor};
|
||||||
|
stroke-width: ${e.axisStrokeWidth};
|
||||||
|
}
|
||||||
|
.radarAxisLabel {
|
||||||
|
font-size: ${e.axisLabelFontSize}px;
|
||||||
|
color: ${e.axisColor};
|
||||||
|
}
|
||||||
|
.radarGraticule {
|
||||||
|
fill: ${e.graticuleColor};
|
||||||
|
fill-opacity: ${e.graticuleOpacity};
|
||||||
|
stroke: ${e.graticuleColor};
|
||||||
|
stroke-width: ${e.graticuleStrokeWidth};
|
||||||
|
}
|
||||||
|
.radarLegendText {
|
||||||
|
text-anchor: start;
|
||||||
|
font-size: ${e.legendFontSize}px;
|
||||||
|
dominant-baseline: hanging;
|
||||||
|
}
|
||||||
|
${ot(t,e)}
|
||||||
|
`},"styles"),xt={parser:tt,db:$,renderer:nt,styles:lt};export{xt as diagram};
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
import{p as k}from"./chunk-JWPE2WC7-C7S97jLg.js";import{s as R,g as E,o as I,n as _,a as D,b as F,_ as c,D as P,p as z,A as y,y as C,B as G,l as B,E as W,e as V}from"./mermaid.core-CqiFQExc.js";import{p as H}from"./cynefin-VYW2F7L2-DEnbetzx.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var m={showLegend:!0,ticks:5,max:null,min:0,graticule:"circle"},w={axes:[],curves:[],options:m},x=structuredClone(w),j=G.radar,N=c(()=>y({...j,...C().radar}),"getConfig"),b=c(()=>x.axes,"getAxes"),U=c(()=>x.curves,"getCurves"),X=c(()=>x.options,"getOptions"),Y=c(a=>{x.axes=a.map(t=>({name:t.name,label:t.label??t.name}))},"setAxes"),Z=c(a=>{x.curves=a.map(t=>({name:t.name,label:t.label??t.name,entries:q(t.entries)}))},"setCurves"),q=c(a=>{if(a[0].axis==null)return a.map(e=>e.value);const t=b();if(t.length===0)throw new Error("Axes must be populated before curves for reference entries");return t.map(e=>{const r=a.find(s=>s.axis?.$refText===e.name);if(r===void 0)throw new Error("Missing entry for axis "+e.label);return r.value})},"computeCurveEntries"),J=c(a=>{const t=a.reduce((e,r)=>(e[r.name]=r,e),{});x.options={showLegend:t.showLegend?.value??m.showLegend,ticks:t.ticks?.value??m.ticks,max:t.max?.value??m.max,min:t.min?.value??m.min,graticule:t.graticule?.value??m.graticule}},"setOptions"),K=c(()=>{z(),x=structuredClone(w)},"clear"),$={getAxes:b,getCurves:U,getOptions:X,setAxes:Y,setCurves:Z,setOptions:J,getConfig:N,clear:K,setAccTitle:F,getAccTitle:D,setDiagramTitle:_,getDiagramTitle:I,getAccDescription:E,setAccDescription:R},Q=c(a=>{k(a,$);const{axes:t,curves:e,options:r}=a;$.setAxes(t),$.setCurves(e),$.setOptions(r)},"populate"),tt={parse:c(async a=>{const t=await H("radar",a);B.debug(t),Q(t)},"parse")},et=c((a,t,e,r)=>{const s=r.db,i=s.getAxes(),l=s.getCurves(),n=s.getOptions(),o=s.getConfig(),d=s.getDiagramTitle(),p=P(t),u=at(p,o),g=n.max??Math.max(...l.map(f=>Math.max(...f.entries))),h=n.min,v=Math.min(o.width,o.height)/2;rt(u,i,v,n.ticks,n.graticule),st(u,i,v,o),A(u,i,l,h,g,n.graticule,o),T(u,l,n.showLegend,o),u.append("text").attr("class","radarTitle").text(d).attr("x",0).attr("y",-o.height/2-o.marginTop)},"draw"),at=c((a,t)=>{const e=t.width+t.marginLeft+t.marginRight,r=t.height+t.marginTop+t.marginBottom,s={x:t.marginLeft+t.width/2,y:t.marginTop+t.height/2};return V(a,r,e,t.useMaxWidth??!0),a.attr("viewBox",`0 0 ${e} ${r}`).attr("overflow","visible"),a.append("g").attr("transform",`translate(${s.x}, ${s.y})`)},"drawFrame"),rt=c((a,t,e,r,s)=>{if(s==="circle")for(let i=0;i<r;i++){const l=e*(i+1)/r;a.append("circle").attr("r",l).attr("class","radarGraticule")}else if(s==="polygon"){const i=t.length;for(let l=0;l<r;l++){const n=e*(l+1)/r,o=t.map((d,p)=>{const u=2*p*Math.PI/i-Math.PI/2,g=n*Math.cos(u),h=n*Math.sin(u);return`${g},${h}`}).join(" ");a.append("polygon").attr("points",o).attr("class","radarGraticule")}}},"drawGraticule"),st=c((a,t,e,r)=>{const s=t.length;for(let i=0;i<s;i++){const l=t[i].label,n=2*i*Math.PI/s-Math.PI/2,o=Math.cos(n),d=Math.sin(n);a.append("line").attr("x1",0).attr("y1",0).attr("x2",e*r.axisScaleFactor*o).attr("y2",e*r.axisScaleFactor*d).attr("class","radarAxisLine");const p=o>.01?"start":o<-.01?"end":"middle",u=d>.01?"hanging":d<-.01?"auto":"central",g=4;a.append("text").text(l).attr("x",e*r.axisLabelFactor*o+g*o).attr("y",e*r.axisLabelFactor*d+g*d).attr("text-anchor",p).attr("dominant-baseline",u).attr("class","radarAxisLabel")}},"drawAxes");function A(a,t,e,r,s,i,l){const n=t.length,o=Math.min(l.width,l.height)/2;e.forEach((d,p)=>{if(d.entries.length!==n)return;const u=d.entries.map((g,h)=>{const v=2*Math.PI*h/n-Math.PI/2,f=M(g,r,s,o),S=f*Math.cos(v),O=f*Math.sin(v);return{x:S,y:O}});i==="circle"?a.append("path").attr("d",L(u,l.curveTension)).attr("class",`radarCurve-${p}`):i==="polygon"&&a.append("polygon").attr("points",u.map(g=>`${g.x},${g.y}`).join(" ")).attr("class",`radarCurve-${p}`)})}c(A,"drawCurves");function M(a,t,e,r){const s=Math.min(Math.max(a,t),e);return r*(s-t)/(e-t)}c(M,"relativeRadius");function L(a,t){const e=a.length;let r=`M${a[0].x},${a[0].y}`;for(let s=0;s<e;s++){const i=a[(s-1+e)%e],l=a[s],n=a[(s+1)%e],o=a[(s+2)%e],d={x:l.x+(n.x-i.x)*t,y:l.y+(n.y-i.y)*t},p={x:n.x-(o.x-l.x)*t,y:n.y-(o.y-l.y)*t};r+=` C${d.x},${d.y} ${p.x},${p.y} ${n.x},${n.y}`}return`${r} Z`}c(L,"closedRoundCurve");function T(a,t,e,r){if(!e)return;const s=(r.width/2+r.marginRight)*3/4,i=-(r.height/2+r.marginTop)*3/4,l=20;t.forEach((n,o)=>{const d=a.append("g").attr("transform",`translate(${s}, ${i+o*l})`);d.append("rect").attr("width",12).attr("height",12).attr("class",`radarLegendBox-${o}`),d.append("text").attr("x",16).attr("y",0).attr("class","radarLegendText").text(n.label)})}c(T,"drawLegend");var nt={draw:et},ot=c((a,t)=>{let e="";for(let r=0;r<a.THEME_COLOR_LIMIT;r++){const s=a[`cScale${r}`];e+=`
|
|
||||||
.radarCurve-${r} {
|
|
||||||
color: ${s};
|
|
||||||
fill: ${s};
|
|
||||||
fill-opacity: ${t.curveOpacity};
|
|
||||||
stroke: ${s};
|
|
||||||
stroke-width: ${t.curveStrokeWidth};
|
|
||||||
}
|
|
||||||
.radarLegendBox-${r} {
|
|
||||||
fill: ${s};
|
|
||||||
fill-opacity: ${t.curveOpacity};
|
|
||||||
stroke: ${s};
|
|
||||||
}
|
|
||||||
`}return e},"genIndexStyles"),it=c(a=>{const t=W(),e=C(),r=y(t,e.themeVariables),s=y(r.radar,a);return{themeVariables:r,radarOptions:s}},"buildRadarStyleOptions"),lt=c(({radar:a}={})=>{const{themeVariables:t,radarOptions:e}=it(a);return`
|
|
||||||
.radarTitle {
|
|
||||||
font-size: ${t.fontSize};
|
|
||||||
color: ${t.titleColor};
|
|
||||||
dominant-baseline: hanging;
|
|
||||||
text-anchor: middle;
|
|
||||||
}
|
|
||||||
.radarAxisLine {
|
|
||||||
stroke: ${e.axisColor};
|
|
||||||
stroke-width: ${e.axisStrokeWidth};
|
|
||||||
}
|
|
||||||
.radarAxisLabel {
|
|
||||||
font-size: ${e.axisLabelFontSize}px;
|
|
||||||
color: ${e.axisColor};
|
|
||||||
}
|
|
||||||
.radarGraticule {
|
|
||||||
fill: ${e.graticuleColor};
|
|
||||||
fill-opacity: ${e.graticuleOpacity};
|
|
||||||
stroke: ${e.graticuleColor};
|
|
||||||
stroke-width: ${e.graticuleStrokeWidth};
|
|
||||||
}
|
|
||||||
.radarLegendText {
|
|
||||||
text-anchor: start;
|
|
||||||
font-size: ${e.legendFontSize}px;
|
|
||||||
dominant-baseline: hanging;
|
|
||||||
}
|
|
||||||
${ot(t,e)}
|
|
||||||
`},"styles"),xt={parser:tt,db:$,renderer:nt,styles:lt};export{xt as diagram};
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
import{g as l,r as m,d as n}from"./chunk-MOJQB5TN-DcgqWRh_.js";import{p}from"./chunk-JWPE2WC7-C7S97jLg.js";import{_ as t,l as o}from"./mermaid.core-CqiFQExc.js";import{M as u,a as f}from"./cynefin-VYW2F7L2-DEnbetzx.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var c=f().RailroadEbnf.parser.LangiumParser,s=t(e=>{const r=e.alternatives.map(E);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformChoice"),E=t(e=>{const r=e.elements.map(d);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformSequence"),i=t(e=>{switch(e.$type){case"EbnfTerminal":return{type:"terminal",value:e.value};case"EbnfNonTerminal":return{type:"nonterminal",name:e.name};case"EbnfSpecial":return{type:"special",text:e.text};case"EbnfGroup":return s(e.element);case"EbnfOptional":return{type:"optional",element:s(e.element)};case"EbnfRepetition":return{type:"repetition",element:s(e.element),min:0,max:1/0};default:throw new Error(`Unsupported EBNF primary node: ${e.$type}`)}},"transformPrimary"),b=t((e,r)=>{switch(r.$type){case"EbnfOptionalPostfix":return{type:"optional",element:e};case"EbnfZeroOrMorePostfix":return{type:"repetition",element:e,min:0,max:1/0};case"EbnfOneOrMorePostfix":return{type:"repetition",element:e,min:1,max:1/0};case"EbnfExceptionPostfix":return{type:"sequence",elements:[e,{type:"terminal",value:"-"},i(r.except)]};default:throw new Error(`Unsupported EBNF postfix node: ${r.$type}`)}},"transformPostfix"),d=t(e=>e.postfixes.reduce((r,a)=>b(r,a),i(e.base)),"transformTerm"),y=t(e=>({name:e.name,definition:s(e.definition)}),"transformRule"),v=t(e=>{p(e,n),e.title&&n.setTitle(e.title),e.rules.map(r=>n.addRule(y(r)))},"populateDb"),g={parse:t(e=>{n.clear(),o.debug("[EBNF Parser] Starting Langium parse");const r=c.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new u(r);const a=r.value;o.debug("[EBNF Parser] Parsed rules:",a.rules.length),v(a),o.debug("[EBNF Parser] Parse complete")},"parse"),parser:{yy:n}},S={parser:g,db:n,renderer:m,styles:l};export{S as diagram};
|
import{g as l,r as m,d as n}from"./chunk-MOJQB5TN-CC2YIE_t.js";import{p}from"./chunk-JWPE2WC7-DYhWNXPR.js";import{_ as t,l as o}from"./mermaid.core-cXaFT3ek.js";import{M as u,a as f}from"./cynefin-VYW2F7L2-BRNWksTk.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var c=f().RailroadEbnf.parser.LangiumParser,s=t(e=>{const r=e.alternatives.map(E);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformChoice"),E=t(e=>{const r=e.elements.map(d);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformSequence"),i=t(e=>{switch(e.$type){case"EbnfTerminal":return{type:"terminal",value:e.value};case"EbnfNonTerminal":return{type:"nonterminal",name:e.name};case"EbnfSpecial":return{type:"special",text:e.text};case"EbnfGroup":return s(e.element);case"EbnfOptional":return{type:"optional",element:s(e.element)};case"EbnfRepetition":return{type:"repetition",element:s(e.element),min:0,max:1/0};default:throw new Error(`Unsupported EBNF primary node: ${e.$type}`)}},"transformPrimary"),b=t((e,r)=>{switch(r.$type){case"EbnfOptionalPostfix":return{type:"optional",element:e};case"EbnfZeroOrMorePostfix":return{type:"repetition",element:e,min:0,max:1/0};case"EbnfOneOrMorePostfix":return{type:"repetition",element:e,min:1,max:1/0};case"EbnfExceptionPostfix":return{type:"sequence",elements:[e,{type:"terminal",value:"-"},i(r.except)]};default:throw new Error(`Unsupported EBNF postfix node: ${r.$type}`)}},"transformPostfix"),d=t(e=>e.postfixes.reduce((r,a)=>b(r,a),i(e.base)),"transformTerm"),y=t(e=>({name:e.name,definition:s(e.definition)}),"transformRule"),v=t(e=>{p(e,n),e.title&&n.setTitle(e.title),e.rules.map(r=>n.addRule(y(r)))},"populateDb"),g={parse:t(e=>{n.clear(),o.debug("[EBNF Parser] Starting Langium parse");const r=c.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new u(r);const a=r.value;o.debug("[EBNF Parser] Parsed rules:",a.rules.length),v(a),o.debug("[EBNF Parser] Parse complete")},"parse"),parser:{yy:n}},S={parser:g,db:n,renderer:m,styles:l};export{S as diagram};
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
669
apps/kimi-code/dist-web/assets/index-BdL5hCoZ.js
Normal file
669
apps/kimi-code/dist-web/assets/index-BdL5hCoZ.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
apps/kimi-code/dist-web/assets/index-CiiPSBw1.css
Normal file
1
apps/kimi-code/dist-web/assets/index-CiiPSBw1.css
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
import c from"./CodeBlockNode-BNOCy4ai.js";import{M as v,bl as g,aL as P,s as C,A as b,bJ as i,aY as d,av as k,a4 as x,ar as S,bk as T,q as O}from"./index--0t1wzw_.js";import"./safeRaf-DGuzXxDK.js";var H=Object.defineProperty,z=Object.defineProperties,j=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,m=(o,s,e)=>s in o?H(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;const h=v({__name:"MarkdownCodeBlockNode",props:{node:{},loading:{type:Boolean,default:!0},stream:{type:Boolean,default:!0},darkTheme:{default:"vitesse-dark"},lightTheme:{default:"vitesse-light"},isDark:{type:Boolean,default:!1},isShowPreview:{type:Boolean,default:!0},enableFontSizeControl:{type:Boolean,default:!0},minWidth:{default:void 0},maxWidth:{default:void 0},showPreviewButton:{type:Boolean,default:!0},showCollapseButton:{type:Boolean,default:!0},showFontSizeButtons:{type:Boolean,default:!0},showTooltips:{type:Boolean},autoScrollOnUpdate:{type:Boolean},autoScrollInitial:{type:Boolean},estimatedHeightPx:{},estimatedContentHeightPx:{},themes:{},langs:{},showHeader:{type:Boolean,default:!0},showCopyButton:{type:Boolean,default:!0},showExpandButton:{type:Boolean,default:!0}},emits:["previewCode","copy"],setup(o,{emit:s}){const e=o,p=s,w=c,f=g(),y=O(()=>{return t=((a,n)=>{for(var r in n||(n={}))F.call(n,r)&&m(a,r,n[r]);if(u)for(var r of u(n))W.call(n,r)&&m(a,r,n[r]);return a})({},f),l={node:e.node,loading:e.loading,stream:e.stream,darkTheme:e.darkTheme,lightTheme:e.lightTheme,isDark:e.isDark,isShowPreview:e.isShowPreview,enableFontSizeControl:e.enableFontSizeControl,minWidth:e.minWidth,maxWidth:e.maxWidth,themes:e.themes,showHeader:e.showHeader,showCopyButton:e.showCopyButton,showExpandButton:e.showExpandButton,showPreviewButton:e.showPreviewButton,showCollapseButton:e.showCollapseButton,showFontSizeButtons:e.showFontSizeButtons,showTooltips:e.showTooltips,estimatedHeightPx:e.estimatedHeightPx,estimatedContentHeightPx:e.estimatedContentHeightPx},z(t,j(l));var t,l});function B(t){p("previewCode",{type:t.artifactType,content:e.node.code,title:t.artifactTitle})}return(t,l)=>(P(),C(T(w),S(y.value,{onPreviewCode:B,onCopy:l[0]||(l[0]=a=>p("copy",a))}),b({_:2},[t.$slots["header-left"]?{name:"header-left",fn:i(()=>[d(t.$slots,"header-left")]),key:"0"}:void 0,t.$slots["header-right"]?{name:"header-right",fn:i(()=>[d(t.$slots,"header-right")]),key:"1"}:void 0,t.$slots.loading?{name:"loading",fn:i(a=>[d(t.$slots,"loading",k(x(a)))]),key:"2"}:void 0]),1040))}});h.install=o=>{o.component(h.__name,h)};export{h as default};
|
import c from"./CodeBlockNode-quY55RAx.js";import{M as v,bl as g,aL as P,s as C,A as b,bJ as i,aY as d,av as k,a4 as x,ar as S,bk as T,q as O}from"./index-BdL5hCoZ.js";import"./safeRaf-DGuzXxDK.js";var H=Object.defineProperty,z=Object.defineProperties,j=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable,m=(o,s,e)=>s in o?H(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;const h=v({__name:"MarkdownCodeBlockNode",props:{node:{},loading:{type:Boolean,default:!0},stream:{type:Boolean,default:!0},darkTheme:{default:"vitesse-dark"},lightTheme:{default:"vitesse-light"},isDark:{type:Boolean,default:!1},isShowPreview:{type:Boolean,default:!0},enableFontSizeControl:{type:Boolean,default:!0},minWidth:{default:void 0},maxWidth:{default:void 0},showPreviewButton:{type:Boolean,default:!0},showCollapseButton:{type:Boolean,default:!0},showFontSizeButtons:{type:Boolean,default:!0},showTooltips:{type:Boolean},autoScrollOnUpdate:{type:Boolean},autoScrollInitial:{type:Boolean},estimatedHeightPx:{},estimatedContentHeightPx:{},themes:{},langs:{},showHeader:{type:Boolean,default:!0},showCopyButton:{type:Boolean,default:!0},showExpandButton:{type:Boolean,default:!0}},emits:["previewCode","copy"],setup(o,{emit:s}){const e=o,p=s,w=c,f=g(),y=O(()=>{return t=((a,n)=>{for(var r in n||(n={}))F.call(n,r)&&m(a,r,n[r]);if(u)for(var r of u(n))W.call(n,r)&&m(a,r,n[r]);return a})({},f),l={node:e.node,loading:e.loading,stream:e.stream,darkTheme:e.darkTheme,lightTheme:e.lightTheme,isDark:e.isDark,isShowPreview:e.isShowPreview,enableFontSizeControl:e.enableFontSizeControl,minWidth:e.minWidth,maxWidth:e.maxWidth,themes:e.themes,showHeader:e.showHeader,showCopyButton:e.showCopyButton,showExpandButton:e.showExpandButton,showPreviewButton:e.showPreviewButton,showCollapseButton:e.showCollapseButton,showFontSizeButtons:e.showFontSizeButtons,showTooltips:e.showTooltips,estimatedHeightPx:e.estimatedHeightPx,estimatedContentHeightPx:e.estimatedContentHeightPx},z(t,j(l));var t,l});function B(t){p("previewCode",{type:t.artifactType,content:e.node.code,title:t.artifactTitle})}return(t,l)=>(P(),C(T(w),S(y.value,{onPreviewCode:B,onCopy:l[0]||(l[0]=a=>p("copy",a))}),b({_:2},[t.$slots["header-left"]?{name:"header-left",fn:i(()=>[d(t.$slots,"header-left")]),key:"0"}:void 0,t.$slots["header-right"]?{name:"header-right",fn:i(()=>[d(t.$slots,"header-right")]),key:"1"}:void 0,t.$slots.loading?{name:"loading",fn:i(a=>[d(t.$slots,"loading",k(x(a)))]),key:"2"}:void 0]),1040))}});h.install=o=>{o.component(h.__name,h)};export{h as default};
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
||||||
import{bQ as C,M as D,a0 as N,bS as U,bT as L,aU as h,bE as A,aD as K,az as W,aL as y,u as x,bb as z,s as H,bJ as P,v as M,aY as V,g as X,t as j,q as O,bU as q,bV as F,bW as J,bX as Q}from"./index--0t1wzw_.js";var S=(f,b,r)=>new Promise((e,k)=>{var i=l=>{try{p(r.next(l))}catch(t){k(t)}},d=l=>{try{p(r.throw(l))}catch(t){k(t)}},p=l=>l.done?e(l.value):Promise.resolve(l.value).then(i,d);p((r=r.apply(f,b)).next())});const Y=["data-markstream-mode","data-markstream-pending"],G=["innerHTML"],Z={key:1,class:"math-inline math-inline--fallback"},ee={class:"math-inline__loading",role:"status","aria-live":"polite"},R=C(D({__name:"MathInlineNode",props:{node:{}},setup(f){var b,r;const e=f,k=h(null),i=O(()=>e.node.markup==="$$"),d=O(()=>q(e.node.content)),p=((r=(b=N())==null?void 0:b.vnode.el)==null?void 0:r.nodeType)===1,l=(function(){if(!e.node.content)return{html:"",text:e.node.loading?"":e.node.raw,loading:e.node.loading};if(e.node.loading)return{html:"",text:"",loading:!0};const a=U();if(!a){const n=typeof window>"u"||p;return{html:"",text:n?e.node.raw:"",loading:!n}}try{const n=a.renderToString(d.value,{throwOnError:!1,displayMode:i.value});return L(d.value,i.value,n),{html:n,text:"",loading:!1}}catch{return{html:"",text:e.node.loading?"":e.node.raw,loading:e.node.loading}}})(),t=h(l.html),u=h(l.text);let g=!1,m=0,s=!1,c=null;const v=h(l.loading),_=h(!1);function T(a){a!=null&&a!==m||(_.value=!1)}function B(){return S(this,null,function*(){if(s)return;c&&(c.abort(),c=null);const a=++m;if(!e.node.content)return T(),t.value="",u.value=e.node.loading?"":e.node.raw,v.value=e.node.loading,void(g=!1);const n=new AbortController;c=n,_.value=!0,s||a!==m||n.signal.aborted?T(a):F(d.value,i.value,{timeout:1500,waitTimeout:1500,maxRetries:8,signal:n.signal}).then(o=>{s||a!==m||(t.value=o,u.value="",v.value=!1,g=!0)}).catch(o=>S(null,null,function*(){if(s||a!==m)return;const w=o?.code||o?.name,$=w==="KATEX_DISABLED";if(w==="WORKER_INIT_ERROR"||o?.fallbackToRenderer||(w===J||w==="WORKER_TIMEOUT")&&!e.node.loading){const I=yield Q();if(s||a!==m)return;if(I){try{const E=I.renderToString(d.value,{throwOnError:e.node.loading,displayMode:i.value});t.value=E,u.value="",v.value=!1,g=!0,L(d.value,i.value,E)}catch{}return}}if($||!e.node.loading)return v.value=!1,t.value="",void(u.value=e.node.raw);g||(v.value=!0)})).finally(()=>{s||T(a)})})}return l.html&&(g=!0),A(()=>[e.node.content,e.node.loading,e.node.raw,e.node.markup],()=>{B()}),K(()=>{t.value||B()}),W(()=>{s=!0,c&&(c.abort(),c=null)}),(a,n)=>(y(),x("span",{ref_key:"containerEl",ref:k,class:"math-inline-wrapper","data-markstream-math":"inline","data-markstream-mode":t.value?"katex":u.value?"fallback":"loading","data-markstream-pending":_.value?"true":void 0},[t.value?(y(),x("span",{key:0,class:"math-inline",innerHTML:t.value},null,8,G)):u.value?(y(),x("span",Z,z(u.value),1)):v.value?(y(),H(X,{key:2,name:"table-node-fade"},{default:P(()=>[M("span",ee,[V(a.$slots,"loading",{isLoading:v.value},()=>[n[0]||(n[0]=M("span",{class:"math-inline__spinner animate-spin","aria-hidden":"true"},null,-1)),n[1]||(n[1]=M("span",{class:"sr-only"},"Loading",-1))],!0)])]),_:3})):j("",!0)],8,Y))}}),[["__scopeId","data-v-6c556261"]]);R.install=f=>{f.component(R.__name,R)};export{R as default};
|
import{bQ as C,M as D,a0 as N,bS as U,bT as L,aU as h,bE as A,aD as K,az as W,aL as y,u as x,bb as z,s as H,bJ as P,v as M,aY as V,g as X,t as j,q as O,bU as q,bV as F,bW as J,bX as Q}from"./index-BdL5hCoZ.js";var S=(f,b,r)=>new Promise((e,k)=>{var i=l=>{try{p(r.next(l))}catch(t){k(t)}},d=l=>{try{p(r.throw(l))}catch(t){k(t)}},p=l=>l.done?e(l.value):Promise.resolve(l.value).then(i,d);p((r=r.apply(f,b)).next())});const Y=["data-markstream-mode","data-markstream-pending"],G=["innerHTML"],Z={key:1,class:"math-inline math-inline--fallback"},ee={class:"math-inline__loading",role:"status","aria-live":"polite"},R=C(D({__name:"MathInlineNode",props:{node:{}},setup(f){var b,r;const e=f,k=h(null),i=O(()=>e.node.markup==="$$"),d=O(()=>q(e.node.content)),p=((r=(b=N())==null?void 0:b.vnode.el)==null?void 0:r.nodeType)===1,l=(function(){if(!e.node.content)return{html:"",text:e.node.loading?"":e.node.raw,loading:e.node.loading};if(e.node.loading)return{html:"",text:"",loading:!0};const a=U();if(!a){const n=typeof window>"u"||p;return{html:"",text:n?e.node.raw:"",loading:!n}}try{const n=a.renderToString(d.value,{throwOnError:!1,displayMode:i.value});return L(d.value,i.value,n),{html:n,text:"",loading:!1}}catch{return{html:"",text:e.node.loading?"":e.node.raw,loading:e.node.loading}}})(),t=h(l.html),u=h(l.text);let g=!1,m=0,s=!1,c=null;const v=h(l.loading),_=h(!1);function T(a){a!=null&&a!==m||(_.value=!1)}function B(){return S(this,null,function*(){if(s)return;c&&(c.abort(),c=null);const a=++m;if(!e.node.content)return T(),t.value="",u.value=e.node.loading?"":e.node.raw,v.value=e.node.loading,void(g=!1);const n=new AbortController;c=n,_.value=!0,s||a!==m||n.signal.aborted?T(a):F(d.value,i.value,{timeout:1500,waitTimeout:1500,maxRetries:8,signal:n.signal}).then(o=>{s||a!==m||(t.value=o,u.value="",v.value=!1,g=!0)}).catch(o=>S(null,null,function*(){if(s||a!==m)return;const w=o?.code||o?.name,$=w==="KATEX_DISABLED";if(w==="WORKER_INIT_ERROR"||o?.fallbackToRenderer||(w===J||w==="WORKER_TIMEOUT")&&!e.node.loading){const I=yield Q();if(s||a!==m)return;if(I){try{const E=I.renderToString(d.value,{throwOnError:e.node.loading,displayMode:i.value});t.value=E,u.value="",v.value=!1,g=!0,L(d.value,i.value,E)}catch{}return}}if($||!e.node.loading)return v.value=!1,t.value="",void(u.value=e.node.raw);g||(v.value=!0)})).finally(()=>{s||T(a)})})}return l.html&&(g=!0),A(()=>[e.node.content,e.node.loading,e.node.raw,e.node.markup],()=>{B()}),K(()=>{t.value||B()}),W(()=>{s=!0,c&&(c.abort(),c=null)}),(a,n)=>(y(),x("span",{ref_key:"containerEl",ref:k,class:"math-inline-wrapper","data-markstream-math":"inline","data-markstream-mode":t.value?"katex":u.value?"fallback":"loading","data-markstream-pending":_.value?"true":void 0},[t.value?(y(),x("span",{key:0,class:"math-inline",innerHTML:t.value},null,8,G)):u.value?(y(),x("span",Z,z(u.value),1)):v.value?(y(),H(X,{key:2,name:"table-node-fade"},{default:P(()=>[M("span",ee,[V(a.$slots,"loading",{isLoading:v.value},()=>[n[0]||(n[0]=M("span",{class:"math-inline__spinner animate-spin","aria-hidden":"true"},null,-1)),n[1]||(n[1]=M("span",{class:"sr-only"},"Loading",-1))],!0)])]),_:3})):j("",!0)],8,Y))}}),[["__scopeId","data-v-6c556261"]]);R.install=f=>{f.component(R.__name,R)};export{R as default};
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,2 +1,2 @@
|
||||||
import{_ as a,l as s,D as n,e as i}from"./mermaid.core-CqiFQExc.js";import{p}from"./cynefin-VYW2F7L2-DEnbetzx.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var g={parse:a(async r=>{const e=await p("info",r);s.debug(e)},"parse")},v={version:"11.16.0"},d=a(()=>v.version,"getVersion"),m={getVersion:d},c=a((r,e,o)=>{s.debug(`rendering info diagram
|
import{_ as a,l as s,F as n,e as i}from"./mermaid.core-cXaFT3ek.js";import{p}from"./cynefin-VYW2F7L2-BRNWksTk.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var g={parse:a(async r=>{const e=await p("info",r);s.debug(e)},"parse")},v={version:"11.16.0"},d=a(()=>v.version,"getVersion"),m={getVersion:d},c=a((r,e,o)=>{s.debug(`rendering info diagram
|
||||||
`+r);const t=n(e);i(t,100,400,!0),t.append("g").append("text").attr("x",100).attr("y",40).attr("class","version").attr("font-size",32).style("text-anchor","middle").text(`v${o}`)},"draw"),l={draw:c},w={parser:g,db:m,renderer:l};export{w as diagram};
|
`+r);const t=n(e);i(t,100,400,!0),t.append("g").append("text").attr("x",100).attr("y",40).attr("class","version").attr("font-size",32).style("text-anchor","middle").text(`v${o}`)},"draw"),l={draw:c},w={parser:g,db:m,renderer:l};export{w as diagram};
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
||||||
import{g as gt}from"./chunk-5VM5RSS4-BRWxG5tM.js";import{a as mt,g as lt,h as xt,d as kt}from"./chunk-32BRIVSS-mfMW4-bV.js";import{g as _t,s as vt,a as bt,b as wt,o as Tt,n as St,_ as s,c as R,d as X,e as $t,p as Mt}from"./mermaid.core-CqiFQExc.js";import{d as it}from"./arc-CxCMb0Ef.js";import"./index--0t1wzw_.js";import"./_commonjsHelpers-CqkleIqs.js";var U=(function(){var t=s(function(h,r,n,l){for(n=n||{},l=h.length;l--;n[h[l]]=r);return n},"o"),e=[6,8,10,11,12,14,16,17,18],a=[1,9],f=[1,10],i=[1,11],u=[1,12],p=[1,13],o=[1,14],g={trace:s(function(){},"trace"),yy:{},symbols_:{error:2,start:3,journey:4,document:5,EOF:6,line:7,SPACE:8,statement:9,NEWLINE:10,title:11,acc_title:12,acc_title_value:13,acc_descr:14,acc_descr_value:15,acc_descr_multiline_value:16,section:17,taskName:18,taskData:19,$accept:0,$end:1},terminals_:{2:"error",4:"journey",6:"EOF",8:"SPACE",10:"NEWLINE",11:"title",12:"acc_title",13:"acc_title_value",14:"acc_descr",15:"acc_descr_value",16:"acc_descr_multiline_value",17:"section",18:"taskName",19:"taskData"},productions_:[0,[3,3],[5,0],[5,2],[7,2],[7,1],[7,1],[7,1],[9,1],[9,2],[9,2],[9,1],[9,1],[9,2]],performAction:s(function(r,n,l,y,d,c,v){var k=c.length-1;switch(d){case 1:return c[k-1];case 2:this.$=[];break;case 3:c[k-1].push(c[k]),this.$=c[k-1];break;case 4:case 5:this.$=c[k];break;case 6:case 7:this.$=[];break;case 8:y.setDiagramTitle(c[k].substr(6)),this.$=c[k].substr(6);break;case 9:this.$=c[k].trim(),y.setAccTitle(this.$);break;case 10:case 11:this.$=c[k].trim(),y.setAccDescription(this.$);break;case 12:y.addSection(c[k].substr(8)),this.$=c[k].substr(8);break;case 13:y.addTask(c[k-1],c[k]),this.$="task";break}},"anonymous"),table:[{3:1,4:[1,2]},{1:[3]},t(e,[2,2],{5:3}),{6:[1,4],7:5,8:[1,6],9:7,10:[1,8],11:a,12:f,14:i,16:u,17:p,18:o},t(e,[2,7],{1:[2,1]}),t(e,[2,3]),{9:15,11:a,12:f,14:i,16:u,17:p,18:o},t(e,[2,5]),t(e,[2,6]),t(e,[2,8]),{13:[1,16]},{15:[1,17]},t(e,[2,11]),t(e,[2,12]),{19:[1,18]},t(e,[2,4]),t(e,[2,9]),t(e,[2,10]),t(e,[2,13])],defaultActions:{},parseError:s(function(r,n){if(n.recoverable)this.trace(r);else{var l=new Error(r);throw l.hash=n,l}},"parseError"),parse:s(function(r){var n=this,l=[0],y=[],d=[null],c=[],v=this.table,k="",C=0,Q=0,yt=2,D=1,dt=c.slice.call(arguments,1),_=Object.create(this.lexer),I={yy:{}};for(var O in this.yy)Object.prototype.hasOwnProperty.call(this.yy,O)&&(I.yy[O]=this.yy[O]);_.setInput(r,I.yy),I.yy.lexer=_,I.yy.parser=this,typeof _.yylloc>"u"&&(_.yylloc={});var Y=_.yylloc;c.push(Y);var ft=_.options&&_.options.ranges;typeof I.yy.parseError=="function"?this.parseError=I.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function pt(w){l.length=l.length-2*w,d.length=d.length-w,c.length=c.length-w}s(pt,"popStack");function tt(){var w;return w=y.pop()||_.lex()||D,typeof w!="number"&&(w instanceof Array&&(y=w,w=y.pop()),w=n.symbols_[w]||w),w}s(tt,"lex");for(var b,A,T,q,F={},N,M,et,z;;){if(A=l[l.length-1],this.defaultActions[A]?T=this.defaultActions[A]:((b===null||typeof b>"u")&&(b=tt()),T=v[A]&&v[A][b]),typeof T>"u"||!T.length||!T[0]){var H="";z=[];for(N in v[A])this.terminals_[N]&&N>yt&&z.push("'"+this.terminals_[N]+"'");_.showPosition?H="Parse error on line "+(C+1)+`:
|
import{g as gt}from"./chunk-5VM5RSS4-KnT0i4wx.js";import{a as mt,g as lt,h as xt,d as kt}from"./chunk-32BRIVSS-OEA_sg25.js";import{g as _t,s as vt,a as bt,b as wt,p as Tt,o as St,_ as s,c as R,d as X,e as $t,q as Mt}from"./mermaid.core-cXaFT3ek.js";import{d as it}from"./arc-CddDuEjz.js";import"./index-BdL5hCoZ.js";import"./_commonjsHelpers-CqkleIqs.js";var U=(function(){var t=s(function(h,r,n,l){for(n=n||{},l=h.length;l--;n[h[l]]=r);return n},"o"),e=[6,8,10,11,12,14,16,17,18],a=[1,9],f=[1,10],i=[1,11],u=[1,12],p=[1,13],o=[1,14],g={trace:s(function(){},"trace"),yy:{},symbols_:{error:2,start:3,journey:4,document:5,EOF:6,line:7,SPACE:8,statement:9,NEWLINE:10,title:11,acc_title:12,acc_title_value:13,acc_descr:14,acc_descr_value:15,acc_descr_multiline_value:16,section:17,taskName:18,taskData:19,$accept:0,$end:1},terminals_:{2:"error",4:"journey",6:"EOF",8:"SPACE",10:"NEWLINE",11:"title",12:"acc_title",13:"acc_title_value",14:"acc_descr",15:"acc_descr_value",16:"acc_descr_multiline_value",17:"section",18:"taskName",19:"taskData"},productions_:[0,[3,3],[5,0],[5,2],[7,2],[7,1],[7,1],[7,1],[9,1],[9,2],[9,2],[9,1],[9,1],[9,2]],performAction:s(function(r,n,l,y,d,c,v){var k=c.length-1;switch(d){case 1:return c[k-1];case 2:this.$=[];break;case 3:c[k-1].push(c[k]),this.$=c[k-1];break;case 4:case 5:this.$=c[k];break;case 6:case 7:this.$=[];break;case 8:y.setDiagramTitle(c[k].substr(6)),this.$=c[k].substr(6);break;case 9:this.$=c[k].trim(),y.setAccTitle(this.$);break;case 10:case 11:this.$=c[k].trim(),y.setAccDescription(this.$);break;case 12:y.addSection(c[k].substr(8)),this.$=c[k].substr(8);break;case 13:y.addTask(c[k-1],c[k]),this.$="task";break}},"anonymous"),table:[{3:1,4:[1,2]},{1:[3]},t(e,[2,2],{5:3}),{6:[1,4],7:5,8:[1,6],9:7,10:[1,8],11:a,12:f,14:i,16:u,17:p,18:o},t(e,[2,7],{1:[2,1]}),t(e,[2,3]),{9:15,11:a,12:f,14:i,16:u,17:p,18:o},t(e,[2,5]),t(e,[2,6]),t(e,[2,8]),{13:[1,16]},{15:[1,17]},t(e,[2,11]),t(e,[2,12]),{19:[1,18]},t(e,[2,4]),t(e,[2,9]),t(e,[2,10]),t(e,[2,13])],defaultActions:{},parseError:s(function(r,n){if(n.recoverable)this.trace(r);else{var l=new Error(r);throw l.hash=n,l}},"parseError"),parse:s(function(r){var n=this,l=[0],y=[],d=[null],c=[],v=this.table,k="",C=0,Q=0,yt=2,D=1,dt=c.slice.call(arguments,1),_=Object.create(this.lexer),I={yy:{}};for(var O in this.yy)Object.prototype.hasOwnProperty.call(this.yy,O)&&(I.yy[O]=this.yy[O]);_.setInput(r,I.yy),I.yy.lexer=_,I.yy.parser=this,typeof _.yylloc>"u"&&(_.yylloc={});var Y=_.yylloc;c.push(Y);var ft=_.options&&_.options.ranges;typeof I.yy.parseError=="function"?this.parseError=I.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;function pt(w){l.length=l.length-2*w,d.length=d.length-w,c.length=c.length-w}s(pt,"popStack");function tt(){var w;return w=y.pop()||_.lex()||D,typeof w!="number"&&(w instanceof Array&&(y=w,w=y.pop()),w=n.symbols_[w]||w),w}s(tt,"lex");for(var b,A,T,q,F={},N,M,et,z;;){if(A=l[l.length-1],this.defaultActions[A]?T=this.defaultActions[A]:((b===null||typeof b>"u")&&(b=tt()),T=v[A]&&v[A][b]),typeof T>"u"||!T.length||!T[0]){var H="";z=[];for(N in v[A])this.terminals_[N]&&N>yt&&z.push("'"+this.terminals_[N]+"'");_.showPosition?H="Parse error on line "+(C+1)+`:
|
||||||
`+_.showPosition()+`
|
`+_.showPosition()+`
|
||||||
Expecting `+z.join(", ")+", got '"+(this.terminals_[b]||b)+"'":H="Parse error on line "+(C+1)+": Unexpected "+(b==D?"end of input":"'"+(this.terminals_[b]||b)+"'"),this.parseError(H,{text:_.match,token:this.terminals_[b]||b,line:_.yylineno,loc:Y,expected:z})}if(T[0]instanceof Array&&T.length>1)throw new Error("Parse Error: multiple actions possible at state: "+A+", token: "+b);switch(T[0]){case 1:l.push(b),d.push(_.yytext),c.push(_.yylloc),l.push(T[1]),b=null,Q=_.yyleng,k=_.yytext,C=_.yylineno,Y=_.yylloc;break;case 2:if(M=this.productions_[T[1]][1],F.$=d[d.length-M],F._$={first_line:c[c.length-(M||1)].first_line,last_line:c[c.length-1].last_line,first_column:c[c.length-(M||1)].first_column,last_column:c[c.length-1].last_column},ft&&(F._$.range=[c[c.length-(M||1)].range[0],c[c.length-1].range[1]]),q=this.performAction.apply(F,[k,Q,C,I.yy,T[1],d,c].concat(dt)),typeof q<"u")return q;M&&(l=l.slice(0,-1*M*2),d=d.slice(0,-1*M),c=c.slice(0,-1*M)),l.push(this.productions_[T[1]][0]),d.push(F.$),c.push(F._$),et=v[l[l.length-2]][l[l.length-1]],l.push(et);break;case 3:return!0}}return!0},"parse")},m=(function(){var h={EOF:1,parseError:s(function(n,l){if(this.yy.parser)this.yy.parser.parseError(n,l);else throw new Error(n)},"parseError"),setInput:s(function(r,n){return this.yy=n||this.yy||{},this._input=r,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},"setInput"),input:s(function(){var r=this._input[0];this.yytext+=r,this.yyleng++,this.offset++,this.match+=r,this.matched+=r;var n=r.match(/(?:\r\n?|\n).*/g);return n?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),r},"input"),unput:s(function(r){var n=r.length,l=r.split(/(?:\r\n?|\n)/g);this._input=r+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-n),this.offset-=n;var y=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),l.length-1&&(this.yylineno-=l.length-1);var d=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:l?(l.length===y.length?this.yylloc.first_column:0)+y[y.length-l.length].length-l[0].length:this.yylloc.first_column-n},this.options.ranges&&(this.yylloc.range=[d[0],d[0]+this.yyleng-n]),this.yyleng=this.yytext.length,this},"unput"),more:s(function(){return this._more=!0,this},"more"),reject:s(function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
|
Expecting `+z.join(", ")+", got '"+(this.terminals_[b]||b)+"'":H="Parse error on line "+(C+1)+": Unexpected "+(b==D?"end of input":"'"+(this.terminals_[b]||b)+"'"),this.parseError(H,{text:_.match,token:this.terminals_[b]||b,line:_.yylineno,loc:Y,expected:z})}if(T[0]instanceof Array&&T.length>1)throw new Error("Parse Error: multiple actions possible at state: "+A+", token: "+b);switch(T[0]){case 1:l.push(b),d.push(_.yytext),c.push(_.yylloc),l.push(T[1]),b=null,Q=_.yyleng,k=_.yytext,C=_.yylineno,Y=_.yylloc;break;case 2:if(M=this.productions_[T[1]][1],F.$=d[d.length-M],F._$={first_line:c[c.length-(M||1)].first_line,last_line:c[c.length-1].last_line,first_column:c[c.length-(M||1)].first_column,last_column:c[c.length-1].last_column},ft&&(F._$.range=[c[c.length-(M||1)].range[0],c[c.length-1].range[1]]),q=this.performAction.apply(F,[k,Q,C,I.yy,T[1],d,c].concat(dt)),typeof q<"u")return q;M&&(l=l.slice(0,-1*M*2),d=d.slice(0,-1*M),c=c.slice(0,-1*M)),l.push(this.productions_[T[1]][0]),d.push(F.$),c.push(F._$),et=v[l[l.length-2]][l[l.length-1]],l.push(et);break;case 3:return!0}}return!0},"parse")},m=(function(){var h={EOF:1,parseError:s(function(n,l){if(this.yy.parser)this.yy.parser.parseError(n,l);else throw new Error(n)},"parseError"),setInput:s(function(r,n){return this.yy=n||this.yy||{},this._input=r,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},"setInput"),input:s(function(){var r=this._input[0];this.yytext+=r,this.yyleng++,this.offset++,this.match+=r,this.matched+=r;var n=r.match(/(?:\r\n?|\n).*/g);return n?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),r},"input"),unput:s(function(r){var n=r.length,l=r.split(/(?:\r\n?|\n)/g);this._input=r+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-n),this.offset-=n;var y=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),l.length-1&&(this.yylineno-=l.length-1);var d=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:l?(l.length===y.length?this.yylloc.first_column:0)+y[y.length-l.length].length-l[0].length:this.yylloc.first_column-n},this.options.ranges&&(this.yylloc.range=[d[0],d[0]+this.yyleng-n]),this.yyleng=this.yytext.length,this},"unput"),more:s(function(){return this._more=!0,this},"more"),reject:s(function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
|
||||||
`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},"reject"),less:s(function(r){this.unput(this.match.slice(r))},"less"),pastInput:s(function(){var r=this.matched.substr(0,this.matched.length-this.match.length);return(r.length>20?"...":"")+r.substr(-20).replace(/\n/g,"")},"pastInput"),upcomingInput:s(function(){var r=this.match;return r.length<20&&(r+=this._input.substr(0,20-r.length)),(r.substr(0,20)+(r.length>20?"...":"")).replace(/\n/g,"")},"upcomingInput"),showPosition:s(function(){var r=this.pastInput(),n=new Array(r.length+1).join("-");return r+this.upcomingInput()+`
|
`+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},"reject"),less:s(function(r){this.unput(this.match.slice(r))},"less"),pastInput:s(function(){var r=this.matched.substr(0,this.matched.length-this.match.length);return(r.length>20?"...":"")+r.substr(-20).replace(/\n/g,"")},"pastInput"),upcomingInput:s(function(){var r=this.match;return r.length<20&&(r+=this._input.substr(0,20-r.length)),(r.substr(0,20)+(r.length>20?"...":"")).replace(/\n/g,"")},"upcomingInput"),showPosition:s(function(){var r=this.pastInput(),n=new Array(r.length+1).join("-");return r+this.upcomingInput()+`
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue