Skip to content

Commit 3315984

Browse files
authored
refactor: clean up agent package (#574)
1 parent ec1f9ee commit 3315984

46 files changed

Lines changed: 2739 additions & 6951 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/twig/src/api/posthogClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { AgentEvent } from "@posthog/agent";
21
import { logger } from "@renderer/lib/logger";
32
import type { Task, TaskRun } from "@shared/types";
43
import type { StoredLogEntry } from "@shared/types/session-events";
@@ -258,7 +257,7 @@ export class PostHogAPIClient {
258257
}
259258
}
260259

261-
async getTaskLogs(taskId: string): Promise<AgentEvent[]> {
260+
async getTaskLogs(taskId: string): Promise<StoredLogEntry[]> {
262261
try {
263262
const task = (await this.getTask(taskId)) as unknown as Task;
264263
const logUrl = task?.latest_run?.log_url;
@@ -284,7 +283,7 @@ export class PostHogAPIClient {
284283
return content
285284
.trim()
286285
.split("\n")
287-
.map((line) => JSON.parse(line) as AgentEvent);
286+
.map((line) => JSON.parse(line) as StoredLogEntry);
288287
} catch (err) {
289288
log.warn("Failed to fetch task logs from latest run", err);
290289
return [];

apps/twig/src/main/services/agent/service.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,17 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
341341
this.setupEnvironment(credentials, mockNodeDir);
342342

343343
const agent = new Agent({
344-
workingDirectory: repoPath,
345-
posthogApiUrl: credentials.apiHost,
346-
getPosthogApiKey: () => this.getToken(credentials.apiKey),
347-
posthogProjectId: credentials.projectId,
344+
posthog: {
345+
apiUrl: credentials.apiHost,
346+
getApiKey: () => this.getToken(credentials.apiKey),
347+
projectId: credentials.projectId,
348+
},
348349
debug: !app.isPackaged,
349350
onLog: onAgentLog,
350351
});
351352

352353
try {
353-
const { clientStreams } = await agent.runTaskV2(taskId, taskRunId, {
354-
skipGitBranch: true,
355-
isReconnect,
356-
});
354+
const { clientStreams } = await agent.run(taskId, taskRunId);
357355

358356
const connection = this.createClientConnection(
359357
taskRunId,
@@ -534,14 +532,8 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
534532
const session = this.sessions.get(sessionId);
535533
if (!session) return false;
536534

537-
try {
538-
session.agent.cancelTask(session.taskId);
539-
this.cleanupSession(sessionId);
540-
return true;
541-
} catch (_err) {
542-
this.cleanupSession(sessionId);
543-
return false;
544-
}
535+
this.cleanupSession(sessionId);
536+
return true;
545537
}
546538

547539
async cancelPrompt(
@@ -724,14 +716,7 @@ For git operations while detached:
724716
log.warn("Failed to send ACP cancel", { taskRunId, error: err });
725717
}
726718

727-
// Step 2: Cancel via agent (triggers AbortController)
728-
try {
729-
session.agent.cancelTask(session.taskId);
730-
} catch (err) {
731-
log.warn("Failed to cancel task", { taskRunId, error: err });
732-
}
733-
734-
// Step 3: Cleanup agent connection (closes streams, aborts subprocess)
719+
// Step 2: Cleanup agent connection (closes streams, aborts subprocess)
735720
try {
736721
await session.agent.cleanup();
737722
} catch (err) {

apps/twig/src/renderer/features/task-detail/utils/eventEmitter.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

knip.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/knip@latest/schema.json",
3+
"ignoreWorkspaces": ["apps/mobile"],
34
"workspaces": {
45
".": {
56
"entry": ["mprocs.yaml"]

0 commit comments

Comments
 (0)