* feat: surface the bound model on subagent UIs The subagent.spawned event now carries the display-normalized model alias (the derived __secondary__ entry resolves to its base alias), so clients can show which model a subagent is bound to. The TUI subagent card, swarm panel header, and background-agent entry show it at spawn; the WS snapshot roster and REST /tasks (background/detached subagents) carry it too, keeping the model visible across client reconnects. * feat: carry the subagent thinking effort alongside the model The spawned event, snapshot roster, and REST /tasks now also carry the child's effective thinking effort (read from the child profile at spawn, the same vocabulary as agent.status.updated). UIs show it only when it diverges from the main session's current effort — an inherited level adds no information, and 'off' is never shown. * feat(tui): show the bound model and effort in the /tasks browser The task browser's Detail pane renders Model and Effort rows for agent tasks (raw alias and level — it is the inspector surface, so no diff filtering), and its minimum height grows to fit the new rows. The values were already persisted on SubagentTaskInfo; the TaskInfo union, its zod schemas (protocol, kap-server, klient contract), and the v1 type declaration now carry them so nothing strips them in transit. * feat(tui): show concrete subagent effort levels unconditionally Display rule simplified: any concrete effort tier (low/high/max/…) is shown next to the model — including when it matches the main session's level. Only the boolean states stay hidden: 'off' (no thinking) and 'on' (generic thinking) carry no level information. * docs: trim the changeset entry * fix(tui): keep the model and effort on background-agent entries across resume replayBackgroundProjection only copied agentId/parentToolCallId/ description, so a background subagent that outlived a resume lost its model/effort on the later terminal transcript entry. The projection now threads the persisted values (catalog-mapped model; boolean effort states dropped), and session replay passes the loaded model catalog through. * fix(agent-core-v2): normalize the derived secondary alias regardless of the flag A child bound while the secondary-model experiment was on keeps __secondary__ in its persisted binding; if the flag is later switched off with the recipe still configured, resolveSecondaryModel() gated the normalization and the sentinel leaked back onto resumed subagents. subagentDisplayModel now reads the recipe straight from config (the flag gates new bindings, not the interpretation of existing ones), which also drops SessionSwarmService's now-unused IFlagService dependency. Also adds the SDK package to the release: the new SubagentSpawnedEvent/AgentTaskInfo fields are SDK-visible types. * fix(agent-core-v2): normalize the status-frame model at the source A derived-bound child republishes agent.status.updated right after spawn with its raw modelAlias, which overwrote the spawned event's normalized display model on single-subagent cards (swarm headers were first-wins and escaped). emitStatusUpdated now maps through subagentDisplayModel, a no-op for the never-derived main agent. Also moves the inline comments added by this branch into top-of-file headers per the v2 comment convention. * fix(tui): clamp the /tasks detail frame to the available body At terminals near the minimum height the forced 10-row detail frame overflowed the body and truncated the preview frame's border. The detail height now caps out at whatever leaves the preview its borders plus one content row, with a regression test at exactly MIN_HEIGHT. * fix: normalize inherited derived aliases and keep model/effort on replayed terminal entries - resolveSubagentBinding's caller-fallback branch also maps through subagentDisplayModel: a caller itself bound to the derived entry (a resumed subagent making a nested Agent call) no longer publishes __secondary__. - The replayed background-task terminal notification builds its metadata with the persisted model (catalog-mapped) and concrete effort, matching the live completion path. - Drops the inline comments this branch added inside v2 test bodies; the scenario context lives in the source file headers. |
||
|---|---|---|
| .. | ||
| examples | ||
| scripts | ||
| src | ||
| test | ||
| AGENTS.md | ||
| CHANGELOG.md | ||
| Dockerfile | ||
| package.json | ||
| README.md | ||
| tsconfig.examples.json | ||
| tsconfig.json | ||
| tsdown.config.ts | ||
| vitest.config.ts | ||
@moonshot-ai/klient
Contract-driven client SDK for the agent-core-v2 engine. One facade, two transports — you pick the transport once at creation; everything after that is byte-identical:
import { bootstrap, logSeed, resolveLoggingConfig } from '@moonshot-ai/agent-core-v2';
import { createKlient } from '@moonshot-ai/klient/memory'; // or '/ipc'
const { app } = bootstrap({ homeDir }, [
...logSeed(resolveLoggingConfig({ homeDir, env: process.env })),
]);
const klient = createKlient({ scope: app });
const env = await klient.global.env();
const sessions = await klient.global.sessions.list({ limit: 20 });
const session = await klient.global.sessions.create({ workDir: process.cwd() });
const agent = klient.session(session.id).agent('main');
agent.events.on('assistant.delta', (e) => process.stdout.write(e.delta));
agent.events.on('prompt.completed', () => console.log('\ndone'));
await agent.prompt({ input: [{ type: 'text', text: 'Say OK.' }] });
await klient.close();
Architecture
facade (klient.global.*, klient.session(id).*, session.agent(id).*, *.events.*)
↓ single-object params, zod-validated
contract (procedure schemas, shared by all transports)
↓
KlientChannel { call, listen } ← the only transport SPI
↓
ipc │ memory
- Facade — aggregated methods, no engine service tokens, no
onDid*/onWill*event names. There is no escape hatch to raw services: the facade is the public contract.klient.global.*—sessions.*(incl.create),workspaces.*,config.*,providers.*,models.*,catalog.*,auth.*,flags.*,plugins.*,hostFs.*,env().klient.session(id).*—get/setTitle/update/status/close/archive/ restore/fork/createChild,approvals.*,questions.*,interactions.*,agents().session.agent(id).*—prompt/steer/cancel/runShellCommand/ cancelShellCommand/getModel/setModel/setPermission/getUsage/getContext/ getPlan*/getTasks*/stopTask/getTaskOutput.
- Contract — every method has a zod input tuple + output schema, validated
on the client before send / after receive (default on;
validate: falseto disable). Validation is sub-µs for typical payloads — cheaper than the JSON serialization the wire already pays. - Events —
klient.events.on(...)for the global bus (config.changed,kosong.models.changed,session.archived, …),session(id).events.on('metadata.changed' | 'interactions.changed' | 'interactions.resolved'), andagent(id).events.on('turn.started' | 'assistant.delta' | 'tool.call.started' | 'prompt.completed' | …). Underlying subscriptions are shared and ref-counted; payloads are validated; bad payloads drop toevents.onError.
Transports
| entry | options | events |
|---|---|---|
@moonshot-ai/klient/ipc |
{ socketPath, token? } |
same socket |
@moonshot-ai/klient/memory |
{ scope } (a bootstrapped engine app scope) |
direct emitter/bus subscription |
ipc and memory share one in-process dispatcher, so they behave identically
by construction; memory additionally JSON round-trips every value so results
cross the same JSON boundary a socket transport would impose. The IPC host
ships with the transport: serveKlientIpc({ scope, socketPath }).
The same conformance suite runs against both transports in this
package's tests (test/helpers/conformance.ts — one test file per transport).
This package also hosts the e2e suites (the retired server-e2e package was
folded in here):
test/e2e/legacy/+test/e2e/harness/— the legacy/api/v1live suites and their client harness (skip unlessKIMI_SERVER_URLis set; the v1 surface has no in-memory equivalent, so these stay live-server-only).
The docker e2e runner (pnpm docker:e2e) runs this whole vitest suite inside
a container against a container-local server. See AGENTS.md for the testing
rules.
Scope
The facade covers the global (app), session, and agent surfaces shown above.
What it deliberately leaves out (for now): onWill/hook-style interception
(engine hooks are in-process OrderedHookSlots and not wire-exposable), file
upload (v1 multipart REST only), and the terminal surface (v1 REST + WS
only).
Smoke check
pnpm -C packages/klient smoke
examples/smoke.ts boots an in-process engine (memory transport) and asserts
the global facade end-to-end — no server needed. examples/basic.ts is a
shorter narrated tour; examples/context-usage.ts traces context-size
readings through a real prompt (requires KIMI_EXAMPLE_MODEL +
KIMI_EXAMPLE_API_KEY).