acp-discord 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Randy
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 ADDED
@@ -0,0 +1,112 @@
1
+ # acp-discord
2
+
3
+ Discord bot that connects coding agents (Claude Code, Codex, etc.) to Discord channels via the [Agent Client Protocol (ACP)](https://agentclientprotocol.org/).
4
+
5
+ Send a message in Discord, get AI coding assistance back — with tool call visualization, permission prompts, and real-time streaming.
6
+
7
+ ## Features
8
+
9
+ - **Slash commands & mentions** — `/ask <message>` or `@bot message`
10
+ - **Real-time streaming** — agent responses stream into Discord with smart message splitting
11
+ - **Tool call visualization** — see what the agent is doing with emoji status indicators
12
+ - **Permission UI** — Discord buttons for approving/denying agent actions
13
+ - **Multi-agent support** — different channels can use different agents
14
+ - **Daemon mode** — runs in background with auto-start (systemd/launchd)
15
+ - **Interactive setup** — guided `init` wizard for first-time configuration
16
+
17
+ ## Prerequisites
18
+
19
+ - Node.js >= 18
20
+ - A Discord bot token ([create one here](https://discord.com/developers/applications))
21
+ - **An ACP-compatible coding agent installed and working** — the `init` wizard uses an agent to help generate your config. For example, install [Claude Code](https://docs.anthropic.com/en/docs/claude-code) and verify it runs with `claude --version`.
22
+
23
+ ## Quick Start
24
+
25
+ ```bash
26
+ # Run the setup wizard (interactive, agent-driven)
27
+ npx acp-discord init
28
+
29
+ # Start the daemon
30
+ npx acp-discord daemon start
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ Config lives at `~/.acp-discord/config.toml`:
36
+
37
+ ```toml
38
+ [discord]
39
+ token = "your-discord-bot-token"
40
+
41
+ [agents.claude]
42
+ command = "claude-code"
43
+ args = ["--acp"]
44
+ cwd = "/path/to/your/project"
45
+ idle_timeout = 600 # seconds, optional
46
+
47
+ [channels.1234567890123456]
48
+ agent = "claude"
49
+ cwd = "/override/path" # optional, per-channel override
50
+ ```
51
+
52
+ ### Discord Bot Setup
53
+
54
+ 1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
55
+ 2. Create a new application → Bot → copy the token
56
+ 3. Enable **Message Content Intent** under Bot settings
57
+ 4. Invite the bot to your server with `bot` + `applications.commands` scopes
58
+ 5. Copy the channel ID(s) you want the bot to respond in (right-click channel → Copy Channel ID)
59
+
60
+ ## Usage
61
+
62
+ ### CLI Commands
63
+
64
+ ```bash
65
+ # Interactive setup wizard
66
+ acp-discord init
67
+
68
+ # Daemon management
69
+ acp-discord daemon start # Start in background
70
+ acp-discord daemon run # Run in foreground (for service managers)
71
+ acp-discord daemon stop # Graceful shutdown
72
+ acp-discord daemon status # Check if running
73
+
74
+ # Auto-start on boot
75
+ acp-discord daemon enable # Setup systemd (Linux) / launchd (macOS)
76
+ acp-discord daemon disable # Remove auto-start
77
+ ```
78
+
79
+ ### Discord Commands
80
+
81
+ | Command | Description |
82
+ |---------|-------------|
83
+ | `/ask <message>` | Send a prompt to the coding agent |
84
+ | `@bot <message>` | Mention the bot to send a prompt |
85
+
86
+ ### Development
87
+
88
+ ```bash
89
+ pnpm dev # Run with tsx (auto-reload)
90
+ pnpm test # Run tests
91
+ pnpm test:watch # Watch mode
92
+ ```
93
+
94
+ ## Architecture
95
+
96
+ ```
97
+ Discord User
98
+ ↓ slash command / mention
99
+ Discord Bot (discord.js)
100
+ ↓ channel routing
101
+ Session Manager (per-channel sessions)
102
+ ↓ spawn agent subprocess
103
+ ACP Client (JSON-RPC over stdio)
104
+ ↓ prompt / permissions / tool calls
105
+ Agent (claude-code, codex, etc.)
106
+
107
+ Discord messages, embeds, buttons
108
+ ```
109
+
110
+ ## License
111
+
112
+ MIT
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli/pid.ts
4
+ import { readFileSync, writeFileSync, unlinkSync, existsSync, mkdirSync } from "fs";
5
+ import { dirname } from "path";
6
+ function writePid(pidPath, pid) {
7
+ mkdirSync(dirname(pidPath), { recursive: true });
8
+ writeFileSync(pidPath, String(pid), "utf-8");
9
+ }
10
+ function readPid(pidPath) {
11
+ if (!existsSync(pidPath)) return null;
12
+ const content = readFileSync(pidPath, "utf-8").trim();
13
+ const pid = parseInt(content, 10);
14
+ return isNaN(pid) ? null : pid;
15
+ }
16
+ function removePid(pidPath) {
17
+ if (existsSync(pidPath)) unlinkSync(pidPath);
18
+ }
19
+ function isDaemonRunning(pidPath) {
20
+ const pid = readPid(pidPath);
21
+ if (pid === null) return false;
22
+ try {
23
+ process.kill(pid, 0);
24
+ return true;
25
+ } catch {
26
+ return false;
27
+ }
28
+ }
29
+
30
+ // src/shared/config.ts
31
+ import { parse } from "smol-toml";
32
+ import { readFileSync as readFileSync2 } from "fs";
33
+ function parseConfig(toml) {
34
+ const raw = parse(toml);
35
+ const discord = raw.discord;
36
+ if (!discord?.token || typeof discord.token !== "string") {
37
+ throw new Error("Missing required: discord.token");
38
+ }
39
+ if (discord.token.trim().length === 0) {
40
+ throw new Error("discord.token must not be empty");
41
+ }
42
+ const agents = raw.agents;
43
+ if (!agents || Object.keys(agents).length === 0) {
44
+ throw new Error("Missing required: at least one agent in [agents.*]");
45
+ }
46
+ const parsedAgents = {};
47
+ for (const [name, agent] of Object.entries(agents)) {
48
+ if (!agent.command || typeof agent.command !== "string") {
49
+ throw new Error(`agents.${name}.command must be a non-empty string`);
50
+ }
51
+ if (agent.args !== void 0) {
52
+ if (!Array.isArray(agent.args) || !agent.args.every((a) => typeof a === "string")) {
53
+ throw new Error(`agents.${name}.args must be an array of strings`);
54
+ }
55
+ }
56
+ if (agent.idle_timeout !== void 0) {
57
+ if (typeof agent.idle_timeout !== "number" || agent.idle_timeout <= 0) {
58
+ throw new Error(`agents.${name}.idle_timeout must be a positive number`);
59
+ }
60
+ }
61
+ if (agent.cwd !== void 0 && typeof agent.cwd !== "string") {
62
+ throw new Error(`agents.${name}.cwd must be a string`);
63
+ }
64
+ parsedAgents[name] = {
65
+ command: agent.command,
66
+ args: agent.args ?? [],
67
+ cwd: typeof agent.cwd === "string" ? agent.cwd : process.cwd(),
68
+ idle_timeout: typeof agent.idle_timeout === "number" ? agent.idle_timeout : 600
69
+ };
70
+ }
71
+ const channels = raw.channels ?? {};
72
+ const parsedChannels = {};
73
+ for (const [id, ch] of Object.entries(channels)) {
74
+ const agentRef = ch.agent ?? "default";
75
+ if (typeof agentRef !== "string") {
76
+ throw new Error(`channels.${id}.agent must be a string`);
77
+ }
78
+ if (!parsedAgents[agentRef]) {
79
+ throw new Error(`channels.${id}.agent references unknown agent "${agentRef}"`);
80
+ }
81
+ if (ch.cwd !== void 0 && typeof ch.cwd !== "string") {
82
+ throw new Error(`channels.${id}.cwd must be a string`);
83
+ }
84
+ parsedChannels[id] = {
85
+ agent: agentRef,
86
+ cwd: ch.cwd ? String(ch.cwd) : void 0
87
+ };
88
+ }
89
+ return {
90
+ discord: { token: String(discord.token) },
91
+ agents: parsedAgents,
92
+ channels: parsedChannels
93
+ };
94
+ }
95
+ function loadConfig(configPath) {
96
+ const content = readFileSync2(configPath, "utf-8");
97
+ return parseConfig(content);
98
+ }
99
+ function resolveChannelConfig(config, channelId) {
100
+ const channelConf = config.channels[channelId];
101
+ if (!channelConf) return null;
102
+ const agentConf = config.agents[channelConf.agent];
103
+ if (!agentConf) return null;
104
+ return {
105
+ channelId,
106
+ agent: {
107
+ ...agentConf,
108
+ cwd: channelConf.cwd ?? agentConf.cwd
109
+ }
110
+ };
111
+ }
112
+
113
+ export {
114
+ writePid,
115
+ readPid,
116
+ removePid,
117
+ isDaemonRunning,
118
+ parseConfig,
119
+ loadConfig,
120
+ resolveChannelConfig
121
+ };
122
+ //# sourceMappingURL=chunk-SITRIFHO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli/pid.ts","../src/shared/config.ts"],"sourcesContent":["import { readFileSync, writeFileSync, unlinkSync, existsSync, mkdirSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\n\nexport function writePid(pidPath: string, pid: number): void {\n mkdirSync(dirname(pidPath), { recursive: true });\n writeFileSync(pidPath, String(pid), \"utf-8\");\n}\n\nexport function readPid(pidPath: string): number | null {\n if (!existsSync(pidPath)) return null;\n const content = readFileSync(pidPath, \"utf-8\").trim();\n const pid = parseInt(content, 10);\n return isNaN(pid) ? null : pid;\n}\n\nexport function removePid(pidPath: string): void {\n if (existsSync(pidPath)) unlinkSync(pidPath);\n}\n\nexport function isDaemonRunning(pidPath: string): boolean {\n const pid = readPid(pidPath);\n if (pid === null) return false;\n try {\n process.kill(pid, 0); // signal 0 = check if process exists\n return true;\n } catch {\n return false;\n }\n}\n","import { parse } from \"smol-toml\";\nimport { readFileSync } from \"node:fs\";\nimport type { AppConfig, ResolvedChannelConfig } from \"./types.js\";\n\nexport function parseConfig(toml: string): AppConfig {\n const raw = parse(toml) as Record<string, unknown>;\n\n const discord = raw.discord as Record<string, unknown> | undefined;\n if (!discord?.token || typeof discord.token !== \"string\") {\n throw new Error(\"Missing required: discord.token\");\n }\n if (discord.token.trim().length === 0) {\n throw new Error(\"discord.token must not be empty\");\n }\n\n const agents = raw.agents as Record<string, Record<string, unknown>> | undefined;\n if (!agents || Object.keys(agents).length === 0) {\n throw new Error(\"Missing required: at least one agent in [agents.*]\");\n }\n\n const parsedAgents: AppConfig[\"agents\"] = {};\n for (const [name, agent] of Object.entries(agents)) {\n // Validate command is a non-empty string\n if (!agent.command || typeof agent.command !== \"string\") {\n throw new Error(`agents.${name}.command must be a non-empty string`);\n }\n\n // Validate args is an array of strings\n if (agent.args !== undefined) {\n if (!Array.isArray(agent.args) || !agent.args.every((a: unknown) => typeof a === \"string\")) {\n throw new Error(`agents.${name}.args must be an array of strings`);\n }\n }\n\n // Validate idle_timeout is a positive number\n if (agent.idle_timeout !== undefined) {\n if (typeof agent.idle_timeout !== \"number\" || agent.idle_timeout <= 0) {\n throw new Error(`agents.${name}.idle_timeout must be a positive number`);\n }\n }\n\n // Validate cwd is a string if provided\n if (agent.cwd !== undefined && typeof agent.cwd !== \"string\") {\n throw new Error(`agents.${name}.cwd must be a string`);\n }\n\n parsedAgents[name] = {\n command: agent.command,\n args: (agent.args as string[]) ?? [],\n cwd: typeof agent.cwd === \"string\" ? agent.cwd : process.cwd(),\n idle_timeout: typeof agent.idle_timeout === \"number\" ? agent.idle_timeout : 600,\n };\n }\n\n const channels = (raw.channels ?? {}) as Record<string, Record<string, unknown>>;\n const parsedChannels: AppConfig[\"channels\"] = {};\n for (const [id, ch] of Object.entries(channels)) {\n const agentRef = ch.agent ?? \"default\";\n if (typeof agentRef !== \"string\") {\n throw new Error(`channels.${id}.agent must be a string`);\n }\n if (!parsedAgents[agentRef]) {\n throw new Error(`channels.${id}.agent references unknown agent \"${agentRef}\"`);\n }\n if (ch.cwd !== undefined && typeof ch.cwd !== \"string\") {\n throw new Error(`channels.${id}.cwd must be a string`);\n }\n\n parsedChannels[id] = {\n agent: agentRef,\n cwd: ch.cwd ? String(ch.cwd) : undefined,\n };\n }\n\n return {\n discord: { token: String(discord.token) },\n agents: parsedAgents,\n channels: parsedChannels,\n };\n}\n\nexport function loadConfig(configPath: string): AppConfig {\n const content = readFileSync(configPath, \"utf-8\");\n return parseConfig(content);\n}\n\nexport function resolveChannelConfig(\n config: AppConfig,\n channelId: string,\n): ResolvedChannelConfig | null {\n const channelConf = config.channels[channelId];\n if (!channelConf) return null;\n\n const agentConf = config.agents[channelConf.agent];\n if (!agentConf) return null;\n\n return {\n channelId,\n agent: {\n ...agentConf,\n cwd: channelConf.cwd ?? agentConf.cwd,\n },\n };\n}\n"],"mappings":";;;AAAA,SAAS,cAAc,eAAe,YAAY,YAAY,iBAAiB;AAC/E,SAAS,eAAe;AAEjB,SAAS,SAAS,SAAiB,KAAmB;AAC3D,YAAU,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AAC/C,gBAAc,SAAS,OAAO,GAAG,GAAG,OAAO;AAC7C;AAEO,SAAS,QAAQ,SAAgC;AACtD,MAAI,CAAC,WAAW,OAAO,EAAG,QAAO;AACjC,QAAM,UAAU,aAAa,SAAS,OAAO,EAAE,KAAK;AACpD,QAAM,MAAM,SAAS,SAAS,EAAE;AAChC,SAAO,MAAM,GAAG,IAAI,OAAO;AAC7B;AAEO,SAAS,UAAU,SAAuB;AAC/C,MAAI,WAAW,OAAO,EAAG,YAAW,OAAO;AAC7C;AAEO,SAAS,gBAAgB,SAA0B;AACxD,QAAM,MAAM,QAAQ,OAAO;AAC3B,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI;AACF,YAAQ,KAAK,KAAK,CAAC;AACnB,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;;;AC5BA,SAAS,aAAa;AACtB,SAAS,gBAAAA,qBAAoB;AAGtB,SAAS,YAAY,MAAyB;AACnD,QAAM,MAAM,MAAM,IAAI;AAEtB,QAAM,UAAU,IAAI;AACpB,MAAI,CAAC,SAAS,SAA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