edsger 0.73.0 → 0.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/commands/features/index.d.ts +15 -0
  2. package/dist/commands/features/index.js +34 -0
  3. package/dist/commands/pr-resolve/index.d.ts +3 -1
  4. package/dist/commands/pr-resolve/index.js +12 -7
  5. package/dist/commands/pr-review/index.d.ts +3 -1
  6. package/dist/commands/pr-review/index.js +10 -6
  7. package/dist/commands/sync-github-pull-requests/index.d.ts +11 -0
  8. package/dist/commands/sync-github-pull-requests/index.js +42 -0
  9. package/dist/index.js +50 -4
  10. package/dist/phases/features/index.d.ts +65 -0
  11. package/dist/phases/features/index.js +292 -0
  12. package/dist/phases/features/mcp-server.d.ts +61 -0
  13. package/dist/phases/features/mcp-server.js +165 -0
  14. package/dist/phases/features/prompts.d.ts +32 -0
  15. package/dist/phases/features/prompts.js +92 -0
  16. package/dist/phases/features/types.d.ts +34 -0
  17. package/dist/phases/features/types.js +15 -0
  18. package/dist/phases/pr-resolve/index.d.ts +3 -1
  19. package/dist/phases/pr-resolve/index.js +12 -12
  20. package/dist/phases/pr-review/index.d.ts +3 -1
  21. package/dist/phases/pr-review/index.js +13 -16
  22. package/dist/phases/pr-shared/status.d.ts +18 -0
  23. package/dist/phases/pr-shared/status.js +37 -0
  24. package/dist/phases/sync-github-pull-requests/index.d.ts +23 -0
  25. package/dist/phases/sync-github-pull-requests/index.js +210 -0
  26. package/dist/phases/sync-github-pull-requests/state.d.ts +24 -0
  27. package/dist/phases/sync-github-pull-requests/state.js +16 -0
  28. package/dist/phases/sync-github-pull-requests/types.d.ts +22 -0
  29. package/dist/phases/sync-github-pull-requests/types.js +1 -0
  30. package/package.json +1 -1
