Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(cos): resolve PR opening and merging lifecycle for Antigravity and TUI agents

[._.]/ Adam Eivy9c8e0ef04744
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index d97d497f0d..dd7a464e48 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -1561,6 +1561,17 @@ After your task completes, the system will spawn a follow-up agent that runs the
// top of buildAgentPrompt under the same reviewLoopFollowUp guard — reuse it
// rather than re-reading the lib a second time.
reviewLoopFollowUpSection = buildReviewLoopFollowUpSection(task.metadata || {}, { verbose: true, rprBody, localAgentLoopBody });
+ if (isTui) {
+ const sentinelPath = `${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`;
+ const branchName = worktreeInfo?.branchName || task.metadata?.reviewLoopPRBranch || null;
+ const sentinelTail = branchName ? ` ## Branch\n ${branchName}` : ' ## Branch\n <branch name>';
+ reviewLoopFollowUpSection += '\n\n' + [
+ '## Completion Handoff',
+ 'When finished with the follow-up steps above, write the completion sentinel to signal PortOS that you are done:',
+ '',
+ ...buildSentinelWriteSteps(1, sentinelPath, sentinelTail)
+ ].join('\n');
+ }
}
// Build JIRA context section if applicable
@@ -1934,6 +1945,17 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, isTruthyMet
}));
} else if (isReviewLoopFollowUp) {
sections.push(buildReviewLoopFollowUpSection(task.metadata || {}, { verbose: false, localAgentLoopBody }));
+ if (isTui) {
+ const sentinelPath = `${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`;
+ const branchName = worktreeInfo?.branchName || task.metadata?.reviewLoopPRBranch || null;
+ const sentinelTail = branchName ? ` ## Branch\n ${branchName}` : ' ## Branch\n <branch name>';
+ sections.push([
+ '## Completion Handoff',
+ 'When finished with the follow-up steps above, write the completion sentinel to signal PortOS that you are done:',
+ '',
+ ...buildSentinelWriteSteps(1, sentinelPath, sentinelTail)
+ ].join('\n'));
+ }
} else if (isTui) {
sections.push(buildTuiCompletionSection({
willOpenPR, prCompletion, simplifyEnabled, slashdoFree: tuiSlashdoFree,
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index a9d7485abd..6b3005ac0a 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -2445,3 +2445,32 @@ describe('getClaudeMdContext — nested CLAUDE.md discovery (#3866)', () => {
rmSync(empty, { recursive: true, force: true });
});
});
+
+describe('TUI reviewLoopFollowUp completion instructions', () => {
+ it('appends .agent-done sentinel instructions for TUI agents on follow-up tasks', async () => {
+ const task = {
+ id: 'task-flw-1',
+ description: 'Follow-up merge PR',
+ metadata: {
+ useWorktree: true,
+ openPR: false,
+ reviewLoopFollowUp: true,
+ reviewLoopMergeOnly: true,
+ reviewLoopPRUrl: 'https://github.com/org/repo/pull/42',
+ reviewLoopPRBranch: 'cos/task-orig/agent-1',
+ providerId: 'antigravity-tui',
+ providerCommand: 'agy',
+ }
+ };
+ const worktreeInfo = { worktreePath: '/tmp/wt-1', branchName: 'cos/task-orig/agent-1' };
+ const prompt = await buildLightContextPrompt(task, '/repo', worktreeInfo, (v) => v === true || v === 'true', {
+ isTui: true,
+ providerId: 'antigravity-tui',
+ providerCommand: 'agy',
+ });
+ expect(prompt).toContain('## Completion Handoff');
+ expect(prompt).toContain('cat > "/tmp/wt-1/.agent-done"');
+ expect(prompt).toContain('## Summary');
+ });
+});
+
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index e9bca91f5e..f71ae1b4d2 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -1070,7 +1070,7 @@ export async function spawnTuiAgent({
openPR: agentOwnsPR ? false : taskOpenPR,
prCompletion: resolvePrCompletion(task.metadata),
...reviewOptions,
- skipMerge: agentOwnsPR,
+ skipMerge: taskReviewLoopFollowUp || agentOwnsPR,
description: task.description,
agentOutput: getOutputBuffer(),
originalTask: task
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index dcb3dcc14e..903ca39fd7 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -1839,6 +1839,9 @@ export function applyAppWorktreeDefault(metadata, app) {
metadata.useWorktree = true; // openPR implies useWorktree
} else if (app.defaultOpenPR === false || taskTypeDisabledWorktree) {
metadata.openPR = false;
+ } else if ((app.defaultUseWorktree === true || metadata.useWorktree === true || metadata.useWorktree === 'true') && app.defaultOpenPR !== false) {
+ metadata.openPR = true;
+ metadata.useWorktree = true;
}
}
diff --git a/server/services/subAgentSpawner.test.js b/server/services/subAgentSpawner.test.js
index 8b9e5fbf18..9b0555cbcd 100644
--- a/server/services/subAgentSpawner.test.js
+++ b/server/services/subAgentSpawner.test.js
@@ -401,6 +401,18 @@ describe('Worktree & metadata flag helpers', () => {
expect(metadata.useWorktree).toBe(true);
expect(metadata.openPR).toBe(true);
});
+
+ it('should default openPR to true when worktree is enabled and defaultOpenPR is not false', () => {
+ const metadata = { useWorktree: true };
+ applyAppWorktreeDefault(metadata, {});
+ expect(metadata.openPR).toBe(true);
+
+ const metadata2 = {};
+ applyAppWorktreeDefault(metadata2, { defaultUseWorktree: true });
+ expect(metadata2.useWorktree).toBe(true);
+ expect(metadata2.openPR).toBe(true);
+ });
});
});
+