@hyperwindmill/caretaker-cli 0.32.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.
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +9 -1
- 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 +7 -0
- package/dist/cli/web/openapi.d.ts.map +1 -0
- package/dist/cli/web/openapi.js +489 -0
- package/dist/cli/web/scheduler/cycle_events.d.ts +8 -3
- package/dist/cli/web/scheduler/cycle_events.d.ts.map +1 -1
- package/dist/cli/web/scheduler/cycle_events.js +2 -0
- package/dist/cli/web/scheduler/email_triage.d.ts +8 -1
- package/dist/cli/web/scheduler/email_triage.d.ts.map +1 -1
- package/dist/cli/web/scheduler/email_triage.js +19 -4
- package/dist/cli/web/scheduler/email_triage_agent.d.ts.map +1 -1
- package/dist/cli/web/scheduler/email_triage_agent.js +1 -0
- package/dist/cli/web/scheduler/heartbeat.d.ts +1 -1
- package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -1
- package/dist/cli/web/scheduler/heartbeat.js +9 -5
- package/dist/cli/web/scheduler/service_runs.d.ts +12 -0
- package/dist/cli/web/scheduler/service_runs.d.ts.map +1 -0
- package/dist/cli/web/scheduler/service_runs.js +39 -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.js +41 -14
- package/dist/cli/web/scheduler.d.ts +9 -0
- package/dist/cli/web/scheduler.d.ts.map +1 -1
- package/dist/cli/web/scheduler.js +24 -2
- package/dist/cli/web/server.d.ts +4 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +67 -13
- 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/email.d.ts.map +1 -1
- package/dist/lib/email.js +2 -1
- 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/webview/standalone.js +1039 -768
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { MessageRecord } from '../../../session/types.js';
|
|
2
|
-
export type CycleEvent =
|
|
2
|
+
export type CycleEvent =
|
|
3
|
+
/** A user turn known only mid-run (the triage prompt is built after listing mail). */
|
|
4
|
+
{
|
|
5
|
+
type: 'user';
|
|
6
|
+
text: string;
|
|
7
|
+
} | {
|
|
3
8
|
type: 'chunk';
|
|
4
9
|
text: string;
|
|
5
10
|
} | {
|
|
@@ -20,12 +25,12 @@ export type CycleEvent = {
|
|
|
20
25
|
type: 'error';
|
|
21
26
|
message: string;
|
|
22
27
|
};
|
|
23
|
-
export declare function beginCycleStream(sessionId: string, prompt: MessageRecord): void;
|
|
28
|
+
export declare function beginCycleStream(sessionId: string, prompt: MessageRecord | null): void;
|
|
24
29
|
export declare function emitCycleEvent(sessionId: string, ev: CycleEvent): void;
|
|
25
30
|
/** Attach to a running cycle. Snapshot and attach happen synchronously, so no
|
|
26
31
|
* event can fall between them. `null` when the cycle is not running. */
|
|
27
32
|
export declare function watchCycleStream(sessionId: string, listener: (ev: CycleEvent) => void): {
|
|
28
|
-
prompt: MessageRecord;
|
|
33
|
+
prompt: MessageRecord | null;
|
|
29
34
|
events: CycleEvent[];
|
|
30
35
|
unwatch: () => void;
|
|
31
36
|
} | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cycle_events.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/cycle_events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cycle_events.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/cycle_events.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,MAAM,UAAU;AACpB,sFAAsF;AACpF;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAWvC,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAEtF;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,GAAG,IAAI,CAgBtE;AAED;yEACyE;AACzE,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,EAAE,EAAE,UAAU,KAAK,IAAI,GACjC;IAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG,IAAI,CAWpF"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// the chat's own stream events keyed by session id; WebSocket watchers attach
|
|
3
3
|
// to a running cycle and replay what has happened so far, then follow it.
|
|
4
4
|
// Finished cycles are dropped from the map — watchers then load from disk.
|
|
5
|
+
// Service runs (heartbeat, email triage) use the same channel keyed by run id;
|
|
6
|
+
// see service_runs.ts.
|
|
5
7
|
const running = new Map();
|
|
6
8
|
export function beginCycleStream(sessionId, prompt) {
|
|
7
9
|
running.set(sessionId, { prompt, events: [], listeners: new Set() });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type EmailAccount, type OutgoingMail, type TriageEnvelope, type listUnseenEnvelopes } from '../../../lib/email.js';
|
|
2
2
|
import type { MessageRecord } from '../../../session/types.js';
|
|
3
3
|
import type { AgentConfig, CaretakerConfig, ProviderConfig, ServiceConfig } from '../../../types.js';
|
|
4
|
+
import { serviceRunCallbacks } from './service_runs.js';
|
|
4
5
|
export declare const TRIAGE_INSTRUCTIONS = "You are triaging an inbox. Classify every unread email below into exactly one bucket:\n\n- IMPORTANT: needs action soon: outages, blocked users or customers, failures, direct requests with a deadline.\n- INFORMATION: worth knowing, no immediate action.\n- TRASH: noise: automated notifications without a decision, time tracking, routine bot chatter. Count only, never list.\n\nYour final message must contain only the report, in exactly this shape, starting with \"## IMPORTANT\". Every bucket header is always present; when a table would be empty, write \"_No important emails._\" or \"_No information emails._\" instead of it.\n\n## IMPORTANT\n| From | Subject | Category | Summary | Suggested Action |\n\n## INFORMATION\n| From | Subject | Category | Summary | Suggested Action |\n\n## TRASH\nN emails classified as trash (not listed).\n\nHeaders, bucket names and the table header row are literal and must never be translated, whatever language the rest of the report is written in.\n\nGuidelines:\n- Work from the envelopes (From, Subject, Date). Open a body with email_read only when the subject is not enough.\n- Cluster related notifications into one row.\n- Other tools you have (for example an issue tracker) may be used to understand a reference in an email.\n- Do not send mail: your final message is delivered automatically.";
|
|
5
6
|
export type TriageStop = 'done' | 'max_turns' | 'aborted';
|
|
6
7
|
export declare function buildTriagePrompt(p: {
|
|
@@ -12,6 +13,10 @@ export declare function buildTriagePrompt(p: {
|
|
|
12
13
|
* line on. A truncated run (max_turns/aborted) never yields one: its last
|
|
13
14
|
* message may be a half-finished "let me read uid 42". */
|
|
14
15
|
export declare function extractReport(messages: MessageRecord[], stop: TriageStop): string | null;
|
|
16
|
+
/** Envelopes per run: unset → 50; otherwise 1..MAX_SCAN. Only envelopes reach
|
|
17
|
+
* the prompt (one line each), so the cap is the scan window, not email_fetch's
|
|
18
|
+
* MAX_FETCH, which bounds full bodies. */
|
|
19
|
+
export declare function triageLimit(max: number | undefined): number;
|
|
15
20
|
export declare function triageSubject(prefix: string, count: number, now: Date): string;
|
|
16
21
|
export declare function parseRecipients(raw: string | undefined): string[];
|
|
17
22
|
/** Preflight: everything that can be checked before touching IMAP. Looks the
|
|
@@ -30,6 +35,8 @@ export type TriageAgentInput = {
|
|
|
30
35
|
account: EmailAccount;
|
|
31
36
|
workingDir: string;
|
|
32
37
|
signal: AbortSignal;
|
|
38
|
+
/** Live-stream hooks for the log viewer; spread into the run's callbacks. */
|
|
39
|
+
stream: ReturnType<typeof serviceRunCallbacks>;
|
|
33
40
|
};
|
|
34
41
|
export type TriageDeps = {
|
|
35
42
|
load(): Promise<{
|
|
@@ -59,5 +66,5 @@ export type TriageOutcome = {
|
|
|
59
66
|
marked: boolean;
|
|
60
67
|
warning?: string;
|
|
61
68
|
};
|
|
62
|
-
export declare function executeTriageRun(service: ServiceConfig, deps: TriageDeps): Promise<TriageOutcome>;
|
|
69
|
+
export declare function executeTriageRun(service: ServiceConfig, deps: TriageDeps, runId?: string): Promise<TriageOutcome>;
|
|
63
70
|
//# sourceMappingURL=email_triage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email_triage.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/email_triage.ts"],"names":[],"mappings":"AAQA,OAAO,
|
|
1
|
+
{"version":3,"file":"email_triage.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/email_triage.ts"],"names":[],"mappings":"AAQA,OAAO,EAOL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,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