@bbcsoftwarefactory/cli 0.1.0 → 1.1.2

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 (126) hide show
  1. package/dist/audit-ledger.d.ts +2 -0
  2. package/dist/audit-ledger.js +71 -0
  3. package/dist/bbc-install.d.ts +2 -0
  4. package/dist/bbc-install.js +1250 -0
  5. package/dist/bbc.d.ts +2 -0
  6. package/dist/bbc.js +124 -0
  7. package/dist/bigo/complexity.d.ts +18 -0
  8. package/dist/bigo/complexity.js +139 -0
  9. package/dist/bigo/functions.d.ts +5 -0
  10. package/dist/bigo/functions.js +174 -0
  11. package/dist/bigo/keywords.d.ts +1 -0
  12. package/dist/bigo/keywords.js +43 -0
  13. package/dist/bigo/lexical.d.ts +14 -0
  14. package/dist/bigo/lexical.js +69 -0
  15. package/dist/bigo/source-files.d.ts +1 -0
  16. package/dist/bigo/source-files.js +80 -0
  17. package/dist/change-lane/classification.d.ts +41 -0
  18. package/dist/change-lane/classification.js +104 -0
  19. package/dist/change-lane/git.d.ts +8 -0
  20. package/dist/change-lane/git.js +105 -0
  21. package/dist/check-issue-claim.d.ts +2 -0
  22. package/dist/check-issue-claim.js +146 -0
  23. package/dist/check-worktree-guard.d.ts +2 -0
  24. package/dist/check-worktree-guard.js +114 -0
  25. package/dist/classify-change-lane.d.ts +2 -0
  26. package/dist/classify-change-lane.js +128 -0
  27. package/dist/diff-scope/git-diff.d.ts +25 -0
  28. package/dist/diff-scope/git-diff.js +146 -0
  29. package/dist/error-scan.d.ts +3 -0
  30. package/dist/error-scan.js +216 -0
  31. package/dist/export-public.d.ts +9 -0
  32. package/dist/export-public.js +274 -0
  33. package/dist/extract-diff-scope.d.ts +2 -0
  34. package/dist/extract-diff-scope.js +111 -0
  35. package/dist/fetch-issue-attachments.d.ts +22 -0
  36. package/dist/fetch-issue-attachments.js +325 -0
  37. package/dist/issue-claim/evaluation.d.ts +66 -0
  38. package/dist/issue-claim/evaluation.js +259 -0
  39. package/dist/issue-claim/loaders.d.ts +5 -0
  40. package/dist/issue-claim/loaders.js +116 -0
  41. package/dist/list-zed-commands.d.ts +7 -0
  42. package/dist/list-zed-commands.js +288 -0
  43. package/dist/measure-bigo.d.ts +2 -0
  44. package/dist/measure-bigo.js +84 -0
  45. package/dist/plan-issue-triage.d.ts +3 -0
  46. package/dist/plan-issue-triage.js +404 -0
  47. package/dist/question-gate/ledger.d.ts +5 -0
  48. package/dist/question-gate/ledger.js +115 -0
  49. package/dist/question-gate/rules.d.ts +40 -0
  50. package/dist/question-gate/rules.js +483 -0
  51. package/dist/recap/board.d.ts +5 -0
  52. package/dist/recap/board.js +384 -0
  53. package/dist/recap/git-and-github.d.ts +11 -0
  54. package/dist/recap/git-and-github.js +620 -0
  55. package/dist/recap/report-and-hud.d.ts +2 -0
  56. package/dist/recap/report-and-hud.js +294 -0
  57. package/dist/recap/time-and-refs.d.ts +27 -0
  58. package/dist/recap/time-and-refs.js +148 -0
  59. package/dist/recap.d.ts +2 -0
  60. package/dist/recap.js +217 -0
  61. package/dist/render-workflow.d.ts +2 -0
  62. package/dist/render-workflow.js +142 -0
  63. package/dist/resolve-containers.d.ts +2 -0
  64. package/dist/resolve-containers.js +96 -0
  65. package/dist/review-loop.d.ts +7 -0
  66. package/dist/review-loop.js +622 -0
  67. package/dist/save-counts.d.ts +2 -0
  68. package/dist/save-counts.js +191 -0
  69. package/dist/summarize-logs.d.ts +2 -0
  70. package/dist/summarize-logs.js +41 -0
  71. package/dist/sweep-github.d.ts +10 -0
  72. package/dist/sweep-github.js +453 -0
  73. package/dist/sweep-issues.d.ts +56 -0
  74. package/dist/sweep-issues.js +650 -0
  75. package/dist/sweep.d.ts +2 -0
  76. package/dist/sweep.js +301 -0
  77. package/dist/triage-question.d.ts +2 -0
  78. package/dist/triage-question.js +189 -0
  79. package/dist/validate-skills.d.ts +2 -0
  80. package/dist/validate-skills.js +48 -0
  81. package/dist/watch-live.d.ts +7 -0
  82. package/dist/watch-live.js +83 -0
  83. package/dist/watcher/config.d.ts +11 -0
  84. package/dist/watcher/config.js +265 -0
  85. package/dist/watcher/live-classifier.d.ts +52 -0
  86. package/dist/watcher/live-classifier.js +510 -0
  87. package/dist/watcher/safe-fs.d.ts +9 -0
  88. package/dist/watcher/safe-fs.js +159 -0
  89. package/dist/watcher/stream.d.ts +27 -0
  90. package/dist/watcher/stream.js +340 -0
  91. package/dist/watcher/summarizer.d.ts +19 -0
  92. package/dist/watcher/summarizer.js +121 -0
  93. package/dist/wave3/process.d.ts +14 -0
  94. package/dist/wave3/process.js +84 -0
  95. package/dist/wave4/process.d.ts +14 -0
  96. package/dist/wave4/process.js +128 -0
  97. package/dist/workflow/render.d.ts +13 -0
  98. package/dist/workflow/render.js +31 -0
  99. package/dist/workflow/schema.d.ts +25 -0
  100. package/dist/workflow/schema.js +99 -0
  101. package/dist/workflow-auditor/audit.d.ts +27 -0
  102. package/dist/workflow-auditor/audit.js +583 -0
  103. package/dist/workflow-auditor/ledger-io.d.ts +5 -0
  104. package/dist/workflow-auditor/ledger-io.js +99 -0
  105. package/dist/workflow-auditor/skills-validator.d.ts +10 -0
  106. package/dist/workflow-auditor/skills-validator.js +533 -0
  107. package/dist/worktree-guard/evaluation.d.ts +19 -0
  108. package/dist/worktree-guard/evaluation.js +84 -0
  109. package/dist/worktree-guard/git.d.ts +3 -0
  110. package/dist/worktree-guard/git.js +61 -0
  111. package/package.json +32 -33
  112. package/src/bbc.ts +0 -39
  113. package/src/bigo/complexity.ts +0 -138
  114. package/src/bigo/functions.ts +0 -183
  115. package/src/bigo/keywords.ts +0 -41
  116. package/src/bigo/lexical.ts +0 -68
  117. package/src/bigo/source-files.ts +0 -80
  118. package/src/change-lane/classification.ts +0 -128
  119. package/src/change-lane/git.ts +0 -110
  120. package/src/classify-change-lane.ts +0 -140
  121. package/src/diff-scope/git-diff.ts +0 -161
  122. package/src/extract-diff-scope.ts +0 -130
  123. package/src/measure-bigo.ts +0 -86
  124. package/src/render-workflow.ts +0 -144
  125. package/src/workflow/render.ts +0 -40
  126. package/src/workflow/schema.ts +0 -141
