@tirso0882/factory 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.mts ADDED
@@ -0,0 +1,375 @@
1
+ // The factory: plan → implement → review → pull request → CI, in waves.
2
+ //
3
+ // Update Each wave starts by merging origin/main into every open factory
4
+ // pull request that conflicts with it. The host merges, and an
5
+ // agent resolves the conflicts if there are any. A pull request
6
+ // that is only behind merges cleanly and is left alone.
7
+ // Address Each factory pull request you labelled `ready-for-agent` goes
8
+ // back to an agent with your unresolved review comments. It fixes
9
+ // or answers them in the pull request's sandbox; the host pushes,
10
+ // posts its replies, removes the label and waits for CI.
11
+ // Plan The host lists the open `ready-for-agent` issues you wrote and
12
+ // drops any with an open blocker or an open factory pull request.
13
+ // A planner picks the ones that can be built side by side.
14
+ // Implement Each issue gets a bwrap sandbox on `factory/issue-<n>`,
15
+ // branched from origin/main. The implementer builds it and the
16
+ // reviewer checks it against the coding standards and the issue.
17
+ // Publish A writer drafts the pull request body, with the `pr` skill if
18
+ // the config lists it, and the host pushes the branch and opens
19
+ // the pull request.
20
+ // CI The host waits for the checks on the pushed commit. On a failure
21
+ // the implementer gets the failing log, up to `limits.maxCiFixes`
22
+ // times.
23
+ //
24
+ // Nothing merges by itself: you merge the pull requests, and a later run picks
25
+ // up what they unblock. A ticket the factory can't finish is relabelled
26
+ // `ready-for-human` with a comment, so no run retries it.
27
+ //
28
+ // Worktrees branch from origin/main and the host pushes from refs, so the
29
+ // checkout you start it from can be on any branch, with uncommitted work.
30
+ //
31
+ // Where things are:
32
+ // .factory/factory.config.mts the project's settings: limits, labels,
33
+ // models, toolchains, services, its sandbox's variables
34
+ // cli.mts the `factory` command, which loads them
35
+ // shared/factory.mts the settings' defaults, resolved for a run
36
+ // shared/ host commands, tickets, CI, retries
37
+ // workflows/<name>/ one agent each, its code next to its prompt
38
+ // ticket.mts one ticket from sandbox to CI result
39
+ // environment.mts the sandbox built from the config's declarations
40
+ // **/*.test.mts `npm test`; `npm run typecheck` covers it all too
41
+ //
42
+ // Usage, in the project's repo:
43
+ // factory check --quick # first
44
+ // factory # the backlog
45
+ // factory --issue 160 --parallel 1
46
+ // factory --update-pr 187 # only merge main into it
47
+ // factory --address-pr 187 # only address your review of it
48
+
49
+ import { parseArgs } from "node:util"
50
+ import { startServices, stopServices } from "./environment.mts"
51
+ import { type ResolvedFactory, capParallel } from "./shared/factory.mts"
52
+ import {
53
+ conflictingPullRequests,
54
+ loadTickets,
55
+ openFactoryPullRequests,
56
+ } from "./shared/github.mts"
57
+ import { git } from "./shared/host.mts"
58
+ import type { FactoryPullRequest } from "./shared/pull-requests.mts"
59
+ import { type Outcome, runTicket } from "./ticket.mts"
60
+ import {
61
+ type AddressOutcome,
62
+ addressPullRequest,
63
+ } from "./workflows/address-review/address-review.mts"
64
+ import { plan } from "./workflows/plan/plan.mts"
65
+ import { preflight } from "./workflows/preflight/preflight.mts"
66
+ import {
67
+ type UpdateOutcome,
68
+ updatePullRequest,
69
+ } from "./workflows/update-branch/update-branch.mts"
70
+
71
+ /** A run of the factory on the project `factory` describes. `args` are the
72
+ * command line's options: `--issue`, `--parallel`, `--update-pr` and
73
+ * `--address-pr`. */
74
+ export const runFactory = async (
75
+ factory: ResolvedFactory,
76
+ args: readonly string[]
77
+ ) => {
78
+ const { names, limits } = factory
79
+ const { baseBranch, baseRef, readyLabel, humanLabel } = names
80
+
81
+ // -------------------------------------------------------------------------
82
+ // Command line
83
+ // -------------------------------------------------------------------------
84
+
85
+ const { values: cli } = parseArgs({
86
+ args: [...args],
87
+ options: {
88
+ issue: { type: "string", multiple: true },
89
+ parallel: { type: "string" },
90
+ "update-pr": { type: "string" },
91
+ "address-pr": { type: "string" },
92
+ },
93
+ })
94
+
95
+ const onlyIssues = new Set((cli.issue ?? []).map(Number))
96
+ // `limits.parallel` is already capped at the project's `maxSlots`.
97
+ const asked = Number(cli.parallel ?? limits.parallel)
98
+ if (cli.parallel !== undefined && (!Number.isInteger(asked) || asked < 1)) {
99
+ throw new Error(
100
+ `--parallel takes a positive whole number, got ${cli.parallel}.`
101
+ )
102
+ }
103
+ const parallel = capParallel(factory, asked)
104
+ if (parallel < asked) {
105
+ console.warn(
106
+ `--parallel ${asked} is more than the project's maxSlots: running ${parallel} at once.`
107
+ )
108
+ }
109
+ if ([...onlyIssues].some((n) => !Number.isInteger(n) || n < 1)) {
110
+ throw new Error(`--issue takes issue numbers, got ${cli.issue?.join(", ")}.`)
111
+ }
112
+
113
+ const pullRequestOption = (name: "update-pr" | "address-pr") => {
114
+ const value = cli[name]
115
+ if (value === undefined) return undefined
116
+ const number = Number(value)
117
+ if (!Number.isInteger(number) || number < 1) {
118
+ throw new Error(`--${name} takes a pull request number, got ${value}.`)
119
+ }
120
+ return number
121
+ }
122
+
123
+ const onlyUpdate = pullRequestOption("update-pr")
124
+ const onlyAddress = pullRequestOption("address-pr")
125
+ if (onlyUpdate !== undefined && onlyAddress !== undefined) {
126
+ throw new Error("--update-pr and --address-pr run on their own: pick one.")
127
+ }
128
+ if (
129
+ (onlyUpdate !== undefined || onlyAddress !== undefined) &&
130
+ onlyIssues.size > 0
131
+ ) {
132
+ throw new Error(
133
+ "--update-pr and --address-pr run on their own: drop --issue."
134
+ )
135
+ }
136
+
137
+ // -------------------------------------------------------------------------
138
+ // Stopping and the concurrency cap
139
+ // -------------------------------------------------------------------------
140
+
141
+ // Ctrl-C stops the agents in flight and still tears everything down. A second
142
+ // Ctrl-C exits at once.
143
+ const stop = new AbortController()
144
+ process.on("SIGINT", () => {
145
+ if (stop.signal.aborted) process.exit(130)
146
+ console.warn(
147
+ "\nStopping: killing the agents in flight. Ctrl-C again to quit."
148
+ )
149
+ stop.abort(new Error("Stopped by Ctrl-C."))
150
+ })
151
+
152
+ // At most `size` tasks run at once, and each holds a numbered slot, 1 to
153
+ // `size`, while it runs. The project's `env(slot)` keeps parallel sandboxes
154
+ // apart, such as one Redis database each (.factory/factory.config.mts).
155
+ const createSlotPool = (size: number) => {
156
+ const free = Array.from({ length: size }, (_, i) => i + 1)
157
+ const waiting: ((slot: number) => void)[] = []
158
+ const acquire = () =>
159
+ free.length > 0
160
+ ? Promise.resolve(free.shift()!)
161
+ : new Promise<number>((resolve) => waiting.push(resolve))
162
+ const release = (slot: number) => {
163
+ const next = waiting.shift()
164
+ if (next) next(slot)
165
+ else free.push(slot)
166
+ }
167
+ return async <T,>(task: (slot: number) => Promise<T>) => {
168
+ const slot = await acquire()
169
+ try {
170
+ return await task(slot)
171
+ } finally {
172
+ release(slot)
173
+ }
174
+ }
175
+ }
176
+
177
+ // -------------------------------------------------------------------------
178
+ // Main loop
179
+ // -------------------------------------------------------------------------
180
+
181
+ const withSlot = createSlotPool(parallel)
182
+ const done = new Set<number>()
183
+ const outcomes = new Map<number, Outcome>()
184
+ const updates = new Map<number, UpdateOutcome>()
185
+ const reviewOutcomes = new Map<number, AddressOutcome>()
186
+
187
+ const updatePullRequests = (pullRequests: readonly FactoryPullRequest[]) =>
188
+ Promise.all(
189
+ pullRequests.map((pr) =>
190
+ withSlot(async (slot) => {
191
+ console.log(
192
+ ` PR #${pr.number}: merging ${baseRef} into ${pr.headRefName}`
193
+ )
194
+ updates.set(
195
+ pr.number,
196
+ stop.signal.aborted
197
+ ? { status: "interrupted", reason: "The run stopped first." }
198
+ : await updatePullRequest(factory, pr, slot, stop)
199
+ )
200
+ })
201
+ )
202
+ )
203
+
204
+ const addressPullRequests = (pullRequests: readonly FactoryPullRequest[]) =>
205
+ Promise.all(
206
+ pullRequests.map((pr) =>
207
+ withSlot(async (slot) => {
208
+ console.log(` PR #${pr.number}: addressing your review`)
209
+ reviewOutcomes.set(
210
+ pr.number,
211
+ stop.signal.aborted
212
+ ? { status: "interrupted", reason: "The run stopped first." }
213
+ : await addressPullRequest(factory, pr, slot, stop)
214
+ )
215
+ })
216
+ )
217
+ )
218
+
219
+ // One pull request you named, whatever GitHub says of it or its labels.
220
+ const onePullRequest = (number: number) => {
221
+ git("fetch", "--quiet", "origin", baseBranch)
222
+ const pr = openFactoryPullRequests(names).find((p) => p.number === number)
223
+ if (pr === undefined) {
224
+ console.warn(`PR #${number} isn't an open factory pull request.`)
225
+ }
226
+ return pr
227
+ }
228
+
229
+ await preflight(factory, stop.signal)
230
+
231
+ const runWaves = async () => {
232
+ for (let wave = 1; wave <= limits.maxWaves && !stop.signal.aborted; wave++) {
233
+ console.log(`\n=== Wave ${wave}/${limits.maxWaves} ===\n`)
234
+ git("fetch", "--quiet", "origin", baseBranch)
235
+
236
+ // A pull request this run couldn't update waits for the next run: it
237
+ // has its comment, or the failure is in this log.
238
+ const conflicting = (
239
+ await conflictingPullRequests(factory, stop.signal)
240
+ ).filter(
241
+ (pr) => (updates.get(pr.number)?.status ?? "updated") === "updated"
242
+ )
243
+ if (conflicting.length > 0) {
244
+ console.log(
245
+ `${conflicting.length} pull request(s) conflict with ${baseBranch}:`
246
+ )
247
+ await updatePullRequests(conflicting)
248
+ }
249
+ if (stop.signal.aborted) break
250
+
251
+ // A pull request is addressed once a run, and not while it conflicts.
252
+ const sentBack = openFactoryPullRequests(names, readyLabel).filter(
253
+ (pr) =>
254
+ !reviewOutcomes.has(pr.number) &&
255
+ (updates.get(pr.number)?.status ?? "updated") === "updated"
256
+ )
257
+ if (sentBack.length > 0) {
258
+ console.log(`${sentBack.length} pull request(s) sent back for review:`)
259
+ await addressPullRequests(sentBack)
260
+ }
261
+ if (stop.signal.aborted) break
262
+
263
+ const candidates = loadTickets(names, done, onlyIssues)
264
+ if (candidates.length === 0) {
265
+ console.log("No open, unblocked tickets. Exiting.")
266
+ break
267
+ }
268
+
269
+ // One ticket, or tickets you named, need no planner.
270
+ const tickets =
271
+ candidates.length <= 1 || onlyIssues.size > 0
272
+ ? candidates
273
+ : await plan(factory, candidates, stop.signal)
274
+ if (tickets.length === 0) {
275
+ console.log("The planner chose no tickets. Exiting.")
276
+ break
277
+ }
278
+ console.log(`${tickets.length} ticket(s), at most ${parallel} at once:`)
279
+ for (const t of tickets)
280
+ console.log(` #${t.number}: ${t.title} → ${t.branch}`)
281
+
282
+ await Promise.all(
283
+ tickets.map((ticket) =>
284
+ withSlot(async (slot) => {
285
+ done.add(ticket.number)
286
+ outcomes.set(
287
+ ticket.number,
288
+ stop.signal.aborted
289
+ ? { status: "interrupted", reason: "The run stopped first." }
290
+ : await runTicket(factory, ticket, slot, stop)
291
+ )
292
+ })
293
+ )
294
+ )
295
+
296
+ // Tickets you named run once.
297
+ if (onlyIssues.size > 0) break
298
+ }
299
+ }
300
+
301
+ const runOne = async () => {
302
+ if (onlyUpdate !== undefined) {
303
+ const pr = onePullRequest(onlyUpdate)
304
+ if (pr) await updatePullRequests([pr])
305
+ } else if (onlyAddress !== undefined) {
306
+ const pr = onePullRequest(onlyAddress)
307
+ if (pr) await addressPullRequests([pr])
308
+ } else {
309
+ await runWaves()
310
+ }
311
+ }
312
+
313
+ startServices(factory)
314
+ try {
315
+ await runOne()
316
+ } finally {
317
+ stopServices(factory)
318
+ }
319
+
320
+ console.log("\n=== Summary ===\n")
321
+ for (const [number, update] of updates) {
322
+ switch (update.status) {
323
+ case "updated":
324
+ console.log(` ↻ PR #${number}: ${baseBranch} merged in, ${update.merge}`)
325
+ break
326
+ case "failed":
327
+ console.log(` ✗ PR #${number}: not updated, commented: ${update.reason}`)
328
+ break
329
+ case "interrupted":
330
+ console.log(` … PR #${number}: not updated: ${update.reason}`)
331
+ break
332
+ }
333
+ }
334
+ for (const [number, address] of reviewOutcomes) {
335
+ switch (address.status) {
336
+ case "addressed":
337
+ console.log(
338
+ ` ✎ PR #${number}: review addressed: ${address.commits} commit(s), ${address.replies} reply(ies), ${address.comments} comment(s)`
339
+ )
340
+ break
341
+ case "nothing to do":
342
+ console.log(` ✎ PR #${number}: nothing actionable, commented`)
343
+ break
344
+ case "failed":
345
+ console.log(
346
+ ` ✗ PR #${number}: review not addressed, commented: ${address.reason}`
347
+ )
348
+ break
349
+ case "interrupted":
350
+ console.log(
351
+ ` … PR #${number}: interrupted, still ${readyLabel}: ${address.reason}`
352
+ )
353
+ break
354
+ }
355
+ }
356
+ for (const [number, outcome] of outcomes) {
357
+ switch (outcome.status) {
358
+ case "ready":
359
+ console.log(
360
+ ` ✓ #${number}: CI passes, ready for review: ${outcome.pullRequest}`
361
+ )
362
+ break
363
+ case "handed-off":
364
+ console.log(` → #${number}: relabelled ${humanLabel}: ${outcome.reason}`)
365
+ break
366
+ case "interrupted":
367
+ console.log(
368
+ ` … #${number}: interrupted, still ${readyLabel}: ${outcome.reason}`
369
+ )
370
+ break
371
+ }
372
+ }
373
+ if (outcomes.size === 0 && updates.size === 0 && reviewOutcomes.size === 0)
374
+ console.log(" Nothing ran.")
375
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@tirso0882/factory",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "The agent factory: builds ready-for-agent issues into pull requests.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Tirso0882/factory.git"
9
+ },
10
+ "bin": {
11
+ "factory": "bin/factory.mjs"
12
+ },
13
+ "exports": {
14
+ ".": "./index.mts"
15
+ },
16
+ "files": [
17
+ "bin/",
18
+ "*.mts",
19
+ "shared/",
20
+ "workflows/",
21
+ "!**/*.test.mts",
22
+ "!shared/fake-host.mts"
23
+ ],
24
+ "engines": {
25
+ "node": ">=24"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "typecheck": "tsc",
32
+ "test": "node --test 'shared/**/*.test.mts' 'workflows/**/*.test.mts' 'bin/**/*.test.mts'",
33
+ "lint": "eslint ."
34
+ },
35
+ "dependencies": {
36
+ "@ai-hero/sandcastle": "^0.14.0",
37
+ "semver": "^7.8.6",
38
+ "tsx": "^4.23.15",
39
+ "zod": "4.6.7"
40
+ },
41
+ "devDependencies": {
42
+ "@eslint/js": "^10.0.1",
43
+ "@standard-schema/spec": "^1.1.0",
44
+ "@types/node": "^24.0.0",
45
+ "@types/semver": "^7.8.0",
46
+ "eslint": "^10.15.0",
47
+ "globals": "^17.14.0",
48
+ "typescript": "^5.9.3",
49
+ "typescript-eslint": "^8.74.0"
50
+ }
51
+ }
@@ -0,0 +1,10 @@
1
+ // The agent for each role, from the resolved settings.
2
+
3
+ import * as sandcastle from "@ai-hero/sandcastle"
4
+ import type { ResolvedFactory, Role } from "./factory.mts"
5
+
6
+ /** The agent that plays `role`, with the model and effort the settings give it. */
7
+ export const agentFor = (factory: ResolvedFactory, role: Role) => {
8
+ const { model, effort } = factory.models[role]
9
+ return sandcastle.claudeCode(model, { effort })
10
+ }
@@ -0,0 +1,163 @@
1
+ // What each agent answers the host, as structured output (see
2
+ // `run-with-extraction.mts`), and what the host makes of it.
3
+
4
+ import * as sandcastle from "@ai-hero/sandcastle"
5
+ import { z } from "zod"
6
+
7
+ const MAX_REASON_CHARS = 1500
8
+
9
+ /**
10
+ * Whether the implementer or the branch updater finished, or stopped. The
11
+ * reason is posted publicly, so it's cut to a comment's length.
12
+ */
13
+ export const DONE_OR_BLOCKED = sandcastle.Output.object({
14
+ tag: "answer",
15
+ schema: z.discriminatedUnion("status", [
16
+ z.object({ status: z.literal("done") }),
17
+ z.object({
18
+ status: z.literal("blocked"),
19
+ reason: z
20
+ .string()
21
+ .trim()
22
+ .min(1)
23
+ .transform((reason) => reason.slice(0, MAX_REASON_CHARS)),
24
+ }),
25
+ ]),
26
+ })
27
+
28
+ export const DONE_OR_BLOCKED_PROMPT = `Answer the host with JSON in an <answer> tag, and nothing else.
29
+
30
+ If you built everything the task asks and committed it:
31
+
32
+ <answer>{"status": "done"}</answer>
33
+
34
+ If you stopped as BLOCKED says, with your one-paragraph explanation for the maintainer:
35
+
36
+ <answer>{"status": "blocked", "reason": "The issue asks for X, but ADR 0010 says Y."}</answer>`
37
+
38
+ const reviewReport = z.object({
39
+ criteria: z.array(
40
+ z.object({
41
+ criterion: z.string().min(1),
42
+ status: z.enum(["met", "not-verifiable", "missing"]),
43
+ /** The test that proves a met criterion. */
44
+ // Models often send null for "no test".
45
+ test: z.string().min(1).nullish(),
46
+ })
47
+ ),
48
+ /** What the reviewer changed, and why. */
49
+ changes: z.array(z.string()),
50
+ /** What a person should look at. */
51
+ notes: z.array(z.string()),
52
+ })
53
+
54
+ export type ReviewReport = z.infer<typeof reviewReport>
55
+
56
+ /** The reviewer's report: each acceptance criterion, its fixes, its notes. */
57
+ export const REVIEW_REPORT = sandcastle.Output.object({
58
+ tag: "review",
59
+ schema: reviewReport,
60
+ })
61
+
62
+ const CRITERION_STATUS: Record<
63
+ ReviewReport["criteria"][number]["status"],
64
+ string
65
+ > = {
66
+ met: "Met",
67
+ "not-verifiable": "Not verifiable in the sandbox",
68
+ missing: "Missing",
69
+ }
70
+
71
+ export const REVIEW_PROMPT = `Answer the host with your report as JSON in a <review> tag, and nothing else. The PR writer writes the pull request from it.
72
+
73
+ - \`criteria\`: every acceptance criterion of the issue, as the issue words it, with its \`status\`: "met", "not-verifiable" (it needs Docker, a browser, a model or a service the project doesn't start for the sandbox) or "missing". For a met criterion, \`test\` names the test that proves it.
74
+ - \`changes\`: what you changed on the branch, and why, one line each.
75
+ - \`notes\`: anything a person should look at, one line each.
76
+
77
+ <review>{"criteria": [{"criterion": "An order stores its total", "status": "met", "test": "test_an_order_stores_its_total"}, {"criterion": "Checked by hand in the running app", "status": "not-verifiable"}], "changes": ["Renamed data to invoice in the route, per the glossary."], "notes": []}</review>`
78
+
79
+ const bullets = (lines: readonly string[]) =>
80
+ lines.length === 0 ? "- None." : lines.map((line) => `- ${line}`).join("\n")
81
+
82
+ /** The reviewer's report as Markdown, for the PR writer. */
83
+ export const reviewMarkdown = (report: ReviewReport) =>
84
+ [
85
+ "### Acceptance criteria",
86
+ bullets(
87
+ report.criteria.map(
88
+ ({ criterion, status, test }) =>
89
+ `**${CRITERION_STATUS[status]}:** ${criterion}${test ? ` (test: \`${test}\`)` : ""}`
90
+ )
91
+ ),
92
+ "### What the reviewer changed",
93
+ bullets(report.changes),
94
+ "### For a person to look at",
95
+ bullets(report.notes),
96
+ ].join("\n\n")
97
+
98
+ const pullRequestDraft = z.object({
99
+ title: z.string().trim().min(1),
100
+ body: z.string().trim().min(1),
101
+ })
102
+
103
+ export type PullRequestDraft = z.infer<typeof pullRequestDraft>
104
+
105
+ /** The PR writer's pull request. The host fixes it up before opening it. */
106
+ export const PULL_REQUEST_DRAFT = sandcastle.Output.object({
107
+ tag: "pull-request",
108
+ schema: pullRequestDraft,
109
+ })
110
+
111
+ export const PULL_REQUEST_PROMPT = `Answer the host with the pull request as JSON in a <pull-request> tag, and nothing else: its \`title\` and its Markdown \`body\`, as THE TITLE and THE BODY say.
112
+
113
+ <pull-request>{"title": "feat(agent): hand a support case to the operator", "body": "## Summary\\n\\n..."}</pull-request>`
114
+
115
+ const CONVENTIONAL_TITLE =
116
+ /^(feat|fix|docs|test|refactor|perf|build|ci|chore|style)(\([\w./-]+\))?!?: \S/
117
+
118
+ const FOOTER =
119
+ "---\n\nBuilt by the Sandcastle factory. It merges nothing: review it as you would any pull request."
120
+
121
+ /**
122
+ * The pull request the host opens for issue `issue`: the writer's title on one
123
+ * line, and its body with a closing line for the issue and the factory's
124
+ * footer. A title that isn't a conventional commit is the host's to warn of:
125
+ * release tooling may read it.
126
+ */
127
+ export const finishPullRequest = (issue: number, draft: PullRequestDraft) => {
128
+ const title = draft.title.trim().split("\n")[0] ?? ""
129
+ let body = draft.body.trim()
130
+ if (!new RegExp(`\\b(Closes|Fixes|Resolves) #${issue}\\b`, "i").test(body)) {
131
+ body += `\n\nCloses #${issue}`
132
+ }
133
+ return {
134
+ title,
135
+ body: `${body}\n\n${FOOTER}`,
136
+ titleIsConventional: CONVENTIONAL_TITLE.test(title),
137
+ }
138
+ }
139
+
140
+ const commentBody = z.string().trim().min(1)
141
+
142
+ /**
143
+ * What the review addresser posts: its replies to your thread comments, by
144
+ * their node ids, and comments on the pull request. The host posts them.
145
+ */
146
+ export const FEEDBACK_ANSWER = sandcastle.Output.object({
147
+ tag: "answer",
148
+ schema: z.object({
149
+ threadReplies: z
150
+ .array(z.object({ commentId: z.string().min(1), body: commentBody }))
151
+ .default([]),
152
+ topLevelComments: z.array(z.object({ body: commentBody })).default([]),
153
+ }),
154
+ })
155
+
156
+ export const FEEDBACK_PROMPT = `Answer the host with JSON in an <answer> tag, and nothing else. The host posts it on the pull request, as the factory.
157
+
158
+ - \`threadReplies\`: your reply to a review comment, by the \`commentId\` it has in the feedback.
159
+ - \`topLevelComments\`: comments on the pull request itself, for feedback that isn't in a thread.
160
+
161
+ Use empty lists when you have nothing to say.
162
+
163
+ <answer>{"threadReplies": [{"commentId": "PRRC_kwDOexample", "body": "Renamed to \`invoice\` in 1a2b3c4."}], "topLevelComments": [{"body": "Kept the retry: ADR 0004 says every call to the payment service retries once."}]}</answer>`