@hearsay-tools/squawk 0.18.0-pr4089.7823 → 0.18.0-pr4090.7828
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/activity/read-model.d.ts +3 -1
- package/dist/activity/read-model.js +17 -15
- package/dist/activity/read-model.js.map +1 -1
- package/dist/activity/requests.d.ts +3 -1
- package/dist/activity/requests.js +1 -1
- package/dist/activity/requests.js.map +1 -1
- package/dist/automations/service.js +1 -1
- package/dist/automations/service.js.map +1 -1
- package/dist/automations/task-template.js +3 -3
- package/dist/automations/task-template.js.map +1 -1
- package/dist/ci-wait/controller.d.ts +46 -46
- package/dist/delegation/conversations.d.ts +6 -2
- package/dist/delegation/conversations.js +1 -1
- package/dist/delegation/conversations.js.map +1 -1
- package/dist/delegation/family-end.d.ts +4 -2
- package/dist/delegation/family-end.js +1 -1
- package/dist/delegation/family-end.js.map +1 -1
- package/dist/delegation/routes.d.ts +10 -10
- package/dist/delegation/scratch-cleanup.js +2 -2
- package/dist/delegation/scratch-cleanup.js.map +1 -1
- package/dist/delegation/task-discovery.js +1 -1
- package/dist/delegation/task-discovery.js.map +1 -1
- package/dist/delegation/transport.d.ts +14 -14
- package/dist/delegation/worker-cleanup.js +4 -4
- package/dist/delegation/worker-cleanup.js.map +1 -1
- package/dist/project-commands.js +1 -1
- package/dist/project-commands.js.map +1 -1
- package/dist/project-migration/live.js +1 -1
- package/dist/project-migration/live.js.map +1 -1
- package/dist/runs/branch-owners.d.ts +2 -2
- package/dist/runs/cold-reads.d.ts +1 -1
- package/dist/runs/cold-reads.js +1 -1
- package/dist/runs/live-tasks.js +1 -1
- package/dist/runs/live-tasks.js.map +1 -1
- package/dist/runs/ports.d.ts +50 -28
- package/dist/runs/retention.d.ts +4 -3
- package/dist/runs/retention.js +2 -2
- package/dist/runs/retention.js.map +1 -1
- package/dist/runs/run-cold-reads.d.ts +98 -0
- package/dist/runs/run-cold-reads.js +194 -0
- package/dist/runs/run-cold-reads.js.map +1 -0
- package/dist/runs/run-queries.d.ts +190 -0
- package/dist/runs/run-queries.js +480 -0
- package/dist/runs/run-queries.js.map +1 -0
- package/dist/runs/run-repo-scope.d.ts +38 -0
- package/dist/runs/run-repo-scope.js +78 -0
- package/dist/runs/run-repo-scope.js.map +1 -0
- package/dist/runs/store.d.ts +9 -222
- package/dist/runs/store.js +82 -738
- package/dist/runs/store.js.map +1 -1
- package/dist/serve-boot.d.ts +3 -1
- package/dist/serve-boot.js +2 -2
- package/dist/serve-boot.js.map +1 -1
- package/dist/server/models-routes.d.ts +13 -13
- package/dist/server/project-context.js +3 -3
- package/dist/server/project-context.js.map +1 -1
- package/dist/server/repo-branches.d.ts +5 -3
- package/dist/server/repo-branches.js +1 -1
- package/dist/server/repo-branches.js.map +1 -1
- package/dist/server/reports-api.d.ts +2 -2
- package/dist/server/run-checkout.d.ts +3 -1
- package/dist/server/run-checkout.js +2 -2
- package/dist/server/run-checkout.js.map +1 -1
- package/dist/server/run-relationships.d.ts +3 -1
- package/dist/server/run-relationships.js +1 -1
- package/dist/server/run-relationships.js.map +1 -1
- package/dist/server/server.js +12 -12
- package/dist/server/server.js.map +1 -1
- package/dist/server/workspace-live-routes.d.ts +6 -6
- package/dist/workflows/run/auto-resume.js +2 -2
- package/dist/workflows/run/auto-resume.js.map +1 -1
- package/dist/workflows/run/completion-gate.js +1 -1
- package/dist/workflows/run/completion-gate.js.map +1 -1
- package/dist/workflows/run/family-reconciler.js +8 -8
- package/dist/workflows/run/family-reconciler.js.map +1 -1
- package/dist/workflows/run/maintenance-claims.js +2 -2
- package/dist/workflows/run/maintenance-claims.js.map +1 -1
- package/dist/workflows/run/run-cancel.js +1 -1
- package/dist/workflows/run/run-cancel.js.map +1 -1
- package/dist/workflows/run/run-line.js +2 -2
- package/dist/workflows/run/run-line.js.map +1 -1
- package/dist/workflows/run/run-recovery.js +6 -6
- package/dist/workflows/run/run-recovery.js.map +1 -1
- package/dist/workflows/run/run-start.js +1 -1
- package/dist/workflows/run/run-start.js.map +1 -1
- package/dist/workflows/run/wake-admission.js +1 -1
- package/dist/workflows/run/wake-admission.js.map +1 -1
- package/dist/workflows/run/worker-questions.js +3 -3
- package/dist/workflows/run/worker-questions.js.map +1 -1
- package/dist/workflows/run.js +1 -1
- package/dist/workflows/run.js.map +1 -1
- package/package.json +4 -4
- package/scripts/benchmark-automation-lookups.ts +2 -2
- package/scripts/benchmark-conversation-lookup.ts +2 -2
- package/scripts/benchmark-family-reconcile.ts +1 -1
- package/scripts/benchmark-worktree-retention.ts +1 -1
- package/scripts/seed-archive-profile.ts +2 -2
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { ArchivedRunsResponse, RunSummary } from '../contract/index.js';
|
|
2
|
+
import { type AutomationNames } from '../contract/index.js';
|
|
3
|
+
import { type BranchOwner } from './branch-owners.ts';
|
|
4
|
+
import type { ColdReadCache, StoredRow } from './cold-reads.ts';
|
|
5
|
+
import type { RunFamilyReads, RunQueries } from './ports.ts';
|
|
6
|
+
import type { RunColdReadsTopic } from './run-cold-reads.ts';
|
|
7
|
+
import { type RunDatabase } from './run-database.ts';
|
|
8
|
+
import type { RunPinHolder } from './run-pins.ts';
|
|
9
|
+
import { type ListOrder } from './run-row.ts';
|
|
10
|
+
import { type PeerTaskPageOptions } from './run-summary-page.ts';
|
|
11
|
+
import type { RunRecord } from './store.ts';
|
|
12
|
+
/** The items newest first, each by the order beside it. Stable: ties keep their input order. */
|
|
13
|
+
export declare function sortNewestFirst<T>(entries: Iterable<readonly [T, ListOrder]>): T[];
|
|
14
|
+
/** What the topic asks of the store; no import of `store.ts` values. */
|
|
15
|
+
export interface QueriesState {
|
|
16
|
+
/** The open database; null for an unavailable or closed store. */
|
|
17
|
+
db(): RunDatabase | null;
|
|
18
|
+
readonly held: Map<string, RunRecord>;
|
|
19
|
+
readonly pins: Map<string, Set<RunPinHolder>>;
|
|
20
|
+
readonly deleted: Set<string>;
|
|
21
|
+
readonly unreadable: Set<string>;
|
|
22
|
+
readonly base: Map<string, StoredRow>;
|
|
23
|
+
readonly coldReads: Pick<ColdReadCache, 'scope'>;
|
|
24
|
+
readonly rows: Pick<RunColdReadsTopic, 'loadCold' | 'decodeCold' | 'fromRow'>;
|
|
25
|
+
/** The store's `getRun`, so a spy on it sees the queries' reads. */
|
|
26
|
+
getRun(id: string): RunRecord | undefined;
|
|
27
|
+
}
|
|
28
|
+
export declare class RunQueriesTopic implements RunQueries, RunFamilyReads {
|
|
29
|
+
private readonly state;
|
|
30
|
+
constructor(state: QueriesState);
|
|
31
|
+
private get db();
|
|
32
|
+
private get held();
|
|
33
|
+
private get pins();
|
|
34
|
+
private get deleted();
|
|
35
|
+
private get unreadable();
|
|
36
|
+
private get base();
|
|
37
|
+
private get coldReads();
|
|
38
|
+
private loadCold;
|
|
39
|
+
private decodeCold;
|
|
40
|
+
private fromRow;
|
|
41
|
+
private getRun;
|
|
42
|
+
/**
|
|
43
|
+
* The live set, newest first: runs whose record is live (`isLiveRecord`) or that a RunManager
|
|
44
|
+
* pins. Finished runs are not here — read one by id (`getRun`), by an indexed query
|
|
45
|
+
* (`listWorkersOf`, `findRunByClientRequestId`, `listRunsWithWorktree`,
|
|
46
|
+
* `listBranchOwners`), or as list rows (`listRunSummaries`).
|
|
47
|
+
*/
|
|
48
|
+
listRuns(): RunRecord[];
|
|
49
|
+
/** Where a held run lists: its row's insertion order, or after every row while this store has
|
|
50
|
+
* not written it yet. The held set keeps such runs in creation order, and so does every list
|
|
51
|
+
* that sorts them in held-set order (`sortNewestFirst` is stable). */
|
|
52
|
+
listOrder(run: RunRecord): ListOrder;
|
|
53
|
+
/**
|
|
54
|
+
* EVERY run as a full record, newest first — decoded row by row. Only the legacy `GET /runs`
|
|
55
|
+
* (older clients; the cockpit reads `GET /run-summaries`) may call this: it is exactly the
|
|
56
|
+
* whole-history parse #779 exists to remove from everything else.
|
|
57
|
+
*/
|
|
58
|
+
listAllRunsForLegacyRoute(): RunRecord[];
|
|
59
|
+
/** A bounded page of discoverable peer roots, including the current held overlay. */
|
|
60
|
+
listPeerTaskSummaries(options: PeerTaskPageOptions): {
|
|
61
|
+
runs: RunSummary[];
|
|
62
|
+
nextOffset?: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Every run as its list row, newest first: the stored `summary` column, with each held run's
|
|
66
|
+
* own projection laid over it — a debounced save keeps memory up to 300 ms ahead of the row,
|
|
67
|
+
* and a run created since the last save has no row yet. `usage` is the caller's to attach.
|
|
68
|
+
*
|
|
69
|
+
* With `archivedWindow` (#864), the window the cockpit's lists read: every unarchived run, plus
|
|
70
|
+
* the newest `archivedWindow` archived ROOT runs, and whether older archived roots were left
|
|
71
|
+
* out. Archived workers are never in it (see `RunDatabase.listWindowSummaries`); with `roots`,
|
|
72
|
+
* no worker is — the runs index, whose readers list no workers. A held run
|
|
73
|
+
* lists by its record, so one archived or unarchived since the last save is ranked as it is now.
|
|
74
|
+
*
|
|
75
|
+
* A row this store found unreadable is left out, as the cold reader leaves out a row it had to
|
|
76
|
+
* decode and could not. A finished row nobody has decoded is served from its summary by both,
|
|
77
|
+
* which decodes nothing; reading it is what finds out (`isUnreadable`).
|
|
78
|
+
*/
|
|
79
|
+
listRunSummaries(options?: {
|
|
80
|
+
archivedWindow?: number | undefined;
|
|
81
|
+
roots?: boolean;
|
|
82
|
+
}): {
|
|
83
|
+
runs: RunSummary[];
|
|
84
|
+
truncated: boolean;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* One page of archived ROOT runs, newest first (#864): `GET /run-summaries/archived`, the
|
|
88
|
+
* archived runs past the window. Held runs list by their record, as in `listRunSummaries`.
|
|
89
|
+
* `before` is the previous page's `nextCursor`; with `q`, only runs `matchesRunSearch` keeps, and
|
|
90
|
+
* `total` counts those. `automationNames` lets `q` match a task by its automation's name, as the
|
|
91
|
+
* list's origin line shows it (hearsay-tools/cezarion#1616). A cursor this store did not write
|
|
92
|
+
* answers `{ error }`.
|
|
93
|
+
*
|
|
94
|
+
* Ranking reads every archived root's key (id, created_at, seq: no record, no summary), so the
|
|
95
|
+
* page and `total` agree with the held overlay; only the page's own rows are read in full.
|
|
96
|
+
*/
|
|
97
|
+
listArchivedRuns(options: {
|
|
98
|
+
before?: string;
|
|
99
|
+
limit: number;
|
|
100
|
+
q?: string;
|
|
101
|
+
automationNames?: AutomationNames;
|
|
102
|
+
}): ArchivedRunsResponse | {
|
|
103
|
+
error: string;
|
|
104
|
+
};
|
|
105
|
+
/** The archived roots in `runs.db`, each by its key: every one without `q` (no record, no
|
|
106
|
+
* summary read), and with `q` the searched rows `matchesRunSearch` keeps, which carry the summary
|
|
107
|
+
* the search read. A deleted, held or unreadable run's row is left out; a held run joins in
|
|
108
|
+
* `overlayHeldArchived`. */
|
|
109
|
+
private rankArchivedRows;
|
|
110
|
+
/** Lay the held archived roots over `ranked`, each by its record: it replaces its stored row
|
|
111
|
+
* (already left out of `ranked`), and with `q` it must match. A held worker never lists. */
|
|
112
|
+
private overlayHeldArchived;
|
|
113
|
+
/** The page of `ordered` after the cursor `after`: its summaries, the cursor of the next page,
|
|
114
|
+
* and `total`, the count of all of `ordered`. */
|
|
115
|
+
private archivedPage;
|
|
116
|
+
/** The page's summaries: a ranked key's own, else its stored one, read for the rows that have
|
|
117
|
+
* none in a single query. A row whose stored summary does not fit the contract is projected from
|
|
118
|
+
* its record; a row that cannot be read at all is left out. */
|
|
119
|
+
private hydrateArchivedPage;
|
|
120
|
+
/**
|
|
121
|
+
* The ROOT runs, archived or not, that match `query` (`matchesRunSearch`), newest first: at most
|
|
122
|
+
* `limit`, and whether more matched. The owned half of the workspace search (#864); held runs
|
|
123
|
+
* match by their record.
|
|
124
|
+
*/
|
|
125
|
+
searchRunSummaries(query: string, limit: number): {
|
|
126
|
+
runs: RunSummary[];
|
|
127
|
+
truncated: boolean;
|
|
128
|
+
};
|
|
129
|
+
/** A row whose stored summary does not fit the contract any more, projected from its record. */
|
|
130
|
+
private coldSummary;
|
|
131
|
+
/** Run `fn` reading each run that is not held at most once (`ColdReadCache`, hearsay-tools/cezarion#2378). */
|
|
132
|
+
withReadCache<T>(fn: () => T): T;
|
|
133
|
+
/** The ids in memory right now: the held set, for diagnostics and the benchmark's heap pass. */
|
|
134
|
+
heldIds(): string[];
|
|
135
|
+
/**
|
|
136
|
+
* The workers a root run owns, newest first, read off its own `receipts` (#659). Every
|
|
137
|
+
* `createOwnedRun` writes the receipt and the worker record in one transaction, and the
|
|
138
|
+
* receipt list is capped at 1,024 creations (#816), so this is a bounded lookup rather than a walk of the whole
|
|
139
|
+
* project index. An ordinary or worker run owns nothing and costs one map read; a receipt
|
|
140
|
+
* whose record has been deleted is skipped, never invented. A parent quarantined to
|
|
141
|
+
* `invalid` has no readable receipts and reports none, which is also what the cockpit
|
|
142
|
+
* assumes for that role.
|
|
143
|
+
*/
|
|
144
|
+
listOwnedWorkers(parentId: string): RunRecord[];
|
|
145
|
+
/** Every worker filed under `parentId` (the `parent_run_id` index plus memory), newest first:
|
|
146
|
+
* receipts or not, which is what the reconcile and deletion checks ask. */
|
|
147
|
+
listWorkersOf(parentId: string): RunRecord[];
|
|
148
|
+
/** The id of every worker, held or stored, without decoding any (recovery's worker passes). */
|
|
149
|
+
listWorkerIds(): string[];
|
|
150
|
+
/** The id of every run whose delegation is quarantined (`invalid`), held or stored: its stored
|
|
151
|
+
* summary says so, so nothing is decoded (scratch cleanup). */
|
|
152
|
+
listQuarantinedRunIds(): string[];
|
|
153
|
+
/** All retained tasks this automation started, including variants, finished and archived runs.
|
|
154
|
+
* Logs and receipts may compact independently. Read only matching keys in SQLite and overlay
|
|
155
|
+
* held records so a debounced provenance update or deletion is reflected immediately. */
|
|
156
|
+
countAutomationRuns(automationId: string): number;
|
|
157
|
+
/** First non-archived task referencing a project issue, including secondary references. */
|
|
158
|
+
findNonArchivedRunByIssue(repo: string, number: number): string | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* The runs automation receipts launched, by receipt id (`automation.receiptId` or
|
|
161
|
+
* `automationTrigger.receiptId`). Memory answers first; a receipt it does not know costs one
|
|
162
|
+
* pass over `runs.db` that reads the records' JSON in SQLite — only a crash leftover (a
|
|
163
|
+
* receipt still `reserved` at startup) ever asks.
|
|
164
|
+
*/
|
|
165
|
+
findRunIdsByAutomationReceipt(receiptIds: readonly string[]): Map<string, string>;
|
|
166
|
+
/** The id of every root whose delegation carries a conversation, held or stored: recovery's full
|
|
167
|
+
* reconcile pass (#661). `naming` keeps the ledgers whose messages name that run id as sender or
|
|
168
|
+
* recipient. Stored roots come from the `conversation_members` index, so no record is read. */
|
|
169
|
+
listConversationRootIds(naming?: string): string[];
|
|
170
|
+
/** The id of every run, held or stored, without decoding any (orphan-worktree sweeps). */
|
|
171
|
+
listRunIds(): string[];
|
|
172
|
+
/** Runs with a materialized worktree directory (`worktreePath`, not reclaimed), most recently
|
|
173
|
+
* finished first, then newest first: worktree retention and the worktrees panel. */
|
|
174
|
+
listRunsWithWorktree(): RunRecord[];
|
|
175
|
+
/**
|
|
176
|
+
* Every run that owns a branch or names the PR it created, as the few fields branch cleanup and
|
|
177
|
+
* git-log attribution read (issue 08 §B3, §B5; a squash commit is attributed by its PR number):
|
|
178
|
+
* the stored summary plus the `branch` and `base_branch` columns, so a Git-tab request decodes
|
|
179
|
+
* no record. Held runs answer from memory.
|
|
180
|
+
*/
|
|
181
|
+
listBranchOwners(): BranchOwner[];
|
|
182
|
+
/** The rows a column query returned, as records, with memory laid over them: a held run
|
|
183
|
+
* answers from memory (matching `matches` there, not on its maybe-older row). */
|
|
184
|
+
private queryRuns;
|
|
185
|
+
/** The run an idempotent start already created (#504), archived or not. A deleted run is gone
|
|
186
|
+
* with its record, so a retry after deletion honestly creates a fresh one. */
|
|
187
|
+
findRunByClientRequestId(clientRequestId: string): RunRecord | undefined;
|
|
188
|
+
/** Indexed family enumeration, including members not yet flushed to SQLite. */
|
|
189
|
+
listFamilyRunIds(rootId: string): string[];
|
|
190
|
+
}
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The list and find queries over a project's runs (hearsay-tools/squawk#4044): the live set, the
|
|
3
|
+
* list rows and their archived window and pages, the workspace search, the workers of a run and
|
|
4
|
+
* the indexed finds. Each query lays the held records over the rows it read. `RunStore` keeps one
|
|
5
|
+
* of these as `store.queries`.
|
|
6
|
+
*/
|
|
7
|
+
import { toRunSummary } from '../contract/index.js';
|
|
8
|
+
import { matchesRunSearch, sqlPrefilterTokens } from '../contract/index.js';
|
|
9
|
+
import { listBranchOwners } from './branch-owners.js';
|
|
10
|
+
import { guardedJsonSql } from './guarded-json-sql.js';
|
|
11
|
+
import { ARCHIVED_ROOT } from './run-database.js';
|
|
12
|
+
import { ISSUE_URL_RE } from './run-references.js';
|
|
13
|
+
import { familyRootOf, isLiveRecord, materializedWorktreePath, newestFirst } from './run-row.js';
|
|
14
|
+
import { listPeerTaskSummaries, parseStoredSummary } from './run-summary-page.js';
|
|
15
|
+
/** An archived page's cursor: the last row's order, opaque to clients. A held run with no row yet
|
|
16
|
+
* lists after every row (`seq` is infinite), which JSON cannot carry, so it travels as null. */
|
|
17
|
+
function encodeArchivedCursor(key) {
|
|
18
|
+
return Buffer.from(JSON.stringify({ c: key.createdAt, s: Number.isFinite(key.seq) ? key.seq : null })).toString('base64url');
|
|
19
|
+
}
|
|
20
|
+
function decodeArchivedCursor(cursor) {
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
|
|
23
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
24
|
+
return undefined;
|
|
25
|
+
const { c, s } = parsed;
|
|
26
|
+
if (typeof c !== 'string' || !(s === null || (typeof s === 'number' && Number.isInteger(s))))
|
|
27
|
+
return undefined;
|
|
28
|
+
return { createdAt: c, seq: s ?? Number.POSITIVE_INFINITY };
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** The items newest first, each by the order beside it. Stable: ties keep their input order. */
|
|
35
|
+
export function sortNewestFirst(entries) {
|
|
36
|
+
return [...entries].sort(([, a], [, b]) => newestFirst(a, b)).map(([item]) => item);
|
|
37
|
+
}
|
|
38
|
+
export class RunQueriesTopic {
|
|
39
|
+
state;
|
|
40
|
+
constructor(state) {
|
|
41
|
+
this.state = state;
|
|
42
|
+
}
|
|
43
|
+
get db() { return this.state.db(); }
|
|
44
|
+
get held() { return this.state.held; }
|
|
45
|
+
get pins() { return this.state.pins; }
|
|
46
|
+
get deleted() { return this.state.deleted; }
|
|
47
|
+
get unreadable() { return this.state.unreadable; }
|
|
48
|
+
get base() { return this.state.base; }
|
|
49
|
+
get coldReads() { return this.state.coldReads; }
|
|
50
|
+
loadCold(id) { return this.state.rows.loadCold(id); }
|
|
51
|
+
decodeCold(row) { return this.state.rows.decodeCold(row); }
|
|
52
|
+
fromRow(row) { return this.state.rows.fromRow(row); }
|
|
53
|
+
getRun(id) { return this.state.getRun(id); }
|
|
54
|
+
/**
|
|
55
|
+
* The live set, newest first: runs whose record is live (`isLiveRecord`) or that a RunManager
|
|
56
|
+
* pins. Finished runs are not here — read one by id (`getRun`), by an indexed query
|
|
57
|
+
* (`listWorkersOf`, `findRunByClientRequestId`, `listRunsWithWorktree`,
|
|
58
|
+
* `listBranchOwners`), or as list rows (`listRunSummaries`).
|
|
59
|
+
*/
|
|
60
|
+
listRuns() {
|
|
61
|
+
return sortNewestFirst([...this.held].filter(([id, run]) => isLiveRecord(run) || this.pins.has(id)).map(([, run]) => [run, this.listOrder(run)]));
|
|
62
|
+
}
|
|
63
|
+
/** Where a held run lists: its row's insertion order, or after every row while this store has
|
|
64
|
+
* not written it yet. The held set keeps such runs in creation order, and so does every list
|
|
65
|
+
* that sorts them in held-set order (`sortNewestFirst` is stable). */
|
|
66
|
+
listOrder(run) {
|
|
67
|
+
return { createdAt: run.createdAt, seq: this.base.get(run.id)?.seq ?? Number.POSITIVE_INFINITY };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* EVERY run as a full record, newest first — decoded row by row. Only the legacy `GET /runs`
|
|
71
|
+
* (older clients; the cockpit reads `GET /run-summaries`) may call this: it is exactly the
|
|
72
|
+
* whole-history parse #779 exists to remove from everything else.
|
|
73
|
+
*/
|
|
74
|
+
listAllRunsForLegacyRoute() {
|
|
75
|
+
const runs = new Map();
|
|
76
|
+
for (const row of this.db?.listAll() ?? []) {
|
|
77
|
+
if (this.deleted.has(row.id) || this.held.has(row.id))
|
|
78
|
+
continue;
|
|
79
|
+
const run = this.decodeCold(row);
|
|
80
|
+
if (run)
|
|
81
|
+
runs.set(row.id, [run, row]);
|
|
82
|
+
}
|
|
83
|
+
for (const [id, run] of this.held)
|
|
84
|
+
runs.set(id, [run, this.listOrder(run)]);
|
|
85
|
+
return sortNewestFirst(runs.values());
|
|
86
|
+
}
|
|
87
|
+
/** A bounded page of discoverable peer roots, including the current held overlay. */
|
|
88
|
+
listPeerTaskSummaries(options) {
|
|
89
|
+
return listPeerTaskSummaries({ db: this.db, held: this.held, skipped: this.deleted,
|
|
90
|
+
order: run => this.listOrder(run), cold: id => this.coldSummary(id) }, options);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Every run as its list row, newest first: the stored `summary` column, with each held run's
|
|
94
|
+
* own projection laid over it — a debounced save keeps memory up to 300 ms ahead of the row,
|
|
95
|
+
* and a run created since the last save has no row yet. `usage` is the caller's to attach.
|
|
96
|
+
*
|
|
97
|
+
* With `archivedWindow` (#864), the window the cockpit's lists read: every unarchived run, plus
|
|
98
|
+
* the newest `archivedWindow` archived ROOT runs, and whether older archived roots were left
|
|
99
|
+
* out. Archived workers are never in it (see `RunDatabase.listWindowSummaries`); with `roots`,
|
|
100
|
+
* no worker is — the runs index, whose readers list no workers. A held run
|
|
101
|
+
* lists by its record, so one archived or unarchived since the last save is ranked as it is now.
|
|
102
|
+
*
|
|
103
|
+
* A row this store found unreadable is left out, as the cold reader leaves out a row it had to
|
|
104
|
+
* decode and could not. A finished row nobody has decoded is served from its summary by both,
|
|
105
|
+
* which decodes nothing; reading it is what finds out (`isUnreadable`).
|
|
106
|
+
*/
|
|
107
|
+
listRunSummaries(options = {}) {
|
|
108
|
+
const { archivedWindow, roots = false } = options;
|
|
109
|
+
// Every skipped row may be an archived root, so ask for that many more: one past the window
|
|
110
|
+
// after skipping is how "older ones were left out" is known without counting them.
|
|
111
|
+
const rows = (archivedWindow === undefined
|
|
112
|
+
? this.db?.listSummaries()
|
|
113
|
+
: this.db?.listWindowSummaries(archivedWindow + 1 + this.deleted.size + this.unreadable.size + this.held.size, { roots })) ?? [];
|
|
114
|
+
const summaries = new Map();
|
|
115
|
+
for (const row of rows) {
|
|
116
|
+
if (this.deleted.has(row.id) || this.held.has(row.id) || this.unreadable.has(row.id))
|
|
117
|
+
continue;
|
|
118
|
+
const summary = parseStoredSummary(row.summary) ?? this.coldSummary(row.id);
|
|
119
|
+
if (summary)
|
|
120
|
+
summaries.set(row.id, [summary, row]);
|
|
121
|
+
}
|
|
122
|
+
for (const [id, run] of this.held) {
|
|
123
|
+
if (archivedWindow !== undefined && (run.archived || roots) && run.delegation?.role === 'worker')
|
|
124
|
+
continue;
|
|
125
|
+
summaries.set(id, [toRunSummary(run), this.listOrder(run)]);
|
|
126
|
+
}
|
|
127
|
+
const runs = sortNewestFirst(summaries.values());
|
|
128
|
+
if (archivedWindow === undefined)
|
|
129
|
+
return { runs, truncated: false };
|
|
130
|
+
let archived = 0;
|
|
131
|
+
const kept = runs.filter((run) => !run.archived || ++archived <= archivedWindow);
|
|
132
|
+
return { runs: kept, truncated: archived > archivedWindow };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* One page of archived ROOT runs, newest first (#864): `GET /run-summaries/archived`, the
|
|
136
|
+
* archived runs past the window. Held runs list by their record, as in `listRunSummaries`.
|
|
137
|
+
* `before` is the previous page's `nextCursor`; with `q`, only runs `matchesRunSearch` keeps, and
|
|
138
|
+
* `total` counts those. `automationNames` lets `q` match a task by its automation's name, as the
|
|
139
|
+
* list's origin line shows it (hearsay-tools/cezarion#1616). A cursor this store did not write
|
|
140
|
+
* answers `{ error }`.
|
|
141
|
+
*
|
|
142
|
+
* Ranking reads every archived root's key (id, created_at, seq: no record, no summary), so the
|
|
143
|
+
* page and `total` agree with the held overlay; only the page's own rows are read in full.
|
|
144
|
+
*/
|
|
145
|
+
listArchivedRuns(options) {
|
|
146
|
+
let after;
|
|
147
|
+
if (options.before !== undefined) {
|
|
148
|
+
after = decodeArchivedCursor(options.before);
|
|
149
|
+
if (!after)
|
|
150
|
+
return { error: 'before is not a cursor this server wrote' };
|
|
151
|
+
}
|
|
152
|
+
const q = options.q?.trim() ?? '';
|
|
153
|
+
const ranked = this.rankArchivedRows(q, options.automationNames);
|
|
154
|
+
this.overlayHeldArchived(ranked, q, options.automationNames);
|
|
155
|
+
const ordered = [...ranked.entries()].sort(([, a], [, b]) => newestFirst(a, b));
|
|
156
|
+
return this.archivedPage(ordered, after, options.limit);
|
|
157
|
+
}
|
|
158
|
+
/** The archived roots in `runs.db`, each by its key: every one without `q` (no record, no
|
|
159
|
+
* summary read), and with `q` the searched rows `matchesRunSearch` keeps, which carry the summary
|
|
160
|
+
* the search read. A deleted, held or unreadable run's row is left out; a held run joins in
|
|
161
|
+
* `overlayHeldArchived`. */
|
|
162
|
+
rankArchivedRows(q, automationNames) {
|
|
163
|
+
const skipped = (id) => this.deleted.has(id) || this.held.has(id) || this.unreadable.has(id);
|
|
164
|
+
const ranked = new Map();
|
|
165
|
+
if (q === '') {
|
|
166
|
+
for (const key of this.db?.listKeysWhere(ARCHIVED_ROOT) ?? [])
|
|
167
|
+
if (!skipped(key.id))
|
|
168
|
+
ranked.set(key.id, key);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
for (const row of this.db?.searchRootSummaries(sqlPrefilterTokens(q, { automationNames })) ?? []) {
|
|
172
|
+
if (skipped(row.id))
|
|
173
|
+
continue;
|
|
174
|
+
const summary = parseStoredSummary(row.summary) ?? this.coldSummary(row.id);
|
|
175
|
+
if (summary?.archived && matchesRunSearch(summary, q, { automationNames }))
|
|
176
|
+
ranked.set(row.id, { ...row, summary });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return ranked;
|
|
180
|
+
}
|
|
181
|
+
/** Lay the held archived roots over `ranked`, each by its record: it replaces its stored row
|
|
182
|
+
* (already left out of `ranked`), and with `q` it must match. A held worker never lists. */
|
|
183
|
+
overlayHeldArchived(ranked, q, automationNames) {
|
|
184
|
+
for (const [id, run] of this.held) {
|
|
185
|
+
if (!run.archived || run.delegation?.role === 'worker')
|
|
186
|
+
continue;
|
|
187
|
+
const summary = toRunSummary(run);
|
|
188
|
+
if (q === '' || matchesRunSearch(summary, q, { automationNames }))
|
|
189
|
+
ranked.set(id, { ...this.listOrder(run), summary });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/** The page of `ordered` after the cursor `after`: its summaries, the cursor of the next page,
|
|
193
|
+
* and `total`, the count of all of `ordered`. */
|
|
194
|
+
archivedPage(ordered, after, limit) {
|
|
195
|
+
const rest = after ? ordered.filter(([, key]) => newestFirst(key, after) > 0) : ordered;
|
|
196
|
+
const page = rest.slice(0, limit);
|
|
197
|
+
const runs = this.hydrateArchivedPage(page);
|
|
198
|
+
const last = page.at(-1)?.[1];
|
|
199
|
+
return {
|
|
200
|
+
runs,
|
|
201
|
+
nextCursor: last && rest.length > page.length ? encodeArchivedCursor(last) : null,
|
|
202
|
+
total: ordered.length,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/** The page's summaries: a ranked key's own, else its stored one, read for the rows that have
|
|
206
|
+
* none in a single query. A row whose stored summary does not fit the contract is projected from
|
|
207
|
+
* its record; a row that cannot be read at all is left out. */
|
|
208
|
+
hydrateArchivedPage(page) {
|
|
209
|
+
const cold = new Map((this.db?.getSummaries(page.filter(([, key]) => !key.summary).map(([id]) => id)) ?? [])
|
|
210
|
+
.map((row) => [row.id, parseStoredSummary(row.summary) ?? this.coldSummary(row.id)]));
|
|
211
|
+
return page.flatMap(([id, key]) => {
|
|
212
|
+
const summary = key.summary ?? cold.get(id);
|
|
213
|
+
return summary ? [summary] : [];
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The ROOT runs, archived or not, that match `query` (`matchesRunSearch`), newest first: at most
|
|
218
|
+
* `limit`, and whether more matched. The owned half of the workspace search (#864); held runs
|
|
219
|
+
* match by their record.
|
|
220
|
+
*/
|
|
221
|
+
searchRunSummaries(query, limit) {
|
|
222
|
+
const matched = new Map();
|
|
223
|
+
// Rows come newest first, so the newest `limit + 1` row matches are all a page can use; held
|
|
224
|
+
// runs, which may be newer than any row, are ranked in below.
|
|
225
|
+
this.db?.visitRootSummaries(sqlPrefilterTokens(query), (row) => {
|
|
226
|
+
if (this.deleted.has(row.id) || this.held.has(row.id) || this.unreadable.has(row.id))
|
|
227
|
+
return true;
|
|
228
|
+
const summary = parseStoredSummary(row.summary) ?? this.coldSummary(row.id);
|
|
229
|
+
if (summary && matchesRunSearch(summary, query))
|
|
230
|
+
matched.set(row.id, [summary, row]);
|
|
231
|
+
return matched.size <= limit;
|
|
232
|
+
});
|
|
233
|
+
for (const [id, run] of this.held) {
|
|
234
|
+
if (run.delegation?.role === 'worker')
|
|
235
|
+
continue;
|
|
236
|
+
const summary = toRunSummary(run);
|
|
237
|
+
if (matchesRunSearch(summary, query))
|
|
238
|
+
matched.set(id, [summary, this.listOrder(run)]);
|
|
239
|
+
}
|
|
240
|
+
const runs = sortNewestFirst(matched.values());
|
|
241
|
+
return { runs: runs.slice(0, limit), truncated: runs.length > limit };
|
|
242
|
+
}
|
|
243
|
+
/** A row whose stored summary does not fit the contract any more, projected from its record. */
|
|
244
|
+
coldSummary(id) {
|
|
245
|
+
const run = this.loadCold(id);
|
|
246
|
+
return run ? toRunSummary(run) : undefined;
|
|
247
|
+
}
|
|
248
|
+
/** Run `fn` reading each run that is not held at most once (`ColdReadCache`, hearsay-tools/cezarion#2378). */
|
|
249
|
+
withReadCache(fn) { return this.coldReads.scope(fn); }
|
|
250
|
+
/** The ids in memory right now: the held set, for diagnostics and the benchmark's heap pass. */
|
|
251
|
+
heldIds() {
|
|
252
|
+
return [...this.held.keys()];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The workers a root run owns, newest first, read off its own `receipts` (#659). Every
|
|
256
|
+
* `createOwnedRun` writes the receipt and the worker record in one transaction, and the
|
|
257
|
+
* receipt list is capped at 1,024 creations (#816), so this is a bounded lookup rather than a walk of the whole
|
|
258
|
+
* project index. An ordinary or worker run owns nothing and costs one map read; a receipt
|
|
259
|
+
* whose record has been deleted is skipped, never invented. A parent quarantined to
|
|
260
|
+
* `invalid` has no readable receipts and reports none, which is also what the cockpit
|
|
261
|
+
* assumes for that role.
|
|
262
|
+
*/
|
|
263
|
+
listOwnedWorkers(parentId) {
|
|
264
|
+
const parent = this.getRun(parentId);
|
|
265
|
+
if (parent?.delegation?.role !== 'root')
|
|
266
|
+
return [];
|
|
267
|
+
const workers = [];
|
|
268
|
+
for (const receipt of parent.delegation.receipts) {
|
|
269
|
+
const worker = this.getRun(receipt.workerId);
|
|
270
|
+
if (worker?.delegation?.role === 'worker' && worker.delegation.parentRunId === parentId)
|
|
271
|
+
workers.push(worker);
|
|
272
|
+
}
|
|
273
|
+
return workers.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
274
|
+
}
|
|
275
|
+
/** Every worker filed under `parentId` (the `parent_run_id` index plus memory), newest first:
|
|
276
|
+
* receipts or not, which is what the reconcile and deletion checks ask. */
|
|
277
|
+
listWorkersOf(parentId) {
|
|
278
|
+
const workers = new Map();
|
|
279
|
+
for (const run of this.held.values()) {
|
|
280
|
+
if (run.delegation?.role === 'worker' && run.delegation.parentRunId === parentId)
|
|
281
|
+
workers.set(run.id, [run, this.listOrder(run)]);
|
|
282
|
+
}
|
|
283
|
+
// Ids first: a live family's workers are usually all held, and then no record is read at all.
|
|
284
|
+
const cold = (this.db?.listIdsByParent(parentId) ?? []).filter((id) => !this.held.has(id) && !this.deleted.has(id));
|
|
285
|
+
for (const row of cold.length > 0 ? this.db.getMany(cold) : []) {
|
|
286
|
+
const run = this.fromRow(row);
|
|
287
|
+
if (run?.delegation?.role === 'worker' && run.delegation.parentRunId === parentId)
|
|
288
|
+
workers.set(row.id, [run, row]);
|
|
289
|
+
}
|
|
290
|
+
return sortNewestFirst(workers.values());
|
|
291
|
+
}
|
|
292
|
+
/** The id of every worker, held or stored, without decoding any (recovery's worker passes). */
|
|
293
|
+
listWorkerIds() {
|
|
294
|
+
const ids = new Set(this.db?.listWorkerIds() ?? []);
|
|
295
|
+
for (const id of this.deleted)
|
|
296
|
+
ids.delete(id);
|
|
297
|
+
for (const run of this.held.values())
|
|
298
|
+
if (run.delegation?.role === 'worker')
|
|
299
|
+
ids.add(run.id);
|
|
300
|
+
return [...ids];
|
|
301
|
+
}
|
|
302
|
+
/** The id of every run whose delegation is quarantined (`invalid`), held or stored: its stored
|
|
303
|
+
* summary says so, so nothing is decoded (scratch cleanup). */
|
|
304
|
+
listQuarantinedRunIds() {
|
|
305
|
+
const ids = new Set((this.db?.listKeysWhere(guardedJsonSql("json_extract(summary, '$.delegation.role') = 'invalid'", 0)) ?? []).map((key) => key.id));
|
|
306
|
+
for (const id of this.deleted)
|
|
307
|
+
ids.delete(id);
|
|
308
|
+
for (const [id, run] of this.held) {
|
|
309
|
+
if (run.delegation?.role === 'invalid')
|
|
310
|
+
ids.add(id);
|
|
311
|
+
else
|
|
312
|
+
ids.delete(id);
|
|
313
|
+
}
|
|
314
|
+
return [...ids];
|
|
315
|
+
}
|
|
316
|
+
/** All retained tasks this automation started, including variants, finished and archived runs.
|
|
317
|
+
* Logs and receipts may compact independently. Read only matching keys in SQLite and overlay
|
|
318
|
+
* held records so a debounced provenance update or deletion is reflected immediately. */
|
|
319
|
+
countAutomationRuns(automationId) {
|
|
320
|
+
const ids = new Set(this.db?.listAutomationRuns(automationId) ?? []);
|
|
321
|
+
for (const id of this.deleted)
|
|
322
|
+
ids.delete(id);
|
|
323
|
+
for (const [id, run] of this.held) {
|
|
324
|
+
if (run.automation?.automationId === automationId || run.automationTrigger?.automationId === automationId)
|
|
325
|
+
ids.add(id);
|
|
326
|
+
else
|
|
327
|
+
ids.delete(id);
|
|
328
|
+
}
|
|
329
|
+
return ids.size;
|
|
330
|
+
}
|
|
331
|
+
/** First non-archived task referencing a project issue, including secondary references. */
|
|
332
|
+
findNonArchivedRunByIssue(repo, number) {
|
|
333
|
+
const url = `https://github.com/${repo}/issues/${number}`.toLowerCase();
|
|
334
|
+
const matches = (run) => {
|
|
335
|
+
if (run.archived)
|
|
336
|
+
return false;
|
|
337
|
+
const urls = [run.referencedIssueUrl, ...(run.referencedIssueCandidates ?? []),
|
|
338
|
+
...(run.automation?.event.startsWith('issue.') ? [run.automation.githubUrl] : []),
|
|
339
|
+
...[...run.task.matchAll(new RegExp(ISSUE_URL_RE.source, 'gi'))].map((match) => match[0])]
|
|
340
|
+
.filter((value) => value !== undefined)
|
|
341
|
+
.map((value) => value.replace(/\/+$/, '').toLowerCase())
|
|
342
|
+
.filter((value) => value.endsWith(`/issues/${number}`));
|
|
343
|
+
// The legacy issueNumber is display-only and cannot establish repository identity.
|
|
344
|
+
// Explicit task markers remain project-scoped unless a qualified URL contradicts them.
|
|
345
|
+
return urls.includes(url) || (urls.length === 0 && run.markerRefs?.issue === number);
|
|
346
|
+
};
|
|
347
|
+
for (const run of this.held.values())
|
|
348
|
+
if (matches(run))
|
|
349
|
+
return run.id;
|
|
350
|
+
// Secondary references are record-only: query them in SQLite rather than hydrating every
|
|
351
|
+
// finished transcript or relying on the slim summary's primary issue number.
|
|
352
|
+
const where = `archived = 0 AND ${guardedJsonSql(`
|
|
353
|
+
json_extract(data, '$.issueNumber') = ? OR json_extract(data, '$.markerRefs.issue') = ?
|
|
354
|
+
OR lower(rtrim(json_extract(data, '$.referencedIssueUrl'), '/')) = ?
|
|
355
|
+
OR EXISTS (SELECT 1 FROM json_each(data, '$.referencedIssueCandidates') WHERE lower(rtrim(value, '/')) = ?)
|
|
356
|
+
OR (json_extract(data, '$.automation.event') LIKE 'issue.%' AND lower(rtrim(json_extract(data, '$.automation.githubUrl'), '/')) = ?)
|
|
357
|
+
OR instr(lower(json_extract(data, '$.task')), ?) > 0
|
|
358
|
+
`, 0, ['data'])}`;
|
|
359
|
+
for (const key of this.db?.listKeysWhere(where, [number, number, url, url, url, url]) ?? []) {
|
|
360
|
+
if (this.held.has(key.id) || this.deleted.has(key.id) || this.unreadable.has(key.id))
|
|
361
|
+
continue;
|
|
362
|
+
const run = this.getRun(key.id);
|
|
363
|
+
if (run && matches(run))
|
|
364
|
+
return key.id;
|
|
365
|
+
}
|
|
366
|
+
return undefined;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The runs automation receipts launched, by receipt id (`automation.receiptId` or
|
|
370
|
+
* `automationTrigger.receiptId`). Memory answers first; a receipt it does not know costs one
|
|
371
|
+
* pass over `runs.db` that reads the records' JSON in SQLite — only a crash leftover (a
|
|
372
|
+
* receipt still `reserved` at startup) ever asks.
|
|
373
|
+
*/
|
|
374
|
+
findRunIdsByAutomationReceipt(receiptIds) {
|
|
375
|
+
const wanted = new Set(receiptIds);
|
|
376
|
+
const found = new Map();
|
|
377
|
+
const receiptOf = (run) => run.automation?.receiptId ?? run.automationTrigger?.receiptId;
|
|
378
|
+
for (const run of this.held.values()) {
|
|
379
|
+
const receipt = receiptOf(run);
|
|
380
|
+
if (receipt !== undefined && wanted.has(receipt))
|
|
381
|
+
found.set(receipt, run.id);
|
|
382
|
+
}
|
|
383
|
+
const missing = [...wanted].filter((receipt) => !found.has(receipt));
|
|
384
|
+
if (missing.length === 0 || !this.db)
|
|
385
|
+
return found;
|
|
386
|
+
for (const id of this.db.listRunsByAutomationReceipt(missing)) {
|
|
387
|
+
if (this.held.has(id) || this.deleted.has(id))
|
|
388
|
+
continue;
|
|
389
|
+
const run = this.getRun(id);
|
|
390
|
+
const receipt = run && receiptOf(run);
|
|
391
|
+
if (receipt !== undefined && wanted.has(receipt) && !found.has(receipt))
|
|
392
|
+
found.set(receipt, id);
|
|
393
|
+
}
|
|
394
|
+
return found;
|
|
395
|
+
}
|
|
396
|
+
/** The id of every root whose delegation carries a conversation, held or stored: recovery's full
|
|
397
|
+
* reconcile pass (#661). `naming` keeps the ledgers whose messages name that run id as sender or
|
|
398
|
+
* recipient. Stored roots come from the `conversation_members` index, so no record is read. */
|
|
399
|
+
listConversationRootIds(naming) {
|
|
400
|
+
const ids = new Set(this.db?.listConversationRoots(naming) ?? []);
|
|
401
|
+
for (const id of this.deleted)
|
|
402
|
+
ids.delete(id);
|
|
403
|
+
for (const [id, run] of this.held) {
|
|
404
|
+
if (run.delegation?.role === 'root' && run.delegation.conversation && (!naming || run.delegation.conversation.messages.some(message => [message.senderRunId, message.recipientRunId].includes(naming))))
|
|
405
|
+
ids.add(id);
|
|
406
|
+
else
|
|
407
|
+
ids.delete(id);
|
|
408
|
+
}
|
|
409
|
+
return [...ids];
|
|
410
|
+
}
|
|
411
|
+
/** The id of every run, held or stored, without decoding any (orphan-worktree sweeps). */
|
|
412
|
+
listRunIds() {
|
|
413
|
+
const ids = new Set(this.db?.listIds() ?? []);
|
|
414
|
+
for (const id of this.deleted)
|
|
415
|
+
ids.delete(id);
|
|
416
|
+
for (const id of this.held.keys())
|
|
417
|
+
ids.add(id);
|
|
418
|
+
return [...ids];
|
|
419
|
+
}
|
|
420
|
+
/** Runs with a materialized worktree directory (`worktreePath`, not reclaimed), most recently
|
|
421
|
+
* finished first, then newest first: worktree retention and the worktrees panel. */
|
|
422
|
+
listRunsWithWorktree() {
|
|
423
|
+
const runs = this.queryRuns(this.db?.listWithWorktree() ?? [], (run) => materializedWorktreePath(run) !== undefined);
|
|
424
|
+
const recency = ([run]) => run.finishedAt ?? run.createdAt;
|
|
425
|
+
return runs.sort((a, b) => (recency(a) < recency(b) ? 1 : recency(a) > recency(b) ? -1 : newestFirst(a[1], b[1]))).map(([run]) => run);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Every run that owns a branch or names the PR it created, as the few fields branch cleanup and
|
|
429
|
+
* git-log attribution read (issue 08 §B3, §B5; a squash commit is attributed by its PR number):
|
|
430
|
+
* the stored summary plus the `branch` and `base_branch` columns, so a Git-tab request decodes
|
|
431
|
+
* no record. Held runs answer from memory.
|
|
432
|
+
*/
|
|
433
|
+
listBranchOwners() {
|
|
434
|
+
const rows = (this.db?.listBranchOwners(`branch IS NOT NULL OR ${guardedJsonSql("json_extract(summary, '$.pullRequestUrl') IS NOT NULL", 0)}`) ?? [])
|
|
435
|
+
.filter((row) => !this.deleted.has(row.id) && !this.held.has(row.id));
|
|
436
|
+
return listBranchOwners(rows, [...this.held.values()], (id) => this.getRun(id));
|
|
437
|
+
}
|
|
438
|
+
/** The rows a column query returned, as records, with memory laid over them: a held run
|
|
439
|
+
* answers from memory (matching `matches` there, not on its maybe-older row). */
|
|
440
|
+
queryRuns(rows, matches) {
|
|
441
|
+
const runs = new Map();
|
|
442
|
+
for (const run of this.held.values())
|
|
443
|
+
if (matches(run))
|
|
444
|
+
runs.set(run.id, [run, this.listOrder(run)]);
|
|
445
|
+
for (const row of rows) {
|
|
446
|
+
if (runs.has(row.id) || this.held.has(row.id) || this.deleted.has(row.id))
|
|
447
|
+
continue;
|
|
448
|
+
const run = this.fromRow(row);
|
|
449
|
+
if (run && matches(run))
|
|
450
|
+
runs.set(row.id, [run, row]);
|
|
451
|
+
}
|
|
452
|
+
return [...runs.values()];
|
|
453
|
+
}
|
|
454
|
+
/** The run an idempotent start already created (#504), archived or not. A deleted run is gone
|
|
455
|
+
* with its record, so a retry after deletion honestly creates a fresh one. */
|
|
456
|
+
findRunByClientRequestId(clientRequestId) {
|
|
457
|
+
for (const run of this.held.values())
|
|
458
|
+
if (run.clientRequestId === clientRequestId)
|
|
459
|
+
return run;
|
|
460
|
+
const row = this.db?.findByClientRequestId(clientRequestId);
|
|
461
|
+
if (!row || this.held.has(row.id))
|
|
462
|
+
return undefined;
|
|
463
|
+
const run = this.getRun(row.id);
|
|
464
|
+
return run?.clientRequestId === clientRequestId ? run : undefined;
|
|
465
|
+
}
|
|
466
|
+
/** Indexed family enumeration, including members not yet flushed to SQLite. */
|
|
467
|
+
listFamilyRunIds(rootId) {
|
|
468
|
+
const ids = new Set([rootId, ...(this.db?.listIdsByParent(rootId) ?? [])]);
|
|
469
|
+
for (const [id, run] of this.held) {
|
|
470
|
+
if (familyRootOf(run) === rootId)
|
|
471
|
+
ids.add(id);
|
|
472
|
+
else if (id !== rootId)
|
|
473
|
+
ids.delete(id);
|
|
474
|
+
}
|
|
475
|
+
for (const id of this.deleted)
|
|
476
|
+
ids.delete(id);
|
|
477
|
+
return [...ids];
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
//# sourceMappingURL=run-queries.js.map
|