11import { logger , metadata , task } from "@trigger.dev/sdk" ;
2- import { spawn } from "child_process" ;
3- import { chmodSync , copyFileSync , existsSync , mkdirSync , readdirSync } from "fs" ;
2+ import { mkdirSync } from "fs" ;
43import type { CursorEvent } from "@/lib/cursor-events" ;
4+ import { spawnCursorAgent } from "../extensions/cursor-cli" ;
55
66export type CursorAgentPayload = {
77 prompt : string ;
@@ -22,44 +22,12 @@ export const cursorAgentTask = task({
2222
2323 const model = payload . model ?? "sonnet-4.5" ;
2424
25- // The Trigger.dev runtime strips execute permissions from all binaries.
26- // cursor-agent bundles native .node modules (pty, sqlite3, etc.) compiled for its own node,
27- // so we must use cursor-agent's bundled node — not the container's node (ABI mismatch).
28- // Workaround: copy the bundled node to /tmp and chmod +x it there.
29- const cursorDir = "/usr/local/lib/cursor-agent" ;
30- const entryPoint = `${ cursorDir } /index.js` ;
31- const bundledNode = `${ cursorDir } /node` ;
32- const tmpNode = "/tmp/cursor-node" ;
33-
34- if ( ! existsSync ( entryPoint ) ) {
35- const dirExists = existsSync ( cursorDir ) ;
36- throw new Error ( `cursor-agent not found at ${ entryPoint } . Dir: ${ dirExists } . Contents: ${ dirExists ? readdirSync ( cursorDir ) . join ( ", " ) : "N/A" } ` ) ;
37- }
25+ logger . info ( "Spawning cursor-agent" , { workspace, model } ) ;
3826
39- // Copy bundled node to /tmp and make it executable
40- copyFileSync ( bundledNode , tmpNode ) ;
41- chmodSync ( tmpNode , 0o755 ) ;
42-
43- logger . info ( "Spawning cursor-agent" , { node : tmpNode , entryPoint, workspace, model } ) ;
44-
45- const child = spawn ( tmpNode , [
46- entryPoint ,
47- "-p" ,
48- "--force" ,
49- "--output-format" ,
50- "stream-json" ,
51- "--model" ,
52- model ,
53- payload . prompt ,
54- ] , {
55- stdio : [ "ignore" , "pipe" , "pipe" ] ,
56- env : {
57- ...process . env ,
58- CURSOR_API_KEY : process . env . CURSOR_API_KEY ,
59- CURSOR_INVOKED_AS : "cursor-agent" ,
60- } ,
61- cwd : workspace ,
62- } ) ;
27+ const child = spawnCursorAgent (
28+ [ "-p" , "--force" , "--output-format" , "stream-json" , "--model" , model , payload . prompt ] ,
29+ { cwd : workspace , env : { CURSOR_API_KEY : process . env . CURSOR_API_KEY } } ,
30+ ) ;
6331
6432 let spawnError : Error | null = null ;
6533 child . on ( "error" , ( err ) => {
0 commit comments