@hyperwindmill/caretaker-cli 0.33.0 → 0.34.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.
@@ -0,0 +1,489 @@
1
+ import { readFileSync } from 'node:fs';
2
+ const ref = (name) => ({ $ref: `#/components/schemas/${name}` });
3
+ const json = (schema) => ({ content: { 'application/json': { schema } } });
4
+ const res = (description, schema = ref('Ok')) => ({ description, ...json(schema) });
5
+ const errorRes = (description) => res(description, ref('Error'));
6
+ const body = (schema) => ({ required: true, ...json(schema) });
7
+ const nullable = (type, description) => ({
8
+ type: [type, 'null'],
9
+ ...(description ? { description } : {}),
10
+ });
11
+ const idParam = (what) => ({
12
+ name: 'id',
13
+ in: 'path',
14
+ required: true,
15
+ description: `${what} id.`,
16
+ schema: { type: 'string', pattern: '^[a-z0-9][a-z0-9-]*$' },
17
+ });
18
+ const TRI_STATE = 'true/false overrides the project; null inherits from it.';
19
+ const RUNNING = errorRes('The task is running. Pause it or wait for the cycle to end.');
20
+ const NOT_FOUND = errorRes('No task with this id.');
21
+ const checklistStatus = {
22
+ type: 'string',
23
+ enum: ['pending', 'in_progress', 'done', 'skipped'],
24
+ };
25
+ const roleFields = {
26
+ agentId: nullable('string', 'Developer agent. Null falls back to the project, then to the first agent.'),
27
+ plannerAgentId: nullable('string', 'Planner agent. Null falls back to the developer.'),
28
+ reviewerAgentId: nullable('string', 'Reviewer agent. Null falls back to the developer.'),
29
+ planningEnabled: nullable('boolean', `Planning phase before execution. ${TRI_STATE}`),
30
+ reviewEnabled: nullable('boolean', `Review gate before done. ${TRI_STATE}`),
31
+ sddEnabled: nullable('boolean', `Let the planner write markdown documents. ${TRI_STATE}`),
32
+ maxRunSeconds: nullable('number', 'Wall-clock budget of one cycle, in seconds. Null inherits.'),
33
+ };
34
+ const schemas = {
35
+ Ok: { type: 'object', required: ['ok'], properties: { ok: { type: 'boolean', const: true } } },
36
+ Error: {
37
+ type: 'object',
38
+ required: ['error'],
39
+ properties: { ok: { type: 'boolean', const: false }, error: { type: 'string' } },
40
+ },
41
+ ChecklistItem: {
42
+ type: 'object',
43
+ required: ['id', 'text', 'status', 'order'],
44
+ properties: {
45
+ id: { type: 'string' },
46
+ text: { type: 'string' },
47
+ status: checklistStatus,
48
+ order: { type: 'integer', description: 'Position in the checklist, from 0.' },
49
+ },
50
+ },
51
+ ChecklistItemInput: {
52
+ type: 'object',
53
+ required: ['text'],
54
+ properties: {
55
+ id: { type: 'string', description: 'Keep this id. Omit it to get a new one.' },
56
+ text: { type: 'string', minLength: 1 },
57
+ status: {
58
+ ...checklistStatus,
59
+ description: 'Optional when creating a task (defaults to pending). Required when replacing a checklist.',
60
+ },
61
+ },
62
+ },
63
+ Task: {
64
+ type: 'object',
65
+ required: ['id', 'projectId', 'seq', 'title', 'objective', 'checklist', 'status', 'createdAt', 'updatedAt'],
66
+ properties: {
67
+ id: { type: 'string', description: 'Opaque. Do not parse it; use projectId and seq.' },
68
+ projectId: { type: 'string' },
69
+ seq: { type: 'integer', description: 'Per-project sequence number, never reused.' },
70
+ title: { type: 'string' },
71
+ objective: { type: 'string' },
72
+ checklist: { type: 'array', items: ref('ChecklistItem') },
73
+ status: {
74
+ type: 'string',
75
+ enum: ['draft', 'planning', 'active', 'reviewing', 'paused', 'blocked', 'done'],
76
+ description: 'planning, active and reviewing are advanced by the scheduler. blocked needs a person: see blockedReason.',
77
+ },
78
+ blockedReason: nullable('string', 'Why the task is blocked. Null otherwise.'),
79
+ noProgressCount: { type: 'integer' },
80
+ maxNoProgress: { type: 'integer' },
81
+ lockedAt: nullable('string', 'Set while a cycle is running.'),
82
+ branch: nullable('string', 'Git branch holding the task work, for projects in a git repository.'),
83
+ worktreePath: nullable('string', 'Null once the worktree is removed (done or discarded).'),
84
+ dockerContainer: nullable('string'),
85
+ archived: { type: 'boolean' },
86
+ ...roleFields,
87
+ createdAt: { type: 'string', format: 'date-time' },
88
+ updatedAt: { type: 'string', format: 'date-time' },
89
+ },
90
+ },
91
+ TaskMessage: {
92
+ type: 'object',
93
+ required: ['id', 'taskId', 'role', 'messageType', 'content', 'createdAt'],
94
+ properties: {
95
+ id: { type: 'integer' },
96
+ taskId: { type: 'string' },
97
+ role: { type: 'string', enum: ['user', 'assistant', 'tool'] },
98
+ messageType: {
99
+ type: 'string',
100
+ enum: ['chat', 'heartbeat', 'heartbeat_live', 'system', 'block', 'tool_call', 'yield', 'review', 'plan', 'cycle'],
101
+ description: 'chat: a note from a person or an agent handoff. plan / review: the planner and reviewer output. block: why the task was blocked. cycle: one autonomous run (see cycleRole and cycleOutcome). system: an audit note.',
102
+ },
103
+ content: { type: 'string' },
104
+ agentId: nullable('string'),
105
+ agentLabel: nullable('string', '"name · model" of the agent that produced the message, as it was then.'),
106
+ sessionId: nullable('string', 'cycle messages: the session recording the run.'),
107
+ sessionAgentId: nullable('string'),
108
+ cycleRole: { type: ['string', 'null'], enum: ['developer', 'planner', 'reviewer', null] },
109
+ cycleOutcome: {
110
+ type: ['string', 'null'],
111
+ enum: ['running', 'handoff', 'completed', 'blocked', 'plan', 'review-pass', 'review-changes', 'aborted', 'failed', null],
112
+ description: 'running until the cycle closes.',
113
+ },
114
+ createdAt: { type: 'string', format: 'date-time' },
115
+ },
116
+ },
117
+ Project: {
118
+ type: 'object',
119
+ required: ['id', 'name'],
120
+ properties: {
121
+ id: { type: 'string', description: 'Slug chosen at creation, immutable.' },
122
+ name: { type: 'string' },
123
+ description: { type: 'string' },
124
+ workingDir: { type: 'string', description: 'Blank for a remote-backed project using a managed clone.' },
125
+ active: { type: 'boolean' },
126
+ ...roleFields,
127
+ bootstrapCommands: {
128
+ type: ['array', 'null'],
129
+ items: { type: 'string' },
130
+ description: 'Run once in a new task worktree, each in its own shell.',
131
+ },
132
+ dockerImage: nullable('string', 'Image reference, or a Dockerfile path, isolating the task runs.'),
133
+ repositoryUrl: nullable('string', 'HTTPS URL without credentials.'),
134
+ repositoryToken: nullable('string', 'Write-only in practice: read back as an encrypted value.'),
135
+ },
136
+ },
137
+ ProjectInput: {
138
+ type: 'object',
139
+ required: ['id', 'name'],
140
+ properties: {
141
+ id: { type: 'string', pattern: '^[a-z0-9][a-z0-9-]*$' },
142
+ name: { type: 'string' },
143
+ description: { type: 'string' },
144
+ workingDir: { type: 'string' },
145
+ ...roleFields,
146
+ bootstrapCommands: { type: 'array', items: { type: 'string' } },
147
+ dockerImage: { type: 'string' },
148
+ repositoryUrl: { type: 'string' },
149
+ repositoryToken: { type: 'string' },
150
+ },
151
+ },
152
+ TaskInput: {
153
+ type: 'object',
154
+ required: ['title', 'objective'],
155
+ properties: {
156
+ title: { type: 'string' },
157
+ objective: { type: 'string' },
158
+ checklist: { type: 'array', items: ref('ChecklistItemInput') },
159
+ startActive: {
160
+ type: 'boolean',
161
+ description: 'true starts the task at once (planning, or active when planning is off). Default: draft.',
162
+ },
163
+ ...roleFields,
164
+ },
165
+ },
166
+ };
167
+ const task = [idParam('Task')];
168
+ const project = [idParam('Project')];
169
+ const paths = {
170
+ '/api/projects': {
171
+ get: {
172
+ tags: ['Projects'],
173
+ summary: 'List projects',
174
+ responses: { 200: res('The configured projects.', { type: 'array', items: ref('Project') }) },
175
+ },
176
+ post: {
177
+ tags: ['Projects'],
178
+ summary: 'Create a project',
179
+ requestBody: body(ref('ProjectInput')),
180
+ responses: {
181
+ 200: res('Created.'),
182
+ 400: errorRes('Invalid or duplicate id, or a repository URL that is not credential-free HTTPS.'),
183
+ },
184
+ },
185
+ },
186
+ '/api/projects/{id}': {
187
+ delete: {
188
+ tags: ['Projects'],
189
+ summary: 'Delete a project with its tasks',
190
+ description: 'Removes the project, every task and message in it, and its managed repository clone. A working directory you chose is never touched.',
191
+ parameters: project,
192
+ responses: { 200: res('Deleted.'), 400: errorRes('Invalid id.') },
193
+ },
194
+ },
195
+ '/api/projects/{id}/sync': {
196
+ post: {
197
+ tags: ['Projects'],
198
+ summary: 'Clone or pull the project repository',
199
+ description: 'Progress is streamed as newline-delimited JSON; a failure arrives as a line with step "error".',
200
+ parameters: project,
201
+ responses: {
202
+ 200: {
203
+ description: 'Progress lines.',
204
+ content: { 'application/x-ndjson': { schema: { type: 'object', properties: { step: { type: 'string' } } } } },
205
+ },
206
+ 400: errorRes('Invalid id, or the project has no repository URL.'),
207
+ 404: errorRes('No project with this id.'),
208
+ 409: errorRes('A sync is already running.'),
209
+ },
210
+ },
211
+ },
212
+ '/api/projects/{id}/repo-status': {
213
+ get: {
214
+ tags: ['Projects'],
215
+ summary: 'State of the project repository on disk',
216
+ parameters: project,
217
+ responses: {
218
+ 200: res('Derived at request time, never stored.', {
219
+ type: 'object',
220
+ required: ['state'],
221
+ properties: { state: { type: 'string' } },
222
+ additionalProperties: true,
223
+ }),
224
+ 400: errorRes('Invalid id, or the project has no repository URL.'),
225
+ 404: errorRes('No project with this id.'),
226
+ },
227
+ },
228
+ },
229
+ '/api/projects/{id}/tasks': {
230
+ get: {
231
+ tags: ['Tasks'],
232
+ summary: 'List the tasks of a project',
233
+ description: 'An unknown project answers an empty list.',
234
+ parameters: [
235
+ ...project,
236
+ {
237
+ name: 'archived',
238
+ in: 'query',
239
+ description: 'true includes archived tasks.',
240
+ schema: { type: 'string', enum: ['true'] },
241
+ },
242
+ ],
243
+ responses: { 200: res('Tasks, with status, checklist and blockedReason.', { type: 'array', items: ref('Task') }) },
244
+ },
245
+ post: {
246
+ tags: ['Tasks'],
247
+ summary: 'Create a task',
248
+ description: 'Tasks advance only while a web server process is running.',
249
+ parameters: project,
250
+ requestBody: body(ref('TaskInput')),
251
+ responses: {
252
+ 200: res('The created task, with its id and the ids of its checklist items.', {
253
+ type: 'object',
254
+ required: ['ok', 'task'],
255
+ properties: { ok: { type: 'boolean', const: true }, task: ref('Task') },
256
+ }),
257
+ 400: errorRes('Unknown agent id, or an invalid checklist.'),
258
+ },
259
+ },
260
+ },
261
+ '/api/tasks/{id}': {
262
+ patch: {
263
+ tags: ['Tasks'],
264
+ summary: 'Change the title or the objective',
265
+ description: 'An absent key is left unchanged. The next cycle reads the new text; a running one is not interrupted.',
266
+ parameters: task,
267
+ requestBody: body({
268
+ type: 'object',
269
+ minProperties: 1,
270
+ properties: { title: { type: 'string', minLength: 1 }, objective: { type: 'string' } },
271
+ }),
272
+ responses: {
273
+ 200: res('The stored values.', {
274
+ type: 'object',
275
+ properties: { ok: { type: 'boolean', const: true }, title: { type: 'string' }, objective: { type: 'string' } },
276
+ }),
277
+ 400: errorRes('Nothing to update, a wrong type, or a blank title.'),
278
+ 404: NOT_FOUND,
279
+ },
280
+ },
281
+ delete: {
282
+ tags: ['Tasks'],
283
+ summary: 'Delete a task and its messages',
284
+ description: 'Permanent. The worktree is removed; the branch is pushed first when the project has a repository.',
285
+ parameters: task,
286
+ responses: { 200: res('Deleted.'), 404: NOT_FOUND, 409: RUNNING },
287
+ },
288
+ },
289
+ '/api/tasks/{id}/messages': {
290
+ get: {
291
+ tags: ['Tasks'],
292
+ summary: 'Read the task thread',
293
+ description: 'Oldest first. An unknown task answers an empty list.',
294
+ parameters: task,
295
+ responses: { 200: res('Messages.', { type: 'array', items: ref('TaskMessage') }) },
296
+ },
297
+ post: {
298
+ tags: ['Tasks'],
299
+ summary: 'Send a message to the task',
300
+ description: 'Stored as a chat message from a person, read by the agent on its next cycle. It also reactivates the task whatever its status — paused, blocked and done included — so read the status first if that is not wanted.',
301
+ parameters: task,
302
+ requestBody: body({ type: 'object', required: ['content'], properties: { content: { type: 'string' } } }),
303
+ responses: { 200: res('Stored.') },
304
+ },
305
+ },
306
+ '/api/tasks/{id}/status': {
307
+ post: {
308
+ tags: ['Tasks'],
309
+ summary: 'Pause, block or reactivate a task',
310
+ description: '"active" reactivates: the task goes to planning when planning is on and no plan exists yet, otherwise to active, and blockedReason is cleared. Any other status is stored as given and aborts the cycle in flight. An unknown task still answers ok.',
311
+ parameters: task,
312
+ requestBody: body({
313
+ type: 'object',
314
+ required: ['status'],
315
+ properties: { status: { type: 'string', enum: ['active', 'paused', 'blocked', 'draft', 'done'] } },
316
+ }),
317
+ responses: { 200: res('Applied.') },
318
+ },
319
+ },
320
+ '/api/tasks/{id}/checklist': {
321
+ put: {
322
+ tags: ['Tasks'],
323
+ summary: 'Replace the checklist',
324
+ description: 'Items with an id keep it, the others get a new one. Order follows the array. Every item needs a status.',
325
+ parameters: task,
326
+ requestBody: body({
327
+ type: 'object',
328
+ required: ['checklist'],
329
+ properties: { checklist: { type: 'array', items: ref('ChecklistItemInput') } },
330
+ }),
331
+ responses: {
332
+ 200: res('The stored checklist.', {
333
+ type: 'object',
334
+ required: ['ok', 'checklist'],
335
+ properties: { ok: { type: 'boolean', const: true }, checklist: { type: 'array', items: ref('ChecklistItem') } },
336
+ }),
337
+ 400: errorRes('Blank text, a missing or unknown status, or a duplicate id.'),
338
+ 404: NOT_FOUND,
339
+ },
340
+ },
341
+ },
342
+ '/api/tasks/{id}/checklist-item': {
343
+ post: {
344
+ tags: ['Tasks'],
345
+ summary: 'Set the status of one checklist item',
346
+ description: 'An unknown task or item still answers ok and changes nothing.',
347
+ parameters: task,
348
+ requestBody: body({
349
+ type: 'object',
350
+ required: ['itemId', 'status'],
351
+ properties: { itemId: { type: 'string' }, status: checklistStatus },
352
+ }),
353
+ responses: { 200: res('Applied.'), 400: errorRes('Unknown status.') },
354
+ },
355
+ },
356
+ '/api/tasks/{id}/agent': {
357
+ patch: {
358
+ tags: ['Tasks'],
359
+ summary: 'Assign the agent of a role',
360
+ parameters: task,
361
+ requestBody: body({
362
+ type: 'object',
363
+ properties: {
364
+ agentId: nullable('string', 'Null clears the override.'),
365
+ role: { type: 'string', enum: ['developer', 'planner', 'reviewer'], default: 'developer' },
366
+ },
367
+ }),
368
+ responses: {
369
+ 200: res('The assignment.', {
370
+ type: 'object',
371
+ properties: { ok: { type: 'boolean', const: true }, role: { type: 'string' }, agentId: nullable('string') },
372
+ }),
373
+ 400: errorRes('Unknown agent id.'),
374
+ 404: NOT_FOUND,
375
+ 409: RUNNING,
376
+ },
377
+ },
378
+ },
379
+ '/api/tasks/{id}/flags': {
380
+ patch: {
381
+ tags: ['Tasks'],
382
+ summary: 'Set the phase gates and the time budget',
383
+ description: 'An absent key is left unchanged; null goes back to inheriting from the project.',
384
+ parameters: task,
385
+ requestBody: body({
386
+ type: 'object',
387
+ properties: {
388
+ planningEnabled: roleFields.planningEnabled,
389
+ reviewEnabled: roleFields.reviewEnabled,
390
+ sddEnabled: roleFields.sddEnabled,
391
+ maxRunSeconds: roleFields.maxRunSeconds,
392
+ },
393
+ }),
394
+ responses: { 200: res('The stored values.', { type: 'object', additionalProperties: true }), 404: NOT_FOUND },
395
+ },
396
+ },
397
+ '/api/tasks/{id}/archive': {
398
+ post: {
399
+ tags: ['Tasks'],
400
+ summary: 'Archive a task',
401
+ description: 'Hidden from the default list and skipped by the scheduler. An active or reviewing task is paused.',
402
+ parameters: task,
403
+ responses: { 200: res('Archived.'), 404: NOT_FOUND },
404
+ },
405
+ },
406
+ '/api/tasks/{id}/unarchive': {
407
+ post: {
408
+ tags: ['Tasks'],
409
+ summary: 'Unarchive a task',
410
+ parameters: task,
411
+ responses: { 200: res('Unarchived.'), 404: NOT_FOUND },
412
+ },
413
+ },
414
+ '/api/tasks/{id}/discard-worktree': {
415
+ post: {
416
+ tags: ['Tasks'],
417
+ summary: 'Remove the task worktree, keeping the branch',
418
+ description: 'The branch is pushed first when the project has a repository; a failed push keeps the worktree.',
419
+ parameters: task,
420
+ responses: {
421
+ 200: res('Removed.', {
422
+ type: 'object',
423
+ properties: { ok: { type: 'boolean', const: true }, branch: nullable('string') },
424
+ }),
425
+ 400: errorRes('The task has no worktree.'),
426
+ 404: NOT_FOUND,
427
+ 409: RUNNING,
428
+ 500: errorRes('The push failed; the worktree is kept.'),
429
+ },
430
+ },
431
+ },
432
+ };
433
+ export function openApiDocument(version) {
434
+ return {
435
+ openapi: '3.1.0',
436
+ info: {
437
+ title: 'Caretaker API',
438
+ version,
439
+ description: 'Projects and autonomous tasks of a Caretaker web server.\n\nOn the API port every request needs `Authorization: Bearer <token>`; create a token in Settings → API. The main port serves the same routes without authentication and is meant for the local GUI.',
440
+ },
441
+ servers: [{ url: '/', description: 'The server this document was loaded from.' }],
442
+ tags: [{ name: 'Projects' }, { name: 'Tasks' }],
443
+ security: [{ bearerAuth: [] }],
444
+ components: {
445
+ securitySchemes: {
446
+ bearerAuth: { type: 'http', scheme: 'bearer', description: 'An API token (`ctk_…`). Not needed on the main port.' },
447
+ },
448
+ schemas,
449
+ },
450
+ paths,
451
+ };
452
+ }
453
+ /** Routes that describe the API rather than expose data: served without a
454
+ * token on the API port too, or Swagger UI's Authorize could never load. */
455
+ export const OPENAPI_PUBLIC_PATHS = ['/api/openapi.json', '/api/docs'];
456
+ // Pinned; the assets come from a CDN, so the page needs network access. The
457
+ // JSON document above does not.
458
+ const SWAGGER_UI = 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.17.14';
459
+ const DOCS_HTML = `<!doctype html>
460
+ <html lang="en">
461
+ <head>
462
+ <meta charset="utf-8">
463
+ <meta name="viewport" content="width=device-width, initial-scale=1">
464
+ <title>Caretaker API</title>
465
+ <link rel="stylesheet" href="${SWAGGER_UI}/swagger-ui.css">
466
+ </head>
467
+ <body>
468
+ <div id="ui"><p style="font-family:sans-serif;padding:1rem">Loading the API explorer needs network access. The description itself is at <a href="/api/openapi.json">/api/openapi.json</a>.</p></div>
469
+ <script src="${SWAGGER_UI}/swagger-ui-bundle.js"></script>
470
+ <script>
471
+ window.SwaggerUIBundle && SwaggerUIBundle({ url: '/api/openapi.json', dom_id: '#ui', persistAuthorization: true });
472
+ </script>
473
+ </body>
474
+ </html>`;
475
+ /** Same guarded read as cli/index.ts: package.json is not always shipped next
476
+ * to dist/ (the desktop bundle), and that must only degrade the version. */
477
+ function cliVersion() {
478
+ try {
479
+ return JSON.parse(readFileSync(new URL('../../../package.json', import.meta.url), 'utf8')).version;
480
+ }
481
+ catch {
482
+ return '0.0.0';
483
+ }
484
+ }
485
+ export function registerOpenApi(app) {
486
+ const version = cliVersion();
487
+ app.get('/api/openapi.json', (c) => c.json(openApiDocument(version)));
488
+ app.get('/api/docs', (c) => c.html(DOCS_HTML));
489
+ }
@@ -2,6 +2,14 @@ import type { AgentConfig, ProviderConfig } from '../../../types.js';
2
2
  import type { Tool } from '../../../harness/tools/types.js';
