thepopebot 1.2.76-beta.8 → 1.2.77

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 (161) hide show
  1. package/README.md +147 -124
  2. package/api/CLAUDE.md +21 -10
  3. package/api/index.js +170 -57
  4. package/bin/CLAUDE.md +7 -4
  5. package/bin/cli.js +44 -67
  6. package/bin/docker-build.js +80 -53
  7. package/bin/sync.js +18 -1
  8. package/config/CLAUDE.md +24 -4
  9. package/config/instrumentation.js +29 -1
  10. package/drizzle/0022_organic_apocalypse.sql +16 -0
  11. package/drizzle/0023_needy_ender_wiggin.sql +1 -0
  12. package/drizzle/0024_third_moondragon.sql +3 -0
  13. package/drizzle/0025_common_psylocke.sql +51 -0
  14. package/drizzle/0026_parched_king_bedlam.sql +1 -0
  15. package/drizzle/meta/0021_snapshot.json +639 -0
  16. package/drizzle/meta/0022_snapshot.json +743 -0
  17. package/drizzle/meta/0023_snapshot.json +750 -0
  18. package/drizzle/meta/0024_snapshot.json +771 -0
  19. package/drizzle/meta/0025_snapshot.json +734 -0
  20. package/drizzle/meta/0026_snapshot.json +742 -0
  21. package/drizzle/meta/_journal.json +35 -0
  22. package/lib/CLAUDE.md +4 -2
  23. package/lib/actions.js +3 -1
  24. package/lib/ai/CLAUDE.md +75 -57
  25. package/lib/ai/helper-llm.js +108 -0
  26. package/lib/ai/index.js +375 -459
  27. package/lib/ai/line-mappers.js +47 -26
  28. package/lib/ai/scope.js +26 -0
  29. package/lib/ai/sdk-adapters/CLAUDE.md +4 -3
  30. package/lib/ai/sdk-adapters/claude-code.js +34 -14
  31. package/lib/ai/system-prompt.js +23 -5
  32. package/lib/ai/workspace-setup.js +32 -99
  33. package/lib/auth/CLAUDE.md +13 -0
  34. package/lib/auth/actions.js +15 -22
  35. package/lib/auth/index.js +20 -0
  36. package/lib/channels/CLAUDE.md +14 -4
  37. package/lib/channels/base.js +6 -2
  38. package/lib/channels/commands/index.js +42 -0
  39. package/lib/channels/commands/session.js +53 -0
  40. package/lib/channels/commands/verify.js +18 -0
  41. package/lib/channels/telegram.js +79 -28
  42. package/lib/chat/CLAUDE.md +14 -10
  43. package/lib/chat/actions.js +286 -96
  44. package/lib/chat/api.js +89 -26
  45. package/lib/chat/components/CLAUDE.md +22 -15
  46. package/lib/chat/components/app-sidebar.js +7 -20
  47. package/lib/chat/components/app-sidebar.jsx +28 -26
  48. package/lib/chat/components/chat-input.js +45 -23
  49. package/lib/chat/components/chat-input.jsx +42 -20
  50. package/lib/chat/components/chat-page.js +2 -0
  51. package/lib/chat/components/chat-page.jsx +3 -0
  52. package/lib/chat/components/chat.js +97 -95
  53. package/lib/chat/components/chat.jsx +66 -53
  54. package/lib/chat/components/code-mode-toggle.js +141 -72
  55. package/lib/chat/components/code-mode-toggle.jsx +148 -96
  56. package/lib/chat/components/containers-page.js +58 -40
  57. package/lib/chat/components/containers-page.jsx +64 -25
  58. package/lib/chat/components/crons-page.js +17 -3
  59. package/lib/chat/components/crons-page.jsx +34 -6
  60. package/lib/chat/components/index.js +4 -4
  61. package/lib/chat/components/message.js +16 -1
  62. package/lib/chat/components/message.jsx +16 -1
  63. package/lib/chat/components/messages-page.js +138 -0
  64. package/lib/chat/components/messages-page.jsx +180 -0
  65. package/lib/chat/components/profile-page.js +428 -47
  66. package/lib/chat/components/profile-page.jsx +476 -63
  67. package/lib/chat/components/scope-picker.js +21 -0
  68. package/lib/chat/components/scope-picker.jsx +27 -0
  69. package/lib/chat/components/settings-chat-page.js +11 -11
  70. package/lib/chat/components/settings-chat-page.jsx +14 -18
  71. package/lib/chat/components/settings-coding-agents-page.js +152 -16
  72. package/lib/chat/components/settings-coding-agents-page.jsx +125 -3
  73. package/lib/chat/components/settings-github-page.js +5 -0
  74. package/lib/chat/components/settings-github-page.jsx +5 -0
  75. package/lib/chat/components/settings-jobs-page.js +42 -28
  76. package/lib/chat/components/settings-jobs-page.jsx +43 -27
  77. package/lib/chat/components/settings-layout.js +3 -3
  78. package/lib/chat/components/settings-layout.jsx +3 -3
  79. package/lib/chat/components/settings-secrets-layout.js +1 -2
  80. package/lib/chat/components/settings-secrets-layout.jsx +1 -2
  81. package/lib/chat/components/settings-secrets-page.js +180 -75
  82. package/lib/chat/components/settings-secrets-page.jsx +212 -66
  83. package/lib/chat/components/settings-shared.js +2 -2
  84. package/lib/chat/components/settings-shared.jsx +2 -2
  85. package/lib/chat/components/triggers-page.js +17 -3
  86. package/lib/chat/components/triggers-page.jsx +34 -6
  87. package/lib/chat/components/ui/dropdown-menu.js +23 -2
  88. package/lib/chat/components/ui/dropdown-menu.jsx +27 -2
  89. package/lib/chat/telegram-profile.js +34 -0
  90. package/lib/cluster/CLAUDE.md +9 -3
  91. package/lib/code/CLAUDE.md +21 -3
  92. package/lib/code/actions.js +35 -22
  93. package/lib/code/code-page.js +1 -1
  94. package/lib/code/code-page.jsx +3 -1
  95. package/lib/code/terminal-view.js +63 -43
  96. package/lib/code/terminal-view.jsx +49 -27
  97. package/lib/config.js +19 -4
  98. package/lib/containers/CLAUDE.md +17 -6
  99. package/lib/containers/logs.js +12 -0
  100. package/lib/cron.js +32 -4
  101. package/lib/db/CLAUDE.md +21 -7
  102. package/lib/db/chats.js +15 -7
  103. package/lib/db/code-workspaces.js +2 -1
  104. package/lib/db/config.js +0 -1
  105. package/lib/db/index.js +12 -0
  106. package/lib/db/messages.js +117 -0
  107. package/lib/db/schema.js +46 -24
  108. package/lib/db/user-channels.js +152 -0
  109. package/lib/db/users.js +32 -16
  110. package/lib/git-commands.js +41 -0
  111. package/lib/llm-providers.js +8 -0
  112. package/lib/tools/CLAUDE.md +18 -5
  113. package/lib/tools/assemblyai.js +17 -0
  114. package/lib/tools/create-agent-job.js +26 -8
  115. package/lib/tools/docker.js +19 -3
  116. package/lib/tools/github.js +31 -6
  117. package/lib/tools/telegram.js +106 -0
  118. package/lib/triggers.js +38 -1
  119. package/lib/utils/render-md.js +43 -17
  120. package/package.json +8 -7
  121. package/setup/CLAUDE.md +28 -17
  122. package/setup/lib/providers.mjs +2 -1
  123. package/setup/lib/targets.mjs +13 -16
  124. package/setup/setup.mjs +42 -34
  125. package/templates/.env.example +0 -7
  126. package/templates/.github/workflows/notify-pr-complete.yml +5 -1
  127. package/templates/.github/workflows/rebuild-event-handler.yml +1 -6
  128. package/templates/.gitignore.template +0 -2
  129. package/templates/CLAUDE.md.template +28 -6
  130. package/templates/agent-job/CLAUDE.md.template +11 -4
  131. package/templates/agent-job/CRONS.json +16 -0
  132. package/templates/agent-job/SYSTEM.md +17 -9
  133. package/templates/agents/CLAUDE.md.template +17 -17
  134. package/templates/data/CLAUDE.md.template +1 -1
  135. package/templates/docker-compose.custom.yml +1 -0
  136. package/templates/docker-compose.yml +1 -0
  137. package/templates/event-handler/CLAUDE.md.template +84 -0
  138. package/templates/event-handler/TRIGGERS.json +18 -2
  139. package/templates/skills/CLAUDE.md.template +12 -119
  140. package/templates/skills-library/CLAUDE.md.template +151 -0
  141. package/templates/skills-library/agent-job-background/SKILL.md +34 -0
  142. package/templates/skills-library/agent-job-background/agent-job-background.js +78 -0
  143. package/templates/skills-library/agent-job-dm/SKILL.md +55 -0
  144. package/templates/skills-library/agent-job-dm/agent-job-dm.js +81 -0
  145. package/templates/skills-library/agent-job-secrets/SKILL.md +23 -0
  146. package/templates/skills-library/agent-job-secrets/agent-job-secrets.js +68 -0
  147. package/lib/ai/agent.js +0 -65
  148. package/lib/ai/async-channel.js +0 -51
  149. package/lib/ai/model.js +0 -130
  150. package/lib/ai/tools.js +0 -167
  151. package/lib/chat/components/notifications-page.js +0 -89
  152. package/lib/chat/components/notifications-page.jsx +0 -126
  153. package/lib/db/notifications.js +0 -104
  154. package/lib/tools/openai.js +0 -37
  155. package/setup/lib/telegram-verify.mjs +0 -63
  156. package/setup/lib/telegram.mjs +0 -76
  157. package/setup/setup-telegram.mjs +0 -260
  158. package/templates/skills/active/.gitkeep +0 -0
  159. package/templates/skills/library/agent-job-secrets/SKILL.md +0 -23
  160. package/templates/skills/library/agent-job-secrets/agent-job-secrets.js +0 -62
  161. /package/templates/{skills/library → skills-library}/playwright-cli/SKILL.md +0 -0
