crysk 0.0.0 → 0.3.0

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 (229) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +609 -3
  3. package/bin/pr-hero.js +166 -0
  4. package/config/models/anthropic.json +5 -0
  5. package/dist/SKILL-7e3725zn.md +496 -0
  6. package/dist/SKILL-7q35wcaz.md +66 -0
  7. package/dist/SKILL-9at22381.md +74 -0
  8. package/dist/SKILL-ex2hxxh3.md +134 -0
  9. package/dist/adjudicator-dtg2axnh.md +86 -0
  10. package/dist/admission-config.example-a9vqmmad.json +9 -0
  11. package/dist/ci-admission-camfbx2b.md +122 -0
  12. package/dist/cli.js +42292 -0
  13. package/dist/consolidate-ac0mnfyj.md +24 -0
  14. package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
  15. package/dist/deep-review-logic-a6b1gczf.md +156 -0
  16. package/dist/deep-review-parity-0ec904db.md +120 -0
  17. package/dist/deep-review-reliability-qyakbjb9.md +125 -0
  18. package/dist/deep-review-resilience-3tz8y26e.md +118 -0
  19. package/dist/index.js +20190 -0
  20. package/dist/opencode-ci-7b0be64p.md +141 -0
  21. package/dist/review-refuter-j4e9gezy.md +71 -0
  22. package/dist/scout-yvp153q7.md +140 -0
  23. package/dist/summarizer-zca44nxa.md +18 -0
  24. package/dist/workflow-w1g9szna.yml +151 -0
  25. package/package.json +81 -4
  26. package/prompts/consolidate.md +24 -0
  27. package/prompts/default/PROVENANCE.md +18 -0
  28. package/prompts/default/deep-review-lifecycle.md +362 -0
  29. package/prompts/default/deep-review-logic.md +156 -0
  30. package/prompts/default/deep-review-parity.md +120 -0
  31. package/prompts/default/deep-review-reliability.md +125 -0
  32. package/prompts/default/deep-review-resilience.md +118 -0
  33. package/prompts/default/review-refuter.md +71 -0
  34. package/prompts/scout.md +140 -0
  35. package/prompts/summarizer.md +18 -0
  36. package/skills/crysk/SKILL.md +74 -0
  37. package/skills/crysk-ci-setup/SKILL.md +134 -0
  38. package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
  39. package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
  40. package/skills/crysk-ci-setup/references/ci-admission.md +122 -0
  41. package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
  42. package/skills/crysk-loop/SKILL.md +496 -0
  43. package/skills/crysk-loop/adjudicator.md +86 -0
  44. package/skills/crysk-pr/SKILL.md +66 -0
  45. package/src/agent-env.ts +1084 -0
  46. package/src/asset-manifest.ts +83 -0
  47. package/src/assets.d.ts +6 -0
  48. package/src/assets.ts +183 -0
  49. package/src/brand-paths.ts +155 -0
  50. package/src/brand.ts +255 -0
  51. package/src/ci/admission-ledger.ts +350 -0
  52. package/src/ci/classify-error.ts +73 -0
  53. package/src/ci/cli-record.ts +271 -0
  54. package/src/ci/force-comment.ts +39 -0
  55. package/src/ci/gates.ts +923 -0
  56. package/src/ci/outcome.ts +2181 -0
  57. package/src/ci/override.ts +187 -0
  58. package/src/ci/publish.ts +1639 -0
  59. package/src/ci/reporter.ts +626 -0
  60. package/src/ci/review-admission.ts +901 -0
  61. package/src/ci/review-levels.ts +310 -0
  62. package/src/ci/review-policy.ts +18 -0
  63. package/src/ci/review-risk.ts +184 -0
  64. package/src/ci/setup.ts +844 -0
  65. package/src/ci/trigger.ts +1353 -0
  66. package/src/cli.ts +348 -0
  67. package/src/commands/activity.ts +67 -0
  68. package/src/commands/ci-setup-questions.ts +397 -0
  69. package/src/commands/ci-setup.ts +381 -0
  70. package/src/commands/config.ts +99 -0
  71. package/src/commands/doctor.ts +108 -0
  72. package/src/commands/init.ts +139 -0
  73. package/src/commands/mcp.ts +10 -0
  74. package/src/commands/menu.ts +129 -0
  75. package/src/commands/post.ts +302 -0
  76. package/src/commands/skills.ts +83 -0
  77. package/src/commands/status.ts +173 -0
  78. package/src/commands/triage.ts +342 -0
  79. package/src/commands/uninstall.ts +37 -0
  80. package/src/commands/upgrade.ts +214 -0
  81. package/src/commands/usage.ts +98 -0
  82. package/src/compare/compare.ts +28 -0
  83. package/src/compare/floor-test.ts +471 -0
  84. package/src/compare/martian-adapter.ts +80 -0
  85. package/src/config/config.ts +267 -0
  86. package/src/corpus/corpus.ts +1094 -0
  87. package/src/corpus/preflight.ts +1789 -0
  88. package/src/diversity/accounting.ts +90 -0
  89. package/src/diversity/adjudication.ts +145 -0
  90. package/src/diversity/admission.ts +60 -0
  91. package/src/diversity/benchmark.ts +195 -0
  92. package/src/diversity/clustering.ts +285 -0
  93. package/src/diversity/errors.ts +7 -0
  94. package/src/diversity/identity.ts +285 -0
  95. package/src/diversity/index.ts +11 -0
  96. package/src/diversity/pipeline-integration.ts +448 -0
  97. package/src/diversity/projection.ts +57 -0
  98. package/src/diversity/self-contained.ts +68 -0
  99. package/src/diversity/target-validation.ts +179 -0
  100. package/src/doctor-migration.ts +209 -0
  101. package/src/doctor.ts +723 -0
  102. package/src/errors.ts +83 -0
  103. package/src/execution/admission.ts +75 -0
  104. package/src/execution/atomic-write.ts +35 -0
  105. package/src/execution/attempt-evidence.ts +415 -0
  106. package/src/execution/bucket-id.ts +136 -0
  107. package/src/execution/concurrency-limiter.ts +175 -0
  108. package/src/execution/contracts.ts +443 -0
  109. package/src/execution/failure-classification.ts +42 -0
  110. package/src/execution/failure-policy.ts +240 -0
  111. package/src/execution/harness.ts +2548 -0
  112. package/src/execution/settlement.ts +348 -0
  113. package/src/execution/spawned-process.ts +66 -0
  114. package/src/execution/spend-limiter.ts +424 -0
  115. package/src/execution/step-artifacts.ts +55 -0
  116. package/src/execution/usage-normalized.ts +469 -0
  117. package/src/git/git.ts +396 -0
  118. package/src/git/identity.ts +64 -0
  119. package/src/git/refs.ts +140 -0
  120. package/src/home-preflight.ts +443 -0
  121. package/src/home.ts +243 -0
  122. package/src/ignore-file.ts +336 -0
  123. package/src/ignore-read.ts +118 -0
  124. package/src/index.ts +34 -0
  125. package/src/legacy-launchd.ts +29 -0
  126. package/src/mcp/mcp.ts +150 -0
  127. package/src/mcp/preflight.ts +407 -0
  128. package/src/menu-context.ts +192 -0
  129. package/src/model/catalog.ts +251 -0
  130. package/src/model/exec-snapshots.ts +390 -0
  131. package/src/model/free-discovery.ts +302 -0
  132. package/src/model/provider-capabilities.ts +814 -0
  133. package/src/model/routing.ts +600 -0
  134. package/src/pr/admission.ts +847 -0
  135. package/src/pr/ci-admission-gate.ts +665 -0
  136. package/src/pr/ci-publish.ts +76 -0
  137. package/src/pr/discovery.ts +432 -0
  138. package/src/pr/inline.ts +507 -0
  139. package/src/pr/plan.ts +366 -0
  140. package/src/pr/posting.ts +115 -0
  141. package/src/pr/pr-status.ts +787 -0
  142. package/src/pr/pr.ts +3642 -0
  143. package/src/pr/preflight.ts +1031 -0
  144. package/src/pr/publish-outcome.ts +361 -0
  145. package/src/pr/range.ts +119 -0
  146. package/src/pr/reverts-preflight.ts +606 -0
  147. package/src/pr/reverts.ts +377 -0
  148. package/src/pr/review-pr.ts +927 -0
  149. package/src/pr/status.ts +154 -0
  150. package/src/pr/target.ts +388 -0
  151. package/src/pr/teardown.ts +437 -0
  152. package/src/pr/worktree-setup.ts +60 -0
  153. package/src/production-runtime.ts +1877 -0
  154. package/src/progress.ts +487 -0
  155. package/src/rereview/adjudicate.ts +89 -0
  156. package/src/rereview/classify.ts +362 -0
  157. package/src/rereview/identity.ts +211 -0
  158. package/src/rereview/plan.ts +308 -0
  159. package/src/rereview/prepare.ts +1025 -0
  160. package/src/rereview/state.ts +767 -0
  161. package/src/rereview/verify.ts +241 -0
  162. package/src/review/boundary.ts +105 -0
  163. package/src/review/consolidate.ts +246 -0
  164. package/src/review/dedupe.ts +368 -0
  165. package/src/review/drafts.ts +448 -0
  166. package/src/review/findings-conformance.ts +120 -0
  167. package/src/review/findings.ts +714 -0
  168. package/src/review/pipeline.ts +3977 -0
  169. package/src/review/preflight.ts +3575 -0
  170. package/src/review/prompt-set.ts +177 -0
  171. package/src/review/proof-refs.ts +187 -0
  172. package/src/review/report.ts +1821 -0
  173. package/src/review/review.ts +490 -0
  174. package/src/review/root-cause.ts +120 -0
  175. package/src/review/route-preflight.ts +289 -0
  176. package/src/review/run.ts +601 -0
  177. package/src/review/scout.ts +323 -0
  178. package/src/review/size-gate.ts +595 -0
  179. package/src/review/spec.ts +235 -0
  180. package/src/review/step-runner.ts +233 -0
  181. package/src/runner-authority.ts +596 -0
  182. package/src/security/binding-policy.ts +115 -0
  183. package/src/security/credential-broker.ts +773 -0
  184. package/src/security/evidence-redaction.ts +62 -0
  185. package/src/security/execution-authority.ts +27 -0
  186. package/src/security/redact.ts +71 -0
  187. package/src/security/workspace-read-broker.ts +466 -0
  188. package/src/server/client.ts +190 -0
  189. package/src/server/preflight.ts +217 -0
  190. package/src/server/server.ts +327 -0
  191. package/src/signal-handler.ts +50 -0
  192. package/src/store/activity.ts +413 -0
  193. package/src/store/backfill-preflight.ts +49 -0
  194. package/src/store/backfill.ts +141 -0
  195. package/src/store/gc-preflight.ts +206 -0
  196. package/src/store/gc.ts +424 -0
  197. package/src/store/metrics-preflight.ts +229 -0
  198. package/src/store/metrics.ts +236 -0
  199. package/src/store/preflight.ts +748 -0
  200. package/src/store/store.ts +693 -0
  201. package/src/system-tools.ts +355 -0
  202. package/src/transport-registry.ts +1124 -0
  203. package/src/transports/claude-code-cli.ts +1348 -0
  204. package/src/transports/opencode-admission.ts +515 -0
  205. package/src/transports/opencode-client.ts +3328 -0
  206. package/src/transports/opencode-evidence.ts +557 -0
  207. package/src/transports/opencode-mcp.ts +248 -0
  208. package/src/transports/opencode-sdk.ts +2294 -0
  209. package/src/transports/opencode-server.ts +535 -0
  210. package/src/triage/adjudication.ts +113 -0
  211. package/src/triage/reply.ts +125 -0
  212. package/src/triage/triage.ts +255 -0
  213. package/src/ui/activity.ts +173 -0
  214. package/src/ui/config-edit.ts +816 -0
  215. package/src/ui/config.ts +462 -0
  216. package/src/ui/menu.ts +1325 -0
  217. package/src/ui/plan.ts +1039 -0
  218. package/src/ui/primitives.ts +300 -0
  219. package/src/ui/progress.ts +298 -0
  220. package/src/ui/result.ts +552 -0
  221. package/src/ui/review-menu.ts +312 -0
  222. package/src/ui/select.ts +528 -0
  223. package/src/ui/tree.ts +178 -0
  224. package/src/uninstaller.ts +479 -0
  225. package/src/updater.ts +836 -0
  226. package/src/usage.ts +77 -0
  227. package/src/watch/preflight.ts +1389 -0
  228. package/src/watch/watch.ts +1235 -0
  229. package/src/wizard.ts +877 -0
