@hearsay-tools/squawk 0.18.0-dev.8274 → 0.18.0-dev.8291
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/delegation/transport.d.ts +65 -65
- package/dist/runners/claude/claude-executable.js +3 -9
- package/dist/runners/claude/claude-executable.js.map +1 -1
- package/dist/runners/claude/claude-model-catalog.d.ts +1 -1
- package/dist/runners/claude/claude-model-catalog.js +1 -1
- package/dist/runners/claude/claude-model-catalog.js.map +1 -1
- package/dist/runners/claude/claude-skill-catalog.d.ts +1 -1
- package/dist/runners/claude/claude-skill-catalog.js +1 -1
- package/dist/runners/claude/claude-skill-catalog.js.map +1 -1
- package/dist/runners/codex/codex-app-server-transport.js +3 -3
- package/dist/runners/codex/codex-app-server-transport.js.map +1 -1
- package/dist/runners/codex/codex-approvals.d.ts +1 -1
- package/dist/runners/codex/codex-approvals.js +1 -1
- package/dist/runners/codex/codex-approvals.js.map +1 -1
- package/dist/runners/codex/codex-model-catalog.d.ts +1 -1
- package/dist/runners/codex/codex-model-catalog.js +1 -1
- package/dist/runners/codex/codex-model-catalog.js.map +1 -1
- package/dist/runners/codex/codex-permissions.js +1 -1
- package/dist/runners/codex/codex-permissions.js.map +1 -1
- package/dist/runners/codex/codex-skill-catalog.d.ts +1 -1
- package/dist/runners/codex/codex-skill-catalog.js +1 -1
- package/dist/runners/codex/codex-skill-catalog.js.map +1 -1
- package/dist/server/forge/github-checks.d.ts +31 -0
- package/dist/server/forge/github-checks.js +155 -0
- package/dist/server/forge/github-checks.js.map +1 -0
- package/dist/server/forge/github-list.d.ts +77 -0
- package/dist/server/forge/github-list.js +541 -0
- package/dist/server/forge/github-list.js.map +1 -0
- package/dist/server/forge/github-pr-diff.d.ts +10 -0
- package/dist/server/forge/github-pr-diff.js +126 -0
- package/dist/server/forge/github-pr-diff.js.map +1 -0
- package/dist/server/forge/github-shared.d.ts +119 -0
- package/dist/server/forge/github-shared.js +225 -0
- package/dist/server/forge/github-shared.js.map +1 -0
- package/dist/server/forge/github.d.ts +8 -192
- package/dist/server/forge/github.js +12 -1166
- package/dist/server/forge/github.js.map +1 -1
- package/dist/server/reports-api.d.ts +2 -2
- package/dist/server/runner-install-routes.d.ts +10 -10
- package/dist/server/server.d.ts +60 -60
- package/package.json +4 -4
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { productEnv } from '../../core/product-env.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { gh } from './github-cli.js';
|
|
4
|
+
import { CACHE_MS, firstLine } from './github-shared.js';
|
|
5
|
+
export const GH_PR_DIFF_FILE_CAP = 300;
|
|
6
|
+
export const GH_PR_PATCH_CAP = 512 * 1024;
|
|
7
|
+
export const GH_PR_DIFF_JSON_CAP = 4 * 1024 * 1024;
|
|
8
|
+
const ghPrFileSchema = z.object({
|
|
9
|
+
filename: z.string().min(1),
|
|
10
|
+
previous_filename: z.string().optional(),
|
|
11
|
+
status: z.enum(['added', 'modified', 'removed', 'renamed', 'copied', 'changed']),
|
|
12
|
+
additions: z.number().int().nonnegative(),
|
|
13
|
+
deletions: z.number().int().nonnegative(),
|
|
14
|
+
patch: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
const ghPrHeadSchema = z.object({ headRefOid: z.string().regex(/^[0-9a-f]{40}$/i) });
|
|
17
|
+
export class GithubPrNotFoundError extends Error {
|
|
18
|
+
}
|
|
19
|
+
const prDiffCache = new Map();
|
|
20
|
+
/** Fetch no more than the three GitHub pages represented by the public 300-file response cap. */
|
|
21
|
+
export async function fetchPrFilePages(runPage) {
|
|
22
|
+
const rows = [];
|
|
23
|
+
for (let page = 1; page <= GH_PR_DIFF_FILE_CAP / 100; page++) {
|
|
24
|
+
const next = z.array(z.unknown()).parse(JSON.parse(await runPage(page)));
|
|
25
|
+
rows.push(...next);
|
|
26
|
+
if (next.length < 100)
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
return rows;
|
|
30
|
+
}
|
|
31
|
+
export async function fetchGithubPrDiff(repoRoot, number, refresh = false) {
|
|
32
|
+
if (productEnv('DRY_RUN') === '1')
|
|
33
|
+
return mockGithubPrDiff(number);
|
|
34
|
+
try {
|
|
35
|
+
const head = ghPrHeadSchema.parse(JSON.parse(await gh(repoRoot, ['pr', 'view', String(number), '--json', 'headRefOid']))).headRefOid;
|
|
36
|
+
const key = `${repoRoot}\0${number}\0${head}`;
|
|
37
|
+
const hit = prDiffCache.get(key);
|
|
38
|
+
if (!refresh && hit && Date.now() - hit.at < CACHE_MS)
|
|
39
|
+
return hit.data;
|
|
40
|
+
const rows = z.array(ghPrFileSchema).parse(await fetchPrFilePages((page) => gh(repoRoot, ['api', `repos/{owner}/{repo}/pulls/${number}/files?per_page=100&page=${page}`], 30_000)));
|
|
41
|
+
const limited = rows.slice(0, GH_PR_DIFF_FILE_CAP);
|
|
42
|
+
// A full third page may have a successor. Without fetching a 301st file, conservatively call
|
|
43
|
+
// the response partial rather than claiming completeness we cannot prove.
|
|
44
|
+
let responseTruncated = rows.length >= GH_PR_DIFF_FILE_CAP;
|
|
45
|
+
const reasons = responseTruncated ? [`Only the first ${GH_PR_DIFF_FILE_CAP} files are shown.`] : [];
|
|
46
|
+
const files = limited.map((row) => {
|
|
47
|
+
let patch = row.patch;
|
|
48
|
+
let truncated = false;
|
|
49
|
+
let patchUnavailableReason;
|
|
50
|
+
if (patch !== undefined && Buffer.byteLength(patch, 'utf8') > GH_PR_PATCH_CAP) {
|
|
51
|
+
patch = undefined;
|
|
52
|
+
truncated = true;
|
|
53
|
+
patchUnavailableReason = 'too-large';
|
|
54
|
+
responseTruncated = true;
|
|
55
|
+
}
|
|
56
|
+
else if (patch === undefined) {
|
|
57
|
+
patchUnavailableReason = row.additions === 0 && row.deletions === 0 ? 'binary' : 'not-provided';
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
path: row.filename,
|
|
61
|
+
...(row.previous_filename ? { previousPath: row.previous_filename } : {}),
|
|
62
|
+
status: row.status,
|
|
63
|
+
additions: row.additions,
|
|
64
|
+
deletions: row.deletions,
|
|
65
|
+
...(patch !== undefined ? { patch } : {}),
|
|
66
|
+
...(patchUnavailableReason ? { patchUnavailableReason } : {}),
|
|
67
|
+
...(truncated ? { truncated: true } : {}),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
let kept = files;
|
|
71
|
+
while (kept.length > 0 &&
|
|
72
|
+
Buffer.byteLength(JSON.stringify({ available: true, number, headSha: head, files: kept }), 'utf8') >
|
|
73
|
+
GH_PR_DIFF_JSON_CAP) {
|
|
74
|
+
kept = kept.slice(0, -1);
|
|
75
|
+
responseTruncated = true;
|
|
76
|
+
}
|
|
77
|
+
if (kept.length < files.length)
|
|
78
|
+
reasons.push('The response size limit omitted some files.');
|
|
79
|
+
if (files.some((file) => file.truncated))
|
|
80
|
+
reasons.push('One or more patches exceeded the per-file limit.');
|
|
81
|
+
const data = {
|
|
82
|
+
available: true,
|
|
83
|
+
number,
|
|
84
|
+
headSha: head,
|
|
85
|
+
files: kept,
|
|
86
|
+
additions: rows.reduce((sum, row) => sum + row.additions, 0),
|
|
87
|
+
deletions: rows.reduce((sum, row) => sum + row.deletions, 0),
|
|
88
|
+
truncated: responseTruncated,
|
|
89
|
+
...(reasons.length ? { reason: reasons.join(' ') } : {}),
|
|
90
|
+
};
|
|
91
|
+
prDiffCache.set(key, { at: Date.now(), data });
|
|
92
|
+
while (prDiffCache.size > 50)
|
|
93
|
+
prDiffCache.delete(prDiffCache.keys().next().value);
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
98
|
+
if (/HTTP 404|Could not resolve to a PullRequest|no pull requests found/i.test(message)) {
|
|
99
|
+
throw new GithubPrNotFoundError(`Pull request #${number} was not found`);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
available: false,
|
|
103
|
+
reason: /ENOENT/.test(message)
|
|
104
|
+
? 'gh CLI not found — install it and run `gh auth login`'
|
|
105
|
+
: firstLine(message),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function mockGithubPrDiff(number) {
|
|
110
|
+
return {
|
|
111
|
+
available: true,
|
|
112
|
+
number,
|
|
113
|
+
headSha: '0123456789abcdef0123456789abcdef01234567',
|
|
114
|
+
additions: 15,
|
|
115
|
+
deletions: 4,
|
|
116
|
+
truncated: true,
|
|
117
|
+
reason: 'One or more patches were not provided by GitHub.',
|
|
118
|
+
files: [
|
|
119
|
+
{ path: 'src/session.ts', status: 'modified', additions: 8, deletions: 3, patch: '@@ -1,3 +1,4 @@\n-old\n+new\n context' },
|
|
120
|
+
{ path: 'src/new-name.ts', previousPath: 'src/old-name.ts', status: 'renamed', additions: 7, deletions: 1, patch: '@@ -1 +1 @@\n-old name\n+new name' },
|
|
121
|
+
{ path: 'assets/logo.png', status: 'modified', additions: 0, deletions: 0, patchUnavailableReason: 'binary' },
|
|
122
|
+
{ path: 'generated/output.txt', status: 'modified', additions: 0, deletions: 0, patchUnavailableReason: 'too-large', truncated: true },
|
|
123
|
+
],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=github-pr-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-pr-diff.js","sourceRoot":"","sources":["../../../src/server/forge/github-pr-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AACvC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,GAAG,IAAI,CAAC;AAC1C,MAAM,CAAC,MAAM,m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AAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,uCAAuC,EAAE;YAC1H,EAAE,IAAI,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,mCAAmC,EAAE;YACvJ,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,sBAAsB,EAAE,QAAQ,EAAE;YAC7G,EAAE,IAAI,EAAE,sBAAsB,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,sBAAsB,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE;SACvI;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ForgeAvailability, ForgeItem } from './types.ts';
|
|
3
|
+
/** Short cache TTL shared across GitHub list, diff, comment, check, and ref-status reads. */
|
|
4
|
+
export declare const CACHE_MS = 60000;
|
|
5
|
+
/** One GitHub issue or pull request, flattened for the cockpit's GitHub tab. */
|
|
6
|
+
export type GithubItem = ForgeItem;
|
|
7
|
+
export type GithubData = import('../../contract/index.js').GithubData;
|
|
8
|
+
/** owner/repo parsed out of the origin remote — feeds `viewUrl`. Reads that name the repository
|
|
9
|
+
* use `canonicalRepoRef` instead, which follows a rename. */
|
|
10
|
+
export interface GithubRepoRef {
|
|
11
|
+
owner: string;
|
|
12
|
+
repo: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const ghAuthor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
15
|
+
login: z.ZodString;
|
|
16
|
+
}, z.core.$strip>>>;
|
|
17
|
+
export declare const ghLabel: z.ZodObject<{
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
color: z.ZodDefault<z.ZodString>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export declare const ghIssueSchema: z.ZodObject<{
|
|
22
|
+
number: z.ZodNumber;
|
|
23
|
+
title: z.ZodString;
|
|
24
|
+
author: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
25
|
+
login: z.ZodString;
|
|
26
|
+
}, z.core.$strip>>>;
|
|
27
|
+
createdAt: z.ZodString;
|
|
28
|
+
labels: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
29
|
+
name: z.ZodString;
|
|
30
|
+
color: z.ZodDefault<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>>>;
|
|
32
|
+
assignees: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
33
|
+
login: z.ZodString;
|
|
34
|
+
}, z.core.$strip>>>;
|
|
35
|
+
body: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
36
|
+
url: z.ZodString;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export declare const ghCheckRunSchema: z.ZodObject<{
|
|
39
|
+
state: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
conclusion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export declare const ghStatusCheckRollup: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
44
|
+
state: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
conclusion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
}, z.core.$strip>>>>;
|
|
48
|
+
export declare const ghPrViewSchema: z.ZodObject<{
|
|
49
|
+
number: z.ZodNumber;
|
|
50
|
+
url: z.ZodString;
|
|
51
|
+
state: z.ZodDefault<z.ZodString>;
|
|
52
|
+
mergedAt: z.ZodOptional<z.ZodUnknown>;
|
|
53
|
+
isDraft: z.ZodDefault<z.ZodBoolean>;
|
|
54
|
+
statusCheckRollup: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
55
|
+
state: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
56
|
+
status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
conclusion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
58
|
+
}, z.core.$strip>>>>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
export declare const ghMergeResultSchema: z.ZodObject<{
|
|
61
|
+
merged: z.ZodBoolean;
|
|
62
|
+
message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
sha: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
/** Exported for unit tests (#400) — collapses a zod-validated `statusCheckRollup` array down to
|
|
66
|
+
* the single enum the GitHub tab (list rows + detail badge) renders. */
|
|
67
|
+
export declare function rollupToChecks(rollup: z.infer<typeof ghStatusCheckRollup>): GithubItem['checks'];
|
|
68
|
+
/** Runs a GraphQL query — injected so pagination is unit-testable without shelling to `gh`.
|
|
69
|
+
* Number variables reach GitHub typed (`-F`), strings raw (`-f`): see `ghGraphqlArgs`. */
|
|
70
|
+
export type GraphqlRunner = (query: string, variables: Record<string, string | number>) => Promise<string>;
|
|
71
|
+
/** `gh api graphql` argv. `-f` sends every value as a String, and GitHub rejects a String where
|
|
72
|
+
* the query declares `Int!` ("Could not coerce value to Int", open-mercato/cezar#1366), so a
|
|
73
|
+
* number goes through `-F`. A string never does: `-F` would read `@file` and coerce
|
|
74
|
+
* `true`/numerals, which is not what an opaque cursor or a login means. */
|
|
75
|
+
export declare function ghGraphqlArgs(query: string, variables?: Record<string, string | number>): string[];
|
|
76
|
+
/** A `gh` failure as one readable line. GitHub's own words come on stderr; the Node message
|
|
77
|
+
* starts with the whole argv, and a GraphQL argv is a multi-line query, so its first line is
|
|
78
|
+
* a fragment of that query rather than the reason (open-mercato/cezar#1366). */
|
|
79
|
+
export declare function ghFailureReason(err: unknown): string;
|
|
80
|
+
export declare function firstLine(s: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* The repo handle, memoized in the same map `resolveRepoHandle` uses — but rethrowing instead of
|
|
83
|
+
* answering `null`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveRepoHandleStrict(repoRoot: string, context?: {
|
|
86
|
+
key: string;
|
|
87
|
+
env: {
|
|
88
|
+
GH_HOST: string | undefined;
|
|
89
|
+
GH_CONFIG_DIR: string | undefined;
|
|
90
|
+
};
|
|
91
|
+
}): Promise<{
|
|
92
|
+
owner: string;
|
|
93
|
+
name: string;
|
|
94
|
+
} | null>;
|
|
95
|
+
/** Is this a reply we can still read aliases out of? `repository: null` says the handle did not
|
|
96
|
+
* resolve, which is a real failure and must not be read as "the numbers are all missing". */
|
|
97
|
+
export declare function hasResolvedRepository(stdout: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Use failed gh GraphQL stdout only when it contains usable data.repository. Preserve successful
|
|
100
|
+
* aliases in partial responses; rethrow malformed or unresolved-repository failures.
|
|
101
|
+
*/
|
|
102
|
+
export declare function refStatusGraphql(repoRoot: string, context?: {
|
|
103
|
+
key: string;
|
|
104
|
+
env: {
|
|
105
|
+
GH_HOST: string | undefined;
|
|
106
|
+
GH_CONFIG_DIR: string | undefined;
|
|
107
|
+
};
|
|
108
|
+
}): GraphqlRunner;
|
|
109
|
+
/** CEZ_DRY_RUN=1 — a small fixed catalog so the GitHub tab is demoable offline. */
|
|
110
|
+
export declare function mockGithub(): GithubData;
|
|
111
|
+
export declare function detectGithub(repoRoot: string): Promise<ForgeAvailability>;
|
|
112
|
+
/** How old an availability answer `/health` serves before it probes again (hearsay-tools/squawk#3658). */
|
|
113
|
+
export declare const HEALTH_AVAILABILITY_TTL_MS: number;
|
|
114
|
+
/**
|
|
115
|
+
* Non-blocking availability for `GET /api/health` (#major-health-latency): serves the last-known
|
|
116
|
+
* probe immediately (stale-while-revalidate) and only returns `null` on a cold start, before the
|
|
117
|
+
* first probe has ever warmed the cache.
|
|
118
|
+
*/
|
|
119
|
+
export declare function detectGithubCached(repoRoot: string): ForgeAvailability | null;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { productEnv } from '../../core/product-env.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { gh, githubContext } from './github-cli.js';
|
|
4
|
+
import { sharedRepoHandle } from './github-repo-handle.js';
|
|
5
|
+
/** Short cache TTL shared across GitHub list, diff, comment, check, and ref-status reads. */
|
|
6
|
+
export const CACHE_MS = 60_000;
|
|
7
|
+
// `gh … --json` output — validated at the boundary, extras stripped.
|
|
8
|
+
export const ghAuthor = z.object({ login: z.string() }).nullish();
|
|
9
|
+
// `color` is the 6-hex GitHub label color (no `#`), '' when gh omits it.
|
|
10
|
+
export const ghLabel = z.object({ name: z.string(), color: z.string().default('') });
|
|
11
|
+
export const ghIssueSchema = z.object({
|
|
12
|
+
number: z.number(),
|
|
13
|
+
title: z.string(),
|
|
14
|
+
author: ghAuthor,
|
|
15
|
+
createdAt: z.string(),
|
|
16
|
+
labels: z.array(ghLabel).default([]),
|
|
17
|
+
assignees: z.array(z.object({ login: z.string() })).default([]),
|
|
18
|
+
body: z.string().nullish(),
|
|
19
|
+
url: z.string(),
|
|
20
|
+
});
|
|
21
|
+
// One check run's `gh --json statusCheckRollup` entry — every field optional/nullish because
|
|
22
|
+
// gh's shape varies by check provider (exported so #400's unit tests can build fixtures).
|
|
23
|
+
export const ghCheckRunSchema = z.object({
|
|
24
|
+
state: z.string().nullish(),
|
|
25
|
+
status: z.string().nullish(),
|
|
26
|
+
conclusion: z.string().nullish(),
|
|
27
|
+
});
|
|
28
|
+
export const ghStatusCheckRollup = z.array(ghCheckRunSchema).nullish();
|
|
29
|
+
export const ghPrViewSchema = z.object({
|
|
30
|
+
number: z.number(),
|
|
31
|
+
url: z.string(),
|
|
32
|
+
state: z.string().default('OPEN'),
|
|
33
|
+
mergedAt: z.unknown().optional(),
|
|
34
|
+
isDraft: z.boolean().default(false),
|
|
35
|
+
statusCheckRollup: ghStatusCheckRollup,
|
|
36
|
+
});
|
|
37
|
+
export const ghMergeResultSchema = z.object({
|
|
38
|
+
merged: z.boolean(),
|
|
39
|
+
message: z.string().nullish(),
|
|
40
|
+
sha: z.string().nullish(),
|
|
41
|
+
});
|
|
42
|
+
/** Exported for unit tests (#400) — collapses a zod-validated `statusCheckRollup` array down to
|
|
43
|
+
* the single enum the GitHub tab (list rows + detail badge) renders. */
|
|
44
|
+
export function rollupToChecks(rollup) {
|
|
45
|
+
if (!rollup || rollup.length === 0)
|
|
46
|
+
return null;
|
|
47
|
+
const states = rollup.map((r) => (r.conclusion || r.state || r.status || '').toUpperCase());
|
|
48
|
+
if (states.some((s) => ['FAILURE', 'ERROR', 'TIMED_OUT', 'ACTION_REQUIRED'].includes(s)))
|
|
49
|
+
return 'failing';
|
|
50
|
+
if (states.some((s) => ['PENDING', 'IN_PROGRESS', 'QUEUED', 'EXPECTED', ''].includes(s)))
|
|
51
|
+
return 'pending';
|
|
52
|
+
return 'passing';
|
|
53
|
+
}
|
|
54
|
+
/** `gh api graphql` argv. `-f` sends every value as a String, and GitHub rejects a String where
|
|
55
|
+
* the query declares `Int!` ("Could not coerce value to Int", open-mercato/cezar#1366), so a
|
|
56
|
+
* number goes through `-F`. A string never does: `-F` would read `@file` and coerce
|
|
57
|
+
* `true`/numerals, which is not what an opaque cursor or a login means. */
|
|
58
|
+
export function ghGraphqlArgs(query, variables = {}) {
|
|
59
|
+
const args = ['api', 'graphql', '-f', `query=${query}`];
|
|
60
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
61
|
+
args.push(typeof value === 'number' ? '-F' : '-f', `${key}=${value}`);
|
|
62
|
+
}
|
|
63
|
+
return args;
|
|
64
|
+
}
|
|
65
|
+
/** A `gh` failure as one readable line. GitHub's own words come on stderr; the Node message
|
|
66
|
+
* starts with the whole argv, and a GraphQL argv is a multi-line query, so its first line is
|
|
67
|
+
* a fragment of that query rather than the reason (open-mercato/cezar#1366). */
|
|
68
|
+
export function ghFailureReason(err) {
|
|
69
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
70
|
+
if (/ENOENT/.test(message))
|
|
71
|
+
return 'gh CLI not found — install it and run `gh auth login`';
|
|
72
|
+
const failure = (err ?? {});
|
|
73
|
+
const stderr = typeof failure.stderr === 'string' ? failure.stderr : '';
|
|
74
|
+
if (stderr.trim()) {
|
|
75
|
+
const lines = stderr.split('\n').map((line) => line.trim()).filter(Boolean);
|
|
76
|
+
return lines.find((line) => !/^Command failed:/i.test(line)) ?? lines[0];
|
|
77
|
+
}
|
|
78
|
+
if (failure.killed === true || typeof failure.signal === 'string')
|
|
79
|
+
return 'GitHub did not answer in time. Refresh to try again.';
|
|
80
|
+
// Without stderr, everything after "Command failed:" is the argv, which is query text.
|
|
81
|
+
if (/^Command failed:/i.test(message))
|
|
82
|
+
return 'GitHub request failed. Refresh to try again.';
|
|
83
|
+
return message.split('\n').map((line) => line.trim()).find(Boolean) ?? 'gh failed';
|
|
84
|
+
}
|
|
85
|
+
export function firstLine(s) {
|
|
86
|
+
return s.split('\n').find((l) => l.trim().length > 0)?.trim() ?? 'gh failed';
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The repo handle, memoized in the same map `resolveRepoHandle` uses — but rethrowing instead of
|
|
90
|
+
* answering `null`.
|
|
91
|
+
*/
|
|
92
|
+
export async function resolveRepoHandleStrict(repoRoot, context = githubContext(repoRoot)) {
|
|
93
|
+
return sharedRepoHandle(repoRoot, undefined, context);
|
|
94
|
+
}
|
|
95
|
+
/** Is this a reply we can still read aliases out of? `repository: null` says the handle did not
|
|
96
|
+
* resolve, which is a real failure and must not be read as "the numbers are all missing". */
|
|
97
|
+
export function hasResolvedRepository(stdout) {
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(stdout);
|
|
100
|
+
const repository = parsed?.data?.repository;
|
|
101
|
+
return typeof repository === 'object' && repository !== null;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Use failed gh GraphQL stdout only when it contains usable data.repository. Preserve successful
|
|
109
|
+
* aliases in partial responses; rethrow malformed or unresolved-repository failures.
|
|
110
|
+
*/
|
|
111
|
+
export function refStatusGraphql(repoRoot, context = githubContext(repoRoot)) {
|
|
112
|
+
return async (query, variables) => {
|
|
113
|
+
const args = ghGraphqlArgs(query, variables);
|
|
114
|
+
try {
|
|
115
|
+
return await gh(repoRoot, args, 15_000, undefined, context);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
const stdout = err.stdout;
|
|
119
|
+
if (typeof stdout === 'string' && hasResolvedRepository(stdout))
|
|
120
|
+
return stdout;
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** CEZ_DRY_RUN=1 — a small fixed catalog so the GitHub tab is demoable offline. */
|
|
126
|
+
export function mockGithub() {
|
|
127
|
+
const mk = (over) => ({
|
|
128
|
+
author: 'mock',
|
|
129
|
+
createdAt: new Date(Date.now() - over.number * 3_600_000).toISOString(),
|
|
130
|
+
labels: [],
|
|
131
|
+
url: `https://github.com/mock/repo/${over.kind === 'pr' ? 'pull' : 'issues'}/${over.number}`,
|
|
132
|
+
comments: 0,
|
|
133
|
+
...over,
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
available: true,
|
|
137
|
+
repo: 'mock/repo',
|
|
138
|
+
viewerLogin: 'octocat',
|
|
139
|
+
projects: [{ id: 'mock-delivery', title: 'Delivery', url: 'https://github.com/users/mock/projects/1' }],
|
|
140
|
+
syncedAt: new Date().toISOString(),
|
|
141
|
+
issues: [
|
|
142
|
+
mk({ kind: 'issue', assignees: ['octocat'], projectIds: ['mock-delivery'], number: 142, title: 'Login form drops session on refresh', labels: ['bug', 'auth'], comments: 3, body: 'Repro: log in, hit reload — you land back on /login. The session cookie is set correctly, but the client store rehydrates before the cookie check resolves, so the auth guard redirects.' }),
|
|
143
|
+
mk({ kind: 'issue', assignees: ['ada'], projectIds: [], number: 139, title: 'Add --json flag to cez CLI output', labels: ['enhancement', 'cli'], comments: 1, body: 'For scripting it would help if `cez list` and `cez status` could emit machine-readable JSON instead of the table view.' }),
|
|
144
|
+
mk({ kind: 'issue', assignees: [], projectIds: ['mock-delivery'], number: 135, title: 'Flaky e2e: worktree cleanup race on cancel', labels: ['bug', 'flaky-test'], comments: 6, body: 'Cancelling a run while the agent holds a file lock leaves a dangling worktree. The next run on the same branch then fails with "worktree already exists".' }),
|
|
145
|
+
],
|
|
146
|
+
prs: [
|
|
147
|
+
mk({ kind: 'pr', number: 128, title: 'Fix flaky auth test in CI', labels: ['tests'], checks: 'passing', additions: 6, deletions: 3, body: 'Loosens the timing assertion in refresh.test.ts to a realistic budget.' }),
|
|
148
|
+
mk({ kind: 'pr', number: 124, title: 'Rate limit /api/runs', labels: ['server', 'draft'], isDraft: true, checks: 'failing', additions: 118, deletions: 7, comments: 4, body: 'Draft: token-bucket middleware on the runs router. Still needs the config surface and README docs before review.' }),
|
|
149
|
+
],
|
|
150
|
+
labelColors: {
|
|
151
|
+
bug: 'd73a4a',
|
|
152
|
+
auth: '5319e7',
|
|
153
|
+
enhancement: 'a2eeef',
|
|
154
|
+
cli: '0e8a16',
|
|
155
|
+
'flaky-test': 'fbca04',
|
|
156
|
+
tests: 'c5def5',
|
|
157
|
+
server: '1d76db',
|
|
158
|
+
draft: '6a737d',
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Cached availability probe so `GET /api/health` never pays a full listing. Keyed by GitHub context (root, host, account).
|
|
164
|
+
*/
|
|
165
|
+
const DETECT_CACHE_MAX = 64;
|
|
166
|
+
const detectCache = new Map();
|
|
167
|
+
const detectInflight = new Map();
|
|
168
|
+
async function probeGithub(repoRoot, context) {
|
|
169
|
+
let result;
|
|
170
|
+
try {
|
|
171
|
+
await gh(repoRoot, ['repo', 'view', '--json', 'nameWithOwner'], 5_000, undefined, context);
|
|
172
|
+
result = { available: true };
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
176
|
+
result = {
|
|
177
|
+
available: false,
|
|
178
|
+
reason: /ENOENT/.test(message)
|
|
179
|
+
? 'gh CLI not found — install it and run `gh auth login`'
|
|
180
|
+
: firstLine(message),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
detectCache.delete(context.key); // re-insert so Map order tracks recency
|
|
184
|
+
detectCache.set(context.key, { at: Date.now(), result });
|
|
185
|
+
while (detectCache.size > DETECT_CACHE_MAX) {
|
|
186
|
+
const oldest = detectCache.keys().next().value;
|
|
187
|
+
if (oldest === undefined)
|
|
188
|
+
break;
|
|
189
|
+
detectCache.delete(oldest);
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
export async function detectGithub(repoRoot) {
|
|
194
|
+
if (productEnv('DRY_RUN') === '1')
|
|
195
|
+
return { available: true };
|
|
196
|
+
const context = githubContext(repoRoot);
|
|
197
|
+
const hit = detectCache.get(context.key);
|
|
198
|
+
if (hit && Date.now() - hit.at < CACHE_MS)
|
|
199
|
+
return hit.result;
|
|
200
|
+
const pending = detectInflight.get(context.key);
|
|
201
|
+
if (pending)
|
|
202
|
+
return pending;
|
|
203
|
+
const probe = probeGithub(repoRoot, context).finally(() => detectInflight.delete(context.key));
|
|
204
|
+
detectInflight.set(context.key, probe);
|
|
205
|
+
return probe;
|
|
206
|
+
}
|
|
207
|
+
/** How old an availability answer `/health` serves before it probes again (hearsay-tools/squawk#3658). */
|
|
208
|
+
export const HEALTH_AVAILABILITY_TTL_MS = 10 * 60_000;
|
|
209
|
+
/**
|
|
210
|
+
* Non-blocking availability for `GET /api/health` (#major-health-latency): serves the last-known
|
|
211
|
+
* probe immediately (stale-while-revalidate) and only returns `null` on a cold start, before the
|
|
212
|
+
* first probe has ever warmed the cache.
|
|
213
|
+
*/
|
|
214
|
+
export function detectGithubCached(repoRoot) {
|
|
215
|
+
if (productEnv('DRY_RUN') === '1')
|
|
216
|
+
return { available: true };
|
|
217
|
+
const hit = detectCache.get(githubContext(repoRoot).key);
|
|
218
|
+
const cached = hit?.result ?? null;
|
|
219
|
+
const fresh = hit !== undefined && Date.now() - hit.at < HEALTH_AVAILABILITY_TTL_MS;
|
|
220
|
+
if (!fresh) {
|
|
221
|
+
void detectGithub(repoRoot).catch(() => { }); // revalidate off the request path
|
|
222
|
+
}
|
|
223
|
+
return cached; // last-known value while revalidating; null only until the first probe warms
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=github-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-shared.js","sourceRoot":"","sources":["../../../src/server/forge/github-shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,EAAE,EAAE,aAAa,EAAsB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,6FAA6F;AAC7F,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAc/B,qEAAqE;AACrE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAClE,yEAAyE;AACzE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM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