@@ -0,0 +1,61 @@
1
+ /**
2
+ * In-process MCP server exposing the features toolkit. Three tools:
3
+ *
4
+ * - create_feature INSERT a product_features row (source = 'agent')
5
+ * - update_feature UPDATE an existing row (enrichment, latest-wins on
6
+ * the fields passed)
7
+ * - remove_feature DELETE a previously agent-discovered row the agent
8
+ * confirmed is no longer present (manual rows are
9
+ * never deletable from a scan)
10
+ *
11
+ * All writes are scoped to the active feature_scan's product_id. The
12
+ * handlers persist directly via the Supabase client passed in by the
13
+ * orchestrator — there is no captured-extraction buffer to flush at the
14
+ * end. Each tool call is its own committed effect.
15
+ */
16
+ import type { SupabaseClient } from '@supabase/supabase-js';
17
+ import { z } from 'zod';
18
+ import { type FeatureSummary } from './types.js';
19
+ export interface FeaturesToolContext {
20
+ supabase: SupabaseClient;
21
+ productId: string;
22
+ createdBy: string;
23
+ }
24
+ /**
25
+ * Records how many of each kind of mutation the agent made — exported so the
26
+ * orchestrator can print a summary line at the end of the scan.
27
+ */
28
+ export interface FeaturesMutationCounts {
29
+ created: number;
30
+ updated: number;
31
+ removed: number;
32
+ }
33
+ export declare function createFeaturesMutationCounts(): FeaturesMutationCounts;
34
+ export declare function createCreateFeatureTool(ctx: FeaturesToolContext, counts: FeaturesMutationCounts, knownFeatures: Map<string, FeatureSummary>): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition<{
35
+ name: z.ZodString;
36
+ description: z.ZodString;
37
+ status: z.ZodOptional<z.ZodEnum<{
38
+ shipped: "shipped";
39
+ deprecated: "deprecated";
40
+ planned: "planned";
41
+ in_development: "in_development";
42
+ }>>;
43
+ repos: z.ZodArray<z.ZodString>;
44
+ evidence: z.ZodString;
45
+ }>;
46
+ export declare function createUpdateFeatureTool(ctx: FeaturesToolContext, counts: FeaturesMutationCounts, knownFeatures: Map<string, FeatureSummary>): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition<{
47
+ feature_id: z.ZodString;
48
+ description: z.ZodOptional<z.ZodString>;
49
+ status: z.ZodOptional<z.ZodEnum<{
50
+ shipped: "shipped";
51
+ deprecated: "deprecated";
52
+ planned: "planned";
53
+ in_development: "in_development";
54
+ }>>;
55
+ repos: z.ZodOptional<z.ZodArray<z.ZodString>>;
56
+ evidence: z.ZodOptional<z.ZodString>;
57
+ }>;
58
+ export declare function createRemoveFeatureTool(ctx: FeaturesToolContext, counts: FeaturesMutationCounts, knownFeatures: Map<string, FeatureSummary>): import("@anthropic-ai/claude-agent-sdk").SdkMcpToolDefinition<{
59
+ feature_id: z.ZodString;
60
+ }>;
61
+ export declare function createFeaturesMcpServer(ctx: FeaturesToolContext, counts: FeaturesMutationCounts, existingFeatures: FeatureSummary[]): import("@anthropic-ai/claude-agent-sdk").McpSdkServerConfigWithInstance;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * In-process MCP server exposing the features toolkit. Three tools:
3
+ *
4
+ * - create_feature INSERT a product_features row (source = 'agent')
5
+ * - update_feature UPDATE an existing row (enrichment, latest-wins on
6
+ * the fields passed)
7
+ * - remove_feature DELETE a previously agent-discovered row the agent
8
+ * confirmed is no longer present (manual rows are
9
+ * never deletable from a scan)
10
+ *
11
+ * All writes are scoped to the active feature_scan's product_id. The
12
+ * handlers persist directly via the Supabase client passed in by the
13
+ * orchestrator — there is no captured-extraction buffer to flush at the
14
+ * end. Each tool call is its own committed effect.
15
+ */
16
+ import { createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
17
+ import { z } from 'zod';
18
+ import { FEATURE_DESCRIPTION_MAX, FEATURE_EVIDENCE_MAX, FEATURE_NAME_MAX, FEATURE_REPO_NAME_MAX, FEATURE_REPOS_MAX, } from './types.js';
19
+ export function createFeaturesMutationCounts() {
20
+ return { created: 0, updated: 0, removed: 0 };
21
+ }
22
+ const statusSchema = z
23
+ .enum(['planned', 'in_development', 'shipped', 'deprecated'])
24
+ .describe('Lifecycle status as evidenced by the code. Default "shipped"; use "in_development" for half-wired / flag-gated code.');
25
+ const reposSchema = z
26
+ .array(z.string().min(1).max(FEATURE_REPO_NAME_MAX))
27
+ .max(FEATURE_REPOS_MAX)
28
+ .describe('Repository full names ("owner/repo") where the feature is implemented. Only names from the repository list you were given.');
29
+ function normalizeRepos(repos) {
30
+ const cleaned = repos.map((r) => r.trim()).filter((r) => r.length > 0);
31
+ return Array.from(new Set(cleaned)).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
32
+ }
33
+ function textError(message) {
34
+ return {
35
+ content: [{ type: 'text', text: message }],
36
+ isError: true,
37
+ };
38
+ }
39
+ function textOk(message) {
40
+ return {
41
+ content: [{ type: 'text', text: message }],
42
+ };
43
+ }
44
+ export function createCreateFeatureTool(ctx, counts, knownFeatures) {
45
+ return tool('create_feature', 'Register a feature that is not in the existing list for this product. Pass a short user-facing name, a 1-3 sentence description, the repos it lives in, and evidence (file paths / entry points).', {
46
+ name: z.string().min(1).max(FEATURE_NAME_MAX),
47
+ description: z.string().min(1).max(FEATURE_DESCRIPTION_MAX),
48
+ status: statusSchema.optional(),
49
+ repos: reposSchema,
50
+ evidence: z
51
+ .string()
52
+ .min(1)
53
+ .max(FEATURE_EVIDENCE_MAX)
54
+ .describe('Plain-text paragraph saying where in the code this feature shows up (file paths, routes, entry points).'),
55
+ }, async (args) => {
56
+ const name = args.name.trim();
57
+ const duplicate = [...knownFeatures.values()].find((f) => f.name.toLowerCase() === name.toLowerCase());
58
+ if (duplicate) {
59
+ return textError(`A feature named "${duplicate.name}" already exists (id=${duplicate.id}). Use update_feature instead.`);
60
+ }
61
+ const { data, error } = await ctx.supabase
62
+ .from('product_features')
63
+ .insert({
64
+ product_id: ctx.productId,
65
+ name,
66
+ description: args.description.trim(),
67
+ status: args.status ?? 'shipped',
68
+ source: 'agent',
69
+ repos: normalizeRepos(args.repos),
70
+ evidence: args.evidence.trim(),
71
+ created_by: ctx.createdBy,
72
+ })
73
+ .select('id')
74
+ .single();
75
+ if (error || !data) {
76
+ return textError(`Failed to create feature: ${error?.message ?? 'unknown error'}`);
77
+ }
78
+ knownFeatures.set(data.id, {
79
+ id: data.id,
80
+ name,
81
+ description: args.description.trim(),
82
+ status: args.status ?? 'shipped',
83
+ source: 'agent',
84
+ });
85
+ counts.created += 1;
86
+ return textOk(`Created feature ${data.id} ("${name}").`);
87
+ });
88
+ }
89
+ export function createUpdateFeatureTool(ctx, counts, knownFeatures) {
90
+ return tool('update_feature', "Enrich an existing feature you corroborated in the code: evidence, repos, corrected status, or a better description. Omit fields you do not want to change. For source=manual entries only add evidence/repos/status or fill a missing description — never rewrite the user's intent.", {
91
+ feature_id: z.string().uuid().describe('id from the existing list'),
92
+ description: z.string().min(1).max(FEATURE_DESCRIPTION_MAX).optional(),
93
+ status: statusSchema.optional(),
94
+ repos: reposSchema.optional(),
95
+ evidence: z.string().min(1).max(FEATURE_EVIDENCE_MAX).optional(),
96
+ }, async (args) => {
97
+ const known = knownFeatures.get(args.feature_id);
98
+ if (!known) {
99
+ return textError(`feature_id ${args.feature_id} is not in this product's feature list. Use create_feature for new entries.`);
100
+ }
101
+ const patch = {};
102
+ if (args.description !== undefined) {
103
+ patch.description = args.description.trim();
104
+ }
105
+ if (args.status !== undefined) {
106
+ patch.status = args.status;
107
+ }
108
+ if (args.repos !== undefined) {
109
+ patch.repos = normalizeRepos(args.repos);
110
+ }
111
+ if (args.evidence !== undefined) {
112
+ patch.evidence = args.evidence.trim();
113
+ }
114
+ if (Object.keys(patch).length === 0) {
115
+ return textError('Nothing to update — pass at least one field.');
116
+ }
117
+ const { error } = await ctx.supabase
118
+ .from('product_features')
119
+ .update(patch)
120
+ .eq('id', args.feature_id)
121
+ .eq('product_id', ctx.productId);
122
+ if (error) {
123
+ return textError(`Failed to update feature: ${error.message}`);
124
+ }
125
+ counts.updated += 1;
126
+ return textOk(`Updated feature ${args.feature_id} ("${known.name}").`);
127
+ });
128
+ }
129
+ export function createRemoveFeatureTool(ctx, counts, knownFeatures) {
130
+ return tool('remove_feature', 'Delete a previously agent-discovered feature (source=agent) that you have confirmed is NO LONGER present in the code. Manually defined features cannot be removed by a scan.', {
131
+ feature_id: z.string().uuid(),
132
+ }, async (args) => {
133
+ const known = knownFeatures.get(args.feature_id);
134
+ if (!known) {
135
+ return textError(`feature_id ${args.feature_id} is not in this product's feature list — nothing to remove.`);
136
+ }
137
+ if (known.source !== 'agent') {
138
+ return textError(`Feature ${args.feature_id} ("${known.name}") was defined manually and cannot be removed by a scan. If it looks wrong, leave it for the user.`);
139
+ }
140
+ const { error } = await ctx.supabase
141
+ .from('product_features')
142
+ .delete()
143
+ .eq('id', args.feature_id)
144
+ .eq('product_id', ctx.productId)
145
+ .eq('source', 'agent');
146
+ if (error) {
147
+ return textError(`Failed to remove feature: ${error.message}`);
148
+ }
149
+ knownFeatures.delete(args.feature_id);
150
+ counts.removed += 1;
151
+ return textOk(`Removed feature ${args.feature_id} ("${known.name}").`);
152
+ });
153
+ }
154
+ export function createFeaturesMcpServer(ctx, counts, existingFeatures) {
155
+ const knownFeatures = new Map(existingFeatures.map((f) => [f.id, f]));
156
+ return createSdkMcpServer({
157
+ name: 'features',
158
+ version: '1.0.0',
159
+ tools: [
160
+ createCreateFeatureTool(ctx, counts, knownFeatures),
161
+ createUpdateFeatureTool(ctx, counts, knownFeatures),
162
+ createRemoveFeatureTool(ctx, counts, knownFeatures),
163
+ ],
164
+ });
165
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Prompts for the features phase.
3
+ *
4
+ * Agent's job: explore the cloned repositories of a product (one or several
5
+ * — multi-repo products are cloned side by side as subdirectories of the
6
+ * working directory) and catalogue the user-facing FEATURES the product
7
+ * delivers. A feature is the WHAT from the user's perspective ("Export
8
+ * board as PDF", "Slack notifications", "SSO login"), not the HOW (that is
9
+ * what recipes capture) and not a tech-stack inventory.
10
+ *
11
+ * The agent is fed the product's existing features (manual + previously
12
+ * discovered) and must, for each feature it identifies, pick one of:
13
+ * - update_feature — an existing entry matches; enrich it with evidence /
14
+ * repos / corrected status
15
+ * - create_feature — nothing matches; new entry (source = 'agent')
16
+ * - remove_feature — a previously agent-discovered entry can no longer be
17
+ * corroborated in the code (manual entries are never
18
+ * removed)
19
+ *
20
+ * Submission is via MCP tool calls only — no fenced JSON.
21
+ */
22
+ import type { FeatureSummary } from './types.js';
23
+ export interface FeaturesPromptContext {
24
+ productName: string;
25
+ productDescription?: string;
26
+ guidance?: string;
27
+ existingFeatures: FeatureSummary[];
28
+ /** Multi-repo note from describeRepoScope(); empty for single-repo. */
29
+ repoScopeNote: string;
30
+ }
31
+ export declare function createFeaturesSystemPrompt(): string;
32
+ export declare function createFeaturesUserPrompt(ctx: FeaturesPromptContext): string;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Prompts for the features phase.
3
+ *
4
+ * Agent's job: explore the cloned repositories of a product (one or several
5
+ * — multi-repo products are cloned side by side as subdirectories of the
6
+ * working directory) and catalogue the user-facing FEATURES the product
7
+ * delivers. A feature is the WHAT from the user's perspective ("Export
8
+ * board as PDF", "Slack notifications", "SSO login"), not the HOW (that is
9
+ * what recipes capture) and not a tech-stack inventory.
10
+ *
11
+ * The agent is fed the product's existing features (manual + previously
12
+ * discovered) and must, for each feature it identifies, pick one of:
13
+ * - update_feature — an existing entry matches; enrich it with evidence /
14
+ * repos / corrected status
15
+ * - create_feature — nothing matches; new entry (source = 'agent')
16
+ * - remove_feature — a previously agent-discovered entry can no longer be
17
+ * corroborated in the code (manual entries are never
18
+ * removed)
19
+ *
20
+ * Submission is via MCP tool calls only — no fenced JSON.
21
+ */
22
+ export function createFeaturesSystemPrompt() {
23
+ return `You are a senior product manager with a staff-engineer's eye, cataloguing the FEATURES a product delivers by reading its source code.
24
+
25
+ The current working directory contains a fresh clone of the product's repository (or, for multi-repo products, one subdirectory per repository). Use Glob/Grep/Read (and Bash for git log when helpful) to explore before writing anything.
26
+
27
+ ## What is a "feature"?
28
+
29
+ A feature is ONE user-facing capability, named from the user's point of view. It answers "what can a user do with this product?", not "how is it built?".
30
+
31
+ Good feature names: "Export board as PDF", "Slack notifications", "Single sign-on (SAML)", "Real-time collaborative editing", "Usage-based billing".
32
+ Bad feature names: "React frontend", "Postgres database", "REST API", "Utils module" (implementation details, not user value).
33
+
34
+ Keep names short (a few words, Title-style), and the description 1–3 sentences in plain product language: what the user gets, plus any notable scope/limits you can see in the code.
35
+
36
+ ## Output protocol
37
+
38
+ The MCP server exposes these tools — use them, do NOT paste content as fenced code:
39
+
40
+ 1. \`create_feature({ name, description, status?, repos, evidence })\` — register a feature that is not in the existing list. \`status\` defaults to "shipped"; use "in_development" when the code is clearly behind an unfinished flag or half-wired.
41
+
42
+ 2. \`update_feature({ feature_id, description?, status?, repos?, evidence? })\` — enrich an existing entry you corroborated in the code. Omit fields you don't want to change.
43
+
44
+ 3. \`remove_feature({ feature_id })\` — drop a previously agent-discovered entry you could NOT corroborate anywhere in the code. Only entries marked source=agent can be removed; manually defined features are never deleted by a scan.
45
+
46
+ Call exactly one of create / update for each feature you identify, then remove for any stale agent entries. When you are done, end your turn — no summary message, no JSON dump.
47
+
48
+ ## Rules
49
+
50
+ - \`repos\` is the list of repository full names ("owner/repo") where the feature is implemented — only use names from the repository list you were given.
51
+ - \`evidence\` is one short plain-text paragraph pointing at where the feature lives: key file paths, routes, entry points. For multi-repo products prefix paths with the repo subdirectory.
52
+ - Aim for the level of granularity a changelog or pricing page would use. Don't list every API endpoint as its own feature, and don't collapse the whole product into one feature. Most products have 5–30 features.
53
+ - Don't invent features. If you can't point at concrete code, don't record it.
54
+ - Existing entries: match by meaning, not exact name. If an existing feature (manual or agent) covers what you found, \`update_feature\` it instead of creating a near-duplicate.
55
+ - Manual entries (source=manual) are the user's own definitions: never rewrite their intent. You may add \`evidence\` / \`repos\`, correct an obviously wrong \`status\`, or fill in a missing description — nothing more.`;
56
+ }
57
+ export function createFeaturesUserPrompt(ctx) {
58
+ const lines = [];
59
+ lines.push(`# Product: ${ctx.productName}`);
60
+ if (ctx.productDescription) {
61
+ lines.push('');
62
+ lines.push('## Description');
63
+ lines.push(ctx.productDescription);
64
+ }
65
+ if (ctx.repoScopeNote) {
66
+ lines.push('');
67
+ lines.push('## Repositories');
68
+ lines.push(ctx.repoScopeNote);
69
+ }
70
+ if (ctx.guidance && ctx.guidance.trim()) {
71
+ lines.push('');
72
+ lines.push('## Reviewer guidance (focus or exclusions)');
73
+ lines.push(ctx.guidance.trim());
74
+ }
75
+ lines.push('');
76
+ lines.push('## Existing features for this product');
77
+ if (ctx.existingFeatures.length === 0) {
78
+ lines.push('(none — every feature you identify will be a `create_feature`.)');
79
+ }
80
+ else {
81
+ lines.push('Prefer `update_feature` over `create_feature` when one of these matches what you found. Entries marked source=manual were written by a human — enrich, never rewrite.');
82
+ lines.push('');
83
+ for (const f of ctx.existingFeatures) {
84
+ const desc = f.description ? ` — ${f.description}` : '';
85
+ lines.push(`- id=${f.id} "${f.name}" [status=${f.status}, source=${f.source}]${desc}`);
86
+ }
87
+ }
88
+ lines.push('');
89
+ lines.push('## Task');
90
+ lines.push('Explore the cloned repositories, identify every user-facing feature the product delivers, and for each call exactly one of `create_feature` / `update_feature`. Then call `remove_feature` for any previously agent-discovered entry you could not corroborate. End your turn when done.');
91
+ return lines.join('\n');
92
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shapes the features MCP tools accept and return. The Zod schemas live in
3
+ * mcp-server.ts; these plain TS types are what the rest of the phase
4
+ * (orchestrator, persistence helpers, tests) consumes so they don't have
5
+ * to inflate Zod into their dependency graph.
6
+ */
7
+ export type FeatureStatus = 'planned' | 'in_development' | 'shipped' | 'deprecated';
8
+ export type FeatureSource = 'manual' | 'agent';
9
+ export interface FeatureSummary {
10
+ id: string;
11
+ name: string;
12
+ description: string | null;
13
+ status: FeatureStatus;
14
+ source: FeatureSource;
15
+ }
16
+ export interface CreateFeatureArgs {
17
+ name: string;
18
+ description: string;
19
+ status?: FeatureStatus;
20
+ repos: string[];
21
+ evidence: string;
22
+ }
23
+ export interface UpdateFeatureArgs {
24
+ featureId: string;
25
+ description?: string;
26
+ status?: FeatureStatus;
27
+ repos?: string[];
28
+ evidence?: string;
29
+ }
30
+ export declare const FEATURE_NAME_MAX = 200;
31
+ export declare const FEATURE_DESCRIPTION_MAX = 10000;
32
+ export declare const FEATURE_EVIDENCE_MAX = 4000;
33
+ export declare const FEATURE_REPOS_MAX = 20;
34
+ export declare const FEATURE_REPO_NAME_MAX = 200;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shapes the features MCP tools accept and return. The Zod schemas live in
3
+ * mcp-server.ts; these plain TS types are what the rest of the phase
4
+ * (orchestrator, persistence helpers, tests) consumes so they don't have
5
+ * to inflate Zod into their dependency graph.
6
+ */
7
+ // Defensive caps mirroring the DB CHECK constraints from
8
+ // 20260613000000_create_product_features.sql. Keeping the limits here lets
9
+ // the MCP tool reject oversized output with an actionable error message
10
+ // instead of getting a Postgres constraint violation.
11
+ export const FEATURE_NAME_MAX = 200;
12
+ export const FEATURE_DESCRIPTION_MAX = 10_000;
13
+ export const FEATURE_EVIDENCE_MAX = 4000;
14
+ export const FEATURE_REPOS_MAX = 20;
15
+ export const FEATURE_REPO_NAME_MAX = 200;
@@ -4,7 +4,9 @@
4
4
  * replies to every comment on GitHub explaining the decision.
5
5
  */
6
6
  export interface StandalonePRResolveOptions {
7
- productId: string;
7
+ productId?: string;
8
+ /** Set for repo-scoped PRs — routes the status write through Supabase. */
9
+ repositoryId?: string;
8
10
  pullRequestUrl: string;
9
11
  githubToken: string;
10
12
  owner: string;
@@ -6,13 +6,13 @@
6
6
  import { query } from '@anthropic-ai/claude-agent-sdk';
7
7
  import { Octokit } from '@octokit/rest';
8
8
  import { execSync } from 'child_process';
9
- import { callMcpEndpoint } from '../../api/mcp-client.js';
10
9
  import { DEFAULT_MODEL } from '../../constants.js';
11
10
  import { logError, logInfo, logSuccess } from '../../utils/logger.js';
12
11
  import { cleanupIssueRepo } from '../../workspace/workspace-manager.js';
13
12
  import { fetchUnresolvedReviewThreads } from '../code-refine-verification/github.js';
14
13
  import { createPromptGenerator, extractTextFromContent, tryExtractResult, } from '../pr-shared/agent-utils.js';
15
14
  import { parsePullRequestUrl } from '../pr-shared/context.js';
15
+ import { updatePullRequestStatus } from '../pr-shared/status.js';
16
16
  import { learnFromReviewFeedback } from './checklist-learner.js';
17
17
  import { hasResolveMarker, replyToReviewThread, resolveReviewThread, } from './github-reply.js';
18
18
  import { createResolveSystemPrompt, createResolveUserPrompt, } from './prompts.js';
@@ -221,8 +221,12 @@ export async function resolveStandalonePR(options) {
221
221
  }
222
222
  }
223
223
  logSuccess(`PR resolve completed: ${threadsAddressed} addressed, ${threadsSkipped} skipped, ${threadsErrored} errors`);
224
- // Learn from addressed comments to update code-review checklists
225
- if (options.learn !== false && threadsAddressed > 0 && resolveResult) {
224
+ // Learn from addressed comments to update code-review checklists.
225
+ // Product-scoped only repo-only mode passes learn=false.
226
+ if (options.learn !== false &&
227
+ options.productId &&
228
+ threadsAddressed > 0 &&
229
+ resolveResult) {
226
230
  await learnFromReviewFeedback({
227
231
  productId: options.productId,
228
232
  unresolvedThreads,
@@ -232,15 +236,11 @@ export async function resolveStandalonePR(options) {
232
236
  });
233
237
  }
234
238
  if (prId) {
235
- try {
236
- await callMcpEndpoint('pull_requests/update', {
237
- pull_request_id: prId,
238
- status: 'in_review',
239
- });
240
- }
241
- catch {
242
- // Non-critical
243
- }
239
+ await updatePullRequestStatus({
240
+ prId,
241
+ status: 'in_review',
242
+ repositoryId: options.repositoryId,
243
+ });
244
244
  }
245
245
  // Clean up workspace on success
246
246
  cleanupIssueRepo(repoPath);
@@ -3,7 +3,9 @@
3
3
  * Reviews a GitHub PR and posts review comments, without issue lifecycle dependency.
4
4
  */
5
5
  export interface StandalonePRReviewOptions {
6
- productId: string;
6
+ productId?: string;
7
+ /** Set for repo-scoped PRs — routes the status write through Supabase. */
8
+ repositoryId?: string;
7
9
  pullRequestUrl: string;
8
10
  githubToken: string;
9
11
  owner: string;
@@ -4,19 +4,19 @@
4
4
  */
5
5
  import { query } from '@anthropic-ai/claude-agent-sdk';
6
6
  import { Octokit } from '@octokit/rest';
7
- import { callMcpEndpoint } from '../../api/mcp-client.js';
8
7
  import { DEFAULT_MODEL } from '../../constants.js';
9
8
  import { logError, logInfo } from '../../utils/logger.js';
10
9
  import { buildLineToPositionMap, findClosestPosition, } from '../code-review/diff-utils.js';
11
10
  import { createPromptGenerator, extractTextFromContent, tryExtractResult, } from '../pr-shared/agent-utils.js';
12
11
  import { fetchStandalonePRContext, formatStandalonePRContextForPrompt, } from '../pr-shared/context.js';
12
+ import { updatePullRequestStatus } from '../pr-shared/status.js';
13
13
  import { createStandaloneReviewSystemPrompt, createStandaloneReviewUserPrompt, } from './prompts.js';
14
14
  /**
15
15
  * Review a standalone PR and post comments to GitHub.
16
16
  */
17
17
  // eslint-disable-next-line complexity
18
18
  export async function reviewStandalonePR(options) {
19
- const { pullRequestUrl, githubToken, verbose, prId } = options;
19
+ const { pullRequestUrl, githubToken, verbose, prId, repositoryId } = options;
20
20
  logInfo(`Starting standalone PR review: ${pullRequestUrl}`);
21
21
  try {
22
22
  // Fetch PR context
@@ -95,7 +95,11 @@ export async function reviewStandalonePR(options) {
95
95
  'Code review completed. No issues found.',
96
96
  });
97
97
  if (prId) {
98
- await updatePRStatus(prId, 'in_review');
98
+ await updatePullRequestStatus({
99
+ prId,
100
+ status: 'in_review',
101
+ repositoryId,
102
+ });
99
103
  }
100
104
  return {
101
105
  status: 'success',
@@ -154,7 +158,11 @@ export async function reviewStandalonePR(options) {
154
158
  body: `${summary || 'Code review completed.'}\n\n**Note**: Some review comments could not be posted because they referenced lines not present in the diff.`,
155
159
  });
156
160
  if (prId) {
157
- await updatePRStatus(prId, 'in_review');
161
+ await updatePullRequestStatus({
162
+ prId,
163
+ status: 'in_review',
164
+ repositoryId,
165
+ });
158
166
  }
159
167
  return {
160
168
  status: 'success',
@@ -179,7 +187,7 @@ export async function reviewStandalonePR(options) {
179
187
  });
180
188
  logInfo(`GitHub review created: ${review.data.html_url}`);
181
189
  if (prId) {
182
- await updatePRStatus(prId, 'in_review');
190
+ await updatePullRequestStatus({ prId, status: 'in_review', repositoryId });
183
191
  }
184
192
  return {
185
193
  status: 'success',
@@ -199,14 +207,3 @@ export async function reviewStandalonePR(options) {
199
207
  };
200
208
  }
201
209
  }
202
- async function updatePRStatus(prId, status) {
203
- try {
204
- await callMcpEndpoint('pull_requests/update', {
205
- pull_request_id: prId,
206
- status,
207
- });
208
- }
209
- catch {
210
- // Non-critical, don't fail the review
211
- }
212
- }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Update a pull_requests row's status, choosing the right transport for the
3
+ * scope:
4
+ *
5
+ * - Repo-scoped PRs (repo-only mode) have no product, so the MCP
6
+ * pull_requests/update endpoint — which authorises by product/issue —
7
+ * can't see them. Write straight through the CLI's RLS-scoped Supabase
8
+ * session instead (team-membership RLS authorises the repo PR).
9
+ * - Product/issue PRs keep using the MCP endpoint.
10
+ *
11
+ * Best-effort: a status update is never allowed to fail the review/resolve.
12
+ */
13
+ export declare function updatePullRequestStatus(opts: {
14
+ prId: string;
15
+ status: string;
16
+ /** When set, the PR is repo-scoped and updated directly via Supabase. */
17
+ repositoryId?: string;
18
+ }): Promise<void>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Update a pull_requests row's status, choosing the right transport for the
3
+ * scope:
4
+ *
5
+ * - Repo-scoped PRs (repo-only mode) have no product, so the MCP
6
+ * pull_requests/update endpoint — which authorises by product/issue —
7
+ * can't see them. Write straight through the CLI's RLS-scoped Supabase
8
+ * session instead (team-membership RLS authorises the repo PR).
9
+ * - Product/issue PRs keep using the MCP endpoint.
10
+ *
11
+ * Best-effort: a status update is never allowed to fail the review/resolve.
12
+ */
13
+ import { callMcpEndpoint } from '../../api/mcp-client.js';
14
+ import { ensureSupabaseSession, getSupabase } from '../../supabase/client.js';
15
+ export async function updatePullRequestStatus(opts) {
16
+ const { prId, status, repositoryId } = opts;
17
+ try {
18
+ if (repositoryId) {
19
+ const ready = await ensureSupabaseSession();
20
+ if (!ready) {
21
+ return;
22
+ }
23
+ await getSupabase()
24
+ .from('pull_requests')
25
+ .update({ status, updated_at: new Date().toISOString() })
26
+ .eq('id', prId);
27
+ return;
28
+ }
29
+ await callMcpEndpoint('pull_requests/update', {
30
+ pull_request_id: prId,
31
+ status,
32
+ });
33
+ }
34
+ catch {
35
+ // Non-critical — don't fail the review/resolve on a status write.
36
+ }
37
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * sync-github-pull-requests phase: pull every pull request from a repository's
3
+ * connected GitHub repo and mirror them into the `pull_requests` table scoped
4
+ * by `repository_id`. Deterministic — no Claude Agent SDK; plain Octokit plus
5
+ * the user's RLS-scoped Supabase session.
6
+ *
7
+ * Idempotent: rows are keyed on (repository_id, pull_request_number). New PRs
8
+ * are inserted, and the GitHub-owned fields (status/title/description) of
9
+ * already-synced PRs are refreshed. Re-running never duplicates a PR.
10
+ */
11
+ import { Octokit } from '@octokit/rest';
12
+ import { type GitHubPullRequestLite, type SyncPullRequestsResult } from './types.js';
13
+ export interface SyncGithubPullRequestsOptions {
14
+ repositoryId: string;
15
+ /** GitHub installation token (or PAT). */
16
+ githubToken: string;
17
+ owner: string;
18
+ repo: string;
19
+ verbose?: boolean;
20
+ }
21
+ /** Pull every pull request from the repo, paginated (state=all). */
22
+ export declare function fetchAllRepoPullRequests(octokit: Octokit, owner: string, repo: string): Promise<GitHubPullRequestLite[]>;
23
+ export declare function syncGithubPullRequests(options: SyncGithubPullRequestsOptions): Promise<SyncPullRequestsResult>;