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
fix: derive PR titles from the remote target history
Adam Eivy28501f01f080
diff --git a/server/services/git.js b/server/services/git.jsindex 868f762d2b..d63293c6c4 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -564,12 +564,19 @@ export async function generatePRDescription(dir, baseBranch, headBranch, agentOu* @returns {Promise<string>} PR title (<= 100 chars)*/export async function suggestPRTitle(dir, baseBranch, headBranch, fallbackText) {- const comparison = await getBranchComparison(dir, baseBranch, headBranch).catch(() => null);- if (comparison?.commits?.length) {- const oldest = comparison.commits[comparison.commits.length - 1];- const subject = oldest?.message?.trim();- if (subject) return subject.substring(0, 100);- }+ assertSafeRef(baseBranch);+ assertSafeRef(headBranch);+ // A worktree's local main may lag the PR target by many merged commits.+ // Compare against the fetched remote target, matching what the forge reviews.+ const remoteBase = `refs/remotes/origin/${baseBranch}`;+ const remote = await execGitSafe(['rev-parse', '--verify', remoteBase], dir);+ const baseRef = remote.exitCode === 0 ? remoteBase : baseBranch;+ const log = await execGitSafe(+ ['log', '--reverse', '--no-merges', '--format=%s', `${baseRef}..${headBranch}`], dir,+ );+ // Subjects are plain text: JSON interpolation drops titles containing quotes.+ const subject = log.stdout?.split(/\r?\n/).find(line => line.trim())?.trim();+ if (subject) return subject.substring(0, 100);const firstLine = (fallbackText || '').split(/[\r\n]/).find(l => l.trim()) || '';return firstLine.trim().substring(0, 100) || 'CoS automated task';}diff --git a/server/services/git.prTitle.test.js b/server/services/git.prTitle.test.jsnew file mode 100644index 0000000000..6deeaf56d7--- /dev/null+++ b/server/services/git.prTitle.test.js@@ -0,0 +1,31 @@+import { afterEach, describe, expect, it } from 'vitest';+import { rm } from 'fs/promises';+import { makeGitSandbox } from '../lib/gitTestRepo.js';+import { execGit, suggestPRTitle } from './git.js';++let scratch;+afterEach(async () => { if (scratch) await rm(scratch, { recursive: true, force: true }); });++describe('PR title provenance with real git history', () => {+ it('excludes already-published commits despite stale local main and preserves quoted subjects', async () => {+ const fixture = await makeGitSandbox({ origin: true });+ scratch = fixture.scratch;+ const { repo } = fixture;+ await execGit(['checkout', '-b', 'audit'], repo);+ await execGit(['commit', '--allow-empty', '-m', 'chore: publish PortOS quality snapshot'], repo);+ await execGit(['push', 'origin', 'HEAD:main'], repo);+ await execGit(['commit', '--allow-empty', '-m', 'fix: preserve "unknown" call status'], repo);+ await execGit(['commit', '--allow-empty', '-m', 'test: cover follow-up'], repo);+ expect(await suggestPRTitle(repo, 'main', 'audit', 'fallback')).toBe('fix: preserve "unknown" call status');+ });++ it('supports local-only repositories and falls back when the branch has no commits', async () => {+ const fixture = await makeGitSandbox();+ scratch = fixture.scratch;+ const { repo } = fixture;+ expect(await suggestPRTitle(repo, 'main', 'main', 'Audit task\nMore detail')).toBe('Audit task');+ await execGit(['checkout', '-b', 'audit'], repo);+ await execGit(['commit', '--allow-empty', '-m', 'fix: local task'], repo);+ expect(await suggestPRTitle(repo, 'main', 'audit', 'fallback')).toBe('fix: local task');+ });+});