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

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 (207) hide show
  1. package/client/linked-findings.js +3 -0
  2. package/common/bundle-metadata.d.ts +1 -0
  3. package/common/bundle-metadata.js +1 -1
  4. package/common/bundle-sources.js +25 -2
  5. package/common/default-scan-models.ts +1 -1
  6. package/common/dependency-reviews.d.ts +0 -5
  7. package/common/dependency-reviews.js +0 -17
  8. package/common/line-diff.js +5 -4
  9. package/common/managed/agent-tasks.ts +292 -0
  10. package/common/managed/github-agents.ts +92 -0
  11. package/common/managed/github-logins.ts +49 -0
  12. package/common/managed/roles.ts +7 -0
  13. package/common/managed/routes.js +88 -7
  14. package/common/managed/team-app.d.ts +5 -2
  15. package/common/managed/team-app.js +2 -2
  16. package/common/server-info.ts +3 -0
  17. package/common/workspace-app.js +6 -3
  18. package/out/brotli-fallback.js +3 -3
  19. package/out/chunk-2XUEZHIP.js +18 -18
  20. package/out/chunk-2ZDZWLFY.js +1 -0
  21. package/out/chunk-3PS4KWD2.js +10 -0
  22. package/out/chunk-4HI2MSAV.js +17 -0
  23. package/out/chunk-4UFAMJAX.js +1 -0
  24. package/out/chunk-7C7DWL7I.js +1 -0
  25. package/out/chunk-7XRR4OFU.js +1 -0
  26. package/out/chunk-BC2UCLFJ.js +1 -0
  27. package/out/chunk-BOIXMUU5.js +3 -0
  28. package/out/chunk-C4Z6ZBXV.js +6 -6
  29. package/out/chunk-CC4OM6TZ.js +3 -0
  30. package/out/chunk-G24A42V6.js +2 -0
  31. package/out/chunk-GDPCLSOS.js +2 -0
  32. package/out/chunk-GO7FT4OD.js +1 -0
  33. package/out/chunk-I2MDGSQX.js +3 -0
  34. package/out/chunk-IYPY47MC.js +1 -0
  35. package/out/chunk-IZ7POWI3.js +18 -0
  36. package/out/chunk-JCIIBLKR.js +1 -1
  37. package/out/chunk-JKGQ3O7O.js +6 -0
  38. package/out/chunk-LE5ZWLG4.js +235 -0
  39. package/out/chunk-MSION3G4.js +36 -0
  40. package/out/chunk-NRPC74AM.js +1 -1
  41. package/out/chunk-OKRLLE5I.js +17 -0
  42. package/out/chunk-OOJM4CTU.js +1 -1
  43. package/out/chunk-PNHBZGDD.js +1 -1
  44. package/out/chunk-PXK7EU4V.js +1 -0
  45. package/out/chunk-QB4CBOX2.js +1 -0
  46. package/out/chunk-R3NZFXVR.js +1 -0
  47. package/out/chunk-R5O6FAW4.js +1 -1
  48. package/out/chunk-S6GIXWQW.js +52 -0
  49. package/out/chunk-SXV2T5C4.js +80 -0
  50. package/out/chunk-TUII34K2.js +1 -1
  51. package/out/chunk-V3KWNNMY.js +1 -0
  52. package/out/chunk-VFWMQ3LG.js +2 -0
  53. package/out/chunk-VH4XMZIW.js +2 -0
  54. package/out/chunk-WFYLMF6Z.js +10 -0
  55. package/out/chunk-WQ74ZBZF.js +7 -0
  56. package/out/client-managed-import.js +3 -3
  57. package/out/client-managed.js +31 -35
  58. package/out/client-sync.js +11 -11
  59. package/out/compare.js +35 -0
  60. package/out/dialogs.js +51 -0
  61. package/out/github-issue-authorized.html +1 -1
  62. package/out/github-issue-authorized.js +1 -1
  63. package/out/graph.js +17 -17
  64. package/out/index.html +30 -34
  65. package/out/prism.js +14 -14
  66. package/out/scan.js +2 -0
  67. package/out/terminal.js +294 -293
  68. package/out/view.css +1 -1
  69. package/out/view.js +16 -107
  70. package/package.json +53 -6
  71. package/risk/actions/findings.js +161 -0
  72. package/risk/actions/resolve.js +219 -0
  73. package/risk/actions/scripts/commands.js +182 -0
  74. package/risk/actions/scripts/grade.js +113 -0
  75. package/risk/actions/scripts/packages.js +123 -0
  76. package/risk/actions/scripts/shell.js +169 -0
  77. package/risk/actions/uses.js +76 -0
  78. package/risk/actions/workflow.js +110 -0
  79. package/risk/files/hosts.js +6 -6
  80. package/risk/files/readability.js +23 -17
  81. package/risk/files/runs-code.js +18 -6
  82. package/risk/files/script.js +7 -3
  83. package/risk/files/stamps.js +8 -7
  84. package/risk/index.d.ts +71 -1
  85. package/risk/index.js +6 -2
  86. package/risk/npm/assess.js +1 -1
  87. package/risk/npm/compare.js +34 -10
  88. package/risk/npm/files.js +413 -2
  89. package/risk/npm/tarball.js +56 -73
  90. package/server-e2e/app.ts +5 -4
  91. package/server-e2e/http.ts +5 -2
  92. package/server-managed/agent-merges.ts +198 -0
  93. package/server-managed/app-agents.ts +30 -0
  94. package/server-managed/avatar-store.ts +1 -0
  95. package/server-managed/bundle-cache.ts +7 -1
  96. package/server-managed/combined.ts +3 -2
  97. package/server-managed/commit-coauthors.ts +83 -0
  98. package/server-managed/commit-lockfiles.ts +72 -0
  99. package/server-managed/config.ts +6 -0
  100. package/server-managed/db-methods.ts +66 -19
  101. package/server-managed/db-neon.ts +89 -21
  102. package/server-managed/db-schema.ts +13 -2
  103. package/server-managed/db.ts +9 -1
  104. package/server-managed/dependabot-access.ts +60 -0
  105. package/server-managed/dependabot-alerts.ts +185 -0
  106. package/server-managed/dependency-review-comments.ts +97 -0
  107. package/server-managed/dependency-reviews.ts +78 -18
  108. package/server-managed/github-accounts.ts +33 -0
  109. package/server-managed/github-actions.ts +71 -0
  110. package/server-managed/github-app.ts +33 -13
  111. package/server-managed/github-errors.ts +2 -0
  112. package/server-managed/github-issue-links.ts +11 -5
  113. package/server-managed/github-link-oauth.ts +69 -0
  114. package/server-managed/github-links.ts +204 -0
  115. package/server-managed/github-oauth.ts +5 -2
  116. package/server-managed/github-pulls.ts +2 -2
  117. package/server-managed/github-requests.ts +39 -0
  118. package/server-managed/github-users.ts +30 -0
  119. package/server-managed/http-response.ts +10 -2
  120. package/server-managed/http.ts +1251 -97
  121. package/server-managed/index.ts +13 -8
  122. package/server-managed/kept-briefly.ts +37 -0
  123. package/server-managed/locked-packages.ts +37 -16
  124. package/server-managed/lockfile-scope.ts +49 -0
  125. package/server-managed/npm-delta-worker.js +23 -0
  126. package/server-managed/npm-delta.ts +178 -0
  127. package/server-managed/npm-insights.ts +20 -11
  128. package/server-managed/npm-kept.ts +83 -6
  129. package/server-managed/npm-loads.ts +114 -37
  130. package/server-managed/npm-packages.ts +110 -64
  131. package/server-managed/npm-risk.ts +4 -1
  132. package/server-managed/pretty-print.ts +67 -23
  133. package/server-managed/pull-comment-reviews.ts +161 -0
  134. package/server-managed/pull-dependencies.ts +300 -0
  135. package/server-managed/pull-dependency-reviews.ts +318 -0
  136. package/server-managed/pull-reviews.ts +205 -0
  137. package/server-managed/queue.ts +16 -0
  138. package/server-managed/release-commits.ts +84 -0
  139. package/server-managed/rename-diff.ts +22 -13
  140. package/server-managed/report-sources.ts +1 -1
  141. package/server-managed/report-store.ts +42 -9
  142. package/server-managed/repository-actions.ts +218 -0
  143. package/server-managed/repository-agents.ts +220 -0
  144. package/server-managed/repository-browser.ts +166 -37
  145. package/server-managed/repository-changes.ts +284 -0
  146. package/server-managed/repository-code.ts +52 -0
  147. package/server-managed/repository-dependency-reviews.ts +157 -0
  148. package/server-managed/repository-history.ts +461 -0
  149. package/server-managed/repository-issues.ts +181 -0
  150. package/server-managed/repository-pulse.ts +439 -0
  151. package/server-managed/repository-risk-audit.ts +13 -0
  152. package/server-managed/repository-risk-read.ts +170 -0
  153. package/server-managed/repository-risk.ts +133 -118
  154. package/server-managed/reviewed-dependencies.ts +149 -0
  155. package/server-managed/session.ts +27 -9
  156. package/server-managed/sql.ts +6 -3
  157. package/server-managed/storage-stores.ts +5 -0
  158. package/server-managed/storage.ts +4 -2
  159. package/server-managed/team-app.ts +19 -3
  160. package/server-managed/team-reports.ts +24 -12
  161. package/server-managed/upstream-cache.ts +12 -0
  162. package/server-managed/workspace-shares.ts +4 -1
  163. package/server.ts +25 -5
  164. package/out/chunk-2ABLKCOY.js +0 -46
  165. package/out/chunk-2KBF5TZ7.js +0 -2
  166. package/out/chunk-35VE6CDH.js +0 -2
  167. package/out/chunk-3BZ7JERB.js +0 -1
  168. package/out/chunk-4XCDFGDP.js +0 -10
  169. package/out/chunk-5LSXOLUS.js +0 -1
  170. package/out/chunk-5RCM2J63.js +0 -1
  171. package/out/chunk-7B6HB4D7.js +0 -1
  172. package/out/chunk-AJ4GTATZ.js +0 -3
  173. package/out/chunk-CH4UN6WK.js +0 -225
  174. package/out/chunk-CMQA4DM6.js +0 -1
  175. package/out/chunk-CVVJAXVY.js +0 -2
  176. package/out/chunk-DIJJNTRH.js +0 -10
  177. package/out/chunk-EDKLBQQN.js +0 -17
  178. package/out/chunk-F47DXCEV.js +0 -33
  179. package/out/chunk-FK3DZEKL.js +0 -1
  180. package/out/chunk-G6AJWENO.js +0 -1
  181. package/out/chunk-GJ4IUCNS.js +0 -1
  182. package/out/chunk-GNXOKIGP.js +0 -80
  183. package/out/chunk-GZ4MS3TE.js +0 -13
  184. package/out/chunk-GZWM7UQM.js +0 -2
  185. package/out/chunk-IU3CCINR.js +0 -3
  186. package/out/chunk-K3X5EJBQ.js +0 -2
  187. package/out/chunk-KEX2ATEW.js +0 -2
  188. package/out/chunk-KYCNJVB7.js +0 -1
  189. package/out/chunk-LPCTJYNA.js +0 -7
  190. package/out/chunk-O4RJY5TP.js +0 -2
  191. package/out/chunk-OD4LPN3H.js +0 -1
  192. package/out/chunk-QWDWTBM7.js +0 -1
  193. package/out/chunk-QYWKC557.js +0 -1
  194. package/out/chunk-R75XOKUP.js +0 -1
  195. package/out/chunk-SWTLADW5.js +0 -1
  196. package/out/chunk-T7OKH4VW.js +0 -1
  197. package/out/chunk-TZ5KB2Y5.js +0 -10
  198. package/out/chunk-UNTRGE26.js +0 -2
  199. package/out/chunk-UTR2LVME.js +0 -2
  200. package/out/chunk-UYAXVRVL.js +0 -1
  201. package/out/chunk-V3ME6FI5.js +0 -2
  202. package/out/chunk-V5O7M2YT.js +0 -1
  203. package/out/chunk-VIHGO77Y.js +0 -1
  204. package/out/chunk-W4J3MGLB.js +0 -1
  205. package/out/chunk-WGG7KQUH.js +0 -1
  206. package/out/chunk-XYFXXB2G.js +0 -10
  207. package/out/chunk-ZESLQCTF.js +0 -6
