@hyperwindmill/caretaker-cli 0.33.0 → 0.35.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/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +25 -1
- package/dist/cli/orchestrator_demo.d.ts +39 -0
- package/dist/cli/orchestrator_demo.d.ts.map +1 -0
- package/dist/cli/orchestrator_demo.js +98 -0
- package/dist/cli/web/api_access.d.ts +38 -0
- package/dist/cli/web/api_access.d.ts.map +1 -0
- package/dist/cli/web/api_access.js +125 -0
- package/dist/cli/web/openapi.d.ts +12 -0
- package/dist/cli/web/openapi.d.ts.map +1 -0
- package/dist/cli/web/openapi.js +526 -0
- package/dist/cli/web/orchestrator.d.ts +51 -0
- package/dist/cli/web/orchestrator.d.ts.map +1 -0
- package/dist/cli/web/orchestrator.js +596 -0
- package/dist/cli/web/orchestrator_core.d.ts +83 -0
- package/dist/cli/web/orchestrator_core.d.ts.map +1 -0
- package/dist/cli/web/orchestrator_core.js +219 -0
- package/dist/cli/web/save_config.d.ts +8 -0
- package/dist/cli/web/save_config.d.ts.map +1 -0
- package/dist/cli/web/save_config.js +9 -0
- package/dist/cli/web/scheduler/task_review.d.ts +8 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +17 -1
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +62 -16
- package/dist/cli/web/server.d.ts +7 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +44 -25
- package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/task_tools.js +5 -17
- package/dist/lib/task_git.d.ts +3 -0
- package/dist/lib/task_git.d.ts.map +1 -1
- package/dist/lib/task_git.js +29 -0
- package/dist/store/db.d.ts +12 -0
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +37 -0
- package/dist/store/json.d.ts +29 -0
- package/dist/store/json.d.ts.map +1 -1
- package/dist/store/json.js +54 -0
- package/dist/store/orchestrator.d.ts +50 -0
- package/dist/store/orchestrator.d.ts.map +1 -0
- package/dist/store/orchestrator.js +127 -0
- package/dist/webview/standalone.css +159 -1
- package/dist/webview/standalone.css.map +2 -2
- package/dist/webview/standalone.js +933 -495
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -0,0 +1,526 @@
|
|
|
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
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* True when method + pathname is an operation of `paths` ({param} = exactly
|
|
492
|
+
* one non-empty segment), or GET /api/openapi.json. Pathname only: no query.
|
|
493
|
+
*/
|
|
494
|
+
export function isDocumentedRoute(method, pathname) {
|
|
495
|
+
if (!pathname || pathname.includes('?'))
|
|
496
|
+
return false;
|
|
497
|
+
const lowerMethod = method.toLowerCase();
|
|
498
|
+
if (lowerMethod === 'get' && pathname === '/api/openapi.json')
|
|
499
|
+
return true;
|
|
500
|
+
const pathSegs = pathname.split('/');
|
|
501
|
+
for (const [template, ops] of Object.entries(paths)) {
|
|
502
|
+
if (!Object.prototype.hasOwnProperty.call(ops, lowerMethod))
|
|
503
|
+
continue;
|
|
504
|
+
const templateSegs = template.split('/');
|
|
505
|
+
if (templateSegs.length !== pathSegs.length)
|
|
506
|
+
continue;
|
|
507
|
+
let match = true;
|
|
508
|
+
for (let i = 0; i < templateSegs.length; i++) {
|
|
509
|
+
const t = templateSegs[i];
|
|
510
|
+
const p = pathSegs[i];
|
|
511
|
+
if (t.startsWith('{') && t.endsWith('}')) {
|
|
512
|
+
if (p.length === 0) {
|
|
513
|
+
match = false;
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
else if (t !== p) {
|
|
518
|
+
match = false;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (match)
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import { type RemoteMessage } from './orchestrator_core.js';
|
|
3
|
+
export type AppLike = {
|
|
4
|
+
request(path: string, init?: RequestInit): Response | Promise<Response>;
|
|
5
|
+
};
|
|
6
|
+
export interface CycleDeps {
|
|
7
|
+
app: AppLike;
|
|
8
|
+
fetch: typeof fetch;
|
|
9
|
+
now?: () => Date;
|
|
10
|
+
}
|
|
11
|
+
export interface OrchestratorStatus {
|
|
12
|
+
state: 'off' | 'registering' | 'connected' | 'error';
|
|
13
|
+
orchestratorName?: string;
|
|
14
|
+
lastPollAt?: string;
|
|
15
|
+
lastError?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs one request against the in-process Hono app. Never throws.
|
|
19
|
+
* Refuses (404) when the normalized pathname is not documented in OpenAPI.
|
|
20
|
+
* Response bodies over MAX_BODY_BYTES become 413.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyMessage(app: AppLike, msg: RemoteMessage): Promise<{
|
|
23
|
+
status: number;
|
|
24
|
+
body: unknown;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* One register-if-needed + poll cycle. Never throws; failures land in status.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runCycle(deps: CycleDeps): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Approves or rejects a pending ledger message.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolvePending(app: AppLike, id: string, decision: 'approve' | 'reject'): Promise<'ok' | 'not_found' | 'not_pending'>;
|
|
34
|
+
export declare function orchestratorStatus(): OrchestratorStatus;
|
|
35
|
+
/**
|
|
36
|
+
* Config-save hook: forgets the registration and the status, and retires any
|
|
37
|
+
* cycle still running under the previous configuration. Leaves the boot
|
|
38
|
+
* recovery alone: it runs once per process, and re-running it would settle a
|
|
39
|
+
* message that is being applied right now as an interrupted one.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resetOrchestrator(): void;
|
|
42
|
+
/** Tests only: also re-arms the once-per-process boot recovery. */
|
|
43
|
+
export declare function resetOrchestratorForTests(): void;
|
|
44
|
+
export declare function stopOrchestrator(): void;
|
|
45
|
+
/**
|
|
46
|
+
* (Re)starts the self-rescheduling poll loop from the saved config.
|
|
47
|
+
* Runs recoverLedger once per process before the first cycle.
|
|
48
|
+
*/
|
|
49
|
+
export declare function startOrchestrator(app: AppLike, fetchImpl?: typeof fetch): void;
|
|
50
|
+
export declare function registerOrchestrator(app: Hono, fetchImpl?: typeof fetch): void;
|
|
51
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../../src/cli/web/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAUjC,OAAO,EAYL,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAGhC,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACzE,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,GAAG,aAAa,GAAG,WAAW,GAAG,OAAO,CAAC;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,aAAa,GACjB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CA2C5C;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAIvD;AAiQD;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAC7B,OAAO,CAAC,IAAI,GAAG,WAAW,GAAG,aAAa,CAAC,CA0C7C;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC;AAED,mEAAmE;AACnE,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAMvC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,GAAE,OAAO,KAAa,GAAG,IAAI,CA6BrF;AAqBD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,GAAE,OAAO,KAAa,GAAG,IAAI,CAqGrF"}
|