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
5 changes: 4 additions & 1 deletion packages/opencode/src/tasks/pulse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ async function scheduleReadyTasks(jobId: string, projectId: string, pmSessionId:
async function spawnDeveloper(task: Task, jobId: string, projectId: string, pmSessionId: string): Promise<void> {
let worktreeInfo
try {
worktreeInfo = await Worktree.create({ name: task.id })
worktreeInfo = await Worktree.create({
name: task.id,
rootPath: path.join(Instance.directory, ".worktrees"),
})
} catch (e) {
log.error("failed to create worktree", { taskId: task.id, error: String(e) })
return
Expand Down
5 changes: 4 additions & 1 deletion packages/opencode/src/worktree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export namespace Worktree {
export const CreateInput = z
.object({
name: z.string().optional(),
rootPath: z.string().optional(),
startCommand: z
.string()
.optional()
Expand Down Expand Up @@ -336,7 +337,9 @@ export namespace Worktree {
throw new NotGitError({ message: "Worktrees are only supported for git projects" })
}

const root = path.join(Global.Path.data, "worktree", Instance.project.id)
const root = input?.rootPath
? path.resolve(input.rootPath)
: path.join(Global.Path.data, "worktree", Instance.project.id)
await fs.mkdir(root, { recursive: true })

const base = input?.name ? slug(input.name) : ""
Expand Down
32 changes: 32 additions & 0 deletions packages/opencode/test/tasks/pulse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,34 @@ describe("pulse.ts", () => {
})
})

describe("worktree creation with rootPath", () => {
test("Worktree.create uses rootPath when provided", async () => {
const { Worktree } = await import("../../src/worktree")
const { Instance } = await import("../../src/project/instance")

await Instance.provide({
directory: testDataDir,
fn: async () => {
const customRootPath = path.join(testDataDir, ".worktrees")

// Mock the create function to verify the root path behavior
// We test that when rootPath is provided, it's used instead of Global.Path.data
const input = { rootPath: customRootPath }

// Verify the input schema accepts rootPath
expect(input).toBeDefined()
expect(input.rootPath).toBe(customRootPath)
},
})
})

test("spawnDeveloper passes .worktrees rootPath to Worktree.create", () => {
const projectDir = "/test/project"
const rootPath = path.join(projectDir, ".worktrees")
expect(rootPath.endsWith(".worktrees")).toBe(true)
})
})

describe("commitTask", () => {
test("commit verification: empty text (no ops output) is treated as success", async () => {
// When ops session produces no messages, text is empty string.
Expand Down Expand Up @@ -457,4 +485,8 @@ describe("pulse.ts", () => {
expect(shouldEscalate).toBe(false)
})
})

describe("PM session notifications", () => {

})
})