3
3
  import { type CycleRecorder } from './task_cycle.js';
4
4
  export declare const MAX_REVIEW_ROUNDS = 3;
5
+ /**
6
+ * What a review verdict does to the task. Rounds are counted from the `review`
7
+ * message stream, so a task unblocked after exhausting them comes back at
8
+ * round MAX+1: each manual unblock grants exactly one more round.
9
+ */
10
+ export declare function reviewTransition(verdict: 'pass' | 'changes', round: number): 'done' | 'reopen' | 'block';
11
+ /** `2/3` within the automatic rounds, the bare number for one granted by an unblock. */
12
+ export declare function reviewRoundLabel(round: number): string;
5
13
  export declare function reviewPrompt(objective: string, branch: string, round: number): string;
6
14
  export declare function parseReviewVerdict(text: string): 'pass' | 'changes';
7
15
  export declare function runDoneReview(opts: {
@@ -1 +1 @@
1
- {"version":3,"file":"task_review.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_review.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAI5D,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA2BrF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMnE;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB;yEACqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;wDAEoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;0EACsE;IACtE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CACxD,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAAE,CAAC,CAsFhF"}
1
+ {"version":3,"file":"task_review.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_review.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAI5D,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAGxG;AAED,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA+BrF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMnE;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB;yEACqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;wDAEoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;0EACsE;IACtE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CACxD,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAAE,CAAC,CAsFhF"}
@@ -4,6 +4,20 @@ import { dockerDevAllowlist } from '../../../lib/docker.js';
4
4
  import { getTaskBridgeUrl, issueBridgeToken, revokeBridgeToken } from '../mcp_bridge.js';
5
5
  import { resolveCycleOutcome } from './task_cycle.js';
6
6
  export const MAX_REVIEW_ROUNDS = 3;
7
+ /**
8
+ * What a review verdict does to the task. Rounds are counted from the `review`
9
+ * message stream, so a task unblocked after exhausting them comes back at
10
+ * round MAX+1: each manual unblock grants exactly one more round.
11
+ */
12
+ export function reviewTransition(verdict, round) {
13
+ if (verdict === 'pass')
14
+ return 'done';
15
+ return round < MAX_REVIEW_ROUNDS ? 'reopen' : 'block';
16
+ }
17
+ /** `2/3` within the automatic rounds, the bare number for one granted by an unblock. */
18
+ export function reviewRoundLabel(round) {
19
+ return round <= MAX_REVIEW_ROUNDS ? `${round}/${MAX_REVIEW_ROUNDS}` : String(round);
20
+ }
7
21
  export function reviewPrompt(objective, branch, round) {
8
22
  return `You are an INDEPENDENT code reviewer. You did not write this code, and your job is to find real problems — not to be agreeable. Do not rubber-stamp.
9
23
 
@@ -26,7 +40,9 @@ Verify claims against the code — do not trust comments or commit messages.
26
40
 
27
41
  Be concrete: cite files and lines. If the work is genuinely complete and correct, say so plainly.
28
42
 
29
- This is review round ${round} of at most ${MAX_REVIEW_ROUNDS}.
43
+ ${round < MAX_REVIEW_ROUNDS
44
+ ? `This is review round ${round} of at most ${MAX_REVIEW_ROUNDS}.`
45
+ : `This is review round ${round}, the last automatic one: a CHANGES_REQUESTED verdict now hands the task back to a person instead of the developer.`}
30
46
 
31
47
  End your response with EXACTLY ONE of these two lines, and nothing after it:
32
48
  REVIEW_RESULT: PASS
@@ -4,7 +4,7 @@ import { loadAgents, loadConfig } from '../../../store/json.js';
4
4
  import { getTaskById, saveTask, addTaskMessage, runQuery } from '../../../store/db.js';
5
5
  import { runningTasks, runningTaskControllers, syncingProjects } from './locks.js';
6
6
  import { isGitRepo, ensureWorktree, agentDirIn, commitWip, finalizeDone, runBootstrap, gitCommonDir, syncProjectRepo, projectWorkingDir, pushBranch } from '../../../lib/task_git.js';
7
- import { runDoneReview, MAX_REVIEW_ROUNDS } from './task_review.js';
7
+ import { runDoneReview, MAX_REVIEW_ROUNDS, reviewTransition, reviewRoundLabel } from './task_review.js';
8
8
  import { openCycle, filterHandoffMessages, resolveCycleOutcome } from './task_cycle.js';
9
9
  import { claudeCodeTaskExtras } from '../../../harness/claude_code_runner.js';
10
10
  import { acpTaskExtras } from '../../../harness/acp_policy.js';
@@ -595,6 +595,7 @@ async function runReviewCycle(opts) {
595
595
  const round = priorReviews + 1;
596
596
  let verdict = 'pass';
597
597
  let reviewText = '';
598
+ let reviewError = null;
598
599
  let cycle;
599
600
  try {
600
601
  const review = await runDoneReview({
@@ -617,9 +618,10 @@ async function runReviewCycle(opts) {
617
618
  cycle = review.cycle;
618
619
  }
619
620
  catch (reviewErr) {
620
- // A broken review must not trap the task in reviewing — finalize as pass.
621
- console.error(`[task_heartbeat] Task #${task.id} review failed, finalizing:`, reviewErr);
622
- verdict = 'pass';
621
+ // A review that could not run proves nothing about the work: it must
622
+ // neither trap the task in reviewing nor pass it. Blocked below.
623
+ reviewError = reviewErr instanceof Error ? reviewErr.message : String(reviewErr);
624
+ console.error(`[task_heartbeat] Task #${task.id} review failed:`, reviewErr);
623
625
  }
624
626
  // The review cycle's session closes once its verdict is written (the recap
625
627
  // is the review text), or at once when a Pause lands mid-review.
@@ -633,12 +635,27 @@ async function runReviewCycle(opts) {
633
635
  await closeCycle();
634
636
  return;
635
637
  }
638
+ if (reviewError !== null) {
639
+ // No review message is written, so the failed attempt uses up no round.
640
+ const reason = `The review could not run, so the task was not finalized: ${reviewError}`;
641
+ current.status = 'blocked';
642
+ current.blockedReason = reason;
643
+ current.updatedAt = new Date().toISOString();
644
+ await saveTask(current);
645
+ await addTaskMessage({
646
+ taskId: task.id,
647
+ role: 'assistant',
648
+ messageType: 'block',
649
+ content: `${reason}\n\nThe worktree and branch are kept. Fix the reviewer agent or its provider and unblock the task; the review runs again at the next completion.`,
650
+ });
651
+ return;
652
+ }
636
653
  if (reviewText) {
637
654
  await addTaskMessage({
638
655
  taskId: task.id,
639
656
  role: 'user',
640
657
  messageType: 'review',
641
- content: `[CODE REVIEW round ${round}/${MAX_REVIEW_ROUNDS}] verdict=${verdict}\n\n${reviewText}`,
658
+ content: `[CODE REVIEW round ${reviewRoundLabel(round)}] verdict=${verdict}\n\n${reviewText}`,
642
659
  // role is 'user' so the verdict replays into the agent's history as feedback,
643
660
  // but the reviewer agent produced it — capture that for the log display.
644
661
  agentLabel: `${agent.name} · ${agent.model}`,
@@ -646,7 +663,8 @@ async function runReviewCycle(opts) {
646
663
  }
647
664
  await closeCycle();
648
665
  console.log(`[task_heartbeat] Task #${task.id} review round ${round}: ${verdict}`);
649
- if (verdict === 'changes' && round < MAX_REVIEW_ROUNDS) {
666
+ const transition = reviewTransition(verdict, round);
667
+ if (transition === 'reopen') {
650
668
  // Reopen: keep the worktree; the review message is replayed to the agent next cycle.
651
669
  current.status = 'active';
652
670
  current.noProgressCount = 0;
@@ -654,15 +672,24 @@ async function runReviewCycle(opts) {
654
672
  await saveTask(current);
655
673
  console.log(`[task_heartbeat] Task #${task.id} reopened by review (round ${round}).`);
656
674
  }
675
+ else if (transition === 'block') {
676
+ // Rounds exhausted with findings outstanding: a task marked done reads as
677
+ // ready to whoever verifies it, so hand it to a person instead. Worktree and
678
+ // branch are kept; unblocking resumes the developer and grants one more round.
679
+ const reason = `Review rounds exhausted (${MAX_REVIEW_ROUNDS}) with findings still outstanding.`;
680
+ current.status = 'blocked';
681
+ current.blockedReason = reason;
682
+ current.updatedAt = new Date().toISOString();
683
+ await saveTask(current);
684
+ await addTaskMessage({
685
+ taskId: task.id,
686
+ role: 'assistant',
687
+ messageType: 'block',
688
+ content: `${reason} The worktree and branch are kept; unblock the task to let the developer address the last review, which grants one more review round.`,
689
+ });
690
+ console.log(`[task_heartbeat] Task #${task.id} blocked: review rounds exhausted (round ${round}).`);
691
+ }
657
692
  else {
658
- if (verdict === 'changes') {
659
- await addTaskMessage({
660
- taskId: task.id,
661
- role: 'assistant',
662
- messageType: 'system',
663
- content: `Finished as done despite outstanding review findings after ${MAX_REVIEW_ROUNDS} rounds.`,
664
- });
665
- }
666
693
  if (!(await pushOrBlock(current, project)))
667
694
  return;
668
695
  if (current.dockerContainer) {
@@ -34,5 +34,8 @@ export declare class WebSessionController {
34
34
  }>, voiceConversation?: boolean): Promise<void>;
35
35
  abort(): void;
36
36
  }
37
- export declare function startServer(port: number, host: string): Promise<void>;
37
+ export declare function startServer(port: number, host: string, api?: {
38
+ port?: number;
39
+ host?: string;
40
+ }): Promise<void>;
38
41
  //# sourceMappingURL=server.d.ts.map