dsh-loop-engine 1.0.0-rc6 → 1.0.0-rc8

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.
Files changed (36) hide show
  1. package/README.md +43 -3
  2. package/README.zh.md +4 -3
  3. package/lib/client.js +82 -19
  4. package/lib/index.js +2249 -460
  5. package/lib/invariant.js +4 -3
  6. package/lib/types/client/LoopEngineBadge.d.ts +1 -1
  7. package/lib/types/client/LoopEngineComposerSelect.d.ts +1 -1
  8. package/lib/types/client/LoopEngineSection.d.ts +1 -1
  9. package/lib/types/client/index.d.ts +1 -1
  10. package/lib/types/client/locales.d.ts +4 -0
  11. package/lib/types/client/store.d.ts +2 -1
  12. package/lib/types/engine-claude/agent.d.ts +2 -0
  13. package/lib/types/engine-claude/loop.d.ts +24 -2
  14. package/lib/types/engine-claude/mapping.d.ts +3 -3
  15. package/lib/types/engine-codex/agent.d.ts +2 -0
  16. package/lib/types/engine-codex/appserver/mapping.d.ts +4 -4
  17. package/lib/types/engine-codex/loop.d.ts +24 -2
  18. package/lib/types/engine-kimi/acp/client.d.ts +76 -0
  19. package/lib/types/engine-kimi/acp/mapping.d.ts +44 -0
  20. package/lib/types/engine-kimi/acp/types.d.ts +95 -0
  21. package/lib/types/engine-kimi/agent.d.ts +123 -0
  22. package/lib/types/engine-kimi/commands.d.ts +40 -0
  23. package/lib/types/engine-kimi/loop.d.ts +108 -0
  24. package/lib/types/engine-kimi/mapping.d.ts +71 -0
  25. package/lib/types/engine-kimi/permission.d.ts +28 -0
  26. package/lib/types/engine-kimi/process.d.ts +61 -0
  27. package/lib/types/engine-kimi/skills.d.ts +57 -0
  28. package/lib/types/engine-kimi/types.d.ts +23 -0
  29. package/lib/types/engine-pi/agent.d.ts +2 -0
  30. package/lib/types/engine-pi/loop.d.ts +24 -2
  31. package/lib/types/index.d.ts +20 -2
  32. package/lib/types/patch-manager.d.ts +9 -0
  33. package/lib/types/preset.d.ts +73 -0
  34. package/lib/types/provider-route.d.ts +35 -0
  35. package/lib/types/settings.d.ts +6 -6
  36. package/package.json +24 -24
package/lib/invariant.js CHANGED
@@ -1,9 +1,8 @@
1
1
  // src/settings.ts
2
2
  import z from "@deepseek-ai/schemastery";
3
- import { settingsNamespace } from "@deepseek-ai/dsh-settings";
4
- var LOOP_ENGINE_IDS = ["in-process", "claude-code", "codex", "pi"];
3
+ var LOOP_ENGINE_IDS = ["in-process", "claude-code", "codex", "pi", "kimi"];
5
4
  var LOOP_ENGINE_SETTINGS_SCHEMA = z.object({
6
- engine: z.union([z.const("in-process"), z.const("claude-code"), z.const("codex"), z.const("pi")]).default("in-process"),
5
+ engine: z.union([z.const("in-process"), z.const("claude-code"), z.const("codex"), z.const("pi"), z.const("kimi")]).default("in-process"),
7
6
  showInComposer: z.boolean().default(true)
8
7
  });
9
8
 
@@ -18,6 +17,8 @@ function renderManagedBlock(engine) {
18
17
  `${MANAGED_BLOCK_BEGIN}${engine} --`,
19
18
  "- id: agent-loop",
20
19
  " disabled: true",
20
+ "- id: command-goal",
21
+ " disabled: true",
21
22
  END_MARKER_LINE
22
23
  ].join("\n");
