@phnx-labs/agents-cli 1.23.20 → 1.23.21
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.23.21
|
|
4
|
+
|
|
5
|
+
- **`agents projects prs` reads open PRs in one GraphQL query per repository or owner.**
|
|
6
|
+
The project read and the all-orgs read behind AGI Menu's GitHub tab used to read each
|
|
7
|
+
open PR three more times (`pulls/{n}`, check-runs, status), one `gh` process per call.
|
|
8
|
+
Each page of 100 PRs now carries the head, merge state and check rollup for 2 GraphQL
|
|
9
|
+
points. Measured on one Mac with 1.23.19: a 101-PR project read took 43.8 s, 20.7
|
|
10
|
+
CPU-seconds and 304 `gh` processes; the all-orgs read of 201 PRs took 76.6 s, 32.0
|
|
11
|
+
CPU-seconds and 527 processes. The JSON fields and the newest-first order are
|
|
12
|
+
unchanged. One tradeoff: if the shared GraphQL budget is exhausted, a repository's
|
|
13
|
+
list fails (`error`, `partial`) instead of showing PRs without CI. Source: `cli/src/lib/github/project-prs.ts`,
|
|
14
|
+
`cli/src/lib/github/open-prs.ts`.
|
|
15
|
+
|
|
16
|
+
- **AGI Menu 1.18.1.** The menubar floor moves to 1.18.1: Home's pull requests and the GitHub tab draw their last list at once after a relaunch, the menu-bar badge is redrawn only when it changes, and the snapshot poll runs every 15 minutes while the menu is closed. Source: `cli/src/lib/helper-versions.ts`.
|
|
17
|
+
|
|
3
18
|
## 1.23.20
|
|
4
19
|
|
|
5
20
|
- **Balanced and available rotation never pick an API-key account (owner decision 2026-10-12).**
|
|
@@ -30,8 +30,6 @@ export interface OpenPrsOptions {
|
|
|
30
30
|
owners?: string[];
|
|
31
31
|
repo?: string;
|
|
32
32
|
number?: number;
|
|
33
|
-
cacheDir?: string;
|
|
34
|
-
nowMs?: number;
|
|
35
33
|
}
|
|
36
34
|
export declare const SEARCH_RESULT_CAP = 1000;
|
|
37
35
|
export declare function listViewerOwners(viewer: string | null, gh?: GhExec): Promise<string[]>;
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { ghExec, canonicalizeRepo, projectRepoSlugs } from './pr-mergeable.js';
|
|
2
|
-
import { CiErrors,
|
|
3
|
-
import { getCacheDir } from '../state.js';
|
|
2
|
+
import { CiErrors, PR_NODE_FIELDS, enrichPr, fetchOnePr, fetchViewer, ghFailure, prFromNode, readRepoMergeAbility, } from './project-prs.js';
|
|
4
3
|
const NEEDS_ME_RANK = { review: 0, failing: 1, conflicts: 2 };
|
|
5
4
|
export const SEARCH_RESULT_CAP = 1000;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
5
|
+
const SEARCH_QUERY = `query($q: String!, $endCursor: String) {
|
|
6
|
+
search(query: $q, type: ISSUE, first: 100, after: $endCursor) {
|
|
7
|
+
pageInfo { hasNextPage endCursor }
|
|
8
|
+
nodes { ... on PullRequest { ${PR_NODE_FIELDS} } }
|
|
9
|
+
}
|
|
10
|
+
}`;
|
|
13
11
|
async function searchOpenPrs(qualifier, gh) {
|
|
14
|
-
const q = encodeURIComponent(`is:pr is:open archived:false ${qualifier}`);
|
|
15
12
|
const out = await gh([
|
|
16
|
-
'api',
|
|
13
|
+
'api', 'graphql', '--paginate',
|
|
14
|
+
'-f', `q=is:pr is:open archived:false sort:updated-desc ${qualifier}`, '-f', `query=${SEARCH_QUERY}`,
|
|
15
|
+
'--jq', '.data.search.nodes[] | select(.number)',
|
|
17
16
|
]);
|
|
18
|
-
return
|
|
17
|
+
return out.split('\n').filter((l) => l.trim()).map((l) => prFromNode(JSON.parse(l)));
|
|
19
18
|
}
|
|
20
19
|
export async function listViewerOwners(viewer, gh = ghExec) {
|
|
21
20
|
const orgs = (await gh(['api', 'user/orgs', '--paginate', '--cache', '1h', '--jq', '.[].login']))
|
|
@@ -113,39 +112,22 @@ export async function buildOpenPrs(defs, opts = {}, gh = ghExec) {
|
|
|
113
112
|
prs.set(pr.number, pr);
|
|
114
113
|
bySlug.set(slug, prs);
|
|
115
114
|
}
|
|
116
|
-
const cacheDir = opts.cacheDir ?? getCacheDir();
|
|
117
|
-
const rollups = new KeyedCache(cacheDir, 'project-pr-ci.json', '@', isCachedRollup);
|
|
118
|
-
const nowMs = opts.nowMs ?? Date.now();
|
|
119
115
|
const projects = await projectMap;
|
|
120
|
-
const
|
|
121
|
-
for (const slug of bySlug.keys())
|
|
122
|
-
readers.set(slug, { slug, gh, rollups, errors: new CiErrors(), nowMs, reads: new Map() });
|
|
116
|
+
const errors = new Map([...bySlug.keys()].map((slug) => [slug, new CiErrors()]));
|
|
123
117
|
const merges = new Map([...bySlug.keys()].map((slug) => [slug, readRepoMergeAbility(slug, gh).catch((err) => {
|
|
124
|
-
|
|
118
|
+
errors.get(slug).record(err);
|
|
125
119
|
return null;
|
|
126
120
|
})]));
|
|
127
|
-
const listed = [...bySlug].flatMap(([slug, prs]) => [...prs.values()].map((pr) => ({ slug, pr })));
|
|
128
|
-
const read = await mapBounded(listed, 8, async ({ slug, pr: row }) => {
|
|
129
|
-
const ci = readers.get(slug);
|
|
130
|
-
let pr = row;
|
|
131
|
-
try {
|
|
132
|
-
pr = await fetchOnePr(slug, row.number, gh, '60s');
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
ci.errors.record(err);
|
|
136
|
-
}
|
|
137
|
-
const ciSummary = await readCi(ci, pr.headSha || null);
|
|
138
|
-
return { slug, pr: withNeeds({ ...pr, ...ciSummary }, viewer, requested.has(key(slug, pr.number))) };
|
|
139
|
-
});
|
|
140
121
|
const repositories = await Promise.all([...bySlug.keys()].map(async (slug) => ({
|
|
141
122
|
slug,
|
|
142
123
|
projects: projects.get(slug.toLowerCase()) ?? [],
|
|
143
124
|
merge: await merges.get(slug),
|
|
144
|
-
pullRequests:
|
|
145
|
-
|
|
125
|
+
pullRequests: [...bySlug.get(slug).values()]
|
|
126
|
+
.map((pr) => withNeeds(pr, viewer, requested.has(key(slug, pr.number))))
|
|
127
|
+
.sort(compareOpenPrs),
|
|
128
|
+
ciError: errors.get(slug).message,
|
|
146
129
|
})));
|
|
147
130
|
repositories.sort(compareRepos);
|
|
148
|
-
rollups.save();
|
|
149
131
|
const owners = ownerReads.map((r) => r.owner);
|
|
150
132
|
return {
|
|
151
133
|
viewer,
|
|
@@ -94,6 +94,11 @@ export interface ProjectPrsOptions {
|
|
|
94
94
|
number?: number;
|
|
95
95
|
}
|
|
96
96
|
export declare function rowToProjectPr(row: Record<string, unknown>): ProjectPr;
|
|
97
|
+
export declare const PR_NODE_FIELDS = "\n number title url isDraft state createdAt updatedAt body\n author { __typename login avatarUrl }\n repository { nameWithOwner }\n headRefName baseRefName headRefOid mergeable mergeStateStatus\n autoMergeRequest { enabledBy { login } mergeMethod }\n commits(last: 1) { nodes { commit { statusCheckRollup { state contexts(first: 100) { pageInfo { hasNextPage } nodes {\n __typename\n ... on CheckRun { name status conclusion detailsUrl }\n ... on StatusContext { context state targetUrl }\n } } } } } }";
|
|
98
|
+
export declare function prFromNode(node: Record<string, unknown>): {
|
|
99
|
+
slug: string;
|
|
100
|
+
pr: ProjectPr;
|
|
101
|
+
};
|
|
97
102
|
export declare function listOpenPrs(repo: string, gh?: GhExec): Promise<ProjectPr[]>;
|
|
98
103
|
export declare function fetchOnePr(repo: string, number: number, gh?: GhExec, cache?: string): Promise<ProjectPr>;
|
|
99
104
|
export declare function fetchReviewAndHead(repo: string, number: number, gh?: GhExec): Promise<{
|
|
@@ -50,16 +50,75 @@ export function rowToProjectPr(row) {
|
|
|
50
50
|
: null,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
+
export const PR_NODE_FIELDS = `
|
|
54
|
+
number title url isDraft state createdAt updatedAt body
|
|
55
|
+
author { __typename login avatarUrl }
|
|
56
|
+
repository { nameWithOwner }
|
|
57
|
+
headRefName baseRefName headRefOid mergeable mergeStateStatus
|
|
58
|
+
autoMergeRequest { enabledBy { login } mergeMethod }
|
|
59
|
+
commits(last: 1) { nodes { commit { statusCheckRollup { state contexts(first: 100) { pageInfo { hasNextPage } nodes {
|
|
60
|
+
__typename
|
|
61
|
+
... on CheckRun { name status conclusion detailsUrl }
|
|
62
|
+
... on StatusContext { context state targetUrl }
|
|
63
|
+
} } } } } }`;
|
|
64
|
+
const OPEN_PRS_QUERY = `query($owner: String!, $name: String!, $endCursor: String) {
|
|
65
|
+
repository(owner: $owner, name: $name) {
|
|
66
|
+
pullRequests(states: OPEN, first: 100, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}) {
|
|
67
|
+
pageInfo { hasNextPage endCursor }
|
|
68
|
+
nodes { ${PR_NODE_FIELDS} }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}`;
|
|
72
|
+
const MERGEABLE = { MERGEABLE: true, CONFLICTING: false };
|
|
73
|
+
function rollupFromContexts(contexts) {
|
|
74
|
+
const byName = new Map();
|
|
75
|
+
for (const c of contexts) {
|
|
76
|
+
if (c.__typename !== 'StatusContext')
|
|
77
|
+
continue;
|
|
78
|
+
const name = String(c.context ?? '');
|
|
79
|
+
if (!byName.has(name))
|
|
80
|
+
byName.set(name, { name, state: String(c.state ?? ''), link: String(c.targetUrl ?? '') });
|
|
81
|
+
}
|
|
82
|
+
for (const c of contexts) {
|
|
83
|
+
if (c.__typename !== 'CheckRun')
|
|
84
|
+
continue;
|
|
85
|
+
const name = String(c.name ?? '');
|
|
86
|
+
byName.set(name, { name, status: String(c.status ?? ''), conclusion: String(c.conclusion ?? ''), link: String(c.detailsUrl ?? '') });
|
|
87
|
+
}
|
|
88
|
+
return [...byName.values()];
|
|
89
|
+
}
|
|
90
|
+
export function prFromNode(node) {
|
|
91
|
+
const rec = (v) => (isRecord(v) ? v : {});
|
|
92
|
+
const author = rec(node.author);
|
|
93
|
+
const auto = isRecord(node.autoMergeRequest) ? node.autoMergeRequest : null;
|
|
94
|
+
const commits = rec(node.commits).nodes;
|
|
95
|
+
const commit = rec(rec(Array.isArray(commits) ? commits[0] : null).commit);
|
|
96
|
+
const rollup = rec(commit.statusCheckRollup);
|
|
97
|
+
const contexts = rec(rollup.contexts).nodes;
|
|
98
|
+
const truncated = rec(rec(rollup.contexts).pageInfo).hasNextPage === true;
|
|
99
|
+
const pr = rowToProjectPr({
|
|
100
|
+
...node,
|
|
101
|
+
login: `${author.login ?? ''}${author.__typename === 'Bot' ? '[bot]' : ''}`,
|
|
102
|
+
avatarUrl: author.avatarUrl ?? '',
|
|
103
|
+
headSha: node.headRefOid ?? '',
|
|
104
|
+
mergeable: MERGEABLE[String(node.mergeable)] ?? null,
|
|
105
|
+
mergeableState: typeof node.mergeStateStatus === 'string' ? node.mergeStateStatus.toLowerCase() : null,
|
|
106
|
+
autoMerge: auto ? { enabledBy: rec(auto.enabledBy).login ?? '', method: String(auto.mergeMethod ?? '').toLowerCase() } : null,
|
|
107
|
+
});
|
|
108
|
+
const items = rollupFromContexts(Array.isArray(contexts) ? contexts.filter(isRecord) : []);
|
|
109
|
+
const ci = { ...ciFromRollupItems(items) };
|
|
110
|
+
if (truncated && typeof rollup.state === 'string')
|
|
111
|
+
ci.ciState = rollup.state;
|
|
112
|
+
return { slug: String(rec(node.repository).nameWithOwner ?? ''), pr: { ...pr, ...ci } };
|
|
113
|
+
}
|
|
53
114
|
export async function listOpenPrs(repo, gh = ghExec) {
|
|
115
|
+
const [owner, name] = repo.split('/');
|
|
54
116
|
const out = await gh([
|
|
55
|
-
'api',
|
|
56
|
-
`
|
|
57
|
-
'--
|
|
58
|
-
'--cache', '60s',
|
|
59
|
-
'--jq',
|
|
60
|
-
`.[] | ${PR_JQ}`,
|
|
117
|
+
'api', 'graphql', '--paginate',
|
|
118
|
+
'-f', `owner=${owner}`, '-f', `name=${name}`, '-f', `query=${OPEN_PRS_QUERY}`,
|
|
119
|
+
'--jq', '.data.repository.pullRequests.nodes[]',
|
|
61
120
|
]);
|
|
62
|
-
return parseNdjson(out).map(
|
|
121
|
+
return parseNdjson(out).map((node) => prFromNode(node).pr);
|
|
63
122
|
}
|
|
64
123
|
export async function fetchOnePr(repo, number, gh = ghExec, cache) {
|
|
65
124
|
const out = await gh(['api', `repos/${repo}/pulls/${number}`, ...(cache ? ['--cache', cache] : []), '--jq', PR_JQ]);
|
|
@@ -270,16 +329,6 @@ export async function listRecentlyMerged(repo, sinceMs, gh = ghExec) {
|
|
|
270
329
|
}));
|
|
271
330
|
return { merged, truncated };
|
|
272
331
|
}
|
|
273
|
-
async function readMergeState(slug, number, gh, errors) {
|
|
274
|
-
try {
|
|
275
|
-
const { mergeable, mergeableState } = await fetchOnePr(slug, number, gh, '60s');
|
|
276
|
-
return { mergeable, mergeableState };
|
|
277
|
-
}
|
|
278
|
-
catch (err) {
|
|
279
|
-
errors.record(err);
|
|
280
|
-
return {};
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
332
|
async function readMergedDetail(slug, number, gh, details, errors) {
|
|
284
333
|
const hit = details.get(slug, number);
|
|
285
334
|
if (hit)
|
|
@@ -463,20 +512,13 @@ export async function buildProjectPrs(def, opts = {}, gh = ghExec, peers = [], c
|
|
|
463
512
|
? withMergesSince(tag, mergedListed ? merged.map((m) => m.pr) : null, { sinceMs, truncated: mergedRead?.truncated ?? false, base: defaultBranch?.name ?? null })
|
|
464
513
|
: null;
|
|
465
514
|
merged = merged.slice(0, MERGED_LIMIT);
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
readMergedDetail(slug, m.pr.number, gh, details, errors),
|
|
474
|
-
readCi(ci, m.pr.mergeCommitSha),
|
|
475
|
-
]);
|
|
476
|
-
return { ...m.pr, ...(detail ?? {}), ...mergeCi };
|
|
477
|
-
}),
|
|
478
|
-
]);
|
|
479
|
-
pullRequests = pullRequests.map((pr, i) => ({ ...pr, ...openCi[i] }));
|
|
515
|
+
const recentlyMerged = await mapBounded(merged, 8, async (m) => {
|
|
516
|
+
const [detail, mergeCi] = await Promise.all([
|
|
517
|
+
readMergedDetail(slug, m.pr.number, gh, details, errors),
|
|
518
|
+
readCi(ci, m.pr.mergeCommitSha),
|
|
519
|
+
]);
|
|
520
|
+
return { ...m.pr, ...(detail ?? {}), ...mergeCi };
|
|
521
|
+
});
|
|
480
522
|
const { merge, error: mergeError } = await mergeRead;
|
|
481
523
|
if (mergeError !== null)
|
|
482
524
|
errors.record(mergeError);
|
|
@@ -484,7 +526,6 @@ export async function buildProjectPrs(def, opts = {}, gh = ghExec, peers = [], c
|
|
|
484
526
|
details.prune(slug, new Set(mergedListed.map((m) => String(m.pr.number))));
|
|
485
527
|
if (defaultBranch) {
|
|
486
528
|
rollups.prune(slug, new Set([
|
|
487
|
-
...listed.map((pr) => pr.headSha),
|
|
488
529
|
...mergedListed.flatMap((m) => (m.pr.mergeCommitSha ? [m.pr.mergeCommitSha] : [])),
|
|
489
530
|
defaultBranch.sha,
|
|
490
531
|
]));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phnx-labs/agents-cli",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.21",
|
|
4
4
|
"description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|