@@ -0,0 +1,620 @@
1
+ /**
2
+ * LAYER: Infrastructure
3
+ * Contains: Local Git and GitHub REST / GraphQL collectors for /recap.
4
+ * Rules: Read-only collection; gracefully degrade to GAP metadata on unavailable tools.
5
+ * BigO: O(n) score:4
6
+ * keywords: [LocalGitCollector, GitHubCollector, ProjectBoardCollector]
7
+ * GOAL: Collect local Git commit/diff stats and GitHub issue/PR/board activity.
8
+ */
9
+ import { runCommand } from "../wave3/process.js";
10
+ import { inWindow, parseRepoFromRemote } from "./time-and-refs.js";
11
+ const CLOSES_ISSUE_RE = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)/gi;
12
+ function execSafe(cmd, cwd, timeoutMs = 20_000) {
13
+ try {
14
+ return runCommand(cmd, { cwd, timeoutMs });
15
+ }
16
+ catch (error) {
17
+ return { code: 1, stdout: '', stderr: error instanceof Error ? error.message : String(error) };
18
+ }
19
+ }
20
+ export function ghApiJson(endpoint, method = 'GET', body) {
21
+ const cmd = ['gh', 'api'];
22
+ let stdinText;
23
+ if (method !== 'GET') {
24
+ cmd.push('-X', method);
25
+ }
26
+ cmd.push(endpoint);
27
+ if (body !== undefined) {
28
+ cmd.push('--input', '-');
29
+ stdinText = JSON.stringify(body);
30
+ }
31
+ const res = execSafe(cmd, undefined, 25_000);
32
+ if (res.code !== 0) {
33
+ throw new Error(res.stderr || `gh api failed for ${endpoint}`);
34
+ }
35
+ return res.stdout.trim() ? JSON.parse(res.stdout) : {};
36
+ }
37
+ export function ghGraphql(query, variables) {
38
+ return ghGraphqlSafe(query, variables);
39
+ }
40
+ function ghGraphqlSafe(query, variables) {
41
+ const payload = JSON.stringify({ query, variables: variables ?? {} });
42
+ let res;
43
+ try {
44
+ res = runCommand(['gh', 'api', 'graphql', '--input', '-'], { input: payload, timeoutMs: 30_000 });
45
+ }
46
+ catch (error) {
47
+ throw new Error(error instanceof Error ? error.message : String(error));
48
+ }
49
+ if (res.code !== 0) {
50
+ throw new Error(res.stderr || 'gh api graphql failed');
51
+ }
52
+ const data = JSON.parse(res.stdout);
53
+ if (Array.isArray(data.errors) && data.errors.length > 0) {
54
+ throw new Error(data.errors.map((e) => e.message ?? 'GraphQL error').join('; '));
55
+ }
56
+ return data.data ?? {};
57
+ }
58
+ function ghApiJsonSafe(endpoint, method = 'GET', body) {
59
+ const cmd = ['gh', 'api'];
60
+ let input;
61
+ if (method !== 'GET')
62
+ cmd.push('-X', method);
63
+ cmd.push(endpoint);
64
+ if (body !== undefined) {
65
+ cmd.push('--input', '-');
66
+ input = JSON.stringify(body);
67
+ }
68
+ let res;
69
+ try {
70
+ res = runCommand(cmd, { input, timeoutMs: 25_000 });
71
+ }
72
+ catch (error) {
73
+ throw new Error(error instanceof Error ? error.message : String(error));
74
+ }
75
+ if (res.code !== 0) {
76
+ throw new Error(res.stderr || `gh api failed for ${endpoint}`);
77
+ }
78
+ return res.stdout.trim() ? JSON.parse(res.stdout) : {};
79
+ }
80
+ export { ghApiJsonSafe as apiJson, ghGraphqlSafe as graphql };
81
+ export function collectLocalGit(cwd, sinceDt, authorPattern) {
82
+ const top = execSafe(['git', 'rev-parse', '--show-toplevel'], cwd);
83
+ if (top.code !== 0 || !top.stdout.trim()) {
84
+ return { available: false, reason: 'Not inside a Git working tree' };
85
+ }
86
+ const root = top.stdout.trim();
87
+ const branch = execSafe(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], root).stdout.trim() || 'HEAD';
88
+ const remoteOut = execSafe(['git', 'remote', 'get-url', 'origin'], root).stdout;
89
+ const detectedRepo = parseRepoFromRemote(remoteOut);
90
+ let displayName = execSafe(['git', 'config', 'user.name'], root).stdout.trim();
91
+ let author = (authorPattern ?? '').trim();
92
+ if (!author)
93
+ author = execSafe(['git', 'config', 'user.email'], root).stdout.trim();
94
+ if (!author)
95
+ author = displayName;
96
+ if (!displayName && author)
97
+ displayName = author.split('@', 1)[0] ?? '';
98
+ const logCmd = [
99
+ 'git',
100
+ 'log',
101
+ '--branches',
102
+ '--no-merges',
103
+ `--since=${sinceDt.iso}`,
104
+ '--numstat',
105
+ '--format=__COMMIT__%x09%H%x09%s%x09%aI',
106
+ ];
107
+ if (author)
108
+ logCmd.push(`--author=${author}`);
109
+ const logRes = execSafe(logCmd, root);
110
+ let commits = 0;
111
+ let insertions = 0;
112
+ let deletions = 0;
113
+ const touchedFiles = new Set();
114
+ const seenShas = new Set();
115
+ let activeSha = null;
116
+ if (logRes.code === 0) {
117
+ for (const line of logRes.stdout.split(/\r?\n/)) {
118
+ if (line.startsWith('__COMMIT__\t')) {
119
+ const parts = line.split('\t');
120
+ const sha = parts[1] ?? '';
121
+ if (sha && !seenShas.has(sha)) {
122
+ seenShas.add(sha);
123
+ commits += 1;
124
+ activeSha = sha;
125
+ }
126
+ else {
127
+ activeSha = null;
128
+ }
129
+ continue;
130
+ }
131
+ if (activeSha === null || !line.trim())
132
+ continue;
133
+ const cols = line.split('\t');
134
+ if (cols.length < 3)
135
+ continue;
136
+ const insS = cols[0] ?? '';
137
+ const delS = cols[1] ?? '';
138
+ const pathS = cols[2] ?? '';
139
+ if (/^\d+$/.test(insS))
140
+ insertions += Number.parseInt(insS, 10);
141
+ if (/^\d+$/.test(delS))
142
+ deletions += Number.parseInt(delS, 10);
143
+ if (pathS.trim())
144
+ touchedFiles.add(pathS.trim());
145
+ }
146
+ }
147
+ let aheadCommits = 0;
148
+ const up = execSafe(['git', 'rev-list', '--count', '@{u}..HEAD'], root);
149
+ if (up.code === 0 && /^\d+$/.test(up.stdout.trim())) {
150
+ aheadCommits = Number.parseInt(up.stdout.trim(), 10);
151
+ }
152
+ else if (branch !== 'HEAD') {
153
+ const rem = execSafe(['git', 'rev-list', '--count', branch, '--not', '--remotes'], root);
154
+ if (rem.code === 0 && /^\d+$/.test(rem.stdout.trim())) {
155
+ aheadCommits = Number.parseInt(rem.stdout.trim(), 10);
156
+ }
157
+ }
158
+ const status = execSafe(['git', 'status', '--porcelain'], root);
159
+ const workingChanges = status.stdout.split(/\r?\n/).filter((ln) => ln.trim().length > 0).length;
160
+ return {
161
+ available: true,
162
+ repo: detectedRepo,
163
+ branch,
164
+ author: displayName || null,
165
+ commits,
166
+ files_changed: touchedFiles.size,
167
+ insertions,
168
+ deletions,
169
+ ahead_commits: aheadCommits,
170
+ working_changes: workingChanges,
171
+ };
172
+ }
173
+ function searchItems(query) {
174
+ const encoded = encodeURIComponent(query);
175
+ const data = ghApiJsonSafe(`search/issues?q=${encoded}&per_page=100`);
176
+ const items = Array.isArray(data?.items) ? data.items : [];
177
+ return items.filter((it) => it !== null && typeof it === 'object' && !Array.isArray(it));
178
+ }
179
+ function repoFromApiItem(item) {
180
+ const repoUrl = typeof item.repository_url === 'string' ? item.repository_url : '';
181
+ const idx = repoUrl.indexOf('/repos/');
182
+ return idx >= 0 ? repoUrl.slice(idx + '/repos/'.length) : null;
183
+ }
184
+ function summarizeCi(repoSlug, headSha) {
185
+ if (!repoSlug || !headSha)
186
+ return 'unknown';
187
+ let data;
188
+ try {
189
+ data = ghApiJsonSafe(`repos/${repoSlug}/commits/${headSha}/check-runs?per_page=100`);
190
+ }
191
+ catch {
192
+ return 'unknown';
193
+ }
194
+ const runs = Array.isArray(data?.check_runs) ? data.check_runs : [];
195
+ if (runs.length === 0)
196
+ return 'none';
197
+ let hasPending = false;
198
+ for (const run of runs) {
199
+ if (run === null || typeof run !== 'object')
200
+ continue;
201
+ const rec = run;
202
+ if (rec.status !== 'completed') {
203
+ hasPending = true;
204
+ continue;
205
+ }
206
+ const conclusion = rec.conclusion;
207
+ if (conclusion !== 'success' && conclusion !== 'skipped' && conclusion !== 'neutral') {
208
+ return 'failing';
209
+ }
210
+ }
211
+ return hasPending ? 'pending' : 'success';
212
+ }
213
+ function enrichPrItem(item, fallbackRepo) {
214
+ const repoSlug = repoFromApiItem(item) ?? fallbackRepo;
215
+ const num = item.number;
216
+ const prMeta = item.pull_request ?? {};
217
+ let mergedAt = item.merged_at ?? prMeta.merged_at ?? null;
218
+ let draft = Boolean(item.draft);
219
+ let ciStatus = 'unknown';
220
+ if (repoSlug && typeof num === 'number') {
221
+ try {
222
+ const detail = ghApiJsonSafe(`repos/${repoSlug}/pulls/${num}`);
223
+ mergedAt = detail.merged_at ?? mergedAt;
224
+ draft = Boolean(detail.draft ?? draft);
225
+ const head = detail.head ?? {};
226
+ ciStatus = summarizeCi(repoSlug, typeof head.sha === 'string' ? head.sha : null);
227
+ }
228
+ catch {
229
+ // Best-effort enrichment
230
+ }
231
+ }
232
+ return {
233
+ repo: repoSlug,
234
+ number: num ?? null,
235
+ title: item.title ?? '',
236
+ state: item.state ?? 'open',
237
+ draft,
238
+ created_at: item.created_at ?? null,
239
+ updated_at: item.updated_at ?? null,
240
+ merged_at: mergedAt,
241
+ ci_status: ciStatus,
242
+ url: item.html_url ?? null,
243
+ };
244
+ }
245
+ function extractLinkedIssues(bodyText) {
246
+ if (typeof bodyText !== 'string' || !bodyText)
247
+ return [];
248
+ const nums = [];
249
+ for (const match of bodyText.matchAll(CLOSES_ISSUE_RE)) {
250
+ if (match[1])
251
+ nums.push(Number.parseInt(match[1], 10));
252
+ }
253
+ return nums;
254
+ }
255
+ function assigneeLogins(item) {
256
+ const raw = Array.isArray(item.assignees) ? item.assignees : [];
257
+ const logins = new Set();
258
+ for (const entry of raw) {
259
+ if (entry !== null && typeof entry === 'object' && typeof entry.login === 'string') {
260
+ logins.add(entry.login);
261
+ }
262
+ }
263
+ return logins;
264
+ }
265
+ export function collectGithub(repo, allRepos, sinceDt, userOverride) {
266
+ const auth = execSafe(['gh', 'auth', 'status'], undefined, 15_000);
267
+ if (auth.code !== 0) {
268
+ return { available: false, gap: auth.stderr || 'gh CLI not installed or not authenticated' };
269
+ }
270
+ let login = (userOverride ?? '').trim();
271
+ if (!login) {
272
+ try {
273
+ const userData = ghApiJsonSafe('user');
274
+ login = typeof userData.login === 'string' ? userData.login.trim() : '';
275
+ }
276
+ catch (error) {
277
+ const msg = error instanceof Error ? error.message : String(error);
278
+ return { available: false, gap: `Could not resolve GitHub user: ${msg}` };
279
+ }
280
+ }
281
+ if (!login) {
282
+ return { available: false, gap: 'GitHub user login is empty' };
283
+ }
284
+ if (!allRepos && !repo) {
285
+ return {
286
+ available: false,
287
+ user: login,
288
+ gap: 'No GitHub repository detected; pass --repo owner/repo or --all-repos',
289
+ };
290
+ }
291
+ const scopeFilter = allRepos ? '' : ` repo:${repo}`;
292
+ const searchDate = sinceDt.utcDate;
293
+ const gaps = [];
294
+ try {
295
+ const rawCreated = searchItems(`is:issue author:${login} created:>=${searchDate}${scopeFilter}`);
296
+ const issuesCreated = rawCreated
297
+ .filter((it) => inWindow(it.created_at, sinceDt.ms))
298
+ .map((it) => ({
299
+ repo: repoFromApiItem(it) ?? repo,
300
+ number: it.number ?? null,
301
+ title: it.title ?? '',
302
+ state: it.state ?? 'open',
303
+ created_at: it.created_at ?? null,
304
+ url: it.html_url ?? null,
305
+ }));
306
+ const rawMerged = searchItems(`is:pr author:${login} is:merged merged:>=${searchDate}${scopeFilter}`);
307
+ const prsMerged = [];
308
+ const linkedIssues = new Set();
309
+ for (const it of rawMerged) {
310
+ const prMeta = it.pull_request ?? {};
311
+ let mergedAt = it.merged_at ?? prMeta.merged_at ?? null;
312
+ if (!mergedAt && repo) {
313
+ mergedAt = enrichPrItem(it, repo).merged_at ?? null;
314
+ }
315
+ if (!inWindow(mergedAt, sinceDt.ms))
316
+ continue;
317
+ prsMerged.push({
318
+ repo: repoFromApiItem(it) ?? repo,
319
+ number: it.number ?? null,
320
+ title: it.title ?? '',
321
+ merged_at: mergedAt,
322
+ url: it.html_url ?? null,
323
+ });
324
+ for (const n of extractLinkedIssues(it.body))
325
+ linkedIssues.add(n);
326
+ }
327
+ let issuesClosed = [];
328
+ if (allRepos || !repo) {
329
+ const rawClosed = searchItems(`is:issue involves:${login} is:closed closed:>=${searchDate}`);
330
+ issuesClosed = rawClosed
331
+ .filter((it) => inWindow(it.closed_at, sinceDt.ms))
332
+ .map((it) => ({
333
+ repo: repoFromApiItem(it),
334
+ number: it.number ?? null,
335
+ title: it.title ?? '',
336
+ closed_at: it.closed_at ?? null,
337
+ url: it.html_url ?? null,
338
+ }));
339
+ }
340
+ else {
341
+ const closedList = ghApiJsonSafe(`repos/${repo}/issues?state=closed&since=${sinceDt.utcIso}&per_page=100`);
342
+ if (Array.isArray(closedList)) {
343
+ for (const it of closedList) {
344
+ if (it === null || typeof it !== 'object' || 'pull_request' in it)
345
+ continue;
346
+ const rec = it;
347
+ if (!inWindow(rec.closed_at, sinceDt.ms))
348
+ continue;
349
+ const closedBy = rec.closed_by?.login;
350
+ const authorLogin = rec.user?.login;
351
+ const assignees = assigneeLogins(rec);
352
+ const num = typeof rec.number === 'number' ? rec.number : -1;
353
+ if (closedBy === login || authorLogin === login || assignees.has(login) || linkedIssues.has(num)) {
354
+ issuesClosed.push({
355
+ repo,
356
+ number: rec.number ?? null,
357
+ title: rec.title ?? '',
358
+ closed_at: rec.closed_at ?? null,
359
+ url: rec.html_url ?? null,
360
+ });
361
+ }
362
+ }
363
+ }
364
+ }
365
+ const rawOpened = searchItems(`is:pr author:${login} created:>=${searchDate}${scopeFilter}`);
366
+ const openedFiltered = rawOpened.filter((it) => inWindow(it.created_at, sinceDt.ms));
367
+ const prsOpened = openedFiltered.slice(0, 20).map((it) => enrichPrItem(it, repo));
368
+ if (openedFiltered.length > 20) {
369
+ gaps.push(`PR details capped at 20 of ${openedFiltered.length} opened PRs`);
370
+ }
371
+ const rawOpenUpd = searchItems(`is:pr is:open author:${login} updated:>=${searchDate}${scopeFilter}`);
372
+ const openUpdFiltered = rawOpenUpd.filter((it) => inWindow(it.updated_at, sinceDt.ms));
373
+ const prsInProgress = openUpdFiltered.slice(0, 20).map((it) => enrichPrItem(it, repo));
374
+ const rawCommented = searchItems(`is:pr commenter:${login} updated:>=${searchDate}${scopeFilter}`);
375
+ const rawReviewed = searchItems(`is:pr reviewed-by:${login} updated:>=${searchDate}${scopeFilter}`);
376
+ const peerPrs = new Set();
377
+ for (const it of [...rawCommented, ...rawReviewed]) {
378
+ if (!inWindow(it.updated_at, sinceDt.ms))
379
+ continue;
380
+ const authorLogin = it.user?.login;
381
+ if (authorLogin === login)
382
+ continue;
383
+ const key = (typeof it.html_url === 'string' && it.html_url) ||
384
+ `${String(repoFromApiItem(it))}#${String(it.number)}`;
385
+ peerPrs.add(key);
386
+ }
387
+ return {
388
+ available: true,
389
+ user: login,
390
+ issues_created: issuesCreated,
391
+ issues_closed: issuesClosed,
392
+ prs_opened: prsOpened,
393
+ prs_merged: prsMerged,
394
+ prs_in_progress: prsInProgress,
395
+ reviews_and_comments: peerPrs.size,
396
+ gaps,
397
+ };
398
+ }
399
+ catch (error) {
400
+ const msg = error instanceof Error ? error.message : String(error);
401
+ return { available: false, user: login, gap: `GitHub REST error: ${msg}` };
402
+ }
403
+ }
404
+ function extractBoardItem(node) {
405
+ const content = node.content ?? {};
406
+ const repoInfo = content.repository ?? {};
407
+ const fields = {};
408
+ const fieldNodes = node.fieldValues?.nodes ?? [];
409
+ for (const fv of fieldNodes) {
410
+ if (fv === null || typeof fv !== 'object')
411
+ continue;
412
+ const rec = fv;
413
+ const fld = rec.field ?? {};
414
+ if (typeof fld.name === 'string' && rec.name !== undefined && rec.name !== null) {
415
+ fields[fld.name] = rec.name;
416
+ }
417
+ }
418
+ const assignees = (content.assignees?.nodes ?? [])
419
+ .filter((a) => a !== null && typeof a === 'object' && typeof a.login === 'string')
420
+ .map((a) => a.login);
421
+ const labels = (content.labels?.nodes ?? [])
422
+ .filter((l) => l !== null && typeof l === 'object' && typeof l.name === 'string')
423
+ .map((l) => l.name);
424
+ const number = content.number ?? null;
425
+ return {
426
+ id: node.id ?? null,
427
+ repo: repoInfo.nameWithOwner ?? null,
428
+ number,
429
+ type: 'merged' in content ? 'PullRequest' : number ? 'Issue' : 'DraftIssue',
430
+ title: content.title ?? '',
431
+ state: content.state ?? null,
432
+ merged: Boolean(content.merged),
433
+ url: content.url ?? null,
434
+ status: fields.Status ?? 'Sin estado',
435
+ priority: fields.Priority ?? null,
436
+ fields,
437
+ assignees,
438
+ labels,
439
+ };
440
+ }
441
+ export function collectProjectBoard(projectRef) {
442
+ const auth = execSafe(['gh', 'auth', 'status'], undefined, 15_000);
443
+ if (auth.code !== 0) {
444
+ return { available: false, gap: auth.stderr || 'gh CLI not installed or not authenticated' };
445
+ }
446
+ const ownerField = projectRef.owner_type;
447
+ const query = `query($owner: String!, $number: Int!, $cursor: String) {
448
+ ${ownerField}(login: $owner) {
449
+ projectV2(number: $number) {
450
+ id
451
+ title
452
+ url
453
+ views(first: 20) {
454
+ nodes { id number name layout filter }
455
+ }
456
+ fields(first: 30) {
457
+ nodes {
458
+ ... on ProjectV2FieldCommon { id name dataType }
459
+ ... on ProjectV2SingleSelectField {
460
+ id name dataType
461
+ options { id name color description }
462
+ }
463
+ }
464
+ }
465
+ items(first: 100, after: $cursor) {
466
+ pageInfo { hasNextPage endCursor }
467
+ nodes {
468
+ id
469
+ fieldValues(first: 20) {
470
+ nodes {
471
+ ... on ProjectV2ItemFieldSingleSelectValue {
472
+ name
473
+ field { ... on ProjectV2FieldCommon { name } }
474
+ }
475
+ }
476
+ }
477
+ content {
478
+ ... on Issue {
479
+ number title state url
480
+ repository { nameWithOwner }
481
+ assignees(first: 10) { nodes { login } }
482
+ labels(first: 10) { nodes { name } }
483
+ }
484
+ ... on PullRequest {
485
+ number title state merged url
486
+ repository { nameWithOwner }
487
+ assignees(first: 10) { nodes { login } }
488
+ labels(first: 10) { nodes { name } }
489
+ }
490
+ ... on DraftIssue { title }
491
+ }
492
+ }
493
+ }
494
+ }
495
+ }
496
+ }`;
497
+ const items = [];
498
+ let cursor = null;
499
+ let projectId = null;
500
+ let title = null;
501
+ let url = null;
502
+ let views = [];
503
+ let fields = [];
504
+ try {
505
+ while (true) {
506
+ const data = ghGraphqlSafe(query, {
507
+ owner: projectRef.owner,
508
+ number: projectRef.number,
509
+ cursor,
510
+ });
511
+ const ownerObj = data[ownerField] ?? {};
512
+ const proj = ownerObj.projectV2;
513
+ if (!proj) {
514
+ return { available: false, gap: `Project ${projectRef.owner}/${projectRef.number} not found` };
515
+ }
516
+ projectId = proj.id ?? null;
517
+ title = proj.title ?? null;
518
+ url = typeof proj.url === 'string' ? proj.url : null;
519
+ views = (proj.views?.nodes ?? []);
520
+ fields = (proj.fields?.nodes ?? []);
521
+ const page = proj.items ?? {};
522
+ for (const node of page.nodes ?? []) {
523
+ if (node !== null && typeof node === 'object') {
524
+ items.push(extractBoardItem(node));
525
+ }
526
+ }
527
+ const pageInfo = page.pageInfo ?? {};
528
+ if (!pageInfo.hasNextPage || typeof pageInfo.endCursor !== 'string' || !pageInfo.endCursor) {
529
+ break;
530
+ }
531
+ cursor = pageInfo.endCursor;
532
+ }
533
+ }
534
+ catch (error) {
535
+ const msg = error instanceof Error ? error.message : String(error);
536
+ return { available: false, gap: `GitHub Project error: ${msg}` };
537
+ }
538
+ let targetView = null;
539
+ let viewName = null;
540
+ if (projectRef.view !== null) {
541
+ for (const v of views) {
542
+ if (v.number === projectRef.view) {
543
+ targetView = v;
544
+ viewName = typeof v.name === 'string' ? v.name : null;
545
+ break;
546
+ }
547
+ }
548
+ if (url) {
549
+ url = `${url.replace(/\/+$/, '')}/views/${projectRef.view}`;
550
+ }
551
+ }
552
+ return {
553
+ available: true,
554
+ project_id: projectId,
555
+ title,
556
+ url,
557
+ view: projectRef.view,
558
+ view_name: viewName,
559
+ target_view: targetView,
560
+ fields,
561
+ items,
562
+ };
563
+ }
564
+ export function collectTeamMembers(org, usersArg) {
565
+ if (usersArg) {
566
+ return usersArg.split(',').map((u) => u.trim()).filter(Boolean);
567
+ }
568
+ if (!org)
569
+ return [];
570
+ try {
571
+ const members = ghApiJsonSafe(`orgs/${org}/members?per_page=100`);
572
+ if (!Array.isArray(members))
573
+ return [];
574
+ return members
575
+ .filter((m) => m !== null && typeof m === 'object' && typeof m.login === 'string')
576
+ .map((m) => m.login);
577
+ }
578
+ catch {
579
+ return [];
580
+ }
581
+ }
582
+ export function collectTeamRecaps(members, targetRepo, allRepos, sinceDt, cachedGh) {
583
+ const memberReports = [];
584
+ const combinedItems = [];
585
+ const cachedUser = cachedGh && cachedGh.available && typeof cachedGh.user === 'string' ? cachedGh.user : null;
586
+ for (const login of members) {
587
+ const gh = cachedUser && login === cachedUser
588
+ ? cachedGh
589
+ : collectGithub(targetRepo, allRepos, sinceDt, login);
590
+ if (!gh.available) {
591
+ memberReports.push({ user: login, available: false, gap: gh.gap ?? 'unavailable' });
592
+ continue;
593
+ }
594
+ const created = gh.issues_created ?? [];
595
+ const closed = gh.issues_closed ?? [];
596
+ const opened = gh.prs_opened ?? [];
597
+ const merged = gh.prs_merged ?? [];
598
+ const inProg = gh.prs_in_progress ?? [];
599
+ memberReports.push({
600
+ user: login,
601
+ available: true,
602
+ issues_created: created.length,
603
+ issues_closed: closed.length,
604
+ prs_opened: opened.length,
605
+ prs_merged: merged.length,
606
+ prs_open_updated: inProg.length,
607
+ reviews_and_comments: Number(gh.reviews_and_comments ?? 0),
608
+ gaps: gh.gaps ?? [],
609
+ });
610
+ combinedItems.push(...created);
611
+ combinedItems.push(...closed.map((it) => ({ ...it, state: it.state ?? 'closed' })));
612
+ combinedItems.push(...inProg.map((pr) => ({ ...pr, is_pr: true })));
613
+ for (const pr of opened) {
614
+ if (pr.state === 'open') {
615
+ combinedItems.push({ ...pr, is_pr: true });
616
+ }
617
+ }
618
+ }
619
+ return [memberReports, combinedItems];
620
+ }
@@ -0,0 +1,2 @@
1
+ export declare function computeRecap(payload: Record<string, unknown>): Record<string, unknown>;
2
+ export declare function formatHud(report: Record<string, unknown>, lang?: string): string;