@easbot/acp 0.0.0-stage → 0.3.29

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 (38) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +495 -0
  3. package/README.md +616 -2
  4. package/dist/chunks/bootstrap-5LQOAO3Q.cjs +1 -0
  5. package/dist/chunks/bootstrap-VXDGNMPK.mjs +1 -0
  6. package/dist/chunks/cache-EJ4Y2PSY.cjs +1 -0
  7. package/dist/chunks/cache-SOYLU2DS.mjs +1 -0
  8. package/dist/chunks/chunk-3OTURNTA.cjs +11 -0
  9. package/dist/chunks/chunk-CIOYWMQM.cjs +1 -0
  10. package/dist/chunks/chunk-DS4SO4NN.cjs +2 -0
  11. package/dist/chunks/chunk-ER7EK5Z3.mjs +8 -0
  12. package/dist/chunks/chunk-F44AHCPJ.cjs +8 -0
  13. package/dist/chunks/chunk-HA3RF4AE.cjs +1 -0
  14. package/dist/chunks/chunk-HQBRVVXS.mjs +1 -0
  15. package/dist/chunks/chunk-M2YU5LAI.cjs +1 -0
  16. package/dist/chunks/chunk-MFINI6BI.mjs +1 -0
  17. package/dist/chunks/chunk-PEMSMRYT.mjs +1 -0
  18. package/dist/chunks/chunk-RTXRNSMY.mjs +1 -0
  19. package/dist/chunks/chunk-SHXWJMFY.mjs +11 -0
  20. package/dist/chunks/chunk-UTBY7IJT.mjs +2 -0
  21. package/dist/chunks/chunk-Z4D2PWDQ.cjs +1 -0
  22. package/dist/chunks/cli-handler-2KK2I4DG.mjs +1 -0
  23. package/dist/chunks/cli-handler-EM2BY47U.cjs +1 -0
  24. package/dist/chunks/config-KX5CSYLV.mjs +1 -0
  25. package/dist/chunks/config-YIR7GKPG.cjs +1 -0
  26. package/dist/chunks/interfaces-6BMD3FTB.cjs +1 -0
  27. package/dist/chunks/interfaces-UB3BFHJN.mjs +1 -0
  28. package/dist/chunks/types-CHN33Z37.mjs +1 -0
  29. package/dist/chunks/types-XGBPFI7X.cjs +1 -0
  30. package/dist/cli.cjs +2 -0
  31. package/dist/cli.d.cts +1 -0
  32. package/dist/cli.d.ts +1 -0
  33. package/dist/cli.mjs +2 -0
  34. package/dist/index.cjs +1 -0
  35. package/dist/index.d.cts +1247 -0
  36. package/dist/index.d.ts +1247 -0
  37. package/dist/index.mjs +1 -0
  38. 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,495 @@
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.29
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` + `<cwd>/easbot.json` top-level `acp` field (multi-directory mixed loading)
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
+ - **Multi-directory config loader**: mirrors `packages/gateway/src/config/loader.ts` — multi-dir 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. Multi-directory config loading (mirrors gateway)
156
+
157
+ ACP config is layered **from low to high priority**:
158
+
159
+ | Priority | Path | Notes |
160
+ | -------- | --------------------------------------------- | --------------------------------------------- |
161
+ | Lowest | `~/.config/easbot/acp.json` | Global config |
162
+ | ↑ | `<cwd>/acp.json` | Project config |
163
+ | ↑ | Walk-up `.easbot/` directories for `acp.json` | git-worktree compatible |
164
+ | ↑ | `<cwd>/.easbot/acp.json` | Project-level (aligned with `<workspaceDir>`) |
165
+ | Highest | `<cwd>/easbot.json` top-level `acp` field | Mixed field (shared with global) |
166
+
167
+ Supports:
168
+
169
+ - **JSONC comments** (`//` / `/* ... */`)
170
+ - **`{env:VAR_NAME}` substitution** (auto-read from `process.env`)
171
+ - **Deep merge** (`server` block + `clients` block)
172
+ - **State.holder caching** (per-process singleton + explicit `clearConfigCache()`)
173
+
174
+ ### 4. L2 cache: `AcpCache` namespace
175
+
176
+ 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`.
177
+
178
+ ```typescript
179
+ import { AcpCache } from '@easbot/acp';
180
+
181
+ // 1. Explicit pre-warm (called at agent bootstrap)
182
+ await AcpCache.init();
183
+
184
+ // 2. Read
185
+ const cfg = await AcpCache.getAcpJson(); // undefined means file does not exist
186
+ const exists = await AcpCache.exists(); // fs.existsSync real probe
187
+ const rootDir = await AcpCache.getRootDir(); // current workspaceDir
188
+ const path = await AcpCache.getConfigPath(); // `<rootDir>/.easbot/acp.json` absolute path
189
+
190
+ // 3. Write (partial fields are merged with existing acp.json, unspecified fields preserved)
191
+ await AcpCache.writeAcpJson({ server: { channel: 'http', port: 8080 } });
192
+
193
+ // 4. Test isolation
194
+ AcpCache.resetState(); // clear holder + idempotent flag
195
+ ```
196
+
197
+ ### 5. Error handling
198
+
199
+ Layered per `spec/error-handling-standard.md` v1.5:
200
+
201
+ | Layer | Path | acp usage |
202
+ | -------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------- |
203
+ | L1 generic | `NameErrors` (utils) | Cross-module (FileParse / InvalidArgument / OperationFailed / Timeout / Network / Validation) |
204
+ | L1.5 cross-business | `BusinessErrors` (utils) | **Not used by this package** (no cross-business scenarios) |
205
+ | L2 in-package | `AcpError` namespace | 5 core error classes (see below) |
206
+ | L3 business feedback | `ServiceError` + `ServiceErrorBus` | 5 ACP-specific codes + hints (`registerBusinessErrors()` to register) |
207
+
208
+ ```typescript
209
+ import { AcpError, NameErrors, registerBusinessErrors, ServiceError } from '@easbot/acp';
210
+
211
+ // 1. Register business feedback (once; cli-handler entry calls it automatically)
212
+ await registerBusinessErrors();
213
+
214
+ // 2. L2 in-package business errors (5 core classes)
215
+ throw new AcpError.ServerStartFailedError({
216
+ message: 'port 3000 is in use',
217
+ channel: 'websocket',
218
+ port: 3000,
219
+ code: 'EADDRINUSE',
220
+ });
221
+
222
+ throw new AcpError.ConfigNotFoundError({
223
+ message: 'acp config not found',
224
+ path: '/Users/xiaomo/demo/.easbot/acp.json',
225
+ });
226
+
227
+ // 3. Caller type guard
228
+ if (AcpError.ServerStartFailedError.isInstance(err)) {
229
+ console.log('server start failed:', err.data.port);
230
+ }
231
+
232
+ // 4. L1 generic errors (utils) — reuse, don't redefine
233
+ throw new NameErrors.InvalidArgumentError({ message: 'invalid channel', param: 'channel' });
234
+ throw new NameErrors.FileParseError({
235
+ message: 'JSON parse failed',
236
+ filePath: '/path/to/acp.json',
237
+ });
238
+ throw new NameErrors.OperationFailedError({
239
+ message: 'acp server stop timeout',
240
+ operation: 'acp.server.stop',
241
+ });
242
+
243
+ // 5. L3 business feedback (LLM-actionable hints; caller throws ServiceError)
244
+ throw new ServiceError({
245
+ code: 'CONNECTION_FAILED',
246
+ message: 'remote ACP agent unreachable',
247
+ details: { clientId: 'remote-1', channel: 'websocket' },
248
+ });
249
+ ```
250
+
251
+ **5 L2 error classes**:
252
+
253
+ | Class | Trigger | Replaces v1.0 |
254
+ | -------------------------------------- | ------------------------- | --------------------------------------------------------- |
255
+ | `AcpError.ConfigNotFoundError` | acp.json missing | `ConfigNotFoundError` |
256
+ | `AcpError.ConfigValidationError` | schema validation failed | `ConfigValidationError` + `InvalidHostnameError` |
257
+ | `AcpError.ServerStartFailedError` | server start failed | `ServerStartFailedError` |
258
+ | `AcpError.ClientConnectionFailedError` | client connection failed | `ClientConnectionFailedError` + `ClientDisconnectedError` |
259
+ | `AcpError.RpcParseFailedError` | JSON-RPC frame corruption | `RpcParseFailedError` |
260
+
261
+ **Removed v1.0 error classes** (per v1.5 layering, use utils `NameErrors`):
262
+
263
+ - ❌ `ConfigLoadFailedError` → `NameErrors.FileParseError({ filePath, cause })`
264
+ - ❌ `InvalidHostnameError` → `NameErrors.ValidationError({ message, param: 'hostname' })`
265
+ - ❌ `ServerStopFailedError` → `NameErrors.OperationFailedError({ operation: 'acp.server.stop' })`
266
+ - ❌ `ClientDisconnectedError` → `NameErrors.OperationFailedError({ operation: 'acp.client.disconnect' })`
267
+ - ❌ `CacheReadFailedError` / `CacheWriteFailedError` → `NameErrors.FileParseError` / `NameErrors.OperationFailedError`
268
+
269
+ ### 6. Internationalization (i18n)
270
+
271
+ All user-facing strings (banner / help / command output / error hints) go through `t()`, with `zh-CN` (default) / `en-US` support.
272
+
273
+ ```typescript
274
+ import { t, I18n, registerI18nResources } from '@easbot/acp';
275
+
276
+ // 1. Main translation function
277
+ console.log(t('cli.cmd.init.description'));
278
+ // → "初始化 acp 工作区(创建 .easbot/acp.json)" (zh-CN)
279
+ // → "Initialize acp workspace (creates .easbot/acp.json)" (en-US)
280
+
281
+ // 2. Template interpolation
282
+ console.log(t('cli.init.created', { vars: { path: '/Users/xiaomo/demo/.easbot/acp.json' } }));
283
+ // → "✓ acp 配置已初始化到 /Users/xiaomo/demo/.easbot/acp.json"
284
+
285
+ // 3. Explicit locale
286
+ console.log(t('cli.banner.title', { locale: 'en-US' }));
287
+
288
+ // 4. Missing-key fallback
289
+ console.log(t('cli.unknown.key', { fallback: 'fallback string' }));
290
+
291
+ // 5. Register custom resources (optional)
292
+ registerI18nResources('zh-CN', {
293
+ translation: {
294
+ 'acp.custom.key': '自定义中文文案',
295
+ },
296
+ });
297
+ ```
298
+
299
+ **locale priority**: explicit arg > `process.env.EASBOT_LANG` > `process.env.LANG` > `I18n.defaultLocale` (zh-CN)
300
+
301
+ **Translation key convention**: `<module>.<action>.<result>` (cli.banner / cli.cmd / cli.init / cli.start / cli.status / cli.doctor / cli.config / acp.cli / acp.error)
302
+
303
+ **Supported locales**:
304
+
305
+ | Locale | File | Status |
306
+ | ------- | ------------------ | ---------- |
307
+ | `zh-CN` | `locales/zh-CN.ts` | ✅ default |
308
+ | `en-US` | `locales/en-US.ts` | ✅ |
309
+
310
+ **Spec alignment**: `spec/internationalization-standard.md` v2.1.0
311
+
312
+ ### 7. host ↔ package decoupling (ADR 0066)
313
+
314
+ ```typescript
315
+ import { setGlobalAdapter, setInstanceAdapter } from '@easbot/acp';
316
+
317
+ // Inject during agent bootstrap
318
+ setGlobalAdapter({
319
+ Path: {
320
+ home: '/Users/xiaomo',
321
+ data: '/Users/xiaomo/.local/share/easbot',
322
+ config: '/Users/xiaomo/.config/easbot',
323
+ cache: '/Users/xiaomo/.cache/easbot',
324
+ // ...
325
+ },
326
+ });
327
+ setInstanceAdapter({
328
+ directory: '/Users/xiaomo/projects/demo',
329
+ worktree: '/Users/xiaomo/projects/demo',
330
+ });
331
+ ```
332
+
333
+ ## CLI commands
334
+
335
+ 5 sub-commands (v0.1 scope):
336
+
337
+ ### lifecycle (3)
338
+
339
+ - **`init`** — initialize workspace (creates `.easbot/acp.json`)
340
+ - `--channel <stdio|http|websocket>`: default channel
341
+ - `--port <n>`: port (http/websocket)
342
+ - `--hostname <addr>`: hostname
343
+ - `--force`: overwrite existing config
344
+ - `--json`: JSON output
345
+
346
+ - **`status`** — show config summary (server channel / port / clients)
347
+ - `--json`: JSON output
348
+
349
+ - **`doctor`** — health check (config loadable / schema valid / deps)
350
+ - `--json`: JSON output
351
+
352
+ ### server (1)
353
+
354
+ - **`start`** — start ACP server, blocks until Ctrl+C / SIGTERM
355
+ - `--channel <stdio|http|websocket>`
356
+ - `--port <n>`
357
+ - `--hostname <addr>`
358
+ - `--timeout <ms>`
359
+
360
+ ### external (1)
361
+
362
+ - **`config`** — get / set acp config
363
+ - `easbot-acp config get [key]` (dot-path like `server.channel`)
364
+ - `easbot-acp config set <key> <value>` (auto-detects number / boolean)
365
+
366
+ ### Global flags (aligned with agent / note)
367
+
368
+ - `--cwd <dir>`: workspace directory
369
+ - `--config <path>`: global config file path
370
+ - `--log-level <DEBUG|INFO|WARN|ERROR>`: default INFO
371
+ - `--print-logs`: print logs to stderr
372
+ - `--debug`: equivalent to `--log-level DEBUG`
373
+
374
+ ### Usage examples
375
+
376
+ ```bash
377
+ # Standalone CLI (user at project root)
378
+ $ easbot-acp init --channel websocket --port 3000
379
+ ✓ acp config initialized at /Users/xiaomo/demo/.easbot/acp.json
380
+
381
+ $ easbot-acp status
382
+ directory: /Users/xiaomo/demo
383
+ server.channel: websocket
384
+ server.port: 3000
385
+ server.hostname: localhost
386
+ server.enabled: true
387
+ clients: 0
388
+
389
+ $ easbot-acp config set server.port 8080
390
+ ✓ set server.port = 8080
391
+
392
+ $ easbot-acp start --channel websocket
393
+ [acp] server starting on ws://localhost:8080
394
+ ^C
395
+ [acp] server received signal, shutting down
396
+
397
+ # Agent CLI (reuses @easbot/agent)
398
+ $ easbot acp start --channel http --port 3000
399
+ ```
400
+
401
+ ## Architecture
402
+
403
+ ```
404
+ ┌─────────────────────────────────────────────────────────┐
405
+ │ @easbot/agent │
406
+ │ ├─ cli/commands/acp.ts (agent acp serve subcommand) │
407
+ │ └─ api/, session/, scheduler/, ... │
408
+ └────────────┬─────────────────────────────────────────────┘
409
+ │ reuses handleAcpCli / mergeConfig pattern
410
+ ▼
411
+ ┌─────────────────────────────────────────────────────────┐
412
+ │ @easbot/acp (this package) │
413
+ │ ├─ cli.ts / cli-handler.ts (standalone CLI entry) │
414
+ │ ├─ cache/ (AcpCache namespace) │
415
+ │ ├─ config/ (schema + loader + accessors) │
416
+ │ ├─ errors.ts (AcpError namespace) │
417
+ │ ├─ interfaces.ts (host ↔ package decoupling) │
418
+ │ ├─ server/ (acp-server / http-server / ws-server) │
419
+ │ ├─ client/ (acp-client / stdio / http / ws subscriber) │
420
+ │ ├─ connection/ (registry / router) │
421
+ │ ├─ event/ (acp-event-bridge) │
422
+ │ ├─ performance/ (performance-monitor / streaming) │
423
+ │ ├─ error/ (error-handler / timeout-manager) │
424
+ │ ├─ types/ (adapter / channel / error / event) │
425
+ │ ├─ bootstrap/ (EasbotAdapter) │
426
+ │ └─ easbot-agent.ts (EasBotAgent instance) │
427
+ └─────────────────────────────────────────────────────────┘
428
+ ```
429
+
430
+ ## Differences from note / gateway / memory
431
+
432
+ | Dimension | note | gateway | acp |
433
+ | ----------------------- | --------------------- | ------------------------- | ------------------------- |
434
+ | L2 config file name | `note.json` | `gateway.json` | `acp.json` |
435
+ | L2 cache name | `NoteCache` | (no L2 cache) | `AcpCache` |
436
+ | Error namespace | `NoteError` | `GatewayError` | `AcpError` |
437
+ | Business code whitelist | 13 | (not registered) | 5 |
438
+ | Command count | 11 | 0 (no standalone CLI) | 5 |
439
+ | Top-level deps | LLM / DB / parser | hono / undici / ws | @agentclientprotocol/sdk |
440
+ | Config loading | single-file NoteCache | multi-dir mixed (gateway) | multi-dir mixed (gateway) |
441
+
442
+ ## Development commands
443
+
444
+ ```bash
445
+ # Build (tsup, outputs ESM + CJS + DTS)
446
+ pnpm --filter @easbot/acp build
447
+
448
+ # Watch mode
449
+ pnpm --filter @easbot/acp dev
450
+
451
+ # Type check
452
+ pnpm --filter @easbot/acp type-check
453
+
454
+ # Lint (biome)
455
+ pnpm --filter @easbot/acp lint
456
+
457
+ # Lint fix
458
+ pnpm --filter @easbot/acp lint:fix
459
+
460
+ # Unit tests
461
+ pnpm --filter @easbot/acp test:run
462
+
463
+ # Unit tests + coverage
464
+ pnpm --filter @easbot/acp test:coverage
465
+
466
+ # Clean test fixtures
467
+ pnpm --filter @easbot/acp test:clean
468
+ ```
469
+
470
+ ## Design principles
471
+
472
+ 1. **host ↔ package decoupling**: all runtime dependencies are explicitly injected via `setGlobalAdapter / setInstanceAdapter`; agent package / standalone CLI / tests share the same semantics
473
+ 2. **Multi-directory config loading**: mirrors `packages/gateway/src/config/loader.ts`, with JSONC + env substitution + State.holder three-piece set
474
+ 3. **Error layering**: in-package `AcpError` (business semantics) + `NameErrors` (generic) + `ServiceError + ServiceErrorBus` (LLM business feedback)
475
+ 4. **CLI / handler separation**: `handleAcpCli(args, deps)` entry is independently testable; agent / standalone CLI / MCP server reuse the same dispatch logic
476
+ 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)
477
+ 6. **Independent cache**: `AcpCache` is fully isolated from the global `easbot.json`; project-level `.easbot/acp.json` is managed as a single file
478
+
479
+ ## Split history
480
+
481
+ | Version | Key changes |
482
+ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
483
+ | **Earlier (within agent)** | `packages/agent/src/adapter/` — ACP adapter coupled with agent package |
484
+ | **v0.1 (2026-10-06)** | Split into standalone workspace package `@easbot/acp`; added cli / errors / cache / config loader; agent now reuses `@easbot/acp` entry |
485
+ | **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) |
486
+
487
+ ## References
488
+
489
+ - [`@agentclientprotocol/sdk`](https://github.com/agentclientprotocol/typescript-sdk) — official TypeScript SDK for ACP protocol
490
+ - `packages/note/src/cli-handler.ts` — CLI handler reference
491
+ - `packages/gateway/src/config/loader.ts` — multi-directory config loader reference
492
+ - `packages/note/src/cache/index.ts` — same-source reference for AcpCache (Pattern E)
493
+ - `packages/note/src/errors.ts` — same-source reference for AcpError
494
+ - `ADR 0066` — host ↔ package decoupling specification
495
+ - `ADR 0102 Phase 2.1` — ServiceError + NamedError business feedback channel