7.7 KiB
7.7 KiB
OpenACP: Publish as npm Package
Goal
Publish OpenACP as a single npm package openacp so users can run it with one command:
npx openacp
Current State
- Monorepo with pnpm workspaces:
@openacp/core+@openacp/adapter-telegram - Root
package.jsonis"private": true main.tsimports telegram adapter via relative file path- Install requires git clone + pnpm install + pnpm build
Design
1. Package Identity
- npm name:
openacp(confirmed available) - Binary:
openacp - License: AGPL-3.0
2. Build Pipeline
Keep monorepo structure for development. Add a publish build step that bundles everything into a single publishable package.
Tooling: tsup (esbuild wrapper) for bundling.
Build commands:
pnpm build— existing per-package tsc build for developmentpnpm build:publish— generatesdist-publish/directory ready fornpm publish
Bundle strategy:
- Two entry points for tsup:
cli(frompackages/core/src/cli.ts) andindex(frompackages/core/src/index.ts) cli.tsimports telegram adapter via@openacp/adapter-telegram(workspace dependency), tsup resolves and bundles it- External dependencies stay as dependencies (not bundled):
grammy,zod,nanoid,@agentclientprotocol/sdk - Output: ESM (
"type": "module"),platform: 'node' - Generate declaration files (
.d.ts) via tsupdts: true— may needdts: { resolve: true }for workspace deps - Shebang
#!/usr/bin/env nodeinjected intocli.jsvia tsupbanneroption
Output structure:
dist-publish/
package.json → name: "openacp"
dist/
cli.js → #!/usr/bin/env node, CLI entry point
index.js → library exports (ChannelAdapter, types, etc.)
index.d.ts → type declarations
[chunk files] → shared code between cli and index
README.md → copied from root
3. Package.json (generated)
{
"name": "openacp",
"version": "0.1.0",
"description": "Self-hosted bridge for AI coding agents via ACP protocol",
"type": "module",
"bin": {
"openacp": "./dist/cli.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"files": ["dist/", "README.md"],
"engines": {
"node": ">=20"
},
"dependencies": {
"@agentclientprotocol/sdk": "^0.16.0",
"grammy": "^1.30.0",
"nanoid": "^5.0.0",
"zod": "^3.25.0"
},
"repository": {
"type": "git",
"url": "https://github.com/nicepkg/OpenACP"
},
"license": "AGPL-3.0",
"keywords": ["acp", "ai", "coding-agent", "telegram", "claude", "codex"]
}
4. CLI Entry Points
cli.js handles:
npx openacp → start server
npx openacp install @openacp/adapter-discord → install plugin
npx openacp uninstall @openacp/adapter-discord → uninstall plugin
npx openacp plugins → list installed plugins
npx openacp --version → show version
npx openacp --help → show help
index.js exports library API for third-party adapter developers:
import { ChannelAdapter } from 'openacp'
5. Plugin System
Storage: ~/.openacp/plugins/
~/.openacp/
config.json
plugins/
package.json ← managed by `openacp install`
node_modules/
@openacp/adapter-discord/
Install mechanism:
openacp install <pkg>runsnpm install <pkg>with--prefix ~/.openacp/plugins/- Creates
~/.openacp/plugins/package.jsonif it doesn't exist openacp uninstall <pkg>runsnpm uninstall <pkg>with same prefixopenacp pluginsreads~/.openacp/plugins/package.jsondependencies
Plugin loading:
- Telegram adapter is built-in (bundled), loaded directly
- External adapters configured in
config.jsonwith explicitadapterfield:
{
"channels": {
"telegram": {
"enabled": true,
"botToken": "..."
},
"discord": {
"enabled": true,
"adapter": "@openacp/adapter-discord",
"botToken": "..."
}
}
}
- Core loads external adapters using
createRequirefromnode:modulerooted at~/.openacp/plugins/:
import { createRequire } from 'node:module'
import path from 'node:path'
import os from 'node:os'
const pluginsDir = path.join(os.homedir(), '.openacp', 'plugins')
const pluginRequire = createRequire(path.join(pluginsDir, 'node_modules', '.package.json'))
// To load a plugin adapter:
const adapterModule = await import(pluginRequire.resolve(packageName))
- Each plugin must export an
AdapterFactoryconforming to this interface:
export interface AdapterFactory {
name: string // e.g. "discord"
createAdapter(core: OpenACPCore, config: any): ChannelAdapter
}
Error handling:
- If a configured adapter package is not installed → log error with install instruction, skip that channel
- If package is installed but doesn't export a valid
AdapterFactory→ log error, skip that channel - Server continues running with whatever channels loaded successfully
6. User Experience
First time:
npx openacp
# → Downloads + runs
# → Creates ~/.openacp/config.json with defaults
# → "No channels enabled. Edit ~/.openacp/config.json"
Normal usage:
# Edit config, add bot token...
npx openacp
# → Starts server with telegram built-in
Adding a plugin:
npx openacp install @openacp/adapter-discord
# → Installs to ~/.openacp/plugins/
# Edit config to add discord channel
npx openacp
# → Starts with telegram (built-in) + discord (plugin)
7. Version Management
- Version sourced from root
package.json(represents the whole project) - Build script copies version into
dist-publish/package.json - Publish workflow:
pnpm build:publish && cd dist-publish && npm publish
8. Changes to Existing Code
main.ts (now cli.ts):
- Add CLI argument parsing (start, install, uninstall, plugins)
- Replace relative telegram adapter import with direct bundled import
- Add plugin loading logic for external adapters from
~/.openacp/plugins/
core.ts:
- Add method to load adapter from plugin path
- Accept adapter config with optional
adapterpackage name
config.ts:
- Restructure
channelsschema from fixedz.object({ telegram })toz.record(z.string(), ChannelSchema)to support arbitrary channel names - Base
ChannelSchemahasenabled, optionaladapter(package name), andz.passthrough()for channel-specific config - Telegram channel is recognized by key name
"telegram"and uses built-in adapter (noadapterfield needed) - Other channels require
adapterfield pointing to installed plugin package - Add plugins directory path constant
New files:
packages/core/src/cli.ts— CLI command routing (start, install, uninstall, plugins)packages/core/src/plugin-manager.ts— install/uninstall/list/load pluginstsup.config.ts— build config for publish bundlescripts/build-publish.ts— generates dist-publish/ with package.json, README
9. What Does NOT Change
- Monorepo structure for development
pnpm buildfor dev builds@openacp/coreand@openacp/adapter-telegraminternal package names- Existing adapter interface (
ChannelAdapterabstract class) - Config file format (backwards compatible — existing telegram config still works,
adapterfield is optional for built-in channels)
10. Future Considerations
- Plugin adapters for Discord, Slack, WhatsApp etc. published as
@openacp/adapter-* - Agent plugins could follow same pattern:
@openacp/agent-* openacp pluginscould show available plugins from a registry