thepopebot 1.2.76-beta.2 → 1.2.76-beta.21

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 (128) hide show
  1. package/README.md +3 -3
  2. package/api/CLAUDE.md +11 -4
  3. package/api/index.js +56 -18
  4. package/bin/CLAUDE.md +7 -4
  5. package/bin/cli.js +25 -45
  6. package/config/CLAUDE.md +23 -4
  7. package/drizzle/0021_coding_agent_workspace.sql +1 -0
  8. package/drizzle/0022_organic_apocalypse.sql +16 -0
  9. package/drizzle/0023_needy_ender_wiggin.sql +1 -0
  10. package/drizzle/meta/0021_snapshot.json +639 -0
  11. package/drizzle/meta/0022_snapshot.json +743 -0
  12. package/drizzle/meta/0023_snapshot.json +750 -0
  13. package/drizzle/meta/_journal.json +21 -0
  14. package/lib/CLAUDE.md +2 -2
  15. package/lib/actions.js +9 -1
  16. package/lib/ai/CLAUDE.md +72 -57
  17. package/lib/ai/helper-llm.js +108 -0
  18. package/lib/ai/index.js +308 -438
  19. package/lib/ai/line-mappers.js +42 -24
  20. package/lib/ai/scope.js +26 -0
  21. package/lib/ai/sdk-adapters/CLAUDE.md +114 -0
  22. package/lib/ai/sdk-adapters/claude-code.js +120 -8
  23. package/lib/ai/system-prompt.js +34 -0
  24. package/lib/ai/workspace-setup.js +19 -35
  25. package/lib/channels/CLAUDE.md +14 -4
  26. package/lib/channels/base.js +6 -2
  27. package/lib/channels/commands/index.js +42 -0
  28. package/lib/channels/commands/session.js +53 -0
  29. package/lib/channels/commands/verify.js +18 -0
  30. package/lib/channels/telegram.js +79 -28
  31. package/lib/chat/CLAUDE.md +4 -4
  32. package/lib/chat/actions.js +270 -49
  33. package/lib/chat/api.js +185 -31
  34. package/lib/chat/components/CLAUDE.md +6 -2
  35. package/lib/chat/components/chat-input.js +77 -47
  36. package/lib/chat/components/chat-input.jsx +77 -40
  37. package/lib/chat/components/chat-page.js +2 -0
  38. package/lib/chat/components/chat-page.jsx +3 -0
  39. package/lib/chat/components/chat.js +62 -14
  40. package/lib/chat/components/chat.jsx +68 -10
  41. package/lib/chat/components/code-mode-toggle.js +141 -22
  42. package/lib/chat/components/code-mode-toggle.jsx +129 -20
  43. package/lib/chat/components/containers-page.js +58 -40
  44. package/lib/chat/components/containers-page.jsx +64 -25
  45. package/lib/chat/components/crons-page.js +17 -3
  46. package/lib/chat/components/crons-page.jsx +34 -6
  47. package/lib/chat/components/index.js +2 -2
  48. package/lib/chat/components/message.js +18 -3
  49. package/lib/chat/components/message.jsx +18 -3
  50. package/lib/chat/components/profile-page.js +182 -4
  51. package/lib/chat/components/profile-page.jsx +196 -1
  52. package/lib/chat/components/scope-picker.js +21 -0
  53. package/lib/chat/components/scope-picker.jsx +27 -0
  54. package/lib/chat/components/settings-chat-page.js +11 -11
  55. package/lib/chat/components/settings-chat-page.jsx +14 -18
  56. package/lib/chat/components/settings-coding-agents-page.js +110 -16
  57. package/lib/chat/components/settings-coding-agents-page.jsx +87 -3
  58. package/lib/chat/components/settings-github-page.js +5 -0
  59. package/lib/chat/components/settings-github-page.jsx +5 -0
  60. package/lib/chat/components/settings-layout.js +3 -3
  61. package/lib/chat/components/settings-layout.jsx +3 -3
  62. package/lib/chat/components/settings-secrets-layout.js +1 -2
  63. package/lib/chat/components/settings-secrets-layout.jsx +1 -2
  64. package/lib/chat/components/settings-secrets-page.js +180 -75
  65. package/lib/chat/components/settings-secrets-page.jsx +212 -66
  66. package/lib/chat/components/triggers-page.js +17 -3
  67. package/lib/chat/components/triggers-page.jsx +34 -6
  68. package/lib/chat/components/ui/combobox.js +18 -2
  69. package/lib/chat/components/ui/combobox.jsx +17 -1
  70. package/lib/chat/components/ui/dropdown-menu.js +23 -2
  71. package/lib/chat/components/ui/dropdown-menu.jsx +27 -2
  72. package/lib/chat/telegram-profile.js +33 -0
  73. package/lib/cluster/CLAUDE.md +9 -3
  74. package/lib/code/CLAUDE.md +11 -3
  75. package/lib/code/actions.js +47 -8
  76. package/lib/code/terminal-view.js +31 -21
  77. package/lib/code/terminal-view.jsx +32 -23
  78. package/lib/config.js +15 -4
  79. package/lib/containers/CLAUDE.md +16 -6
  80. package/lib/db/CLAUDE.md +5 -2
  81. package/lib/db/chats.js +9 -17
  82. package/lib/db/code-workspaces.js +8 -3
  83. package/lib/db/config.js +0 -1
  84. package/lib/db/index.js +12 -0
  85. package/lib/db/schema.js +24 -1
  86. package/lib/db/user-channels.js +129 -0
  87. package/lib/llm-providers.js +8 -0
  88. package/lib/maintenance.js +31 -21
  89. package/lib/tools/CLAUDE.md +12 -3
  90. package/lib/tools/assemblyai.js +17 -0
  91. package/lib/tools/create-agent-job.js +12 -8
  92. package/lib/tools/docker.js +34 -10
  93. package/lib/tools/github.js +34 -0
  94. package/lib/tools/telegram.js +106 -0
  95. package/lib/utils/render-md.js +44 -18
  96. package/package.json +8 -8
  97. package/setup/CLAUDE.md +11 -5
  98. package/setup/lib/providers.mjs +2 -1
  99. package/setup/lib/targets.mjs +13 -16
  100. package/setup/lib/telegram.mjs +8 -69
  101. package/templates/.env.example +0 -7
  102. package/templates/.github/workflows/rebuild-event-handler.yml +1 -1
  103. package/templates/.gitignore.template +1 -3
  104. package/templates/CLAUDE.md +1 -1
  105. package/templates/CLAUDE.md.template +29 -7
  106. package/templates/agent-job/CLAUDE.md.template +5 -3
  107. package/templates/agent-job/CRONS.json +16 -0
  108. package/templates/agent-job/SYSTEM.md +16 -11
  109. package/templates/agents/CLAUDE.md.template +17 -17
  110. package/templates/coding-workspace/CLAUDE.md.template +7 -0
  111. package/templates/data/CLAUDE.md.template +1 -1
  112. package/templates/docker-compose.custom.yml +1 -0
  113. package/templates/docker-compose.yml +1 -0
  114. package/templates/event-handler/CLAUDE.md.template +79 -0
  115. package/templates/event-handler/TRIGGERS.json +18 -2
  116. package/templates/skills/CLAUDE.md.template +20 -22
  117. package/templates/skills/{library/agent-job-secrets → agent-job-secrets}/SKILL.md +2 -2
  118. package/lib/ai/agent.js +0 -65
  119. package/lib/ai/async-channel.js +0 -51
  120. package/lib/ai/model.js +0 -130
  121. package/lib/ai/tools.js +0 -164
  122. package/lib/tools/openai.js +0 -37
  123. package/setup/lib/telegram-verify.mjs +0 -63
  124. package/setup/setup-telegram.mjs +0 -260
  125. package/templates/agent-job/SOUL.md +0 -17
  126. /package/templates/{skills/active/.gitkeep → coding-workspace/SYSTEM.md} +0 -0
  127. /package/templates/skills/{library/agent-job-secrets → agent-job-secrets}/agent-job-secrets.js +0 -0
  128. /package/templates/skills/{library/playwright-cli → playwright-cli}/SKILL.md +0 -0
