@preventive/triage 1.0.0-alpha.46 → 1.0.0-alpha.47

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 (71) hide show
  1. package/common/managed/agent-tasks.ts +5 -3
  2. package/common/managed/github-agents.ts +28 -10
  3. package/out/activity.js +4 -0
  4. package/out/chunk-5AHIQFFG.js +36 -0
  5. package/out/chunk-6ANSHRFQ.js +6 -0
  6. package/out/chunk-6WF3KNTL.js +3 -0
  7. package/out/chunk-7BKKYVWR.js +7 -0
  8. package/out/{chunk-7XRR4OFU.js → chunk-FH24VHSJ.js} +1 -1
  9. package/out/chunk-NOZJULWS.js +52 -0
  10. package/out/{chunk-OKRLLE5I.js → chunk-PWFUOLZK.js} +1 -1
  11. package/out/chunk-S6U2J62U.js +232 -0
  12. package/out/{chunk-G24A42V6.js → chunk-SPEFPML6.js} +1 -1
  13. package/out/chunk-UENXT2HK.js +3 -0
  14. package/out/chunk-VL43BTSO.js +1 -0
  15. package/out/{chunk-3PS4KWD2.js → chunk-WCPJDAYA.js} +1 -1
  16. package/out/chunk-ZCS4UYHI.js +1 -0
  17. package/out/chunk-ZGNMDGSB.js +1 -0
  18. package/out/client-managed-import.js +1 -1
  19. package/out/client-managed.js +22 -22
  20. package/out/client-sync.js +2 -2
  21. package/out/compare.js +14 -14
  22. package/out/dialogs.js +40 -40
  23. package/out/graph.js +11 -11
  24. package/out/index.html +11 -11
  25. package/out/scan.js +2 -2
  26. package/out/terminal.js +6 -6
  27. package/out/view.css +1 -1
  28. package/out/view.js +15 -15
  29. package/package.json +2 -1
  30. package/risk/index.d.ts +4 -2
  31. package/risk/npm/assess.js +15 -4
  32. package/risk/npm/registry.js +6 -1
  33. package/server-managed/activity.ts +24 -11
  34. package/server-managed/app-agents.ts +10 -21
  35. package/server-managed/bundle-build-worker.js +7 -3
  36. package/server-managed/bundle-build.ts +5 -3
  37. package/server-managed/bundle-cache.ts +9 -3
  38. package/server-managed/bundle.ts +3 -4
  39. package/server-managed/commit-coauthors.ts +5 -9
  40. package/server-managed/db-methods.ts +286 -149
  41. package/server-managed/db-neon.ts +11 -4
  42. package/server-managed/http.ts +75 -33
  43. package/server-managed/link-reports.ts +5 -1
  44. package/server-managed/npm-kept.ts +19 -5
  45. package/server-managed/npm-loads.ts +27 -15
  46. package/server-managed/npm-packages.ts +18 -11
  47. package/server-managed/npm-risk.ts +64 -17
  48. package/server-managed/pretty-print.ts +45 -12
  49. package/server-managed/report-store.ts +16 -11
  50. package/server-managed/repository-agents.ts +1 -1
  51. package/server-managed/repository-browser.ts +4 -2
  52. package/server-managed/repository-code.ts +28 -11
  53. package/server-managed/repository-pulse.ts +1 -1
  54. package/server-managed/solidity-entry-points.ts +5 -3
  55. package/server-managed/sql-postgres.ts +3 -0
  56. package/server-managed/sql.ts +2 -1
  57. package/server-managed/storage-db.ts +11 -3
  58. package/server-managed/storage-encryption.ts +7 -4
  59. package/server-managed/storage.ts +4 -2
  60. package/server-managed/team-feed.ts +3 -1
  61. package/server-managed/team-reports.ts +6 -1
  62. package/server-managed/uploads.ts +29 -9
  63. package/out/chunk-4UFAMJAX.js +0 -1
  64. package/out/chunk-BOIXMUU5.js +0 -3
  65. package/out/chunk-CC4OM6TZ.js +0 -3
  66. package/out/chunk-JKGQ3O7O.js +0 -6
  67. package/out/chunk-LE5ZWLG4.js +0 -235
  68. package/out/chunk-MSION3G4.js +0 -36
  69. package/out/chunk-S6GIXWQW.js +0 -52
  70. package/out/chunk-V3KWNNMY.js +0 -1
  71. package/out/chunk-WQ74ZBZF.js +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preventive/triage",
