@andorra-labs/code 0.1.15 → 0.1.17

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 (242) hide show
  1. package/dist/src/acp-agent.d.ts +6 -0
  2. package/dist/src/acp-agent.js +15 -4
  3. package/dist/src/agent-definitions.js +29 -6
  4. package/dist/src/agent-execution.js +15 -10
  5. package/dist/src/agent-mcp-catalog.js +1 -0
  6. package/dist/src/agent-mcp.d.ts +4 -1
  7. package/dist/src/agent-mcp.js +46 -10
  8. package/dist/src/andorra/entry.d.ts +10 -0
  9. package/dist/src/andorra/entry.js +18 -4
  10. package/dist/src/andorra/hosted.d.ts +2 -1
  11. package/dist/src/andorra/hosted.js +2 -1
  12. package/dist/src/andorra/notices.d.ts +5 -0
  13. package/dist/src/andorra/notices.js +7 -0
  14. package/dist/src/andorra/state.d.ts +3 -2
  15. package/dist/src/andorra/state.js +4 -4
  16. package/dist/src/andorra/terminal.js +7 -2
  17. package/dist/src/anthropic-credentials.js +2 -0
  18. package/dist/src/app-server/error.d.ts +5 -0
  19. package/dist/src/app-server/error.js +7 -0
  20. package/dist/src/app-server/protocol.d.ts +22 -44
  21. package/dist/src/app-server/protocol.js +5 -1
  22. package/dist/src/app-server/workspace.d.ts +89 -0
  23. package/dist/src/app-server/workspace.js +457 -11
  24. package/dist/src/app-server.d.ts +465 -32
  25. package/dist/src/app-server.js +3308 -517
  26. package/dist/src/auth/deployment.js +2 -2
  27. package/dist/src/bridge/cloud.d.ts +27 -0
  28. package/dist/src/bridge/cloud.js +187 -0
  29. package/dist/src/bridge/command.d.ts +30 -0
  30. package/dist/src/bridge/command.js +347 -0
  31. package/dist/src/bridge/control.d.ts +68 -0
  32. package/dist/src/bridge/control.js +233 -0
  33. package/dist/src/bridge/engines.d.ts +90 -0
  34. package/dist/src/bridge/engines.js +601 -0
  35. package/dist/src/bridge/host-ops.d.ts +9 -0
  36. package/dist/src/bridge/host-ops.js +129 -0
  37. package/dist/src/bridge/host.d.ts +47 -0
  38. package/dist/src/bridge/host.js +540 -0
  39. package/dist/src/bridge/link.d.ts +38 -0
  40. package/dist/src/bridge/link.js +508 -0
  41. package/dist/src/bridge/login-link.d.ts +29 -0
  42. package/dist/src/bridge/login-link.js +54 -0
  43. package/dist/src/bridge/protocol.d.ts +136 -0
  44. package/dist/src/bridge/protocol.js +11 -0
  45. package/dist/src/bridge/store.d.ts +12 -0
  46. package/dist/src/bridge/store.js +61 -0
  47. package/dist/src/bridge/wording.d.ts +6 -0
  48. package/dist/src/bridge/wording.js +10 -0
  49. package/dist/src/browser-runner.js +1 -0
  50. package/dist/src/browser-server.js +7 -1
  51. package/dist/src/browser-ui/style.css +3 -3
  52. package/dist/src/browser-ui/tokens.css +28 -17
  53. package/dist/src/change-authors.d.ts +41 -0
  54. package/dist/src/change-authors.js +146 -0
  55. package/dist/src/claude-provider.js +3 -1
  56. package/dist/src/cli.js +202 -38
  57. package/dist/src/codex-errors.js +4 -1
  58. package/dist/src/coding-tools.js +15 -15
  59. package/dist/src/command-screens.d.ts +6 -0
  60. package/dist/src/command-screens.js +19 -14
  61. package/dist/src/commands.d.ts +14 -1
  62. package/dist/src/compaction-phrases.d.ts +4 -0
  63. package/dist/src/compaction-phrases.js +20 -0
  64. package/dist/src/completion.js +82 -5
  65. package/dist/src/config.d.ts +71 -3
  66. package/dist/src/config.js +202 -77
  67. package/dist/src/context-compaction.js +2 -1
  68. package/dist/src/deadline.js +13 -1
  69. package/dist/src/decision/DecisionManager.js +3 -2
  70. package/dist/src/decision/checks.js +1 -1
  71. package/dist/src/decision/requestPhrases.d.ts +4 -0
  72. package/dist/src/decision/requestPhrases.js +22 -0
  73. package/dist/src/default-graph.js +1 -1
  74. package/dist/src/file-diff.d.ts +4 -0
  75. package/dist/src/file-diff.js +2 -1
  76. package/dist/src/github-app/agent-writes.d.ts +102 -0
  77. package/dist/src/github-app/agent-writes.js +320 -0
  78. package/dist/src/github-app/client.d.ts +349 -0
  79. package/dist/src/github-app/client.js +810 -0
  80. package/dist/src/github-app/event-source.d.ts +208 -0
  81. package/dist/src/github-app/event-source.js +684 -0
  82. package/dist/src/github-app/metrics.d.ts +32 -0
  83. package/dist/src/github-app/metrics.js +49 -0
  84. package/dist/src/github-app/review-loop.d.ts +274 -0
  85. package/dist/src/github-app/review-loop.js +1177 -0
  86. package/dist/src/github-app/review-node.d.ts +81 -0
  87. package/dist/src/github-app/review-node.js +205 -0
  88. package/dist/src/github-app/review-post.d.ts +73 -0
  89. package/dist/src/github-app/review-post.js +139 -0
  90. package/dist/src/github-app/review-text.d.ts +107 -0
  91. package/dist/src/github-app/review-text.js +1133 -0
  92. package/dist/src/github-app/review-threads.d.ts +47 -0
  93. package/dist/src/github-app/review-threads.js +107 -0
  94. package/dist/src/github-app/reviewer.d.ts +121 -0
  95. package/dist/src/github-app/reviewer.js +598 -0
  96. package/dist/src/github-app/store.d.ts +59 -0
  97. package/dist/src/github-app/store.js +148 -0
  98. package/dist/src/github-app/triggers.d.ts +141 -0
  99. package/dist/src/github-app/triggers.js +441 -0
  100. package/dist/src/github-inbox.d.ts +55 -0
  101. package/dist/src/github-inbox.js +153 -0
  102. package/dist/src/github-names.d.ts +8 -0
  103. package/dist/src/github-names.js +8 -0
  104. package/dist/src/glob-search.d.ts +61 -0
  105. package/dist/src/glob-search.js +180 -0
  106. package/dist/src/graph-health.js +13 -4
  107. package/dist/src/graph-manager-chat.js +1 -1
  108. package/dist/src/graph-preview.d.ts +46 -0
  109. package/dist/src/graph-preview.js +55 -0
  110. package/dist/src/graph-provider-portability.js +34 -11
  111. package/dist/src/graph-quota.d.ts +29 -2
  112. package/dist/src/graph-quota.js +68 -10
  113. package/dist/src/graph-runner.js +88 -10
  114. package/dist/src/graph-server.d.ts +1 -1
  115. package/dist/src/graph-server.js +11 -9
  116. package/dist/src/graph-sync.js +3 -3
  117. package/dist/src/graph-ui/app.js +201 -40
  118. package/dist/src/graph-ui/controls.css +1 -0
  119. package/dist/src/graph-ui/embed.js +2 -2
  120. package/dist/src/graph-ui/icons.js +3 -1
  121. package/dist/src/graph-ui/index.html +1 -1
  122. package/dist/src/graph-ui/manager.css +1 -1
  123. package/dist/src/graph-ui/manager.js +2 -2
  124. package/dist/src/graph-ui/sidebar.js +30 -0
  125. package/dist/src/graph-ui/studio-canvas.js +26 -13
  126. package/dist/src/graph-ui/studio.css +15 -7
  127. package/dist/src/graph-ui/studio.js +26 -5
  128. package/dist/src/graph-ui/style.css +77 -45
  129. package/dist/src/graph-ui/theme.js +3 -36
  130. package/dist/src/graph-ui/tokens.css +28 -20
  131. package/dist/src/graphs.d.ts +34 -1
  132. package/dist/src/graphs.js +162 -17
  133. package/dist/src/image-input.d.ts +16 -0
  134. package/dist/src/image-input.js +41 -0
  135. package/dist/src/membership.d.ts +30 -1
  136. package/dist/src/membership.js +48 -8
  137. package/dist/src/model-health-cache.js +1 -1
  138. package/dist/src/model-metadata.d.ts +7 -1
  139. package/dist/src/model-metadata.js +39 -17
  140. package/dist/src/model-relay/local.d.ts +116 -0
  141. package/dist/src/model-relay/local.js +468 -0
  142. package/dist/src/model-relay/remote.d.ts +129 -0
  143. package/dist/src/model-relay/remote.js +252 -0
  144. package/dist/src/model-relay/runs.d.ts +34 -0
  145. package/dist/src/model-relay/runs.js +146 -0
  146. package/dist/src/model-relay/wire.d.ts +5 -0
  147. package/dist/src/model-relay/wire.js +5 -0
  148. package/dist/src/plan-pass.d.ts +59 -0
  149. package/dist/src/plan-pass.js +165 -0
  150. package/dist/src/project-registry.d.ts +21 -0
  151. package/dist/src/project-registry.js +74 -0
  152. package/dist/src/provider-engine.js +3 -0
  153. package/dist/src/provider-import.d.ts +0 -12
  154. package/dist/src/provider-import.js +7 -195
  155. package/dist/src/providers.d.ts +40 -2
  156. package/dist/src/providers.js +93 -23
  157. package/dist/src/pull-request-checks.d.ts +26 -0
  158. package/dist/src/pull-request-checks.js +56 -0
  159. package/dist/src/pull-request-conversation.d.ts +134 -0
  160. package/dist/src/pull-request-conversation.js +221 -0
  161. package/dist/src/pull-request-create.d.ts +175 -0
  162. package/dist/src/pull-request-create.js +392 -0
  163. package/dist/src/pull-request-details.d.ts +242 -0
  164. package/dist/src/pull-request-details.js +614 -0
  165. package/dist/src/pull-request-edit.d.ts +23 -0
  166. package/dist/src/pull-request-edit.js +91 -0
  167. package/dist/src/pull-request-logs.d.ts +87 -0
  168. package/dist/src/pull-request-logs.js +183 -0
  169. package/dist/src/pull-request-merge.d.ts +112 -0
  170. package/dist/src/pull-request-merge.js +258 -0
  171. package/dist/src/pull-request-review.d.ts +137 -0
  172. package/dist/src/pull-request-review.js +401 -0
  173. package/dist/src/pull-requests.d.ts +369 -8
  174. package/dist/src/pull-requests.js +524 -55
  175. package/dist/src/react-runtime.js +38 -5
  176. package/dist/src/remote/engine-pool.d.ts +88 -4
  177. package/dist/src/remote/engine-pool.js +379 -90
  178. package/dist/src/remote/roots.d.ts +19 -0
  179. package/dist/src/remote/roots.js +45 -7
  180. package/dist/src/remote/types.d.ts +0 -44
  181. package/dist/src/run-control.d.ts +17 -0
  182. package/dist/src/run-control.js +47 -0
  183. package/dist/src/run-progress.d.ts +10 -0
  184. package/dist/src/run-progress.js +122 -0
  185. package/dist/src/run-records.d.ts +7 -2
  186. package/dist/src/run-records.js +71 -6
  187. package/dist/src/runtime.d.ts +9 -1
  188. package/dist/src/runtime.js +24 -4
  189. package/dist/src/session-changes.d.ts +35 -0
  190. package/dist/src/session-changes.js +194 -6
  191. package/dist/src/session-monitor.js +2 -1
  192. package/dist/src/session-reaper.d.ts +1 -1
  193. package/dist/src/session-reaper.js +6 -1
  194. package/dist/src/session-summary.d.ts +2 -1
  195. package/dist/src/session-summary.js +2 -1
  196. package/dist/src/sessions.d.ts +11 -1
  197. package/dist/src/sessions.js +17 -4
  198. package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
  199. package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
  200. package/dist/src/skills/bundled/provenance.json +2 -2
  201. package/dist/src/skills/runtime-skills.js +1 -1
  202. package/dist/src/subagent-run.js +1 -0
  203. package/dist/src/telemetry/capture-core.d.ts +17 -0
  204. package/dist/src/telemetry/capture-core.js +59 -1
  205. package/dist/src/telemetry/classify.d.ts +3 -1
  206. package/dist/src/telemetry/classify.js +37 -0
  207. package/dist/src/telemetry/emitter.d.ts +17 -0
  208. package/dist/src/telemetry/emitter.js +76 -5
  209. package/dist/src/telemetry/schema.d.ts +47 -2
  210. package/dist/src/telemetry/schema.js +120 -5
  211. package/dist/src/telemetry/surface.d.ts +3 -1
  212. package/dist/src/telemetry/surface.js +4 -1
  213. package/dist/src/telemetry/uploader.d.ts +6 -1
  214. package/dist/src/telemetry/uploader.js +22 -3
  215. package/dist/src/terminal-ui.d.ts +1 -0
  216. package/dist/src/terminal-ui.js +10 -3
  217. package/dist/src/test-edit-guard.d.ts +7 -0
  218. package/dist/src/test-edit-guard.js +49 -1
  219. package/dist/src/timers.d.ts +2 -0
  220. package/dist/src/tools.js +59 -9
  221. package/dist/src/transcript.js +8 -2
  222. package/dist/src/types.d.ts +7 -0
  223. package/dist/src/usage-analytics.js +18 -10
  224. package/package.json +6 -1
  225. package/dist/src/remote/cert.d.ts +0 -11
  226. package/dist/src/remote/cert.js +0 -87
  227. package/dist/src/remote/client.d.ts +0 -119
  228. package/dist/src/remote/client.js +0 -544
  229. package/dist/src/remote/command.d.ts +0 -4
  230. package/dist/src/remote/command.js +0 -194
  231. package/dist/src/remote/errors.d.ts +0 -11
  232. package/dist/src/remote/errors.js +0 -14
  233. package/dist/src/remote/network.d.ts +0 -22
  234. package/dist/src/remote/network.js +0 -102
  235. package/dist/src/remote/pairing.d.ts +0 -63
  236. package/dist/src/remote/pairing.js +0 -299
  237. package/dist/src/remote/pem.d.ts +0 -2
  238. package/dist/src/remote/pem.js +0 -7
  239. package/dist/src/remote/serve.d.ts +0 -68
  240. package/dist/src/remote/serve.js +0 -244
  241. package/dist/src/remote/server.d.ts +0 -21
  242. package/dist/src/remote/server.js +0 -406
