Skip to content

Commit c084708

Browse files
sylvansysclaude
andauthored
fix(project-context): Integrate PR #320 path fix and test hooks (#323)
* fix(project-context): correct parent transcript path resolution Agent transcripts are at .../project/{sessionId}/subagents/agent-{agentId}.jsonl Parent transcripts are at .../project/{sessionId}.jsonl The previous code incorrectly computed the parent path by only going up one directory level. This fix properly navigates from the subagents/ directory to the project root to find the parent transcript. Integrates fix from PR #320. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(github-orchestration): fix gh pr create command The `gh pr create` command doesn't support `--json` flag. Instead, parse the PR URL from stdout and extract the PR number. Also use heredoc for body to handle multiline content properly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * [unknown] Subagent task completed (#326) Auto-generated from stacked PR workflow. Files: 1 new, 1 edited, 0 deleted --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5c4156f commit c084708

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

plugins/github-orchestration/shared/hooks/utils/stacked-branches.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,13 @@ export async function createPRWithAutoMerge(
543543
body: string;
544544
}
545545
): Promise<{ success: boolean; prNumber?: number; prUrl?: string; error?: string }> {
546-
// Create PR
547-
const escapedTitle = options.title.replace(/"/g, '\\"');
548-
const escapedBody = options.body.replace(/"/g, '\\"').replace(/\n/g, '\\n');
549-
546+
// Create PR using heredoc for proper body handling
547+
// gh pr create outputs the PR URL on success
550548
const createResult = await execCommand(
551-
`gh pr create --head "${options.head}" --base "${options.base}" --title "${escapedTitle}" --body "${escapedBody}" --json number,url`,
549+
`gh pr create --head "${options.head}" --base "${options.base}" --title "${options.title.replace(/"/g, '\\"')}" --body "$(cat <<'PRBODYEOF'
550+
${options.body}
551+
PRBODYEOF
552+
)"`,
552553
cwd,
553554
60000
554555
);
@@ -560,20 +561,20 @@ export async function createPRWithAutoMerge(
560561
};
561562
}
562563

563-
let prNumber: number;
564-
let prUrl: string;
564+
// Parse PR URL from stdout (gh pr create prints the URL)
565+
const prUrl = createResult.stdout.trim();
565566

566-
try {
567-
const prData = JSON.parse(createResult.stdout);
568-
prNumber = prData.number;
569-
prUrl = prData.url;
570-
} catch {
567+
// Extract PR number from URL (e.g., https://github.com/owner/repo/pull/123)
568+
const prNumberMatch = prUrl.match(/\/pull\/(\d+)$/);
569+
if (!prNumberMatch) {
571570
return {
572571
success: false,
573-
error: 'Failed to parse PR creation response',
572+
error: `Failed to parse PR number from URL: ${prUrl}`,
574573
};
575574
}
576575

576+
const prNumber = parseInt(prNumberMatch[1], 10);
577+
577578
// Enable auto-merge
578579
const mergeResult = await execCommand(
579580
`gh pr merge ${prNumber} --auto --squash`,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Stacked PR Test v2
2+
3+
Created at: 2026-01-24T07:00:00Z
4+
Purpose: Test that SubagentStop hook creates PR after fix
5+
6+
Expected outcome:
7+
- Branch created on SubagentStart
8+
- File committed on SubagentStop
9+
- PR created and linked

plugins/project-context/shared/hooks/utils/task-state.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,13 @@ export async function getTaskEdits(
336336
}
337337

338338
// Find parent session transcript
339-
const dir = path.dirname(agentTranscriptPath);
339+
// Agent transcripts are at: .../project/{sessionId}/subagents/agent-{agentId}.jsonl
340+
// Parent transcripts are at: .../project/{sessionId}.jsonl
341+
let dir = path.dirname(agentTranscriptPath); // .../sessionId/subagents/
342+
if (path.basename(dir) === 'subagents') {
343+
dir = path.dirname(dir); // .../sessionId/
344+
}
345+
dir = path.dirname(dir); // .../project/
340346
const parentPath = path.join(dir, `${sessionId}.jsonl`);
341347

342348
try {

0 commit comments

Comments
 (0)