deepseek-agent-acp 0.0.0-stage โ†’ 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dong Tran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # ๐Ÿง  deepseek-agent-acp
4
+
5
+ **Native Agent Client Protocol (ACP) Adapter for DeepSeek Reasoning and Chat Models**
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
8
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen.svg?style=flat-square)](https://nodejs.org)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
10
+ [![Protocol: ACP](https://img.shields.io/badge/Protocol-ACP%20(JSON--RPC%202.0)-purple?style=flat-square)](https://agentclientprotocol.org)
11
+ [![MCP Compatible](https://img.shields.io/badge/MCP-1.32.2-blueviolet.svg?style=flat-square)](https://modelcontextprotocol.io)
12
+
13
+ <p align="center">
14
+ Bridge DeepSeek's native reasoning engine (DeepSeek-R1 / V3) with headless agent orchestration harnesses over the standard Agent Client Protocol (ACP), featuring full Model Context Protocol (MCP) tool execution.
15
+ </p>
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ ## ๐ŸŒŸ Overview
22
+
23
+ **`deepseek-agent-acp`** is a high-performance [Agent Client Protocol (ACP)](https://agentclientprotocol.org) adapter designed specifically for **DeepSeek** models (`deepseek-reasoner`, `deepseek-chat`).
24
+
25
+ It bridges headless orchestrators, team chat relays, and multi-agent harnesses with DeepSeek's native completions API over standard line-delimited `stdio` JSON-RPC. It features native 3-phase streaming (CoT reasoning tokens, content deltas, and tool calls), strict stdio isolation, transactional rollback on cancellation, and full tool execution delegation to Model Context Protocol (MCP) servers.
26
+
27
+ ---
28
+
29
+ ## ๐Ÿ— System Architecture
30
+
31
+ ```
32
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
33
+ โ”‚ AGENT ORCHESTRATOR / HARNESS โ”‚
34
+ โ”‚ (e.g., Solace Buzz `buzz-acp`, ACP clients, Hubs) โ”‚
35
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
36
+ โ”‚ Standard Input / Output (stdio)
37
+ โ”‚ Protocol: ACP (JSON-RPC 2.0)
38
+ โ–ผ
39
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
40
+ โ”‚ deepseek-agent-acp โ”‚
41
+ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
42
+ โ”‚ โ”‚ 1. ACP Protocol Router (`src/index.ts`) โ”‚ โ”‚
43
+ โ”‚ โ”‚ โ€ข JSON-RPC: initialize, session/new, session/prompt, session/cancel โ”‚ โ”‚
44
+ โ”‚ โ”‚ โ€ข Stdio Hygiene: Stderr redirection; stdout reserved 100% for JSON-RPC โ”‚ โ”‚
45
+ โ”‚ โ”‚ โ€ข In-Memory Secret Sanitization: Strips API keys from process.env on boot โ”‚ โ”‚
46
+ โ”‚ โ”‚ โ€ข Transactional State Manager: Instant rollback on error or cancel โ”‚ โ”‚
47
+ โ”‚ โ”‚ โ€ข Circuit Breaker: Auto-aborts on recurring repetitive tool failures โ”‚ โ”‚
48
+ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
49
+ โ”‚ โ”‚ โ”‚ โ”‚
50
+ โ”‚ โ–ผ (SSE Stream) โ–ผ (JSON-RPC stdio) โ”‚
51
+ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
52
+ โ”‚ โ”‚ 2. SSE Parser (`src/sse-parser.ts`) โ”‚ โ”‚ 3. MCP Client (`src/mcp-client.ts`) โ”‚ โ”‚
53
+ โ”‚ โ”‚ โ€ข 3-phase streaming parser โ”‚ โ”‚ โ€ข Dynamic tool discovery โ”‚ โ”‚
54
+ โ”‚ โ”‚ โ€ข Phase 1: reasoning_content (CoT) โ”‚ โ”‚ โ€ข OpenAI Schema translation โ”‚ โ”‚
55
+ โ”‚ โ”‚ โ€ข Phase 2: response content delta โ”‚ โ”‚ โ€ข Subprocess env sanitization โ”‚ โ”‚
56
+ โ”‚ โ”‚ โ€ข Phase 3: tool_calls chunk assemblyโ”‚ โ”‚ โ€ข Execution timeout safeguards โ”‚ โ”‚
57
+ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
58
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
59
+ โ”‚ HTTPS POST /chat/completions โ”‚ stdio JSON-RPC
60
+ โ–ผ โ–ผ
61
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
62
+ โ”‚ DEEPSEEK REST API โ”‚ โ”‚ MCP TOOL SERVER โ”‚
63
+ โ”‚ (https://api.deepseek.com) โ”‚ โ”‚ (e.g., buzz-dev-mcp, etc.) โ”‚
64
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
65
+ ```
66
+
67
+ ---
68
+
69
+ ## โœจ Key Features
70
+
71
+ 1. **Native 3-Phase SSE Streaming Parser**:
72
+ * **Phase 1 (`thought`)**: Real-time streaming of `reasoning_content` (DeepSeek-R1 Chain-of-Thought tokens).
73
+ * **Phase 2 (`text`)**: Response content tokens emitted as `session/update` notifications.
74
+ * **Phase 3 (`tool_calls`)**: Incremental assembly of tool names and JSON argument chunks.
75
+ 2. **Absolute Stdio Hygiene**:
76
+ * All logging, diagnostics, and subprocess outputs are strictly routed to `process.stderr`.
77
+ * `process.stdout` is 100% isolated and reserved for valid ACP JSON-RPC frames, eliminating frame corruption.
78
+ 3. **In-Memory Secret Sanitization**:
79
+ * API keys are ingested into private memory constants upon initialization and immediately purged from `process.env`.
80
+ * Prevents credential exposure to child processes, inspect commands, or error logs.
81
+ 4. **Transactional State Management & Rollback**:
82
+ * Takes atomic message snapshots before executing each turn.
83
+ * Restores session state seamlessly to the last stable checkpoint upon client cancellation (`session/cancel`) or uncaught runtime exceptions.
84
+ 5. **Execution Circuit Breaker**:
85
+ * Detects stagnant loops (e.g., 2 consecutive identical tool failures).
86
+ * Injects synthetic safeguards for remaining unexecuted tool calls to maintain strict OpenAI tool-call response invariants.
87
+ 6. **Full Model Context Protocol (MCP) Integration**:
88
+ * Discovers tools dynamically from connected MCP servers and translates them to OpenAI function schemas.
89
+ * Automatically sanitizes child process environments while preserving required authorization tokens and signing keys.
90
+
91
+ ---
92
+
93
+ ## ๐Ÿš€ Installation & Usage
94
+
95
+ ### Global Installation
96
+
97
+ ```bash
98
+ npm install -g deepseek-agent-acp
99
+ ```
100
+
101
+ ### Running as an ACP Adapter
102
+
103
+ ```bash
104
+ export DEEPSEEK_API_KEY="sk-your-deepseek-api-key"
105
+ export DEEPSEEK_MODEL="deepseek-chat" # or "deepseek-reasoner"
106
+ export ACP_MCP_COMMAND="buzz-dev-mcp" # or your MCP server command
107
+
108
+ deepseek-agent-acp
109
+ ```
110
+
111
+ ---
112
+
113
+ ## โš™๏ธ Configuration
114
+
115
+ | Variable | Default | Description |
116
+ | :--- | :--- | :--- |
117
+ | `DEEPSEEK_API_KEY` | *(Required)* | DeepSeek API key (or `DEEPSEEK_AUTH_TOKEN`). |
118
+ | `DEEPSEEK_MODEL` | `deepseek-chat` | Target model (`deepseek-chat`, `deepseek-reasoner`). |
119
+ | `DEEPSEEK_BASE_URL` | `https://api.deepseek.com` | Base endpoint URL for completions API. |
120
+ | `DEEPSEEK_TEMPERATURE` | `0.0` | Sampling temperature. |
121
+ | `DEEPSEEK_REQUEST_TIMEOUT_MS`| `90000` | HTTP fetch and chunk read timeout (ms). |
122
+ | `ACP_MCP_COMMAND` | `buzz-dev-mcp` | Command to launch the Stdio MCP tool server. |
123
+ | `ACP_SYSTEM_PROMPT_FILE` | `./system-prompt.md` | Path to custom system instructions. |
124
+ | `ACP_MAX_ITERATIONS` | `15` (`25` for coder) | Maximum autonomous tool execution turn iterations. |
125
+ | `MCP_TOOL_TIMEOUT_MS` | `60000` | Timeout for individual MCP tool calls (ms). |
126
+
127
+ ---
128
+
129
+ ## ๐Ÿ›  Supported ACP Methods
130
+
131
+ ### Requests
132
+ * **`initialize`**: Exchanges protocol version (`1`), agent metadata, and capabilities (`streaming`, `tools`, `sessionCancellation`).
133
+ * **`session/new`**: Initializes a fresh session instance with an isolated message history and system prompt.
134
+ * **`session/prompt`**: Executes an autonomous multi-turn prompt, streaming reasoning and text deltas.
135
+ * **`session/cancel`**: Aborts ongoing completions, restores state to the last checkpoint, and confirms cancellation.
136
+
137
+ ### Notifications
138
+ * **`session/update`**: Emits real-time stream deltas (`type: "thought"` for reasoning, `type: "text"` for content).
139
+ * **`session/turnComplete`**: Signals the clean completion of a prompt turn.
140
+
141
+ ---
142
+
143
+ ## ๐Ÿงช Development & Quality Assurance
144
+
145
+ ```bash
146
+ # Clone the repository
147
+ git clone git@github.com:dongitran/deepseek-agent-acp.git
148
+ cd deepseek-agent-acp
149
+
150
+ # Install dependencies and setup Husky git hooks
151
+ npm install
152
+
153
+ # Run strict ESLint verification
154
+ npm run lint
155
+
156
+ # Run strict TypeScript typecheck
157
+ npm run typecheck
158
+
159
+ # Execute unit test suite
160
+ npm test
161
+
162
+ # Build distribution bundle
163
+ npm run build
164
+ ```
165
+
166
+ ---
167
+
168
+ ## ๐Ÿ“„ License
169
+
170
+ MIT ยฉ [Dong Tran](https://github.com/dongitran)
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * index.ts โ€” Native Agent Client Protocol (ACP) Adapter for DeepSeek reasoning and chat models.
4
+ * Implements:
5
+ * - Line-delimited JSON-RPC over stdin/stdout (initialize, session/new, session/cancel, session/prompt).
6
+ * - Stdio hygiene (all logging redirected to stderr; stdout strictly reserved for JSON-RPC).
7
+ * - In-memory secret loading and sanitization (strips API key from process.env immediately).
8
+ * - Safe stream parsing and synthetic error injection on token limit truncation (finish_reason === 'length').
9
+ * - Transactional state checkpointing and rollback on session/cancel.
10
+ * - Dynamic iteration limits and circuit breaker (abort if 2 identical tool errors occur in a row).
11
+ * - Full Model Context Protocol (MCP) tool execution.
12
+ */
13
+ export declare function loadSecretKey(secretsPath?: string): string;