Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions apps/pi-extension/server/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

import { spawn } from "node:child_process";

import {
type PRMetadata,
type PRRef,
type PRReviewFileComment,
type PRRuntime,
type PRStackTree,
type PRListItem,
parsePRUrl as parsePRUrlCore,
} from "../generated/pr-types.js";
import {
checkAuth as checkAuthCore,
fetchPRContext as fetchPRContextCore,
Expand All @@ -15,13 +24,6 @@ import {
fetchPRList as fetchPRListCore,
getUser as getUserCore,
markPRFilesViewed as markPRFilesViewedCore,
type PRMetadata,
type PRRef,
type PRReviewFileComment,
type PRRuntime,
type PRStackTree,
type PRListItem,
parsePRUrl as parsePRUrlCore,
submitPRReview as submitPRReviewCore,
} from "../generated/pr-provider.js";

Expand Down
8 changes: 4 additions & 4 deletions apps/pi-extension/server/serverReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
type PRMetadata,
type PRReviewFileComment,
prRefFromMetadata,
} from "../generated/pr-provider.js";
} from "../generated/pr-types.js";
import {
type DiffType,
type GitContext,
Expand Down Expand Up @@ -168,15 +168,15 @@ export async function startReviewServer(options: {
? getPRDiffScopeOptions(prMeta, !!(options.worktreePool || options.agentCwd))
: [];

let prListCache: import("../generated/pr-provider.js").PRListItem[] | null = null;
let prListCache: import("../generated/pr-types.js").PRListItem[] | null = null;
let prListCacheTime = 0;
const prSwitchCache = new Map<string, { metadata: PRMetadata; rawPatch: string }>();
if (isPRMode && prMeta) prSwitchCache.set(prMeta.url, { metadata: prMeta, rawPatch: options.rawPatch });
const prStackTreeCache = new Map<string, import("../generated/pr-provider.js").PRStackTree | null>();
const prStackTreeCache = new Map<string, import("../generated/pr-types.js").PRStackTree | null>();

// Fetch full stack tree (best-effort — always try in PR mode so root PRs
// that target the default branch can still discover descendant PRs)
let prStackTree: import("../generated/pr-provider.js").PRStackTree | null = null;
let prStackTree: import("../generated/pr-types.js").PRStackTree | null = null;
if (prRef && prMeta) {
try {
prStackTree = await fetchPRStack(prRef, prMeta);
Expand Down
2 changes: 1 addition & 1 deletion apps/pi-extension/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd "$(dirname "$0")"

mkdir -p generated generated/ai/providers

for f in feedback-templates prompts review-core jj-core vcs-core review-args storage draft project pr-provider pr-stack pr-github pr-gitlab checklist integrations-common repo reference-common favicon code-file resolve-file config external-annotation agent-jobs worktree worktree-pool html-to-markdown url-to-markdown tour annotate-args at-reference pfm-reminder improvement-hooks; do
for f in feedback-templates prompts review-core jj-core vcs-core review-args storage draft project pr-types pr-provider pr-stack pr-github pr-gitlab checklist integrations-common repo reference-common favicon code-file resolve-file config external-annotation agent-jobs worktree worktree-pool html-to-markdown url-to-markdown tour annotate-args at-reference pfm-reminder improvement-hooks; do
src="../../packages/shared/$f.ts"
printf '// @generated — DO NOT EDIT. Source: packages/shared/%s.ts\n' "$f" | cat - "$src" > "generated/$f.ts"
done
Expand Down
4 changes: 2 additions & 2 deletions packages/review-editor/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { GitHubIcon } from '@plannotator/ui/components/GitHubIcon';
import { GitLabIcon } from '@plannotator/ui/components/GitLabIcon';
import { RepoIcon } from '@plannotator/ui/components/RepoIcon';
import { PullRequestIcon } from '@plannotator/ui/components/PullRequestIcon';
import { getPlatformLabel, getMRLabel, getMRNumberLabel, getDisplayRepo } from '@plannotator/shared/pr-provider';
import { getPlatformLabel, getMRLabel, getMRNumberLabel, getDisplayRepo } from '@plannotator/shared/pr-types';
import { configStore, useConfigValue } from '@plannotator/ui/config';
import { loadDiffFont } from '@plannotator/ui/utils/diffFonts';
import { getAgentSwitchSettings, getEffectiveAgentName } from '@plannotator/ui/utils/agentSwitch';
Expand Down Expand Up @@ -70,7 +70,7 @@ import {
} from './dock/reviewPanelTypes';
import type { DiffFile } from './types';
import type { DiffOption, WorktreeInfo, GitContext } from '@plannotator/shared/types';
import type { PRMetadata } from '@plannotator/shared/pr-provider';
import type { PRMetadata } from '@plannotator/shared/pr-types';
import type { PRDiffScope, PRDiffScopeOption, PRStackInfo, PRStackTree } from '@plannotator/shared/pr-stack';
import { altKey } from '@plannotator/ui/utils/platform';
import { TourDialog } from './components/tour/TourDialog';
Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/components/PRChecksTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import type { PRContext, PRCheck } from '@plannotator/shared/pr-provider';
import type { PRContext, PRCheck } from '@plannotator/shared/pr-types';

interface PRChecksTabProps {
context: PRContext;
Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/components/PRCommentsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState, useEffect, useRef, useCallback } from 'react';
import type { PRContext, PRComment, PRReview, PRReviewThread } from '@plannotator/shared/pr-provider';
import type { PRContext, PRComment, PRReview, PRReviewThread } from '@plannotator/shared/pr-types';
import { MarkdownBody } from './PRSummaryTab';
import { CopyButton } from './CopyButton';
import { DiffHunkPreview } from './DiffHunkPreview';
Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/components/PRSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useCallback, useEffect, useMemo } from 'react';
import { SearchableSelect } from '@plannotator/ui/components/SearchableSelect';
import { PullRequestIcon } from '@plannotator/ui/components/PullRequestIcon';
import { getItem, setItem } from '@plannotator/ui/utils/storage';
import type { PRListItem } from '@plannotator/shared/pr-provider';
import type { PRListItem } from '@plannotator/shared/pr-types';

type PRItem = PRListItem;

Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/components/PRSummaryTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useMemo, useRef, useEffect } from 'react';
import DOMPurify from 'dompurify';
import { parseMarkdownToBlocks } from '@plannotator/ui/utils/parser';
import { renderInlineMarkdown } from '../utils/renderInlineMarkdown';
import type { PRContext, PRMetadata } from '@plannotator/shared/pr-provider';
import type { PRContext, PRMetadata } from '@plannotator/shared/pr-types';

interface PRSummaryTabProps {
context: PRContext;
Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/components/ReviewSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { renderInlineMarkdown } from '../utils/renderInlineMarkdown';
import { formatRelativeTime } from '../utils/formatRelativeTime';
import { AITab } from './AITab';
import { AgentsTab } from '@plannotator/ui/components/AgentsTab';
import type { PRMetadata } from '@plannotator/shared/pr-provider';
import type { PRMetadata } from '@plannotator/shared/pr-types';
import { OverlayScrollArea } from '@plannotator/ui/components/OverlayScrollArea';
import type { AIChatEntry } from '../hooks/useAIChat';
import type { AgentJobInfo, AgentCapabilities } from '@plannotator/ui/types';
Expand Down
4 changes: 2 additions & 2 deletions packages/review-editor/components/StackedPRLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState } from 'react';
import * as Popover from '@radix-ui/react-popover';
import { getPlatformLabel } from '@plannotator/shared/pr-provider';
import { getPlatformLabel } from '@plannotator/shared/pr-types';
import { buildMinimalStackTree } from '@plannotator/shared/pr-stack';
import { getItem, setItem } from '@plannotator/ui/utils/storage';
import type { PRMetadata } from '@plannotator/shared/pr-provider';
import type { PRMetadata } from '@plannotator/shared/pr-types';
import type { PRDiffScope, PRDiffScopeOption, PRStackInfo, PRStackTree, PRStackNode } from '@plannotator/shared/pr-stack';

interface StackedPRLabelProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/dock/ReviewStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AgentJobInfo } from '@plannotator/ui/types';
import type { DiffFile } from '../types';
import type { AIChatEntry } from '../hooks/useAIChat';
import type { ReviewSearchMatch } from '../utils/reviewSearch';
import type { PRMetadata, PRContext } from '@plannotator/shared/pr-provider';
import type { PRMetadata, PRContext } from '@plannotator/shared/pr-types';
import type { PRDiffScope } from '@plannotator/shared/pr-stack';
import type { FeedbackDiffContext } from '../utils/exportFeedback';

Expand Down
4 changes: 2 additions & 2 deletions packages/review-editor/hooks/useAnnotationFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useCallback } from 'react';
import { getDisplayRepo } from '@plannotator/shared/pr-provider';
import type { PRMetadata } from '@plannotator/shared/pr-provider';
import { getDisplayRepo } from '@plannotator/shared/pr-types';
import type { PRMetadata } from '@plannotator/shared/pr-types';
import type { PRDiffScope } from '@plannotator/shared/pr-stack';
import type { CodeAnnotation } from '@plannotator/ui/types';

Expand Down
4 changes: 2 additions & 2 deletions packages/review-editor/hooks/usePRContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useRef, useCallback, useEffect } from 'react';
import type { PRContext } from '@plannotator/shared/pr-provider';
import type { PRMetadata } from '@plannotator/shared/pr-provider';
import type { PRContext } from '@plannotator/shared/pr-types';
import type { PRMetadata } from '@plannotator/shared/pr-types';

