@hearsay-tools/squawk 0.18.0-dev.5842 → 0.18.0-dev.5845
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/automations/automation-cli.js +5 -0
- package/dist/automations/automation-cli.js.map +1 -1
- package/dist/automations/github-baseline.js +2 -0
- package/dist/automations/github-baseline.js.map +1 -1
- package/dist/automations/github-repository.d.ts +22 -0
- package/dist/automations/github-repository.js +40 -0
- package/dist/automations/github-repository.js.map +1 -0
- package/dist/automations/scheduler.d.ts +2 -3
- package/dist/automations/scheduler.js +31 -11
- package/dist/automations/scheduler.js.map +1 -1
- package/dist/automations/service.d.ts +4 -0
- package/dist/automations/task-template.js +12 -2
- package/dist/automations/task-template.js.map +1 -1
- package/dist/ci-wait/controller.d.ts +4 -4
- package/dist/ci-wait/tools.d.ts +4 -4
- package/dist/contract/automation-storage.d.ts +4 -0
- package/dist/contract/automations.d.ts +26 -0
- package/dist/contract/index.js +22 -0
- package/dist/delegation/routes.d.ts +13 -13
- package/dist/delegation/transport.d.ts +71 -71
- package/dist/server/forge/github-cli.d.ts +14 -0
- package/dist/server/forge/github-cli.js +25 -0
- package/dist/server/forge/github-cli.js.map +1 -0
- package/dist/server/forge/github-repo-handle.d.ts +42 -0
- package/dist/server/forge/github-repo-handle.js +160 -0
- package/dist/server/forge/github-repo-handle.js.map +1 -0
- package/dist/server/forge/github.d.ts +11 -17
- package/dist/server/forge/github.js +22 -139
- package/dist/server/forge/github.js.map +1 -1
- package/dist/server/live-routes.d.ts +6 -6
- package/dist/server/server.d.ts +1640 -1632
- package/dist/server/server.js +7 -11
- package/dist/server/server.js.map +1 -1
- package/dist/voice/routes.d.ts +19 -19
- package/dist/workflows/run/wait-engine.d.ts +72 -72
- package/package.json +4 -4
- package/web/dist/assets/{activity-motion-2nE59DAT.js → activity-motion-BdGFmrw-.js} +1 -1
- package/web/dist/assets/{activity-route-R9lPc2jy.js → activity-route-1OFUVP3A.js} +1 -1
- package/web/dist/assets/{commit-diff-panel-BJyNYmCY.js → commit-diff-panel-BiNPMHC6.js} +1 -1
- package/web/dist/assets/{diff-D_9MtICR.js → diff-BHwQUS2W.js} +2 -2
- package/web/dist/assets/{diff-view-xRPxXHXl.js → diff-view-BBhxSIlf.js} +1 -1
- package/web/dist/assets/{git-toolbar-D9taioU5.js → git-toolbar-BnOaO_OH.js} +1 -1
- package/web/dist/assets/{github-bv_pBGc5.js → github-CXc8nroh.js} +1 -1
- package/web/dist/assets/{global-activity-route-QxTPDyx-.js → global-activity-route-Dt83uvZc.js} +1 -1
- package/web/dist/assets/{index-DgU3yYUl.js → index-B5LayM4y.js} +6 -6
- package/web/dist/assets/{preview-pane-connected-cD-MTiVN.js → preview-pane-connected-JHeCgq7I.js} +1 -1
- package/web/dist/assets/{repo-git-E_4Ighvg.js → repo-git-wEXDON29.js} +1 -1
- package/web/dist/assets/{report-reader-XVNQsXB4.js → report-reader-DJ_0htSx.js} +1 -1
- package/web/dist/assets/{reports-B_PVTBzP.js → reports-BIXmTBFJ.js} +1 -1
- package/web/dist/assets/{run-header-wm0gSs6X.js → run-header-Bgtlx-vc.js} +1 -1
- package/web/dist/assets/{skills-D2RLxUIc.js → skills-BJ2nSfyr.js} +1 -1
- package/web/dist/assets/{task-changes-DNtkfFzQ.js → task-changes-Dz0udwrE.js} +1 -1
- package/web/dist/assets/{task-commits-CivO-OrN.js → task-commits-5uILgm5M.js} +1 -1
- package/web/dist/assets/{task-files-dczkxV_G.js → task-files-DGZjTKSS.js} +1 -1
- package/web/dist/assets/{task-github-item-DKV4yrcf.js → task-github-item-npfGLu9C.js} +1 -1
- package/web/dist/assets/{task-thread-DIaTTGEF.js → task-thread-DnpkXb5P.js} +1 -1
- package/web/dist/assets/{thread-state-DIozHuHb.js → thread-state-BfrO2t7g.js} +1 -1
- package/web/dist/assets/{use-hand-to-agent-state-D58ayxI4.js → use-hand-to-agent-state-DyVB4IBv.js} +1 -1
- package/web/dist/assets/{workflows-YMEsGXeB.js → workflows-ByduCwgu.js} +1 -1
- package/web/dist/index.html +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { productEnv } from '../../core/product-env.js';
|
|
2
|
+
import { gh, githubContext, parseOwnerName } from './github-cli.js';
|
|
3
|
+
const repoHandleCache = new Map();
|
|
4
|
+
const repoDiscoveryFlights = new Map();
|
|
5
|
+
/** Each subscriber owns a lease, not the subprocess. Only the last cancellation aborts it.
|
|
6
|
+
* Keep the rejecting promise intact so strict callers retain gh's diagnostic. */
|
|
7
|
+
export function sharedRepoHandle(repoRoot, signal, context = githubContext(repoRoot)) {
|
|
8
|
+
if (signal?.aborted)
|
|
9
|
+
return Promise.reject(signal.reason);
|
|
10
|
+
const memo = repoHandleCache.get(context.key);
|
|
11
|
+
if (memo !== undefined)
|
|
12
|
+
return Promise.resolve(memo);
|
|
13
|
+
let flight = repoDiscoveryFlights.get(context.key);
|
|
14
|
+
if (!flight) {
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
const created = {
|
|
17
|
+
controller, owners: 0,
|
|
18
|
+
promise: gh(repoRoot, ['repo', 'view', '--json', 'nameWithOwner', '--jq', '.nameWithOwner'], 15_000, controller.signal, context)
|
|
19
|
+
.then(parseOwnerName),
|
|
20
|
+
};
|
|
21
|
+
created.promise = created.promise.then(handle => {
|
|
22
|
+
// A disposed owner may complete late; it must not overwrite a replacement discovery.
|
|
23
|
+
if (!controller.signal.aborted && repoDiscoveryFlights.get(context.key) === created) {
|
|
24
|
+
repoHandleCache.set(context.key, handle);
|
|
25
|
+
}
|
|
26
|
+
return handle;
|
|
27
|
+
}).finally(() => {
|
|
28
|
+
if (repoDiscoveryFlights.get(context.key) === created)
|
|
29
|
+
repoDiscoveryFlights.delete(context.key);
|
|
30
|
+
});
|
|
31
|
+
flight = created;
|
|
32
|
+
repoDiscoveryFlights.set(context.key, flight);
|
|
33
|
+
}
|
|
34
|
+
const owned = flight;
|
|
35
|
+
owned.owners++;
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
let released = false;
|
|
38
|
+
const release = () => {
|
|
39
|
+
if (released)
|
|
40
|
+
return false;
|
|
41
|
+
released = true;
|
|
42
|
+
signal?.removeEventListener('abort', cancel);
|
|
43
|
+
if (--owned.owners === 0 && repoDiscoveryFlights.get(context.key) === owned) {
|
|
44
|
+
repoDiscoveryFlights.delete(context.key);
|
|
45
|
+
owned.controller.abort();
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
const cancel = () => { if (release())
|
|
50
|
+
reject(signal?.reason); };
|
|
51
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
52
|
+
owned.promise.then(handle => { if (release())
|
|
53
|
+
resolve(handle); }, error => { if (release())
|
|
54
|
+
reject(error); });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Test-only: drop the memoized repo handles. */
|
|
58
|
+
export function __clearRepoHandleCacheForTests() {
|
|
59
|
+
repoHandleCache.clear();
|
|
60
|
+
canonicalNames.clear();
|
|
61
|
+
for (const flight of repoDiscoveryFlights.values())
|
|
62
|
+
flight.controller.abort();
|
|
63
|
+
repoDiscoveryFlights.clear();
|
|
64
|
+
}
|
|
65
|
+
/** Drop this root's memoized names after a read that named them failed or was redirected: the
|
|
66
|
+
* repository may have been renamed since, and the next lookup asks GitHub again. */
|
|
67
|
+
export function forgetRepoHandle(repoRoot) {
|
|
68
|
+
const { key } = githubContext(repoRoot);
|
|
69
|
+
repoHandleCache.delete(key);
|
|
70
|
+
for (const name of canonicalNames.keys())
|
|
71
|
+
if (name.startsWith(`${key}\n`))
|
|
72
|
+
canonicalNames.delete(name);
|
|
73
|
+
}
|
|
74
|
+
/** A GitHub answer that can mean the name is no longer the repository's. */
|
|
75
|
+
export function isRepositoryNameMiss(error) {
|
|
76
|
+
if (!(error instanceof Error))
|
|
77
|
+
return false;
|
|
78
|
+
const stderr = 'stderr' in error && typeof error.stderr === 'string' ? error.stderr : '';
|
|
79
|
+
return /HTTP 404|HTTP 422|Not Found|Validation Failed|Could not resolve to a Repository/i.test(`${error.message}\n${stderr}`);
|
|
80
|
+
}
|
|
81
|
+
/** Runs a read that names the repository; when GitHub no longer knows that name, the next read
|
|
82
|
+
* asks for the current one. The error still reaches the caller. */
|
|
83
|
+
export async function forgettingNameOnMiss(repoRoot, read) {
|
|
84
|
+
try {
|
|
85
|
+
return await read();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (isRepositoryNameMiss(error))
|
|
89
|
+
forgetRepoHandle(repoRoot);
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Local absence cannot improve through network retries. Authentication, timeouts and remote
|
|
94
|
+
* errors deliberately stay retryable, including 404s for temporarily inaccessible repositories. */
|
|
95
|
+
function isPermanentRepoFailure(error) {
|
|
96
|
+
if (!(error instanceof Error))
|
|
97
|
+
return false;
|
|
98
|
+
if ('code' in error && error.code === 'ENOENT')
|
|
99
|
+
return true;
|
|
100
|
+
const stderr = 'stderr' in error && typeof error.stderr === 'string' ? error.stderr : '';
|
|
101
|
+
return /not a git repository|no git remotes found|none of the git remotes configured for this repository point to a known GitHub host/i.test(`${error.message}\n${stderr}`);
|
|
102
|
+
}
|
|
103
|
+
/** Share the existing memo with ordinary discovery, but retain failure classification (#102).
|
|
104
|
+
* An aborted owner must never publish its late result into this shared cache. */
|
|
105
|
+
export async function discoverRepoHandle(repoRoot, signal) {
|
|
106
|
+
const context = githubContext(repoRoot);
|
|
107
|
+
if (signal?.aborted)
|
|
108
|
+
return { status: 'cancelled' };
|
|
109
|
+
try {
|
|
110
|
+
const handle = await sharedRepoHandle(repoRoot, signal, context);
|
|
111
|
+
if (signal?.aborted)
|
|
112
|
+
return { status: 'cancelled' };
|
|
113
|
+
return handle ? { status: 'resolved', handle } : { status: 'unknown' };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (signal?.aborted)
|
|
117
|
+
return { status: 'cancelled' };
|
|
118
|
+
if (isPermanentRepoFailure(error)) {
|
|
119
|
+
// Do not replace a successful discovery another caller completed while this one failed.
|
|
120
|
+
const recovered = repoHandleCache.get(context.key);
|
|
121
|
+
if (recovered)
|
|
122
|
+
return { status: 'resolved', handle: recovered };
|
|
123
|
+
// The live arming loop stops on unknown. Do not memoize local failures here: later cold
|
|
124
|
+
// index/status requests must still discover an installed gh or a newly added remote.
|
|
125
|
+
return { status: 'unknown' };
|
|
126
|
+
}
|
|
127
|
+
return { status: 'retryable' };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Compatible fail-open lookup for existing API and cold-index callers. */
|
|
131
|
+
export async function resolveRepoHandle(repoRoot, signal) {
|
|
132
|
+
const result = await discoverRepoHandle(repoRoot, signal);
|
|
133
|
+
return result.status === 'resolved' ? result.handle : null;
|
|
134
|
+
}
|
|
135
|
+
const canonicalNames = new Map();
|
|
136
|
+
/** The name to read `remote`'s repository under: GitHub's current name for that repository, or
|
|
137
|
+
* `remote` itself when `gh` cannot say. It names `remote` explicitly: an unqualified `gh repo
|
|
138
|
+
* view` follows gh's default repository, which in a fork checkout is `upstream`. Failures are not
|
|
139
|
+
* memoized. Null only without a remote. */
|
|
140
|
+
export async function canonicalRepoRef(repoRoot, remote) {
|
|
141
|
+
if (!remote || productEnv('DRY_RUN') === '1')
|
|
142
|
+
return remote;
|
|
143
|
+
const context = githubContext(repoRoot);
|
|
144
|
+
const key = `${context.key}\n${`${remote.owner}/${remote.repo}`.toLowerCase()}`;
|
|
145
|
+
const memo = canonicalNames.get(key);
|
|
146
|
+
if (memo)
|
|
147
|
+
return memo;
|
|
148
|
+
try {
|
|
149
|
+
const handle = parseOwnerName(await gh(repoRoot, ['repo', 'view', `github.com/${remote.owner}/${remote.repo}`, '--json', 'nameWithOwner', '--jq', '.nameWithOwner'], 15_000, undefined, context));
|
|
150
|
+
if (!handle)
|
|
151
|
+
return remote;
|
|
152
|
+
const ref = { owner: handle.owner, repo: handle.name };
|
|
153
|
+
canonicalNames.set(key, ref);
|
|
154
|
+
return ref;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return remote;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=github-repo-handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-repo-handle.js","sourceRoot":"","sources":["../../../src/server/forge/github-repo-handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAWpE,MAAM,eAAe,GAAG,IAAI,GAAG,EAAsB,CAAC;AAMtD,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAA+B,CAAC;AAEpE;iFACiF;AACjF,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,MAAoB,EAAE,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC;IACxG,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,MAAM,GAAG,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,OAAO,GAAwB;YACnC,UAAU,EAAE,MAAM,EAAE,CAAC;YACrB,OAAO,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAA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type { RepoHandleDiscovery } from './repo-handle-discovery.ts';
|
|
2
1
|
export type { RepoHandleDiscovery } from './repo-handle-discovery.ts';
|
|
3
2
|
export { createDraftPr, buildPrBody } from './draft-pr.ts';
|
|
4
3
|
import type { ArchivePullRequestIdentity, MergedPullRequest } from '../../contract/index.js';
|
|
5
4
|
import { z } from 'zod';
|
|
5
|
+
export { parseOwnerName } from './github-cli.ts';
|
|
6
|
+
export { __clearRepoHandleCacheForTests, discoverRepoHandle, forgetRepoHandle, resolveRepoHandle } from './github-repo-handle.ts';
|
|
6
7
|
import { type GithubCommentCountsData, type GithubItemResponse, type GithubProjectsData } from '../../contract/index.js';
|
|
7
8
|
export { normalizeMergeState } from './github-merge-state.ts';
|
|
8
9
|
export { fetchTimelinePages, ghTimelineEventSchema, normalizeEvents, TIMELINE_BUDGET_MS, TIMELINE_EVENT_CAP, TIMELINE_EVENT_KINDS, TIMELINE_MAX_PAGES, TIMELINE_MIN_PAGE_MS, } from './github-timeline.ts';
|
|
9
10
|
import type { ForgeAvailability, ForgeComment, ForgeCommentsData, ForgeDriver, ForgeItem, ForgeListOptions, ForgePrMergeState, ForgePrDiffResult, ForgeSearchData, ForgeTimelineEvent } from './types.ts';
|
|
11
|
+
/**
|
|
12
|
+
* The GitHub forge driver — all `gh`-CLI logic in one place, moved here from
|
|
13
|
+
* `src/server/github.ts` (tab listing) and `src/server/pr.ts` (draft PRs)
|
|
14
|
+
* behind the `ForgeDriver` seam. Those modules remain as thin delegates.
|
|
15
|
+
* `/api/github`'s response shape is this driver's serialization and is
|
|
16
|
+
* protected by BACKWARD_COMPATIBILITY.md — additive changes only.
|
|
17
|
+
*/
|
|
10
18
|
export declare const GH_PR_DIFF_FILE_CAP = 300;
|
|
11
19
|
export declare const GH_PR_PATCH_CAP: number;
|
|
12
20
|
export declare const GH_PR_DIFF_JSON_CAP: number;
|
|
@@ -40,11 +48,6 @@ export type GraphqlRunner = (query: string, variables: Record<string, string | n
|
|
|
40
48
|
* number goes through `-F`. A string never does: `-F` would read `@file` and coerce
|
|
41
49
|
* `true`/numerals, which is not what an opaque cursor or a login means. */
|
|
42
50
|
export declare function ghGraphqlArgs(query: string, variables?: Record<string, string | number>): string[];
|
|
43
|
-
/** `owner/name` → `{ owner, name }`, or null when the handle isn't a clean two-part slug. */
|
|
44
|
-
export declare function parseOwnerName(nameWithOwner: string): {
|
|
45
|
-
owner: string;
|
|
46
|
-
name: string;
|
|
47
|
-
} | null;
|
|
48
51
|
/** GitHub GraphQL rejects `first` above 100 (EXCESSIVE_PAGINATION); larger limits walk pages. */
|
|
49
52
|
export declare const GH_GRAPHQL_PAGE_MAX = 100;
|
|
50
53
|
export type ListSide = 'issues' | 'pullRequests';
|
|
@@ -143,16 +146,6 @@ export declare function forgetGithubItem(repoRoot: string, kind: 'issue' | 'pr',
|
|
|
143
146
|
/** Test-only: drop the single-item cache. */
|
|
144
147
|
export declare function __clearGithubItemCacheForTests(): void;
|
|
145
148
|
export declare function fetchGithubItem(repoRoot: string, kind: 'issue' | 'pr', number: number, refresh?: boolean): Promise<GithubItemResponse>;
|
|
146
|
-
/** Test-only: drop the memoized repo handles. */
|
|
147
|
-
export declare function __clearRepoHandleCacheForTests(): void;
|
|
148
|
-
/** Share the existing memo with ordinary discovery, but retain failure classification (#102).
|
|
149
|
-
* An aborted owner must never publish its late result into this shared cache. */
|
|
150
|
-
export declare function discoverRepoHandle(repoRoot: string, signal?: AbortSignal): Promise<RepoHandleDiscovery>;
|
|
151
|
-
/** Compatible fail-open lookup for existing API and cold-index callers. */
|
|
152
|
-
export declare function resolveRepoHandle(repoRoot: string, signal?: AbortSignal): Promise<{
|
|
153
|
-
owner: string;
|
|
154
|
-
name: string;
|
|
155
|
-
} | null>;
|
|
156
149
|
/** SHAs per rollup query. Aliases resolve independently, so a chunk that fails costs only its own
|
|
157
150
|
* glyphs — but an unbounded alias list would eventually blow the query size limit. */
|
|
158
151
|
export declare const COMMIT_CHECKS_CHUNK = 50;
|
|
@@ -382,7 +375,8 @@ export declare function fetchGithubComments(repoRoot: string, kind: 'issue' | 'p
|
|
|
382
375
|
export declare function detectGithubCached(repoRoot: string): ForgeAvailability | null;
|
|
383
376
|
export declare function evictGithubProjectCaches(repoRoot: string): void;
|
|
384
377
|
export declare function mergePreflightAllowed(current: ForgePrMergeState, overrideRules?: boolean): boolean;
|
|
385
|
-
/** owner/repo parsed out of the origin remote — feeds `viewUrl`.
|
|
378
|
+
/** owner/repo parsed out of the origin remote — feeds `viewUrl`. Reads that name the repository
|
|
379
|
+
* use `canonicalRepoRef` instead, which follows a rename. */
|
|
386
380
|
export interface GithubRepoRef {
|
|
387
381
|
owner: string;
|
|
388
382
|
repo: string;
|
|
@@ -6,9 +6,11 @@ import { activeWorkflowRunsArgs, parseActiveWorkflowRuns } from '../../ci-wait/g
|
|
|
6
6
|
import { pullRequestKey } from '../../runs/pull-requests.js';
|
|
7
7
|
import { matchesGithubPullRequest, mergedPullRequestObservations } from '../../merge-observations.js';
|
|
8
8
|
import { randomUUID } from 'node:crypto';
|
|
9
|
-
import { execFile } from 'node:child_process';
|
|
10
|
-
import { promisify } from 'node:util';
|
|
11
9
|
import { z } from 'zod';
|
|
10
|
+
import { gh, githubContext, parseOwnerName } from './github-cli.js';
|
|
11
|
+
import { canonicalRepoRef, discoverRepoHandle, forgetRepoHandle, forgettingNameOnMiss, resolveRepoHandle, sharedRepoHandle } from './github-repo-handle.js';
|
|
12
|
+
export { parseOwnerName } from './github-cli.js';
|
|
13
|
+
export { __clearRepoHandleCacheForTests, discoverRepoHandle, forgetRepoHandle, resolveRepoHandle } from './github-repo-handle.js';
|
|
12
14
|
import { GITHUB_COMMENT_COUNTS_MAX, GITHUB_SEARCH_MAX, REFERENCE_STATUS_MAX } from '../../contract/index.js';
|
|
13
15
|
import { fetchIssueProjects, fetchRepositoryProjects, fetchViewerLogin } from './github-filters.js';
|
|
14
16
|
import { fetchGithubMergeRequirements } from './github-merge-requirements.js';
|
|
@@ -24,7 +26,6 @@ import { refNumberFromUrl } from '../../contract/index.js';
|
|
|
24
26
|
* `/api/github`'s response shape is this driver's serialization and is
|
|
25
27
|
* protected by BACKWARD_COMPATIBILITY.md — additive changes only.
|
|
26
28
|
*/
|
|
27
|
-
const exec = promisify(execFile);
|
|
28
29
|
export const GH_PR_DIFF_FILE_CAP = 300;
|
|
29
30
|
export const GH_PR_PATCH_CAP = 512 * 1024;
|
|
30
31
|
export const GH_PR_DIFF_JSON_CAP = 4 * 1024 * 1024;
|
|
@@ -193,22 +194,6 @@ export function rollupToChecks(rollup) {
|
|
|
193
194
|
return 'pending';
|
|
194
195
|
return 'passing';
|
|
195
196
|
}
|
|
196
|
-
// Keep account-directory and host selection attached to shared work. Never key by owner/name:
|
|
197
|
-
// separate local roots (including different remotes/accounts) must not share results.
|
|
198
|
-
function githubContext(repoRoot) {
|
|
199
|
-
const env = { GH_HOST: process.env.GH_HOST, GH_CONFIG_DIR: process.env.GH_CONFIG_DIR };
|
|
200
|
-
return { key: JSON.stringify([repoRoot, env.GH_HOST, env.GH_CONFIG_DIR]), env };
|
|
201
|
-
}
|
|
202
|
-
async function gh(repoRoot, args, timeout = 15_000, signal, context) {
|
|
203
|
-
const { stdout } = await exec('gh', args, {
|
|
204
|
-
cwd: repoRoot,
|
|
205
|
-
...(context ? { env: { ...process.env, ...context.env } } : {}),
|
|
206
|
-
timeout,
|
|
207
|
-
maxBuffer: 50 * 1024 * 1024,
|
|
208
|
-
...(signal ? { signal } : {}),
|
|
209
|
-
});
|
|
210
|
-
return stdout;
|
|
211
|
-
}
|
|
212
197
|
/** `gh api graphql` argv. `-f` sends every value as a String, and GitHub rejects a String where
|
|
213
198
|
* the query declares `Int!` ("Could not coerce value to Int", open-mercato/cezar#1366), so a
|
|
214
199
|
* number goes through `-F`. A string never does: `-F` would read `@file` and coerce
|
|
@@ -220,11 +205,6 @@ export function ghGraphqlArgs(query, variables = {}) {
|
|
|
220
205
|
}
|
|
221
206
|
return args;
|
|
222
207
|
}
|
|
223
|
-
/** `owner/name` → `{ owner, name }`, or null when the handle isn't a clean two-part slug. */
|
|
224
|
-
export function parseOwnerName(nameWithOwner) {
|
|
225
|
-
const [owner, name, ...rest] = nameWithOwner.trim().split('/');
|
|
226
|
-
return owner && name && rest.length === 0 ? { owner, name } : null;
|
|
227
|
-
}
|
|
228
208
|
// Paged open lists defer comment counts; hydrate them through the counts route after paint.
|
|
229
209
|
/** GitHub GraphQL rejects `first` above 100 (EXCESSIVE_PAGINATION); larger limits walk pages. */
|
|
230
210
|
export const GH_GRAPHQL_PAGE_MAX = 100;
|
|
@@ -497,7 +477,7 @@ async function loadGithubPage(repoRoot, context, capped, page, key, hit, order,
|
|
|
497
477
|
const ownerName = await resolveRepoHandleStrict(repoRoot, context);
|
|
498
478
|
if (!ownerName)
|
|
499
479
|
return { available: false, reason: 'Could not resolve this repository on GitHub.', issues: [], prs: [] };
|
|
500
|
-
const runGraphql = (query, variables) => gh(repoRoot, ghGraphqlArgs(query, variables), timeout, undefined, context);
|
|
480
|
+
const runGraphql = (query, variables) => forgettingNameOnMiss(repoRoot, () => gh(repoRoot, ghGraphqlArgs(query, variables), timeout, undefined, context));
|
|
501
481
|
const projectGraphql = githubProjectGraphql(repoRoot, context);
|
|
502
482
|
const firstPage = isFirstGithubPage(page);
|
|
503
483
|
const issueSide = fetchListConnection(runGraphql, ownerName.owner, ownerName.name, 'issues', capped, page.issuesCursor, page.issuesDone);
|
|
@@ -766,7 +746,7 @@ export async function searchGithubItems(repoRoot, kind, query, limit = GH_SEARCH
|
|
|
766
746
|
if (!handle) {
|
|
767
747
|
return { available: false, reason: 'no GitHub remote to search', items: [] };
|
|
768
748
|
}
|
|
769
|
-
const out = await gh(repoRoot, [
|
|
749
|
+
const out = await forgettingNameOnMiss(repoRoot, () => gh(repoRoot, [
|
|
770
750
|
'search',
|
|
771
751
|
kind === 'pr' ? 'prs' : 'issues',
|
|
772
752
|
'--repo',
|
|
@@ -781,7 +761,7 @@ export async function searchGithubItems(repoRoot, kind, query, limit = GH_SEARCH
|
|
|
781
761
|
// on the cockpit's host. Behind `--` it is search text, which is all the box ever means.
|
|
782
762
|
'--',
|
|
783
763
|
trimmed,
|
|
784
|
-
]);
|
|
764
|
+
]));
|
|
785
765
|
const hits = z.array(ghSearchHitSchema).parse(JSON.parse(out));
|
|
786
766
|
// Older gh/GHES search treats repeated repo qualifiers as OR. Never hydrate a foreign
|
|
787
767
|
// hit's number with this repository's memberships or expose it as a local detail row.
|
|
@@ -1043,109 +1023,6 @@ export async function fetchGithubItem(repoRoot, kind, number, refresh = false) {
|
|
|
1043
1023
|
};
|
|
1044
1024
|
}
|
|
1045
1025
|
}
|
|
1046
|
-
const repoHandleCache = new Map();
|
|
1047
|
-
const repoDiscoveryFlights = new Map();
|
|
1048
|
-
/** Each subscriber owns a lease, not the subprocess. Only the last cancellation aborts it.
|
|
1049
|
-
* Keep the rejecting promise intact so strict callers retain gh's diagnostic. */
|
|
1050
|
-
function sharedRepoHandle(repoRoot, signal, context = githubContext(repoRoot)) {
|
|
1051
|
-
if (signal?.aborted)
|
|
1052
|
-
return Promise.reject(signal.reason);
|
|
1053
|
-
const memo = repoHandleCache.get(context.key);
|
|
1054
|
-
if (memo !== undefined)
|
|
1055
|
-
return Promise.resolve(memo);
|
|
1056
|
-
let flight = repoDiscoveryFlights.get(context.key);
|
|
1057
|
-
if (!flight) {
|
|
1058
|
-
const controller = new AbortController();
|
|
1059
|
-
const created = {
|
|
1060
|
-
controller, owners: 0,
|
|
1061
|
-
promise: gh(repoRoot, ['repo', 'view', '--json', 'nameWithOwner', '--jq', '.nameWithOwner'], 15_000, controller.signal, context)
|
|
1062
|
-
.then(parseOwnerName),
|
|
1063
|
-
};
|
|
1064
|
-
created.promise = created.promise.then(handle => {
|
|
1065
|
-
// A disposed owner may complete late; it must not overwrite a replacement discovery.
|
|
1066
|
-
if (!controller.signal.aborted && repoDiscoveryFlights.get(context.key) === created) {
|
|
1067
|
-
repoHandleCache.set(context.key, handle);
|
|
1068
|
-
}
|
|
1069
|
-
return handle;
|
|
1070
|
-
}).finally(() => {
|
|
1071
|
-
if (repoDiscoveryFlights.get(context.key) === created)
|
|
1072
|
-
repoDiscoveryFlights.delete(context.key);
|
|
1073
|
-
});
|
|
1074
|
-
flight = created;
|
|
1075
|
-
repoDiscoveryFlights.set(context.key, flight);
|
|
1076
|
-
}
|
|
1077
|
-
const owned = flight;
|
|
1078
|
-
owned.owners++;
|
|
1079
|
-
return new Promise((resolve, reject) => {
|
|
1080
|
-
let released = false;
|
|
1081
|
-
const release = () => {
|
|
1082
|
-
if (released)
|
|
1083
|
-
return false;
|
|
1084
|
-
released = true;
|
|
1085
|
-
signal?.removeEventListener('abort', cancel);
|
|
1086
|
-
if (--owned.owners === 0 && repoDiscoveryFlights.get(context.key) === owned) {
|
|
1087
|
-
repoDiscoveryFlights.delete(context.key);
|
|
1088
|
-
owned.controller.abort();
|
|
1089
|
-
}
|
|
1090
|
-
return true;
|
|
1091
|
-
};
|
|
1092
|
-
const cancel = () => { if (release())
|
|
1093
|
-
reject(signal?.reason); };
|
|
1094
|
-
signal?.addEventListener('abort', cancel, { once: true });
|
|
1095
|
-
owned.promise.then(handle => { if (release())
|
|
1096
|
-
resolve(handle); }, error => { if (release())
|
|
1097
|
-
reject(error); });
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1100
|
-
/** Test-only: drop the memoized repo handles. */
|
|
1101
|
-
export function __clearRepoHandleCacheForTests() {
|
|
1102
|
-
repoHandleCache.clear();
|
|
1103
|
-
for (const flight of repoDiscoveryFlights.values())
|
|
1104
|
-
flight.controller.abort();
|
|
1105
|
-
repoDiscoveryFlights.clear();
|
|
1106
|
-
}
|
|
1107
|
-
/** Local absence cannot improve through network retries. Authentication, timeouts and remote
|
|
1108
|
-
* errors deliberately stay retryable, including 404s for temporarily inaccessible repositories. */
|
|
1109
|
-
function isPermanentRepoFailure(error) {
|
|
1110
|
-
if (!(error instanceof Error))
|
|
1111
|
-
return false;
|
|
1112
|
-
if ('code' in error && error.code === 'ENOENT')
|
|
1113
|
-
return true;
|
|
1114
|
-
const stderr = 'stderr' in error && typeof error.stderr === 'string' ? error.stderr : '';
|
|
1115
|
-
return /not a git repository|no git remotes found|none of the git remotes configured for this repository point to a known GitHub host/i.test(`${error.message}\n${stderr}`);
|
|
1116
|
-
}
|
|
1117
|
-
/** Share the existing memo with ordinary discovery, but retain failure classification (#102).
|
|
1118
|
-
* An aborted owner must never publish its late result into this shared cache. */
|
|
1119
|
-
export async function discoverRepoHandle(repoRoot, signal) {
|
|
1120
|
-
const context = githubContext(repoRoot);
|
|
1121
|
-
if (signal?.aborted)
|
|
1122
|
-
return { status: 'cancelled' };
|
|
1123
|
-
try {
|
|
1124
|
-
const handle = await sharedRepoHandle(repoRoot, signal, context);
|
|
1125
|
-
if (signal?.aborted)
|
|
1126
|
-
return { status: 'cancelled' };
|
|
1127
|
-
return handle ? { status: 'resolved', handle } : { status: 'unknown' };
|
|
1128
|
-
}
|
|
1129
|
-
catch (error) {
|
|
1130
|
-
if (signal?.aborted)
|
|
1131
|
-
return { status: 'cancelled' };
|
|
1132
|
-
if (isPermanentRepoFailure(error)) {
|
|
1133
|
-
// Do not replace a successful discovery another caller completed while this one failed.
|
|
1134
|
-
const recovered = repoHandleCache.get(context.key);
|
|
1135
|
-
if (recovered)
|
|
1136
|
-
return { status: 'resolved', handle: recovered };
|
|
1137
|
-
// The live arming loop stops on unknown. Do not memoize local failures here: later cold
|
|
1138
|
-
// index/status requests must still discover an installed gh or a newly added remote.
|
|
1139
|
-
return { status: 'unknown' };
|
|
1140
|
-
}
|
|
1141
|
-
return { status: 'retryable' };
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
/** Compatible fail-open lookup for existing API and cold-index callers. */
|
|
1145
|
-
export async function resolveRepoHandle(repoRoot, signal) {
|
|
1146
|
-
const result = await discoverRepoHandle(repoRoot, signal);
|
|
1147
|
-
return result.status === 'resolved' ? result.handle : null;
|
|
1148
|
-
}
|
|
1149
1026
|
/** SHAs per rollup query. Aliases resolve independently, so a chunk that fails costs only its own
|
|
1150
1027
|
* glyphs — but an unbounded alias list would eventually blow the query size limit. */
|
|
1151
1028
|
export const COMMIT_CHECKS_CHUNK = 50;
|
|
@@ -2473,8 +2350,11 @@ async function fetchPrMergeState(repoRoot, repoRef, number, refresh = false) {
|
|
|
2473
2350
|
'number,title,url,state,isDraft,headRefName,baseRefName,headRefOid,mergeable,mergeStateStatus,reviewDecision,statusCheckRollup,mergedAt',
|
|
2474
2351
|
]);
|
|
2475
2352
|
const parsedPr = mergePrSchema.parse(JSON.parse(prOut));
|
|
2476
|
-
|
|
2353
|
+
// A pull request under another name is a redirect after a rename: look the name up again.
|
|
2354
|
+
if (!matchesGithubPullRequest({ ...repoRef, number }, parsedPr)) {
|
|
2355
|
+
forgetRepoHandle(repoRoot);
|
|
2477
2356
|
return { available: false, reason: 'GitHub returned a different pull request.' };
|
|
2357
|
+
}
|
|
2478
2358
|
mergedPullRequestObservations.observe({ ...repoRef, number }, parsedPr);
|
|
2479
2359
|
const [policyOut, requirements] = await Promise.all([
|
|
2480
2360
|
gh(repoRoot, ['api', `repos/${repoRef.owner}/${repoRef.repo}`]),
|
|
@@ -2586,7 +2466,8 @@ async function mergePullRequest(repoRoot, repoRef, number, input) {
|
|
|
2586
2466
|
try {
|
|
2587
2467
|
if (input.canProceed?.() === false)
|
|
2588
2468
|
return mergeCancelledResult();
|
|
2589
|
-
const
|
|
2469
|
+
const ref = await canonicalRepoRef(repoRoot, repoRef);
|
|
2470
|
+
const fresh = await fetchPrMergeState(repoRoot, ref, number, true);
|
|
2590
2471
|
if (input.canProceed?.() === false)
|
|
2591
2472
|
return mergeCancelledResult();
|
|
2592
2473
|
if (!fresh.available)
|
|
@@ -2595,10 +2476,10 @@ async function mergePullRequest(repoRoot, repoRef, number, input) {
|
|
|
2595
2476
|
const preflight = mergePullRequestPreflight(current, input);
|
|
2596
2477
|
if (preflight)
|
|
2597
2478
|
return preflight;
|
|
2598
|
-
const ciConflict = await mergeActiveCiConflict(repoRoot,
|
|
2479
|
+
const ciConflict = await mergeActiveCiConflict(repoRoot, ref, current, input);
|
|
2599
2480
|
if (ciConflict)
|
|
2600
2481
|
return ciConflict;
|
|
2601
|
-
return await executeGithubMerge(repoRoot,
|
|
2482
|
+
return await executeGithubMerge(repoRoot, ref, number, input, current);
|
|
2602
2483
|
}
|
|
2603
2484
|
catch (error) {
|
|
2604
2485
|
return mergePullRequestFailure(error);
|
|
@@ -2674,12 +2555,13 @@ async function readyPullRequest(repoRoot, repoRef, number, input) {
|
|
|
2674
2555
|
try {
|
|
2675
2556
|
if (input.canProceed?.() === false)
|
|
2676
2557
|
return readyCancelledResult();
|
|
2558
|
+
const ref = await canonicalRepoRef(repoRoot, repoRef);
|
|
2677
2559
|
if (productEnv('DRY_RUN') !== '1') {
|
|
2678
|
-
const ownership = await readyPullRequestOwnership(repoRoot,
|
|
2560
|
+
const ownership = await readyPullRequestOwnership(repoRoot, ref, number, input);
|
|
2679
2561
|
if (ownership)
|
|
2680
2562
|
return ownership;
|
|
2681
2563
|
}
|
|
2682
|
-
return await refreshReadyPullRequestState(repoRoot,
|
|
2564
|
+
return await refreshReadyPullRequestState(repoRoot, ref, number, input);
|
|
2683
2565
|
}
|
|
2684
2566
|
catch {
|
|
2685
2567
|
return { available: false, reason: 'GitHub could not mark the pull request ready for review.' };
|
|
@@ -2744,8 +2626,9 @@ export function createGithubDriver(repoRoot, repoRef) {
|
|
|
2744
2626
|
try {
|
|
2745
2627
|
const out = await gh(repoRoot, ['pr', 'view', branch, '--json', 'number,url,state,isDraft,statusCheckRollup,mergedAt']);
|
|
2746
2628
|
const pr = ghPrViewSchema.parse(JSON.parse(out));
|
|
2747
|
-
|
|
2748
|
-
|
|
2629
|
+
const ref = await canonicalRepoRef(repoRoot, repoRef);
|
|
2630
|
+
if (ref)
|
|
2631
|
+
mergedPullRequestObservations.observe({ ...ref, number: pr.number }, pr);
|
|
2749
2632
|
return {
|
|
2750
2633
|
number: pr.number,
|
|
2751
2634
|
url: pr.url,
|
|
@@ -2758,7 +2641,7 @@ export function createGithubDriver(repoRoot, repoRef) {
|
|
|
2758
2641
|
return null;
|
|
2759
2642
|
}
|
|
2760
2643
|
},
|
|
2761
|
-
prMergeState: (number, opts) => fetchPrMergeState(repoRoot, repoRef, number, opts?.refresh),
|
|
2644
|
+
prMergeState: async (number, opts) => fetchPrMergeState(repoRoot, await canonicalRepoRef(repoRoot, repoRef), number, opts?.refresh),
|
|
2762
2645
|
readyPR: (number, input) => readyPullRequest(repoRoot, repoRef, number, input),
|
|
2763
2646
|
mergePR: async (number, input) => {
|
|
2764
2647
|
const result = await mergePullRequest(repoRoot, repoRef, number, input);
|