23
24
  }
@@ -9,7 +9,7 @@
9
9
  * @module dsh-loop-engine/client/badge
10
10
  */
11
11
  import type { JSX } from 'react';
12
- import type { SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client';
12
+ import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
13
13
  import type { InjectFace } from '@deepseek-ai/dsh-client-ui-slots';
14
14
  import type { LoopEngineState } from './store.ts';
15
15
  import type { en } from './locales.ts';
@@ -13,7 +13,7 @@
13
13
  * @module dsh-loop-engine/client/composer
14
14
  */
15
15
  import { type JSX } from 'react';
16
- import type { SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client';
16
+ import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
17
17
  import type { InjectFace } from '@deepseek-ai/dsh-client-ui-slots';
18
18
  import type { LoopEngineStore, LoopEngineState } from './store.ts';
19
19
  import type { en } from './locales.ts';
@@ -12,7 +12,7 @@
12
12
  * @module dsh-loop-engine/client
13
13
  */
14
14
  import { type JSX } from 'react';
15
- import type { SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client';
15
+ import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
16
16
  import type { InjectFace } from '@deepseek-ai/dsh-client-ui-slots';
17
17
  import type { LoopEngineStore, LoopEngineState } from './store.ts';
18
18
  import type { en } from './locales.ts';
@@ -5,7 +5,7 @@
5
5
  * Export discipline: packages/client/AGENTS.md.
6
6
  * @module dsh-loop-engine/client
7
7
  */
8
- import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client';
8
+ import type { Context as ClientContext } from '@deepseek-ai/cordis';
9
9
  import { type LoopEngineKey } from './locales.ts';
10
10
  export type { LoopEngineSectionInjected, LoopEngineSectionProps } from './LoopEngineSection.tsx';
11
11
  export type { LoopEngineBadgeInjected, LoopEngineBadgeProps } from './LoopEngineBadge.tsx';
@@ -16,6 +16,8 @@ export interface LoopEngineKey {
16
16
  engineCodex: string;
17
17
  /** Option label: the Pi CLI driver. */
18
18
  enginePi: string;
19
+ /** Option label: the Kimi Code CLI driver. */
20
+ engineKimi: string;
19
21
  /** Settings toggle: show the engine picker in the chat page composer. */
20
22
  showInComposerLabel: string;
21
23
  /** Unavailable-state message. */
@@ -32,6 +34,8 @@ export interface LoopEngineKey {
32
34
  confirmAction: string;
33
35
  /** Cancel action label. */
34
36
  cancelAction: string;
37
+ /** Accessible close-button label of the confirmation dialog. */
38
+ closeLabel: string;
35
39
  /** Notice shown while the Claude Code engine owns the slot: model selection is native. */
36
40
  claudeModelNotice: string;
37
41
  }
@@ -3,7 +3,8 @@
3
3
  * and the store publishes a render-safe snapshot plus the write path.
4
4
  * @module dsh-loop-engine/client/store
5
5
  */
6
- import type { SettingsScope, SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client';
6
+ import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client';
7
+ import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
7
8
  import type { LoopEngineId } from '../settings.ts';
8
9
  /** State rendered by the loop engine section. */
9
10
  export interface LoopEngineState {
@@ -12,6 +12,8 @@ import type { Scope } from '@deepseek-ai/dsh-scope';
12
12
  import type { Session, SessionId, UserMessage } from '@deepseek-ai/dsh-session';
13
13
  import type { Context } from '@deepseek-ai/cordis';
14
14
  import type { ResolvedConfig } from './types.ts';
15
+ /** Provider route label used for logged header snapshots and message provenance. */
16
+ export declare const PROVIDER = "claude-code";
15
17
  /** Drives one session through turn and step boundaries on Claude Code. */
16
18
  export declare class ClaudeCodeAgent implements Agent {
17
19
  private loopCtx;
@@ -70,12 +70,34 @@ export declare class ClaudeCodeLoop extends Service implements AgentFactory {
70
70
  private setupAndPublish;
71
71
  /**
72
72
  * Create an agent and session under one caller-supplied identity, owned by
73
- * the accessing fiber.
73
+ * the accessing fiber. When a persistence backend is mounted, the session's
74
+ * durable identity is stored before publication.
74
75
  * @param ownerCtx - caller context that structurally owns the lifecycle.
75
76
  * @param options - identities, session seed/metadata, loop options, setup, and cancellation.
76
77
  * @returns the published handle.
77
78
  */
78
79
  createAgent(ownerCtx: Context, options: CreateAgentOptions): Promise<AgentHandle>;
80
+ /**
81
+ * Take a fresh session's write ownership when persistence is mounted.
82
+ * Nothing is appended here: the constructor seed (which never re-emits
83
+ * through `session/event`) is stored by {@link appendUnstoredSuffix} at the
84
+ * publication commit point, so a failed or cancelled setup closes an
85
+ * unmaterialized handle and leaves no stored residue — the same id can be
86
+ * created again.
87
+ * @param session - the unpublished session to store.
88
+ * @param signal - optional cancellation forwarded to the backend create.
89
+ * @returns the owned handle and stored cursor, or `undefined` without a backend.
90
+ */
91
+ private createStoredSession;
92
+ /**
93
+ * Durably store the session events appended since the last stored cursor.
94
+ * Pre-publication appends (constructor seed markers, setup-window events)
95
+ * never re-emit through `session/event`, so publication must flush them
96
+ * through the handle before live events start routing into it.
97
+ * @param stored - the session's owned handle and stored cursor, if any.
98
+ * @param session - the unpublished session whose suffix is stored.
99
+ */
100
+ private appendUnstoredSuffix;
79
101
  /**
80
102
  * Resume an owned agent from the configured persistence service.
81
103
  * @param ownerCtx - caller context that owns load, setup, and the live lifecycle.
@@ -83,7 +105,7 @@ export declare class ClaudeCodeLoop extends Service implements AgentFactory {
83
105
  * @returns the published handle.
84
106
  */
85
107
  resume(ownerCtx: Context, options: ResumeAgentOptions): Promise<AgentHandle>;
86
- /** Resume through an explicit persistence handle. */
108
+ /** Resume through an explicit persistence service. */
87
109
  private resumeWith;
88
110
  }
89
111
  //# sourceMappingURL=loop.d.ts.map
@@ -8,11 +8,11 @@
8
8
  */
9
9
  import type { BetaMessage, BetaRawMessageStreamEvent, BetaUsage } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
10
10
  import type { MessageParam } from '@anthropic-ai/sdk/resources';
11
- import { CallId, type ContentBlock, type StreamChunk, type TokenUsage, type ToolResultMessage } from '@deepseek-ai/dsh-llm';
11
+ import { ToolCallId, type ContentBlock, type StreamChunk, type TokenUsage, type ToolResultMessage } from '@deepseek-ai/dsh-llm';
12
12
  /** One tool invocation surfaced from a Claude Code assistant message. */
13
13
  export interface MappedToolCall {
14
14
  /** SDK tool_use id, reused as the dsh call-id so results pair. */
15
- readonly callId: CallId;
15
+ readonly callId: ToolCallId;
16
16
  /** Tool name exactly as the SDK reported it. */
17
17
  readonly name: string;
18
18
  /** Raw JSON arguments string as the SDK produced them. */
@@ -63,7 +63,7 @@ export declare function mapToolResults(message: MessageParam): ToolResultMessage
63
63
  export declare function mapUsage(usage: BetaUsage): TokenUsage;
64
64
  /** Per-block-index tool-call identity captured at `content_block_start`, reused by `input_json_delta`. */
65
65
  export interface StreamToolCall {
66
- readonly callId: CallId;
66
+ readonly callId: ToolCallId;
67
67
  readonly name: string;
68
68
  }
69
69
  /**
@@ -17,6 +17,8 @@ import type { Scope } from '@deepseek-ai/dsh-scope';
17
17
  import type { Session, SessionId, UserMessage } from '@deepseek-ai/dsh-session';
18
18
  import type { Context } from '@deepseek-ai/cordis';
19
19
  import type { ResolvedConfig } from './types.ts';
20
+ /** Provider route label used for logged header snapshots and message provenance. */
21
+ export declare const PROVIDER = "codex";
20
22
  /** Drives one session through turn and step boundaries on Codex. */
21
23
  export declare class CodexAgent implements Agent {
22
24
  private loopCtx;
@@ -8,7 +8,7 @@
8
8
  * @module dsh-loop-engine/engine-codex/appserver/mapping
9
9
  */
10
10
  import type { TokenUsage, ToolResultMessage } from '@deepseek-ai/dsh-llm';
11
- import { CallId } from '@deepseek-ai/dsh-llm';
11
+ import { ToolCallId } from '@deepseek-ai/dsh-llm';
12
12
  /** Map app-server turn usage to dsh TokenUsage. */
13
13
  export declare function mapUsage(usage: {
14
14
  inputTokens: number;
@@ -25,7 +25,7 @@ export declare function mapCommandExecution(item: {
25
25
  status?: string;
26
26
  }): {
27
27
  call: {
28
- callId: CallId;
28
+ callId: ToolCallId;
29
29
  name: string;
30
30
  arguments: string;
31
31
  };
@@ -38,7 +38,7 @@ export declare function mapFileChange(item: {
38
38
  status?: string;
39
39
  }): {
40
40
  call: {
41
- callId: CallId;
41
+ callId: ToolCallId;
42
42
  name: string;
43
43
  arguments: string;
44
44
  };
@@ -58,7 +58,7 @@ export declare function mapMcpToolCall(item: {
58
58
  };
59
59
  }): {
60
60
  call: {
61
- callId: CallId;
61
+ callId: ToolCallId;
62
62
  name: string;
63
63
  arguments: string;
64
64
  };
@@ -73,12 +73,34 @@ export declare class CodexLoop extends Service implements AgentFactory {
73
73
  private setupAndPublish;
74
74
  /**
75
75
  * Create an agent and session under one caller-supplied identity, owned by
76
- * the accessing fiber.
76
+ * the accessing fiber. When a persistence backend is mounted, the session's
77
+ * durable identity is stored before publication.
77
78
  * @param ownerCtx - caller context that structurally owns the lifecycle.
78
79
  * @param options - identities, session seed/metadata, loop options, setup, and cancellation.
79
80
  * @returns the published handle.
80
81
  */
81
82
  createAgent(ownerCtx: Context, options: CreateAgentOptions): Promise<AgentHandle>;
83
+ /**
84
+ * Take a fresh session's write ownership when persistence is mounted.
85
+ * Nothing is appended here: the constructor seed (which never re-emits
86
+ * through `session/event`) is stored by {@link appendUnstoredSuffix} at the
87
+ * publication commit point, so a failed or cancelled setup closes an
88
+ * unmaterialized handle and leaves no stored residue — the same id can be
89
+ * created again.
90
+ * @param session - the unpublished session to store.
91
+ * @param signal - optional cancellation forwarded to the backend create.
92
+ * @returns the owned handle and stored cursor, or `undefined` without a backend.
93
+ */
94
+ private createStoredSession;
95
+ /**
96
+ * Durably store the session events appended since the last stored cursor.
97
+ * Pre-publication appends (constructor seed markers, setup-window events)
98
+ * never re-emit through `session/event`, so publication must flush them
99
+ * through the handle before live events start routing into it.
100
+ * @param stored - the session's owned handle and stored cursor, if any.
101
+ * @param session - the unpublished session whose suffix is stored.
102
+ */
103
+ private appendUnstoredSuffix;
82
104
  /**
83
105
  * Resume an owned agent from the configured persistence service.
84
106
  * @param ownerCtx - caller context that owns load, setup, and the live lifecycle.
@@ -86,7 +108,7 @@ export declare class CodexLoop extends Service implements AgentFactory {
86
108
  * @returns the published handle.
87
109
  */
88
110
  resume(ownerCtx: Context, options: ResumeAgentOptions): Promise<AgentHandle>;
89
- /** Resume through an explicit persistence handle. */
111
+ /** Resume through an explicit persistence service. */
90
112
  private resumeWith;
91
113
  }
92
114
  //# sourceMappingURL=loop.d.ts.map
@@ -0,0 +1,76 @@
1
+ /**
2
+ * JSON-RPC client for the `kimi acp` subprocess (Agent Client Protocol over
3
+ * stdio).
4
+ *
5
+ * The driver hands the client a process handle carrying its stdin/stdout/stderr
6
+ * (projected from the dsh subprocess seam). The client frames JSON-RPC 2.0
7
+ * records on a bare `\n` (via a byte decoder, tolerating a trailing `\r`),
8
+ * correlates request responses by `id`, dispatches every `session/update`
9
+ * notification to a buffered event stream, and answers the reverse-RPC
10
+ * `session/request_permission` requests the agent publishes. The child is
11
+ * long-lived (one per factory) and stepped over via `newSession` + `prompt`.
12
+ *
13
+ * @module dsh-loop-engine/engine-kimi/acp/client
14
+ */
15
+ import type { KimiProcess, KimiSpawnCapability, KimiSpawnSpec } from '../process.ts';
16
+ import { type AcpFrame, type AcpUpdate } from './types.ts';
17
+ /** How the client answers one `session/request_permission`. */
18
+ export type AcpPermissionHandler = (request: AcpFrame) => boolean | Promise<boolean>;
19
+ /** Callback receiving every non-response event line. */
20
+ export type AcpUpdateHandler = (update: AcpUpdate) => void;
21
+ /**
22
+ * ACP client over one `kimi acp` child. Created once per driver scope and reused
23
+ * across steps, matching the Pi RPC client's lifecycle.
24
+ */
25
+ export declare class AcpClient {
26
+ private readonly process;
27
+ private readonly pending;
28
+ private readonly updateBuffer;
29
+ private updateWake;
30
+ private updateHandler;
31
+ private permissionHandler;
32
+ private sealed;
33
+ private nextId;
34
+ private readonly decoder;
35
+ private buffer;
36
+ /** Whether this client was sealed or its process exited. */
37
+ get closed(): boolean;
38
+ /** Mount a client over an already-spawned `kimi acp` process. */
39
+ constructor(process: KimiProcess);
40
+ /**
41
+ * Create a client, spawning the `kimi acp` child through the supplied
42
+ * capability (or the default node spawn when none is given).
43
+ * @param spec - the `kimi acp` argv/cwd/env the child should run with.
44
+ * @param spawn - optional process-spawn capability (the subprocess seam).
45
+ * @returns the connected client.
46
+ */
47
+ static create(spec: KimiSpawnSpec, spawn?: KimiSpawnCapability): AcpClient;
48
+ /** Register the event dispatch handler. */
49
+ onUpdate(handler: AcpUpdateHandler): void;
50
+ /** Register the permission-approval handler (reverse-RPC answers). */
51
+ onPermission(handler: AcpPermissionHandler): void;
52
+ /** Send one request and await the correlated response. */
53
+ request(method: string, params: unknown): Promise<unknown>;
54
+ /** Send a notification (no correlated response awaited). */
55
+ notify(method: string, params: unknown): void;
56
+ /** Open the protocol handshake. */
57
+ initialize(): Promise<unknown>;
58
+ /** Start a fresh ACP session and resolve to its session id. */
59
+ newSession(cwd: string): Promise<string>;
60
+ /** Prompt the agent in a session and resolve when the turn completes. */
61
+ prompt(sessionId: string, text: string): Promise<unknown>;
62
+ /** Cancel the active turn in a session (fire-and-forget). */
63
+ cancel(sessionId: string): void;
64
+ /** Answer a pending `session/request_permission`. */
65
+ respondPermission(id: number, approved: boolean): void;
66
+ /** Consume every buffered update as an async generator. */
67
+ updates(): AsyncGenerator<AcpUpdate, void, void>;
68
+ /** Seal the client and request child termination. */
69
+ dispose(): void;
70
+ private feed;
71
+ /** Dispatch one parsed line: a response, an update notification, or a reverse-RPC request. */
72
+ private dispatch;
73
+ private settle;
74
+ private handlePermission;
75
+ }
76
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Maps `kimi acp` `session/update` events to dsh session-log projections.
3
+ *
4
+ * Kimi streams incremental assistant text (`agent_message_chunk`), incremental
5
+ * thinking (`agent_thought_chunk`), a tool-call announcement (`tool_call`) and its
6
+ * progress/result stream (`tool_call_update`). This module is pure: it classifies
7
+ * an update, extracts chunk deltas, and projects the tool-call identity/result so
8
+ * the agent can fold them into the durable log. Content blocks use the observed
9
+ * kimi `{ type: 'content', content: { type: 'text', text } }` nesting; unknown
10
+ * block types are ignored.
11
+ *
12
+ * @module dsh-loop-engine/engine-kimi/acp/mapping
13
+ */
14
+ import type { ToolResultMessage } from '@deepseek-ai/dsh-llm';
15
+ import type { AcpContentBlock, AcpToolCallExt, AcpToolCallStreamExt, AcpUpdate } from './types.ts';
16
+ /** Whether the update is an incremental assistant text chunk. */
17
+ export declare function isTextChunk(update: AcpUpdate): update is AcpUpdate & {
18
+ readonly sessionUpdate: 'agent_message_chunk';
19
+ readonly content: AcpContentBlock;
20
+ };
21
+ /** Whether the update is an incremental thinking chunk. */
22
+ export declare function isThoughtChunk(update: AcpUpdate): update is AcpUpdate & {
23
+ readonly sessionUpdate: 'agent_thought_chunk';
24
+ readonly content: AcpContentBlock;
25
+ };
26
+ /** Whether the update announces a tool call. */
27
+ export declare function isToolCall(update: AcpUpdate): update is AcpToolCallExt;
28
+ /** Whether the update streams a tool call's progress/result. */
29
+ export declare function isToolCallUpdate(update: AcpUpdate): update is AcpToolCallStreamExt;
30
+ /** The delta text of a text/thinking chunk. */
31
+ export declare function chunkDelta(update: AcpUpdate): string;
32
+ /** The raw tool-call id (+ content index) as the wire carries it. */
33
+ export declare function toolCallIdOf(update: AcpUpdate): string;
34
+ /** The tool display name (`title`). */
35
+ export declare function toolCallName(update: AcpUpdate): string;
36
+ /** Whether a tool stream status is settled (no longer streaming). */
37
+ export declare function isToolSettledStatus(status: string): boolean;
38
+ /** Whether a tool stream status denotes a failure. */
39
+ export declare function isToolErrorStatus(status: string): boolean;
40
+ /** Join the observed `{ type: 'content', content: { type: 'text', text } }` blocks. */
41
+ export declare function toolContentText(update: AcpToolCallExt | AcpToolCallStreamExt): string;
42
+ /** Project a completed tool call to a durable tool/result message. */
43
+ export declare function toolResult(callId: string, text: string, isError: boolean): ToolResultMessage;
44
+ //# sourceMappingURL=mapping.d.ts.map
@@ -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