package/README.md CHANGED
@@ -1,194 +1,217 @@
1
- # ThePopeBot
1
+ # thepopebot
2
2
 
3
- Build autonomous AI agents that work for you 24/7, individually or in teams.
3
+ Your personal agent, coding environment, and communication platform all in
4
+ one app. Works with any LLM or coding agent. Designed to be simple, unified,
5
+ secure, and easy.
4
6
 
5
- ### What You Get
7
+ - 💬 **Smart chat integrations** — Telegram today; Slack and Discord coming soon. Plus the built-in web chat.
8
+ - 🧠 **Any LLM** — Anthropic, OpenAI, Google, DeepSeek, MiniMax, Mistral, xAI, Kimi, OpenRouter, NVIDIA, or any OpenAI-compatible endpoint.
9
+ - 🤖 **Any coding agent** — Claude Code, Codex, Gemini, OpenCode, Pi, or Kimi.
10
+ - 💻 **Live coding workspaces** — open a terminal in your browser, attach to a running container, share the same session as your chat.
11
+ - 🔧 **Real work, not just chat** — agent writes code, opens a PR, auto-merges, DMs you when it's done.
12
+ - 🔐 **Yours, fully** — runs on your hardware, your repo, your tokens.
6
13
 
7
- - **Runs 24/7** set up tasks and your agent handles them around the clock, no babysitting
8
- - **Does real work** — writes code, opens pull requests, completes multi-step tasks end to end
9
- - **Agent clusters** — build teams of agents that coordinate and work together on bigger jobs
10
- - **Full visibility** — every action is a commit you can review, approve, or undo
11
-
12
- <a href="https://www.skool.com/ai-architects"><img src="docs/hero.png" width="100" alt="ThePopeBot" /></a>
14
+ <a href="https://www.skool.com/ai-architects"><img src="docs/hero.png" width="100" alt="thepopebot" /></a>
13
15
 
