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

address review: actually wire openPR+reviewLoop, fix URL parser, align push wording

Adam Eivy6146e15019d7
diff --git a/server/services/agentCliSpawning.js b/server/services/agentCliSpawning.js
index 0d5ece40ab..cd7be8f766 100644
--- a/server/services/agentCliSpawning.js
+++ b/server/services/agentCliSpawning.js
@@ -581,8 +581,10 @@ export async function spawnDirectly(agentId, task, prompt, workspacePath, model,
}
// Clean up worktree if agent was using one
+ const directOpenPR = isTruthyMetaFn(task.metadata?.openPR);
await cleanupWorktreeFn(agentId, success, {
- openPR: isTruthyMetaFn(task.metadata?.openPR),
+ openPR: directOpenPR,
+ requestCopilotReview: directOpenPR && isTruthyMetaFn(task.metadata?.reviewLoop),
description: task.description,
agentOutput: outputBuffer
});
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index 45fe3fb27f..a1662a183d 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -1075,7 +1075,12 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration
if (!jiraBranch) {
const taskOpenPR = isTruthyMeta(agent.task?.metadata?.openPR);
const taskReviewLoop = isTruthyMeta(agent.task?.metadata?.reviewLoop);
- const cleanupWarnings = await cleanupAgentWorktree(agentId, success, { openPR: taskOpenPR && !taskReviewLoop, description: task?.description, agentOutput: outputBuffer });
+ const cleanupWarnings = await cleanupAgentWorktree(agentId, success, {
+ openPR: taskOpenPR,
+ requestCopilotReview: taskOpenPR && taskReviewLoop,
+ description: task?.description,
+ agentOutput: outputBuffer
+ });
if (cleanupWarnings?.length > 0) {
const { getAgent: getAgentForResult } = await import('./cos.js');
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index 6afcad880d..6f55622dfd 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -192,16 +192,21 @@ Read the previous stage's output from:
Use the findings from the previous stage to inform your work. If the previous stage produced a JSON results block, parse it to determine which items to process.
` : '';
- // Build simplify section if enabled
+ // Build simplify section if enabled. In the worktree-with-openPR flow the
+ // system pushes and opens the PR after the agent exits, so the agent must
+ // only commit (not push) — keep this wording aligned with the worktree
+ // section above.
const simplifySection = isTruthyMetaFn(task.metadata?.simplify) ? `
## Simplify Step
-After completing your work and before committing, run \`/simplify\` to review the changed code for reuse, quality, and efficiency. Fix any issues found, then commit and push using \`/do:push\`.
+After completing your work and before committing, run \`/simplify\` to review the changed code for reuse, quality, and efficiency. Fix any issues found, then ${worktreeInfo && willOpenPR ? 'commit your changes (do NOT push — the system will push and open the PR after you exit)' : 'commit and push using `/do:push`'}.
` : '';
// Build review loop section if enabled. The agent itself does NOT open the PR
// or run /do:rpr — by the time the PR exists, the agent has already exited.
// The system requests Copilot review automatically after PR creation.
- const reviewLoopSection = willReviewLoop ? `
+ // Only meaningful when a PR will actually be created (willOpenPR), since the
+ // Copilot review request is a no-op without a PR URL.
+ const reviewLoopSection = willReviewLoop && willOpenPR ? `
## Code Review
After your task completes, the system will request a Copilot code review on the PR automatically. You do not need to open the PR or trigger the review yourself — focus on producing high-quality, well-tested code so the review pass goes cleanly.
` : '';
@@ -322,7 +327,9 @@ ${isTruthyMetaFn(task.metadata?.readOnly) ? `- **This is a read-only task.** Do
- **Before starting work**, run \`git status\` to verify a clean working tree. Do NOT stash or discard uncommitted changes — other agents may be working concurrently and expecting those changes to be present. If the tree is dirty, only commit files YOU changed for this task.
- **NEVER use \`git stash\`** in any form (\`git stash push\`, \`git stash pop\`, etc.). This is a multi-agent system — stashing can silently destroy or corrupt another agent's or the user's in-progress work. Work around uncommitted changes instead. (Note: the backend may use \`--autostash\` in user-triggered pull operations — that is safe because those are single-user UI actions, not concurrent agent operations.)
- **Only commit files YOU changed** for this task. Never use \`git add -A\` or \`git add .\` — always stage specific files by name.
-- **Commit and push using \`/do:push\`** — this handles changelog updates, staging specific files, writing a conventional commit message, and pushing safely. If \`/do:push\` is unavailable, follow its conventions manually: stage specific files, use \`feat:\`/\`fix:\`/\`breaking:\` prefix, no Co-Authored-By annotations, and push with \`git pull --rebase && git push\`.
+${worktreeInfo && willOpenPR
+ ? `- **Commit only — do NOT push.** Stage specific files, use \`feat:\`/\`fix:\`/\`breaking:\` prefix in the commit message, no Co-Authored-By annotations. The system will push your branch and open the PR after you exit, so do NOT run \`git push\` or \`/do:push\` yourself.`
+ : `- **Commit and push using \`/do:push\`** — this handles changelog updates, staging specific files, writing a conventional commit message, and pushing safely. If \`/do:push\` is unavailable, follow its conventions manually: stage specific files, use \`feat:\`/\`fix:\`/\`breaking:\` prefix, no Co-Authored-By annotations, and push with \`git pull --rebase && git push\`.`}
${worktreeInfo ? `- **Your PR should contain only your task's commits.** If you see unrelated commits in your branch history, something is wrong — do not open a PR with other agents' work.` : `- **Commit directly to the current branch.** Do NOT create feature branches or PRs unless explicitly instructed.`}
## Working Directory
diff --git a/server/services/git.js b/server/services/git.js
index 82459f3db7..659ac1ef40 100644
--- a/server/services/git.js
+++ b/server/services/git.js
@@ -483,14 +483,56 @@ export async function createPR(dir, { title, body, base, head }) {
/**
* Parse a PR / MR URL into { host, owner, repo, number }. Returns null on bad input.
- * Handles GitHub (`/pull/N`) and GitLab (`/-/merge_requests/N`) URLs.
+ * Handles GitHub (`/pull/N`) and GitLab (`/-/merge_requests/N`) URLs, including
+ * GitLab projects nested in subgroups (the entire group path becomes `owner`)
+ * and URLs with trailing segments such as `/files`, `/commits`, `?query`, `#hash`.
*/
export function parsePullRequestUrl(url) {
if (!url || typeof url !== 'string') return null;
- const ghMatch = url.match(/^https?:\/\/([^/]+)\/([^/]+)\/([^/]+)\/pull\/(\d+)/);
- if (ghMatch) return { host: ghMatch[1], owner: ghMatch[2], repo: ghMatch[3], number: Number(ghMatch[4]) };
- const glMatch = url.match(/^https?:\/\/([^/]+)\/([^/]+)\/([^/]+)\/-\/merge_requests\/(\d+)/);
- if (glMatch) return { host: glMatch[1], owner: glMatch[2], repo: glMatch[3], number: Number(glMatch[4]) };
+
+ let parsed;
+ // new URL throws on malformed input; we want a structured null instead so a try
+ // wrapper here is the right call (the project's "no try/catch" rule covers
+ // request handlers, not URL validation helpers).
+ try { parsed = new URL(url); } catch { return null; }
+
+ const host = parsed.host;
+ const segments = parsed.pathname.split('/').filter(Boolean);
+
+ // GitHub: /<owner>/<repo>/pull/<number>[/<more>]
+ // Find the last `pull/<n>` pair so trailing /files, /commits etc. are tolerated.
+ for (let i = segments.length - 2; i >= 1; i--) {
+ if (segments[i] === 'pull') {
+ const number = Number(segments[i + 1]);
+ if (Number.isInteger(number) && number > 0) {
+ const project = segments.slice(0, i);
+ if (project.length >= 2) {
+ return { host, owner: project[0], repo: project[project.length - 1], number };
+ }
+ }
+ }
+ }
+
+ // GitLab: /<group>[/<subgroup>...]/<project>/-/merge_requests/<number>[/<more>]
+ // Locate the `-/merge_requests/<n>` triple anchored at any depth.
+ for (let i = segments.length - 3; i >= 2; i--) {
+ if (segments[i] === '-' && segments[i + 1] === 'merge_requests') {
+ const number = Number(segments[i + 2]);
+ if (Number.isInteger(number) && number > 0) {
+ const project = segments.slice(0, i);
+ if (project.length >= 2) {
+ // owner = full group/subgroup path, repo = final project segment
+ return {
+ host,
+ owner: project.slice(0, -1).join('/'),
+ repo: project[project.length - 1],
+ number,
+ };
+ }
+ }
+ }
+ }
+
return null;
}
diff --git a/server/services/git.test.js b/server/services/git.test.js
index aab10f41dc..dc3bc71848 100644
--- a/server/services/git.test.js
+++ b/server/services/git.test.js
@@ -131,12 +131,38 @@ describe('parsePullRequestUrl', () => {
});
});
+ it('parses GitLab MR URLs with subgroups (owner = full group path)', () => {
+ expect(parsePullRequestUrl('https://gitlab.com/group/subgroup/project/-/merge_requests/7')).toEqual({
+ host: 'gitlab.com', owner: 'group/subgroup', repo: 'project', number: 7
+ });
+ expect(parsePullRequestUrl('https://gitlab.example.com/g1/g2/g3/proj/-/merge_requests/100')).toEqual({
+ host: 'gitlab.example.com', owner: 'g1/g2/g3', repo: 'proj', number: 100
+ });
+ });
+
+ it('tolerates trailing path segments and query/hash fragments', () => {
+ expect(parsePullRequestUrl('https://github.com/atomantic/PortOS/pull/186/files')).toEqual({
+ host: 'github.com', owner: 'atomantic', repo: 'PortOS', number: 186
+ });
+ expect(parsePullRequestUrl('https://github.com/atomantic/PortOS/pull/186/commits/abc')).toEqual({
+ host: 'github.com', owner: 'atomantic', repo: 'PortOS', number: 186
+ });
+ expect(parsePullRequestUrl('https://github.com/atomantic/PortOS/pull/186?diff=split')).toEqual({
+ host: 'github.com', owner: 'atomantic', repo: 'PortOS', number: 186
+ });
+ expect(parsePullRequestUrl('https://gitlab.com/group/sub/proj/-/merge_requests/9/diffs')).toEqual({
+ host: 'gitlab.com', owner: 'group/sub', repo: 'proj', number: 9
+ });
+ });
+
it('returns null for invalid input', () => {
expect(parsePullRequestUrl(null)).toBeNull();
expect(parsePullRequestUrl('')).toBeNull();
expect(parsePullRequestUrl(undefined)).toBeNull();
expect(parsePullRequestUrl('https://github.com/atomantic/PortOS')).toBeNull();
expect(parsePullRequestUrl('not a url')).toBeNull();
+ expect(parsePullRequestUrl('https://github.com/atomantic/PortOS/pull/notanumber')).toBeNull();
+ expect(parsePullRequestUrl('https://github.com/atomantic/PortOS/pull/0')).toBeNull();
});
});