Skip to content
Draft
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
22 changes: 22 additions & 0 deletions .github/workflows/dune-review-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Dune Review Trigger

on:
pull_request:
types: [opened, reopened]

permissions:
pull-requests: write
contents: read

jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Add dune-review-requested label
run: |
gh label create 'dune-review-requested' --color '0075ca' --description 'Awaiting Dune agent review' --force
gh label create 'dune-review-in-progress' --color 'e4e669' --description 'Dune agent review in progress' --force
gh pr edit ${{ github.event.pull_request.number }} --add-label 'dune-review-requested'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
33 changes: 33 additions & 0 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { loadNetworkSettings } from '@/renderer/features/settings/model/network-
import { ipcChannels } from '@/shared/electron/ipc-channels';
import { createDefaultTasks } from '@/shared/workflow/default-tasks';
import { createQuitCoordinator } from '@/electron/main/quit-coordinator';
import { startPRReviewer } from '@/electron/main/pr-reviewer';
import { isPlainObject } from '@/shared/is-record';
import type {
WorkflowEvent as StoredWorkflowEvent,
Expand Down Expand Up @@ -85,10 +86,16 @@ let runtimeController: DesktopRuntimeController | null = null;
let nudgeScheduled = false;
let nudgeIntervalHandle: ReturnType<typeof setInterval> | null = null;
let taskSweepIntervalHandle: ReturnType<typeof setInterval> | null = null;
let stopPRReviewer: (() => void) | null = null;
let powerBlockerId: number | null = null;
let telegramReconnectPromise: Promise<void> | null = null;
const NUDGE_INTERVAL_MS = 60_000;
const TASK_SWEEP_INTERVAL_MS = 120_000;
const PR_REVIEWER_POLL_INTERVAL_MS = 5 * 60_000;
const PR_REVIEW_REPO_CONFIGS = [
{ owner: 'polygala-ai', repo: 'dune', reviewerAgentId: 'Mg_8MMfk' },
{ owner: 'boxlite-ai', repo: 'agentlite', reviewerAgentId: 'IaAuvT2t' },
];

/** Returns whether Telegram polling or setup observers should stay alive. */
function hasActiveTelegramChannels(snapshot: AgentServiceSnapshot) {
Expand Down Expand Up @@ -292,6 +299,10 @@ const quitCoordinator = createQuitCoordinator({
clearInterval(taskSweepIntervalHandle);
taskSweepIntervalHandle = null;
}
if (stopPRReviewer) {
stopPRReviewer();
stopPRReviewer = null;
}
stopPowerBlocker();
await runtimeController?.shutdown();
},
Expand Down Expand Up @@ -843,6 +854,28 @@ void app.whenReady().then(async () => {
void sweepItemAssignmentTasks();
}, TASK_SWEEP_INTERVAL_MS);
void sweepItemAssignmentTasks();

if (process.env.GITHUB_TOKEN) {
stopPRReviewer = startPRReviewer(
{
githubToken: process.env.GITHUB_TOKEN,
pollIntervalMs: PR_REVIEWER_POLL_INTERVAL_MS,
repos: PR_REVIEW_REPO_CONFIGS,
stateFilePath: path.join(userDataDir, 'pr-reviewer-state.json'),
},
{
getRuntimeController: requireRuntimeController,
onWorkflowChanged: () => {
for (const window of BrowserWindow.getAllWindows()) {
window.webContents.send(ipcChannels.workflowChanged);
}
},
workflowStore,
},
);
} else {
console.info('Automated PR reviewer poller disabled: GITHUB_TOKEN is not set.');
}
}).catch((error) => {
console.error('Failed to bootstrap the Dune runtime.', error);
throw error;
Expand Down
34 changes: 34 additions & 0 deletions src/electron/main/pr-reviewer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { ToolServices } from '@/electron/main/agent-actions/handlers/types';

import { pollPRReviewer } from './poller';
import type { PRReviewerConfig } from './types';

/** Starts the automated PR reviewer poller. */
export function startPRReviewer(
config: PRReviewerConfig,
services: Omit<ToolServices, 'agentContext'>,
): () => void {
let isPolling = false;

const run = () => {
if (isPolling) {
return;
}

isPolling = true;
void pollPRReviewer(config, services)
.catch((error) => {
console.error('Automated PR reviewer poll failed.', error);
})
.finally(() => {
isPolling = false;
});
};

run();
const intervalHandle = setInterval(run, config.pollIntervalMs);

return () => {
clearInterval(intervalHandle);
};
}
Loading