@@ -1,260 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import chalk from 'chalk';
4
- import * as clack from '@clack/prompts';
5
-
6
- import { checkPrerequisites } from './lib/prerequisites.mjs';
7
- import { setVariables, setSecrets } from './lib/github.mjs';
8
- import { setTelegramWebhook, validateBotToken, generateVerificationCode, getBotFatherURL } from './lib/telegram.mjs';
9
- import { confirm, keepOrReconfigure, generateTelegramWebhookSecret, promptForOptionalKey, maskSecret, openOrShowURL } from './lib/prompts.mjs';
10
- import { updateEnvVariable } from './lib/auth.mjs';
11
- import { runVerificationFlow } from './lib/telegram-verify.mjs';
12
- import { loadEnvFile } from './lib/env.mjs';
13
-
14
- const logo = `
15
- _____ _ ____ ____ _
16
- |_ _| |__ ___| _ \\ ___ _ __ ___| __ ) ___ | |_
17
- | | | '_ \\ / _ \\ |_) / _ \\| '_ \\ / _ \\ _ \\ / _ \\| __|
18
- | | | | | | __/ __/ (_) | |_) | __/ |_) | (_) | |_
19
- |_| |_| |_|\\___|_| \\___/| .__/ \\___|____/ \\___/ \\__|
20
- |_|
21
- `;
22
-
23
- async function main() {
24
- console.log(chalk.cyan(logo));
25
- clack.intro('Telegram Setup');
26
- clack.log.info('Connect a Telegram bot to your agent. This wizard will walk you through creating a bot, registering a webhook, and linking your chat.');
27
-
28
- const TOTAL_STEPS = 6;
29
- let currentStep = 0;
30
-
31
- // Track values for summary
32
- let botUsername = null;
33
- let webhookUrl = null;
34
- let telegramChatId = null;
35
-
36
- // ─── Step 1: Prerequisites ──────────────────────────────────────────
37
- clack.log.step(`[${++currentStep}/${TOTAL_STEPS}] Checking prerequisites`);
38
- clack.log.info('Verifying git remote and loading existing configuration.');
39
-
40
- const prereqs = await checkPrerequisites();
41
-
42
- if (!prereqs.git.remoteInfo) {
43
- clack.log.error('Could not detect GitHub repository from git remote.');
44
- clack.cancel('Run setup first to initialize your repository.');
45
- process.exit(1);
46
- }
47
-
48
- const { owner, repo } = prereqs.git.remoteInfo;
49
- clack.log.success(`Repository: ${owner}/${repo}`);
50
-
51
- const env = loadEnvFile();
52
-
53
- if (env) {
54
- clack.log.info('Existing .env detected — previously configured values can be skipped.');
55
- }
56
-
57
- // ─── Step 2: App URL ────────────────────────────────────────────────
58
- clack.log.step(`[${++currentStep}/${TOTAL_STEPS}] App URL`);
59
- clack.log.info('Your bot needs a public HTTPS URL so Telegram can deliver messages to it via webhook.');
60
- clack.log.warn('Make sure your server is running and publicly accessible.');
61
-
62
- let appUrl = null;
63
-
64
- if (await keepOrReconfigure('APP_URL', env?.APP_URL || null)) {
65
- appUrl = env.APP_URL;
66
- }
67
-
68
- if (!appUrl) {
69
- clack.log.info(
70
- 'Enter the public URL where your agent is running.\n' +
71
- ' Examples:\n' +
72
- ' ngrok: https://abc123.ngrok.io\n' +
73
- ' VPS: https://mybot.example.com\n' +
74
- ' PaaS: https://mybot.vercel.app'
75
- );
76
-
77
- while (!appUrl) {
78
- const url = await clack.text({
79
- message: 'Enter your APP_URL (https://...):',
80
- validate: (input) => {
81
- if (!input) return 'URL is required';
82
- if (!input.startsWith('https://')) return 'URL must start with https://';
83
- },
84
- });
85
- if (clack.isCancel(url)) {
86
- clack.cancel('Setup cancelled.');
87
- process.exit(0);
88
- }
89
- appUrl = url.replace(/\/$/, '');
90
- }
91
- }
92
-
93
- // Update APP_URL and APP_HOSTNAME in .env
94
- const appHostname = new URL(appUrl).hostname;
95
- updateEnvVariable('APP_URL', appUrl);
96
- updateEnvVariable('APP_HOSTNAME', appHostname);
97
- clack.log.success('APP_URL saved to .env');
98
-
99
- // Set APP_URL variable on GitHub
100
- const urlSpinner = clack.spinner();
101
- urlSpinner.start('Updating APP_URL variable on GitHub...');
102
- const urlResult = await setVariables(owner, repo, { APP_URL: appUrl });
103
- if (urlResult.APP_URL.success) {
104
- urlSpinner.stop('APP_URL variable updated on GitHub');
105
- } else {
106
- urlSpinner.stop(`Failed: ${urlResult.APP_URL.error}`);
107
- }
108
-
109
- // ─── Step 3: Bot Token ──────────────────────────────────────────────
110
- clack.log.step(`[${++currentStep}/${TOTAL_STEPS}] Telegram Bot Token`);
111
- clack.log.info('Your agent needs a Telegram bot token from @BotFather to send and receive messages.');
112
-
113
- let token = null;
114
-
115
- if (await keepOrReconfigure('Telegram Bot', env?.TELEGRAM_BOT_TOKEN ? maskSecret(env.TELEGRAM_BOT_TOKEN) : null)) {
116
- // Validate existing token
117
- token = env.TELEGRAM_BOT_TOKEN;
118
- const validateSpinner = clack.spinner();
119
- validateSpinner.start('Validating existing bot token...');
120
- const validation = await validateBotToken(token);
121
- if (validation.valid) {
122
- botUsername = validation.botInfo.username;
123
- validateSpinner.stop(`Bot: @${botUsername}`);
124
- } else {
125
- validateSpinner.stop(`Invalid token in .env: ${validation.error}`);
126
- clack.log.warn('Existing token is invalid — you\'ll need to enter a new one.');
127
- token = null;
128
- }
129
- }
130
-
131
- if (!token) {
132
- clack.log.info(
133
- 'Create a Telegram bot via @BotFather:\n' +
134
- ' 1. Open @BotFather in Telegram\n' +
135
- ' 2. Send /newbot and follow the prompts\n' +
136
- ' 3. Copy the bot token'
137
- );
138
-
139
- await openOrShowURL(getBotFatherURL(), 'Telegram BotFather');
140
-
141
- let tokenValid = false;
142
- while (!tokenValid) {
143
- const inputToken = await clack.password({
144
- message: 'Telegram bot token:',
145
- validate: (input) => {
146
- if (!input) return 'Token is required';
147
- if (!/^\d+:[A-Za-z0-9_-]+$/.test(input)) {
148
- return 'Invalid format. Should be like 123456789:ABC-DEF...';
149
- }
150
- },
151
- });
152
- if (clack.isCancel(inputToken)) {
153
- clack.cancel('Setup cancelled.');
154
- process.exit(0);
155
- }
156
-
157
- const validateSpinner = clack.spinner();
158
- validateSpinner.start('Validating bot token...');
159
- const validation = await validateBotToken(inputToken);
160
-
161
- if (!validation.valid) {
162
- validateSpinner.stop(`Invalid token: ${validation.error}`);
163
- continue;
164
- }
165
-
166
- token = inputToken;
167
- botUsername = validation.botInfo.username;
168
- validateSpinner.stop(`Bot: @${botUsername}`);
169
- tokenValid = true;
170
- }
171
- }
172
-
173
- // Bug fix #146: save token to .env
174
- updateEnvVariable('TELEGRAM_BOT_TOKEN', token);
175
-
176
- // ─── Step 4: Webhook ────────────────────────────────────────────────
177
- clack.log.step(`[${++currentStep}/${TOTAL_STEPS}] Register Webhook`);
178
- clack.log.info('Registering a webhook tells Telegram where to send messages for your bot.');
179
-
180
- // Handle webhook secret
181
- let webhookSecret = env?.TELEGRAM_WEBHOOK_SECRET;
182
- if (webhookSecret) {
183
- clack.log.success('Using existing webhook secret');
184
- } else {
185
- webhookSecret = await generateTelegramWebhookSecret();
186
- updateEnvVariable('TELEGRAM_WEBHOOK_SECRET', webhookSecret);
187
- clack.log.success('Generated webhook secret');
188
- }
189
-
190
- // Register Telegram webhook
191
- webhookUrl = `${appUrl}/api/telegram/webhook`;
192
- const tgSpinner = clack.spinner();
193
- tgSpinner.start('Registering Telegram webhook...');
194
- const tgResult = await setTelegramWebhook(token, webhookUrl, webhookSecret);
195
- if (tgResult.ok) {
196
- tgSpinner.stop('Telegram webhook registered');
197
- } else {
198
- tgSpinner.stop(`Failed: ${tgResult.description}`);
199
- }
200
-
201
- // ─── Step 5: Chat Verification ──────────────────────────────────────
202
- clack.log.step(`[${++currentStep}/${TOTAL_STEPS}] Chat Verification`);
203
- clack.log.info('Link the bot to your Telegram chat so it only responds to you.');
204
-
205
- telegramChatId = env?.TELEGRAM_CHAT_ID || null;
206
-
207
- if (await keepOrReconfigure('Chat ID', telegramChatId)) {
208
- // Keep existing — already set
209
- } else {
210
- telegramChatId = null;
211
- const verificationCode = generateVerificationCode();
212
- updateEnvVariable('TELEGRAM_VERIFICATION', verificationCode);
213
-
214
- clack.log.warn('Waiting for server to restart with new verification code...');
215
- await new Promise(resolve => setTimeout(resolve, 3000));
216
-
217
- const chatId = await runVerificationFlow(verificationCode, { allowSkip: true });
218
-
219
- if (chatId) {
220
- telegramChatId = chatId;
221
- updateEnvVariable('TELEGRAM_CHAT_ID', chatId);
222
- clack.log.success(`Chat ID saved: ${chatId}`);
223
- } else {
224
- clack.log.warn('Chat ID is required — the bot will not respond without it.');
225
- clack.log.info('Run npm run setup-telegram again to complete setup.');
226
- }
227
- }
228
-
229
- // ─── Step 6: Optional Keys ──────────────────────────────────────────
230
- clack.log.step(`[${++currentStep}/${TOTAL_STEPS}] Optional Keys`);
231
- clack.log.info('An OpenAI API key enables voice message transcription via Whisper.');
232
-
233
- if (await keepOrReconfigure('OpenAI key', env?.OPENAI_API_KEY ? maskSecret(env.OPENAI_API_KEY) : null)) {
234
- // Keep existing
235
- } else {
236
- const openaiKey = await promptForOptionalKey('openai', 'voice messages');
237
- if (openaiKey) {
238
- updateEnvVariable('OPENAI_API_KEY', openaiKey);
239
- const s = clack.spinner();
240
- s.start('Setting OpenAI secret on GitHub...');
241
- await setSecrets(owner, repo, { AGENT_OPENAI_API_KEY: openaiKey });
242
- s.stop('OpenAI secret set');
243
- clack.log.success(`OpenAI key added for voice (${maskSecret(openaiKey)})`);
244
- }
245
- }
246
-
247
- // ─── Summary ────────────────────────────────────────────────────────
248
- let summary = '';
249
- summary += `Bot: @${botUsername || '(unknown)'}\n`;
250
- summary += `Webhook: ${webhookUrl}\n`;
251
- summary += `Chat ID: ${telegramChatId || '(not set)'}`;
252
- clack.note(summary, 'Telegram Configuration');
253
-
254
- clack.outro('Telegram setup complete!');
255
- }
256
-
257
- main().catch((error) => {
258
- clack.log.error(`Failed: ${error.message}`);
259
- process.exit(1);
260
- });
@@ -1,17 +0,0 @@
1
- # Agent Job Soul
2
-
3
- ## Identity
4
-
5
- You are a diligent and capable AI worker doing an job. You approach tasks with focus, patience, and craftsmanship.
6
-
7
- ## Personality Traits
8
-
9
- - **Methodical**: You work through problems systematically, step by step
10
- - **Reliable**: You follow through on commitments and complete what I start
11
- - **Curious**: You explore and learn from the codebase I work with
12
- - **Working Style**: You plan before acting
13
-
14
- ## Values
15
-
16
- - **Quality over speed**: Better to do it right than do it twice
17
- - **Simplicity**: The simplest solution that works is usually best