export function usePRContext(prMetadata: PRMetadata | null) {
const [prContext, setPRContext] = useState<PRContext | null>(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/hooks/usePRSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useCallback } from 'react';
import type { PRMetadata } from '@plannotator/shared/pr-provider';
import type { PRMetadata } from '@plannotator/shared/pr-types';
import type { PRDiffScope, PRDiffScopeOption, PRStackInfo, PRStackTree } from '@plannotator/shared/pr-stack';

export interface PRSessionState {
Expand Down
2 changes: 1 addition & 1 deletion packages/review-editor/utils/exportFeedback.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect } from "bun:test";
import { exportReviewFeedback } from "./exportFeedback";
import type { CodeAnnotation } from "@plannotator/ui/types";
import type { PRMetadata } from "@plannotator/shared/pr-provider";
import type { PRMetadata } from "@plannotator/shared/pr-types";

const ann = (overrides: Partial<CodeAnnotation> = {}): CodeAnnotation => ({
id: "1",
Expand Down
4 changes: 2 additions & 2 deletions packages/review-editor/utils/exportFeedback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CodeAnnotation, ConventionalLabel, ConventionalDecoration } from '@plannotator/ui/types';
import type { PRMetadata } from '@plannotator/shared/pr-provider';
import { getMRLabel, getMRNumberLabel, getDisplayRepo } from '@plannotator/shared/pr-provider';
import type { PRMetadata } from '@plannotator/shared/pr-types';
import { getMRLabel, getMRNumberLabel, getDisplayRepo } from '@plannotator/shared/pr-types';

/**
* Format a conventional comment prefix per the Conventional Comments spec:
Expand Down
38 changes: 21 additions & 17 deletions packages/server/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@
* Pre-binds a Bun-based runtime so consumers get a clean API.
*/

import type {
PRRef,
PRMetadata,
PRContext,
PRRuntime,
PRReviewFileComment,
PRStackTree,
PRListItem,
} from "@plannotator/shared/pr-types";
import {
type PRRef,
type PRMetadata,
type PRContext,
type PRRuntime,
type PRReviewFileComment,
type PRStackTree,
type PRListItem,
parsePRUrl as parsePRUrlCore,
prRefFromMetadata,
getPlatformLabel,
getMRLabel,
getMRNumberLabel,
getDisplayRepo,
getCliName,
getCliInstallUrl,
} from "@plannotator/shared/pr-types";
import {
checkAuth as checkAuthCore,
getUser as getUserCore,
fetchPR as fetchPRCore,
Expand All @@ -24,18 +35,11 @@ import {
markPRFilesViewed as markPRFilesViewedCore,
fetchPRStack as fetchPRStackCore,
fetchPRList as fetchPRListCore,
prRefFromMetadata,
getPlatformLabel,
getMRLabel,
getMRNumberLabel,
getDisplayRepo,
getCliName,
getCliInstallUrl,
} from "@plannotator/shared/pr-provider";

export type { PRRef, PRMetadata, PRContext, PRReviewFileComment, PRStackTree, PRListItem } from "@plannotator/shared/pr-provider";
export { prRefFromMetadata, isSameProject, getPlatformLabel, getMRLabel, getMRNumberLabel, getDisplayRepo, getCliName, getCliInstallUrl } from "@plannotator/shared/pr-provider";
export type { GithubPRMetadata } from "@plannotator/shared/pr-provider";
export type { PRRef, PRMetadata, PRContext, PRReviewFileComment, PRStackTree, PRListItem } from "@plannotator/shared/pr-types";
export { prRefFromMetadata, isSameProject, getPlatformLabel, getMRLabel, getMRNumberLabel, getDisplayRepo, getCliName, getCliInstallUrl } from "@plannotator/shared/pr-types";
export type { GithubPRMetadata } from "@plannotator/shared/pr-types";

const runtime: PRRuntime = {
async runCommand(cmd, args) {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"./vcs-core": "./vcs-core.ts",
"./checklist": "./checklist.ts",
"./types": "./types.ts",
"./pr-types": "./pr-types.ts",
"./pr-provider": "./pr-provider.ts",
"./pr-stack": "./pr-stack.ts",
"./project": "./project.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/pr-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* All functions use the `gh` CLI via the PRRuntime abstraction.
*/

import type { PRRuntime, PRMetadata, PRContext, PRReviewThread, PRThreadComment, PRReviewFileComment, CommandResult, PRStackTree, PRStackNode, PRListItem } from "./pr-provider";
import { encodeApiFilePath } from "./pr-provider";
import type { PRRuntime, PRMetadata, PRContext, PRReviewThread, PRThreadComment, PRReviewFileComment, CommandResult, PRStackTree, PRStackNode, PRListItem } from "./pr-types";
import { encodeApiFilePath } from "./pr-types";

// GitHub-specific PRRef shape (used internally)
interface GhPRRef {
Expand Down
48 changes: 40 additions & 8 deletions packages/shared/pr-gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* Self-hosted instances are supported via the --hostname flag.
*/

import type { PRRuntime, PRMetadata, PRContext, PRReviewFileComment, CommandResult } from "./pr-provider";
import { encodeApiFilePath } from "./pr-provider";
import { homedir } from "os";
import { join } from "path";
import { mkdirSync, writeFileSync } from "fs";
import type { PRRuntime, PRMetadata, PRContext, PRReviewFileComment, CommandResult } from "./pr-types";
import { encodeApiFilePath } from "./pr-types";

// GitLab-specific MRRef shape (used internally)
interface GlMRRef {
Expand Down Expand Up @@ -495,13 +498,42 @@ export async function submitGlMRReview(
}
}

if (errors.length > 0 && errors.length === fileComments.length) {
// All failed — throw
throw new Error(`Failed to post inline comments:\n${errors.join("\n")}`);
}
// Partial failures: some comments posted, some didn't — log but don't throw
if (errors.length > 0) {
console.error(`Warning: ${errors.length}/${fileComments.length} inline comments failed:\n${errors.join("\n")}`);
// Persist unposted bodies to disk so the work survives transient GitLab errors.
// We keep the original throw-vs-warn split intentionally:
// - all-fail → throw (nothing was posted, caller retries from clean state)
// - partial-fail → warn only (some discussions + the MR note are already on
// the server; throwing would have the client re-submit the whole review
// and create duplicates).
const failed = results
.map((r, i) => (r.status === "rejected" ? fileComments[i] : null))
.filter((c): c is PRReviewFileComment => c !== null);
let savedTo: string | null = null;
try {
const dir = join(homedir(), ".plannotator", "failed-comments");
mkdirSync(dir, { recursive: true });
const slug = `${ref.host}-${ref.projectPath.replace(/\//g, "_")}-mr${ref.iid}-${Date.now()}`;
savedTo = join(dir, `${slug}.json`);
writeFileSync(
savedTo,
JSON.stringify({ ref, headSha, baseSha, startSha, errors, failedComments: failed }, null, 2),
);
} catch (writeErr) {
console.error(`[plannotator] Failed to persist unposted comments: ${writeErr instanceof Error ? writeErr.message : String(writeErr)}`);
}
const suffix = savedTo ? ` (unposted bodies saved to ${savedTo})` : "";

if (errors.length === fileComments.length) {
// All failed — safe to throw, nothing was posted.
throw new Error(
`Failed to post inline comments${suffix}:\n${errors.join("\n")}`,
);
}
// Partial failure — some comments and the MR note are already posted.
// Don't throw, or the UI will resubmit the whole review and duplicate them.
console.error(
`[plannotator] ${errors.length}/${fileComments.length} inline comments failed${suffix}:\n${errors.join("\n")}`,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/pr-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
prRefFromMetadata,
type PRMetadata,
type PRRef,
} from "./pr-provider";
} from "./pr-types";
import {
getPRDiffScopeOptions,
getPRStackInfo,
Expand Down
Loading
Loading