@andorra-labs/code 0.1.16 → 0.1.18

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