@hearsay-tools/squawk 0.18.0-dev.7825 → 0.18.0-dev.7832

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 (97) hide show
  1. package/dist/activity/read-model.d.ts +3 -1
  2. package/dist/activity/read-model.js +17 -15
  3. package/dist/activity/read-model.js.map +1 -1
  4. package/dist/activity/requests.d.ts +3 -1
  5. package/dist/activity/requests.js +1 -1
  6. package/dist/activity/requests.js.map +1 -1
  7. package/dist/automations/service.js +1 -1
  8. package/dist/automations/service.js.map +1 -1
  9. package/dist/automations/task-template.js +3 -3
  10. package/dist/automations/task-template.js.map +1 -1
  11. package/dist/ci-wait/controller.d.ts +46 -46
  12. package/dist/delegation/conversations.d.ts +6 -2
  13. package/dist/delegation/conversations.js +1 -1
  14. package/dist/delegation/conversations.js.map +1 -1
  15. package/dist/delegation/family-end.d.ts +4 -2
  16. package/dist/delegation/family-end.js +1 -1
  17. package/dist/delegation/family-end.js.map +1 -1
  18. package/dist/delegation/routes.d.ts +75 -75
  19. package/dist/delegation/scratch-cleanup.js +2 -2
  20. package/dist/delegation/scratch-cleanup.js.map +1 -1
  21. package/dist/delegation/task-discovery.js +1 -1
  22. package/dist/delegation/task-discovery.js.map +1 -1
  23. package/dist/delegation/transport.d.ts +14 -14
  24. package/dist/delegation/worker-cleanup.js +4 -4
  25. package/dist/delegation/worker-cleanup.js.map +1 -1
  26. package/dist/project-commands.js +1 -1
  27. package/dist/project-commands.js.map +1 -1
  28. package/dist/project-migration/live.js +1 -1
  29. package/dist/project-migration/live.js.map +1 -1
  30. package/dist/runs/branch-owners.d.ts +2 -2
  31. package/dist/runs/cold-reads.d.ts +1 -1
  32. package/dist/runs/cold-reads.js +1 -1
  33. package/dist/runs/live-tasks.js +1 -1
  34. package/dist/runs/live-tasks.js.map +1 -1
  35. package/dist/runs/ports.d.ts +50 -28
  36. package/dist/runs/retention.d.ts +4 -3
  37. package/dist/runs/retention.js +2 -2
  38. package/dist/runs/retention.js.map +1 -1
  39. package/dist/runs/run-cold-reads.d.ts +98 -0
  40. package/dist/runs/run-cold-reads.js +194 -0
  41. package/dist/runs/run-cold-reads.js.map +1 -0
  42. package/dist/runs/run-queries.d.ts +190 -0
  43. package/dist/runs/run-queries.js +480 -0
  44. package/dist/runs/run-queries.js.map +1 -0
  45. package/dist/runs/run-repo-scope.d.ts +38 -0
  46. package/dist/runs/run-repo-scope.js +78 -0
  47. package/dist/runs/run-repo-scope.js.map +1 -0
  48. package/dist/runs/store.d.ts +9 -222
  49. package/dist/runs/store.js +82 -738
  50. package/dist/runs/store.js.map +1 -1
  51. package/dist/serve-boot.d.ts +3 -1
  52. package/dist/serve-boot.js +2 -2
  53. package/dist/serve-boot.js.map +1 -1
  54. package/dist/server/models-routes.d.ts +13 -13
  55. package/dist/server/project-context.js +3 -3
  56. package/dist/server/project-context.js.map +1 -1
  57. package/dist/server/repo-branches.d.ts +5 -3
  58. package/dist/server/repo-branches.js +1 -1
  59. package/dist/server/repo-branches.js.map +1 -1
  60. package/dist/server/reports-api.d.ts +2 -2
  61. package/dist/server/run-checkout.d.ts +3 -1
  62. package/dist/server/run-checkout.js +2 -2
  63. package/dist/server/run-checkout.js.map +1 -1
  64. package/dist/server/run-relationships.d.ts +3 -1
  65. package/dist/server/run-relationships.js +1 -1
  66. package/dist/server/run-relationships.js.map +1 -1
  67. package/dist/server/server.js +12 -12
  68. package/dist/server/server.js.map +1 -1
  69. package/dist/server/workspace-live-routes.d.ts +6 -6
  70. package/dist/workflows/run/auto-resume.js +2 -2
  71. package/dist/workflows/run/auto-resume.js.map +1 -1
  72. package/dist/workflows/run/completion-gate.js +1 -1
  73. package/dist/workflows/run/completion-gate.js.map +1 -1
  74. package/dist/workflows/run/family-reconciler.js +8 -8
  75. package/dist/workflows/run/family-reconciler.js.map +1 -1
  76. package/dist/workflows/run/maintenance-claims.js +2 -2
  77. package/dist/workflows/run/maintenance-claims.js.map +1 -1
  78. package/dist/workflows/run/run-cancel.js +1 -1
  79. package/dist/workflows/run/run-cancel.js.map +1 -1
  80. package/dist/workflows/run/run-line.js +2 -2
  81. package/dist/workflows/run/run-line.js.map +1 -1
  82. package/dist/workflows/run/run-recovery.js +6 -6
  83. package/dist/workflows/run/run-recovery.js.map +1 -1
  84. package/dist/workflows/run/run-start.js +1 -1
  85. package/dist/workflows/run/run-start.js.map +1 -1
  86. package/dist/workflows/run/wake-admission.js +1 -1
  87. package/dist/workflows/run/wake-admission.js.map +1 -1
  88. package/dist/workflows/run/worker-questions.js +3 -3
  89. package/dist/workflows/run/worker-questions.js.map +1 -1
  90. package/dist/workflows/run.js +1 -1
  91. package/dist/workflows/run.js.map +1 -1
  92. package/package.json +4 -4
  93. package/scripts/benchmark-automation-lookups.ts +2 -2
  94. package/scripts/benchmark-conversation-lookup.ts +2 -2
  95. package/scripts/benchmark-family-reconcile.ts +1 -1
  96. package/scripts/benchmark-worktree-retention.ts +1 -1
  97. package/scripts/seed-archive-profile.ts +2 -2
