@teamvibe/poller 0.1.68 → 0.2.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/dist/auto-update.d.ts +15 -0
- package/dist/auto-update.js +151 -0
- package/dist/cli/commands.js +7 -0
- package/dist/cli/doctor.d.ts +1 -0
- package/dist/cli/doctor.js +195 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +3 -0
- package/dist/control-handler.d.ts +4 -0
- package/dist/control-handler.js +143 -0
- package/dist/control-handler.test.js +74 -0
- package/dist/index.js +1 -1
- package/dist/poller.js +53 -1
- package/dist/types.d.ts +7 -0
- package/package.json +2 -1
- package/dist/kb-manager.d.ts +0 -15
- package/dist/kb-manager.js +0 -61
- package/dist/mailbox-manager.d.ts +0 -26
- package/dist/mailbox-manager.js +0 -95
- package/dist/scripts/add-reaction.d.ts +0 -9
- package/dist/scripts/add-reaction.js +0 -22
- package/dist/scripts/lib/slack-client.d.ts +0 -16
- package/dist/scripts/lib/slack-client.js +0 -48
- package/dist/scripts/read-thread.d.ts +0 -9
- package/dist/scripts/read-thread.js +0 -26
- package/dist/scripts/remove-reaction.d.ts +0 -9
- package/dist/scripts/remove-reaction.js +0 -22
- package/dist/scripts/send-message.d.ts +0 -10
- package/dist/scripts/send-message.js +0 -31
- package/dist/scripts/set-status.d.ts +0 -8
- package/dist/scripts/set-status.js +0 -19
- package/dist/scripts/slack-tool.js +0 -155
- package/dist/scripts/upload-snippet.d.ts +0 -8
- package/dist/scripts/upload-snippet.js +0 -21
- /package/dist/{scripts/slack-tool.d.ts → control-handler.test.d.ts} +0 -0
package/dist/poller.js
CHANGED
|
@@ -10,8 +10,45 @@ import { initAuth, stopRefresh } from './auth-provider.js';
|
|
|
10
10
|
import { registerBrain, startHeartbeatLoop, stopHeartbeatLoop } from './heartbeat-manager.js';
|
|
11
11
|
import { startEventQueue, stopEventQueue, flush as flushEventQueue, emitEvent } from './event-queue.js';
|
|
12
12
|
import { writeMessage, pickNextMessage, markProcessed, markFailed, hasUnprocessed } from './inbox-manager.js';
|
|
13
|
+
import { Cron } from 'croner';
|
|
14
|
+
import { isControlMessage, handleControlMessage } from './control-handler.js';
|
|
15
|
+
import { checkForUpdate } from './auto-update.js';
|
|
13
16
|
// Track active message processing
|
|
14
17
|
const processingMessages = new Set();
|
|
18
|
+
// Poller auto-update cron (separate from brain heartbeats)
|
|
19
|
+
let autoUpdateJob = null;
|
|
20
|
+
function startAutoUpdateCron() {
|
|
21
|
+
const schedule = config.AUTO_UPDATE_SCHEDULE;
|
|
22
|
+
const match = schedule.match(/^(\d{2}):(\d{2})$/);
|
|
23
|
+
if (!match || config.AUTO_UPDATE_POLICY === 'off') {
|
|
24
|
+
if (config.AUTO_UPDATE_POLICY !== 'off') {
|
|
25
|
+
logger.warn(`[AutoUpdate] Invalid AUTO_UPDATE_SCHEDULE: "${schedule}", expected "HH:MM"`);
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Convert "HH:MM" to cron expression: "MM HH * * *"
|
|
30
|
+
const cronExpr = `${match[2]} ${match[1]} * * *`;
|
|
31
|
+
logger.info(`[AutoUpdate] Scheduled daily at ${schedule} UTC (cron: ${cronExpr}), policy: ${config.AUTO_UPDATE_POLICY}`);
|
|
32
|
+
autoUpdateJob = new Cron(cronExpr, { timezone: 'UTC' }, async () => {
|
|
33
|
+
try {
|
|
34
|
+
const shouldRestart = await checkForUpdate();
|
|
35
|
+
if (shouldRestart) {
|
|
36
|
+
logger.info('[AutoUpdate] Update applied, restarting...');
|
|
37
|
+
await flushEventQueue();
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.error(`[AutoUpdate] Check error: ${error instanceof Error ? error.message : error}`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function stopAutoUpdateCron() {
|
|
47
|
+
if (autoUpdateJob) {
|
|
48
|
+
autoUpdateJob.stop();
|
|
49
|
+
autoUpdateJob = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
15
52
|
// Track which threads have an active processing loop
|
|
16
53
|
const activeLoops = new Set();
|
|
17
54
|
async function runInboxLoop(threadId, kbPath, queueMessage, sessionLog) {
|
|
@@ -290,7 +327,20 @@ async function pollLoop() {
|
|
|
290
327
|
if (duplicates.length > 0) {
|
|
291
328
|
logger.info(`Deduplicated: ${messages.length} -> ${unique.length} message(s)`);
|
|
292
329
|
}
|
|
293
|
-
|
|
330
|
+
// Handle control messages immediately (restart/update) — no Claude session needed
|
|
331
|
+
const regularMessages = [];
|
|
332
|
+
for (const msg of unique) {
|
|
333
|
+
const raw = msg.queueMessage;
|
|
334
|
+
if (isControlMessage(raw)) {
|
|
335
|
+
logger.info(`[Control] Received control message: ${raw.action}`);
|
|
336
|
+
await deleteMessage(msg.receiptHandle);
|
|
337
|
+
await handleControlMessage(raw);
|
|
338
|
+
// If we get here, the action didn't trigger an exit (e.g. update failed pre-check)
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
regularMessages.push(msg);
|
|
342
|
+
}
|
|
343
|
+
const processPromises = regularMessages.map((msg) => processMessage(msg).catch((error) => {
|
|
294
344
|
logger.error(`Failed to process message ${msg.messageId}:`, error);
|
|
295
345
|
}));
|
|
296
346
|
// Don't await - let them run in parallel
|
|
@@ -314,6 +364,7 @@ async function shutdown(signal) {
|
|
|
314
364
|
logger.info(`${signal} received, shutting down gracefully...`);
|
|
315
365
|
stopRefresh();
|
|
316
366
|
stopHeartbeatLoop();
|
|
367
|
+
stopAutoUpdateCron();
|
|
317
368
|
stopEventQueue();
|
|
318
369
|
// Kill all active Claude child processes
|
|
319
370
|
await killAllActiveProcesses();
|
|
@@ -351,5 +402,6 @@ export async function startPoller() {
|
|
|
351
402
|
await ensureDirectories();
|
|
352
403
|
await ensureBaseBrain();
|
|
353
404
|
startHeartbeatLoop(processMessage);
|
|
405
|
+
startAutoUpdateCron();
|
|
354
406
|
await pollLoop();
|
|
355
407
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export interface ControlMessage {
|
|
2
|
+
id: string;
|
|
3
|
+
source: 'control';
|
|
4
|
+
action: 'restart' | 'update';
|
|
5
|
+
targetVersion?: string;
|
|
6
|
+
}
|
|
7
|
+
export type QueueMessage = TeamVibeQueueMessage | ControlMessage;
|
|
1
8
|
export interface TeamVibeQueueMessage {
|
|
2
9
|
id: string;
|
|
3
10
|
source: 'slack' | 'email' | 'cron' | 'heartbeat' | 'webhook';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamvibe/poller",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@aws-sdk/client-sqs": "^3.470.0",
|
|
25
25
|
"@aws-sdk/lib-dynamodb": "^3.470.0",
|
|
26
26
|
"@slack/web-api": "^7.0.0",
|
|
27
|
+
"croner": "^10.0.1",
|
|
27
28
|
"dotenv": "^17.2.3",
|
|
28
29
|
"zod": "^3.22.0"
|
|
29
30
|
},
|
package/dist/kb-manager.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
interface KBConfig {
|
|
2
|
-
kbId: string;
|
|
3
|
-
gitRepoUrl: string;
|
|
4
|
-
branch: string;
|
|
5
|
-
claudePath: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Get or clone KB for a persona. Returns the working directory path.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getKnowledgeBasePath(kb?: KBConfig): Promise<string>;
|
|
11
|
-
/**
|
|
12
|
-
* Ensure base paths exist
|
|
13
|
-
*/
|
|
14
|
-
export declare function ensureDirectories(): Promise<void>;
|
|
15
|
-
export {};
|
package/dist/kb-manager.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { exec } from 'child_process';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
|
-
import { existsSync } from 'fs';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
import { config } from './config.js';
|
|
6
|
-
import { logger } from './logger.js';
|
|
7
|
-
const execAsync = promisify(exec);
|
|
8
|
-
// Cooldown tracker per KB
|
|
9
|
-
const lastUpdateTimes = new Map();
|
|
10
|
-
/**
|
|
11
|
-
* Get or clone KB for a persona. Returns the working directory path.
|
|
12
|
-
*/
|
|
13
|
-
export async function getKnowledgeBasePath(kb) {
|
|
14
|
-
if (!kb?.gitRepoUrl)
|
|
15
|
-
return config.DEFAULT_KB_PATH;
|
|
16
|
-
const kbDir = join(config.KB_BASE_PATH, kb.kbId);
|
|
17
|
-
if (!existsSync(kbDir)) {
|
|
18
|
-
logger.info(`Cloning KB ${kb.kbId} from ${kb.gitRepoUrl} (branch: ${kb.branch})...`);
|
|
19
|
-
await execAsync(`git clone --branch ${kb.branch} ${kb.gitRepoUrl} ${kbDir}`);
|
|
20
|
-
logger.info(`KB ${kb.kbId} cloned successfully`);
|
|
21
|
-
}
|
|
22
|
-
else if (config.KB_AUTO_UPDATE) {
|
|
23
|
-
await updateKB(kbDir, kb.kbId, kb.branch);
|
|
24
|
-
}
|
|
25
|
-
return kbDir;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Update a KB repo (respects cooldown)
|
|
29
|
-
*/
|
|
30
|
-
async function updateKB(kbDir, kbId, branch) {
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
const lastUpdate = lastUpdateTimes.get(kbId) || 0;
|
|
33
|
-
if (now - lastUpdate < config.KB_UPDATE_COOLDOWN_MS) {
|
|
34
|
-
logger.debug(`KB ${kbId} update skipped - cooldown active (${Math.round((config.KB_UPDATE_COOLDOWN_MS - (now - lastUpdate)) / 1000)}s remaining)`);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
logger.info(`Updating KB ${kbId} at ${kbDir}...`);
|
|
39
|
-
await execAsync(`git fetch origin ${branch} && git reset --hard origin/${branch}`, {
|
|
40
|
-
cwd: kbDir,
|
|
41
|
-
});
|
|
42
|
-
lastUpdateTimes.set(kbId, Date.now());
|
|
43
|
-
logger.info(`KB ${kbId} updated successfully`);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
47
|
-
logger.error(`Failed to update KB ${kbId}: ${errorMessage}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Ensure base paths exist
|
|
52
|
-
*/
|
|
53
|
-
export async function ensureDirectories() {
|
|
54
|
-
const { mkdirSync } = await import('fs');
|
|
55
|
-
if (!existsSync(config.KB_BASE_PATH)) {
|
|
56
|
-
mkdirSync(config.KB_BASE_PATH, { recursive: true });
|
|
57
|
-
}
|
|
58
|
-
if (!existsSync(config.DEFAULT_KB_PATH)) {
|
|
59
|
-
mkdirSync(config.DEFAULT_KB_PATH, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Write a new message to the mailbox.
|
|
3
|
-
* Returns the filename of the created message file.
|
|
4
|
-
*/
|
|
5
|
-
export declare function writeMessage(brainPath: string, threadId: string, content: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* Pick the oldest message from processing/ (crash recovery) or new/.
|
|
8
|
-
* If found in new/, moves it to processing/.
|
|
9
|
-
* Returns { filename, content } or null if no messages.
|
|
10
|
-
*/
|
|
11
|
-
export declare function pickNextMessage(brainPath: string, threadId: string): {
|
|
12
|
-
filename: string;
|
|
13
|
-
content: string;
|
|
14
|
-
} | null;
|
|
15
|
-
/**
|
|
16
|
-
* Delete a message file from processing/ (marks it as done).
|
|
17
|
-
*/
|
|
18
|
-
export declare function markProcessed(brainPath: string, threadId: string, filename: string): void;
|
|
19
|
-
/**
|
|
20
|
-
* Check if there are unprocessed messages in new/ or processing/.
|
|
21
|
-
*/
|
|
22
|
-
export declare function hasUnprocessed(brainPath: string, threadId: string): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Get the mailbox new/ directory path for use in Claude's system prompt.
|
|
25
|
-
*/
|
|
26
|
-
export declare function getMailboxNewPath(brainPath: string, threadId: string): string;
|
package/dist/mailbox-manager.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync, readFileSync, renameSync, unlinkSync, readdirSync, existsSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { logger } from './logger.js';
|
|
4
|
-
const MAILBOX_DIR = '.mailbox';
|
|
5
|
-
const NEW_DIR = 'new';
|
|
6
|
-
const PROCESSING_DIR = 'processing';
|
|
7
|
-
function getMailboxPath(brainPath, threadId) {
|
|
8
|
-
return join(brainPath, MAILBOX_DIR, threadId);
|
|
9
|
-
}
|
|
10
|
-
function ensureMailboxDirs(brainPath, threadId) {
|
|
11
|
-
const mailbox = getMailboxPath(brainPath, threadId);
|
|
12
|
-
mkdirSync(join(mailbox, NEW_DIR), { recursive: true });
|
|
13
|
-
mkdirSync(join(mailbox, PROCESSING_DIR), { recursive: true });
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Write a new message to the mailbox.
|
|
17
|
-
* Returns the filename of the created message file.
|
|
18
|
-
*/
|
|
19
|
-
export function writeMessage(brainPath, threadId, content) {
|
|
20
|
-
ensureMailboxDirs(brainPath, threadId);
|
|
21
|
-
const timestamp = process.hrtime.bigint().toString();
|
|
22
|
-
const filename = `${timestamp}.txt`;
|
|
23
|
-
const filepath = join(getMailboxPath(brainPath, threadId), NEW_DIR, filename);
|
|
24
|
-
writeFileSync(filepath, content, 'utf-8');
|
|
25
|
-
logger.info(`[Mailbox] Wrote message: ${filename} to ${getMailboxPath(brainPath, threadId)}/new/ (${content.length} chars, threadId=${threadId})`);
|
|
26
|
-
return filename;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Pick the oldest message from processing/ (crash recovery) or new/.
|
|
30
|
-
* If found in new/, moves it to processing/.
|
|
31
|
-
* Returns { filename, content } or null if no messages.
|
|
32
|
-
*/
|
|
33
|
-
export function pickNextMessage(brainPath, threadId) {
|
|
34
|
-
ensureMailboxDirs(brainPath, threadId);
|
|
35
|
-
const mailbox = getMailboxPath(brainPath, threadId);
|
|
36
|
-
const processingDir = join(mailbox, PROCESSING_DIR);
|
|
37
|
-
const newDir = join(mailbox, NEW_DIR);
|
|
38
|
-
// First check processing/ (crash recovery)
|
|
39
|
-
const processingFiles = readdirSync(processingDir).filter(f => f.endsWith('.txt')).sort();
|
|
40
|
-
if (processingFiles.length > 0) {
|
|
41
|
-
const filename = processingFiles[0];
|
|
42
|
-
const content = readFileSync(join(processingDir, filename), 'utf-8');
|
|
43
|
-
logger.info(`[Mailbox] Resuming processing message: ${filename}`);
|
|
44
|
-
return { filename, content };
|
|
45
|
-
}
|
|
46
|
-
// Then check new/
|
|
47
|
-
const newFiles = readdirSync(newDir).filter(f => f.endsWith('.txt')).sort();
|
|
48
|
-
if (newFiles.length > 0) {
|
|
49
|
-
const filename = newFiles[0];
|
|
50
|
-
const srcPath = join(newDir, filename);
|
|
51
|
-
const dstPath = join(processingDir, filename);
|
|
52
|
-
const content = readFileSync(srcPath, 'utf-8');
|
|
53
|
-
renameSync(srcPath, dstPath);
|
|
54
|
-
logger.info(`[Mailbox] Picked message: ${filename} (moved to processing)`);
|
|
55
|
-
return { filename, content };
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Delete a message file from processing/ (marks it as done).
|
|
61
|
-
*/
|
|
62
|
-
export function markProcessed(brainPath, threadId, filename) {
|
|
63
|
-
const filepath = join(getMailboxPath(brainPath, threadId), PROCESSING_DIR, filename);
|
|
64
|
-
try {
|
|
65
|
-
if (existsSync(filepath)) {
|
|
66
|
-
unlinkSync(filepath);
|
|
67
|
-
logger.info(`[Mailbox] Deleted processed message: ${filename}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
logger.warn(`[Mailbox] Failed to delete ${filename}: ${error}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Check if there are unprocessed messages in new/ or processing/.
|
|
76
|
-
*/
|
|
77
|
-
export function hasUnprocessed(brainPath, threadId) {
|
|
78
|
-
const mailbox = getMailboxPath(brainPath, threadId);
|
|
79
|
-
const newDir = join(mailbox, NEW_DIR);
|
|
80
|
-
const processingDir = join(mailbox, PROCESSING_DIR);
|
|
81
|
-
try {
|
|
82
|
-
const newCount = existsSync(newDir) ? readdirSync(newDir).filter(f => f.endsWith('.txt')).length : 0;
|
|
83
|
-
const procCount = existsSync(processingDir) ? readdirSync(processingDir).filter(f => f.endsWith('.txt')).length : 0;
|
|
84
|
-
return (newCount + procCount) > 0;
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Get the mailbox new/ directory path for use in Claude's system prompt.
|
|
92
|
-
*/
|
|
93
|
-
export function getMailboxNewPath(brainPath, threadId) {
|
|
94
|
-
return join(getMailboxPath(brainPath, threadId), NEW_DIR);
|
|
95
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Add an emoji reaction to the original message.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* node add-reaction.js emoji_name
|
|
7
|
-
* node add-reaction.js --channel C123 --message_ts 123.456 emoji_name
|
|
8
|
-
*/
|
|
9
|
-
import { slack, fail, succeed, parseArgs } from './lib/slack-client.js';
|
|
10
|
-
const { channel, messageTs, positional } = parseArgs();
|
|
11
|
-
const emoji = positional[0];
|
|
12
|
-
if (!emoji)
|
|
13
|
-
fail('Emoji name required');
|
|
14
|
-
if (!channel)
|
|
15
|
-
fail('Channel required (--channel or SLACK_CHANNEL env)');
|
|
16
|
-
if (!messageTs)
|
|
17
|
-
fail('Message TS required (--message_ts or SLACK_MESSAGE_TS env)');
|
|
18
|
-
async function main() {
|
|
19
|
-
await slack.reactions.add({ channel: channel, timestamp: messageTs, name: emoji });
|
|
20
|
-
succeed();
|
|
21
|
-
}
|
|
22
|
-
main().catch((err) => fail(err instanceof Error ? err.message : String(err)));
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { WebClient } from '@slack/web-api';
|
|
2
|
-
export declare function fail(error: string): never;
|
|
3
|
-
export declare function succeed(data?: Record<string, unknown>): never;
|
|
4
|
-
export declare const slack: WebClient;
|
|
5
|
-
/**
|
|
6
|
-
* Parse CLI args: extracts known --flags and returns remaining positional args.
|
|
7
|
-
* Supports both --flag value and --flag=value syntax.
|
|
8
|
-
* Falls back to env vars for channel/thread_ts/message_ts.
|
|
9
|
-
*/
|
|
10
|
-
export declare function parseArgs(argv?: string[]): {
|
|
11
|
-
channel: string | undefined;
|
|
12
|
-
threadTs: string | undefined;
|
|
13
|
-
messageTs: string | undefined;
|
|
14
|
-
positional: string[];
|
|
15
|
-
textFromFlag: string | undefined;
|
|
16
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { WebClient } from '@slack/web-api';
|
|
2
|
-
const BOT_TOKEN = process.env['SLACK_BOT_TOKEN'];
|
|
3
|
-
export function fail(error) {
|
|
4
|
-
console.log(JSON.stringify({ ok: false, error }));
|
|
5
|
-
process.exit(1);
|
|
6
|
-
}
|
|
7
|
-
export function succeed(data = {}) {
|
|
8
|
-
console.log(JSON.stringify({ ok: true, ...data }));
|
|
9
|
-
process.exit(0);
|
|
10
|
-
}
|
|
11
|
-
if (!BOT_TOKEN)
|
|
12
|
-
fail('SLACK_BOT_TOKEN not set');
|
|
13
|
-
export const slack = new WebClient(BOT_TOKEN);
|
|
14
|
-
/**
|
|
15
|
-
* Parse CLI args: extracts known --flags and returns remaining positional args.
|
|
16
|
-
* Supports both --flag value and --flag=value syntax.
|
|
17
|
-
* Falls back to env vars for channel/thread_ts/message_ts.
|
|
18
|
-
*/
|
|
19
|
-
export function parseArgs(argv = process.argv.slice(2)) {
|
|
20
|
-
const flags = {};
|
|
21
|
-
const positional = [];
|
|
22
|
-
const knownFlags = ['--channel', '--thread_ts', '--thread-ts', '--message_ts', '--message-ts', '--text'];
|
|
23
|
-
let i = 0;
|
|
24
|
-
while (i < argv.length) {
|
|
25
|
-
const arg = argv[i];
|
|
26
|
-
// --flag=value
|
|
27
|
-
const eqMatch = arg.match(/^(--[\w-]+)=(.*)$/);
|
|
28
|
-
if (eqMatch) {
|
|
29
|
-
flags[eqMatch[1]] = eqMatch[2];
|
|
30
|
-
i++;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
// --flag value
|
|
34
|
-
if (knownFlags.includes(arg) && i + 1 < argv.length) {
|
|
35
|
-
flags[arg] = argv[i + 1];
|
|
36
|
-
i += 2;
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
positional.push(arg);
|
|
40
|
-
i++;
|
|
41
|
-
}
|
|
42
|
-
// If --text was provided, use it (and any remaining positional after it)
|
|
43
|
-
const textFromFlag = flags['--text'];
|
|
44
|
-
const channel = flags['--channel'] || process.env['SLACK_CHANNEL'];
|
|
45
|
-
const threadTs = flags['--thread_ts'] || flags['--thread-ts'] || process.env['SLACK_THREAD_TS'];
|
|
46
|
-
const messageTs = flags['--message_ts'] || flags['--message-ts'] || process.env['SLACK_MESSAGE_TS'];
|
|
47
|
-
return { channel, threadTs, messageTs, positional, textFromFlag };
|
|
48
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Read thread history from a Slack thread.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* node read-thread.js [limit]
|
|
7
|
-
* node read-thread.js --channel C123 --thread_ts 123.456 [limit]
|
|
8
|
-
*/
|
|
9
|
-
import { slack, fail, succeed, parseArgs } from './lib/slack-client.js';
|
|
10
|
-
const { channel, threadTs, positional } = parseArgs();
|
|
11
|
-
const limit = parseInt(positional[0] || '20', 10);
|
|
12
|
-
if (!channel)
|
|
13
|
-
fail('Channel required (--channel or SLACK_CHANNEL env)');
|
|
14
|
-
if (!threadTs)
|
|
15
|
-
fail('Thread TS required (--thread_ts or SLACK_THREAD_TS env)');
|
|
16
|
-
async function main() {
|
|
17
|
-
const result = await slack.conversations.replies({ channel: channel, ts: threadTs, limit });
|
|
18
|
-
const messages = (result.messages || []).map((m) => ({
|
|
19
|
-
user: m.user || m.bot_id || 'unknown',
|
|
20
|
-
text: m.text || '',
|
|
21
|
-
ts: m.ts,
|
|
22
|
-
is_bot: Boolean(m.bot_id),
|
|
23
|
-
}));
|
|
24
|
-
succeed({ messages });
|
|
25
|
-
}
|
|
26
|
-
main().catch((err) => fail(err instanceof Error ? err.message : String(err)));
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Remove an emoji reaction from the original message.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* node remove-reaction.js emoji_name
|
|
7
|
-
* node remove-reaction.js --channel C123 --message_ts 123.456 emoji_name
|
|
8
|
-
*/
|
|
9
|
-
import { slack, fail, succeed, parseArgs } from './lib/slack-client.js';
|
|
10
|
-
const { channel, messageTs, positional } = parseArgs();
|
|
11
|
-
const emoji = positional[0];
|
|
12
|
-
if (!emoji)
|
|
13
|
-
fail('Emoji name required');
|
|
14
|
-
if (!channel)
|
|
15
|
-
fail('Channel required (--channel or SLACK_CHANNEL env)');
|
|
16
|
-
if (!messageTs)
|
|
17
|
-
fail('Message TS required (--message_ts or SLACK_MESSAGE_TS env)');
|
|
18
|
-
async function main() {
|
|
19
|
-
await slack.reactions.remove({ channel: channel, timestamp: messageTs, name: emoji });
|
|
20
|
-
succeed();
|
|
21
|
-
}
|
|
22
|
-
main().catch((err) => fail(err instanceof Error ? err.message : String(err)));
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Send a message to a Slack thread.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* node send-message.js "Your message here"
|
|
7
|
-
* node send-message.js --text "Your message here"
|
|
8
|
-
* node send-message.js --channel C123 --thread_ts 123.456 "Your message"
|
|
9
|
-
*/
|
|
10
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Send a message to a Slack thread.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* node send-message.js "Your message here"
|
|
7
|
-
* node send-message.js --text "Your message here"
|
|
8
|
-
* node send-message.js --channel C123 --thread_ts 123.456 "Your message"
|
|
9
|
-
*/
|
|
10
|
-
import { slack, fail, succeed, parseArgs } from './lib/slack-client.js';
|
|
11
|
-
const { channel, threadTs, positional, textFromFlag } = parseArgs();
|
|
12
|
-
const text = textFromFlag || positional.join(' ');
|
|
13
|
-
if (!text)
|
|
14
|
-
fail('Message text required');
|
|
15
|
-
if (!channel)
|
|
16
|
-
fail('Channel required (--channel or SLACK_CHANNEL env)');
|
|
17
|
-
if (!threadTs)
|
|
18
|
-
fail('Thread TS required (--thread_ts or SLACK_THREAD_TS env)');
|
|
19
|
-
async function main() {
|
|
20
|
-
console.error(`[slack] send_message: channel=${channel}, thread_ts=${threadTs}`);
|
|
21
|
-
const result = await slack.chat.postMessage({
|
|
22
|
-
channel: channel,
|
|
23
|
-
thread_ts: threadTs,
|
|
24
|
-
text,
|
|
25
|
-
unfurl_links: false,
|
|
26
|
-
unfurl_media: false,
|
|
27
|
-
});
|
|
28
|
-
console.error(`[slack] posted: ts=${result.ts}`);
|
|
29
|
-
succeed({ ts: result.ts });
|
|
30
|
-
}
|
|
31
|
-
main().catch((err) => fail(err instanceof Error ? err.message : String(err)));
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Set the assistant thread status.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* node set-status.js "Status text"
|
|
7
|
-
*/
|
|
8
|
-
import { slack, fail, succeed, parseArgs } from './lib/slack-client.js';
|
|
9
|
-
const { channel, threadTs, positional } = parseArgs();
|
|
10
|
-
const status = positional.join(' ');
|
|
11
|
-
if (!channel)
|
|
12
|
-
fail('Channel required');
|
|
13
|
-
if (!threadTs)
|
|
14
|
-
fail('Thread TS required');
|
|
15
|
-
async function main() {
|
|
16
|
-
await slack.apiCall('assistant.threads.setStatus', { channel_id: channel, thread_ts: threadTs, status });
|
|
17
|
-
succeed();
|
|
18
|
-
}
|
|
19
|
-
main().catch((err) => fail(err instanceof Error ? err.message : String(err)));
|