@easbot/acp 0.0.0-stage → 0.3.32

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 (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +522 -0
  3. package/README.md +667 -2
  4. package/dist/chunks/bootstrap-GGS3N5CF.cjs +1 -0
  5. package/dist/chunks/bootstrap-MZQICOGZ.mjs +1 -0
  6. package/dist/chunks/cache-3R3ORBTY.cjs +1 -0
  7. package/dist/chunks/cache-76CBF3LU.mjs +1 -0
  8. package/dist/chunks/chunk-2KOCPHVP.mjs +1 -0
  9. package/dist/chunks/chunk-33M2R2US.mjs +1 -0
  10. package/dist/chunks/chunk-3DHMW4DB.mjs +11 -0
  11. package/dist/chunks/chunk-5HWD3B3N.cjs +11 -0
  12. package/dist/chunks/chunk-7RWES66A.cjs +2 -0
  13. package/dist/chunks/chunk-B3ANZALB.mjs +2 -0
  14. package/dist/chunks/chunk-BNSJ6COS.cjs +1 -0
  15. package/dist/chunks/chunk-D4TSQ2TT.mjs +0 -0
  16. package/dist/chunks/chunk-D7S7ARXV.mjs +8 -0
  17. package/dist/chunks/chunk-DX35VSAT.cjs +1 -0
  18. package/dist/chunks/chunk-HQBRVVXS.mjs +1 -0
  19. package/dist/chunks/chunk-ITV7SWGU.cjs +8 -0
  20. package/dist/chunks/chunk-JLO7UYKQ.cjs +1 -0
  21. package/dist/chunks/chunk-M2YU5LAI.cjs +1 -0
  22. package/dist/chunks/chunk-NHXAYBZH.mjs +1 -0
  23. package/dist/chunks/chunk-PATHHDWE.mjs +1 -0
  24. package/dist/chunks/chunk-RHW6YR3D.mjs +2 -0
  25. package/dist/chunks/chunk-SNWAB3QJ.cjs +2 -0
  26. package/dist/chunks/chunk-VVGGER23.cjs +1 -0
  27. package/dist/chunks/chunk-Z3YEK7DD.cjs +1 -0
  28. package/dist/chunks/cli-handler-6XB6B5DV.mjs +1 -0
  29. package/dist/chunks/cli-handler-IU3YUTOU.cjs +1 -0
  30. package/dist/chunks/config-FTGKCGYZ.mjs +1 -0
  31. package/dist/chunks/config-ZVDYJ7TW.cjs +1 -0
  32. package/dist/chunks/interfaces-6ZCF5T55.cjs +1 -0
  33. package/dist/chunks/interfaces-TXNKX4HT.mjs +1 -0
  34. package/dist/chunks/loader-3KX33KJQ.cjs +1 -0
  35. package/dist/chunks/loader-6HBCWO6Y.mjs +1 -0
  36. package/dist/chunks/types-BZWPIPG6.mjs +1 -0
  37. package/dist/chunks/types-R3VOD4XE.cjs +1 -0
  38. package/dist/cli.cjs +2 -0
  39. package/dist/cli.d.cts +1 -0
  40. package/dist/cli.d.ts +1 -0
  41. package/dist/cli.mjs +2 -0
  42. package/dist/index.cjs +1 -0
  43. package/dist/index.d.cts +2030 -0
  44. package/dist/index.d.ts +2030 -0
  45. package/dist/index.mjs +1 -0
  46. package/package.json +87 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 houjallen
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.en.md ADDED
@@ -0,0 +1,522 @@
1
+ # @easbot/acp
2
+
3
+ English | [中文](./README.md)
4
+
5
+ > EASBot ACP (Agent Communication Protocol) Adapter — multi-channel ACP server / client implementation supporting stdio / http / websocket transports
6
+
7
+ ## Version
8
+
9
+ v0.3.32
10
+ ## Introduction
11
+
12
+ `@easbot/acp` is the **ACP adapter layer** (v0.1, split from `@easbot/agent`'s `adapter/` submodule) of the EASBot ecosystem. Built on top of [`@agentclientprotocol/sdk`](https://github.com/agentclientprotocol/typescript-sdk), it implements the server / client communication layer of the ACP protocol with multi-channel connections, JSON-RPC routing, configuration management, cache management, and a standalone CLI entry point.
13
+
14
+ **v0.1 split rationale**:
15
+
16
+ - ✅ **Decouple business complexity**: agent package strips the ACP protocol layer; business modules (session / mcp / gateway) depend on a lighter surface
17
+ - ✅ **Standalone publishing**: `@easbot/acp` can be published independently; host projects (web / cli / monitor) can import on demand
18
+ - ✅ **Standalone CLI**: `easbot-acp <command>` starts server / config / status / doctor directly without going through agent
19
+ - ✅ **Independent configuration**: `<workspaceDir>/.easbot/acp.json` + `~/.config/easbot/acp.json` + `easbot.json` top-level `acp` field (four-layer merge loading, mirrors gateway)
20
+
21
+ ## Features
22
+
23
+ - **Three transports**: stdio (subprocess) / http (REST + JSON-RPC) / websocket (full-duplex)
24
+ - **JSON-RPC routing**: `acp-rpc-handler` auto-dispatches `initialize / new_session / prompt / cancel` and other methods
25
+ - **Four-layer config loader**: mirrors `packages/gateway/src/config/loader.ts` — global / `easbot.json` field / project-level merge + JSONC + env substitution
26
+ - **L2 cache namespace**: `AcpCache` (State.holder pattern, same source as `NoteCache`) manages project-level `.easbot/acp.json`
27
+ - **Error namespace**: `AcpError` (built on `NamedError.create` + ADR 0102 Phase 2.1 business feedback channel)
28
+ - **Standalone CLI**: `easbot-acp <command>` (init / start / status / doctor / config)
29
+ - **host ↔ package decoupling**: aligned with note / memory / codebase / skills `setGlobalAdapter / setInstanceAdapter` interfaces
30
+ - **Reuses existing business modules**: server / client / connection / event / performance migrated from agent package
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pnpm add @easbot/acp
36
+ ```
37
+
38
+ ## Top-level exports
39
+
40
+ ```typescript
41
+ // Configuration module (schema + loader + convenience accessors)
42
+ import {
43
+ // Schema
44
+ ACPServerConfigSchema,
45
+ ACPClientConfigSchema,
46
+ ACPClientsConfigSchema,
47
+ InfoACPConfigSchema,
48
+ // Defaults
49
+ DEFAULT_ACP_SERVER_CONFIG,
50
+ DEFAULT_ACP_CLIENT_CONFIG,
51
+ // Validation
52
+ validateAcpConfig,
53
+ parsePartialAcpConfig,
54
+ // Loader
55
+ loadConfig,
56
+ getConfig,
57
+ isConfigLoaded,
58
+ clearConfigCache,
59
+ getConfigDirectory,
60
+ reloadConfig,
61
+ // Convenience accessors
62
+ getServerConfig,
63
+ getClientsConfig,
64
+ getClientById,
65
+ getDefaultClient,
66
+ type AcpConfigStateResult,
67
+ } from '@easbot/acp';
68
+ import type {
69
+ ACPServerConfig,
70
+ ACPClientConfig,
71
+ ACPClientsConfig,
72
+ InfoACPConfig,
73
+ } from '@easbot/acp';
74
+
75
+ // L2 cache namespace
76
+ import { AcpCache, ACP_JSON_REL_PATH } from '@easbot/acp';
77
+
78
+ // Error namespace + business feedback registration
79
+ import {
80
+ AcpError,
81
+ NameErrors,
82
+ ACP_BUSINESS_CODES,
83
+ ACP_BUSINESS_HINTS,
84
+ registerBusinessErrors,
85
+ ServiceError,
86
+ type ServiceErrorInstance,
87
+ } from '@easbot/acp';
88
+
89
+ // CLI handler + renderers
90
+ import {
91
+ handleAcpCli,
92
+ renderBanner,
93
+ renderHelp,
94
+ COMMANDS_HELP,
95
+ type AcpCliDeps,
96
+ type AcpCliResult,
97
+ type CommandHelp,
98
+ } from '@easbot/acp';
99
+
100
+ // host ↔ package decoupling interfaces (ADR 0066)
101
+ import {
102
+ setGlobalAdapter,
103
+ setInstanceAdapter,
104
+ resetGlobalAdapter,
105
+ resetInstanceAdapter,
106
+ getGlobal,
107
+ getInstance,
108
+ getHomeDir,
109
+ getXdgData,
110
+ getWorktree,
111
+ getProjectDirectory,
112
+ } from '@easbot/acp';
113
+
114
+ // Business modules (migrated from agent package)
115
+ import { EasBotAgent, EasbotAdapter, ChannelType, AgentStatus } from '@easbot/acp';
116
+ ```
117
+
118
+ ## Quick start
119
+
120
+ ### 1. Start standalone ACP server
121
+
122
+ ```bash
123
+ # 1) Initialize workspace config (creates .easbot/acp.json)
124
+ easbot-acp init --channel websocket --port 3000 --hostname localhost
125
+
126
+ # 2) Start server (blocks; Ctrl+C to exit)
127
+ easbot-acp start --channel websocket --port 3000
128
+
129
+ # 3) View config summary
130
+ easbot-acp status
131
+
132
+ # 4) Health check
133
+ easbot-acp doctor
134
+
135
+ # 5) Modify config
136
+ easbot-acp config set server.port 8080
137
+ easbot-acp config get server.channel
138
+ ```
139
+
140
+ ### 2. Programmatic startup
141
+
142
+ ```typescript
143
+ import { EasbotAdapter, getServerConfig, ChannelType } from '@easbot/acp';
144
+
145
+ const serverCfg = await getServerConfig();
146
+ await EasbotAdapter.init({
147
+ directory: process.cwd(),
148
+ printLogs: false,
149
+ logLevel: 'INFO',
150
+ channel: ChannelType.WS,
151
+ });
152
+ await EasbotAdapter.ensureACPService(serverCfg);
153
+ ```
154
+
155
+ ### 3. Config loading (four-layer merge, mirrors gateway)
156
+
157
+ ACP config is layered **from low to high priority** (later layers override earlier ones, deep-merged across `server` / `clients` blocks):
158
+
159
+ | Priority | Path | Notes |
160
+ | -------- | ---------------------------------------------- | ------------------------------------------------ |
161
+ | Lowest | `~/.config/easbot/easbot.json` top-level `acp` | agent-integration wrapper (global) |
162
+ | ↑ | `~/.config/easbot/acp.json` | Global standalone config |
163
+ | ↑ | `<workspaceDir>/easbot.json` top-level `acp` | agent-integration wrapper (project-level) |
164
+ | Highest | `<workspaceDir>/.easbot/acp.json` | Project-level standalone config (via `AcpCache`) |
165
+
166
+ Two override rules:
167
+
168
+ - **Project-level overrides global** (`<workspaceDir>` wins over `~/.config/easbot/`)
169
+ - **`acp.json` overrides `easbot.json`** (standalone config beats the agent-integration wrapper)
170
+
171
+ Key points:
172
+
173
+ - Project-level `acp.json` lives in **exactly one place**: `.easbot/acp.json` (held by `AcpCache`).
174
+ Bare `<workspaceDir>/acp.json` is no longer supported, and `EASBOT_CONFIG_DIR` no longer
175
+ participates in the resolution chain.
176
+ - `<workspaceDir>` comes from `getInstance().directory` (Instance is injected uniformly by the CLI entry point).
177
+ - **Single schema source**: raw reads apply **no** schema; validation + defaults are applied exactly
178
+ once at the end via `ConfigFileParse.merge(partials, ACPInfoACPConfigSchema)` — applying them
179
+ per-layer would let defaults leak across layers (a defaulted low-priority field overriding a real one).
180
+ - **No config file → no initial values**: `server` in `ACPInfoACPConfigSchema` is `.optional()` with
181
+ **no** transform fallback. When all four layers are missing, `loadConfig()` returns `{}`
182
+ (`server` is `undefined` — it never fabricates a port-3000 server). Use `getServerConfig()`
183
+ (which merges over `ACP_DEFAULT_SERVER_CONFIG`) or `ACPServerConfigSchema.parse({})` when you need
184
+ server defaults.
185
+ - Semantics identical to `packages/gateway`'s `GatewayCache` loader (same structure).
186
+
187
+ Supports:
188
+
189
+ - **JSONC comments** (`//` / `/* ... */`)
190
+ - **`{env:VAR_NAME}` substitution** (auto-read from `process.env`)
191
+ - **Deep merge + schema defaults** (`ConfigFileParse.merge(partials, ACPInfoACPConfigSchema)`)
192
+ - **State.holder caching** (bucketed per workspace + `AcpCache.resetState()` / `clearConfigCache()`)
193
+
194
+ ### 4. L2 cache: `AcpCache` namespace
195
+
196
+ ACP subsystem owns an independent L2 config file `<workspaceDir>/.easbot/acp.json` (**does not conflict with** the global `easbot.json`). `AcpCache` namespace provides centralized in-memory caching (State.holder + fallback), same source as `NoteCache`.
197
+
198
+ ```typescript
199
+ import { AcpCache } from '@easbot/acp';
200
+
201
+ // 1. Explicit warm-up — already invoked by EasbotAdapter.init(), usually no need to call manually
202
+ await AcpCache.init();
203
+
204
+ // 2. Read
205
+ const cfg = await AcpCache.getAcpJson(); // undefined means file does not exist
206
+ const exists = await AcpCache.exists(); // fs.existsSync real probe
207
+ const rootDir = await AcpCache.getRootDir(); // current workspaceDir
208
+ const path = await AcpCache.getConfigPath(); // `<rootDir>/.easbot/acp.json` absolute path
209
+
210
+ // 3. Write (partial fields are merged with existing acp.json, unspecified fields preserved)
211
+ await AcpCache.writeAcpJson({ server: { channel: 'http', port: 8080 } });
212
+
213
+ // 4. Test isolation
214
+ AcpCache.resetState(); // clear holder + idempotent flag
215
+ ```
216
+
217
+ > `EasbotAdapter.init()` warms up `AcpCache` right after `initInstance()` (it must run after `Instance.provide` because the cache is bucketed by `Instance.directory`). A failed warm-up only degrades to a warn log (subsequent reads fall back to lazy load) and never blocks adapter startup.
218
+
219
+ ### 5. Error handling
220
+
221
+ Layered per `spec/error-handling-standard.md` v1.5:
222
+
223
+ | Layer | Path | acp usage |
224
+ | -------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------- |
225
+ | L1 generic | `NameErrors` (utils) | Cross-module (FileParse / InvalidArgument / OperationFailed / Timeout / Network / Validation) |
226
+ | L1.5 cross-business | `BusinessErrors` (utils) | **Not used by this package** (no cross-business scenarios) |
227
+ | L2 in-package | `AcpError` namespace | 5 core error classes (see below) |
228
+ | L3 business feedback | `ServiceError` + `ServiceErrorBus` | 5 ACP-specific codes + hints (`registerBusinessErrors()` to register) |
229
+
230
+ ```typescript
231
+ import { AcpError, NameErrors, registerBusinessErrors, ServiceError } from '@easbot/acp';
232
+
233
+ // 1. Register business feedback (once; cli-handler entry calls it automatically)
234
+ await registerBusinessErrors();
235
+
236
+ // 2. L2 in-package business errors (5 core classes)
237
+ throw new AcpError.ServerStartFailedError({
238
+ message: 'port 3000 is in use',
239
+ channel: 'websocket',
240
+ port: 3000,
241
+ code: 'EADDRINUSE',
242
+ });
243
+
244
+ throw new AcpError.ConfigNotFoundError({
245
+ message: 'acp config not found',
246
+ path: '/Users/xiaomo/demo/.easbot/acp.json',
247
+ });
248
+
249
+ // 3. Caller type guard
250
+ if (AcpError.ServerStartFailedError.isInstance(err)) {
251
+ console.log('server start failed:', err.data.port);
252
+ }
253
+
254
+ // 4. L1 generic errors (utils) — reuse, don't redefine
255
+ throw new NameErrors.InvalidArgumentError({ message: 'invalid channel', param: 'channel' });
256
+ throw new NameErrors.FileParseError({
257
+ message: 'JSON parse failed',
258
+ filePath: '/path/to/acp.json',
259
+ });
260
+ throw new NameErrors.OperationFailedError({
261
+ message: 'acp server stop timeout',
262
+ operation: 'acp.server.stop',
263
+ });
264
+
265
+ // 5. L3 business feedback (LLM-actionable hints; caller throws ServiceError)
266
+ throw new ServiceError({
267
+ code: 'CONNECTION_FAILED',
268
+ message: 'remote ACP agent unreachable',
269
+ details: { clientId: 'remote-1', channel: 'websocket' },
270
+ });
271
+ ```
272
+
273
+ **5 L2 error classes**:
274
+
275
+ | Class | Trigger | Replaces v1.0 |
276
+ | -------------------------------------- | ------------------------- | --------------------------------------------------------- |
277
+ | `AcpError.ConfigNotFoundError` | acp.json missing | `ConfigNotFoundError` |
278
+ | `AcpError.ConfigValidationError` | schema validation failed | `ConfigValidationError` + `InvalidHostnameError` |
279
+ | `AcpError.ServerStartFailedError` | server start failed | `ServerStartFailedError` |
280
+ | `AcpError.ClientConnectionFailedError` | client connection failed | `ClientConnectionFailedError` + `ClientDisconnectedError` |
281
+ | `AcpError.RpcParseFailedError` | JSON-RPC frame corruption | `RpcParseFailedError` |
282
+
283
+ **Removed v1.0 error classes** (per v1.5 layering, use utils `NameErrors`):
284
+
285
+ - ❌ `ConfigLoadFailedError` → `NameErrors.FileParseError({ filePath, cause })`
286
+ - ❌ `InvalidHostnameError` → `NameErrors.ValidationError({ message, param: 'hostname' })`
287
+ - ❌ `ServerStopFailedError` → `NameErrors.OperationFailedError({ operation: 'acp.server.stop' })`
288
+ - ❌ `ClientDisconnectedError` → `NameErrors.OperationFailedError({ operation: 'acp.client.disconnect' })`
289
+ - ❌ `CacheReadFailedError` / `CacheWriteFailedError` → `NameErrors.FileParseError` / `NameErrors.OperationFailedError`
290
+
291
+ ### 6. Internationalization (i18n)
292
+
293
+ All user-facing strings (banner / help / command output / error hints) go through `t()`, with `zh-CN` (default) / `en-US` support.
294
+
295
+ ```typescript
296
+ import { t, I18n, registerI18nResources } from '@easbot/acp';
297
+
298
+ // 1. Main translation function
299
+ console.log(t('cli.cmd.init.description'));
300
+ // → "初始化 acp 工作区(创建 .easbot/acp.json)" (zh-CN)
301
+ // → "Initialize acp workspace (creates .easbot/acp.json)" (en-US)
302
+
303
+ // 2. Template interpolation
304
+ console.log(t('cli.init.created', { vars: { path: '/Users/xiaomo/demo/.easbot/acp.json' } }));
305
+ // → "✓ acp 配置已初始化到 /Users/xiaomo/demo/.easbot/acp.json"
306
+
307
+ // 3. Explicit locale
308
+ console.log(t('cli.banner.title', { locale: 'en-US' }));
309
+
310
+ // 4. Missing-key fallback
311
+ console.log(t('cli.unknown.key', { fallback: 'fallback string' }));
312
+
313
+ // 5. Register custom resources (optional)
314
+ registerI18nResources('zh-CN', {
315
+ translation: {
316
+ 'acp.custom.key': '自定义中文文案',
317
+ },
318
+ });
319
+ ```
320
+
321
+ **locale priority**: explicit arg > `process.env.EASBOT_LANG` > `process.env.LANG` > `I18n.defaultLocale` (zh-CN)
322
+
323
+ **Translation key convention**: `<module>.<action>.<result>` (cli.banner / cli.cmd / cli.init / cli.start / cli.status / cli.doctor / cli.config / acp.cli / acp.error)
324
+
325
+ **Supported locales**:
326
+
327
+ | Locale | File | Status |
328
+ | ------- | ------------------ | ---------- |
329
+ | `zh-CN` | `locales/zh-CN.ts` | ✅ default |
330
+ | `en-US` | `locales/en-US.ts` | ✅ |
331
+
332
+ **Spec alignment**: `spec/internationalization-standard.md` v2.1.0
333
+
334
+ ### 7. host ↔ package decoupling (ADR 0066)
335
+
336
+ ```typescript
337
+ import { setGlobalAdapter, setInstanceAdapter } from '@easbot/acp';
338
+
339
+ // Inject during agent bootstrap
340
+ setGlobalAdapter({
341
+ Path: {
342
+ home: '/Users/xiaomo',
343
+ data: '/Users/xiaomo/.local/share/easbot',
344
+ config: '/Users/xiaomo/.config/easbot',
345
+ cache: '/Users/xiaomo/.cache/easbot',
346
+ // ...
347
+ },
348
+ });
349
+ setInstanceAdapter({
350
+ directory: '/Users/xiaomo/projects/demo',
351
+ worktree: '/Users/xiaomo/projects/demo',
352
+ });
353
+ ```
354
+
355
+ ## CLI commands
356
+
357
+ 5 sub-commands (v0.1 scope):
358
+
359
+ ### lifecycle (3)
360
+
361
+ - **`init`** — initialize workspace (creates `.easbot/acp.json`)
362
+ - `--channel <stdio|http|websocket>`: default channel
363
+ - `--port <n>`: port (http/websocket)
364
+ - `--hostname <addr>`: hostname
365
+ - `--force`: overwrite existing config
366
+ - `--json`: JSON output
367
+
368
+ - **`status`** — show config summary (server channel / port / clients)
369
+ - `--json`: JSON output
370
+
371
+ - **`doctor`** — health check (config loadable / schema valid / deps)
372
+ - `--json`: JSON output
373
+
374
+ ### server (1)
375
+
376
+ - **`start`** — start ACP server, blocks until Ctrl+C / SIGTERM
377
+ - `--channel <stdio|http|websocket>`
378
+ - `--port <n>`
379
+ - `--hostname <addr>`
380
+ - `--timeout <ms>`
381
+
382
+ ### external (1)
383
+
384
+ - **`config`** — get / set acp config
385
+ - `easbot-acp config get [key]` (dot-path like `server.channel`)
386
+ - `easbot-acp config set <key> <value>` (auto-detects number / boolean)
387
+
388
+ ### Global flags (aligned with agent / note)
389
+
390
+ - `--cwd <dir>`: workspace directory
391
+ - `--config <path>`: global config file path
392
+ - `--log-level <DEBUG|INFO|WARN|ERROR>`: default INFO
393
+ - `--print-logs`: print logs to stderr
394
+ - `--debug`: equivalent to `--log-level DEBUG`
395
+
396
+ ### Usage examples
397
+
398
+ ```bash
399
+ # Standalone CLI (user at project root)
400
+ $ easbot-acp init --channel websocket --port 3000
401
+ ✓ acp config initialized at /Users/xiaomo/demo/.easbot/acp.json
402
+
403
+ $ easbot-acp status
404
+ directory: /Users/xiaomo/demo
405
+ server.channel: websocket
406
+ server.port: 3000
407
+ server.hostname: localhost
408
+ server.enabled: true
409
+ clients: 0
410
+
411
+ $ easbot-acp config set server.port 8080
412
+ ✓ set server.port = 8080
413
+
414
+ $ easbot-acp start --channel websocket
415
+ [acp] server starting on ws://localhost:8080
416
+ ^C
417
+ [acp] server received signal, shutting down
418
+
419
+ # Agent CLI (reuses @easbot/agent)
420
+ $ easbot acp start --channel http --port 3000
421
+ ```
422
+
423
+ > The **`address` row** of the start banner is a full protocol URL (built by the single
424
+ > source of truth `getAcpEndpointUrl`): `ws://<hostname>:<port>` / `http://<hostname>:<port>` /
425
+ > `stdio://easbot`. The same rule backs the server-side `getServerUrl` and the `address` the
426
+ > agent registers with Gateway, so the three can never drift apart.
427
+
428
+ ## Architecture
429
+
430
+ ```
431
+ ┌─────────────────────────────────────────────────────────┐
432
+ │ @easbot/agent │
433
+ │ ├─ cli/commands/acp.ts (agent acp serve subcommand) │
434
+ │ └─ api/, session/, scheduler/, ... │
435
+ └────────────┬─────────────────────────────────────────────┘
436
+ │ reuses handleAcpCli / mergeConfig pattern
437
+ ▼
438
+ ┌─────────────────────────────────────────────────────────┐
439
+ │ @easbot/acp (this package) │
440
+ │ ├─ cli.ts / cli-handler.ts (standalone CLI entry) │
441
+ │ ├─ cache/ (AcpCache namespace) │
442
+ │ ├─ config/ (schema + loader + accessors) │
443
+ │ ├─ errors.ts (AcpError namespace) │
444
+ │ ├─ interfaces.ts (host ↔ package decoupling) │
445
+ │ ├─ server/ (acp-server / http-server / ws-server) │
446
+ │ ├─ client/ (acp-client / stdio / http / ws subscriber) │
447
+ │ ├─ connection/ (registry / router / types — types is a re-export layer; source of truth in @easbot/utils) │
448
+ │ ├─ event/ (acp-event-bridge) │
449
+ │ ├─ performance/ (performance-monitor / streaming) │
450
+ │ ├─ error/ (error-handler / timeout-manager) │
451
+ │ ├─ types/ (adapter / channel / error / event) │
452
+ │ ├─ bootstrap/ (EasbotAdapter) │
453
+ │ └─ easbot-agent.ts (EasBotAgent instance) │
454
+ └─────────────────────────────────────────────────────────┘
455
+ ```
456
+
457
+ ## Differences from note / gateway / memory
458
+
459
+ | Dimension | note | gateway | acp |
460
+ | ----------------------- | --------------------- | ------------------------------------------------------- | ------------------------------------------------------- |
461
+ | L2 config file name | `note.json` | `gateway.json` | `acp.json` |
462
+ | L2 cache name | `NoteCache` | (no L2 cache) | `AcpCache` |
463
+ | Error namespace | `NoteError` | `GatewayError` | `AcpError` |
464
+ | Business code whitelist | 13 | (not registered) | 5 |
465
+ | Command count | 11 | 0 (no standalone CLI) | 5 |
466
+ | Top-level deps | LLM / DB / parser | hono / undici / ws | @agentclientprotocol/sdk |
467
+ | Config loading | single-file NoteCache | four-layer merge (global + easbot.json field + project) | four-layer merge (global + easbot.json field + project) |
468
+
469
+ ## Development commands
470
+
471
+ ```bash
472
+ # Build (tsup, outputs ESM + CJS + DTS)
473
+ pnpm --filter @easbot/acp build
474
+
475
+ # Watch mode
476
+ pnpm --filter @easbot/acp dev
477
+
478
+ # Type check
479
+ pnpm --filter @easbot/acp type-check
480
+
481
+ # Lint (biome)
482
+ pnpm --filter @easbot/acp lint
483
+
484
+ # Lint fix
485
+ pnpm --filter @easbot/acp lint:fix
486
+
487
+ # Unit tests
488
+ pnpm --filter @easbot/acp test:run
489
+
490
+ # Unit tests + coverage
491
+ pnpm --filter @easbot/acp test:coverage
492
+
493
+ # Clean test fixtures
494
+ pnpm --filter @easbot/acp test:clean
495
+ ```
496
+
497
+ ## Design principles
498
+
499
+ 1. **host ↔ package decoupling**: all runtime dependencies are explicitly injected via `setGlobalAdapter / setInstanceAdapter`; agent package / standalone CLI / tests share the same semantics
500
+ 2. **Four-layer config loading**: mirrors `packages/gateway/src/config/loader.ts`, with JSONC + env substitution + State.holder three-piece set
501
+ 3. **Error layering**: in-package `AcpError` (business semantics) + `NameErrors` (generic) + `ServiceError + ServiceErrorBus` (LLM business feedback)
502
+ 4. **CLI / handler separation**: `handleAcpCli(args, deps)` entry is independently testable; agent / standalone CLI / MCP server reuse the same dispatch logic
503
+ 5. **No business-instance ownership**: acp package does not depend on `@easbot/agent` internal modules; only exposes server startup via `EasbotAdapter` (AdapterRegistry injected by agent bootstrap)
504
+ 6. **Independent cache**: `AcpCache` is fully isolated from the global `easbot.json`; project-level `.easbot/acp.json` is managed as a single file
505
+
506
+ ## Split history
507
+
508
+ | Version | Key changes |
509
+ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
510
+ | **Earlier (within agent)** | `packages/agent/src/adapter/` — ACP adapter coupled with agent package |
511
+ | **v0.1 (2026-10-06)** | Split into standalone workspace package `@easbot/acp`; added cli / errors / cache / config loader; agent now reuses `@easbot/acp` entry |
512
+ | **v0.3.28 (2026-10-06)** | `agent/src/config/adapter-loader.ts` → `acp-loader.ts`; pure proxy over `@easbot/acp` (mirrors `gateway-loader.ts` pattern). Cache & loader now share JSONC + env parsing (config drift fix); `interfaces.ts` SDK injection now scoped per `getInstance().directory` (multi-tenant safe) |
513
+
514
+ ## References
515
+
516
+ - [`@agentclientprotocol/sdk`](https://github.com/agentclientprotocol/typescript-sdk) — official TypeScript SDK for ACP protocol
517
+ - `packages/note/src/cli-handler.ts` — CLI handler reference
518
+ - `packages/gateway/src/config/loader.ts` — four-layer config loader reference
519
+ - `packages/note/src/cache/index.ts` — same-source reference for AcpCache (Pattern E)
520
+ - `packages/note/src/errors.ts` — same-source reference for AcpError
521
+ - `ADR 0066` — host ↔ package decoupling specification
522
+ - `ADR 0102 Phase 2.1` — ServiceError + NamedError business feedback channel