@hearsay-tools/squawk 0.18.0-pr4275.8266 → 0.18.0-pr4276.8267

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.
@@ -1,18 +1,129 @@
1
1
  export type { RepoHandleDiscovery } from './repo-handle-discovery.ts';
2
2
  export { createDraftPr, buildPrBody } from './draft-pr.ts';
3
3
  import type { ArchivePullRequestIdentity, MergedPullRequest } from '../../contract/index.js';
4
+ import { z } from 'zod';
4
5
  export { parseOwnerName } from './github-cli.ts';
5
6
  export { __clearRepoHandleCacheForTests, discoverRepoHandle, forgetRepoHandle, resolveRepoHandle } from './github-repo-handle.ts';
6
- import { type GithubCommentCountsData, type GithubItemResponse } from '../../contract/index.js';
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
- import { type GithubRepoRef, type GraphqlRunner } from './github-shared.ts';
10
- export { detectGithubCached, ghCheckRunSchema, ghFailureReason, ghGraphqlArgs, HEALTH_AVAILABILITY_TTL_MS, rollupToChecks, type GithubData, type GithubItem, type GithubRepoRef, type GraphqlRunner, } from './github-shared.ts';
11
- export { fetchGithubPrDiff, fetchPrFilePages, GH_PR_DIFF_FILE_CAP, GH_PR_DIFF_JSON_CAP, GH_PR_PATCH_CAP, GithubPrNotFoundError, type PrFilesPageRunner, } from './github-pr-diff.ts';
12
- export { fetchGithub, fetchGithubProjects, fetchListConnection, GH_GRAPHQL_PAGE_MAX, GH_MAX_LIMIT, GH_SEARCH_MAX, searchGithubItems, viewGithubItem, type GithubPageRequest, type ListNode, type ListSide, } from './github-list.ts';
13
- import { type ChecksGlyph } from './github-checks.ts';
14
- export { __clearChecksCacheForTests, COMMIT_CHECKS_CHUNK, fetchCommitChecks, fetchGithubChecks, fetchPrChecks, GH_CHECKS_MAX, type ChecksGlyph, type GithubChecksData, } from './github-checks.ts';
15
- import type { ForgeComment, ForgeCommentsData, ForgeDriver, ForgePrMergeState } from './types.ts';
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.
16
+ */
17
+ export declare const GH_PR_DIFF_FILE_CAP = 300;
18
+ export declare const GH_PR_PATCH_CAP: number;
19
+ export declare const GH_PR_DIFF_JSON_CAP: number;
20
+ export declare class GithubPrNotFoundError extends Error {
21
+ }
22
+ export type PrFilesPageRunner = (page: number) => Promise<string>;
23
+ /** Fetch no more than the three GitHub pages represented by the public 300-file response cap. */
24
+ export declare function fetchPrFilePages(runPage: PrFilesPageRunner): Promise<unknown[]>;
25
+ export declare function fetchGithubPrDiff(repoRoot: string, number: number, refresh?: boolean): Promise<ForgePrDiffResult>;
26
+ /** One GitHub issue or pull request, flattened for the cockpit's GitHub tab. */
27
+ export type GithubItem = ForgeItem;
28
+ export type GithubData = import('../../contract/index.js').GithubData;
29
+ export declare const ghCheckRunSchema: z.ZodObject<{
30
+ state: z.ZodOptional<z.ZodNullable<z.ZodString>>;
31
+ status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
32
+ conclusion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
33
+ }, z.core.$strip>;
34
+ declare const ghStatusCheckRollup: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
35
+ state: z.ZodOptional<z.ZodNullable<z.ZodString>>;
36
+ status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
37
+ conclusion: z.ZodOptional<z.ZodNullable<z.ZodString>>;
38
+ }, z.core.$strip>>>>;
39
+ /** Exported for unit tests (#400) — collapses a zod-validated `statusCheckRollup` array down to
40
+ * the single enum the GitHub tab (list rows + detail badge) renders. */
41
+ export declare function rollupToChecks(rollup: z.infer<typeof ghStatusCheckRollup>): GithubItem['checks'];
42
+ /** Runs a GraphQL query — injected so pagination is unit-testable without shelling to `gh`.
43
+ * Number variables reach GitHub typed (`-F`), strings raw (`-f`): see `ghGraphqlArgs`. */
44
+ export type GraphqlRunner = (query: string, variables: Record<string, string | number>) => Promise<string>;
45
+ /** `gh api graphql` argv. `-f` sends every value as a String, and GitHub rejects a String where
46
+ * the query declares `Int!` ("Could not coerce value to Int", open-mercato/cezar#1366), so a
47
+ * number goes through `-F`. A string never does: `-F` would read `@file` and coerce
48
+ * `true`/numerals, which is not what an opaque cursor or a login means. */
49
+ export declare function ghGraphqlArgs(query: string, variables?: Record<string, string | number>): string[];
50
+ /** GitHub GraphQL rejects `first` above 100 (EXCESSIVE_PAGINATION); larger limits walk pages. */
51
+ export declare const GH_GRAPHQL_PAGE_MAX = 100;
52
+ export type ListSide = 'issues' | 'pullRequests';
53
+ declare const ghListNodeSchema: z.ZodObject<{
54
+ number: z.ZodNumber;
55
+ title: z.ZodString;
56
+ author: z.ZodOptional<z.ZodNullable<z.ZodObject<{
57
+ login: z.ZodString;
58
+ }, z.core.$strip>>>;
59
+ createdAt: z.ZodString;
60
+ url: z.ZodString;
61
+ body: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
+ labels: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodObject<{
63
+ nodes: z.ZodDefault<z.ZodArray<z.ZodNullable<z.ZodObject<{
64
+ name: z.ZodString;
65
+ color: z.ZodDefault<z.ZodString>;
66
+ }, z.core.$strip>>>>;
67
+ }, z.core.$strip>>>, z.ZodTransform<{
68
+ name: string;
69
+ color: string;
70
+ }[], {
71
+ nodes: ({
72
+ name: string;
73
+ color: string;
74
+ } | null)[];
75
+ } | null | undefined>>;
76
+ assignees: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodObject<{
77
+ nodes: z.ZodDefault<z.ZodArray<z.ZodNullable<z.ZodObject<{
78
+ login: z.ZodString;
79
+ }, z.core.$strip>>>>;
80
+ }, z.core.$strip>>>, z.ZodTransform<{
81
+ login: string;
82
+ }[], {
83
+ nodes: ({
84
+ login: string;
85
+ } | null)[];
86
+ } | null | undefined>>;
87
+ isDraft: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
88
+ additions: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
89
+ deletions: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
90
+ }, z.core.$strip>;
91
+ export type ListNode = z.infer<typeof ghListNodeSchema>;
92
+ /**
93
+ * One side of the open list: up to `limit` rows from `cursor`, in requests of at most
94
+ * `GH_GRAPHQL_PAGE_MAX`. `nextCursor` is where the rows stop, or `null` once the side is
95
+ * exhausted. `done` asks for `first: 0`, which still answers `totalCount`, so an exhausted side
96
+ * keeps a fresh total without ever restarting from its first page (open-mercato/cezar#1366
97
+ * restarted it while the other side paged).
98
+ */
99
+ export declare function fetchListConnection(run: GraphqlRunner, owner: string, name: string, side: ListSide, limit: number, cursor?: string, done?: boolean): Promise<{
100
+ totalCount: number;
101
+ nodes: ListNode[];
102
+ nextCursor: string | null;
103
+ }>;
104
+ export declare const GH_MAX_LIMIT = 1000;
105
+ /** Where one list page starts on each side. A done side answered `nextCursor: null` already. */
106
+ export type GithubPageRequest = Pick<ForgeListOptions, 'issuesCursor' | 'prsCursor' | 'issuesDone' | 'prsDone'>;
107
+ export declare function fetchGithub(repoRoot: string, refresh?: boolean, limit?: number, page?: GithubPageRequest): Promise<GithubData>;
108
+ /** A `gh` failure as one readable line. GitHub's own words come on stderr; the Node message
109
+ * starts with the whole argv, and a GraphQL argv is a multi-line query, so its first line is
110
+ * a fragment of that query rather than the reason (open-mercato/cezar#1366). */
111
+ export declare function ghFailureReason(err: unknown): string;
112
+ /** Bounded lookup already started by the list. Never launch work for an expired generation. */
113
+ export declare function fetchGithubProjects(repoRoot: string, generation: string): Promise<GithubProjectsData>;
114
+ /** Hits per search. `gh search`'s own default is 30; 50 matches the page size the incremental-
115
+ * loading spec settled on and keeps one search to a single `gh` round-trip. */
116
+ export declare const GH_SEARCH_MAX = 50;
117
+ /**
118
+ * One issue or PR by number, in any state (#692). `null` when `gh` confirms the item is absent;
119
+ * throws on every other failure. `labelColors` is an optional out-param.
120
+ */
121
+ export declare function viewGithubItem(repoRoot: string, kind: 'issue' | 'pr', number: number, labelColors?: Record<string, string>): Promise<ForgeItem | null>;
122
+ /**
123
+ * Search any state: exact numbers try a direct lookup, then text fallback; text search omits
124
+ * state restriction. Return availability and a reason on failure instead of throwing.
125
+ */
126
+ export declare function searchGithubItems(repoRoot: string, kind: 'issue' | 'pr', query: string, limit?: number): Promise<ForgeSearchData>;
16
127
  /** First 200 thread entries, then `truncated`; each body sliced to 8 000 chars (same cap as
17
128
  * item bodies). */
