@khorsheed/dsh-local-agent-kimi 0.1.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +132 -0
- package/README.i18n.yaml +6 -0
- package/README.md +132 -0
- package/cordis.patch.yml +34 -0
- package/lib/client.js +1066 -0
- package/lib/index.js +4716 -0
- package/lib/invariant.js +31 -0
- package/lib/types/client/SettingsCard.d.ts +77 -0
- package/lib/types/client/SettingsCard.js +197 -0
- package/lib/types/client/icons.d.ts +18 -0
- package/lib/types/client/icons.js +2 -0
- package/lib/types/client/index.d.ts +42 -0
- package/lib/types/client/index.js +89 -0
- package/lib/types/client/locales.d.ts +64 -0
- package/lib/types/client/locales.js +55 -0
- package/lib/types/credential-guard.d.ts +29 -0
- package/lib/types/credential-guard.js +107 -0
- package/lib/types/index.d.ts +69 -0
- package/lib/types/index.js +270 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/invariant.js +33 -0
- package/lib/types/kimi-cli-provider.d.ts +215 -0
- package/lib/types/kimi-cli-provider.js +855 -0
- package/lib/types/live-driver.d.ts +245 -0
- package/lib/types/live-driver.js +1312 -0
- package/lib/types/live-switch.d.ts +78 -0
- package/lib/types/live-switch.js +112 -0
- package/lib/types/member-bridge-config.d.ts +43 -0
- package/lib/types/member-bridge-config.js +80 -0
- package/lib/types/model-broker.d.ts +97 -0
- package/lib/types/model-broker.js +205 -0
- package/lib/types/model-catalog.d.ts +26 -0
- package/lib/types/model-catalog.js +86 -0
- package/lib/types/model-configuration.d.ts +11 -0
- package/lib/types/model-configuration.js +55 -0
- package/lib/types/preset-tools.d.ts +20 -0
- package/lib/types/preset-tools.js +36 -0
- package/lib/types/provision.d.ts +131 -0
- package/lib/types/provision.js +363 -0
- package/lib/types/records.d.ts +35 -0
- package/lib/types/records.js +85 -0
- package/lib/types/session-configuration.d.ts +5 -0
- package/lib/types/session-configuration.js +26 -0
- package/lib/types/session-mirror.d.ts +180 -0
- package/lib/types/session-mirror.js +446 -0
- package/lib/types/session-view.d.ts +121 -0
- package/lib/types/session-view.js +423 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +107 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot and resumable Kimi CLI subagent lifecycle: spawn `kimi -p "<task>"`
|
|
3
|
+
* through the subprocess seam, capture its printed response as the run output,
|
|
4
|
+
* and dispose to whole-tree quiescence. Mirrors the official one-shot Codex
|
|
5
|
+
* provider, and adds the family's own resume: a later round calls the tool with
|
|
6
|
+
* the first round's dsh child session id, the family registry maps it back to
|
|
7
|
+
* the kimi session, and the provider spawns `kimi -S session_<id> -p` so the
|
|
8
|
+
* SAME kimi conversation continues inside the SAME dsh child session.
|
|
9
|
+
* @module @khorsheed/dsh-local-agent-kimi/kimi-cli-provider
|
|
10
|
+
*/
|
|
11
|
+
import type { ContentBlock, TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
12
|
+
import { type ResolvedSubagentStartRequest, type SubagentCapabilities, type SubagentProvider, type SubagentRun, type SubagentStartRequest, type SubagentStopReason } from '@deepseek-ai/dsh-subagent';
|
|
13
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
14
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
15
|
+
import type { SubprocessHandle, SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess';
|
|
16
|
+
import type { DelegationExecTarget, LocalAgentToolCalls } from '@khorsheed/dsh-local-agent/types';
|
|
17
|
+
import type { KimiAcpLiveDriver } from './live-driver.ts';
|
|
18
|
+
import type { KimiModelBroker } from './model-broker.ts';
|
|
19
|
+
import { type KimiMirrorDelta, type KimiMirrorOptions } from './session-mirror.ts';
|
|
20
|
+
/** Default POSIX grace between subprocess termination tiers. */
|
|
21
|
+
export declare const DEFAULT_DISPOSE_GRACE_MS = 3000;
|
|
22
|
+
/**
|
|
23
|
+
* Auth-shaped failure signatures in kimi's stderr or output: the endpoint
|
|
24
|
+
* rejected the credential. Narrow on purpose — matched against
|
|
25
|
+
* provider-controlled error output only.
|
|
26
|
+
*/
|
|
27
|
+
export declare const KIMI_AUTH_FAILURE: RegExp;
|
|
28
|
+
/** Default interval between live transcript-mirror polls during a run. */
|
|
29
|
+
export declare const DEFAULT_LIVE_MIRROR_INTERVAL_MS = 2000;
|
|
30
|
+
/**
|
|
31
|
+
* The version `kimi --version` reports, probed through the shared subprocess
|
|
32
|
+
* seam inside the SCOPED home (never the user's own installation) and cached
|
|
33
|
+
* by the family probe against the executable's identity. Kimi's wire log names
|
|
34
|
+
* no build, so this is the only version channel the harness has — both the
|
|
35
|
+
* effective-settings snapshot and a settled round's read-back read it.
|
|
36
|
+
* @param ctx - host context carrying the subprocess seam.
|
|
37
|
+
* @param homeDir - the harness's scoped home.
|
|
38
|
+
* @returns the version, or undefined when the CLI cannot be asked.
|
|
39
|
+
*/
|
|
40
|
+
export declare function kimiCliVersion(ctx: Context, homeDir: string): Promise<string | undefined>;
|
|
41
|
+
export declare class KimiCliProvider implements SubagentProvider {
|
|
42
|
+
private readonly ctx;
|
|
43
|
+
private readonly live?;
|
|
44
|
+
private readonly model?;
|
|
45
|
+
private readonly memberModels?;
|
|
46
|
+
readonly name = "kimi-cli";
|
|
47
|
+
readonly capabilities: SubagentCapabilities;
|
|
48
|
+
readonly inheritsParentContext = false;
|
|
49
|
+
/**
|
|
50
|
+
* @param live - the live driver, or a resolver returning the current
|
|
51
|
+
* generation's driver per member (the settings toggle swaps generations;
|
|
52
|
+
* a resolver may return undefined to steer one member's round to exec
|
|
53
|
+
* while a retiring generation still hosts it).
|
|
54
|
+
* @param model - resolver for the configured model, read PER ROUND so a
|
|
55
|
+
* settings-card write takes effect on the next delegation without a
|
|
56
|
+
* reload. Undefined (the resolver absent, or returning undefined) leaves
|
|
57
|
+
* the argv exactly as it was before the key rode every round — the scoped
|
|
58
|
+
* config.toml's `default_model` then decides, as it always did.
|
|
59
|
+
* @param memberModels - the broker's member-model ledger: the provider
|
|
60
|
+
* records each delegation's start model here (the live driver's spawn
|
|
61
|
+
* resolver binds it) and reads the session-level override as the exec
|
|
62
|
+
* path's top layer. Absent (older wiring), both drop out.
|
|
63
|
+
*/
|
|
64
|
+
constructor(ctx: Context, live?: KimiAcpLiveDriver | ((childSessionId: string) => KimiAcpLiveDriver | undefined) | undefined, model?: (() => string | undefined) | undefined, memberModels?: KimiModelBroker | undefined);
|
|
65
|
+
/** Resolve the live driver for one round's member, if live is on for it. */
|
|
66
|
+
private liveDriver;
|
|
67
|
+
/**
|
|
68
|
+
* Register one run with the member channel and declare the bridge MCP server
|
|
69
|
+
* in the scoped home's mcp.json (per-run entry, socket + token in its env).
|
|
70
|
+
* Returns the release handle, or undefined when the mounted core
|
|
71
|
+
* predates the member channel (declare-and-degrade: the run proceeds
|
|
72
|
+
* exactly as before). Token-only auth: host 0.1.5 removed the child pid the
|
|
73
|
+
* parentage cross-check used; the per-run token is the sole credential (see
|
|
74
|
+
* the package README's threat model). `release` invalidates the token and
|
|
75
|
+
* prunes the config entry on any settle path.
|
|
76
|
+
*/
|
|
77
|
+
private memberRun;
|
|
78
|
+
start(request: ResolvedSubagentStartRequest): Promise<SubagentRun>;
|
|
79
|
+
/** Fresh round: record the child session, spawn `kimi -p`, mirror after settle. */
|
|
80
|
+
private startKimiFresh;
|
|
81
|
+
/** Resume round: continue the recorded kimi session inside the existing child session. */
|
|
82
|
+
private startKimiResume;
|
|
83
|
+
}
|
|
84
|
+
/** Fully resolved inputs for one Kimi CLI run. */
|
|
85
|
+
export interface KimiCliRunSpec {
|
|
86
|
+
/** Parent Session workspace; also the kimi process cwd. */
|
|
87
|
+
readonly cwd: string;
|
|
88
|
+
/** Explicit environment layered after the shared credential scrub. */
|
|
89
|
+
readonly env: Readonly<NodeJS.ProcessEnv>;
|
|
90
|
+
/**
|
|
91
|
+
* Run the CLI inside this container instead of on the host: the argv below
|
|
92
|
+
* is wrapped in `docker exec` and {@link env} is forwarded through NAME-only
|
|
93
|
+
* `-e` flags. Absent means the host spawn, unchanged.
|
|
94
|
+
*/
|
|
95
|
+
readonly exec?: DelegationExecTarget | undefined;
|
|
96
|
+
/** Resolved endpoint label for diagnostics; absent means the CLI default. */
|
|
97
|
+
readonly endpointLabel?: string | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Model this round runs with, passed as `kimi -m <model>`. The value must
|
|
100
|
+
* name a model the scoped `config.toml` defines (a `[models."…"]` key) —
|
|
101
|
+
* kimi resolves the flag against its own model table. Absent means no `-m`
|
|
102
|
+
* on the argv at all: `default_model` decides, exactly as before the key
|
|
103
|
+
* rode every round.
|
|
104
|
+
*/
|
|
105
|
+
readonly model?: string | undefined;
|
|
106
|
+
readonly effort?: string | undefined;
|
|
107
|
+
readonly controlled?: boolean;
|
|
108
|
+
/** Subprocess termination grace passed to the shared process-tree owner. */
|
|
109
|
+
readonly disposeGraceMs: number;
|
|
110
|
+
/** Shared subprocess service spawn operation. */
|
|
111
|
+
readonly spawn: (spec: SubprocessSpawnSpec) => SubprocessHandle;
|
|
112
|
+
/** Diagnostic sink for a post-publication error flattened into a result. */
|
|
113
|
+
readonly onError?: (error: Error, stopReason: SubagentStopReason) => void;
|
|
114
|
+
/**
|
|
115
|
+
* Called when the settled failure is auth-shaped (the endpoint rejected the
|
|
116
|
+
* credential — a 401 a presence probe cannot see). The provider wires this
|
|
117
|
+
* to the family registry's auth-failure mark.
|
|
118
|
+
*/
|
|
119
|
+
readonly onAuthFailure?: ((detail: string) => void) | undefined;
|
|
120
|
+
/** dsh subagent session recording this delegation; its transcript is mirrored after settle. */
|
|
121
|
+
readonly childSession?: Session | undefined;
|
|
122
|
+
/** The `kimi` harness's scoped home, read for the transcript to mirror. */
|
|
123
|
+
readonly homeDir?: string | undefined;
|
|
124
|
+
/** Host context carrying session persistence for the transcript mirror. */
|
|
125
|
+
readonly ctx?: Context | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Resume round: continue the CLI session named by `cliSessionId` with
|
|
128
|
+
* `kimi -S session_<id> -p` instead of a fresh `kimi -p`, appending this
|
|
129
|
+
* round into the same child session under the given turn number.
|
|
130
|
+
*/
|
|
131
|
+
readonly resume?: {
|
|
132
|
+
readonly cliSessionId: string;
|
|
133
|
+
readonly turn: number;
|
|
134
|
+
} | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Called after the run settles with the kimi session id parsed from stderr
|
|
137
|
+
* (absent when the hint is missing). The fresh path uses it to record the
|
|
138
|
+
* delegation so a later resume round can continue the session.
|
|
139
|
+
*/
|
|
140
|
+
readonly onCliSessionId?: ((cliSessionId: string | undefined) => void) | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Called once per settled round, after the wire log has been fully mirrored:
|
|
143
|
+
* the round's observed model identifier (the wire's `usage.record` /
|
|
144
|
+
* `llm.request` `model`) and token usage (the round's mirror windows summed),
|
|
145
|
+
* each absent when the wire yielded none. The provider wires this to the
|
|
146
|
+
* registry's observation channel (`recordRoundSettled` — the delegation
|
|
147
|
+
* record's `observedModel` merge and the `settled` run-progress event).
|
|
148
|
+
* Fires for fresh and resume rounds alike, on every terminal state.
|
|
149
|
+
*/
|
|
150
|
+
readonly onRoundSettled?: ((round: {
|
|
151
|
+
readonly observedModel?: string;
|
|
152
|
+
readonly cliVersion?: string;
|
|
153
|
+
readonly usage?: TokenUsage;
|
|
154
|
+
readonly toolCalls?: LocalAgentToolCalls;
|
|
155
|
+
}) => void) | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Called when the round SETTLED COMPLETED — the CLI reached its endpoint and
|
|
158
|
+
* produced an answer, which is the only evidence a host has that the scoped
|
|
159
|
+
* credential is live. The provider wires this to the family registry's
|
|
160
|
+
* auth-success mark (the `verified` credential grade).
|
|
161
|
+
*/
|
|
162
|
+
readonly onAuthSuccess?: (() => void) | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* The version the executable reports, resolved lazily and cached by the
|
|
165
|
+
* family probe. Kimi's wire log names no CLI version, so this is the only
|
|
166
|
+
* channel the round's read-back has.
|
|
167
|
+
*/
|
|
168
|
+
readonly cliVersion?: (() => Promise<string | undefined>) | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Live-mirror poll interval during the run; absent disables nothing — the
|
|
171
|
+
* default ({@link DEFAULT_LIVE_MIRROR_INTERVAL_MS}) applies. Tests inject a
|
|
172
|
+
* small value.
|
|
173
|
+
*/
|
|
174
|
+
readonly liveMirrorIntervalMs?: number | undefined;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Extract the kimi session id from the CLI's printed response. `kimi -p`
|
|
178
|
+
* prints a resume hint (`To resume this session: kimi -r session_<id>`) on
|
|
179
|
+
* stdout after a run; mirroring that exact session instead of the newest-by-
|
|
180
|
+
* mtime keeps concurrent delegations from cross-mirroring.
|
|
181
|
+
* @param output - the collected CLI stdout.
|
|
182
|
+
* @returns the session id, or undefined when the hint is absent.
|
|
183
|
+
*/
|
|
184
|
+
export declare function kimiSessionIdFromOutput(output: string): string | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* Validate and join the one-shot task before crossing the process boundary.
|
|
187
|
+
* @param prompt - task content accepted from the shared subagent service.
|
|
188
|
+
* @returns the joined non-empty text.
|
|
189
|
+
*/
|
|
190
|
+
export declare function textTask(prompt: readonly ContentBlock[]): string;
|
|
191
|
+
/**
|
|
192
|
+
* Mirror the transcript delta after the recorded offset, advance the offset,
|
|
193
|
+
* and report one `delta` progress per newly mirrored line. Shared by the live
|
|
194
|
+
* poll and the settle-time mirror so the two paths cannot drift. The offset
|
|
195
|
+
* read (`kimiMirroredLines`) and write (`setKimiMirroredLines`) are the same
|
|
196
|
+
* bookkeeping the settle path used before live mirroring existed.
|
|
197
|
+
* @param ctx - host context carrying localAgent and session persistence.
|
|
198
|
+
* @param childSession - the dsh child session being mirrored into.
|
|
199
|
+
* @param homeDir - the `kimi` harness's scoped home.
|
|
200
|
+
* @param kimiSessionId - the kimi session to mirror.
|
|
201
|
+
* @returns the mirror delta (new total + newly mirrored line texts).
|
|
202
|
+
*/
|
|
203
|
+
export declare function mirrorKimiDelta(ctx: Context, childSession: Session, homeDir: string, kimiSessionId: string | undefined, options?: KimiMirrorOptions): Promise<KimiMirrorDelta>;
|
|
204
|
+
/**
|
|
205
|
+
* Start the real `kimi -p` (fresh) or `kimi -S session_<id> -p` (resume)
|
|
206
|
+
* child and publish its run. The kimi response is printed to stdout; stderr
|
|
207
|
+
* is inherited for diagnostics. The run id is the child session id for a
|
|
208
|
+
* session-backed run, so the tool's `resume="<id>"` self-description names
|
|
209
|
+
* the same handle the registry records.
|
|
210
|
+
* @param request - resolved shared subagent request.
|
|
211
|
+
* @param spec - workspace, environment, process service, and diagnostic policy.
|
|
212
|
+
* @returns the published run after the child starts.
|
|
213
|
+
*/
|
|
214
|
+
export declare function startKimiCliRun(request: SubagentStartRequest, spec: KimiCliRunSpec): Promise<SubagentRun>;
|
|
215
|
+
//# sourceMappingURL=kimi-cli-provider.d.ts.map
|