@gonzih/cc-tg 0.6.5 → 0.6.6

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.
@@ -1,98 +0,0 @@
1
- /**
2
- * cc-agent Redis event subscriber.
3
- *
4
- * Listens to the `cca:events` pub/sub channel for job completion events,
5
- * asks Claude to decide what to do, and acts accordingly:
6
- * NOTIFY_ONLY — send a Telegram message to the configured chat
7
- * SPAWN_FOLLOWUP — spawn a follow-up cc-agent job via MCP + notify Telegram
8
- * SILENT — log and do nothing
9
- *
10
- * Controlled via CC_AGENT_EVENTS_ENABLED env var (default: true).
11
- * Requires CC_AGENT_NOTIFY_CHAT_ID to send Telegram notifications.
12
- */
13
- import { Redis } from "ioredis";
14
- export interface JobEvent {
15
- jobId: string;
16
- status: "done" | "failed" | "interrupted" | "running" | "cancelled";
17
- title: string;
18
- repoUrl: string;
19
- lastLines: string[];
20
- score?: number;
21
- timestamp: number;
22
- }
23
- export interface CoordinatorPlan {
24
- nextStep?: {
25
- repo_url: string;
26
- task: string;
27
- };
28
- summary: string;
29
- }
30
- export interface DecisionResult {
31
- action: "NOTIFY_ONLY" | "SPAWN_FOLLOWUP" | "SILENT";
32
- message?: string;
33
- followup?: {
34
- repo_url: string;
35
- task: string;
36
- };
37
- }
38
- /** Injectable dependencies for testability */
39
- export interface HandlerDeps {
40
- askClaude: (prompt: string) => Promise<string>;
41
- sendTelegramMessage: (chatId: number, text: string) => Promise<void>;
42
- spawnFollowupAgent: (repoUrl: string, task: string) => Promise<void>;
43
- readJobOutput: (jobId: string) => Promise<string[]>;
44
- readCoordinatorPlan: (jobId: string) => Promise<CoordinatorPlan | null>;
45
- getRunningJobCount: () => Promise<number>;
46
- getActiveChatIds: () => Promise<number[]>;
47
- }
48
- export declare function buildDecisionPrompt(event: JobEvent, last40lines: string[], coordinatorPlan: CoordinatorPlan | null): string;
49
- export declare function parseDecision(raw: string): DecisionResult;
50
- /**
51
- * Ask Claude to make a decision about a completed job.
52
- * Returns the raw text response from Claude.
53
- */
54
- export declare function defaultAskClaude(prompt: string): Promise<string>;
55
- export declare function defaultSendTelegramMessage(chatId: number, text: string): Promise<void>;
56
- export declare function defaultSpawnFollowupAgent(repoUrl: string, task: string): Promise<void>;
57
- export declare function defaultReadJobOutput(jobId: string): Promise<string[]>;
58
- export declare function defaultReadCoordinatorPlan(jobId: string): Promise<CoordinatorPlan | null>;
59
- export declare function defaultGetRunningJobCount(): Promise<number>;
60
- /**
61
- * Returns chat IDs to notify about job events.
62
- * Reads unique chatIds from the cron jobs file (same users who set up cron jobs).
63
- * Falls back to CC_AGENT_NOTIFY_CHAT_ID env var for backward compatibility.
64
- */
65
- export declare function defaultGetActiveChatIds(): Promise<number[]>;
66
- /**
67
- * Write a coordinator plan for a job, so cc-tg knows what follow-up to spawn.
68
- * Call this when spawning a job that has a planned follow-up.
69
- * TTL: 7 days.
70
- */
71
- export declare function writeCoordinatorPlan(jobId: string, plan: {
72
- nextStep?: {
73
- repo_url: string;
74
- task: string;
75
- };
76
- summary: string;
77
- }): Promise<void>;
78
- /**
79
- * Handle a single job event message from Redis pub/sub.
80
- * Exported for testability — production code passes defaultDeps.
81
- */
82
- export declare function handleJobEvent(message: string, deps: HandlerDeps): Promise<void>;
83
- /** Parse flat key-value field array from a Redis Stream entry into a record. */
84
- export declare function parseStreamFields(fields: string[]): Record<string, string>;
85
- /** Convert stream entry fields to a JobEvent JSON string for handleJobEvent. */
86
- export declare function streamEntryToMessage(fields: Record<string, string>): string | null;
87
- /**
88
- * Replay events from the Redis Stream that were missed since last-seen ID.
89
- * Uses `cca:event-stream:last-id:{botName}` in Redis to track position.
90
- * Exported for testability — pass a real or mock Redis instance.
91
- */
92
- export declare function replayStreamEvents(redis: Redis, deps: HandlerDeps, botName?: string): Promise<void>;
93
- /**
94
- * Connect to Redis and subscribe to cca:events.
95
- * Reconnects automatically on disconnect.
96
- * Call once at startup.
97
- */
98
- export declare function connectEventSubscriber(): Promise<void>;