dsh-loop-engine 1.0.0-rc10
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.md +121 -0
- package/README.zh.md +38 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +37506 -0
- package/lib/index.js +6412 -0
- package/lib/invariant.js +108 -0
- package/lib/types/client/LoopEngineBadge.d.ts +34 -0
- package/lib/types/client/LoopEngineComposerSelect.d.ts +40 -0
- package/lib/types/client/LoopEngineSection.d.ts +34 -0
- package/lib/types/client/index.d.ts +29 -0
- package/lib/types/client/locales.d.ts +46 -0
- package/lib/types/client/store.d.ts +58 -0
- package/lib/types/commands.d.ts +69 -0
- package/lib/types/driver-core/context-files.d.ts +62 -0
- package/lib/types/driver-core/ownership.d.ts +40 -0
- package/lib/types/driver-core/permission-knobs.d.ts +26 -0
- package/lib/types/driver-core/prompt.d.ts +23 -0
- package/lib/types/driver-core/skill-inject.d.ts +59 -0
- package/lib/types/engine-claude/agent.d.ts +104 -0
- package/lib/types/engine-claude/loop.d.ts +111 -0
- package/lib/types/engine-claude/mapping.d.ts +83 -0
- package/lib/types/engine-claude/permission.d.ts +41 -0
- package/lib/types/engine-claude/process.d.ts +59 -0
- package/lib/types/engine-claude/sdk.d.ts +57 -0
- package/lib/types/engine-claude/types.d.ts +18 -0
- package/lib/types/engine-codex/agent.d.ts +111 -0
- package/lib/types/engine-codex/appserver/client.d.ts +49 -0
- package/lib/types/engine-codex/appserver/mapping.d.ts +67 -0
- package/lib/types/engine-codex/appserver/thread.d.ts +66 -0
- package/lib/types/engine-codex/appserver/types.d.ts +215 -0
- package/lib/types/engine-codex/loop.d.ts +114 -0
- package/lib/types/engine-codex/permission.d.ts +32 -0
- package/lib/types/engine-codex/skills.d.ts +29 -0
- package/lib/types/engine-codex/types.d.ts +19 -0
- package/lib/types/engine-kimi/acp/client.d.ts +76 -0
- package/lib/types/engine-kimi/acp/mapping.d.ts +44 -0
- package/lib/types/engine-kimi/acp/types.d.ts +95 -0
- package/lib/types/engine-kimi/agent.d.ts +123 -0
- package/lib/types/engine-kimi/commands.d.ts +40 -0
- package/lib/types/engine-kimi/loop.d.ts +108 -0
- package/lib/types/engine-kimi/mapping.d.ts +71 -0
- package/lib/types/engine-kimi/permission.d.ts +28 -0
- package/lib/types/engine-kimi/process.d.ts +61 -0
- package/lib/types/engine-kimi/skills.d.ts +57 -0
- package/lib/types/engine-kimi/types.d.ts +23 -0
- package/lib/types/engine-pi/agent.d.ts +135 -0
- package/lib/types/engine-pi/loop.d.ts +123 -0
- package/lib/types/engine-pi/permission.d.ts +43 -0
- package/lib/types/engine-pi/probe.d.ts +23 -0
- package/lib/types/engine-pi/rpc/client.d.ts +105 -0
- package/lib/types/engine-pi/rpc/mapping.d.ts +37 -0
- package/lib/types/engine-pi/rpc/types.d.ts +235 -0
- package/lib/types/engine-pi/skills.d.ts +55 -0
- package/lib/types/engine-pi/types.d.ts +27 -0
- package/lib/types/index.d.ts +114 -0
- package/lib/types/invariant.d.ts +23 -0
- package/lib/types/namespace.d.ts +9 -0
- package/lib/types/patch-manager.d.ts +59 -0
- package/lib/types/preset.d.ts +73 -0
- package/lib/types/provider-route.d.ts +49 -0
- package/lib/types/settings.d.ts +31 -0
- package/lib/types/skills.d.ts +93 -0
- package/package.json +103 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Client Protocol (ACP) wire types for the `kimi acp` driver.
|
|
3
|
+
*
|
|
4
|
+
* Kimi exposes the ACP adapter over stdio (JSON-RPC 2.0). The driver speaks a
|
|
5
|
+
* minimal, stable subset that a normal agent flow needs: initialize, session/new,
|
|
6
|
+
* session/prompt, session/cancel, plus the `session/update` notifications carrying
|
|
7
|
+
* incremental assistant text (`agent_message_chunk`), thinking
|
|
8
|
+
* (`agent_thought_chunk`), and tool calls (`tool_call` / `tool_call_update`).
|
|
9
|
+
* Tool-approval arrives as the reverse-RPC `session/request_permission`, which the
|
|
10
|
+
* client must answer. Shapes below are the live-record deltas observed against the
|
|
11
|
+
* 0.28.1 CLI; content blocks re-use a `{ type, text }` text shape (and tolerate
|
|
12
|
+
* other block types by ignoring them).
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-loop-engine/engine-kimi/acp/types
|
|
15
|
+
*/
|
|
16
|
+
/** A text content block in an ACP update (the observed kimi shape). */
|
|
17
|
+
export interface AcpTextContent {
|
|
18
|
+
readonly type: 'text';
|
|
19
|
+
readonly text: string;
|
|
20
|
+
}
|
|
21
|
+
/** One tool-call content block: the observed kimi `{ type: 'content', content }` nesting. */
|
|
22
|
+
export interface AcpToolContentBlock {
|
|
23
|
+
readonly type: 'content';
|
|
24
|
+
readonly content: AcpTextContent;
|
|
25
|
+
}
|
|
26
|
+
/** A content block in a chunk/thought update; text is handled, others are ignored. */
|
|
27
|
+
export type AcpContentBlock = AcpTextContent | {
|
|
28
|
+
readonly type: 'image' | 'resource_link' | 'audio' | string;
|
|
29
|
+
readonly [key: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
/** One `session/update` notification (partial; the discriminator is `sessionUpdate`). */
|
|
32
|
+
export interface AcpUpdate {
|
|
33
|
+
readonly sessionUpdate: string;
|
|
34
|
+
readonly [key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** A tool-call announcement (`sessionUpdate: 'tool_call'`). */
|
|
37
|
+
export interface AcpToolCallExt extends AcpUpdate {
|
|
38
|
+
readonly sessionUpdate: 'tool_call';
|
|
39
|
+
readonly toolCallId: string;
|
|
40
|
+
readonly title: string;
|
|
41
|
+
readonly kind: string;
|
|
42
|
+
readonly status: string;
|
|
43
|
+
readonly content?: readonly AcpToolContentBlock[];
|
|
44
|
+
}
|
|
45
|
+
/** A tool-call progress/result stream (`sessionUpdate: 'tool_call_update'`). */
|
|
46
|
+
export interface AcpToolCallStreamExt extends AcpUpdate {
|
|
47
|
+
readonly sessionUpdate: 'tool_call_update';
|
|
48
|
+
readonly toolCallId: string;
|
|
49
|
+
readonly status: string;
|
|
50
|
+
readonly content?: readonly AcpToolContentBlock[];
|
|
51
|
+
}
|
|
52
|
+
/** The `session/request_permission` reverse-RPC params. */
|
|
53
|
+
export interface AcpPermissionRequest {
|
|
54
|
+
readonly sessionId?: string;
|
|
55
|
+
readonly request?: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** Result of a completed `session/prompt` request (opaque; the turn ended). */
|
|
58
|
+
export interface AcpPromptResult {
|
|
59
|
+
readonly [key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
/** The id-scoped response to a request (result or error). */
|
|
62
|
+
export interface AcpResponse {
|
|
63
|
+
readonly id: number;
|
|
64
|
+
readonly result?: unknown;
|
|
65
|
+
readonly error?: {
|
|
66
|
+
readonly code: number;
|
|
67
|
+
readonly message: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** A JSON-RPC request/notification frame on the wire. */
|
|
71
|
+
export interface AcpFrame {
|
|
72
|
+
readonly jsonrpc: '2.0';
|
|
73
|
+
readonly id?: number;
|
|
74
|
+
readonly method?: string;
|
|
75
|
+
readonly params?: unknown;
|
|
76
|
+
readonly result?: unknown;
|
|
77
|
+
readonly error?: {
|
|
78
|
+
readonly code: number;
|
|
79
|
+
readonly message: string;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** Guards toolkit: is the frame a `session/update` notification carrying an update. */
|
|
83
|
+
export declare function isUpdateFrame(frame: AcpFrame): frame is AcpFrame & {
|
|
84
|
+
readonly method: 'session/update';
|
|
85
|
+
readonly params: {
|
|
86
|
+
readonly sessionId: string;
|
|
87
|
+
readonly update: AcpUpdate;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
/** Guards toolkit: is the frame a reverse-RPC request needing an approval answer. */
|
|
91
|
+
export declare function isPermissionRequestFrame(frame: AcpFrame): frame is AcpFrame & {
|
|
92
|
+
readonly id: number;
|
|
93
|
+
readonly method: 'session/request_permission';
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi Code loop Agent: drives one session through turn and step boundaries over
|
|
3
|
+
* a persistent `kimi acp` child (Agent Client Protocol over stdio), speaking one
|
|
4
|
+
* stateless `session/new` + `session/prompt` per dsh step. The dsh session log is
|
|
5
|
+
* the sole source of model context and the prompt is a pure serialization of the
|
|
6
|
+
* durable history, so the transcript stays Model-visible ⟺ logged. Kimi owns its
|
|
7
|
+
* system prompt and tools natively; the ACP child is spawned through the dsh
|
|
8
|
+
* subprocess seam (the only available privilege boundary) and tool approvals are
|
|
9
|
+
* answered from the session's dsh approval knobs.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-loop-engine/engine-kimi/agent
|
|
12
|
+
*/
|
|
13
|
+
import type { Agent, AgentCancelCause, AgentOptions, AgentStatus, CancelOptions, InboxTarget } from '@deepseek-ai/dsh-agent';
|
|
14
|
+
import { Inbox } from '@deepseek-ai/dsh-agent';
|
|
15
|
+
import type { Scope } from '@deepseek-ai/dsh-scope';
|
|
16
|
+
import type { Session, SessionId, UserMessage } from '@deepseek-ai/dsh-session';
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
18
|
+
import type { ResolvedConfig } from './types.ts';
|
|
19
|
+
import type { KimiSpawnCapability } from './process.ts';
|
|
20
|
+
/** Provider route label used for logged header snapshots and message provenance. */
|
|
21
|
+
export declare const PROVIDER = "kimi";
|
|
22
|
+
/** Drives one session through turn and step boundaries on Kimi Code. */
|
|
23
|
+
export declare class KimiAgent implements Agent {
|
|
24
|
+
private loopCtx;
|
|
25
|
+
readonly id: SessionId;
|
|
26
|
+
readonly options: AgentOptions;
|
|
27
|
+
readonly session: Session;
|
|
28
|
+
private readonly config;
|
|
29
|
+
private readonly spawn;
|
|
30
|
+
private readonly bin;
|
|
31
|
+
readonly inbox: Inbox;
|
|
32
|
+
private phase;
|
|
33
|
+
private activityDone;
|
|
34
|
+
/** The agent-scoped registration boundary; the lifecycle owner unwinds it after the driver exits. */
|
|
35
|
+
readonly scope: Scope;
|
|
36
|
+
readonly ctx: Context;
|
|
37
|
+
/** Fused dispatcher, built once in the constructor so hot-path dispatches never allocate. */
|
|
38
|
+
private readonly dispatch;
|
|
39
|
+
/** Whether this loop instance has appended its initial/resume request anchor. */
|
|
40
|
+
private requestHeaderLogged;
|
|
41
|
+
/** Lazily created ACP client, reused across steps and released on scope teardown. */
|
|
42
|
+
private acp;
|
|
43
|
+
/** The spawn spec the cached client was built from; a change forces a respawn. */
|
|
44
|
+
private lastSpec;
|
|
45
|
+
constructor(loopCtx: Context, id: SessionId, options: AgentOptions, session: Session, config: ResolvedConfig, spawn: KimiSpawnCapability, bin: string);
|
|
46
|
+
get status(): AgentStatus;
|
|
47
|
+
/** Commit a phase and publish its externally visible status transition. */
|
|
48
|
+
private setPhase;
|
|
49
|
+
send(message: UserMessage, target: InboxTarget, wakeup: boolean): void;
|
|
50
|
+
/**
|
|
51
|
+
* Queue a message for the next turn and wake the driver.
|
|
52
|
+
* @param input - the user message to deliver.
|
|
53
|
+
*/
|
|
54
|
+
followup(input: UserMessage): void;
|
|
55
|
+
/**
|
|
56
|
+
* Queue a message for the running step and wake the driver.
|
|
57
|
+
* @param input - the user message to deliver.
|
|
58
|
+
*/
|
|
59
|
+
steer(input: UserMessage): void;
|
|
60
|
+
/**
|
|
61
|
+
* Queue a message for the running step without waking the driver.
|
|
62
|
+
* @param input - the user message to deliver.
|
|
63
|
+
*/
|
|
64
|
+
inject(input: UserMessage): void;
|
|
65
|
+
cancel(cause: AgentCancelCause, options?: CancelOptions): void;
|
|
66
|
+
/**
|
|
67
|
+
* Run a maintenance job while the agent is idle.
|
|
68
|
+
* @param job - the maintenance operation, receiving the phase abort signal.
|
|
69
|
+
* @returns the maintenance result.
|
|
70
|
+
*/
|
|
71
|
+
runMaintenance<T>(job: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Start one driver, or latch its wake behind maintenance or an aborted
|
|
74
|
+
* activity. A wake sent while idle always opens its turn boundary, even
|
|
75
|
+
* when its message was cleared; only a latched replay is suppressed when
|
|
76
|
+
* the queue no longer holds the wake.
|
|
77
|
+
* @param wakeAfterAbort - the {@link send} classification, captured before
|
|
78
|
+
* the inbox insertion so a reentrant cancel cannot reclassify it.
|
|
79
|
+
*/
|
|
80
|
+
private wakeDriver;
|
|
81
|
+
whenIdle(): Promise<void>;
|
|
82
|
+
/** Report one failure at its live boundary, then preserve it for driver containment. */
|
|
83
|
+
private throwError;
|
|
84
|
+
private kick;
|
|
85
|
+
private preStep;
|
|
86
|
+
/**
|
|
87
|
+
* Scan the step's user messages for `/name` skill gestures, load each
|
|
88
|
+
* matching skill, and inject the rendered skill content into the message
|
|
89
|
+
* batch. This mirrors what dsh-tool-skill does for the in-process engine.
|
|
90
|
+
* @param messages - the current step's message batch.
|
|
91
|
+
* @param signal - cancellation signal (aborted loads are silently dropped).
|
|
92
|
+
* @returns the original batch when no skill was invoked, or an extended
|
|
93
|
+
* batch with injected skill-content messages appended.
|
|
94
|
+
*/
|
|
95
|
+
private injectSkills;
|
|
96
|
+
/** Open one turn before claiming its first proposed step. */
|
|
97
|
+
private turn;
|
|
98
|
+
/** Model label recorded in the request header for one lifecycle. */
|
|
99
|
+
private modelLabel;
|
|
100
|
+
/** Append the request header snapshot once per loop instance. */
|
|
101
|
+
private assertRequestHeader;
|
|
102
|
+
/** Whether two spawn specs describe the same `kimi acp` child. */
|
|
103
|
+
private specsEqual;
|
|
104
|
+
/** Return the cached ACP client, respawning when the spec or process changed. */
|
|
105
|
+
private acpClient;
|
|
106
|
+
/** Build the `kimi acp` argv/cwd/env for the persistent child. */
|
|
107
|
+
private spawnSpec;
|
|
108
|
+
/** Run one `kimi acp` step for the current session history and map the streamed updates. */
|
|
109
|
+
private step;
|
|
110
|
+
/** Per-step accumulation state for streamed assistant blocks and tool calls. */
|
|
111
|
+
private blocks;
|
|
112
|
+
private emittedToolCalls;
|
|
113
|
+
private toolText;
|
|
114
|
+
private blockRef;
|
|
115
|
+
private ensureBlock;
|
|
116
|
+
/** Append one streamed update's durable effect for the current step. */
|
|
117
|
+
private applyUpdate;
|
|
118
|
+
/** Append one live chunk and return its durable seq. */
|
|
119
|
+
private appendChunk;
|
|
120
|
+
/** Flush the accumulated assistant blocks into one durable assistant/message. */
|
|
121
|
+
private flushAssistant;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi Code slash-command bridge.
|
|
3
|
+
*
|
|
4
|
+
* The dsh `commands` runtime executes a registered command locally — the line is
|
|
5
|
+
* consumed and never reaches the model — so a command whose real processing
|
|
6
|
+
* lives inside the Kimi engine must forward the raw line back to the agent, which
|
|
7
|
+
* Kimi then expands (as far as the ACP prompt surface supports). Registering the
|
|
8
|
+
* built-ins keeps them visible in the dsh web slash menu; unregistered `/lines`
|
|
9
|
+
* pass through as user text, but the menu would hide the engine's command
|
|
10
|
+
* surface.
|
|
11
|
+
*
|
|
12
|
+
* Kimi's slash commands are chiefly TUI controls (`/login`, `/provider`,
|
|
13
|
+
* `/settings`, `/sessions`, `/tasks`, …) that the ACP prompt surface does not
|
|
14
|
+
* expand the way an interactive TUI does; this bridge therefore registers the
|
|
15
|
+
* subset that are meaningful to forward to the engine (session/mode/status and
|
|
16
|
+
* the goal form). `skill:` commands are already carried by the dsh skill
|
|
17
|
+
* injection seam and Kimi's own shorthand, so they are not duplicated here.
|
|
18
|
+
*
|
|
19
|
+
* `model` is deliberately absent even though the CLI has it: the dsh web
|
|
20
|
+
* client owns a `/model` contribution, and a same-named host command makes
|
|
21
|
+
* `ui-commands` throw the whole command menu source away, leaving only the
|
|
22
|
+
* skill group. `/goal` stays: the managed block disables dsh's `command-goal`
|
|
23
|
+
* row for hosted engines, so the slot is free and the CLI's own goal mode
|
|
24
|
+
* takes it over.
|
|
25
|
+
*
|
|
26
|
+
* @module dsh-loop-engine/engine-kimi/commands
|
|
27
|
+
*/
|
|
28
|
+
import type { CommandDefinition, CommandInvocation, CommandResult } from '../commands.ts';
|
|
29
|
+
/**
|
|
30
|
+
* Build the forwarding handler for one Kimi slash command: it re-delivers the
|
|
31
|
+
* full `/<name> [args]` line to the receiving agent as a plain user message,
|
|
32
|
+
* where the engine expands it. `rawInput` already carries the separator
|
|
33
|
+
* whitespace and any arguments.
|
|
34
|
+
* @param name - the command name without the leading slash.
|
|
35
|
+
* @returns the command handler.
|
|
36
|
+
*/
|
|
37
|
+
export declare function forwardKimiCommand(name: string): (invocation: CommandInvocation) => CommandResult;
|
|
38
|
+
/** Kimi Code's built-in slash commands that make sense to forward to the engine. */
|
|
39
|
+
export declare const KIMI_COMMANDS: readonly CommandDefinition[];
|
|
40
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi Code loop engine module: hosts the AgentFactory that drives every
|
|
3
|
+
* session through a persistent `kimi acp` child (Agent Client Protocol over
|
|
4
|
+
* stdio), speaking one stateless `session/new` + `session/prompt` per dsh step,
|
|
5
|
+
* with the durable session log as the sole source of model context.
|
|
6
|
+
* dsh-loop-engine constructs this factory when the Kimi engine is selected; this
|
|
7
|
+
* module is a library, not a Cordis plugin entry. Kimi has no host approval
|
|
8
|
+
* callback, so tool approvals surfaced by ACP (`session/request_permission`) are
|
|
9
|
+
* answered from the session's dsh approval knobs (an `ask` policy degrades to
|
|
10
|
+
* denial); the whole child is spawned through the dsh subprocess seam — the only
|
|
11
|
+
* available privilege boundary — and the sandbox stance follows the session's
|
|
12
|
+
* durable permission knobs as the subprocess provider resolves them (default
|
|
13
|
+
* read-only).
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-loop-engine/engine-kimi
|
|
16
|
+
*/
|
|
17
|
+
import { Service } from '@deepseek-ai/cordis';
|
|
18
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
19
|
+
import z from '@deepseek-ai/schemastery';
|
|
20
|
+
import type { AgentFactory, AgentHandle, CreateAgentOptions, ResumeAgentOptions } from '@deepseek-ai/dsh-agent';
|
|
21
|
+
import type { KimiSpawnCapability } from './process.ts';
|
|
22
|
+
import type { ResolvedConfig } from './types.ts';
|
|
23
|
+
/** Grace in milliseconds for Kimi process-tree termination. */
|
|
24
|
+
export declare const KIMI_DISPOSE_GRACE_MS = 3000;
|
|
25
|
+
/** Deployment-owned configuration for the Kimi loop plugin. */
|
|
26
|
+
export interface Config {
|
|
27
|
+
/** Model alias for the `kimi` child (`-m`); Kimi native config owns the model when omitted. */
|
|
28
|
+
model?: string;
|
|
29
|
+
/** Explicit environment entries passed to the `kimi` child. */
|
|
30
|
+
env?: Record<string, string>;
|
|
31
|
+
/** Kimi CLI executable; `'kimi'` resolves through PATH when not pinned to an absolute path. */
|
|
32
|
+
bin?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Schema of the Kimi loop plugin configuration. */
|
|
35
|
+
export declare const Config: z<Config>;
|
|
36
|
+
/** Host-face ctx key for the Kimi loop service. */
|
|
37
|
+
declare module '@deepseek-ai/cordis' {
|
|
38
|
+
interface Context {
|
|
39
|
+
agentLoopKimi: KimiLoop;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Concrete AgentFactory and driver service of the Kimi loop. Creation and
|
|
44
|
+
* resume follow the registry factory contract and the shared publication
|
|
45
|
+
* transaction: prepare, run setup, then publish through both registries,
|
|
46
|
+
* announce, and emit `agent/session-start`.
|
|
47
|
+
*/
|
|
48
|
+
export declare class KimiLoop extends Service implements AgentFactory {
|
|
49
|
+
/** Services the loop resolves through its own fiber; blessed identically to the package-level entry inject. */
|
|
50
|
+
static inject: string[];
|
|
51
|
+
/** Validated configuration owned by the loop plugin. */
|
|
52
|
+
readonly config: ResolvedConfig;
|
|
53
|
+
private readonly ownership;
|
|
54
|
+
/** Plain holder prevents Cordis from re-tracing the factory's dependency context through a caller shadow. */
|
|
55
|
+
private readonly runtime;
|
|
56
|
+
/** One-shot spawn capability handed to every agent, sandboxed by the subprocess seam. */
|
|
57
|
+
readonly spawn: KimiSpawnCapability;
|
|
58
|
+
constructor(ctx: Context, config: Config);
|
|
59
|
+
/**
|
|
60
|
+
* Construct the driver, scope, and one memoized reverse teardown for a new
|
|
61
|
+
* agent. The teardown is registered with the factory and the owner fiber
|
|
62
|
+
* BEFORE publication, so a mid-setup unload rolls everything back; `signal`
|
|
63
|
+
* fuses caller cancellation with lifecycle teardown for setup awaits.
|
|
64
|
+
*/
|
|
65
|
+
private prepare;
|
|
66
|
+
/** Prepare one Agent around an acquired Session, run setup, and publish it. */
|
|
67
|
+
private setupAndPublish;
|
|
68
|
+
/**
|
|
69
|
+
* Create an agent and session under one caller-supplied identity, owned by
|
|
70
|
+
* the accessing fiber. When a persistence backend is mounted, the session's
|
|
71
|
+
* durable identity is stored before publication.
|
|
72
|
+
* @param ownerCtx - caller context that structurally owns the lifecycle.
|
|
73
|
+
* @param options - identities, session seed/metadata, loop options, setup, and cancellation.
|
|
74
|
+
* @returns the published handle.
|
|
75
|
+
*/
|
|
76
|
+
createAgent(ownerCtx: Context, options: CreateAgentOptions): Promise<AgentHandle>;
|
|
77
|
+
/**
|
|
78
|
+
* Take a fresh session's write ownership when persistence is mounted.
|
|
79
|
+
* Nothing is appended here: the constructor seed (which never re-emits
|
|
80
|
+
* through `session/event`) is stored by {@link appendUnstoredSuffix} at the
|
|
81
|
+
* publication commit point, so a failed or cancelled setup closes an
|
|
82
|
+
* unmaterialized handle and leaves no stored residue — the same id can be
|
|
83
|
+
* created again.
|
|
84
|
+
* @param session - the unpublished session to store.
|
|
85
|
+
* @param signal - optional cancellation forwarded to the backend create.
|
|
86
|
+
* @returns the owned handle and stored cursor, or `undefined` without a backend.
|
|
87
|
+
*/
|
|
88
|
+
private createStoredSession;
|
|
89
|
+
/**
|
|
90
|
+
* Durably store the session events appended since the last stored cursor.
|
|
91
|
+
* Pre-publication appends (constructor seed markers, setup-window events)
|
|
92
|
+
* never re-emit through `session/event`, so publication must flush them
|
|
93
|
+
* through the handle before live events start routing into it.
|
|
94
|
+
* @param stored - the session's owned handle and stored cursor, if any.
|
|
95
|
+
* @param session - the unpublished session whose suffix is stored.
|
|
96
|
+
*/
|
|
97
|
+
private appendUnstoredSuffix;
|
|
98
|
+
/**
|
|
99
|
+
* Resume an owned agent from the configured persistence service.
|
|
100
|
+
* @param ownerCtx - caller context that owns load, setup, and the live lifecycle.
|
|
101
|
+
* @param options - persisted identity, loop options, setup, and cancellation.
|
|
102
|
+
* @returns the published handle.
|
|
103
|
+
*/
|
|
104
|
+
resume(ownerCtx: Context, options: ResumeAgentOptions): Promise<AgentHandle>;
|
|
105
|
+
/** Resume through an explicit persistence service. */
|
|
106
|
+
private resumeWith;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=loop.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping from Kimi Code `--output-format stream-json` records to dsh
|
|
3
|
+
* session-log events. Kimi emits one JSON object per stdout line, discriminated
|
|
4
|
+
* by a `role` field (verified against the 0.28.1 CLI):
|
|
5
|
+
* - `{ "role": "assistant", "content": "<text>" }`
|
|
6
|
+
* - `{ "role": "assistant", "tool_calls": [{ "type": "function",
|
|
7
|
+
* "id": "call_…", "function": { "name": "Bash", "arguments": "<json>" } }] }`
|
|
8
|
+
* - `{ "role": "tool", "tool_call_id": "call_…", "content": "<text>" }`
|
|
9
|
+
* - `{ "role": "meta", "type": "session.resume_hint", … }` (discarded)
|
|
10
|
+
* Thinking and tool progress go to stderr, never the JSONL, so this module has no
|
|
11
|
+
* usage or reasoning projection. The module is pure: it parses a raw stdout
|
|
12
|
+
* buffer and returns plain record projections the agent folds into the log.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-loop-engine/engine-kimi/mapping
|
|
15
|
+
*/
|
|
16
|
+
import type { ToolResultMessage } from '@deepseek-ai/dsh-llm';
|
|
17
|
+
/** One normalized Kimi tool-call record. */
|
|
18
|
+
export interface KimiToolCall {
|
|
19
|
+
/** The tool invocation id (`call_…`), correlated with the later `tool` record. */
|
|
20
|
+
readonly id: string;
|
|
21
|
+
/** The tool name. */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/** The raw arguments JSON string, passed verbatim. */
|
|
24
|
+
readonly arguments: string;
|
|
25
|
+
}
|
|
26
|
+
/** One parsed Kimi stream-json record (partial, tolerant of unknown fields). */
|
|
27
|
+
export interface KimiRecord {
|
|
28
|
+
readonly role?: unknown;
|
|
29
|
+
readonly type?: unknown;
|
|
30
|
+
readonly content?: unknown;
|
|
31
|
+
readonly tool_calls?: unknown;
|
|
32
|
+
readonly tool_call_id?: unknown;
|
|
33
|
+
readonly is_error?: unknown;
|
|
34
|
+
readonly isError?: unknown;
|
|
35
|
+
readonly error?: unknown;
|
|
36
|
+
}
|
|
37
|
+
/** Record role discriminant used by the step loop. */
|
|
38
|
+
export type KimiRecordRole = 'assistant' | 'tool' | 'meta' | 'unknown';
|
|
39
|
+
/**
|
|
40
|
+
* Parse a `kimi --output-format stream-json` stdout buffer into records.
|
|
41
|
+
* Lines are bare-`\n` delimited; blank lines and non-JSON lines are dropped.
|
|
42
|
+
* @param stdout - the child's full stdout text.
|
|
43
|
+
* @returns the parsed records, in order.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseKimiRecords(stdout: string): KimiRecord[];
|
|
46
|
+
/** Classify one record's role. */
|
|
47
|
+
export declare function roleOf(record: KimiRecord): KimiRecordRole;
|
|
48
|
+
/**
|
|
49
|
+
* The joined text of one record's `content` field. Handles both the string
|
|
50
|
+
* form (`"content": "<text>"`) and an array form (`[{ "type": "text", "text": … }]`)
|
|
51
|
+
* defensively; any other shape renders empty.
|
|
52
|
+
* @param record - the parsed record.
|
|
53
|
+
* @returns the joined body text.
|
|
54
|
+
*/
|
|
55
|
+
export declare function recordContentText(record: KimiRecord): string;
|
|
56
|
+
/**
|
|
57
|
+
* Normalize an assistant record's `tool_calls` array. Each entry keeps its id,
|
|
58
|
+
* name, and a verbatim argument string (the wire already serializes arguments
|
|
59
|
+
* as JSON text; absent args render `{}`).
|
|
60
|
+
* @param record - the parsed assistant record.
|
|
61
|
+
* @returns the normalized tool calls, in order.
|
|
62
|
+
*/
|
|
63
|
+
export declare function assistantToolCalls(record: KimiRecord): readonly KimiToolCall[];
|
|
64
|
+
/**
|
|
65
|
+
* Surface a `tool` record as a durable tool-result message, or `undefined` when
|
|
66
|
+
* the record is not a correlatable tool result (missing `role: tool` or no id).
|
|
67
|
+
* @param record - the parsed record.
|
|
68
|
+
* @returns the dsh tool-result message, or `undefined`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function toolResultMessage(record: KimiRecord): ToolResultMessage | undefined;
|
|
71
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-approval mapping for the `kimi acp` driver.
|
|
3
|
+
*
|
|
4
|
+
* Kimi's ACP adapter surfaces tool/permission decisions as the reverse-RPC
|
|
5
|
+
* `session/request_permission`, which the client must answer. The dsh harness
|
|
6
|
+
* has no interactive approval callback in the unattended runtime, so the fold
|
|
7
|
+
* mirrors the codex/Pi bridges: an `ask` approval policy degrades to a denial
|
|
8
|
+
* (the only safe answer when no human is present), and anything else
|
|
9
|
+
* (`never`, or knob-less) auto-approves the tool. A full-access sandbox mode
|
|
10
|
+
* also auto-approves; a `workspace-write` stance is still auto-approved here
|
|
11
|
+
* because Kimi's own permission gating (`--permission`/session policy) is what
|
|
12
|
+
* bounds the tool — the ACP approval is the host's gate, and the dsh
|
|
13
|
+
* `approval/policy` knob is its signal.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-loop-engine/engine-kimi/permission
|
|
16
|
+
*/
|
|
17
|
+
import type { PermissionEvent } from '../driver-core/permission-knobs.ts';
|
|
18
|
+
/**
|
|
19
|
+
* Whether the driver should answer `session/request_permission` with approval for
|
|
20
|
+
* one query. An `ask` policy denies (fail-closed — no human is present in the
|
|
21
|
+
* unattended runtime); anything else (`never`, or knob-less) auto-approves. The
|
|
22
|
+
* sandbox stance is not consulted: Kimi's own tool policy bounds what a tool does,
|
|
23
|
+
* and the ACP approval is the host's gate, signalled by `approval/policy`.
|
|
24
|
+
* @param events - the durable session log.
|
|
25
|
+
* @returns whether tool requests are approved.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveToolApproval(events: readonly PermissionEvent[]): boolean;
|
|
28
|
+
//# sourceMappingURL=permission.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi CLI process projection. The driver locates the `kimi` executable, builds
|
|
3
|
+
* the `-p --output-format stream-json` argv for one step, and projects the dsh
|
|
4
|
+
* subprocess seam handle onto a minimal transport the agent can read to
|
|
5
|
+
* completion. Kimi has no host permission callback and no `--tools` pruning
|
|
6
|
+
* flag in `-p` mode, so the whole child is spawned through the seam — the only
|
|
7
|
+
* available privilege boundary (the seam's OS sandbox, default read-only) — and
|
|
8
|
+
* every step is a fresh one-shot child because `-p` is inherently stateless.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-loop-engine/engine-kimi/process
|
|
11
|
+
*/
|
|
12
|
+
import type { Readable, Writable } from 'node:stream';
|
|
13
|
+
import type { SubprocessHandle, SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess';
|
|
14
|
+
/** The exact argv/cwd/env the driver requests for one `kimi -p` child. */
|
|
15
|
+
export interface KimiSpawnSpec {
|
|
16
|
+
/** The program plus its flags; `argv[0]` is the Kimi CLI executable. */
|
|
17
|
+
readonly argv: readonly string[];
|
|
18
|
+
readonly cwd: string;
|
|
19
|
+
readonly env: Record<string, string>;
|
|
20
|
+
/** Cancellation: the seam escalates process-tree termination when it fires. */
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
/** A spawned Kimi process as the agent's transport needs it. */
|
|
24
|
+
export interface KimiProcess {
|
|
25
|
+
/** Child stdin (JSON-RPC request frames). */
|
|
26
|
+
readonly stdin: Writable;
|
|
27
|
+
/** Child stdout (the `session/update` notification frames). */
|
|
28
|
+
readonly stdout: Readable;
|
|
29
|
+
/** Child stderr (diagnostics; drained and dropped). */
|
|
30
|
+
readonly stderr: Readable;
|
|
31
|
+
/** Resolves when the child closes. */
|
|
32
|
+
readonly done: Promise<unknown>;
|
|
33
|
+
/** Request process-tree termination. */
|
|
34
|
+
terminate(): void;
|
|
35
|
+
}
|
|
36
|
+
/** Spawns one Kimi child over the given spec (the driver's spawn capability). */
|
|
37
|
+
export type KimiSpawnCapability = (spec: KimiSpawnSpec) => KimiProcess;
|
|
38
|
+
/** Resolve the Kimi home directory from `KIMI_CODE_HOME` or the current user's home. */
|
|
39
|
+
export declare function kimiHomeDir(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the Kimi CLI executable. An explicit config path wins; otherwise this
|
|
42
|
+
* probes the standard `<kimi home>/bin/kimi[.exe]` location and falls back to
|
|
43
|
+
* `'kimi'` (resolved through PATH by the spawner).
|
|
44
|
+
* @param configBin - an operator-pinned absolute path (or `'kimi'`), if any.
|
|
45
|
+
* @returns the executable to spawn as `argv[0]`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function kimiBinResolver(configBin?: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Build the persistent `kimi acp` argv. The ACP child stays alive across steps
|
|
50
|
+
* and is spoken to over JSON-RPC on stdio — the prompt is a request body, not an
|
|
51
|
+
* argv positional — so there is no command-line length ceiling and no model flag
|
|
52
|
+
* (Kimi owns model selection natively via its own config).
|
|
53
|
+
* @param bin - the Kimi executable.
|
|
54
|
+
* @returns the argv, `argv[0]` being the executable.
|
|
55
|
+
*/
|
|
56
|
+
export declare function kimiAcpArgv(bin: string): string[];
|
|
57
|
+
/** Project the driver's spawn request onto the dsh subprocess seam. */
|
|
58
|
+
export declare function kimiSubprocessSpec(spec: KimiSpawnSpec, graceMs: number): SubprocessSpawnSpec;
|
|
59
|
+
/** Project a dsh subprocess handle onto the Kimi process transport. */
|
|
60
|
+
export declare function fromSubprocess(handle: SubprocessHandle): KimiProcess;
|
|
61
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi Code skill provider: exposes the Kimi CLI's instruction files and skills
|
|
3
|
+
* as DSH skills.
|
|
4
|
+
*
|
|
5
|
+
* Kimi reads per-directory `AGENTS.md` files from the session cwd up to the git
|
|
6
|
+
* root, and installs skills from `skills/` directories — the user-level
|
|
7
|
+
* `$KIMI_CODE_HOME/skills/` (default `~/.kimi-code/skills/`) and the
|
|
8
|
+
* project-level `.kimi-code/skills/` (walking up to the git root). Each
|
|
9
|
+
* context-file set is surfaced as one user-invocable `agents-md` skill whose
|
|
10
|
+
* body is the concatenated file contents; every found `SKILL.md` catalog entry
|
|
11
|
+
* is surfaced under its own name, so the dsh skill-injection seam (`/name`
|
|
12
|
+
* gestures) can carry them into the prompt.
|
|
13
|
+
*
|
|
14
|
+
* The generic `~/.agents/skills/` and `.agents/skills/` roots are deliberately
|
|
15
|
+
* not scanned here: dsh's own `skill-filesystem` provider already exposes them
|
|
16
|
+
* through the same registry in the web profile. Kimi built-in Skills are
|
|
17
|
+
* shipped inside the CLI and cannot be read from a stable on-disk location, so
|
|
18
|
+
* the filesystem subset above is authoritative for the web menu. Note the
|
|
19
|
+
* shared {@link parseSkillFile} mirrors the agents-skill frontmatter
|
|
20
|
+
* (`name`/`description`/`whenToUse`/`disable-model-invocation`); Kimi's own
|
|
21
|
+
* `disableModelInvocation`/`type` fields are not translated, so a `type: flow`
|
|
22
|
+
* skill is surfaced as model-invocable.
|
|
23
|
+
*
|
|
24
|
+
* @module dsh-loop-engine/engine-kimi/skills
|
|
25
|
+
*/
|
|
26
|
+
import type { SkillCandidate, SkillDefinition, SkillLookupOptions, SkillProvider, SkillProviderControl } from '../skills.ts';
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the Kimi config directory, honoring the `KIMI_CODE_HOME` environment
|
|
29
|
+
* override and falling back to `~/.kimi-code`.
|
|
30
|
+
* @returns the absolute Kimi config directory.
|
|
31
|
+
*/
|
|
32
|
+
export declare function kimiAgentDir(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Skill provider that discovers context files and skills from Kimi's standard
|
|
35
|
+
* locations:
|
|
36
|
+
* - project `AGENTS.md` files between the cwd and the git root — surfaced as
|
|
37
|
+
* one `agents-md` skill;
|
|
38
|
+
* - project `.kimi-code/skills/` and user `~/.kimi-code/skills/` — each
|
|
39
|
+
* `SKILL.md` entry surfaced under its own name.
|
|
40
|
+
*/
|
|
41
|
+
export declare class KimiSkillProvider implements SkillProvider {
|
|
42
|
+
private readonly control;
|
|
43
|
+
readonly name = "kimi";
|
|
44
|
+
constructor(control: SkillProviderControl);
|
|
45
|
+
list(options: SkillLookupOptions): Promise<readonly SkillCandidate[]>;
|
|
46
|
+
get(candidate: SkillCandidate, _options: SkillLookupOptions): Promise<SkillDefinition | undefined>;
|
|
47
|
+
/** One merged `agents-md` candidate for a ranked file set. */
|
|
48
|
+
private agentsCandidate;
|
|
49
|
+
/** Collect every skill in one skills directory, both kimi layouts. */
|
|
50
|
+
private collectSkillsDir;
|
|
51
|
+
/** One parsed skill as a ranked candidate. */
|
|
52
|
+
private skillCandidate;
|
|
53
|
+
/** Parse one SKILL.md file, or `undefined` when it is unreadable or invalid. */
|
|
54
|
+
private tryParse;
|
|
55
|
+
}
|
|
56
|
+
export default KimiSkillProvider;
|
|
57
|
+
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types of the Kimi Code loop driver. Types only — no runtime code.
|
|
3
|
+
*
|
|
4
|
+
* Kimi Code (`kimi`) has no host approval callback ("runs with the permissions
|
|
5
|
+
* of the user"), and its non-interactive `-p` surface already auto-approves tool
|
|
6
|
+
* calls. It also exposes no `--tools` pruning flag in `-p` mode, so there is no
|
|
7
|
+
* per-driver permission lever to pin. The driver therefore spawns the whole
|
|
8
|
+
* `kimi -p` child through the dsh subprocess seam — the only available privilege
|
|
9
|
+
* boundary — and the sandbox stance follows the session's durable permission
|
|
10
|
+
* knobs as the subprocess provider resolves them (default read-only).
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-loop-engine/engine-kimi/types
|
|
13
|
+
*/
|
|
14
|
+
/** Driver configuration after defaults and load-time validation. */
|
|
15
|
+
export interface ResolvedConfig {
|
|
16
|
+
/** Model alias the `kimi` child is launched with (`--model`); Kimi native config owns the model when omitted. */
|
|
17
|
+
readonly model: string | undefined;
|
|
18
|
+
/** Explicit environment entries layered over the credential-scrubbed parent environment. */
|
|
19
|
+
readonly env: Record<string, string>;
|
|
20
|
+
/** Kimi CLI executable; `'kimi'` resolves through PATH when not pinned to an absolute path. */
|
|
21
|
+
readonly bin: string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|