Files
AgentCompany/AgentCompany-New/src/main/index.ts
T
ZacharyZhang-NY 0575712e02 Run the CEO agent autonomously with a real tool-use loop
The new app reached a real LLM but never ran an agent: the kickoff task_run
sat queued forever and runTask was a single text completion with no tools.

This adds the missing runtime:
- provider-tool-turn: OpenAI Responses + Anthropic Messages tool-use turns
- agent-tools + deliverable-writer: hire_agent, create_task,
  update_task_status, write_deliverable (workspace-scoped, traversal-safe)
- agent-run-loop: real tool-use loop, capped iterations
- task-queue-worker: claims queued runs in a transaction and executes them

task-execution now drives the loop; a background worker auto-runs the
bootstrap CEO run so it hires its team, delegates tasks, and writes the first
deliverable into the bound workspace. Autonomy is gated by AGENTCOMPANY_NEW_AUTORUN
(tests run with it off to stay hermetic).
2026-05-29 21:08:04 -04:00

55 lines
1.7 KiB
TypeScript

import { app } from "electron";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { DatabaseConnection } from "./database/connection";
import { createMainWindow } from "./app/create-window";
import { registerIpcHandlers } from "./app/ipc-handlers";
import { startProviderBackgroundWorker } from "./app/provider-background-worker";
import { startTaskQueueWorker } from "./app/task-queue-worker";
const __dirname = dirname(fileURLToPath(import.meta.url));
const hasSingleInstanceLock = app.requestSingleInstanceLock();
if (!hasSingleInstanceLock) {
app.quit();
}
app.whenReady().then(() => {
const profileDir = process.env.AGENTCOMPANY_NEW_PROFILE_DIR ?? join(app.getPath("userData"), "profile");
const connection = new DatabaseConnection(join(profileDir, "agentcompany.db"));
const win = createMainWindow({
preloadPath: join(__dirname, "../preload/index.js"),
rendererDist: join(__dirname, "../renderer"),
devServerUrl: process.env.ELECTRON_RENDERER_URL,
});
registerIpcHandlers({
connection,
mainWindow: win,
artifactRoot: join(profileDir, "artifacts"),
});
const stopProviderBackgroundWorker = startProviderBackgroundWorker({
db: connection.db,
mainWindow: win,
});
const autonomousExecution = process.env.AGENTCOMPANY_NEW_AUTORUN !== "0";
const stopTaskQueueWorker = autonomousExecution
? startTaskQueueWorker({ connection, mainWindow: win })
: () => {};
app.on("second-instance", () => {
if (win.isMinimized()) win.restore();
win.focus();
});
app.on("before-quit", () => {
stopProviderBackgroundWorker();
stopTaskQueueWorker();
connection.close();
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});