Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions src/backends/progressMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ export interface ProgressMonitorConfig {
github?: { owner: string; repo: string; headerMessage: string };
/** Pre-seeded comment ID from router ack — skip initial comment posting */
preSeededCommentId?: string;
/**
* Progressive schedule of delays (in minutes) before falling back to
* `intervalMinutes` for steady-state ticks.
* Example: [1, 3, 5] means first tick at 1min, second at 3min, third at 5min,
* then every `intervalMinutes` thereafter.
* Defaults to DEFAULT_SCHEDULE_MINUTES = [1, 3, 5].
*/
scheduleMinutes?: number[];
}

/** Default progressive schedule: 1min, 3min, 5min, then every intervalMinutes */
const DEFAULT_SCHEDULE_MINUTES = [1, 3, 5];

const RING_BUFFER_MAX = 20;
const TEXT_SNIPPETS_MAX = 10;
const COMPLETED_TASKS_MAX = 5;
Expand Down Expand Up @@ -65,12 +76,18 @@ export class ProgressMonitor implements ProgressReporter {
private currentIteration = 0;
private maxIterations = 0;
private startTime = Date.now();
private timer: ReturnType<typeof setInterval> | null = null;
private timer: ReturnType<typeof setTimeout> | null = null;
private isGenerating = false;
private progressCommentId: string | null = null;
private initialCommentPromise: Promise<void> | null = null;
private tickIndex = 0;
private stopped = false;
private started = false;
private readonly schedule: number[];

constructor(private readonly config: ProgressMonitorConfig) {}
constructor(private readonly config: ProgressMonitorConfig) {
this.schedule = config.scheduleMinutes ?? DEFAULT_SCHEDULE_MINUTES;
}

// ── Public accessors ──

Expand Down Expand Up @@ -126,12 +143,9 @@ export class ProgressMonitor implements ProgressReporter {
// ── Lifecycle ──

start(): void {
if (this.timer) return;
if (this.started) return;
this.started = true;
this.startTime = Date.now();
const intervalMs = this.config.intervalMinutes * 60 * 1000;
this.timer = setInterval(() => {
void this.tick();
}, intervalMs);

if (this.config.preSeededCommentId) {
// Router already posted the ack comment — reuse its ID
Expand All @@ -156,11 +170,15 @@ export class ProgressMonitor implements ProgressReporter {
});
});
}

// Start the progressive tick chain
this.scheduleNextTick();
}

stop(): void {
this.stopped = true;
if (this.timer) {
clearInterval(this.timer);
clearTimeout(this.timer);
this.timer = null;
}
// Clean up state file on stop (best-effort — stop() is called from finally
Expand All @@ -174,6 +192,31 @@ export class ProgressMonitor implements ProgressReporter {

// ── Internal ──

/**
* Schedules the next tick using the progressive schedule.
* Uses schedule[tickIndex] if available, otherwise falls back to intervalMinutes.
*/
private scheduleNextTick(): void {
const delayMinutes =
this.tickIndex < this.schedule.length
? this.schedule[this.tickIndex]
: this.config.intervalMinutes;
const delayMs = delayMinutes * 60 * 1000;
this.timer = setTimeout(() => {
void this.tickAndScheduleNext();
}, delayMs);
}

/** Fires a tick, increments the counter, then schedules the next one. */
private async tickAndScheduleNext(): Promise<void> {
await this.tick();
this.tickIndex++;
// Only schedule next tick if stop() hasn't been called
if (!this.stopped) {
this.scheduleNextTick();
}
}

private formatInitialMessage(): string {
return (
INITIAL_MESSAGES[this.config.agentType] ??
Expand Down
4 changes: 2 additions & 2 deletions src/router/ackMessageGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { getOrgCredential, loadConfig } from '../config/provider.js';
// System prompt for ack message generation
// ---------------------------------------------------------------------------

const ACK_SYSTEM_PROMPT = `You write brief acknowledgment messages for CASCADE, an AI coding automation platform.
Given the agent type and request context, write a SHORT 1-sentence message confirming understanding of the request. Keep it under 25 words. Use markdown bold for the header. Start with an appropriate emoji. Do not mention implementation details — just confirm what you'll be working on.`;
const ACK_SYSTEM_PROMPT = `You write brief, casual acknowledgment messages for an AI coding bot. The goal is to buy time — let the user know you've seen their request while work kicks off in the background.
Keep it under 20 words. Start with a single relevant emoji. Be conversational and natural — like a friendly coworker responding in chat. Reference the specific topic from the context (e.g. "the chart library question", "that auth bug", "the dark mode feature"). Never say "Understood", "I will", or "I'll be working on". Use casual buying-time phrasing like "Just a moment, let me look into...", "On it — checking the...", "Give me a sec, pulling up...", "Looking into the... now", "Let me dig into...". No markdown formatting. No period at the end.`;

// ---------------------------------------------------------------------------
// Context extractors — pull relevant snippets from webhook payloads
Expand Down
Loading