14
16
  [Get priority support HERE](https://www.skool.com/ai-architects)
15
17
 
16
18
  ---
17
19
 
18
- ## How It Works
20
+ ## How it works
21
+
22
+ Three doors, one brain:
19
23
 
20
24
  ```
21
- ┌──────────────────────────────────────────────────────────────────────┐
22
-
23
- ┌─────────────────┐ ┌─────────────────┐ │
24
- │ │ Event Handler ──1──► │ GitHub │ │
25
- │ │ (creates branch)(agent-job/* br) │ │
26
- └────────▲────────┘ └─────────────────┘
27
-
28
- 2 (launches Docker container locally)
29
-
30
-
31
- ┌─────────────────┐ │
32
- │ Docker Agent │ │
33
- │ (coding agent) │ │
34
- │ └────────┬────────┘ │
35
- │ │ │
36
- │ │ 3 (commits, pushes, creates PR) │
37
-
38
-
39
- ┌─────────────────┐
40
- GitHub
41
- │ │ (PR opened)
42
- └────────┬────────┘
43
-
44
- 4a (auto-merge.yml)
45
- 4b (rebuild-event-handler.yml)
46
- │ │ │
47
- │ 5 (notify-pr-complete.yml → │
48
- │ │ webhook to event handler) │
49
- │ └──────────────────────────► Event Handler │
50
- │ │
51
- └──────────────────────────────────────────────────────────────────────┘
25
+ ┌── Browser chat ──┐ ┌── Telegram (verified per-user)
26
+ ▼ ▼
27
+ ┌──────────────────────────────────┐
28
+ attach The Brain
29
+ a live (your event handler) │
30
+ terminal
31
+ • picks the coding agent
32
+ picks the coding agent
33
+ • remembers the session
34
+ • runs Docker for you │
35
+ └── Code ────┤
36
+ workspace └──────────────┬───────────────────┘
37
+
38
+ ┌────────┴────────┐
39
+ ▼ ▼
40
+ ┌─────────────┐ ┌─────────────────┐
41
+ Live chat Agent job │
42
+ (right now) │ (background) │
43
+ │ │
44
+ same coding │ same coding
45
+ agent runs agent runs in
46
+ in-process │ a fresh Docker │
47
+ or in a container, │
48
+ headless opens a PR,
49
+ container DMs you back
50
+ └─────────────┘ └─────────────────┘
52
51
  ```
53
52
 
54
- You interact with your bot via the web chat interface or Telegram (optional). The Event Handler creates an agent-job branch and launches a Docker container locally with the coding agent. The agent does the work, commits the results, pushes, and opens a PR. Auto-merge handles the rest. You get a notification when it's done.
53
+ ### Live chat vs. agent job
55
54
 
56
- ---
55
+ | Path | When | What happens |
56
+ |----------------|-------------------------------|----------------------------------------------------|
57
+ | **Live chat** | Quick questions, small edits | Coding agent runs now, streams to your screen |
58
+ | **Agent job** | "Build it. DM me when done." | Background worker opens a PR, auto-merges, DMs you |
57
59
 
58
- ## Star History
60
+ ### Two flavors of chat (`chatMode`)
59
61
 
60
- [![Star History Chart](https://api.star-history.com/svg?repos=stephengpope/thepopebot&type=date&legend=top-left)](https://www.star-history.com/#stephengpope/thepopebot&type=date&legend=top-left)
62
+ | `chatMode` | Repo & branch | Use it for |
63
+ |------------|----------------------------|---------------------------------------------|
64
+ | `agent` | Your bot's own repo | Talking *to* your bot — config, skills, ops |
65
+ | `code` | Any repo + branch you pick | Real coding sessions on a project |
66
+
67
+ ### Live coding workspaces
68
+
69
+ Open a workspace from any code-mode chat and the browser attaches a terminal
70
+ to a persistent container running your coding agent of choice. Workspace and
71
+ chat share the same session — fire a question in chat, hop into the terminal,
72
+ the agent already knows what you were just talking about.
73
+
74
+ ### When you ask for a job
75
+
76
+ ```
77
+ you ──► chat ──► event handler ──► creates `agent-job/<id>` branch
78
+
79
+
80
+ launches a Docker container
81
+ locally (your chosen agent)
82
+
83
+
84
+ agent commits, pushes,
85
+ opens a PR
86
+
87
+
88
+ auto-merge.yml ──► merged
89
+
90
+
91
+ notify-pr-complete.yml ──► DM to you
92
+ ```
61
93
 
62
94
  ---
63
95
 
64
- ## Get Started
96
+ ## Install
65
97
 
66
98
  ### Prerequisites
67
99
 
68
100
  | Requirement | Install |
69
101
  |-------------|---------|
70
102
  | **Node.js 18+** | [nodejs.org](https://nodejs.org) |
71
- | **npm** | Included with Node.js |
72
103
  | **Git** | [git-scm.com](https://git-scm.com) |
73
104
  | **GitHub CLI** | [cli.github.com](https://cli.github.com) |
74
- | **Docker + Docker Compose** | [docker.com](https://docs.docker.com/get-docker/) (installer requires admin password) |
75
- | **ngrok*** | [ngrok.com](https://ngrok.com/download) (free account + authtoken required) |
105
+ | **Docker + Docker Compose** | [docker.com](https://docs.docker.com/get-docker/) |
106
+ | **ngrok*** | [ngrok.com](https://ngrok.com/download) (free account + authtoken) |
76
107
 
77
- *\*ngrok is only required for local installs without port forwarding. VPS/cloud deployments don't need it. [Sign up](https://dashboard.ngrok.com/signup) for a free ngrok account, then run `ngrok config add-authtoken <YOUR_TOKEN>` before starting setup.*
108
+ *\*ngrok is only needed for local installs without port forwarding. VPS/cloud deployments don't need it.*
78
109
 
79
110
  ### Two steps
80
111
 
81
- **Step 1** — Scaffold a new project:
82
-
83
112
  ```bash
84
113
  mkdir my-agent && cd my-agent
85
- npx thepopebot@latest init
114
+ npx thepopebot@latest init # scaffold project
115
+ npm run setup # interactive wizard
86
116
  ```
87
117
 
88
- This creates a Next.js project with configuration files, GitHub Actions workflows, and agent templates. You don't need to create a GitHub repo first — the setup wizard handles that.
118
+ The wizard checks prerequisites, creates a GitHub repo, generates a PAT, configures your URL, and starts Docker. Visit your APP_URL when it finishes.
119
+
120
+ > **Local installs**: your server needs to be reachable from the internet for GitHub webhooks and Telegram. Use [ngrok](https://ngrok.com) (`ngrok http 80`). If your ngrok URL changes, run `npx thepopebot set-var APP_URL <new-url>` and re-register the Telegram webhook from `/admin/event-handler/telegram`.
89
121
 
90
- **Step 2** — Run the setup wizard:
122
+ ---
123
+
124
+ ## Upgrade
91
125
 
92
126
  ```bash
93
- npm run setup
127
+ npx thepopebot upgrade # latest stable
128
+ npx thepopebot upgrade @beta # latest beta
129
+ npx thepopebot upgrade 1.2.72 # specific version
130
+ ```
131
+
132
+ Installs the new package, syncs managed files, rebuilds, restarts Docker.
133
+
134
+ ### What's protected, what gets updated
135
+
136
+ Two kinds of files behave differently — by design, so an upgrade never blows
137
+ away your customizations.
138
+
139
+ ```
140
+ ┌─ Managed files ──────────────┐ ┌─ Your files ─────────────────┐
141
+ │ .github/workflows/ │ │ agent-job/SYSTEM.md │
142
+ │ docker-compose.yml │ │ agent-job/CRONS.json │
143
+ │ .gitignore │ │ event-handler/TRIGGERS.json │
144
+ │ │ │ agents/ │
145
+ │ Always replaced with the │ │ skills-library/, skills/ │
146
+ │ latest version on every │ │ .env, secrets │
147
+ │ init / upgrade. │ │ Never touched by upgrade. │
148
+ └──────────────────────────────┘ └──────────────────────────────┘
94
149
  ```
95
150
 
96
- The wizard walks you through everything:
97
- - Checks prerequisites (Node.js, Git, GitHub CLI, Docker)
98
- - Creates a GitHub repository and pushes your initial commit
99
- - Creates a GitHub Personal Access Token (scoped to your repo)
100
- - Configures your public URL and webhook secret
101
- - Syncs settings to `.env`, database, and GitHub secrets/variables
102
- - Starts Docker for you
151
+ So you never lose your work — but you might miss a useful template change.
152
+ Three commands let you pull updates in deliberately:
103
153
 
104
- **That's it.** Visit your APP_URL when the wizard finishes.
154
+ ```bash
155
+ npx thepopebot audit # show what's drifted from the templates
156
+ npx thepopebot diff <file> # show the diff for one file
157
+ npx thepopebot reset <file> # replace one file with the latest template
158
+ npx thepopebot reset-all # ⚠ nuclear: wipe local edits, restore everything
159
+ ```
105
160
 
106
- - **Web Chat**: Visit your APP_URL to chat with your agent, create jobs, upload files
107
- - **Telegram** (optional): Run `npm run setup-telegram` to connect a Telegram bot
108
- - **Webhook**: Send a POST to `/api/create-agent-job` with your API key to create jobs programmatically
109
- - **Cron**: Edit `agent-job/CRONS.json` to schedule recurring jobs
161
+ Use them when release notes mention a SYSTEM.md or workflow improvement you want.
110
162
 
111
- ### Chat vs Agent LLM
163
+ > **Upgrade failed?** See [Recovering from a Failed Upgrade](docs/UPGRADE.md#recovering-from-a-failed-upgrade).
112
164
 
113
- Your bot has two sides — a **chat** side and an **agent** side.
165
+ ---
114
166
 
115
- **Chat** is the conversational part. When you talk to your bot in the web UI or Telegram, it uses the chat LLM. This runs on your server and responds in real time.
167
+ ## How LLMs are wired
116
168
 
117
- **Agent** is the worker. When your bot needs to write code, modify files, or do a bigger task, it spins up a separate job that runs in a Docker container on GitHub. That job uses the agent LLM.
169
+ Two slots, you pick whether they share a model.
118
170
 
119
- By default, both use the same model. But during setup, you can choose different models for each for example, a faster model for chat and a more capable one for agent jobs. The wizard asks "Would you like agent jobs to use different LLM settings?" and lets you pick.
171
+ - **Coding agent** drives **everything you actually talk to**: live chat in the browser/Telegram, code workspaces, and background agent jobs. One agent, one model. For Claude Code the chat runs in-process via the Claude Agent SDK; for any other agent (Pi, Codex, Gemini, OpenCode, Kimi) it runs in an ephemeral headless container same chunk shape either way. Configured at `/admin/event-handler/coding-agents`.
172
+ - **Helper LLM** — small one-shot calls only: chat auto-titles, agent-job titles, PR-merge summaries. Independent provider/model from the coding agent. Configured at `/admin/event-handler/helper-llm`.
120
173
 
121
- ### Using a Claude Subscription (OAuth Token)
174
+ A coding-agent task can override its model per-run via `agent_backend` + `llm_model` on a cron, trigger, or chained agent job.
122
175
 
123
- If you have a Claude Pro ($20/mo) or Max ($100+/mo) subscription, you can use it to power your agent jobs instead of paying per API call. During setup, choose Anthropic as your agent provider and say yes when asked about a subscription.
176
+ ### Using a Claude subscription
124
177
 
125
- You'll need to generate a token:
178
+ If you have Claude Pro or Max, you can power Claude Code with your subscription instead of API billing. Generate a token:
126
179
 
127
180
  ```bash
128
- # Install Claude Code CLI (if you don't have it)
129
181
  npm install -g @anthropic-ai/claude-code
130
-
131
- # Generate your token (opens browser to log in)
132
182
  claude setup-token
133
183
  ```
134
184
 
135
- Paste the token (starts with `sk-ant-oat01-`) into the setup wizard. Your agent jobs will now run through your subscription. Note that usage counts toward your Claude.ai limits, and you still need an API key for the chat side.
136
-
137
- See [Coding Agents](docs/CODING_AGENTS.md) for details on all five agent backends.
185
+ Paste it (starts with `sk-ant-oat01-`) into Admin > Event Handler > Coding Agents > Claude Code (auth mode: OAuth). The same token drives live chat *and* background agent jobs no separate API key needed for chat. Add multiple tokens and they rotate LRU on each container launch.
138
186
 
139
- > **Local installs**: Your server needs to be reachable from the internet for GitHub webhooks and Telegram. On a VPS/cloud server, your APP_URL is just your domain. For local development, use [ngrok](https://ngrok.com) (`ngrok http 80`) or port forwarding to expose your machine.
140
- >
141
- > **If your ngrok URL changes** (it changes every time you restart ngrok on the free plan), you must update APP_URL everywhere:
142
- >
143
- > ```bash
144
- > # Update .env and GitHub variable in one command:
145
- > npx thepopebot set-var APP_URL https://your-new-url.ngrok.io
146
- > # If Telegram is configured, re-register the webhook:
147
- > npm run setup-telegram
148
- > ```
187
+ See [Coding Agents](docs/CODING_AGENTS.md) for details on all six agent backends.
149
188
 
150
189
  ---
151
190
 
152
- ## Updating
191
+ ## Connect Telegram (optional)
153
192
 
154
- ```bash
155
- npx thepopebot upgrade # latest stable
156
- npx thepopebot upgrade @beta # latest beta
157
- npx thepopebot upgrade 1.2.72 # specific version
158
- ```
159
-
160
- Saves your local changes, syncs with GitHub, installs the new version, rebuilds, pushes, and restarts Docker.
161
-
162
- **What it does:**
193
+ Talk to your bot from your phone. Two steps:
163
194
 
164
- 1. Saves any local changes you've made
165
- 2. Pulls the latest from GitHub (stops if there are conflicts)
166
- 3. Installs the new version and updates project files
167
- 4. Rebuilds your project
168
- 5. Pushes everything to GitHub
169
- 6. Restarts Docker containers (if running)
195
+ 1. **Wire up the bot** at `/admin/event-handler/telegram`, paste the bot token from [@BotFather](https://t.me/BotFather) and click **Register webhook**.
196
+ 2. **Verify your account** at `/profile/telegram`, generate a one-time code and send `/verify <code>` to your bot. The bot only responds to verified users; unbound chats are silently dropped.
170
197
 
171
- Pushing to `main` triggers the `rebuild-event-handler.yml` workflow on your server. It detects the version change, runs `thepopebot init`, updates `THEPOPEBOT_VERSION` in the server's `.env`, pulls the new Docker image, restarts the container, rebuilds `.next`, and reloads PM2 — no manual `docker compose` needed.
198
+ Once verified: `/session` lists your active threads, `/session <id>` switches the thread your messages route to. Voice notes are transcribed when an `ASSEMBLYAI_API_KEY` is set in `/admin/event-handler/voice`.
172
199
 
173
- > **Upgrade failed?** See [Recovering from a Failed Upgrade](docs/UPGRADE.md#recovering-from-a-failed-upgrade).
174
-
175
- See [CLI Reference](docs/CLI.md) for full details on `init`, managed vs user files, template conventions, and all CLI commands.
200
+ See [Chat Integrations](docs/CHAT_INTEGRATIONS.md) for the channel adapter pattern and how to add new channels (Slack, Discord coming soon).
176
201
 
177
202
  ---
178
203
 
179
204
  ## Security
180
205
 
181
- thepopebot includes API key authentication, webhook secret validation (fail-closed), session encryption, secret filtering in the Docker agent, and auto-merge path restrictions. However, all software carries risk — thepopebot is provided as-is, and you are responsible for securing your own infrastructure. If you're running locally with a tunnel (ngrok, Cloudflare Tunnel, port forwarding), be aware that your dev server endpoints are publicly accessible with no rate limiting and no TLS on the local hop.
206
+ thepopebot includes API key authentication, webhook secret validation (fail-closed), session encryption (AES-256-GCM keyed off `AUTH_SECRET`), per-job API keys with maintenance-cron expiry, and auto-merge path restrictions. All software carries risk — thepopebot is provided as-is, and you are responsible for securing your own infrastructure. If you're running locally with a tunnel, your dev server endpoints are publicly accessible with no rate limiting and no TLS on the local hop.
182
207
 
183
- See [Security](docs/SECURITY.md) for full details on what's exposed, the risks, and recommendations.
208
+ See [Security](docs/SECURITY.md) for full details.
184
209
 
185
210
  ---
186
211
 
187
- ## Different Models
188
-
189
- thepopebot supports 9 built-in LLM providers (Anthropic, OpenAI, Google, DeepSeek, MiniMax, Mistral, xAI, Kimi, OpenRouter) plus custom OpenAI-compatible endpoints. The chat layer and coding agents are independent — use Claude for interactive chat and a different model for code tasks, or run everything on a single provider.
212
+ ## Star History
190
213
 
191
- See [Different Models](docs/RUNNING_DIFFERENT_MODELS.md) for the full provider reference, admin UI configuration, per-job overrides, and custom provider setup.
214
+ [![Star History Chart](https://api.star-history.com/svg?repos=stephengpope/thepopebot&type=date&legend=top-left)](https://www.star-history.com/#stephengpope/thepopebot&type=date&legend=top-left)
192
215
 
193
216
  ---
194
217
 
@@ -198,8 +221,8 @@ See [Different Models](docs/RUNNING_DIFFERENT_MODELS.md) for the full provider r
198
221
 
199
222
  SQLite can't create or open its shared-memory (`.shm`) file. Common causes:
200
223
 
201
- - **Antivirus** (Windows Defender, etc.) locking the database files — add your project folder to the exclusion list
202
- - **Cloud-synced folders** (OneDrive, Dropbox, Google Drive) — move your project to a non-synced directory like `C:\Projects\`
224
+ - **Antivirus** locking the database — add your project folder to the exclusion list
225
+ - **Cloud-synced folders** (OneDrive, Dropbox, Google Drive) — move your project to a non-synced directory
203
226
 
204
227
  ---
205
228
 
@@ -209,13 +232,13 @@ SQLite can't create or open its shared-memory (`.shm`) file. Common causes:
209
232
  |----------|-------------|
210
233
  | [Architecture](docs/ARCHITECTURE.md) | Two-layer design, file structure, API endpoints, GitHub Actions, Docker agent |
211
234
  | [CLI Reference](docs/CLI.md) | `init`, managed vs user files, template conventions, all CLI commands |
212
- | [Configuration](docs/CONFIGURATION.md) | Admin UI, DB-backed config, infrastructure variables, GitHub secrets, Docker Compose |
213
- | [Customization](docs/CUSTOMIZATION.md) | Personality, skills, operating system files, using your bot, security details |
235
+ | [Configuration](docs/CONFIGURATION.md) | Admin UI, DB-backed config, infrastructure variables, Docker Compose |
236
+ | [Customization](docs/CUSTOMIZATION.md) | Personality, skills, operating system files, using your bot |
214
237
  | [Chat Integrations](docs/CHAT_INTEGRATIONS.md) | Web chat, Telegram, adding new channels |
215
- | [Different Models](docs/RUNNING_DIFFERENT_MODELS.md) | 9 built-in LLM providers, chat vs coding agent config, per-job overrides, custom providers |
238
+ | [Different Models](docs/RUNNING_DIFFERENT_MODELS.md) | 10 built-in LLM providers, helper LLM vs coding agent split, per-job overrides, custom providers |
216
239
  | [Auto-Merge](docs/AUTO_MERGE.md) | Auto-merge controls, ALLOWED_PATHS configuration |
217
240
  | [Deployment](docs/DEPLOYMENT.md) | VPS setup, Docker Compose, HTTPS with Let's Encrypt |
218
- | [Coding Agents](docs/CODING_AGENTS.md) | 5 coding agent backends, OAuth tokens, LiteLLM proxy, per-agent config |
241
+ | [Coding Agents](docs/CODING_AGENTS.md) | 6 coding agent backends, OAuth tokens, LiteLLM proxy, per-agent config |
219
242
  | [How to Build Skills](docs/HOW_TO_BUILD_SKILLS.md) | Guide to building and activating agent skills |
220
243
  | [Pre-Release](docs/PRE_RELEASE.md) | Installing beta/alpha builds |
221
244
  | [Code Workspaces](docs/CODE_WORKSPACES.md) | Interactive Docker containers with in-browser terminal |
package/api/CLAUDE.md CHANGED
@@ -4,31 +4,42 @@ This directory contains the route handlers for all `/api/*` endpoints. These rou
4
4
 
5
5
  ## Auth
6
6
 
7
- All routes (except `/telegram/webhook` and `/github/webhook`, which use their own webhook secrets) require a valid API key passed via the `x-api-key` header. API keys are stored in the SQLite database and managed through the admin UI — they are NOT environment variables.
7
+ Most routes require a valid API key passed via the `x-api-key` header. API keys are stored in the SQLite database and managed through the admin UI — they are NOT environment variables.
8
8
 
9
- Auth flow: `x-api-key` header -> `verifyApiKey()` -> database lookup (hashed, timing-safe comparison).
9
+ **Public routes** (no API key needed): `/ping`, `/telegram/webhook` (Telegram webhook secret), `/github/webhook` (GitHub webhook secret), `/oauth/callback` (validated via short-lived `state` token).
10
+
11
+ Auth flow: `x-api-key` header → `verifyApiKey()` → DB lookup (hashed, timing-safe comparison). Two key types exist:
12
+
13
+ - **User-owned API keys** — long-lived, created via the admin UI, used by external callers (cURL, GitHub Actions, Telegram register).
14
+ - **Per-job agent API keys** (`agent_job_api_key`) — short-lived, auto-created when an agent-job container launches (`createAgentJobApiKey()` in `lib/db/api-keys.js`), tied to the container name, and cleaned up by the maintenance cron after expiry. Routes that read agent-job secrets (`/api/get-agent-job-secret`, `/api/agent-job-list-secrets`) reject any other key type.
10
15
 
11
16
  ## Do NOT use these routes for browser UI
12
17
 
13
18
  Browser-facing data fetching uses **fetch route handlers** colocated with pages (`route.js` files in `web/app/`). These check `auth()` session — never use `/api` routes from the browser. Server actions (`'use server'`) are used only for **mutations** (rename, delete, star, config updates) — never for data fetching (causes page refresh issues). Handler implementations live in `lib/chat/api.js`; route files are thin re-exports.
14
19
 
20
+ Mutation server actions in `lib/chat/actions.js` use `requireAdmin()` for settings/config writes and `requireAuth()` for chat CRUD on user-owned rows. Reads stay open to any logged-in user. Sidebar items like Upgrade are gated on `user.role === 'admin'`.
21
+
15
22
  | Caller | Mechanism | Auth |
16
23
  |--------|-----------|------|
17
24
  | External (cURL, GitHub Actions, Telegram) | `/api` route | `x-api-key` header |
18
25
  | Browser UI (data fetching) | Fetch route handler colocated with page | `auth()` session |
19
- | Browser UI (mutations) | Server action | `requireAuth()` session |
20
- | Browser UI (streaming) | `/stream/chat`, `/stream/containers`, `/stream/cluster/*/logs` | `auth()` session |
26
+ | Browser UI (mutations) | Server action | `requireAuth()` / `requireAdmin()` |
27
+ | Browser UI (streaming) | `/stream/chat`, `/stream/containers`, `/stream/containers/logs`, `/stream/cluster/*/logs` | `auth()` session |
21
28
 
22
29
  ## Routes
23
30
 
24
31
  | Method | Path | Auth | Handler |
25
32
  |--------|------|------|---------|
26
33
  | GET | `/api/ping` | None | Health check |
27
- | POST | `/api/create-agent-job` | `x-api-key` | Create agent job |
28
- | GET | `/api/get-agent-job-secret` | `x-api-key` | Get an agent job secret; oauth2 credentials return only the access_token (auto-refreshed) |
29
- | GET | `/api/agent-job-list-secrets` | `x-api-key` | List agent job secret keys (no values); returns `{secrets: [{key, isSet, updatedAt, secretType}]}` |
34
+ | POST | `/api/create-agent-job` | `x-api-key` | Create agent job. Body: `{ agent_job, llm_model?, agent_backend?, scope?, user_id? }`. `user_id` attributes the job to that user — the PR-merge webhook reads it back to DM the originator instead of broadcasting. |
35
+ | GET | `/api/get-agent-job-secret` | `agent_job_api_key` only | Get an agent job secret. `key` query param is upper-cased before lookup (admin form already saves uppercase). `oauth2` credentials return only the access_token (auto-refreshed under a per-key lock; rotated refresh tokens are persisted back). Other secret types return the raw value. |
36
+ | GET | `/api/agent-job-list-secrets` | `agent_job_api_key` only | List agent job secret keys (no values); returns `{secrets: [{key, isSet, updatedAt, secretType}]}` |
30
37
  | GET | `/api/agent-jobs/status` | `x-api-key` | Agent job status (query: `?agent_job_id=`) |
31
- | POST | `/api/telegram/webhook` | Telegram webhook secret | Telegram message handler |
32
- | POST | `/api/telegram/register` | `x-api-key` | Register bot token + webhook URL |
33
- | POST | `/api/github/webhook` | GitHub webhook secret | GitHub event handler |
38
+ | GET | `/api/users` | `x-api-key` | List users with verified DM channels: `{users: [{id, email, first_name, last_name, nickname, role, channels: ['telegram', ...]}]}`. Used by the `agent-job-dm` skill. |
39
+ | POST | `/api/send-dm` | `x-api-key` | Dispatch a message. Body: `{ user_id?, message, payload?, system_message? }`. With `user_id`: write 1 row + push to that user's default channel. Without: fan out 1 row per admin where `subscribedToSystemMessages=1`, each pushed to their default channel. `system_message: true` (default false) marks it as a system notification — channels with `systemMessagesEnabled=0` skip the push (inbox row still written). Returns `{ok, recipients}`. |
40
+ | POST | `/api/telegram/webhook` | Telegram webhook secret | Telegram message handler (per-user routing via `user_channels`; verifies via `/verify <code>`, dispatches `/session` commands) |
41
+ | POST | `/api/github/webhook` | GitHub webhook secret | GitHub event handler. PR-merge events read `user_id` from `agent-job.config.json` and dispatch the completion message via `dispatchMessage` (per-user when set; broadcast to subscribed admins when absent). Agent-job completions are broadcasts, not system messages — they always push regardless of per-channel `systemMessagesEnabled`. |
34
42
  | POST | `/api/cluster/:clusterId/role/:roleId/webhook` | `x-api-key` | Trigger cluster role execution |
43
+ | GET/POST | `/api/oauth/callback` | `state` token | OAuth provider redirect target. Exchanges `code` for tokens, persists via `setAgentJobSecret(name, stored, 'oauth')`. |
44
+
45
+ Telegram bot configuration (token + webhook registration) is done from the admin UI at `/admin/event-handler/telegram`, not via an API route.