@@ -0,0 +1,194 @@
1
+ /**
2
+ * How the store reads a run it does not hold, and which runs it holds (hearsay-tools/squawk#4044):
3
+ * the anchors and the eviction of the held set, the cold load and decode of a row, the hold a write
4
+ * takes, and the detached reads. `RunStore` keeps one of these as its private `rows`; `getRun` and
5
+ * `isUnreadable` stay on the store.
6
+ */
7
+ import { ColdReadCache, storedRow } from './cold-reads.js';
8
+ import { reconcileLoadedRun } from './loaded-run-exits.js';
9
+ import { familyKey, rowFamily } from './run-claims.js';
10
+ import { rescopeRun } from './run-references.js';
11
+ import { familyRootOf, isLiveRecord } from './run-row.js';
12
+ /** Tests freeze the copies of cold runs, so an in-place write to one throws instead of vanishing. */
13
+ function deepFreeze(value) {
14
+ if (value && typeof value === 'object' && !Object.isFrozen(value)) {
15
+ Object.freeze(value);
16
+ for (const child of Object.values(value))
17
+ deepFreeze(child);
18
+ }
19
+ return value;
20
+ }
21
+ export class RunColdReadsTopic {
22
+ state;
23
+ /** Rows read cold in the current synchronous turn, so a commit staged from one is fenced against
24
+ * the version it was computed from. `owned`: its family was already this store's when read.
25
+ * Cleared at the next microtask: no commit spans a turn. */
26
+ coldBase = new Map();
27
+ coldReads = new ColdReadCache();
28
+ /** Rows whose `data` this store tried to decode and could not: left in the database untouched,
29
+ * and left out of the list rows from then on, as the cold reader leaves them out (run-index.ts). */
30
+ unreadable = new Set();
31
+ constructor(state) {
32
+ this.state = state;
33
+ }
34
+ get db() { return this.state.db(); }
35
+ get keepLive() { return this.state.keepLive(); }
36
+ get repoHandle() { return this.state.repoHandle(); }
37
+ get held() { return this.state.held; }
38
+ get pins() { return this.state.pins; }
39
+ get committing() { return this.state.committing; }
40
+ get dirty() { return this.state.dirty; }
41
+ get deleted() { return this.state.deleted; }
42
+ get quarantined() { return this.state.quarantined; }
43
+ get claimed() { return this.state.claimed; }
44
+ get pendingClaims() { return this.state.pendingClaims; }
45
+ get base() { return this.state.base; }
46
+ get claims() { return this.state.claims(); }
47
+ get persistence() { return this.state.persistence(); }
48
+ /**
49
+ * Whether a held run anchors itself (and its family) in memory. Anything else held is a family
50
+ * member or a settled write, and leaves at the next sweep (`evictSettled`).
51
+ *
52
+ * The held set is: every run that is live (`isLiveRecord`), pinned by a RunManager (`pin`),
53
+ * dirty, or inside a durable commit; plus the whole delegation family (root and direct
54
+ * workers) of any such run. Families are held because the RunManager reads a live run's family
55
+ * on every run event — `GET /runs/:id/relationships`, the global `reconcileWorkerWaits` pass
56
+ * (about twenty call sites), completion blockers and conversations — and decoding a cold
57
+ * record costs about 200 µs (JSON.parse plus the schema). Measured on a copy of a real
58
+ * cockpit's `runs.json` (958 runs, 957 of them delegated): a running root with 26 workers
59
+ * paid about 5 ms per family read, and the live families together about 10 ms per global
60
+ * pass, all on the event loop. Holding them costs memory in proportion to active work, not to
61
+ * history.
62
+ */
63
+ isAnchor(id, run) {
64
+ return isLiveRecord(run) || this.pins.has(id) || this.dirty.has(id) || this.committing.has(id);
65
+ }
66
+ /** The family roots with an anchoring member in memory. */
67
+ anchoredFamilies() {
68
+ const roots = new Set();
69
+ for (const [id, run] of this.held) {
70
+ const root = familyRootOf(run);
71
+ if (root !== undefined && this.isAnchor(id, run))
72
+ roots.add(root);
73
+ }
74
+ return roots;
75
+ }
76
+ /** Drop every held run that is neither an anchor nor in an anchored family. A store without a
77
+ * database keeps everything: memory is the only copy it has. */
78
+ evictSettled() {
79
+ if (!this.db)
80
+ return;
81
+ const families = this.anchoredFamilies();
82
+ for (const [id, run] of this.held) {
83
+ if (this.isAnchor(id, run))
84
+ continue;
85
+ const root = familyRootOf(run);
86
+ if (root !== undefined && families.has(root))
87
+ continue;
88
+ this.held.delete(id);
89
+ this.base.delete(id);
90
+ this.coldReads.forget(id);
91
+ }
92
+ this.claims.releaseUnheldClaims();
93
+ }
94
+ /** A run read from `runs.db`, normalized like a loaded one (`reconcileLoadedRun`, then the
95
+ * repository scope) but held by nobody. Undefined when absent, deleted or unreadable. */
96
+ loadCold(id) {
97
+ if (!this.db || this.deleted.has(id))
98
+ return undefined;
99
+ const row = this.db.get(id);
100
+ return row ? this.decodeCold(row) : undefined;
101
+ }
102
+ /** `loaded` sees the record once the load has normalized it, before it is scoped: a heal's `before`. */
103
+ decodeCold(row, loaded) {
104
+ this.coldReads.at(row.id, row.revision); // the fence below moves to this revision
105
+ const decoded = this.state.decodeRunRow(row.data);
106
+ if (!decoded) {
107
+ this.unreadable.add(row.id);
108
+ return undefined;
109
+ }
110
+ this.unreadable.delete(row.id);
111
+ const { run, extras } = decoded;
112
+ if (this.coldBase.size === 0)
113
+ queueMicrotask(() => this.coldBase.clear());
114
+ const family = rowFamily(row);
115
+ this.coldBase.set(row.id, { revision: row.revision, seq: row.seq, data: row.data, extras, owned: this.claimed.has(family) || this.pendingClaims.has(family) });
116
+ reconcileLoadedRun(run, { keepLive: this.keepLive });
117
+ loaded?.(run);
118
+ rescopeRun(run, this.repoHandle);
119
+ return run;
120
+ }
121
+ /** Hold a writable row. A fallback family's reads stay detached (the cold-read contract). */
122
+ holdDecoded(run) {
123
+ if (this.db?.familyHasFallback(familyKey(run)))
124
+ return process.env.VITEST ? deepFreeze(run) : run;
125
+ const read = this.coldBase.get(run.id);
126
+ this.held.set(run.id, run);
127
+ if (read)
128
+ this.base.set(run.id, storedRow(read));
129
+ return run;
130
+ }
131
+ /**
132
+ * Hold a claimed run for a write; leave after settlement unless anchored.
133
+ * Take the family claim before reading its row. Return undefined for a live foreign owner
134
+ * or a fallback family: neither claim is granted.
135
+ */
136
+ hold(id) {
137
+ const held = this.held.get(id);
138
+ if (held)
139
+ return held;
140
+ const family = this.db && !this.deleted.has(id) ? this.db.familyOf(id) : undefined;
141
+ if (family === undefined || !this.claims.claimFamilies([family]).has(family))
142
+ return undefined;
143
+ const run = this.coldReads.claimed(id, this.coldBase.get(id), () => this.db?.revisionOf(id)) ?? this.loadCold(id);
144
+ if (!run)
145
+ return undefined;
146
+ this.holdDecoded(run);
147
+ this.persistence.scheduleSave();
148
+ return run;
149
+ }
150
+ /** The record a store write changes in place: held, or loaded to be. Undefined for a run this
151
+ * store may not write (another process's, or quarantined), so the write changes nothing. */
152
+ record(id) {
153
+ if (this.quarantined.has(id))
154
+ return undefined;
155
+ return this.held.get(id) ?? this.hold(id);
156
+ }
157
+ /** Read held legacy family members, or a detached cold record. */
158
+ peek(id) {
159
+ const held = this.held.get(id);
160
+ if (held)
161
+ return held;
162
+ const run = this.loadCold(id);
163
+ return run && this.answerCold(run, false);
164
+ }
165
+ /**
166
+ * A run just read off its row, as reads answer it: held when its family is in memory (a live
167
+ * family's members are read on every run event), else a copy nobody holds — frozen under
168
+ * vitest when it leaves the store (`freeze`).
169
+ */
170
+ answerCold(run, freeze) {
171
+ const root = familyRootOf(run);
172
+ if (root !== undefined && this.anchoredFamilies().has(root))
173
+ return this.holdDecoded(run);
174
+ return freeze && process.env.VITEST ? deepFreeze(run) : run;
175
+ }
176
+ /** `getRun` for a row a query already read: the held object, else decoded from `row`. */
177
+ fromRow(row) {
178
+ const held = this.held.get(row.id);
179
+ if (held)
180
+ return held;
181
+ if (this.deleted.has(row.id))
182
+ return undefined;
183
+ const cached = this.coldReads.at(row.id, row.revision);
184
+ if (cached)
185
+ return cached;
186
+ const run = this.decodeCold(row);
187
+ return run && this.coldReads.keep(this.answerCold(run, true), this.coldBase.get(row.id), this.held.has(row.id));
188
+ }
189
+ /** Whether the run exists, held or not, without decoding it. */
190
+ hasRun(id) {
191
+ return this.held.has(id) || (!!this.db && !this.deleted.has(id) && this.db.has(id));
192
+ }
193
+ }
194
+ //# sourceMappingURL=run-cold-reads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-cold-reads.js","sourceRoot":"","sources":["../../src/runs/run-cold-reads.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKvD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG1D,qGAAqG;AACrG,SAAS,UAAU,CAAI,KAAQ;IAC7B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAYD,MAAM,OAAO,iBAAiB;IASC,KAAK;IARlC;;iEAE6D;IACpD,QAAQ,GAAG,IAAI,GAAG,EAA0C,CAAC;IAC7D,SAAS,GAAG,IA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AC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAClH,CAAC;IAED,gEAAgE;IAChE,MAAM,CAAC,EAAU;QACf,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACtF,CAAC;CACF"}
@@ -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
+ }