18
129
  export declare const THREAD_ENTRY_CAP = 200;
@@ -34,12 +145,59 @@ export declare function forgetGithubItem(repoRoot: string, kind: 'issue' | 'pr',
34
145
  /** Test-only: drop the single-item cache. */
35
146
  export declare function __clearGithubItemCacheForTests(): void;
36
147
  export declare function fetchGithubItem(repoRoot: string, kind: 'issue' | 'pr', number: number, refresh?: boolean): Promise<GithubItemResponse>;
148
+ /** SHAs per rollup query. Aliases resolve independently, so a chunk that fails costs only its own
149
+ * glyphs — but an unbounded alias list would eventually blow the query size limit. */
150
+ export declare const COMMIT_CHECKS_CHUNK = 50;
151
+ /**
152
+ * Rolled-up CI state per commit SHA, as a `sha → checks` map.
153
+ *
154
+ * Batched and aliased so a 40-commit PR costs one subprocess, not forty. Verified against the live
155
+ * API: each alias resolves independently and an unknown SHA comes back `null` rather than erroring
156
+ * the batch, so partial results degrade cleanly.
157
+ *
158
+ * Degrades to an empty map on any failure — exactly as `fetchCommentCounts` does for counts. The
159
+ * caller then leaves `checks` **absent**, which the UI renders as no glyph. Exported for tests;
160
+ * `runGraphql` is injected so this is testable without shelling out.
161
+ */
162
+ export declare function fetchCommitChecks(runGraphql: GraphqlRunner, owner: string, name: string, shas: string[], chunkSize?: number): Promise<Record<string, ForgeTimelineEvent['checks']>>;
163
+ /** The single enum a PR row's checks glyph renders (never `undefined` on the wire). */
164
+ export type ChecksGlyph = 'passing' | 'failing' | 'pending' | null;
165
+ export type GithubChecksData = {
166
+ available: true;
167
+ checks: Record<number, ChecksGlyph>;
168
+ } | {
169
+ available: false;
170
+ reason: string;
171
+ };
172
+ /** PR numbers per checks query. Aliases resolve independently (a failed chunk costs only its own
173
+ * glyphs); bounded so an unbounded number list can't blow the query size limit. Also the route's
174
+ * hard cap on how many PRs one request may ask about. */
175
+ export declare const GH_CHECKS_MAX = 100;
176
+ /**
177
+ * Rolled-up CI state per PR number, as a `number → glyph` map.
178
+ *
179
+ * Batched and aliased so a 100-PR window costs one subprocess, not a hundred. Each alias resolves
180
+ * independently and an unknown number comes back `null` (alias resolved null → left absent), so
181
+ * partial results degrade cleanly. Degrades to an empty map on any failure — exactly as
182
+ * `fetchCommitChecks` does. Exported for tests; `runGraphql` is injected so this is testable
183
+ * without shelling out.
184
+ */
185
+ export declare function fetchPrChecks(runGraphql: GraphqlRunner, owner: string, name: string, numbers: number[], chunkSize?: number): Promise<Record<number, ChecksGlyph>>;
37
186
  /**
38
187
  * Comment counts for the given issue or PR numbers, in one aliased GraphQL query. A number GitHub
39
188
  * does not know is absent (unknown), never 0. Degrades to `{ available: false, reason }` — never a
40
189
  * throw. Numbers are de-duplicated, validated and capped at `GITHUB_COMMENT_COUNTS_MAX`.
41
190
  */
42
191
  export declare function fetchGithubCommentCounts(repoRoot: string, kind: 'issue' | 'pr', numbers: number[], refresh?: boolean): Promise<GithubCommentCountsData>;
192
+ /** Test hook — the per-PR checks cache would otherwise leak state across cases in one process. */
193
+ export declare function __clearChecksCacheForTests(): void;
194
+ /**
195
+ * Lazy checks glyphs for the given PR numbers (route-facing). Resolves the repo handle once,
196
+ * serves fresh cache entries, queries only the misses, and degrades to `{ available: false,
197
+ * reason }` when `gh` or the handle is unavailable — never a throw, never a 5xx (plan rule 7).
198
+ * Numbers are de-duplicated, validated, and capped at `GH_CHECKS_MAX`.
199
+ */
200
+ export declare function fetchGithubChecks(repoRoot: string, numbers: number[]): Promise<GithubChecksData>;
43
201
  /** Where a referenced PR or issue stands. Mirrored by `referenceStatusSchema` in the contract —
44
202
  * see there for why PR `closed` and issue `completed` are separate words. */
45
203
  export type ReferenceStatus = 'draft' | 'review-required' | 'changes-requested' | 'checks-pending' | 'checks-failing' | 'ready' | 'merged' | 'closed' | 'open' | 'completed' | 'not-planned';
@@ -201,8 +359,34 @@ export declare function fetchGithubRefStatus(repoRoot: string, input: {
201
359
  issues?: number[];
202
360
  }): Promise<GithubRefStatusData>;
203
361
  export declare function fetchGithubComments(repoRoot: string, kind: 'issue' | 'pr', number: number, refresh?: boolean): Promise<ForgeCommentsData>;
362
+ /**
363
+ * How old an availability answer `/health` serves before it probes again. The server rebuilds
364
+ * health every 5 s while a client reads it, so `CACHE_MS` (60 s) started one `gh repo view` a
365
+ * minute, and each start forks the server process (hearsay-tools/squawk#3658). The answer depends
366
+ * on the network and on GitHub access, so no file change can signal it. A direct `detectGithub`
367
+ * call (automation discovery) still refreshes the shared slot after 60 s.
368
+ */
369
+ export declare const HEALTH_AVAILABILITY_TTL_MS: number;
370
+ /**
371
+ * Non-blocking availability for `GET /api/health` (#major-health-latency): serves the last-known
372
+ * probe immediately (stale-while-revalidate) and only returns `null` on a cold start, before the
373
+ * first probe has ever warmed the cache. It NEVER shells out to `gh` on the request that reads it,
374
+ * so health stays fast (a `gh repo view` round-trip is ~500–650 ms on its own). `null` is contract-safe — the whole `forge` field is additive, so
375
+ * "unknown until warm" is a valid answer.
376
+ *
377
+ * Serving the stale value while revalidating is what keeps the GitHub nav item from flickering:
378
+ * without it, every time the cache expired this returned `null` for one 5 s health poll,
379
+ * dropping `forge.available` and blinking the sidebar item out until the background probe warmed.
380
+ */
381
+ export declare function detectGithubCached(repoRoot: string): ForgeAvailability | null;
204
382
  export declare function evictGithubProjectCaches(repoRoot: string): void;
205
383
  export declare function mergePreflightAllowed(current: ForgePrMergeState, overrideRules?: boolean): boolean;
384
+ /** owner/repo parsed out of the origin remote — feeds `viewUrl`. Reads that name the repository
385
+ * use `canonicalRepoRef` instead, which follows a rename. */
386
+ export interface GithubRepoRef {
387
+ owner: string;
388
+ repo: string;
389
+ }
206
390
  export declare function createGithubDriver(repoRoot: string, repoRef: GithubRepoRef | null): ForgeDriver;
207
391
  /** Strict archive authority: no partial GraphQL success, redirects, guessed identity or date. */
208
392
  export declare function fetchMergedPullRequests(runGraphql: GraphqlRunner, identities: readonly ArchivePullRequestIdentity[]): Promise<MergedPullRequest[]>;