@@ -1,4 +1,127 @@
1
+ import { type PullRequestChecksRollup } from './pull-request-checks.js';
2
+ import { botMention, noSelfMention, type FailedCheck } from './pull-request-logs.js';
1
3
  import type { WakeCarry, WakeOrigin } from './timers.js';
4
+ import type { ReviewLoopEnd } from './github-app/review-post.js';
5
+ /**
6
+ * The Andorra review loop on a task's PR (design/specs/andorra-review-loop.md, "Loop state"). It lives on the PR record and
7
+ * changes under `withPullRequest`, so it survives restarts and every engine process on the home sees one state.
8
+ */
9
+ export type ReviewLoopPhase = 'waiting' | 'reviewing' | 'posting' | 'fixing' | 'ended';
10
+ export declare const REVIEW_LOOP_ENDS: readonly ReviewLoopEnd[];
11
+ /** One P1 or P2 finding of a posted round. Its title, path and line stay on this machine, for the next round's rounds.json. */
12
+ export interface ReviewedFinding {
13
+ priority: 'P1' | 'P2';
14
+ where: 'inline' | 'summary';
15
+ threadId?: string;
16
+ title: string;
17
+ path: string;
18
+ line: number;
19
+ }
20
+ export interface ReviewedRound {
21
+ round: number;
22
+ head: string;
23
+ reviewId: string;
24
+ url: string;
25
+ findings: ReviewedFinding[];
26
+ nits: number;
27
+ reviewerRun?: string;
28
+ at: string;
29
+ }
30
+ /**
31
+ * One line of the loop's history in the task's transcript (design/specs/andorra-review-loop.md, L3): a loop switched on, a
32
+ * round posted, a loop ended. It is kept across loops, newest last, at most `REVIEW_LOG_MAX` lines. `afterTurns` is how
33
+ * many turns the task's history held then, a turn still running included, so the desktop shows the line after that turn.
34
+ */
35
+ export interface ReviewLogEntry {
36
+ at: string;
37
+ loop: string;
38
+ kind: 'started' | 'posted' | 'ended';
39
+ round: number;
40
+ rounds: number;
41
+ afterTurns?: number;
42
+ /** A posted round: the head it reviewed, the review's URL, its P1 and P2 findings, its nits and the reviewer's run. */
43
+ head?: string;
44
+ url?: string;
45
+ findings?: number;
46
+ nits?: number;
47
+ reviewerRun?: string;
48
+ /** An end: why, and the sentence that says so. */
49
+ reason?: ReviewLoopEnd;
50
+ detail?: string;
51
+ }
52
+ export declare const REVIEW_LOG_MAX = 60;
53
+ export interface ReviewLoopState {
54
+ /** False again once a loop ends. */
55
+ on: boolean;
56
+ rounds: number;
57
+ model?: {
58
+ provider: string;
59
+ model: string;
60
+ };
61
+ instruction?: string;
62
+ driver?: {
63
+ kind: 'chat';
64
+ } | {
65
+ kind: 'graph';
66
+ runId: string;
67
+ nodeId?: string;
68
+ };
69
+ /** The current loop's ULID; the service binds it to one Andorra account. */
70
+ loop?: string;
71
+ /** Reviews posted in this loop. */
72
+ round: number;
73
+ phase: ReviewLoopPhase;
74
+ startedAt?: string;
75
+ /** When the round in progress began: the marker check reads GitHub's reviews back to it. */
76
+ roundStartedAt?: string;
77
+ /** The head the round in progress reviews. */
78
+ head?: string;
79
+ /** This round's `stale_head` answers, whether its 422 was already retried, and its reviewer failures. */
80
+ staleHeads?: number;
81
+ retried422?: boolean;
82
+ reviewerFailures?: number;
83
+ /** Rounds that failed in a row (a gh read, the worktree, a marker check that threw); three end the loop `unavailable`. */
84
+ roundCrashes?: number;
85
+ /** When the PR was first seen without coverage (`pending`, `unavailable`); a round waits an hour from it. */
86
+ coverageLostAt?: string;
87
+ /** Whether the record's gh account can push to the PR's head repository, once asked (R10). */
88
+ pushable?: boolean;
89
+ /** The `review` request in flight, so an engine that stops mid-post resumes with the marker check. */
90
+ attempt?: {
91
+ requestId: string;
92
+ firstAt: string;
93
+ head: string;
94
+ };
95
+ /**
96
+ * The fixer's wake, beside Auto-fix's `pendingFix`. `runId` is the turn that took it once it was delivered; `held` says
97
+ * it went straight into a run waiting in await_review rather than starting a turn; `retried` that it was armed again
98
+ * once because the turn that took it was interrupted.
99
+ */
100
+ pendingReview?: {
101
+ wakeId: string;
102
+ round: number;
103
+ prompt: string;
104
+ runId?: string;
105
+ deliveredAt?: string;
106
+ held?: boolean;
107
+ retried?: boolean;
108
+ };
109
+ /** A run of this session waiting in await_review now: it counts as held for the round conditions. */
110
+ waiting?: {
111
+ runId: string;
112
+ since: string;
113
+ };
114
+ reviewed: ReviewedRound[];
115
+ ended?: {
116
+ reason: ReviewLoopEnd;
117
+ at: string;
118
+ detail?: string;
119
+ };
120
+ /** The transcript's lines for this PR's loops, this one and the ones before it. */
121
+ log?: ReviewLogEntry[];
122
+ }
123
+ /** The loop state with one more transcript line, the oldest dropped past `REVIEW_LOG_MAX`. */
124
+ export declare function withReviewLog(review: ReviewLoopState, entry: ReviewLogEntry): ReviewLoopState;
2
125
  export interface SessionPullRequest {
3
126
  url: string;
4
127
  owner: string;
@@ -10,15 +133,28 @@ export interface SessionPullRequest {
10
133
  mergeWhenReady: boolean;
11
134
  attachedAt: string;
12
135
  handledThrough?: string;
136
+ /**
137
+ * An Auto-fix wake on its way. `through` is the newest review comment it hands over; `head` the head
138
+ * commit whose failed checks it hands over.
139
+ */
13
140
  pendingFix?: {
14
141
  wakeId: string;
15
- through: string;
142
+ through?: string;
143
+ head?: string;
16
144
  prompt?: string;
17
145
  };
146
+ /** The head commit whose failed checks Auto-fix last handed to the agent; it is not woken for them again. */
147
+ checksHandled?: string;
148
+ /** The head commit a review wait last asked Codex to review with an "@codex review" comment; it is not asked for that head again. */
149
+ reviewBumped?: string;
18
150
  carry?: WakeCarry;
19
151
  origin?: WakeOrigin;
20
152
  ghUser?: string;
21
153
  watchError?: string;
154
+ /** The head commit's checks, rolled up, as the watcher last saw them; absent when there are none. */
155
+ checks?: PullRequestChecksRollup;
156
+ /** The Andorra review loop: its settings, and the loop in progress or how the last one ended. */
157
+ review?: ReviewLoopState;
22
158
  updatedAt: string;
23
159
  }
24
160
  export type PullRequestState = 'open' | 'draft' | 'merged' | 'closed';
@@ -37,6 +173,14 @@ export interface PullRequestRef {
37
173
  }
38
174
  export declare function parsePullRequestUrl(text: string): PullRequestRef | undefined;
39
175
  export declare const pullRequestsDirectory: (home: string) => string;
176
+ /** The loop state as this engine writes it; anything else is read as no loop. */
177
+ export declare function validReviewLoop(value: unknown): value is ReviewLoopState;
178
+ /** A loop is running: switched on, not ended, with an id. */
179
+ export declare const reviewLoopActive: (pullRequest: Pick<SessionPullRequest, "review"> | undefined) => boolean;
180
+ /** A running loop that chat drives; a graph run's loop (L4) is never started or woken by the chat controller. */
181
+ export declare const chatReviewLoopActive: (pullRequest: Pick<SessionPullRequest, "review"> | undefined) => boolean;
182
+ /** The record with the checks rollup `seen` reports, or without one when there are no checks. */
183
+ export declare function withChecks(pullRequest: SessionPullRequest, checks: PullRequestChecksRollup | undefined): SessionPullRequest;
40
184
  export declare function readPullRequest(home: string, sessionId: string): Promise<SessionPullRequest | undefined>;
41
185
  export declare function writePullRequest(home: string, sessionId: string, pullRequest: SessionPullRequest): Promise<void>;
42
186
  export declare function removePullRequest(home: string, sessionId: string): Promise<void>;
@@ -45,16 +189,37 @@ export declare function listPullRequests(home: string): Promise<{
45
189
  pullRequest: SessionPullRequest;
46
190
  }[]>;
47
191
  export declare function withPullRequest<T>(home: string, sessionId: string, work: () => Promise<T>): Promise<T>;
192
+ /**
193
+ * `maxBuffer` raises the 4 MiB cap on what one command may print, for reads such as a PR's file list.
194
+ * `input` is written to gh's standard input, for `gh api --input -` requests whose JSON body carries
195
+ * text the person wrote (a review, a reply), so it never passes through an argument.
196
+ */
48
197
  export type GhRunner = (args: readonly string[], options?: {
49
198
  user?: string;
199
+ maxBuffer?: number;
200
+ input?: string;
50
201
  }) => Promise<string>;
51
- export type GhExec = (args: readonly string[], env: NodeJS.ProcessEnv) => Promise<string>;
202
+ export type GhExec = (args: readonly string[], env: NodeJS.ProcessEnv, options?: {
203
+ maxBuffer?: number;
204
+ input?: string;
205
+ }) => Promise<string>;
206
+ /**
207
+ * Runs gh (`command`, `gh` on PATH by default) and stops it after `timeoutMs` (30 s by default). A failure carries
208
+ * gh's stdout (GitHub's answer, for a refused or partly failed call) and, when the timeout or a signal stopped it,
209
+ * `killed: true`. Exported so tests can run the real process path against a fake gh.
210
+ */
211
+ export declare function ghExec(settings?: {
212
+ command?: string;
213
+ timeoutMs?: number;
214
+ }): GhExec;
52
215
  export declare function createGhRunner(exec?: GhExec): GhRunner;
53
216
  export declare const runGh: GhRunner;
54
217
  export interface PullRequestView {
55
218
  title: string;
56
219
  state: PullRequestState;
57
220
  autoMerge: boolean;
221
+ checks?: PullRequestChecksRollup;
222
+ headSha?: string;
58
223
  }
59
224
  export declare function viewPullRequest(gh: GhRunner, url: string, user?: string): Promise<PullRequestView>;
60
225
  export declare function ghAccounts(gh: GhRunner): Promise<string[]>;
@@ -80,6 +245,24 @@ export declare function applyPullRequestSettingsAsReadableAccount(gh: GhRunner,
80
245
  export type ReviewWait = {
81
246
  kind: 'comments';
82
247
  prompt: string;
248
+ }
249
+ /** Codex signed off on the head commit: its thumbs-up on the PR, or a review of that commit with no findings. */
250
+ | {
251
+ kind: 'approved';
252
+ pullRequest: SessionPullRequest;
253
+ headSha?: string;
254
+ }
255
+ /** The Andorra review loop posted its next round: the fixer's wake text. */
256
+ | {
257
+ kind: 'review';
258
+ prompt: string;
259
+ }
260
+ /** The Andorra review loop the wait watched ended (a clean round ends it too). */
261
+ | {
262
+ kind: 'review-ended';
263
+ pullRequest: SessionPullRequest;
264
+ reason: ReviewLoopEnd;
265
+ detail?: string;
83
266
  } | {
84
267
  kind: 'finished';
85
268
  pullRequest: SessionPullRequest;
@@ -97,12 +280,48 @@ export type ReviewWait = {
97
280
  };
98
281
  export interface PullRequestControl {
99
282
  status(): Promise<SessionPullRequest | undefined>;
100
- attach(url: string, settings: PullRequestSettings, origin?: WakeOrigin): Promise<SessionPullRequest>;
101
- update(settings: PullRequestSettings, origin?: WakeOrigin): Promise<SessionPullRequest>;
102
- awaitReview?(signal: AbortSignal, timeoutMs: number, origin?: WakeOrigin): Promise<ReviewWait>;
283
+ attach(url: string, settings: PullRequestSettings & ReviewLoopSettings, origin?: WakeOrigin): Promise<SessionPullRequest>;
284
+ update(settings: PullRequestSettings & ReviewLoopSettings, origin?: WakeOrigin): Promise<SessionPullRequest>;
285
+ /**
286
+ * `approveBump` is asked before the wait posts "@codex review" for a head Codex has not picked up; without it,
287
+ * or when it rejects, the wait posts nothing.
288
+ */
289
+ awaitReview?(signal: AbortSignal, timeoutMs: number, origin?: WakeOrigin, options?: {
290
+ approveBump?(detail: string): Promise<void>;
291
+ }): Promise<ReviewWait>;
103
292
  dismiss(): Promise<void>;
293
+ /**
294
+ * A reply, resolve or PR comment on the tracked PR: as the GitHub App's bot where the PR is covered and agent
295
+ * writes are `bot`, otherwise through gh as the record's account. `approve` is asked once the route is
296
+ * known and the write passes that route's checks, before anything is sent. Answers the tool result, which
297
+ * says who posted and why.
298
+ */
299
+ write?(write: import('./github-app/agent-writes.js').AgentPullRequestWrite, options: {
300
+ approve(detail: string): Promise<void>;
301
+ signal?: AbortSignal;
302
+ }): Promise<string>;
104
303
  }
105
304
  export declare function pullRequestSettings(source: Record<string, unknown>): PullRequestSettings;
305
+ /**
306
+ * The Andorra review loop's settings, kept apart from the gh-backed ones above: nothing here changes the PR on GitHub.
307
+ * `reviewInstruction` and `reviewModel` take an empty string to clear them.
308
+ */
309
+ export interface ReviewLoopSettings {
310
+ review?: boolean;
311
+ reviewRounds?: number;
312
+ reviewInstruction?: string;
313
+ reviewModel?: string;
314
+ }
315
+ export declare const REVIEW_ROUNDS_DEFAULT = 3;
316
+ export declare const REVIEW_ROUNDS_MAX = 10;
317
+ export declare const REVIEW_INSTRUCTION_BYTES = 2048;
318
+ export declare const REVIEW_SETTING_KEYS: readonly ["review", "reviewRounds", "reviewInstruction", "reviewModel"];
319
+ /** `provider/model`, split at the first slash (a model id may hold slashes of its own). */
320
+ export declare function parseReviewModel(value: string): {
321
+ provider: string;
322
+ model: string;
323
+ } | undefined;
324
+ export declare function reviewLoopSettings(source: Record<string, unknown>): ReviewLoopSettings;
106
325
  export declare class PullRequestCreateDetector {
107
326
  private readonly pending;
108
327
  observe(event: {
@@ -111,19 +330,88 @@ export declare class PullRequestCreateDetector {
111
330
  }): PullRequestRef | undefined;
112
331
  }
113
332
  export declare const CODE_REVIEWER_LOGINS: readonly string[];
114
- export declare function isCodeReviewer(login: string | undefined): boolean;
333
+ /**
334
+ * One more reviewer login for the GitHub App's real run, read only in test mode (`ANDORRA_TEST_MODE=1`), so
335
+ * review comments posted by a person's own account can stand in for a review bot's. Never read otherwise.
336
+ */
337
+ export declare function testCodeReviewer(env?: NodeJS.ProcessEnv): string | undefined;
338
+ /**
339
+ * The Andorra Code GitHub App's own bots (production and the staging dev App), as REST and webhooks name them
340
+ * without `[bot]` and as GraphQL names them. What the agent posts as the bot is never a review to wake Auto-fix
341
+ * for, not even when the test-mode reviewer names one of them.
342
+ */
343
+ export declare const ANDORRA_BOT_LOGINS: readonly string[];
344
+ export declare function isCodeReviewer(login: string | undefined, env?: NodeJS.ProcessEnv): boolean;
115
345
  export declare function newReviewComments(gh: GhRunner, pullRequest: SessionPullRequest): Promise<{
116
346
  threads: number;
117
347
  comments: number;
118
348
  newest?: string;
119
349
  }>;
350
+ /** Codex's login, as GraphQL names it on comments and reviews; on a reaction it carries `[bot]`. */
351
+ export declare const CODEX_REVIEWER_LOGIN = "chatgpt-codex-connector";
352
+ /** The PR comment that asks Codex for a review of the current head. */
353
+ export declare const REVIEW_BUMP_COMMENT = "@codex review";
354
+ /** How long a review wait sees no sign of Codex on a head before it asks for a review. */
355
+ export declare const REVIEW_BUMP_DELAY_MS = 30000;
356
+ /** How often a review wait reads Codex's reactions: GitHub sends no notice for a reaction. */
357
+ export declare const REVIEW_SIGNAL_INTERVAL_MS = 60000;
358
+ /** What Codex shows on a PR's head commit, as a review wait reads it. */
359
+ export interface ReviewSignals {
360
+ headSha?: string;
361
+ /** Open and not a draft: Codex reviews nothing else. */
362
+ open: boolean;
363
+ /** Codex signed off on this head: a thumbs-up on the PR newer than the head commit, or a review of it with no findings. */
364
+ approved: boolean;
365
+ /** Codex's eyes are on the PR, or its summary says it is reviewing this head. */
366
+ reviewing: boolean;
367
+ /** Codex posted a review for this head: a review of that commit, a review comment newer than it, or a verdict. Its other comments (a setup notice, an answer to a mention) are not one. */
368
+ reviewed: boolean;
369
+ /** Someone already asked with an "@codex review" comment since the head commit. */
370
+ asked: boolean;
371
+ /** Codex has reacted, reviewed or commented on this PR at some point. */
372
+ codexSeen: boolean;
373
+ }
374
+ /**
375
+ * Reads Codex's reactions on the PR's main post, its reviews and its comments, and says what they mean for the
376
+ * head commit. A reaction names no commit, so a thumbs-up counts only when it is newer than the head commit
377
+ * and Codex's summary, where there is one, names that commit too: the thumbs-up of an earlier head stays on
378
+ * the PR until Codex picks the new head up.
379
+ */
380
+ export declare function readReviewSignals(gh: GhRunner, pullRequest: SessionPullRequest, env?: NodeJS.ProcessEnv): Promise<ReviewSignals>;
381
+ /** Whether Codex has shown up on any of the repository's 20 newest pull requests: where it never has, nobody asks it for a review. */
382
+ export declare function codexReviewsRepository(gh: GhRunner, pullRequest: SessionPullRequest, env?: NodeJS.ProcessEnv): Promise<boolean>;
383
+ /**
384
+ * Who the agent's replies and resolves post as, for the Auto-fix prompt: `botWrites` when the PR is covered by
385
+ * the GitHub App and agent writes are set to the bot; `bot` is the bot's login from `GET /v1/github`.
386
+ */
387
+ export interface AutoFixWrites {
388
+ botWrites: boolean;
389
+ bot?: string;
390
+ }
391
+ export { botMention, noSelfMention };
120
392
  export declare function autoFixPrompt(pullRequest: SessionPullRequest, found: {
121
393
  threads: number;
122
394
  comments: number;
123
- }): string;
395
+ }, checks?: {
396
+ checks: readonly FailedCheck[];
397
+ headSha: string;
398
+ branch?: string;
399
+ }, writes?: AutoFixWrites): string;
400
+ /**
401
+ * The head commit's failed checks that Auto-fix hands to the agent: the failed **required** checks, or,
402
+ * where the base branch requires none, every failed check (otherwise Auto-fix would never act on a
403
+ * repository without branch protection). None while the head is one Auto-fix already handed over.
404
+ */
405
+ export declare function failedChecksToFix(gh: GhRunner, pullRequest: SessionPullRequest): Promise<{
406
+ headSha: string;
407
+ branch?: string;
408
+ checks: FailedCheck[];
409
+ } | undefined>;
124
410
  export declare class WatcherLease {
125
411
  private readonly home;
126
412
  private release?;
413
+ /** The acquisition in flight: concurrent claims in one process share it instead of racing their own lock. */
414
+ private claiming?;
127
415
  constructor(home: string);
128
416
  claim(): Promise<boolean>;
129
417
  drop(): Promise<void>;
@@ -137,19 +425,90 @@ export interface PullRequestWatcherOptions {
137
425
  wakePending: (id: string) => boolean;
138
426
  log?: (level: 'info' | 'warn', detail: string) => void;
139
427
  claim?: () => Promise<boolean>;
428
+ /**
429
+ * Whether GitHub App notices reach this session's PR. A covered PR is read when a notice asks
430
+ * (`checkNow`) and, as a safety net, once every 10 minutes; every other PR on every pass, as before.
431
+ */
432
+ covered?: (sessionId: string) => boolean;
433
+ /** Each gh call a check makes for a session, for the GitHub App's measures. */
434
+ onGhCall?: (sessionId: string) => void;
435
+ now?: () => number;
436
+ /** How long `checkNow` waits, so a burst of notices for one PR costs one read. */
437
+ checkNowDelayMs?: number;
438
+ /** Who the agent's replies post as on this session's PR, for the Auto-fix prompt; without it, the gh form. */
439
+ agentWrites?: (sessionId: string) => Promise<AutoFixWrites>;
440
+ /** Each read that refreshed a session's record, for the Andorra review loop's round conditions. Must not throw. */
441
+ onRead?: (sessionId: string, pullRequest: SessionPullRequest) => void;
140
442
  }
443
+ /** How often a PR that GitHub App notices reach is still read: the safety net. */
444
+ export declare const COVERED_CHECK_MS: number;
445
+ export declare const CHECK_NOW_DELAY_MS = 2000;
141
446
  export declare function pullRequestNeedsWatch(pullRequest: SessionPullRequest): boolean;
142
447
  export declare class PullRequestWatcher {
143
448
  private readonly options;
144
449
  private timer?;
145
450
  private running?;
451
+ private forceAfter;
452
+ private runningGated;
146
453
  private stopped;
454
+ private leaseHeld;
147
455
  private readonly lease;
456
+ private readonly now;
457
+ /** When each session's PR was last read, for the covered PRs' 10-minute gate. */
458
+ private readonly lastChecked;
459
+ /** The head commit each session's PR had when it was last read, sent with the GitHub App subscriptions. */
460
+ private readonly heads;
461
+ private readonly soon;
462
+ private readonly inFlight;
463
+ /** `readNow` reads still claiming the lease, before their read is in `inFlight`. */
464
+ private readonly reading;
148
465
  constructor(options: PullRequestWatcherOptions);
149
466
  start(): void;
150
467
  stop(): Promise<void>;
151
- poll(): Promise<void>;
468
+ /** Claims the `.watcher` lease: only the process that holds it reads PRs, wakes Auto-fix and pulls GitHub App notices. */
469
+ claim(): Promise<boolean>;
470
+ holdsLease(): boolean;
471
+ headSha(sessionId: string): string | undefined;
472
+ /**
473
+ * Reads every watched PR now, covered or not: the full pass after a notice gap or a breaker's recovery.
474
+ * A caller that wants one PR read (an attach, a settings change, a review wait) uses `readNow`.
475
+ * With `force`, a pass already running is followed by one more, since it may have started before the gap.
476
+ */
477
+ poll(options?: {
478
+ force?: boolean;
479
+ }): Promise<void>;
480
+ /**
481
+ * The interval timer's pass: a covered PR read within the last 10 minutes is skipped, because GitHub App
482
+ * notices read it when it changes. Every other PR is read, as before the App.
483
+ */
484
+ scheduledPass(): Promise<void>;
485
+ /**
486
+ * Reads one session's PR now, without `checkNow`'s debounce and whether or not it is covered: for a caller
487
+ * that changed or attached that PR, or waits on it. The other watched PRs are left to their own schedule.
488
+ */
489
+ readNow(sessionId: string): Promise<void>;
490
+ private run;
491
+ /**
492
+ * Reads one session's PR soon: after `checkNowDelayMs` (2 s), so a burst of notices for one PR costs one
493
+ * read. It reads whether or not the PR is covered: the 10-minute gate holds only for the interval's passes.
494
+ * `force` is accepted for the same read. Only the lease holder reads. The timer does not keep the process
495
+ * alive.
496
+ */
497
+ checkNow(sessionId: string, _options?: {
498
+ force?: boolean;
499
+ }): Promise<void>;
500
+ /** Whether a read `checkNow` scheduled for a session keeps the process alive (it should not). */
501
+ checkNowKeepsAlive(sessionId: string): boolean | undefined;
502
+ /** Every pass and every read `checkNow` or `readNow` started, finished (for tests). */
503
+ settled(): Promise<void>;
504
+ private checkSoon;
505
+ /** A covered PR read within the last 10 minutes is left to its notices; every other PR is read on every pass. */
506
+ private due;
507
+ /** One read of a session's PR at a time: a notice's read waits for a pass's read of the same PR. */
508
+ private checkOnce;
152
509
  private pass;
510
+ /** The gh one session's check runs: counted for that session when the GitHub App's measures are on. */
511
+ private countedGh;
153
512
  private read;
154
513
  private check;
155
514
  }
@@ -157,5 +516,7 @@ export declare function confirmAutoFixWake(home: string, gh: GhRunner, sessionId
157
516
  deliver: boolean;
158
517
  pullRequest?: SessionPullRequest;
159
518
  }>;
519
+ /** The record once a pending Auto-fix wake reached the agent: what it handed over counts as handled. */
520
+ export declare function handedOver(pullRequest: SessionPullRequest, pending: NonNullable<SessionPullRequest['pendingFix']>): SessionPullRequest;
160
521
  export declare function withoutPendingFix(pullRequest: SessionPullRequest): SessionPullRequest;
161
522
  export declare function markAutoFixDelivered(home: string, sessionId: string, wakeId: string): Promise<SessionPullRequest | undefined>;