Skip to content

Commit 0674b20

Browse files
committed
🤖 fix: address remaining review feedback
- Fix trunk branch detection for worktree/SSH runtimes: detect default trunk branch from parent project for non-local runtimes - Apply preset systemPrompt via additionalSystemInstructions in startTask and rehydrateTasks continuation messages Note: restart-safe foreground task waiting (parentToolCallId plumbing to inject tool output in parent) requires significant additional infrastructure and is deferred. The parentToolCallId is stored for future use but not actively used for restart recovery yet. Change-Id: I9d5a3d18f373564179e7a405a700b31e9a6739db Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent d388d0b commit 0674b20

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/node/services/taskService.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
type MuxFrontendMetadata,
2424
} from "@/common/types/message";
2525
import type { FrontendWorkspaceMetadata } from "@/common/types/workspace";
26+
import { detectDefaultTrunkBranch, listLocalBranches } from "@/node/git";
2627
import * as crypto from "crypto";
2728

2829
export interface CreateTaskOptions {
@@ -163,12 +164,27 @@ export class TaskService extends EventEmitter {
163164
// For local workspaces, this has no change in behavior
164165
const parentRuntime = parentMetadata.runtimeConfig;
165166

167+
// Detect trunk branch for worktree/SSH runtimes
168+
// Local runtime doesn't need a trunk branch
169+
let trunkBranch = "";
170+
const isLocalRuntime =
171+
parentRuntime.type === "local" &&
172+
!("srcBaseDir" in parentRuntime && parentRuntime.srcBaseDir);
173+
if (!isLocalRuntime) {
174+
try {
175+
const branches = await listLocalBranches(parentInfo.projectPath);
176+
trunkBranch = (await detectDefaultTrunkBranch(parentInfo.projectPath, branches)) ?? "main";
177+
} catch (error) {
178+
log.warn(`Failed to detect trunk branch for agent task, using 'main':`, error);
179+
trunkBranch = "main";
180+
}
181+
}
182+
166183
// Create workspace via WorkspaceService
167-
// Using empty trunk branch because agent workspaces don't need git isolation
168184
const createResult = await this.workspaceService.create(
169185
parentInfo.projectPath,
170186
workspaceName,
171-
"", // No trunk branch - agent tasks share parent's working directory context
187+
trunkBranch,
172188
workspaceTitle,
173189
parentRuntime // Inherit runtime from parent workspace
174190
);
@@ -247,8 +263,8 @@ export class TaskService extends EventEmitter {
247263
model: "anthropic:claude-sonnet-4-20250514", // Default model for agents
248264
thinkingLevel: "medium",
249265
toolPolicy: preset.toolPolicy,
266+
additionalSystemInstructions: preset.systemPrompt,
250267
mode: "exec", // Agent tasks are always in exec mode
251-
// System prompt override happens in AIService based on agentType
252268
});
253269

254270
if (!result.success) {
@@ -508,13 +524,15 @@ export class TaskService extends EventEmitter {
508524
} else if (taskState.taskStatus === "running") {
509525
// Send continuation message for running tasks
510526
try {
527+
const preset = getAgentPreset(taskState.agentType);
511528
const result = await this.workspaceService.sendMessage(
512529
workspaceId,
513530
"Mux was restarted. Please continue your task and call agent_report when done.",
514531
{
515532
model: "anthropic:claude-sonnet-4-20250514",
516533
thinkingLevel: "medium",
517-
toolPolicy: getAgentPreset(taskState.agentType).toolPolicy,
534+
toolPolicy: preset.toolPolicy,
535+
additionalSystemInstructions: preset.systemPrompt,
518536
mode: "exec",
519537
}
520538
);

0 commit comments

Comments
 (0)