3
- "version": "1.0.0-alpha.46",
3
+ "version": "1.0.0-alpha.47",
4
4
  "description": "Client & relay server for triaging of automated reports",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "author": {
@@ -343,6 +343,7 @@
343
343
  "client/finding-link.js",
344
344
  "client/linked-findings.d.ts",
345
345
  "client/linked-findings.js",
346
+ "out/activity.js",
346
347
  "out/brotli-fallback.js",
347
348
  "out/chunk-*.js",
348
349
  "out/client-managed.js",
package/risk/index.d.ts CHANGED
@@ -40,8 +40,10 @@ export interface AssessNpmOptions {
40
40
  // Where what is read is kept, by type (risk/npm/registry.js and assess.js
41
41
  // name each): `npm/tarballs`, `risk/npm/versions`, `risk/npm/packages`,
42
42
  // `risk/npm/old-versions`, `risk/npm/public`, `risk/npm/downloads`,
43
- // `risk/npm/advisories` and `risk/npm/assessments`.
44
- cache?: CacheStore | false
43
+ // `risk/npm/advisories` and `risk/npm/assessments`. One that reads records
44
+ // of any types at once (`readEach`, each null where none is kept) is read
45
+ // so where risk reads several together.
46
+ cache?: (CacheStore & { readEach?(entries: [type: string, key: string][]): Promise<unknown[]> }) | false
45
47
  // Asks for a package's whole document in risk's stead, as the managed
46
48
  // server does within its bounds: null where npm has none for this asker.
47
49
  // `authorized` whether it may be asked with the caller's npm token: the
@@ -197,15 +197,22 @@ export async function assessNpm(name, version, { oldVersion = null, fromEmpty =
197
197
  const facts = await npmPackageFacts(name, version, oldVersion, context)
198
198
  const old = facts.oldVersion
199
199
  if (old !== null && !facts.versions.has(old)) throw new NpmRiskError('version-not-found', `npm has no ${name}@${old}`)
200
- const malware = npmMalwareFinding({ takenDown: facts.takenDown, advisories: advisories ? await npmVersionAdvisories(name, version, osv, context) : [] })
201
- if (!facts.versions.has(version)) {
200
+ // Its advisories, its lasting risk and its downloads need none of each
201
+ // other, so all are asked at once, and waited on in this order, so that a
202
+ // failure fails it as the first of them failing would.
203
+ const listed = facts.versions.has(version)
204
+ const advised = settledLater(advisories ? npmVersionAdvisories(name, version, osv, context) : Promise.resolve([]))
205
+ const keeping = listed ? settledLater(lasting(name, version, old, facts, context, fromEmpty)) : null
206
+ const counting = listed && downloads && popularity ? settledLater(npmDownloads(name, context)) : null
207
+ const malware = npmMalwareFinding({ takenDown: facts.takenDown, advisories: await advised })
208
+ if (!listed) {
202
209
  if (!malware) throw new NpmRiskError('version-not-found', `npm has no ${name}@${version}`)
203
210
  return { name, version, oldVersion: null, published: facts.removed.get(version), removed: true, findings: [malware], files: {}, dependencies: { added: [], changed: [] },
204
211
  score: npmRiskScore([malware]) }
205
212
  }
206
213
  const { published, manifest } = facts.versions.get(version)
207
- const kept = await lasting(name, version, old, facts, context, fromEmpty)
208
- const counted = downloads && popularity ? await npmDownloads(name, context) : null
214
+ const kept = await keeping
215
+ const counted = await counting
209
216
  const own = npmVersionFindings({ deprecated: facts.deprecated[version], published, minimumReleaseAge, now, known: Boolean(manifest.knownAccounts), scope: npmKnownScope(name),
210
217
  provenance: Boolean(manifest.provenance), downloads: counted })
211
218
  const was = old === null ? null : facts.versions.get(old).published
@@ -225,6 +232,10 @@ export async function assessNpm(name, version, { oldVersion = null, fromEmpty =
225
232
  // A dependency's key among a version's, by its kind and name.
226
233
  const keyOf = row => `${row.kind ?? ''}\0${row.name}`
227
234
 
235
+ // `promise`, waited on later: its failure, if it fails before then, not
236
+ // thrown as unhandled meanwhile.
237
+ const settledLater = promise => { promise.catch(() => {}); return promise }
238
+
228
239
  // The keys of the dependencies a version holds that nothing of it imports
229
240
  // (`kept`, npmLastingRisk's: its `held-unused-deps`), those risk counts
230
241
  // (dependencies.js npmUnusedDependencyCounted).
@@ -87,6 +87,11 @@ async function kept({ cache }, type, key, ask, fresh = () => true) {
87
87
  return value
88
88
  }
89
89
 
90
+ // What is kept under each `[type, key]` of `entries`, in their order, null
91
+ // where nothing is: in one read where the cache reads records of any types at
92
+ // once (`readEach`), else one a key.
93
+ const readEach = (cache, entries) => cache.readEach ? cache.readEach(entries) : Promise.all(entries.map(([type, key]) => cache.read(type, key)))
94
+
90
95
  // An answer's body as JSON, read no further than `limit` bytes.
91
96
  async function jsonOf(res, limit, what) {
92
97
  const tooLarge = () => new NpmRiskError('upstream-too-large', `npm's answer for ${what} is over ${limit} bytes`)
@@ -169,7 +174,7 @@ export async function npmPackageFacts(name, version, oldVersion, context) {
169
174
  const given = oldVersion === true ? fresh(picked) ? picked.oldVersion : undefined : oldVersion
170
175
  if (cache && given !== undefined) {
171
176
  const wanted = given === null ? [version] : [version, given]
172
- const [facts, pkg] = await Promise.all([Promise.all(wanted.map(at => cache.read('risk/npm/versions', `${name}@${at}`))), cache.read('risk/npm/packages', name)])
177
+ const [pkg, ...facts] = await readEach(cache, [['risk/npm/packages', name], ...wanted.map(at => ['risk/npm/versions', `${name}@${at}`])])
173
178
  const gone = at => Object.hasOwn(pkg.removed, at)
174
179
  if (fresh(pkg) && 'removed' in pkg && wanted.every((at, i) => facts[i] || gone(at))) {
175
180
  return { versions: new Map(wanted.flatMap((at, i) => gone(at) ? [] : [[at, facts[i]]])), removed: new Map(wanted.filter(gone).map(at => [at, pkg.removed[at]])),
@@ -176,12 +176,21 @@ export function activityMethods(db: ManagedSql): ActivityStore {
176
176
  const stmts = contexts == null ? admin : manager
177
177
  const scope = contexts == null ? {} : { contexts: JSON.stringify(contexts), userId: userId ?? '' }
178
178
  const params = { ...scope, kind, query, repo, actor }
179
- const { total } = (await stmts.count.get(params)) as { total: number }
180
- const currentPage = Math.min(page, Math.max(1, Math.ceil(total / limit)))
181
- const history = (await stmts.rows.all({ ...params, limit, offset: (currentPage - 1) * limit })) as ActivityEntry[]
182
- const filters: ActivityFilters = {
183
- repos: ((await stmts.repos.all(scope)) as { repo: string }[]).map(row => row.repo),
184
- users: ((await stmts.users.all(scope)) as ActivityFilters['users']).map(row => ({ id: row.id, login: row.login, detail: row.detail })),
179
+ const read = async (at: number) => (await stmts.rows.all({ ...params, limit, offset: (at - 1) * limit })) as (ActivityEntry & { total: number | string })[]
180
+ // A page's rows carry the total. Only a page past the last has none to
181
+ // carry it: it is counted, and the last page read in its place.
182
+ let currentPage = page, rows = await read(page)
183
+ let total = rows.length > 0 ? Number(rows[0]!.total) : 0
184
+ if (rows.length === 0 && page > 1) {
185
+ total = Number(((await stmts.count.get(params)) as { total: number | string }).total)
186
+ currentPage = Math.min(page, Math.max(1, Math.ceil(total / limit)))
187
+ if (currentPage !== page) rows = total === 0 ? [] : await read(currentPage)
188
+ }
189
+ const history = rows.map(({ total: _total, ...entry }) => entry)
190
+ const filters: ActivityFilters = { repos: [], users: [] }
191
+ for (const row of (await stmts.filters.all(scope)) as { facet: string; id: string; login: string; detail: string | null }[]) {
192
+ if (row.facet === 'repo') filters.repos.push(row.id)
193
+ else filters.users.push({ id: row.id, login: row.login, detail: row.detail })
185
194
  }
186
195
  return { history, total, page: currentPage, limit, filters }
187
196
  },
@@ -199,17 +208,21 @@ function activityStatements(db: ManagedSql, source: string) {
199
208
  AND (:repo = '' OR repo = :repo) AND (:actor = '' OR actorKey = :actor)
200
209
  AND (:query = '' OR instr(lower(coalesce(actor, '') || ' ' || action || ' ' ||
201
210
  coalesce(repo, '') || ' ' || coalesce(report, '') || ' ' || coalesce(finding, '')), lower(:query)) > 0)`
211
+ // A page's rows each carry the total, so the source is read once for both;
212
+ // the selector choices, repositories then users, once between them.
202
213
  return {
203
214
  count: db.prepare(`SELECT count(*) AS total FROM (${filtered}) AS filtered`),
204
- rows: db.prepare(`${filtered} ORDER BY at DESC,
215
+ rows: db.prepare(`SELECT filtered.*, count(*) OVER () AS total FROM (${filtered}) AS filtered ORDER BY at DESC,
205
216
  CASE WHEN kind = 'triage' THEN CAST(substr(id, instr(id, ':') + 1) AS INTEGER) ELSE 0 END DESC,
206
217
  id DESC LIMIT :limit OFFSET :offset`),
207
- repos: db.prepare(`${activity} SELECT DISTINCT repo FROM activity WHERE repo IS NOT NULL AND repo <> '' ORDER BY repo`),
208
- users: db.prepare(`${activity} SELECT a.actorKey AS id, COALESCE(u.login, a.actor, a.actorId) AS login,
209
- CASE WHEN a.actorId IS NULL THEN 'Legacy actor' ELSE NULL END AS detail FROM (
218
+ filters: db.prepare(`${activity} SELECT 'repo' AS facet, repo AS id, repo AS login, NULL AS detail, repo AS sort, '' AS tiebreak
219
+ FROM (SELECT DISTINCT repo FROM activity WHERE repo IS NOT NULL AND repo <> '') AS repos
220
+ UNION ALL SELECT 'user' AS facet, a.actorKey AS id, COALESCE(u.login, a.actor, a.actorId) AS login,
221
+ CASE WHEN a.actorId IS NULL THEN 'Legacy actor' ELSE NULL END AS detail, COALESCE(u.login, a.actor, a.actorId) AS sort, a.actorKey AS tiebreak FROM (
210
222
  SELECT actorKey, actorId, actor, ROW_NUMBER() OVER (PARTITION BY actorKey ORDER BY at DESC, id DESC) AS position
211
223
  FROM activity WHERE actorKey IS NOT NULL AND actorKey <> 'legacy:'
212
- ) a LEFT JOIN managed_user u ON u.id = a.actorId WHERE a.position = 1 ORDER BY login, a.actorKey`),
224
+ ) a LEFT JOIN managed_user u ON u.id = a.actorId WHERE a.position = 1
225
+ ORDER BY facet, sort, tiebreak`),
213
226
  }
214
227
  }
215
228
 
@@ -2,29 +2,18 @@
2
2
  // tab's, server-managed/repository-agents.ts, whose marks the Commits tab
3
3
  // reads on commits too, repository-history.ts).
4
4
  import type { AppAgent, AppAgentMarks } from '../common/managed/agent-tasks.ts'
5
- import { GITHUB_AGENTS } from '../common/managed/github-agents.ts'
5
+ import { GITHUB_AGENTS, type GithubAgent } from '../common/managed/github-agents.ts'
6
6
 
7
7
  // The agents known by their GitHub Apps or accounts, beside Claude and
8
- // Codex: each its id and name, its avatar (its mark, served by
9
- // /api/avatar/<avatar>, for these alone: a GitHub App's, `app-<id>`, or
10
- // account's, `user-<id>`), the fingerprint it leaves as a line of its pull
11
- // requests' bodies and its commits' messages, the account its work is
12
- // authored by (its id and the logins GitHub names it by, told by both), and
13
- // its branches' prefix. Their work may carry Claude's or
14
- // Codex's marks too, those its tools. Copilot's coding agent opens its pull
15
- // requests and authors its commits as its account, Copilot (198982749), on
16
- // `copilot/` branches; Dependabot, its GitHub App (29110), opens its pull
17
- // requests as its account, `dependabot` (49699333, `dependabot[bot]` to
18
- // GitHub's REST API and in its address), on `dependabot/<ecosystem>/…`
19
- // branches. Their accounts and marks are those the app draws their work by
20
- // wherever it shows it (common/managed/github-agents.ts): Copilot's its own,
21
- // the app's to draw, no avatar.
22
- const { copilot, dependabot } = GITHUB_AGENTS
23
- export const APP_AGENTS: readonly (AppAgent & AppAgentMarks)[] = [
24
- { id: 'neo', name: 'Neo', avatar: 'app-3115942', fingerprint: '🤖 Generated with [Neo](', prefix: 'neo/' },
25
- { id: 'copilot', name: copilot.name, account: copilot.accounts[0], prefix: 'copilot/' },
26
- { id: 'dependabot', name: dependabot.name, avatar: dependabot.avatar, account: dependabot.accounts[0], prefix: 'dependabot/' },
27
- ]
8
+ // Codex: those of GITHUB_AGENTS with branches of their own, in its order
9
+ // (common/managed/github-agents.ts, where each is told), each its id and
10
+ // name, its avatar (its mark, served by /api/avatar/<avatar>, a GitHub
11
+ // App's, `app-<id>`), the fingerprint it leaves, the account its work is
12
+ // authored by (its id and the logins GitHub names it by, told by both, or by
13
+ // its id alone where it names none), and its branches' prefix.
14
+ export const APP_AGENTS: readonly (AppAgent & AppAgentMarks)[] = (Object.entries(GITHUB_AGENTS) as [string, GithubAgent][])
15
+ .flatMap(([id, { name, avatar, accounts: [account], prefix, fingerprint }]) => prefix ? [{ id, name, prefix, ...avatar ? { avatar } : {},
16
+ ...account?.id === undefined ? {} : { account: { id: account.id, logins: account.logins } }, ...fingerprint ? { fingerprint } : {} }] : [])
28
17
  // The prefixes of the branches agents work on: Claude Code's and Codex's,
29
18
  // and the app agents'.
30
19
  export const AGENT_BRANCH_PREFIXES = ['claude/', 'codex/', ...APP_AGENTS.map(agent => agent.prefix)]
@@ -96,13 +96,17 @@ export function buildErrorCode(error, message) {
96
96
  if (parentPort && workerData?.type === 'managed-bundle-build') {
97
97
  // Send diagnostics to the request's parent thread, which writes them before
98
98
  // returning the HTTP response. Worker stdout can be lost on termination.
99
- const send = message => {
99
+ const send = (message, transfer = []) => {
100
100
  // Node worker messages have no browser target origin.
101
101
  // oxlint-disable-next-line unicorn/require-post-message-target-origin
102
- parentPort.postMessage(message)
102
+ parentPort.postMessage(message, transfer)
103
103
  }
104
104
  try {
105
- send(await buildStasisBundle(workerData, undefined, stage => send({ type: 'progress', stage })))
105
+ const built = await buildStasisBundle(workerData, undefined, stage => send({ type: 'progress', stage }))
106
+ // The bytes handed over rather than copied, where they alone fill their
107
+ // buffer (a small one may share Node's pool, which can't be moved).
108
+ const { bytes } = built
109
+ send(built, bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength ? [bytes.buffer] : [])
106
110
  } catch (error) {
107
111
  const diagnostic = bundleBuildDiagnostic(error, workerData.token)
108
112
  const code = buildErrorCode(error, diagnostic.message)
@@ -95,7 +95,7 @@ export function githubBundleFilename(github: string, directory: string, commit:
95
95
  return `${repo}.${dir}${tail}`
96
96
  }
97
97
 
98
- export interface BuiltBundle { bytes: Uint8Array; directory: string; filename: string }
98
+ export interface BuiltBundle { bytes: Buffer; directory: string; filename: string }
99
99
  export interface BuildRequest {
100
100
  input: BundleBuildInput; github: string; token: string | null; maxBytes: number; scopes: (string | null)[]
101
101
  // Upstream's disk cache for what a build fetches (setCacheDir), or null for
@@ -174,14 +174,16 @@ export async function buildRepositoryBundle(userId: string, request: BuildReques
174
174
  const abort = () => fail(signal.reason instanceof BundleBuildError ? signal.reason.status : 499,
175
175
  signal.reason instanceof BundleBuildError ? signal.reason.code : 'build-cancelled')
176
176
  signal.addEventListener('abort', abort, { once: true })
177
- running.on('message', (message: BuiltBundle & { type?: string; stage?: BundleBuildStage; error?: string; status?: number; diagnostic?: BundleBuildDiagnostic }) => {
177
+ running.on('message', (message: Omit<BuiltBundle, 'bytes'> & { bytes: Uint8Array; type?: string; stage?: BundleBuildStage; error?: string; status?: number; diagnostic?: BundleBuildDiagnostic }) => {
178
178
  if (settled) return
179
179
  if (message.type === 'progress' && message.stage) { stage = message.stage; log('progress'); return }
180
180
  if (message.error) { fail(message.status ?? 422, message.error, { diagnostic: message.diagnostic }); return }
181
181
  settled = true
182
182
  cleanup()
183
183
  log('completed', { byteSize: message.bytes.length })
184
- resolve({ bytes: Buffer.from(message.bytes), directory: message.directory, filename: message.filename })
184
+ // A view of the bytes the worker handed over, not a copy of them.
185
+ const { bytes } = message
186
+ resolve({ bytes: Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength), directory: message.directory, filename: message.filename })
185
187
  })
186
188
  running.once('error', error => fail(422, 'build-failed', { diagnostic: bundleBuildDiagnostic(error, request.token) }))
187
189
  running.once('exit', exitCode => fail(422, 'build-failed', { exitCode }))
@@ -111,16 +111,22 @@ async function build(record: BundleCacheRecord, storage: BundleCacheStorage, db:
111
111
  const metadata = { ...await createBundleMetadata(details), id: record.id, filename: record.filename }
112
112
  const body = await encodeBrotli(Buffer.from(JSON.stringify(metadata)))
113
113
  if (!(await db.getBundle(record.id))) throw new Error('Bundle deleted')
114
- await storage.put(record.id, filename, body)
115
- if (record.kind === 'stasis') await storage.put(record.id, packagesFilename, encodePackageInventory(details))
116
114
  const summary = bundleSummary(details, metadata)
117
- await storage.put(record.id, SUMMARY_FILENAME, Buffer.from(JSON.stringify(summary)))
115
+ // Written together, each settled before the row is looked at again: one
116
+ // failing leaves the others, which a later open builds over.
117
+ const written = await Promise.allSettled([
118
+ storage.put(record.id, filename, body),
119
+ ...record.kind === 'stasis' ? [storage.put(record.id, packagesFilename, encodePackageInventory(details))] : [],
120
+ storage.put(record.id, SUMMARY_FILENAME, Buffer.from(JSON.stringify(summary))),
121
+ ])
118
122
  // A different instance may have deleted the row while these writes ran.
119
123
  // Reconcile after publishing so its cleanup cannot be undone by us.
120
124
  if (!(await db.getBundle(record.id))) {
121
125
  await storage.delete(record.id)
122
126
  throw new Error('Bundle deleted')
123
127
  }
128
+ const failed = written.find(result => result.status === 'rejected')
129
+ if (failed) throw failed.reason
124
130
  return summary
125
131
  }
126
132
 
@@ -109,10 +109,9 @@ export async function bundleFilePrefix(bytes: Buffer): Promise<string> {
109
109
  }
110
110
 
111
111
  // Extract the bundle integrities a report declares (its top-level
112
- // `bundleHashes`). Non-JSON reports (markdown / CSV) or a missing field → [].
113
- export function reportBundleHashes(bytes: Buffer): string[] {
114
- let data: unknown
115
- try { data = JSON.parse(bytes.toString('utf8')) } catch { return [] }
112
+ // `bundleHashes`), from the JSON it parsed to (readManagedReport's, as is).
113
+ // Non-JSON reports (markdown / CSV, given as null) or a missing field → [].
114
+ export function reportBundleHashes(data: unknown): string[] {
116
115
  if (data == null || typeof data !== 'object') return []
117
116
  const hashes = (data as { bundleHashes?: unknown }).bundleHashes
118
117
  if (!Array.isArray(hashes)) return []
@@ -10,15 +10,14 @@ export const MAX_COAUTHORS = 3
10
10
  // The rules co-authors are read by, the agents' addresses and names among
11
11
  // them: what was kept read by others (history pages, squashed pull requests)
12
12
  // read again by these, once raised.
13
- export const COAUTHORS_READ = 2
13
+ export const COAUTHORS_READ = 3
14
14
  const MAX_NAME = 256
15
15
  const textOf = (value: unknown, max: number) => typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : null
16
16
 
17
17
  // One who made a commit beside its author: by name and account, as its
18
- // author is, and the agent it is where known, one GitHub knows by its account
19
- // or its commits' address or name (common/managed/github-agents.ts) or one
20
- // the server knows by its app (app-agents.ts), with its avatar.
21
- export interface Coauthor { name: string | null; login: string | null; id: number | null; agent?: string; avatar?: string }
18
+ // author is, and the agent it is where known (common/managed/github-agents.ts),
19
+ // by its account, its commits' address or name, or the marks it leaves.
20
+ export interface Coauthor { name: string | null; login: string | null; id: number | null; agent?: string }
22
21
 
23
22
  // `Co-authored-by: <name> <address>` trailers, GitHub matching the key
24
23
  // regardless of case; Cursor's agents' links, as their work carries them;
@@ -75,9 +74,6 @@ export function coauthorsOf(message: unknown, author: Maker, listed: Maker[] | n
75
74
  const { login, id } = agent && maker.account.login && githubAgent(maker.account.login, maker.account.id) !== agent ? { login: null, id: null } : maker.account
76
75
  add({ name: textOf(maker.name, MAX_NAME), login, id, ...agent ? { agent } : {} }, maker.email)
77
76
  }
78
- for (const agent of marked) {
79
- const app = APP_AGENTS.find(known => known.id === agent && !Object.hasOwn(GITHUB_AGENTS, known.id))
80
- add({ name: app?.name ?? GITHUB_AGENTS[agent as GithubAgentId].name, login: null, id: null, agent, ...app?.avatar ? { avatar: app.avatar } : {} })
81
- }
77
+ for (const agent of marked) add({ name: GITHUB_AGENTS[agent as GithubAgentId].name, login: null, id: null, agent })
82
78
  return coauthors
83
79
  }