ralph-hero-mcp-server 2.5.119 → 2.5.120
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.
- package/dist/index.js +25 -1
- package/dist/lib/health.js +180 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { FieldOptionCache } from "./lib/cache.js";
|
|
|
16
16
|
import { createDebugLogger, wrapServerToolWithLogging } from "./lib/debug-logger.js";
|
|
17
17
|
import { toolSuccess, resolveProjectOwner } from "./types.js";
|
|
18
18
|
import { resolveRepoFromProject } from "./lib/helpers.js";
|
|
19
|
+
import { detectOrphanRepoIssues } from "./lib/health.js";
|
|
19
20
|
import { registerProjectTools } from "./tools/project-tools.js";
|
|
20
21
|
import { registerIssueTools } from "./tools/issue-tools.js";
|
|
21
22
|
import { registerRelationshipTools } from "./tools/relationship-tools.js";
|
|
@@ -188,7 +189,7 @@ function initGitHubClient(debugLogger) {
|
|
|
188
189
|
*/
|
|
189
190
|
function registerCoreTools(server, client) {
|
|
190
191
|
// Health check tool - comprehensive validation of auth, repo, project, and fields
|
|
191
|
-
server.tool("ralph_hero__health_check", "Validate GitHub API connectivity, token permissions, repo access, project access, and required fields", {}, async () => {
|
|
192
|
+
server.tool("ralph_hero__health_check", "Validate GitHub API connectivity, token permissions, repo access, project access, and required fields. Also surfaces repo-scope mismatch via the `orphanRepoIssues` field when OPEN issues exist in the repo but are NOT on the configured project board (such issues are invisible to discovery tools like next_actions, list_issues, pipeline_dashboard, project_hygiene). The field is omitted entirely when the board contains every OPEN repo issue. Shape when present: `{ count, repoOpen, boardItems, sample: number[], note }` — `sample` is up to 10 orphan issue numbers (ascending) for diagnostic display.", {}, async () => {
|
|
192
193
|
const checks = {};
|
|
193
194
|
// 1. Auth check (repo token)
|
|
194
195
|
try {
|
|
@@ -297,6 +298,26 @@ function registerCoreTools(server, client) {
|
|
|
297
298
|
detail: "RALPH_GH_PROJECT_NUMBER not set",
|
|
298
299
|
};
|
|
299
300
|
}
|
|
301
|
+
// 5. Orphan repo issues check — only runs when both repo and project
|
|
302
|
+
// access succeeded above. Failures here are non-fatal: orphan detection
|
|
303
|
+
// is informational and shouldn't downgrade the overall health status,
|
|
304
|
+
// because the underlying access checks already capture the real failure
|
|
305
|
+
// mode (broken token, missing project, etc.).
|
|
306
|
+
let orphanRepoIssues = null;
|
|
307
|
+
if (checks.repoAccess?.status === "ok" &&
|
|
308
|
+
checks.projectAccess?.status === "ok" &&
|
|
309
|
+
client.config.owner &&
|
|
310
|
+
client.config.repo &&
|
|
311
|
+
projOwner &&
|
|
312
|
+
projNum) {
|
|
313
|
+
try {
|
|
314
|
+
orphanRepoIssues = await detectOrphanRepoIssues(client, client.config.owner, client.config.repo, projOwner, projNum);
|
|
315
|
+
}
|
|
316
|
+
catch (e) {
|
|
317
|
+
// Non-fatal — log via stderr but don't fail health_check.
|
|
318
|
+
console.error(`[ralph-hero] Orphan repo issues check failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
300
321
|
// Token source detection — re-derive which env vars resolved
|
|
301
322
|
const repoTokenSource = resolveEnv("RALPH_GH_REPO_TOKEN")
|
|
302
323
|
? "RALPH_GH_REPO_TOKEN"
|
|
@@ -327,6 +348,9 @@ function registerCoreTools(server, client) {
|
|
|
327
348
|
? `Repo operations use ${repoTokenSource}, project operations use ${projectTokenSource}`
|
|
328
349
|
: `Both repo and project operations use ${repoTokenSource}`,
|
|
329
350
|
},
|
|
351
|
+
// Omit the field entirely when there are no orphans, per the field's
|
|
352
|
+
// contract (`null` from `detectOrphanRepoIssues` means "clean board").
|
|
353
|
+
...(orphanRepoIssues ? { orphanRepoIssues } : {}),
|
|
330
354
|
});
|
|
331
355
|
});
|
|
332
356
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health-check helpers — pure functions that probe the GitHub API for
|
|
3
|
+
* configuration drift between the project board and its underlying repo.
|
|
4
|
+
*
|
|
5
|
+
* `detectOrphanRepoIssues` compares the set of OPEN issues in the configured
|
|
6
|
+
* repo against the set of `type=ISSUE` items on the configured project
|
|
7
|
+
* board. Issues present in the repo but not on the board are "orphans" —
|
|
8
|
+
* they exist but are structurally invisible to the discovery tools
|
|
9
|
+
* (`next_actions`, `list_issues`, `pipeline_dashboard`, `project_hygiene`),
|
|
10
|
+
* which all read from the project board.
|
|
11
|
+
*
|
|
12
|
+
* Surfaced via `health_check` so users discover the mismatch without having
|
|
13
|
+
* to grep `gh issue list` against the board contents by hand.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Maximum number of orphan issue numbers to include in the response sample.
|
|
17
|
+
* The sample is for diagnostic display only; the full set is summarized via `count`.
|
|
18
|
+
*/
|
|
19
|
+
export const ORPHAN_SAMPLE_LIMIT = 10;
|
|
20
|
+
/**
|
|
21
|
+
* Page size used when paginating repo issues and project items.
|
|
22
|
+
*
|
|
23
|
+
* GitHub GraphQL caps `first:` at 100. Most projects fit comfortably in a
|
|
24
|
+
* handful of pages — pagination is implemented for correctness, not because
|
|
25
|
+
* every call hits it.
|
|
26
|
+
*/
|
|
27
|
+
const PAGE_SIZE = 100;
|
|
28
|
+
/**
|
|
29
|
+
* Hard cap on pages walked when enumerating repo issues or project items.
|
|
30
|
+
* Defensive: prevents a runaway loop on a misconfigured giant repo.
|
|
31
|
+
*/
|
|
32
|
+
const MAX_PAGES = 20;
|
|
33
|
+
/**
|
|
34
|
+
* Standard explanatory note attached to the orphan-repo-issues warning.
|
|
35
|
+
* Lifted to a constant so tests can assert against a single canonical string.
|
|
36
|
+
*/
|
|
37
|
+
export const ORPHAN_REPO_ISSUES_NOTE = "Issues exist in the repo that are not on the project board. They are " +
|
|
38
|
+
"invisible to discovery tools (next_actions, list_issues, pipeline_dashboard, " +
|
|
39
|
+
"project_hygiene). To make them visible, add them to the project or use " +
|
|
40
|
+
"'gh issue list' directly.";
|
|
41
|
+
/**
|
|
42
|
+
* Fetch all OPEN issue numbers in the repo via paginated GraphQL.
|
|
43
|
+
*
|
|
44
|
+
* Returns `{ totalCount, numbers }`. `totalCount` is taken from the first
|
|
45
|
+
* page (it is constant across pages). `numbers` is the union of all
|
|
46
|
+
* `node.number` values walked.
|
|
47
|
+
*/
|
|
48
|
+
async function fetchRepoOpenIssueNumbers(client, owner, repo) {
|
|
49
|
+
const numbers = new Set();
|
|
50
|
+
let totalCount = 0;
|
|
51
|
+
let cursor = null;
|
|
52
|
+
let pages = 0;
|
|
53
|
+
while (pages < MAX_PAGES) {
|
|
54
|
+
const response = await client.query(`query($owner: String!, $repo: String!, $cursor: String, $first: Int!) {
|
|
55
|
+
repository(owner: $owner, name: $repo) {
|
|
56
|
+
issues(states: OPEN, first: $first, after: $cursor) {
|
|
57
|
+
totalCount
|
|
58
|
+
pageInfo { hasNextPage endCursor }
|
|
59
|
+
nodes { number }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}`, { owner, repo, cursor, first: PAGE_SIZE });
|
|
63
|
+
const page = response.repository?.issues;
|
|
64
|
+
if (!page)
|
|
65
|
+
break;
|
|
66
|
+
if (pages === 0)
|
|
67
|
+
totalCount = page.totalCount;
|
|
68
|
+
for (const node of page.nodes)
|
|
69
|
+
numbers.add(node.number);
|
|
70
|
+
if (!page.pageInfo.hasNextPage)
|
|
71
|
+
break;
|
|
72
|
+
cursor = page.pageInfo.endCursor;
|
|
73
|
+
pages += 1;
|
|
74
|
+
}
|
|
75
|
+
return { totalCount, numbers };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Fetch all `type=ISSUE` item numbers on the project board via paginated GraphQL.
|
|
79
|
+
*
|
|
80
|
+
* The query tries `user(login)` first, then falls back to `organization(login)`
|
|
81
|
+
* to handle both account types. PRs and DraftIssues are skipped — only true
|
|
82
|
+
* `Issue`-typed content with a `number` field is collected.
|
|
83
|
+
*/
|
|
84
|
+
async function fetchBoardIssueNumbers(client, projectOwner, projectNumber) {
|
|
85
|
+
const numbers = new Set();
|
|
86
|
+
let totalCount = 0;
|
|
87
|
+
let cursor = null;
|
|
88
|
+
let pages = 0;
|
|
89
|
+
// The project items query is identical across user/org owner — only the
|
|
90
|
+
// root selector changes. Build a closure that runs the same shape and
|
|
91
|
+
// tries both owner types on the first page.
|
|
92
|
+
const runQuery = async (cur) => {
|
|
93
|
+
for (const ownerType of ["user", "organization"]) {
|
|
94
|
+
try {
|
|
95
|
+
const res = await client.projectQuery(`query($owner: String!, $number: Int!, $cursor: String, $first: Int!) {
|
|
96
|
+
${ownerType}(login: $owner) {
|
|
97
|
+
projectV2(number: $number) {
|
|
98
|
+
items(first: $first, after: $cursor) {
|
|
99
|
+
totalCount
|
|
100
|
+
pageInfo { hasNextPage endCursor }
|
|
101
|
+
nodes {
|
|
102
|
+
type
|
|
103
|
+
content {
|
|
104
|
+
__typename
|
|
105
|
+
... on Issue { number }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}`, { owner: projectOwner, number: projectNumber, cursor: cur, first: PAGE_SIZE });
|
|
112
|
+
const proj = res[ownerType]?.projectV2;
|
|
113
|
+
if (proj)
|
|
114
|
+
return proj;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Try next owner type
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
};
|
|
122
|
+
while (pages < MAX_PAGES) {
|
|
123
|
+
const proj = await runQuery(cursor);
|
|
124
|
+
if (!proj || !proj.items)
|
|
125
|
+
break;
|
|
126
|
+
if (pages === 0)
|
|
127
|
+
totalCount = proj.items.totalCount;
|
|
128
|
+
for (const node of proj.items.nodes) {
|
|
129
|
+
// Only count Issue-typed content. Type field is "ISSUE" but we double-check
|
|
130
|
+
// via __typename because draft-issue items can have type=DRAFT_ISSUE and
|
|
131
|
+
// should never count as repo-issue overlap.
|
|
132
|
+
if (node.type === "ISSUE" &&
|
|
133
|
+
node.content?.__typename === "Issue" &&
|
|
134
|
+
typeof node.content.number === "number") {
|
|
135
|
+
numbers.add(node.content.number);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!proj.items.pageInfo.hasNextPage)
|
|
139
|
+
break;
|
|
140
|
+
cursor = proj.items.pageInfo.endCursor;
|
|
141
|
+
pages += 1;
|
|
142
|
+
}
|
|
143
|
+
return { totalCount, numbers };
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Detect repo issues that are absent from the project board.
|
|
147
|
+
*
|
|
148
|
+
* Returns the orphan summary when at least one orphan exists, or `null`
|
|
149
|
+
* when the board contains every OPEN repo issue.
|
|
150
|
+
*
|
|
151
|
+
* Returns `null` (not an empty result) so the `health_check` caller can
|
|
152
|
+
* omit the field entirely on a clean board — keeping the response tight
|
|
153
|
+
* for the common no-orphans case.
|
|
154
|
+
*/
|
|
155
|
+
export async function detectOrphanRepoIssues(client, owner, repo, projectOwner, projectNumber) {
|
|
156
|
+
const [repoSide, boardSide] = await Promise.all([
|
|
157
|
+
fetchRepoOpenIssueNumbers(client, owner, repo),
|
|
158
|
+
fetchBoardIssueNumbers(client, projectOwner, projectNumber),
|
|
159
|
+
]);
|
|
160
|
+
// Orphans = OPEN issues in the repo whose number is NOT in the board set.
|
|
161
|
+
// We compare against the actual numbers walked rather than just totalCount,
|
|
162
|
+
// because a board may contain issues from OTHER repos (multi-repo project)
|
|
163
|
+
// — those would inflate `boardItems` but contribute zero to the overlap.
|
|
164
|
+
const orphanNumbers = [];
|
|
165
|
+
for (const n of repoSide.numbers) {
|
|
166
|
+
if (!boardSide.numbers.has(n))
|
|
167
|
+
orphanNumbers.push(n);
|
|
168
|
+
}
|
|
169
|
+
orphanNumbers.sort((a, b) => a - b);
|
|
170
|
+
if (orphanNumbers.length === 0)
|
|
171
|
+
return null;
|
|
172
|
+
return {
|
|
173
|
+
count: orphanNumbers.length,
|
|
174
|
+
repoOpen: repoSide.totalCount,
|
|
175
|
+
boardItems: boardSide.totalCount,
|
|
176
|
+
sample: orphanNumbers.slice(0, ORPHAN_SAMPLE_LIMIT),
|
|
177
|
+
note: ORPHAN_REPO_ISSUES_NOTE,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=health.js.map
|