@@ -0,0 +1,327 @@
1
+ // Canonical product store (Fundamentals #6 / observability-canonical-store.md),
2
+ // server impure half: local HTTP server over Unix domain socket (Bun.serve).
3
+ //
4
+ // Invariant: The server is the exclusive runtime owner of SQLite.
5
+
6
+ import type { Database } from "bun:sqlite";
7
+ import { unlinkSync } from "node:fs";
8
+ import type { HopTrail } from "#review/findings";
9
+ import type { CanonicalFindingRow, CanonicalRunRow } from "#store/preflight";
10
+ import {
11
+ exportFindingsDocument,
12
+ getFindingTriageByRunId,
13
+ getRunById,
14
+ openProductStore,
15
+ recordFindingTriage,
16
+ saveRunTransaction,
17
+ } from "#store/store";
18
+ import {
19
+ type FindingDetail,
20
+ type HealthResponse,
21
+ type ListRunsResponse,
22
+ matchRoute,
23
+ parseListRunsQuery,
24
+ parseSearchFindingsQuery,
25
+ parseUsageQuery,
26
+ type RecordTriageRequestBody,
27
+ type RecordTriageResponse,
28
+ type SaveRunRequestBody,
29
+ type SaveRunResponse,
30
+ type SearchFindingsResponse,
31
+ type UsageResponse,
32
+ } from "./preflight";
33
+
34
+ export interface ServerOptions {
35
+ dbPath: string;
36
+ socketPath?: string;
37
+ port?: number;
38
+ hostname?: string;
39
+ }
40
+
41
+ export interface StoreServerHandle {
42
+ db: Database;
43
+ url: string;
44
+ socketPath?: string;
45
+ stop: () => void;
46
+ }
47
+
48
+ export function startProductStoreServer(
49
+ options: ServerOptions,
50
+ ): StoreServerHandle {
51
+ const db = openProductStore(options.dbPath);
52
+
53
+ if (options.socketPath) {
54
+ try {
55
+ unlinkSync(options.socketPath);
56
+ } catch {}
57
+ }
58
+
59
+ async function fetchHandler(req: Request): Promise<Response> {
60
+ try {
61
+ const url = new URL(req.url);
62
+ const match = matchRoute(req.method, url.pathname);
63
+
64
+ if (!match) {
65
+ return Response.json({ error: "Not found" }, { status: 404 });
66
+ }
67
+
68
+ switch (match.name) {
69
+ case "health": {
70
+ const count = (
71
+ db.query("SELECT COUNT(*) as c FROM runs;").get() as { c: number }
72
+ ).c;
73
+ const version = (
74
+ db.query("PRAGMA user_version;").get() as { user_version: number }
75
+ ).user_version;
76
+ const body: HealthResponse = {
77
+ status: "ok",
78
+ schema_version: version,
79
+ runs_count: count,
80
+ };
81
+ return Response.json(body);
82
+ }
83
+
84
+ case "save_run": {
85
+ const body = (await req.json()) as SaveRunRequestBody;
86
+ if (!body?.projected?.run) {
87
+ return Response.json(
88
+ { error: "Invalid payload: projected run required" },
89
+ { status: 400 },
90
+ );
91
+ }
92
+ const runId = saveRunTransaction(db, body.projected);
93
+ const response: SaveRunResponse = {
94
+ ok: true,
95
+ run_id: runId,
96
+ run_dir: body.projected.run.run_dir,
97
+ };
98
+ return Response.json(response);
99
+ }
100
+
101
+ case "list_runs": {
102
+ const query = parseListRunsQuery(url);
103
+ let sql = "SELECT * FROM runs WHERE 1=1";
104
+ const params: (string | number)[] = [];
105
+
106
+ if (query.repo_id) {
107
+ sql += " AND repo_id = ?";
108
+ params.push(query.repo_id);
109
+ }
110
+ if (query.pr !== undefined) {
111
+ if (query.pr === 0) {
112
+ sql += " AND (pr = 0 OR pr IS NULL)";
113
+ } else {
114
+ sql += " AND pr = ?";
115
+ params.push(query.pr);
116
+ }
117
+ }
118
+ sql += " ORDER BY generated_at DESC";
119
+ if (query.limit !== undefined) {
120
+ sql += " LIMIT ?";
121
+ params.push(query.limit);
122
+ }
123
+
124
+ const runs = db.query(sql).all(...params) as CanonicalRunRow[];
125
+ const response: ListRunsResponse = { runs };
126
+ return Response.json(response);
127
+ }
128
+
129
+ case "get_run": {
130
+ const id = Number(match.params.id);
131
+ const run = getRunById(db, id);
132
+ if (!run) {
133
+ return Response.json({ error: "Run not found" }, { status: 404 });
134
+ }
135
+ return Response.json({ run });
136
+ }
137
+
138
+ case "get_run_findings_doc": {
139
+ const id = Number(match.params.id);
140
+ const doc = exportFindingsDocument(db, id);
141
+ if (!doc) {
142
+ return Response.json(
143
+ { error: "Run not found or invalid" },
144
+ { status: 404 },
145
+ );
146
+ }
147
+ return Response.json(doc);
148
+ }
149
+
150
+ case "get_run_triage": {
151
+ const id = Number(match.params.id);
152
+ const triage = getFindingTriageByRunId(db, id);
153
+ return Response.json({ triage });
154
+ }
155
+
156
+ case "record_run_triage": {
157
+ const id = Number(match.params.id);
158
+ const run = getRunById(db, id);
159
+ if (!run) {
160
+ return Response.json({ error: "Run not found" }, { status: 404 });
161
+ }
162
+ const body = (await req.json()) as RecordTriageRequestBody;
163
+ const triageId = recordFindingTriage(db, {
164
+ run_id: id,
165
+ finding_id: body.finding_id,
166
+ comment_id: body.comment_id ?? null,
167
+ tag: body.tag,
168
+ verdict: body.verdict ?? null,
169
+ actor: body.actor,
170
+ reasoning: body.reasoning,
171
+ issue_number: body.issue_number ?? null,
172
+ created_at: body.created_at ?? new Date().toISOString(),
173
+ });
174
+ const response: RecordTriageResponse = { ok: true, id: triageId };
175
+ return Response.json(response);
176
+ }
177
+
178
+ case "get_usage": {
179
+ const query = parseUsageQuery(url);
180
+ let sql = "SELECT * FROM runs";
181
+ const params: string[] = [];
182
+
183
+ if (!query.all && query.repo_id) {
184
+ sql += " WHERE repo_id = ?";
185
+ params.push(query.repo_id);
186
+ }
187
+ sql += " ORDER BY generated_at DESC;";
188
+
189
+ const rows = db.query(sql).all(...params) as CanonicalRunRow[];
190
+ let total_tokens = 0;
191
+ let total_cost_usd = 0;
192
+
193
+ for (const r of rows) {
194
+ total_tokens += r.tokens_total;
195
+ total_cost_usd += r.cost_usd_est;
196
+ }
197
+
198
+ const response: UsageResponse = {
199
+ rows,
200
+ total_tokens,
201
+ total_cost_usd,
202
+ };
203
+ return Response.json(response);
204
+ }
205
+
206
+ case "search_findings": {
207
+ const query = parseSearchFindingsQuery(url);
208
+ let sql = `
209
+ SELECT f.*, r.run_dir, r.repo_id
210
+ FROM findings f
211
+ JOIN runs r ON f.run_id = r.id
212
+ WHERE 1=1
213
+ `;
214
+ const params: (string | number)[] = [];
215
+
216
+ if (query.repo_id) {
217
+ sql += " AND r.repo_id = ?";
218
+ params.push(query.repo_id);
219
+ }
220
+ if (query.run_id !== undefined) {
221
+ sql += " AND f.run_id = ?";
222
+ params.push(query.run_id);
223
+ }
224
+ if (query.tier) {
225
+ sql += " AND f.tier = ?";
226
+ params.push(query.tier);
227
+ }
228
+ if (query.path) {
229
+ sql += " AND f.path = ?";
230
+ params.push(query.path);
231
+ }
232
+ sql += " ORDER BY f.run_id DESC, f.finding_order ASC";
233
+ if (query.limit !== undefined) {
234
+ sql += " LIMIT ?";
235
+ params.push(query.limit);
236
+ }
237
+
238
+ const rows = db.query(sql).all(...params) as (CanonicalFindingRow & {
239
+ id: number;
240
+ run_dir: string;
241
+ repo_id: string;
242
+ })[];
243
+
244
+ const findings: FindingDetail[] = [];
245
+ for (const row of rows) {
246
+ const proofRefRows = db
247
+ .query(
248
+ "SELECT proof_ref FROM finding_proof_refs WHERE finding_id = ? ORDER BY ref_order ASC",
249
+ )
250
+ .all(row.id) as { proof_ref: string }[];
251
+
252
+ const hopTrailRows = db
253
+ .query(
254
+ "SELECT step_num, kind, query, reached, is_raw_string FROM finding_hop_trail WHERE finding_id = ? ORDER BY step_order ASC",
255
+ )
256
+ .all(row.id) as {
257
+ step_num: number;
258
+ kind: string;
259
+ query: string;
260
+ reached: string | null;
261
+ is_raw_string: number;
262
+ }[];
263
+
264
+ const isRaw =
265
+ hopTrailRows.length > 0 && hopTrailRows[0]?.is_raw_string === 1;
266
+ const hop_trail: HopTrail = isRaw
267
+ ? hopTrailRows.map((h) => h.query)
268
+ : hopTrailRows.map((h) => ({
269
+ step: h.step_num,
270
+ kind: h.kind,
271
+ query: h.query,
272
+ reached: h.reached ?? "",
273
+ }));
274
+
275
+ findings.push({
276
+ ...row,
277
+ proof_refs: proofRefRows.map((p) => p.proof_ref),
278
+ hop_trail,
279
+ });
280
+ }
281
+
282
+ const response: SearchFindingsResponse = { findings };
283
+ return Response.json(response);
284
+ }
285
+ }
286
+ } catch (error) {
287
+ return Response.json(
288
+ { error: (error as Error).message },
289
+ { status: 500 },
290
+ );
291
+ }
292
+ }
293
+
294
+ let server: ReturnType<typeof Bun.serve>;
295
+ try {
296
+ server = options.socketPath
297
+ ? Bun.serve({
298
+ unix: options.socketPath,
299
+ fetch: fetchHandler,
300
+ })
301
+ : Bun.serve({
302
+ ...(options.port !== undefined ? { port: options.port } : {}),
303
+ ...(options.hostname !== undefined
304
+ ? { hostname: options.hostname }
305
+ : {}),
306
+ fetch: fetchHandler,
307
+ });
308
+ } catch (err) {
309
+ db.close();
310
+ throw err;
311
+ }
312
+
313
+ return {
314
+ db,
315
+ url: server.url?.toString() ?? `unix:${options.socketPath}`,
316
+ socketPath: options.socketPath,
317
+ stop: () => {
318
+ server.stop(true);
319
+ db.close();
320
+ if (options.socketPath) {
321
+ try {
322
+ unlinkSync(options.socketPath);
323
+ } catch {}
324
+ }
325
+ },
326
+ };
327
+ }
@@ -0,0 +1,50 @@
1
+ // The signal handlers' shape: the first signal settles and exits with its own
2
+ // code; every later one waits for that settle instead of starting another.
3
+ export function createSignalHandler(deps: {
4
+ settle: () => Promise<void>;
5
+ exit: (code: number) => void;
6
+ }): (exitCode: number) => () => Promise<void> {
7
+ let signalSettle: Promise<void> | null = null;
8
+ return (exitCode) => async () => {
9
+ if (signalSettle !== null) {
10
+ await signalSettle;
11
+ return;
12
+ }
13
+ signalSettle = (async () => {
14
+ await deps.settle();
15
+ deps.exit(exitCode);
16
+ })();
17
+ await signalSettle;
18
+ };
19
+ }
20
+
21
+ // What the first signal settles: stop spending, then release what this
22
+ // process holds. The OpenCode server close runs CONCURRENTLY with the lock and
23
+ // ledger settles, never ahead of them: a server that ignores SIGTERM takes up
24
+ // to its grace plus reap (~4s), Actions sends SIGKILL ~10s after the first
25
+ // SIGINT, and those settles make network calls. Serialized, a slow server
26
+ // could get the in-flight lock release killed mid-flight, and the next run
27
+ // would skip the head for the rest of the 90-minute TTL (#146).
28
+ export async function settleOnSignal(deps: {
29
+ killChildren: () => void;
30
+ closeServers: () => Promise<void>;
31
+ unregisterRun: () => Promise<void>;
32
+ settleCommitStatus: () => Promise<void>;
33
+ settleAdmissionLedger: () => Promise<void>;
34
+ }): Promise<void> {
35
+ let serversClosed: Promise<void> = Promise.resolve();
36
+ try {
37
+ deps.killChildren();
38
+ serversClosed = deps.closeServers().catch(() => {});
39
+ await deps.unregisterRun();
40
+ } catch {
41
+ // Ignore
42
+ }
43
+ await Promise.all([
44
+ serversClosed,
45
+ (async () => {
46
+ await deps.settleCommitStatus();
47
+ await deps.settleAdmissionLedger();
48
+ })(),
49
+ ]);
50
+ }