@1agents/acp-service 0.1.0

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 ADDED
@@ -0,0 +1,116 @@
1
+ # @1agents/acp-service
2
+
3
+ > DreamMate Network 的 **ACP Agent Runtime Service**:为 Claude Code、Grok、Codex 等 ACP 智能体提供统一的持久化执行、会话重绑与全双工 WebSocket 桥接服务。
4
+ > 默认监听 **36812** 端口,向本机 `dreammate-node`(固定 36908)自动报备与接受探活。
5
+
6
+ ---
7
+
8
+ ## 架构定位
9
+
10
+ 在 DreamMate Network 四层体系中,`acp-service` 作为平级的执行平面(L1/L2 运行时服务)存在:
11
+
12
+ ```
13
+ Control Plane / Web 客户端 / IM 网关
14
+ │
15
+ ├─ 1. 探 36908 发现服务与端口
16
+ ▼
17
+ ┌───────────────────────┐
18
+ │ dreammate-node │ ◄── 固定 36908 (L0.5 基础设施)
19
+ └───────────▲───────────┘
20
+ │ 2. 报备 & /health 周期探活
21
+ ┌───────────┴───────────┐
22
+ │ acp-service │ ◄── 3. 直连 36812 执行 ACP 全双工会话
23
+ │ (默认 36812) │
24
+ ├───────────────────────┤
25
+ │ 底座依赖: │
26
+ │ - @scottzx/1acp │ (携带 Grok _x.ai/* 与 Claude Auth-Env 治理)
27
+ │ - dreammate-network │ (L0 协议契约)
28
+ │ - dreammate-node │ (节点身份与客户端报备)
29
+ └───────────────────────┘
30
+ ```
31
+
32
+ - **单端口复用**:
33
+ - `GET /health`:存活探针,报告 node_id、当前活跃会话数与后台任务数。
34
+ - `GET /manifest`:DreamMate Network 标准节点清单。
35
+ - `WebSocket ws://<host>:36812/`:升级并接管 ACP JSON-RPC 消息流。
36
+
37
+ ---
38
+
39
+ ## 安装与运行
40
+
41
+ ### 1. 全局安装或作为 CLI 运行
42
+
43
+ ```bash
44
+ cd services/acp-service
45
+ npm install
46
+ npm run build
47
+
48
+ # 启动服务(默认监听 0.0.0.0:36812,自动向 36908 报备)
49
+ npm start
50
+
51
+ # 或使用 CLI 任意指定参数
52
+ node dist/bin/acp-service.js --port 36812 --host 0.0.0.0
53
+
54
+ # 单机调试(仅本地回环可见,不向 node-agent 报备)
55
+ node dist/bin/acp-service.js --host 127.0.0.1 --no-report
56
+ ```
57
+
58
+ ### 2. 作为库引入
59
+
60
+ ```ts
61
+ import { serveAcpService } from '@1agents/acp-service';
62
+
63
+ const { port, server, close } = await serveAcpService({
64
+ port: 36812,
65
+ host: '0.0.0.0',
66
+ report: true, // 启动时自动向 dreammate-node (36908) 报备
67
+ });
68
+
69
+ console.log(`ACP Service running on port ${port}`);
70
+ ```
71
+
72
+ ---
73
+
74
+ ## 暴露的能力与接口
75
+
76
+ ### 1. HTTP 探测接口
77
+
78
+ - `GET http://<host>:36812/health`
79
+ ```json
80
+ {
81
+ "status": "ok",
82
+ "node_id": "nigVtDS1s521CNTRL",
83
+ "service": "acp-service",
84
+ "kind": "agent_runtime",
85
+ "sessions": 0,
86
+ "background_tasks": 0,
87
+ "uptime": 12.34
88
+ }
89
+ ```
90
+
91
+ - `GET http://<host>:36812/manifest`
92
+ 返回符合 `@1agents/dreammate-network` 规范的完整 Manifest。
93
+
94
+ ### 2. WebSocket 动作接口(ACP 桥接)
95
+
96
+ 客户端建立 `ws://<host>:36812/` 连接后,发送 JSON 消息:
97
+
98
+ | 动作 (`action`) | 描述 | 关键参数 |
99
+ | :--- | :--- | :--- |
100
+ | `ensure_session` | 创建或恢复 ACP 会话 | `sessionId`, `workspacePath`, `agentType`, `permissionMode` |
101
+ | `prompt` | 发送用户提示词与附件 | `sessionId`, `prompt`, `attachments` |
102
+ | `respond_permission` | 响应工具调用的权限审批 | `sessionId`, `requestId`, `decision` |
103
+ | `respond_ask_user_question` | 响应 Grok `_x.ai/ask_user_question` | `sessionId`, `requestId`, `answers` |
104
+ | `respond_exit_plan_mode` | 响应 Grok `_x.ai/exit_plan_mode` | `sessionId`, `requestId`, `decision` |
105
+ | `set_permission_mode` | 运行时调整权限等级 | `sessionId`, `mode` (`approve-reads`, `yolo` 等) |
106
+ | `cancel_turn` | 取消当前正在执行的轮次 | `sessionId` |
107
+ | `get_history` | 获取当前会话权威历史切片 | `sessionId` |
108
+ | `close_session` | 结束并销毁会话 | `sessionId` |
109
+
110
+ ---
111
+
112
+ ## 协议与底层支持
113
+
114
+ - **Claude Code**:支持第三方 Anthropic 兼容端点,通过 `1acp` 的 `auth-env.ts` 自动清洗 `ANTHROPIC_AUTH_TOKEN` 与 `ANTHROPIC_API_KEY`,规避握手挂死。
115
+ - **Grok Build**:原生支持 `_x.ai/ask_user_question` 问答扩展与 `_x.ai/exit_plan_mode` 退出计划模式扩展。
116
+ - **Codex / Gemini / OpenClaw 等**:支持标准 ACP 子进程生命周期调度。
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import { serveAcpService } from '../src/server.js';
3
+ import { attachProcessSignalHandlers } from '../src/bridge.js';
4
+ function parseArgs(args) {
5
+ const options = {};
6
+ for (let i = 0; i < args.length; i++) {
7
+ const arg = args[i];
8
+ if (arg === '--port' || arg === '-p') {
9
+ const val = args[++i];
10
+ if (val)
11
+ options.port = Number.parseInt(val, 10);
12
+ }
13
+ else if (arg === '--host' || arg === '-h') {
14
+ options.host = args[++i];
15
+ }
16
+ else if (arg === '--no-report') {
17
+ options.report = false;
18
+ }
19
+ else if (arg === '--help') {
20
+ console.log(`用法: acp-service [选项]
21
+
22
+ 选项:
23
+ --port, -p <n> 指定监听端口(默认: 36812)
24
+ --host, -h <ip> 指定绑定 IP(默认: 0.0.0.0)
25
+ --no-report 不向本机 node agent (36908) 报备
26
+ --help 显示帮助信息
27
+ `);
28
+ process.exit(0);
29
+ }
30
+ }
31
+ return options;
32
+ }
33
+ const options = parseArgs(process.argv.slice(2));
34
+ try {
35
+ attachProcessSignalHandlers();
36
+ await serveAcpService(options);
37
+ }
38
+ catch (error) {
39
+ console.error('[acp-service] 启动失败:', error instanceof Error ? error.message : error);
40
+ process.exit(1);
41
+ }
@@ -0,0 +1,14 @@
1
+ export function attachBridgeServer(serverOrOptions?: {}): {
2
+ wss: null;
3
+ runtime: import("@scottzx/1acp/runtime").AcpxRuntime;
4
+ activeSessions: Map<any, any>;
5
+ close: typeof killAllManagedAgents;
6
+ };
7
+ export function setupConnection(ws: any): void;
8
+ export function attachProcessSignalHandlers(): void;
9
+ export let wss: null;
10
+ export function killAllManagedAgents(): Promise<void>;
11
+ export const runtime: import("@scottzx/1acp/runtime").AcpxRuntime;
12
+ export const activeSessions: Map<any, any>;
13
+ export const sessionBackgroundTasks: Map<any, any>;
14
+ export function gracefulExit(source: any): Promise<void>;