@@ -59,6 +59,9 @@ export type HttpServerDeps = {
59
59
  handleSaveRest: (req: HttpRequest, res: ServerResponse) => Promise<void>
60
60
  restPutIdleTimeoutMs: number
61
61
  debug: boolean
62
+ // Serve the static UI bundle (default). False serves only the API and
63
+ // never reads `out/`, for hosts that serve the UI themselves.
64
+ ui?: boolean
62
65
  }
63
66
 
64
67
  // `POST /api/sync/save` dispatch. Returns the in-flight handler promise when
@@ -114,12 +117,12 @@ function dispatchSaveRest(
114
117
  }
115
118
 
116
119
  export function createHttpServer(deps: HttpServerDeps): Server {
117
- const { wss, restDeps, sseServer, serverInfo, isOriginAllowed, isShuttingDown, track, handleSaveRest, restPutIdleTimeoutMs, debug } = deps
120
+ const { wss, restDeps, sseServer, serverInfo, isOriginAllowed, isShuttingDown, track, handleSaveRest, restPutIdleTimeoutMs, debug, ui = true } = deps
118
121
  // Static-file plane (see ./static.ts). The directory is the
119
122
  // `build.js build` output sibling to this file; the loader handles
120
123
  // enumeration, pre-compression, and ETag derivation. Plugged in after
121
124
  // the `/api/objstore/...` REST branch.
122
- const handleStatic = loadStatic(fileURLToPath(new URL('../out', import.meta.url)), serverInfo.deepviewScanServer ?? null)
125
+ const handleStatic = ui ? loadStatic(fileURLToPath(new URL('../out', import.meta.url)), serverInfo.deepviewScanServer ?? null) : () => false
123
126
 
124
127
  const httpServer = createServer((req: HttpRequest, res: ServerResponse) => {
125
128
  // Static mode probe: GET /api/config → this server's `server-info` as JSON.
@@ -0,0 +1,198 @@
1
+ // The commits agents' pull requests brought to a repository's default
2
+ // branch, for its Pulse (repository-pulse.ts commitStats): an agent that
3
+ // commits as whoever ran it (Codex's own) leaves its commits no mark, its
4
+ // pull request's branch alone naming it (app-agents.ts
5
+ // AGENT_BRANCH_PREFIXES), or a label one who ran it gave it naming the agent
6
+ // (agent-tasks.ts labelAgents), as the Agents tab tells an agent's work; or
7
+ // its author, an account agents work as (github-agents.ts AGENT_OPERATED).
8
+ import { labelAgents } from '../common/managed/agent-tasks.ts'
9
+ import { GITHUB_AGENTS, agentOperated } from '../common/managed/github-agents.ts'
10
+ import { AGENT_BRANCH_PREFIXES, APP_AGENTS } from './app-agents.ts'
11
+ import { type HistoryCommit, githubGraphql } from './repository-history.ts'
12
+
13
+ // The merged pull requests read an answer, a page a query, as many queries
14
+ // as MERGED_QUERIES, the rest left for the next to ask; of each, as many of
15
+ // its latest commits as MERGED_COMMITS.
16
+ const MERGED_PAGE = 100
17
+ const MERGED_QUERIES = 5
18
+ const MERGED_COMMITS = 100
19
+ // Of each, as many labels as MERGED_LABELS, GitHub's most a page, a label
20
+ // naming any agent the app knows making it an agent's.
21
+ const MERGED_LABELS = 100
22
+ // How long before or after a pull request rebased onto the branch was merged
23
+ // its copies are committed.
24
+ const REBASE_SKEW_MS = 10 * 60_000
25
+ const LABEL_AGENTS = [...new Set([...Object.keys(GITHUB_AGENTS), ...APP_AGENTS.map(agent => agent.id)])]
26
+ const SHA = /^[a-f\d]{40}$/u
27
+
28
+ const count = (value: unknown) => Number.isSafeInteger(value) && (value as number) >= 0 ? value as number : 0
29
+ const timeOf = (value: unknown) => {
30
+ const at = typeof value === 'string' ? Date.parse(value) : Number.NaN
31
+ return Number.isSafeInteger(at) ? at : null
32
+ }
33
+
34
+ // The agents' pull requests merged since a year's start, as read so far
35
+ // (agentMerges): the commits each brought, and when it was merged; those
36
+ // rebased onto the branch by their last commit there, when merged, and
37
+ // their commits' subjects, the oldest first (agentCommits); when the newest
38
+ // read was last updated, those updated since read again (`through`, null
39
+ // till all are read once); and a read not finished: where it goes on
40
+ // (`after`), when the newest it began with was updated (`from`), the oldest
41
+ // it reads to (`stop`) and how many it has read (`read`). And of every pull
42
+ // request merged, an agent's or not, its merge commit and when (`pulls`),
43
+ // and one rebased so (`pullRebases`), for the commits pushed to the branch
44
+ // directly to be told (directCommits).
45
+ export interface AgentMerges { merges: [string, number][]; rebases: Rebase[]; through: number | null
46
+ next: { after: string; from: number; stop: number; read: number } | null; pulls?: [string, number][]; pullRebases?: Rebase[] }
47
+ // A pull request rebased onto the branch: its last commit there, when it was
48
+ // merged, its latest commits' subjects, the oldest first, and how many more
49
+ // it had than those read (`more`).
50
+ type Rebase = [sha: string, at: number, subjects: string[], more?: number]
51
+
52
+ const MERGED_QUERY = `query($owner: String!, $name: String!, $after: String) {
53
+ repository(owner: $owner, name: $name) {
54
+ pullRequests(states: MERGED, first: ${MERGED_PAGE}, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }) {
55
+ pageInfo { hasNextPage endCursor }
56
+ nodes { updatedAt mergedAt headRefName author { login ... on User { databaseId } } labels(first: ${MERGED_LABELS}) { nodes { name } }
57
+ mergeCommit { oid parents { totalCount } }
58
+ commits(last: ${MERGED_COMMITS}) { totalCount nodes { commit { oid messageHeadline changedFilesIfAvailable } } } }
59
+ }
60
+ }
61
+ }`
62
+ type MergedPage = { repository?: { pullRequests?: { pageInfo?: { hasNextPage?: unknown; endCursor?: unknown }
63
+ nodes?: ({ updatedAt?: unknown; mergedAt?: unknown; headRefName?: unknown; author?: { login?: unknown; databaseId?: unknown } | null
64
+ labels?: { nodes?: ({ name?: unknown } | null)[] } | null
65
+ mergeCommit?: { oid?: unknown; parents?: { totalCount?: unknown } | null } | null
66
+ commits?: { totalCount?: unknown; nodes?: ({ commit?: { oid?: unknown; messageHeadline?: unknown; changedFilesIfAvailable?: unknown } | null } | null)[] } | null
67
+ } | null)[] } | null } | null }
68
+ const agentBranch = (name: unknown) => typeof name === 'string' && AGENT_BRANCH_PREFIXES.some(prefix => name.startsWith(prefix))
69
+ type MergedNode = NonNullable<NonNullable<NonNullable<NonNullable<MergedPage['repository']>['pullRequests']>['nodes']>[number]>
70
+ // Whether a pull request is an agent's: by its branch, a label naming one,
71
+ // or its author, an account agents work as.
72
+ const agentPull = ({ headRefName, labels, author }: MergedNode) => agentBranch(headRefName)
73
+ || labelAgents((labels?.nodes ?? []).map(label => label?.name), LABEL_AGENTS).length > 0
74
+ || agentOperated(typeof author?.login === 'string' ? author.login : null, Number.isSafeInteger(author?.databaseId) ? author!.databaseId as number : null)
75
+
76
+ // The commits the pull requests merged since `since` from an agent's branch,
77
+ // labelled for one, or opened by an account agents work as, brought: each its merge commit, a squash merge's one
78
+ // commit; where it was
79
+ // merged with a merge commit, which a year counts none of, its own commits,
80
+ // its latest MERGED_COMMITS; and of one of more commits whose merge commit
81
+ // has one parent, its commits' subjects, for those it was rebased as to be
82
+ // told by (agentCommits), those of its empty commits left out, as a rebase
83
+ // leaves them. Those merged are read the most recently updated
84
+ // first (a pull request is updated when merged, or after), on from what was
85
+ // `kept`: till one updated before the year, or before the newest read before
86
+ // was, as many queries an answer as MERGED_QUERIES, a read not finished
87
+ // going on from where it was left by the next; one read again whose label
88
+ // no longer names an agent, what it was read to bring forgotten.
89
+ export async function agentMerges(fullName: string, token: string, since: number, kept: AgentMerges | null,
90
+ fetchImpl: typeof fetch = globalThis.fetch): Promise<AgentMerges> {
91
+ const [owner, name] = fullName.split('/') as [string, string]
92
+ const merges = new Map((kept?.merges ?? []).filter(([, at]) => at >= since))
93
+ const rebases = new Map((kept?.rebases ?? []).filter(([, at]) => at >= since).map(([sha, at, subjects, more = 0]) => [sha, [at, subjects, more] as const]))
94
+ const pulls = new Map((kept?.pulls ?? []).filter(([, at]) => at >= since))
95
+ const pullRebases = new Map((kept?.pullRebases ?? []).filter(([, at]) => at >= since).map(([sha, at, subjects, more = 0]) => [sha, [at, subjects, more] as const]))
96
+ const stop = kept?.next?.stop ?? Math.max(since, kept?.through ?? since)
97
+ const listed = (map: typeof rebases) => [...map].map(([sha, [at, subjects, more]]): Rebase => more > 0 ? [sha, at, subjects, more] : [sha, at, subjects])
98
+ const result = (through: number | null, next: AgentMerges['next']): AgentMerges => ({ merges: [...merges], rebases: listed(rebases), through, next,
99
+ pulls: [...pulls], pullRebases: listed(pullRebases) })
100
+ let { after = null, from = null, read = 0 }: { after?: string | null; from?: number | null; read?: number } = kept?.next ?? {}
101
+ for (let queries = 0; queries < MERGED_QUERIES; queries++) {
102
+ const page = (await githubGraphql(MERGED_QUERY, { owner, name, after }, token, fetchImpl) as MergedPage | null)?.repository?.pullRequests
103
+ let done = page?.pageInfo?.hasNextPage !== true || typeof page.pageInfo.endCursor !== 'string'
104
+ for (const node of page?.nodes ?? []) {
105
+ const updated = timeOf(node?.updatedAt)
106
+ if (updated === null) continue
107
+ if (updated < stop) { done = true; break }
108
+ from ??= updated
109
+ read++
110
+ const [merged, merge] = [timeOf(node?.mergedAt), node?.mergeCommit?.oid]
111
+ if (!node || merged === null || merged < since || typeof merge !== 'string' || !SHA.test(merge)) continue
112
+ const own = (node.commits?.nodes ?? []).map(item => item?.commit)
113
+ const merging = count(node.mergeCommit?.parents?.totalCount) > 1
114
+ const brought = [merge, ...merging ? own.map(commit => commit?.oid) : []].filter((oid): oid is string => typeof oid === 'string' && SHA.test(oid))
115
+ const copied = own.filter(commit => commit?.changedFilesIfAvailable !== 0)
116
+ // Of one of more commits than its latest read, how many more it had.
117
+ const more = Math.max(0, count(node.commits?.totalCount) - own.length)
118
+ const subjects = !merging && (copied.length > 1 || more > 0) && copied.length > 0 && copied.every(commit => typeof commit?.messageHeadline === 'string')
119
+ ? copied.map(commit => commit!.messageHeadline as string) : null
120
+ pulls.set(merge, merged)
121
+ if (subjects) pullRebases.set(merge, [merged, subjects, more])
122
+ // One an agent's no more, its label taken off (which updates it), what
123
+ // it was read to bring none of an agent's.
124
+ if (!agentPull(node)) {
125
+ for (const oid of brought.filter(sha => merges.get(sha) === merged)) merges.delete(oid)
126
+ if (rebases.get(merge)?.[0] === merged) rebases.delete(merge)
127
+ continue
128
+ }
129
+ for (const oid of brought) merges.set(oid, merged)
130
+ if (subjects) rebases.set(merge, [merged, subjects, more])
131
+ }
132
+ if (done) return result(from ?? stop, null)
133
+ after = page!.pageInfo!.endCursor as string
134
+ }
135
+ return result(kept?.through ?? null, { after: after!, from: from ?? stop, stop, read })
136
+ }
137
+
138
+ // Whether two reads of the pull requests merged (agentMerges) bring the
139
+ // same commits, the agents' and every one's (`pulls`, `pullRebases`, which
140
+ // tell those pushed directly), whatever order each read them in.
141
+ export function sameMerges(a: AgentMerges, b: AgentMerges) {
142
+ const sorted = (entries: unknown[] = []) => entries.map(entry => JSON.stringify(entry)).toSorted()
143
+ const brought = (read: AgentMerges) => JSON.stringify([read.merges, read.rebases, read.pulls, read.pullRebases].map(sorted))
144
+ return brought(a) === brought(b)
145
+ }
146
+
147
+ // A commit's subject as GitHub heads its message: whole, or, past what it
148
+ // shows, cut short before an ellipsis.
149
+ const headed = (subject: string, headline: string) => headline.endsWith('…') ? subject.startsWith(headline.slice(0, -1)) : subject === headline
150
+
151
+ // The commits of `commits` (a year's) the agents' pull requests brought
152
+ // (`read`, agentMerges): those it names, and of one rebased, its commits'
153
+ // copies, the last and those below it on their first parents, as long as
154
+ // each one's subject is that of one of its commits older than the last
155
+ // matched, as Commits tells a rebase (repository-history.ts squashedPulls),
156
+ // past those of its commits the rebase left none of (an empty one GitHub
157
+ // counted no files of), and, past them all, as many more as it had before
158
+ // its latest read; a squash merge's one commit alone, its subject the pull
159
+ // request's own.
160
+ export function agentCommits(read: AgentMerges, commits: HistoryCommit[]): Set<string> {
161
+ const shas = new Set(read.merges.map(([sha]) => sha))
162
+ const bySha = new Map(commits.map(commit => [commit.sha, commit]))
163
+ for (const [last, merged, subjects, more = 0] of read.rebases) {
164
+ let commit = bySha.get(last)
165
+ let at = subjects.length - 1
166
+ for (; commit && at >= 0; commit = bySha.get(commit.parents[0] ?? '')) {
167
+ const [copied, upTo] = [commit, at]
168
+ const found = subjects.findLastIndex((subject, index) => index <= upTo && headed(copied.subject, subject))
169
+ if (found < 0) break
170
+ shas.add(commit.sha)
171
+ at = found - 1
172
+ }
173
+ // Each of its latest commits read copied, as many as it had before them
174
+ // the commits below, on their first parents, as long as each was
175
+ // committed as it was merged, as a rebase commits its copies: not past
176
+ // its first, its empty ones, which a rebase leaves out, counted too.
177
+ const copiedAsMerged = (when: number | null) => when !== null && Math.abs(when - merged) <= REBASE_SKEW_MS
178
+ for (let rest = at < 0 ? more : 0; commit && rest > 0 && copiedAsMerged(commit.committedAt); rest--, commit = bySha.get(commit.parents[0] ?? '')) {
179
+ shas.add(commit.sha)
180
+ }
181
+ }
182
+ return shas
183
+ }
184
+
185
+ // The commits of `commits` (a year's, from the branch's `head`) pushed to
186
+ // it directly: on its first parents from the head, none a merge, none a
187
+ // pull request brought (`read.pulls`: its merge commit, a squash's one
188
+ // commit, or the copies of one rebased onto it, as agentCommits tells
189
+ // them); those a merge brought from its other parents, not.
190
+ export function directCommits(read: AgentMerges, commits: HistoryCommit[], head: string): Set<string> {
191
+ const pulled = agentCommits({ ...read, merges: read.pulls ?? [], rebases: read.pullRebases ?? [] }, commits)
192
+ const bySha = new Map(commits.map(commit => [commit.sha, commit]))
193
+ const direct = new Set<string>()
194
+ for (let commit = bySha.get(head); commit; commit = bySha.get(commit.parents[0] ?? '')) {
195
+ if (commit.parents.length <= 1 && !pulled.has(commit.sha)) direct.add(commit.sha)
196
+ }
197
+ return direct
198
+ }
@@ -0,0 +1,30 @@
1
+ // The agents the server knows by their GitHub Apps or accounts (the Agents
2
+ // tab's, server-managed/repository-agents.ts, whose marks the Commits tab
3
+ // reads on commits too, repository-history.ts).
4
+ import type { AppAgent, AppAgentMarks } from '../common/managed/agent-tasks.ts'
5
+ import { GITHUB_AGENTS } from '../common/managed/github-agents.ts'
6
+
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
+ ]
28
+ // The prefixes of the branches agents work on: Claude Code's and Codex's,
29
+ // and the app agents'.
30
+ export const AGENT_BRANCH_PREFIXES = ['claude/', 'codex/', ...APP_AGENTS.map(agent => agent.prefix)]
@@ -9,4 +9,5 @@ export interface CachedAvatar {
9
9
  export interface AvatarStore {
10
10
  put(id: string, contentType: string, bytes: Buffer): Promise<void>
11
11
  get(id: string): Promise<CachedAvatar | null>
12
+ delete(id: string): Promise<void>
12
13
  }
@@ -24,11 +24,17 @@ export type BundleCacheRecord = Pick<ManagedBundle, 'id' | 'integrity' | 'filena
24
24
  export interface BundleSummary { files: number; codeFiles: number; lines: number; commit?: string; stasisVersion?: number; versionedPackages?: number }
25
25
 
26
26
  export async function readBundleDetails(record: BundleCacheRecord, store: BundleStore) {
27
+ return (await readSizedBundleDetails(record, store))?.details ?? null
28
+ }
29
+
30
+ // As readBundleDetails, with the bytes the bundle decoded to: about what
31
+ // holding its details takes.
32
+ export async function readSizedBundleDetails(record: BundleCacheRecord, store: BundleStore) {
27
33
  const bytes = await store.get(record.id, record.kind)
28
34
  if (!bytes) return null
29
35
  const decoded = record.kind === 'stasis' || record.kind === 'sourcemap' ? await decompress(bytes, { maxOutputLength: MAX_DECODED_BYTES }) : bytes
30
36
  if (decoded.length > MAX_DECODED_BYTES) throw new Error('Decoded bundle too large')
31
- return parseBundleContents(decodeUtf8(decoded), { integrity: record.integrity, kind: record.kind, size: record.byteSize })
37
+ return { details: parseBundleContents(decodeUtf8(decoded), { integrity: record.integrity, kind: record.kind, size: record.byteSize }), decodedBytes: decoded.length }
32
38
  }
33
39
 
34
40
  export interface BundleCacheStorage {
@@ -10,13 +10,13 @@ import { loadManagedConfig } from './config.ts'
10
10
  import { LOGIN_PATH } from './github-oauth.ts'
11
11
  import { createManagedApp, logManagedStartup } from './index.ts'
12
12
 
13
- export async function init(mode: 'managed+e2e' | 'e2e+managed'): Promise<Server> {
13
+ export async function init(mode: 'managed+e2e' | 'e2e+managed', { ui = true }: { ui?: boolean } = {}): Promise<Server> {
14
14
  const config = loadManagedConfig({ combined: true })
15
15
  const e2eConfig = loadConfig()
16
16
  if (!e2eConfig.neonUrl && !config.neonUrl && config.dbPath !== ':memory:' && resolve(config.dbPath) === resolve(e2eConfig.dbPath)) {
17
17
  throw new Error('MANAGED_DB_PATH must differ from e2e DB_PATH in combined mode.')
18
18
  }
19
- const e2e = await createE2eApp(e2eConfig)
19
+ const e2e = await createE2eApp(e2eConfig, { ui })
20
20
  // Replace the assembled server's single
21
21
  // request listener; adding a second would write two responses per request.
22
22
  const handlers = e2e.httpServer.listeners('request')
@@ -25,6 +25,7 @@ export async function init(mode: 'managed+e2e' | 'e2e+managed'): Promise<Server>
25
25
  const managed = await createManagedApp(config, {
26
26
  next: e2e.handleRequest,
27
27
  isShuttingDown: e2e.isShuttingDown,
28
+ ui,
28
29
  serverInfo: {
29
30
  mode, managed: { loginPath: LOGIN_PATH, cookieName: config.sessionCookieName },
30
31
  ...(e2eConfig.deepviewScanServer ? { deepviewScanServer: e2eConfig.deepviewScanServer } : {}),
@@ -0,0 +1,83 @@
1
+ // Who made a commit beside its author, as the Commits tab shows them
2
+ // (repository-history.ts): its co-authors, as its `Co-authored-by:` trailers
3
+ // name them, and the agents its message marks.
4
+ import { agentSignals, trailerBlock } from '../common/managed/agent-tasks.ts'
5
+ import { GITHUB_AGENTS, type GithubAgentId, emailAgent, githubAgent } from '../common/managed/github-agents.ts'
6
+ import { APP_AGENTS } from './app-agents.ts'
7
+ import { type NamedAccount, commitAccount } from './github-accounts.ts'
8
+
9
+ export const MAX_COAUTHORS = 3
10
+ // The rules co-authors are read by, the agents' addresses and names among
11
+ // them: what was kept read by others (history pages, squashed pull requests)
12
+ // read again by these, once raised.
13
+ export const COAUTHORS_READ = 2
14
+ const MAX_NAME = 256
15
+ const textOf = (value: unknown, max: number) => typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : null
16
+
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 }
22
+
23
+ // `Co-authored-by: <name> <address>` trailers, GitHub matching the key
24
+ // regardless of case; Cursor's agents' links, as their work carries them;
25
+ // the app agents known by the fingerprints they leave.
26
+ const COAUTHOR_TRAILER = /^co-authored-by:[ \t]*([^<\n]*?)[ \t]*<([^<>\s]+)>[ \t]*$/gimu
27
+ const CURSOR_AGENT = /https:\/\/cursor\.com\/(?:agents\?id=|background-agent\?bcId=)bc-/u
28
+ const FINGERPRINTED = APP_AGENTS.filter(agent => agent.fingerprint)
29
+
30
+ // One named as a commit's author or co-author: by name, the address its
31
+ // commit gives (where it is read), and account.
32
+ export type Maker = { name: unknown; email?: unknown; account: NamedAccount }
33
+
34
+ // The agent one who made a commit is: by their account, else the address
35
+ // their commit names them by; else, GitHub naming no account for them, by
36
+ // their name.
37
+ const makerAgent = ({ name, email, account }: Maker): GithubAgentId | null => githubAgent(account.login, account.id) ?? emailAgent(email)
38
+ ?? (account.login ? null : githubAgent(null, null, typeof name === 'string' ? name : null))
39
+
40
+ // Who made a commit, past its author (`author`), as its message names them:
41
+ // its co-authors, those GitHub's GraphQL API lists past the author (`listed`,
42
+ // the addresses its `Co-authored-by:` trailers give, by the accounts GitHub
43
+ // knows them by), else its trailers (agent-tasks.ts trailerBlock), an account's no-reply
44
+ // address naming it;
45
+ // then the agents it marks, Claude's and Codex's as the Agents tab reads them
46
+ // (agent-tasks.ts agentSignals: their sessions' and tasks' links, Claude's
47
+ // co-author and "Generated with" lines), the app agents' by their
48
+ // fingerprints, Cursor's by its agents' links. Each the agent it is where
49
+ // known, and once, the author none of them, as many as MAX_COAUTHORS: two
50
+ // are one by the first of their agent, account, address and name both name,
51
+ // two people of one name with accounts or addresses of their own two.
52
+ export function coauthorsOf(message: unknown, author: Maker, listed: Maker[] | null = null): Coauthor[] {
53
+ const text = typeof message === 'string' ? message.replaceAll('\r\n', '\n') : ''
54
+ const named = listed ?? [...trailerBlock(text).matchAll(COAUTHOR_TRAILER)].map(([, name, email]) => ({ name, email, account: commitAccount({ email }) }))
55
+ const signals = agentSignals([text], FINGERPRINTED)
56
+ const marked = [...signals.claude || signals.sessions.length > 0 ? ['claude'] : [], ...signals.tasks.length > 0 || signals.codex ? ['codex'] : [],
57
+ ...CURSOR_AGENT.test(text) ? ['cursor'] : [], ...signals.agents]
58
+ type Identity = { agent: string | null; login: string | null; email: string | null; name: string | null }
59
+ const identity = (agent: string | null, login: string | null, name: string | null, email: unknown = null): Identity => ({ agent, login: login?.toLowerCase() ?? null,
60
+ email: typeof email === 'string' && email.trim() ? email.trim().toLowerCase() : null, name: name?.toLowerCase() ?? null })
61
+ const same = (a: Identity, b: Identity) => a.agent && b.agent ? a.agent === b.agent : a.login && b.login ? a.login === b.login
62
+ : a.email && b.email ? a.email === b.email : a.name !== null && a.name === b.name
63
+ const seen = [identity(makerAgent(author), author.account.login, textOf(author.name, MAX_NAME), author.email)]
64
+ const coauthors: Coauthor[] = []
65
+ const add = (coauthor: Coauthor, email: unknown = null) => {
66
+ const who = identity(coauthor.agent ?? null, coauthor.login, coauthor.name, email)
67
+ if (seen.some(other => same(other, who)) || coauthors.length >= MAX_COAUTHORS || (!coauthor.login && !coauthor.name && !coauthor.agent)) return
68
+ seen.push(who)
69
+ coauthors.push(coauthor)
70
+ }
71
+ for (const maker of named) {
72
+ const agent = makerAgent(maker)
73
+ // An agent known by its address where GitHub names someone else's
74
+ // account for it (Codex's), as itself, not that account.
75
+ const { login, id } = agent && maker.account.login && githubAgent(maker.account.login, maker.account.id) !== agent ? { login: null, id: null } : maker.account
76
+ add({ name: textOf(maker.name, MAX_NAME), login, id, ...agent ? { agent } : {} }, maker.email)
77
+ }
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
+ }
82
+ return coauthors
83
+ }
@@ -0,0 +1,72 @@
1
+ // The versions a repository's lockfiles of npm's ecosystem lock at a commit,
2
+ // as their review reads them (pull-dependency-reviews.ts): every lockfile
3
+ // there (findRepoLockfiles) a review holds to (`held`, lockfile-scope.ts),
4
+ // read as a pull request's are (pull-dependencies.ts readLockfile, kept in
5
+ // this instance by the commit and path), as many as MAX_LOCKFILES of those,
6
+ // each's versions (`lockfiles`), and those its reader refuses, of Bun's, or
7
+ // past MAX_LOCKFILES (`unread`), as many read at once as READ_AT_ONCE; and
8
+ // those of some of them (lockedIn), each version once by what its reviews
9
+ // are held to (lockedWith), dev only where it is wherever it is locked.
10
+ // GitHub having none of a lockfile it lists there fails the whole, as it
11
+ // would for any file.
12
+ import { createClient } from '@preventive/upstream/github.js'
13
+ import { upstreamGithub } from './github-errors.ts'
14
+ import { GithubApiError } from './github-app.ts'
15
+ import type { LockedPackage } from './locked-packages.ts'
16
+ import { type Lru, lru } from './lru.ts'
17
+ import { eachOf, lockedWith, lockfileFormat, lockfileHeld, readLockfile } from './pull-dependencies.ts'
18
+
19
+ export const MAX_LOCKFILES = 100
20
+ const READ_AT_ONCE = 4
21
+
22
+ export interface CommitLockfiles { lockfiles: { path: string; packages: LockedPackage[] }[]; unread: string[] }
23
+ // Set where GitHub was asked for what a read reads (`github`), not all of it
24
+ // held in this instance.
25
+ export interface GithubAsked { github: boolean }
26
+
27
+ // The lockfiles at commit `sha` its review reads, by their paths, each with
28
+ // its format (pull-dependencies.ts lockfileFormat), kept by the commit;
29
+ // `asked` told where GitHub was.
30
+ const listings: Lru<{ path: string; format: NonNullable<ReturnType<typeof lockfileFormat>> }[]> = lru(20_000, listed => listed.length + 1)
31
+ export async function lockfilesAt(fullName: string, token: string, sha: string, asked?: GithubAsked) {
32
+ const key = `${fullName}\0${sha}`
33
+ const known = listings.get(key)
34
+ if (known) return known
35
+ if (asked) asked.github = true
36
+ const { lockfiles } = await upstreamGithub(() => createClient({ token, userAgent: 'deepview-triage' }).findRepoLockfiles({ repo: fullName, sha }))
37
+ const listed = lockfiles.flatMap(({ path }) => { const format = lockfileFormat(path); return format ? [{ path, format }] : [] })
38
+ listings.set(key, listed)
39
+ return listed
40
+ }
41
+
42
+ export async function lockedAt(fullName: string, token: string, sha: string, held: (path: string) => boolean = () => true, asked?: GithubAsked): Promise<CommitLockfiles> {
43
+ const listed = (await lockfilesAt(fullName, token, sha, asked)).filter(({ path }) => held(path))
44
+ const unread = listed.slice(MAX_LOCKFILES).map(({ path }) => path)
45
+ const lockfiles: CommitLockfiles['lockfiles'] = []
46
+ const reading = listed.slice(0, MAX_LOCKFILES)
47
+ if (asked && reading.some(lockfile => !lockfileHeld(fullName, sha, lockfile))) asked.github = true
48
+ const reads = await eachOf(reading, READ_AT_ONCE, lockfile => readLockfile(fullName, token, sha, lockfile))
49
+ for (const [at, lockfile] of reading.entries()) {
50
+ const read = reads[at]!
51
+ if ('error' in read && read.error === 'github-not-found') throw new GithubApiError(404, 'github-not-found')
52
+ if ('error' in read) unread.push(lockfile.path)
53
+ else lockfiles.push({ path: lockfile.path, packages: read.packages })
54
+ }
55
+ return { lockfiles, unread: unread.toSorted() }
56
+ }
57
+
58
+ // The versions those of `read`'s lockfiles `held` holds to lock, each once,
59
+ // and their paths.
60
+ export function lockedIn(read: CommitLockfiles, held: (path: string) => boolean = () => true) {
61
+ const packages = new Map<string, LockedPackage>()
62
+ const paths: string[] = []
63
+ for (const lockfile of read.lockfiles.filter(({ path }) => held(path))) {
64
+ paths.push(lockfile.path)
65
+ for (const pkg of lockfile.packages) {
66
+ const kept = packages.get(lockedWith(pkg))
67
+ if (!kept) packages.set(lockedWith(pkg), { ...pkg })
68
+ else if (kept.dev && !pkg.dev) delete kept.dev
69
+ }
70
+ }
71
+ return { packages: [...packages.values()], paths }
72
+ }
@@ -42,6 +42,11 @@ export interface ManagedConfig {
42
42
  cookieSecure: boolean
43
43
  sessionCookieName: string
44
44
  sessionTtlMs: number
45
+ // How long GitHub's answer on a user's access to a repository (its
46
+ // visibility, their permission) is kept for that user and repository
47
+ // (repository-browser.ts), asked again past it; 0 asks on every request
48
+ // (MANAGED_REPOSITORY_ACCESS_CACHE_MS, five minutes by default).
49
+ repositoryAccessCacheMs: number
45
50
  // Optional installation credentials for the same GitHub App as login.
46
51
  // Repository permissions are approved when connecting repositories.
47
52
  githubAppId: string | null
@@ -140,6 +145,7 @@ export function loadManagedConfig({ combined = false } = {}): ManagedConfig {
140
145
  cookieSecure,
141
146
  sessionCookieName,
142
147
  sessionTtlMs: intEnv('SESSION_TTL_MS', 1_209_600_000, 60_000, 7_776_000_000),
148
+ repositoryAccessCacheMs: intEnv('MANAGED_REPOSITORY_ACCESS_CACHE_MS', 300_000, 0, 3_600_000),
143
149
  githubAppId: env['GITHUB_APP_ID'] ?? null,
144
150
  githubAppPrivateKey: normalizePem(env['GITHUB_APP_PRIVATE_KEY']),
145
151
  githubAppSlug: env['GITHUB_APP_SLUG'] ?? null,