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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat(cos): generate rich PR descriptions from branch commits and diff stats
Adam Eivye1a317ce3497
diff --git a/server/services/cleanupAgentWorktree.test.js b/server/services/cleanupAgentWorktree.test.jsindex 89a061bca1..5e474e910d 100644--- a/server/services/cleanupAgentWorktree.test.js+++ b/server/services/cleanupAgentWorktree.test.js@@ -158,7 +158,8 @@ vi.mock('./jira.js', () => ({vi.mock('./git.js', () => ({push: vi.fn(),getRepoBranches: vi.fn(),- createPR: vi.fn()+ createPR: vi.fn(),+ generatePRDescription: vi.fn()}));vi.mock('./runner.js', () => ({@@ -194,6 +195,10 @@ describe('cleanupAgentWorktree - openPR path', () => {// Default: agent is a worktree agent with valid metadatagetAgent.mockResolvedValue(mockWorktreeAgent());git.getRepoBranches.mockResolvedValue({ baseBranch: 'main', devBranch: null });+ // generatePRDescription returns a rich body that includes the task description+ git.generatePRDescription.mockImplementation((_dir, _base, _head, desc) =>+ Promise.resolve(`Automated PR created by PortOS Chief of Staff.\n\n## Changes\n- feat: implemented task\n\n**1 file changed** (+10 -2)\n\n<details><summary>Original task</summary>\n\n${desc || 'CoS automated task'}\n\n</details>`)+ );});it('should run PR flow when openPR is true and success is true', async () => {diff --git a/server/services/git.js b/server/services/git.jsindex 8f97a32780..ba6977839e 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -409,6 +409,60 @@ export async function createPR(dir, { title, body, base, head }) {});}+/**+ * Generate a rich PR description from branch commits and diff stats.+ * Falls back to a simple description if git data is unavailable.+ * @param {string} dir - Working directory (repo root)+ * @param {string} baseBranch - Base branch (e.g., 'main')+ * @param {string} headBranch - Head branch (agent's branch)+ * @param {string} taskDescription - Original task prompt+ * @returns {Promise<string>} Formatted PR body+ */+export async function generatePRDescription(dir, baseBranch, headBranch, taskDescription) {+ const sections = ['Automated PR created by PortOS Chief of Staff.'];++ const [comparison, changedFiles] = await Promise.all([+ getBranchComparison(dir, baseBranch, headBranch).catch(() => null),+ execGit(['diff', '--name-only', `${baseBranch}...${headBranch}`], dir, { ignoreExitCode: true })+ .then(r => r.stdout.trim().split('\n').filter(Boolean)).catch(() => [])+ ]);++ if (comparison?.commits?.length) {+ sections.push('\n## Changes');+ for (const c of comparison.commits) {+ sections.push(`- ${c.message}`);+ }+ }++ if (comparison?.stats) {+ const { files, insertions, deletions } = comparison.stats;+ if (files > 0) {+ sections.push(`\n**${files} file${files === 1 ? '' : 's'} changed** (+${insertions} -${deletions})`);+ }+ }++ if (changedFiles.length > 0 && changedFiles.length <= 30) {+ sections.push('\n<details><summary>Files changed</summary>\n');+ for (const f of changedFiles) {+ sections.push(`- \`${f}\``);+ }+ sections.push('\n</details>');+ } else if (changedFiles.length > 30) {+ sections.push(`\n<details><summary>Files changed (${changedFiles.length})</summary>\n`);+ for (const f of changedFiles.slice(0, 30)) {+ sections.push(`- \`${f}\``);+ }+ sections.push(`- ... and ${changedFiles.length - 30} more`);+ sections.push('\n</details>');+ }++ if (taskDescription) {+ sections.push(`\n<details><summary>Original task</summary>\n\n${taskDescription}\n\n</details>`);+ }++ return sections.join('\n');+}+/*** Detect base and dev branches from local branch list* @returns {{ baseBranch: string|null, devBranch: string|null }}diff --git a/server/services/subAgentSpawner.js b/server/services/subAgentSpawner.jsindex 99365c8b0b..382845cdb4 100644--- a/server/services/subAgentSpawner.js+++ b/server/services/subAgentSpawner.js@@ -1934,9 +1934,12 @@ async function handleAgentCompletion(agentId, exitCode, success, duration) {const { baseBranch, devBranch } = await git.getRepoBranches(workspace).catch(() => ({ baseBranch: null, devBranch: null }));const targetBranch = devBranch || baseBranch || 'main';+ const jiraPrBody = await git.generatePRDescription(workspace, targetBranch, jiraBranch, task.description);+ const jiraPrBodyWithRef = `Resolves ${jiraTicketRef}\n\n${jiraPrBody}`;+const prResult = await git.createPR(workspace, {title: `${jiraTicketId}: ${(task.description || 'CoS automated task').substring(0, 100)}`,- body: `Resolves ${jiraTicketRef}\n\nAutomated PR created by PortOS Chief of Staff.\n\n**Task:** ${task.description || ''}`,+ body: jiraPrBodyWithRef,base: targetBranch,head: jiraBranch}).catch(err => {@@ -2051,9 +2054,11 @@ export async function cleanupAgentWorktree(agentId, success, { openPR = false, dconst taskDesc = description || 'CoS automated task';const prTitle = taskDesc.replace(/[\r\n]+/g, ' ').trim().substring(0, 100);+ const prBody = await git.generatePRDescription(worktreePath, targetBranch, worktreeBranch, taskDesc);+const prResult = await git.createPR(worktreePath, {title: prTitle,- body: `Automated PR created by PortOS Chief of Staff.\n\n**Task:** ${taskDesc}`,+ body: prBody,base: targetBranch,head: worktreeBranch}).catch(err => {