@indigoai-us/hq-cli 5.345.252 → 5.345.254

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/contracts/host-canary-release.json +11 -5
  3. package/dist/command-catalog.generated.d.ts +209 -0
  4. package/dist/command-catalog.generated.js +257 -0
  5. package/dist/command-registration-plan.d.ts +6 -0
  6. package/dist/command-registration-plan.js +1 -0
  7. package/dist/commands/ci-intake.d.ts +32 -0
  8. package/dist/commands/ci-intake.js +294 -0
  9. package/dist/commands/ci-metrics.d.ts +8 -0
  10. package/dist/commands/ci-metrics.js +55 -0
  11. package/dist/commands/ci-priorities.d.ts +56 -0
  12. package/dist/commands/ci-priorities.js +144 -0
  13. package/dist/commands/ci.d.ts +13 -0
  14. package/dist/commands/ci.js +11 -0
  15. package/dist/commands/cloud.d.ts +11 -0
  16. package/dist/commands/cloud.js +76 -0
  17. package/dist/commands/files.d.ts +62 -0
  18. package/dist/commands/files.js +249 -8
  19. package/dist/lib/bot/fleet-cron.d.ts +15 -0
  20. package/dist/lib/bot/fleet-cron.js +119 -20
  21. package/dist/lib/daemon/run.js +4 -3
  22. package/dist/lib/daemon/verified-jq.d.ts +6 -0
  23. package/dist/lib/daemon/verified-jq.js +17 -5
  24. package/dist/lib/delivery/migrations.d.ts +32 -1
  25. package/dist/lib/delivery/migrations.js +69 -8
  26. package/dist/lib/hook-engine/adapter-core-pin.d.ts +2 -1
  27. package/dist/lib/hook-engine/adapter-core-pin.js +2 -1
  28. package/dist/lib/hook-engine/coverage.d.ts +15 -0
  29. package/dist/lib/hook-engine/coverage.js +62 -1
  30. package/dist/lib/hook-engine/fleet-registration.d.ts +4 -0
  31. package/dist/lib/hook-engine/fleet-registration.js +25 -3
  32. package/dist/lib/smart-ci/cost.d.ts +72 -0
  33. package/dist/lib/smart-ci/cost.js +120 -0
  34. package/dist/lib/smart-ci/github.d.ts +112 -0
  35. package/dist/lib/smart-ci/github.js +267 -0
  36. package/dist/lib/smart-ci/intake.d.ts +288 -0
  37. package/dist/lib/smart-ci/intake.js +1078 -0
  38. package/dist/lib/smart-ci/ledger.d.ts +218 -0
  39. package/dist/lib/smart-ci/ledger.js +527 -0
  40. package/dist/lib/smart-ci/metrics.d.ts +137 -0
  41. package/dist/lib/smart-ci/metrics.js +249 -0
  42. package/dist/lib/smart-ci/priorities.d.ts +331 -0
  43. package/dist/lib/smart-ci/priorities.js +964 -0
  44. package/dist/lib/smart-ci/priority-refresh.d.ts +192 -0
  45. package/dist/lib/smart-ci/priority-refresh.js +366 -0
  46. package/dist/lib/smart-ci/priority-snapshots.d.ts +88 -0
  47. package/dist/lib/smart-ci/priority-snapshots.js +233 -0
  48. package/dist/lib/smart-ci/records.d.ts +265 -0
  49. package/dist/lib/smart-ci/records.js +281 -0
  50. package/dist/lib/smart-ci/reducer.d.ts +67 -0
  51. package/dist/lib/smart-ci/reducer.js +261 -0
  52. package/dist/lib/smart-ci/sources.d.ts +294 -0
  53. package/dist/lib/smart-ci/sources.js +659 -0
  54. package/dist/lib/smart-ci/text.d.ts +24 -0
  55. package/dist/lib/smart-ci/text.js +83 -0
  56. package/dist/lib/smart-ci/work-in-flight.d.ts +68 -0
  57. package/dist/lib/smart-ci/work-in-flight.js +154 -0
  58. package/dist/lib/sync/cli-manifest-reconcile.d.ts +20 -0
  59. package/dist/lib/sync/cli-manifest-reconcile.js +170 -0
  60. package/dist/lib/sync-core/engine-holds.d.ts +14 -0
  61. package/dist/lib/sync-core/engine-holds.js +78 -11
  62. package/dist/lib/sync-core/hand-back.d.ts +1 -0
  63. package/dist/lib/sync-core/hand-back.js +7 -2
  64. package/dist/lib/sync-core/reconcile.js +10 -2
  65. package/dist/utils/host-registration.d.ts +1 -0
  66. package/dist/utils/host-registration.js +1 -1
  67. package/package.json +9 -7
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Priority map snapshots in the Smart CI ledger (smart-ci US-002).
3
+ *
4
+ * The priority map has no store of its own. It is one scope of US-001's
5
+ * ledger (src/lib/smart-ci/ledger.ts): company = the map's company,
6
+ * namespace = "priorities". Its records are:
7
+ *
8
+ * - `map-snapshot`: one per stored map. The body names the map (built-at
9
+ * time, digest, degraded or not); the map itself is the record's blob, kept
10
+ * by the ledger beside the record and checked against its sha256 on read.
11
+ * - `refresh-failed`: one per refresh that kept the previous map, naming each
12
+ * source that was down. That is the durable log of the failure.
13
+ * - `refresh-attempt`: one record, id "last", holding the time of the last
14
+ * attempt whatever came of it, so refreshDue backs off after a failure.
15
+ *
16
+ * Scope keys carry the company, so one company's records are never read for
17
+ * another. Snapshots are pruned to the newest 20 (their blobs go with them),
18
+ * failures to the newest 200.
19
+ *
20
+ * One writer (the M5 rule of US-001's review). The ledger has one owner
21
+ * process at a time. The priority map writes in one of two ways:
22
+ *
23
+ * - Hosted: inside the process that already owns the ledger (the intake,
24
+ * `hq ci intake --priorities <company>`), through that process's
25
+ * SmartCiLedger. Nothing is opened a second time.
26
+ * - Standalone: `hq ci priorities` with no owner running opens the ledger
27
+ * for the length of one write and closes it again.
28
+ *
29
+ * When another live process owns the ledger a standalone write is refused
30
+ * with LEDGER_HELD and nothing is written; reads never need ownership
31
+ * (readSmartCiSnapshot), so the stored map can always be printed. A store
32
+ * that has delivery workers enrolled is refused by SmartCiLedger.open before
33
+ * anything, blob included, is written.
34
+ */
35
+ import { randomBytes } from "node:crypto";
36
+ import { existsSync, readFileSync } from "node:fs";
37
+ import { hostname } from "node:os";
38
+ import { join } from "node:path";
39
+ import { DeliveryStoreError, parseStoreText } from "../delivery/migrations.js";
40
+ import { STATE_FILE } from "../delivery/store.js";
41
+ import { SmartCiLedger, SmartCiView, readSmartCiSnapshot } from "./ledger.js";
42
+ import { PRIORITY_MAP_SCHEMA } from "./priorities.js";
43
+ import { assertCompanySlug } from "./sources.js";
44
+ import { clip } from "./text.js";
45
+ export const PRIORITIES_NAMESPACE = "priorities";
46
+ export const SNAPSHOT_KIND = "map-snapshot";
47
+ export const FAILURE_KIND = "refresh-failed";
48
+ export const ATTEMPT_KIND = "refresh-attempt";
49
+ const ATTEMPT_ID = "last";
50
+ const DEFAULT_KEEP_SNAPSHOTS = 20;
51
+ const DEFAULT_KEEP_FAILURES = 200;
52
+ const READ_WAIT_MS = 2000;
53
+ /** Thrown, with nothing written, when another live process owns the ledger. */
54
+ export class LedgerHeldError extends Error {
55
+ dir;
56
+ code = "LEDGER_HELD";
57
+ constructor(dir, detail) {
58
+ super(`LEDGER_HELD: the Smart CI ledger in ${dir} is owned by another process, so the priority map was not stored there. That process stores it when it hosts the refresh (hq ci intake --priorities <company>). Nothing was written. (${detail.split("\n")[0]})`);
59
+ this.dir = dir;
60
+ this.name = "LedgerHeldError";
61
+ }
62
+ }
63
+ function scopeRef(company) {
64
+ assertCompanySlug(company);
65
+ return { company, namespace: PRIORITIES_NAMESPACE };
66
+ }
67
+ /** How many delivery workers the store in `dir` has on record. 0 when there is no store. Reads without any lock or ownership. */
68
+ export function enrolledWorkers(dir) {
69
+ const path = join(dir, STATE_FILE);
70
+ if (!existsSync(path))
71
+ return 0;
72
+ return parseStoreText(readFileSync(path, "utf8"), path).state.workers.length;
73
+ }
74
+ /** The records of the priorities scope, without taking ownership. */
75
+ function readScope(opts) {
76
+ const ref = scopeRef(opts.company);
77
+ if (opts.target.ledger)
78
+ return opts.target.ledger.view().scope(ref);
79
+ const dir = opts.target.dir;
80
+ return new SmartCiView(readSmartCiSnapshot(dir, READ_WAIT_MS), dir).scope(ref);
81
+ }
82
+ /** Run `fn` with a writer of the priorities scope: the hosting ledger, or this module's own short ownership of the directory. */
83
+ function withWriter(opts, fn) {
84
+ const ref = scopeRef(opts.company);
85
+ if (opts.target.ledger)
86
+ return fn(opts.target.ledger.scope(ref));
87
+ const dir = opts.target.dir;
88
+ let ledger;
89
+ try {
90
+ ledger = SmartCiLedger.open({ dir, controllerId: opts.controllerId ?? `smart-ci-priorities@${hostname()}`, clock: opts.clock });
91
+ }
92
+ catch (err) {
93
+ if (err instanceof DeliveryStoreError && (err.code === "CONTROLLER_OWNED" || err.code === "CONTROLLER_AMBIGUOUS"))
94
+ throw new LedgerHeldError(dir, err.message);
95
+ throw err;
96
+ }
97
+ try {
98
+ return fn(ledger.scope(ref));
99
+ }
100
+ finally {
101
+ ledger.close();
102
+ }
103
+ }
104
+ /**
105
+ * Whether this process can write the priority map now: true when it hosts the
106
+ * ledger, or when no other live process owns the directory. Answering costs one
107
+ * open and close of the ledger. Never throws.
108
+ */
109
+ export function ledgerWritable(opts) {
110
+ if (opts.target.ledger)
111
+ return { writable: true, reason: "this process owns the ledger" };
112
+ try {
113
+ withWriter({ ...opts }, () => undefined);
114
+ return { writable: true, reason: "no other process owns the ledger" };
115
+ }
116
+ catch (err) {
117
+ return { writable: false, reason: err instanceof Error ? err.message : String(err) };
118
+ }
119
+ }
120
+ const stamp = (ms) => new Date(ms).toISOString().replace(/[-:.]/g, "");
121
+ /** Store a new map as the last good one, and note the attempt, in one commit. Prunes old snapshots after. */
122
+ export function recordSnapshot(opts, map) {
123
+ if (map.company !== opts.company)
124
+ throw new Error(`the map is for company ${map.company}, not ${opts.company}; nothing was written`);
125
+ const text = JSON.stringify(map);
126
+ const nowMs = (opts.clock ?? Date.now)();
127
+ const builtMs = Number.isNaN(Date.parse(map.builtAt)) ? nowMs : Date.parse(map.builtAt);
128
+ return withWriter(opts, (scope) => {
129
+ // The id carries the build time and a nonce; the digest is the blob's sha256, set by the ledger.
130
+ const id = `${stamp(builtMs)}-${randomBytes(4).toString("hex")}`;
131
+ scope.putMany([
132
+ { kind: SNAPSHOT_KIND, id, body: { builtAt: map.builtAt, degraded: map.degraded, priorities: map.priorities.length }, blob: text },
133
+ { kind: ATTEMPT_KIND, id: ATTEMPT_ID, body: { at: new Date(nowMs).toISOString(), outcome: "stored" } },
134
+ ]);
135
+ const stored = scope.records(SNAPSHOT_KIND).find((r) => r.id === id);
136
+ try {
137
+ scope.prune(SNAPSHOT_KIND, { keepLatest: Math.max(1, opts.keepSnapshots ?? DEFAULT_KEEP_SNAPSHOTS) });
138
+ }
139
+ catch (err) {
140
+ // Pruning is housekeeping. The snapshot is already stored.
141
+ opts.log?.(`smart-ci priorities: old snapshots were not pruned: ${err instanceof Error ? err.message : String(err)}`);
142
+ }
143
+ return { id, status: "succeeded", at: stored?.updatedAt ?? new Date(nowMs).toISOString(), digest: blobDigest(stored?.body), failures: [] };
144
+ });
145
+ }
146
+ /** Log a refresh that kept the previous map: one record naming each source that was down. Also notes the attempt. */
147
+ export function recordFailure(opts, failures) {
148
+ const nowMs = (opts.clock ?? Date.now)();
149
+ const list = (failures.length > 0 ? failures : [{ source: "unknown", message: "no reason given" }]).map((f) => ({ source: f.source, message: clip(f.message, 300) }));
150
+ return withWriter(opts, (scope) => {
151
+ const id = `${stamp(nowMs)}-${randomBytes(4).toString("hex")}`;
152
+ scope.putMany([
153
+ { kind: FAILURE_KIND, id, body: { failures: list } },
154
+ { kind: ATTEMPT_KIND, id: ATTEMPT_ID, body: { at: new Date(nowMs).toISOString(), outcome: "kept" } },
155
+ ]);
156
+ const stored = scope.records(FAILURE_KIND).find((r) => r.id === id);
157
+ try {
158
+ scope.prune(FAILURE_KIND, { keepLatest: Math.max(1, opts.keepFailures ?? DEFAULT_KEEP_FAILURES) });
159
+ }
160
+ catch (err) {
161
+ // Housekeeping only. The failure is already stored.
162
+ opts.log?.(`smart-ci priorities: old failure records were not pruned: ${err instanceof Error ? err.message : String(err)}`);
163
+ }
164
+ return { id, status: "failed", at: stored?.updatedAt ?? new Date(nowMs).toISOString(), digest: "", failures: list };
165
+ });
166
+ }
167
+ /**
168
+ * Note the time of a refresh attempt, whatever came of it. Best effort:
169
+ * returns false, with nothing written, when the ledger cannot be written
170
+ * (another owner, or a store with delivery workers).
171
+ */
172
+ export function noteAttempt(opts) {
173
+ const nowMs = (opts.clock ?? Date.now)();
174
+ try {
175
+ withWriter(opts, (scope) => scope.put(ATTEMPT_KIND, ATTEMPT_ID, { at: new Date(nowMs).toISOString(), outcome: "attempted" }));
176
+ return true;
177
+ }
178
+ catch (err) {
179
+ opts.log?.(`smart-ci priorities: the attempt time was not noted in the ledger: ${err instanceof Error ? err.message : String(err)}`);
180
+ return false;
181
+ }
182
+ }
183
+ /** When the last refresh attempt was noted (epoch milliseconds), or NaN when none was. */
184
+ export function lastAttemptMs(opts) {
185
+ try {
186
+ const at = readScope(opts).get(ATTEMPT_KIND, ATTEMPT_ID)?.at;
187
+ return typeof at === "string" ? Date.parse(at) : Number.NaN;
188
+ }
189
+ catch {
190
+ // An unreadable ledger has no attempt on record; refreshDue also checks this process's own note.
191
+ return Number.NaN;
192
+ }
193
+ }
194
+ function blobDigest(body) {
195
+ const ref = body?.$blob;
196
+ return typeof ref?.sha256 === "string" ? ref.sha256 : "";
197
+ }
198
+ function toRefresh(r, status) {
199
+ const failures = status === "failed" && Array.isArray(r.body.failures) ? r.body.failures : [];
200
+ return { id: r.id, status, at: r.updatedAt, digest: status === "succeeded" ? blobDigest(r.body) : "", failures };
201
+ }
202
+ /** Every stored or failed refresh of the company that is still kept, oldest first. Empty when there is no ledger yet. */
203
+ export function readRefreshLog(opts) {
204
+ const scope = readScope(opts);
205
+ const all = [...scope.records(SNAPSHOT_KIND).map((r) => toRefresh(r, "succeeded")), ...scope.records(FAILURE_KIND).map((r) => toRefresh(r, "failed"))];
206
+ return all.sort((a, b) => Date.parse(a.at) - Date.parse(b.at) || a.id.localeCompare(b.id));
207
+ }
208
+ /**
209
+ * The newest map stored for the company, or null. Reads the ledger and one
210
+ * blob; calls no source. A snapshot whose blob is missing, does not match its
211
+ * hash, or is not a map of this company is passed over for the one before it.
212
+ */
213
+ export function readLastGood(opts) {
214
+ const scope = readScope(opts);
215
+ const snapshots = scope.records(SNAPSHOT_KIND).sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt) || b.id.localeCompare(a.id));
216
+ for (const r of snapshots) {
217
+ let map;
218
+ try {
219
+ const bytes = scope.blob(SNAPSHOT_KIND, r.id);
220
+ if (bytes === null)
221
+ continue;
222
+ map = JSON.parse(bytes.toString("utf8"));
223
+ }
224
+ catch {
225
+ continue;
226
+ }
227
+ if (map.schema !== PRIORITY_MAP_SCHEMA || map.company !== opts.company)
228
+ continue;
229
+ return { map, record: toRefresh(r, "succeeded") };
230
+ }
231
+ return null;
232
+ }
233
+ //# sourceMappingURL=priority-snapshots.js.map
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Smart CI records (smart-ci US-001).
3
+ *
4
+ * Two shapes live here. An Observation is what the intake saw: one GitHub
5
+ * workflow run, job, check run, pull request, push, or one sample of the
6
+ * runner pools, reduced to the fields Smart CI uses. A record body is what the
7
+ * ledger keeps: one per run, job, check run, pull request, push and sample,
8
+ * keyed so that the same observation written twice is still one record.
9
+ *
10
+ * Observations carry no actor, author, email or commit message. The fields are
11
+ * picked one by one from the API response, so nothing else can ride along.
12
+ * Every time in a record comes from GitHub, except a runner sample's
13
+ * sampledAt, which is the clock reading when the sample was taken.
14
+ */
15
+ export declare const SMART_CI_TENANT = "smart-ci";
16
+ export declare const KIND: {
17
+ readonly run: "ci.run";
18
+ readonly job: "ci.job";
19
+ readonly checkRun: "ci.check_run";
20
+ readonly pullRequest: "ci.pull_request";
21
+ readonly push: "ci.push";
22
+ readonly runnerSample: "ci.runner_sample";
23
+ /** A stretch of a stream the intake did not read (page limit or request budget). Written so a hole is visible. */
24
+ readonly gap: "ci.gap";
25
+ };
26
+ /** The kinds the intake moves to archive files once they are old and closed. */
27
+ export declare const ROTATED_KINDS: readonly string[];
28
+ export interface GapBody extends Record<string, unknown> {
29
+ repo: string;
30
+ stream: "runs" | "pulls" | "activity";
31
+ /** Not read: from here (ISO, inclusive)... */
32
+ from: string;
33
+ /** ...to here (ISO, exclusive). */
34
+ to: string;
35
+ reason: string;
36
+ notedAt: string;
37
+ }
38
+ export type SmartCiKind = (typeof KIND)[keyof typeof KIND];
39
+ export type JobStatus = "queued" | "in_progress" | "completed";
40
+ export interface RunObservation {
41
+ id: number;
42
+ attempt: number;
43
+ name: string;
44
+ event: string;
45
+ status: JobStatus;
46
+ conclusion: string | null;
47
+ headBranch: string | null;
48
+ headSha: string;
49
+ createdAt: string;
50
+ startedAt: string | null;
51
+ updatedAt: string | null;
52
+ prNumbers: number[];
53
+ /** True once every job of this attempt has been recorded after the run completed. */
54
+ jobsFinal?: boolean;
55
+ }
56
+ export interface JobObservation {
57
+ id: number;
58
+ runId: number;
59
+ runAttempt: number;
60
+ workflow: string;
61
+ name: string;
62
+ headBranch: string | null;
63
+ headSha: string;
64
+ status: JobStatus;
65
+ conclusion: string | null;
66
+ /** GitHub created_at: when the job entered the queue. */
67
+ createdAt: string;
68
+ startedAt: string | null;
69
+ completedAt: string | null;
70
+ labels: string[];
71
+ runnerName: string | null;
72
+ runnerGroup: string | null;
73
+ }
74
+ export interface CheckRunObservation {
75
+ id: number;
76
+ name: string;
77
+ headSha: string;
78
+ status: JobStatus;
79
+ conclusion: string | null;
80
+ startedAt: string | null;
81
+ completedAt: string | null;
82
+ app: string | null;
83
+ }
84
+ export interface PullRequestObservation {
85
+ number: number;
86
+ title: string;
87
+ state: "open" | "closed";
88
+ draft: boolean;
89
+ createdAt: string;
90
+ updatedAt: string;
91
+ closedAt: string | null;
92
+ mergedAt: string | null;
93
+ mergeCommitSha: string | null;
94
+ headSha: string;
95
+ headRef: string;
96
+ baseRef: string;
97
+ labels: string[];
98
+ }
99
+ export interface PushObservation {
100
+ id: number;
101
+ ref: string;
102
+ before: string;
103
+ after: string;
104
+ at: string;
105
+ activityType: string;
106
+ }
107
+ export interface PoolCount {
108
+ pool: string;
109
+ online: number;
110
+ busy: number;
111
+ idle: number;
112
+ offline: number;
113
+ }
114
+ export interface RunnerSampleObservation {
115
+ sampledAt: string;
116
+ total: number;
117
+ pools: PoolCount[];
118
+ }
119
+ export type Observation = {
120
+ type: "workflow_run";
121
+ repo: string;
122
+ run: RunObservation;
123
+ } | {
124
+ type: "workflow_job";
125
+ repo: string;
126
+ job: JobObservation;
127
+ } | {
128
+ type: "check_run";
129
+ repo: string;
130
+ checkRun: CheckRunObservation;
131
+ } | {
132
+ type: "pull_request";
133
+ repo: string;
134
+ pr: PullRequestObservation;
135
+ } | {
136
+ type: "push";
137
+ repo: string;
138
+ push: PushObservation;
139
+ } | {
140
+ type: "runner_pool";
141
+ org: string;
142
+ sample: RunnerSampleObservation;
143
+ };
144
+ export declare const OBSERVATION_TYPES: readonly Observation["type"][];
145
+ /** A later push that moved the branch off this job's head before the job finished. */
146
+ export interface Replacement {
147
+ bySha: string;
148
+ at: string;
149
+ pushId: number;
150
+ }
151
+ export interface RunBody extends Record<string, unknown> {
152
+ repo: string;
153
+ runId: number;
154
+ attempt: number;
155
+ name: string;
156
+ event: string;
157
+ status: JobStatus;
158
+ conclusion: string | null;
159
+ headBranch: string | null;
160
+ headSha: string;
161
+ createdAt: string;
162
+ startedAt: string | null;
163
+ updatedAt: string | null;
164
+ prNumbers: number[];
165
+ jobsFinal: boolean;
166
+ }
167
+ export interface JobBody extends Record<string, unknown> {
168
+ repo: string;
169
+ jobId: number;
170
+ runId: number;
171
+ runAttempt: number;
172
+ workflow: string;
173
+ name: string;
174
+ /** The workflow run's trigger (pull_request, push, ...), or null until the run is recorded. */
175
+ event: string | null;
176
+ headBranch: string | null;
177
+ headSha: string;
178
+ status: JobStatus;
179
+ conclusion: string | null;
180
+ queuedAt: string;
181
+ startedAt: string | null;
182
+ finishedAt: string | null;
183
+ labels: string[];
184
+ /** The runner pool: the first runs-on label that is not a generic one, else the runner group. */
185
+ pool: string;
186
+ runnerName: string | null;
187
+ runnerGroup: string | null;
188
+ replaced: Replacement | null;
189
+ }
190
+ export interface CheckRunBody extends Record<string, unknown> {
191
+ repo: string;
192
+ checkRunId: number;
193
+ name: string;
194
+ headSha: string;
195
+ status: JobStatus;
196
+ conclusion: string | null;
197
+ startedAt: string | null;
198
+ completedAt: string | null;
199
+ app: string | null;
200
+ }
201
+ export interface PullRequestBody extends Record<string, unknown> {
202
+ repo: string;
203
+ number: number;
204
+ title: string;
205
+ state: "open" | "closed";
206
+ draft: boolean;
207
+ createdAt: string;
208
+ updatedAt: string;
209
+ closedAt: string | null;
210
+ mergedAt: string | null;
211
+ mergeCommitSha: string | null;
212
+ headSha: string;
213
+ headRef: string;
214
+ baseRef: string;
215
+ labels: string[];
216
+ }
217
+ export interface PushBody extends Record<string, unknown> {
218
+ repo: string;
219
+ pushId: number;
220
+ ref: string;
221
+ before: string;
222
+ after: string;
223
+ at: string;
224
+ activityType: string;
225
+ }
226
+ export interface RunnerSampleBody extends Record<string, unknown> {
227
+ org: string;
228
+ sampledAt: string;
229
+ total: number;
230
+ pools: PoolCount[];
231
+ }
232
+ export declare const runKey: (repo: string, runId: number, attempt: number) => string;
233
+ export declare const jobKey: (repo: string, jobId: number) => string;
234
+ export declare const checkRunKey: (repo: string, id: number) => string;
235
+ export declare const pullRequestKey: (repo: string, number: number) => string;
236
+ export declare const pushKey: (repo: string, id: number) => string;
237
+ export declare const runnerSampleKey: (org: string, sampledAt: string) => string;
238
+ export declare const statusRank: (s: JobStatus) => number;
239
+ /** GitHub reports several not-yet-running states; Smart CI records them all as queued. */
240
+ export declare function normalizeStatus(raw: unknown): JobStatus;
241
+ /**
242
+ * The pool a job ran on or asked for. A self-hosted job names its pool in
243
+ * runs-on (hq-cli-x64, hq-mac-light); a GitHub-hosted job's label is the image
244
+ * (ubuntu-latest). With no usable label the runner group is the pool.
245
+ */
246
+ export declare function poolOf(labels: readonly string[], runnerGroup: string | null): string;
247
+ /** True when the job asked for a GitHub-hosted runner (no self-hosted label, not in a self-hosted group). */
248
+ export declare function isHosted(job: Pick<JobBody, "labels" | "runnerGroup">): boolean;
249
+ /** GitHub REST workflow run to observation. Array and string fields are coerced here, at the parse boundary. */
250
+ export declare function runFromApi(raw: unknown): RunObservation;
251
+ export declare function jobFromApi(raw: unknown): JobObservation;
252
+ export declare function checkRunFromApi(raw: unknown): CheckRunObservation;
253
+ export declare function pullRequestFromApi(raw: unknown): PullRequestObservation;
254
+ export declare function pushFromApi(raw: unknown): PushObservation;
255
+ /** Pool of a registered runner: its first label that is not a generic one, else its name with digits removed. */
256
+ export declare function runnerPool(raw: unknown): string;
257
+ /** Reduce a list of registered runners to counts per pool. No runner name is kept. */
258
+ export declare function runnerSampleFromApi(runners: readonly unknown[], sampledAt: string): RunnerSampleObservation;
259
+ /**
260
+ * Problems with one observation, or [] when it can be recorded. Used on every
261
+ * fixture line and on everything the poller builds, so a malformed input is
262
+ * refused with a reason instead of becoming a half-filled record.
263
+ */
264
+ export declare function validateObservation(input: unknown): string[];
265
+ //# sourceMappingURL=records.d.ts.map