@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
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
// store, IMAP/SMTP wiring) and the scheduler strategy live in
|
|
6
6
|
// email_triage_agent.ts, so this file is testable with plain fakes.
|
|
7
7
|
import { randomUUID } from 'node:crypto';
|
|
8
|
-
import { canRead, canSend,
|
|
8
|
+
import { canRead, canSend, MAX_SCAN, emailAccounts, markdownToHtml, parsePatterns, } from '../../../lib/email.js';
|
|
9
9
|
import { runningTasks } from './locks.js';
|
|
10
|
+
import { beginServiceRun, emitServiceRunEvent, endServiceRun, newRunId, serviceRunCallbacks, } from './service_runs.js';
|
|
10
11
|
import { CLAUDE_CODE_DEFAULT_RUN_SECONDS } from './task_roles.js';
|
|
11
12
|
const DEFAULT_PREFIX = '[Email Triage]';
|
|
12
13
|
export const TRIAGE_INSTRUCTIONS = `You are triaging an inbox. Classify every unread email below into exactly one bucket:
|
|
@@ -68,6 +69,15 @@ export function extractReport(messages, stop) {
|
|
|
68
69
|
const m = /^## IMPORTANT\b.*$/m.exec(text);
|
|
69
70
|
return m ? text.slice(m.index).trim() : null;
|
|
70
71
|
}
|
|
72
|
+
/** Envelopes per run: unset → 50; otherwise 1..MAX_SCAN. Only envelopes reach
|
|
73
|
+
* the prompt (one line each), so the cap is the scan window, not email_fetch's
|
|
74
|
+
* MAX_FETCH, which bounds full bodies. */
|
|
75
|
+
export function triageLimit(max) {
|
|
76
|
+
if (max == null)
|
|
77
|
+
return 50;
|
|
78
|
+
const n = Math.trunc(Number(max));
|
|
79
|
+
return Number.isFinite(n) && n >= 1 ? Math.min(n, MAX_SCAN) : 50;
|
|
80
|
+
}
|
|
71
81
|
export function triageSubject(prefix, count, now) {
|
|
72
82
|
const p = (n) => String(n).padStart(2, '0');
|
|
73
83
|
const stamp = `${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())} ${p(now.getHours())}:${p(now.getMinutes())}`;
|
|
@@ -116,13 +126,14 @@ const assistantNote = (content) => ({
|
|
|
116
126
|
content,
|
|
117
127
|
createdAt: new Date().toISOString(),
|
|
118
128
|
});
|
|
119
|
-
export async function executeTriageRun(service, deps) {
|
|
129
|
+
export async function executeTriageRun(service, deps, runId = newRunId()) {
|
|
120
130
|
if (runningTasks.has(service.id)) {
|
|
121
131
|
console.log(`[scheduler] Triage "${service.name}" is already running — skipping.`);
|
|
122
132
|
return { kind: 'skipped' };
|
|
123
133
|
}
|
|
124
134
|
runningTasks.add(service.id);
|
|
125
|
-
|
|
135
|
+
// Same synchronous block as the lock. No prompt yet: it needs the mail listing.
|
|
136
|
+
beginServiceRun(service.id, runId, null);
|
|
126
137
|
const ctrl = new AbortController();
|
|
127
138
|
const timer = setTimeout(() => ctrl.abort(), CLAUDE_CODE_DEFAULT_RUN_SECONDS * 1000);
|
|
128
139
|
const messages = [];
|
|
@@ -157,7 +168,7 @@ export async function executeTriageRun(service, deps) {
|
|
|
157
168
|
return await fail(`Triage service "${service.name}" has no report recipients.`);
|
|
158
169
|
let listing;
|
|
159
170
|
try {
|
|
160
|
-
listing = await deps.listEnvelopes(account,
|
|
171
|
+
listing = await deps.listEnvelopes(account, triageLimit(service.triageMaxEmails), ctrl.signal);
|
|
161
172
|
}
|
|
162
173
|
catch (e) {
|
|
163
174
|
return await fail(`Listing unread mail failed: ${errText(e)}`);
|
|
@@ -167,6 +178,7 @@ export async function executeTriageRun(service, deps) {
|
|
|
167
178
|
if (scanTruncated) {
|
|
168
179
|
return await fail(`The oldest ${MAX_SCAN} unread messages are all from senders outside the account's allowedSenders, so triage cannot see newer mail. Read, move or delete them (or widen the allowlist).`);
|
|
169
180
|
}
|
|
181
|
+
emitServiceRunEvent(runId, 'No unread mail to triage.', 'chunk');
|
|
170
182
|
return { kind: 'skipped' };
|
|
171
183
|
}
|
|
172
184
|
const prompt = buildTriagePrompt({
|
|
@@ -180,6 +192,7 @@ export async function executeTriageRun(service, deps) {
|
|
|
180
192
|
content: prompt,
|
|
181
193
|
createdAt: new Date().toISOString(),
|
|
182
194
|
});
|
|
195
|
+
emitServiceRunEvent(runId, prompt, 'user');
|
|
183
196
|
let result;
|
|
184
197
|
try {
|
|
185
198
|
result = await deps.runAgent({
|
|
@@ -189,6 +202,7 @@ export async function executeTriageRun(service, deps) {
|
|
|
189
202
|
account,
|
|
190
203
|
workingDir: service.workingDir || agent.workingDir || process.cwd(),
|
|
191
204
|
signal: ctrl.signal,
|
|
205
|
+
stream: serviceRunCallbacks(runId),
|
|
192
206
|
});
|
|
193
207
|
}
|
|
194
208
|
catch (e) {
|
|
@@ -243,5 +257,6 @@ export async function executeTriageRun(service, deps) {
|
|
|
243
257
|
finally {
|
|
244
258
|
clearTimeout(timer);
|
|
245
259
|
runningTasks.delete(service.id);
|
|
260
|
+
endServiceRun(service.id, runId);
|
|
246
261
|
}
|
|
247
262
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email_triage_agent.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/email_triage_agent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAoB,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG7F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIvD;qEACqE;AACrE,wBAAsB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAK7F;AAED,wBAAsB,cAAc,CAClC,CAAC,EAAE,gBAAgB,GAClB,OAAO,CAAC;IAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"email_triage_agent.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/email_triage_agent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAoB,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG7F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAIvD;qEACqE;AACrE,wBAAsB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAK7F;AAED,wBAAsB,cAAc,CAClC,CAAC,EAAE,gBAAgB,GAClB,OAAO,CAAC;IAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAA;CAAE,CAAC,CA4ChF;AAED,eAAO,MAAM,cAAc,EAAE,UAW5B,CAAC;AAIF,eAAO,MAAM,mBAAmB,EAAE,iBAWjC,CAAC"}
|
|
@@ -11,6 +11,6 @@ export declare function matchesCron(cronStr: string, date: Date): boolean;
|
|
|
11
11
|
* Runs completely in background, automatically approving tool runs.
|
|
12
12
|
* Guards against concurrent execution: if the task is already running, skips.
|
|
13
13
|
*/
|
|
14
|
-
export declare function executeTaskRun(task: ServiceConfig): Promise<void>;
|
|
14
|
+
export declare function executeTaskRun(task: ServiceConfig, runId?: string): Promise<void>;
|
|
15
15
|
export declare const HeartbeatStrategy: SchedulerStrategy;
|
|
16
16
|
//# sourceMappingURL=heartbeat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/heartbeat.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CA2DhE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,GAAE,MAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkHnG;AAID,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { loadAgents, loadConfig } from '../../../store/json.js';
|
|
|
4
4
|
import { userMessage } from '../../../session/store.js';
|
|
5
5
|
import { saveTaskRun } from './logs.js';
|
|
6
6
|
import { runningTasks } from './locks.js';
|
|
7
|
+
import { beginServiceRun, endServiceRun, newRunId, serviceRunCallbacks } from './service_runs.js';
|
|
7
8
|
/**
|
|
8
9
|
* Parses and evaluates a cron expression string against a given Date.
|
|
9
10
|
* Supports standard syntax fields: minute, hour, day of month, month, day of week.
|
|
@@ -66,13 +67,17 @@ export function matchesCron(cronStr, date) {
|
|
|
66
67
|
* Runs completely in background, automatically approving tool runs.
|
|
67
68
|
* Guards against concurrent execution: if the task is already running, skips.
|
|
68
69
|
*/
|
|
69
|
-
export async function executeTaskRun(task) {
|
|
70
|
+
export async function executeTaskRun(task, runId = newRunId()) {
|
|
70
71
|
if (runningTasks.has(task.id)) {
|
|
71
72
|
console.log(`[scheduler] Task "${task.name}" is already running — skipping.`);
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
runningTasks.add(task.id);
|
|
75
|
-
const
|
|
76
|
+
const unattendedNotice = `[UNATTENDED RUN] Note: You are running as an unattended scheduled task. No human is supervising this execution. Act autonomously and complete the task to the best of your ability.`;
|
|
77
|
+
const effectivePrompt = `${unattendedNotice}\n\n${task.prompt}`;
|
|
78
|
+
const startMsg = userMessage(effectivePrompt);
|
|
79
|
+
// Same synchronous block as the lock: the live stream exists as soon as the run does.
|
|
80
|
+
beginServiceRun(task.id, runId, startMsg);
|
|
76
81
|
console.log(`[scheduler] Starting execution run ${runId} for task: "${task.name}"`);
|
|
77
82
|
const runMessages = [];
|
|
78
83
|
try {
|
|
@@ -87,10 +92,7 @@ export async function executeTaskRun(task) {
|
|
|
87
92
|
}
|
|
88
93
|
const tools = await harness.resolveAgentTools(agent, harness.tools);
|
|
89
94
|
const workingDir = task.workingDir || agent.workingDir || process.cwd();
|
|
90
|
-
const unattendedNotice = `[UNATTENDED RUN] Note: You are running as an unattended scheduled task. No human is supervising this execution. Act autonomously and complete the task to the best of your ability.`;
|
|
91
|
-
const effectivePrompt = `${unattendedNotice}\n\n${task.prompt}`;
|
|
92
95
|
// Track the initial user prompt inside run history
|
|
93
|
-
const startMsg = userMessage(effectivePrompt);
|
|
94
96
|
runMessages.push(startMsg);
|
|
95
97
|
// Invoke headless loop run
|
|
96
98
|
await harness.run({
|
|
@@ -101,6 +103,7 @@ export async function executeTaskRun(task) {
|
|
|
101
103
|
history: [],
|
|
102
104
|
workingDir,
|
|
103
105
|
}, {
|
|
106
|
+
...serviceRunCallbacks(runId),
|
|
104
107
|
onMessage: async (msg) => {
|
|
105
108
|
runMessages.push(msg);
|
|
106
109
|
},
|
|
@@ -161,6 +164,7 @@ export async function executeTaskRun(task) {
|
|
|
161
164
|
finally {
|
|
162
165
|
// Always release the lock so future ticks can re-schedule this task
|
|
163
166
|
runningTasks.delete(task.id);
|
|
167
|
+
endServiceRun(task.id, runId);
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
const lastCheckedMinutes = new Map();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RunCallbacks } from '../../../harness/loop.js';
|
|
2
|
+
import type { MessageRecord } from '../../../session/types.js';
|
|
3
|
+
export declare function newRunId(): string;
|
|
4
|
+
/** Must be called in the same synchronous block that takes the service's
|
|
5
|
+
* `runningTasks` lock, so the two can never disagree. */
|
|
6
|
+
export declare function beginServiceRun(serviceId: string, runId: string, prompt: MessageRecord | null): void;
|
|
7
|
+
/** Call only after the run's log is persisted: a watcher reloads the run list on `done`. */
|
|
8
|
+
export declare function endServiceRun(serviceId: string, runId: string): void;
|
|
9
|
+
export declare function activeServiceRun(serviceId: string): string | undefined;
|
|
10
|
+
export declare function emitServiceRunEvent(runId: string, text: string, type: 'user' | 'chunk'): void;
|
|
11
|
+
export declare function serviceRunCallbacks(runId: string): Pick<RunCallbacks, 'onChunk' | 'onThinking' | 'onToolCall' | 'onToolResult'>;
|
|
12
|
+
//# sourceMappingURL=service_runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service_runs.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/service_runs.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D,wBAAgB,QAAQ,IAAI,MAAM,CAEjC;AAED;0DAC0D;AAC1D,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAGpG;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAGpE;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEtE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAE7F;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,cAAc,CAAC,CAO9E"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Live channel for service runs (heartbeat, email triage): the run in flight per
|
|
2
|
+
// service, streamed through the task-cycle buffer keyed by run id, so the log
|
|
3
|
+
// viewer can follow a run whether it was started by its cron or by hand.
|
|
4
|
+
//
|
|
5
|
+
// Harness-free on purpose: email_triage.ts imports it and must stay testable
|
|
6
|
+
// with plain fakes.
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { beginCycleStream, emitCycleEvent } from './cycle_events.js';
|
|
9
|
+
/** serviceId → runId of the run in flight. */
|
|
10
|
+
const active = new Map();
|
|
11
|
+
export function newRunId() {
|
|
12
|
+
return `run_${randomUUID().slice(0, 8)}`;
|
|
13
|
+
}
|
|
14
|
+
/** Must be called in the same synchronous block that takes the service's
|
|
15
|
+
* `runningTasks` lock, so the two can never disagree. */
|
|
16
|
+
export function beginServiceRun(serviceId, runId, prompt) {
|
|
17
|
+
active.set(serviceId, runId);
|
|
18
|
+
beginCycleStream(runId, prompt);
|
|
19
|
+
}
|
|
20
|
+
/** Call only after the run's log is persisted: a watcher reloads the run list on `done`. */
|
|
21
|
+
export function endServiceRun(serviceId, runId) {
|
|
22
|
+
if (active.get(serviceId) === runId)
|
|
23
|
+
active.delete(serviceId);
|
|
24
|
+
emitCycleEvent(runId, { type: 'done' });
|
|
25
|
+
}
|
|
26
|
+
export function activeServiceRun(serviceId) {
|
|
27
|
+
return active.get(serviceId);
|
|
28
|
+
}
|
|
29
|
+
export function emitServiceRunEvent(runId, text, type) {
|
|
30
|
+
emitCycleEvent(runId, { type, text });
|
|
31
|
+
}
|
|
32
|
+
export function serviceRunCallbacks(runId) {
|
|
33
|
+
return {
|
|
34
|
+
onChunk: (text) => emitCycleEvent(runId, { type: 'chunk', text }),
|
|
35
|
+
onThinking: (text) => emitCycleEvent(runId, { type: 'thinking', text }),
|
|
36
|
+
onToolCall: (id, name, args) => emitCycleEvent(runId, { type: 'tool_call', id, name, args }),
|
|
37
|
+
onToolResult: (id, content) => emitCycleEvent(runId, { type: 'tool_result', id, content }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -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,
|
|
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
|
-
|
|
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
|
|
621
|
-
|
|
622
|
-
|
|
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}
|
|
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
|
-
|
|
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) {
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import type { ServiceConfig } from '../../types.js';
|
|
1
2
|
export { schedulerLogsDir, schedulerLogPath, ensureSchedulerLogsDir, loadTaskRuns, saveTaskRun, } from './scheduler/logs.js';
|
|
2
3
|
export { runningTasks } from './scheduler/locks.js';
|
|
3
4
|
/**
|
|
4
5
|
* Evaluates all scheduled tasks and triggers execution loops for matching ones.
|
|
5
6
|
*/
|
|
6
7
|
export declare function runSchedulerTick(): Promise<void>;
|
|
8
|
+
/** Service types a user can run by hand: the cron-driven ones. */
|
|
9
|
+
export declare function isRunnableService(service: ServiceConfig): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Starts a run of a cron-driven service now, regardless of its schedule or
|
|
12
|
+
* enabled flag, and returns its run id. A run already in flight is not
|
|
13
|
+
* duplicated: its id is returned instead, so the caller can follow it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runServiceNow(service: ServiceConfig): string;
|
|
7
16
|
/**
|
|
8
17
|
* Starts the in-process background scheduler loop.
|
|
9
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAUpD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BtD;AAGD,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAU5D;AAID;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAQ/C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAM9C"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { loadConfig } from '../../store/json.js';
|
|
2
|
-
import { HeartbeatStrategy } from './scheduler/heartbeat.js';
|
|
2
|
+
import { HeartbeatStrategy, executeTaskRun } from './scheduler/heartbeat.js';
|
|
3
3
|
import { TelegramStrategy } from './scheduler/telegram.js';
|
|
4
|
-
import { EmailTriageStrategy } from './scheduler/email_triage_agent.js';
|
|
4
|
+
import { EmailTriageStrategy, realTriageDeps } from './scheduler/email_triage_agent.js';
|
|
5
|
+
import { executeTriageRun } from './scheduler/email_triage.js';
|
|
6
|
+
import { activeServiceRun, newRunId } from './scheduler/service_runs.js';
|
|
5
7
|
import { runTaskHeartbeatTick } from './scheduler/task_strategy.js';
|
|
6
8
|
import { runMemorySweepTick } from './scheduler/memory_sweep.js';
|
|
7
9
|
// Re-exported for backwards compatibility with existing consumers (server.ts, tests).
|
|
@@ -42,6 +44,26 @@ export async function runSchedulerTick() {
|
|
|
42
44
|
console.error('[scheduler] Error evaluating scheduler tasks tick:', err);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
47
|
+
/** Service types a user can run by hand: the cron-driven ones. */
|
|
48
|
+
export function isRunnableService(service) {
|
|
49
|
+
return service.type === 'heartbeat' || service.type === 'email_triage';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Starts a run of a cron-driven service now, regardless of its schedule or
|
|
53
|
+
* enabled flag, and returns its run id. A run already in flight is not
|
|
54
|
+
* duplicated: its id is returned instead, so the caller can follow it.
|
|
55
|
+
*/
|
|
56
|
+
export function runServiceNow(service) {
|
|
57
|
+
const inFlight = activeServiceRun(service.id);
|
|
58
|
+
if (inFlight)
|
|
59
|
+
return inFlight;
|
|
60
|
+
const runId = newRunId();
|
|
61
|
+
const run = service.type === 'email_triage'
|
|
62
|
+
? executeTriageRun(service, realTriageDeps, runId)
|
|
63
|
+
: executeTaskRun(service, runId);
|
|
64
|
+
void run.catch((err) => console.error(`[scheduler] Manual run of "${service.name}" failed:`, err));
|
|
65
|
+
return runId;
|
|
66
|
+
}
|
|
45
67
|
let schedulerIntervalRef = null;
|
|
46
68
|
/**
|
|
47
69
|
* Starts the in-process background scheduler loop.
|
package/dist/cli/web/server.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA8ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAe,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAuC9F,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9D,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IACtF,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,qBAAa,oBAAoB;IAQ7B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAPvB,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2B;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAGjB,IAAI,EAAE;QACrB,KAAK,EAAE,WAAW,CAAC;QACnB,QAAQ,EAAE,cAAc,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAMH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,eAAe,IAAI,GAAG;IAIhB,KAAK,CACT,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAsFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GACzC,OAAO,CAAC,IAAI,CAAC,CAywCf"}
|
package/dist/cli/web/server.js
CHANGED
|
@@ -2,13 +2,14 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import { watch, existsSync, mkdirSync } from 'node:fs';
|
|
5
|
-
import { randomUUID } from 'node:crypto';
|
|
6
5
|
import { Hono } from 'hono';
|
|
6
|
+
import { applyApiListener, registerApiAccess } from './api_access.js';
|
|
7
|
+
import { registerOpenApi } from './openapi.js';
|
|
7
8
|
import { stream } from 'hono/streaming';
|
|
8
9
|
import { serve } from '@hono/node-server';
|
|
9
10
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
10
11
|
import * as harness from '../../harness/index.js';
|
|
11
|
-
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, deleteTaskSessions, runQuery, tryNormalizeChecklistStatus } from '../../store/db.js';
|
|
12
|
+
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, deleteTaskSessions, runQuery, tryNormalizeChecklistStatus, buildChecklist } from '../../store/db.js';
|
|
12
13
|
import { discardWorktree, syncProjectRepo, projectRepoStatus, managedRepoDir } from '../../lib/task_git.js';
|
|
13
14
|
import { removeContainer } from '../../lib/docker.js';
|
|
14
15
|
import { validateRepositoryUrl } from '../../lib/repo_url.js';
|
|
@@ -23,7 +24,8 @@ import { listForAgent, readSession, deleteSession, computeContextUsage, createSe
|
|
|
23
24
|
import { sessionRunScope } from './session_scope.js';
|
|
24
25
|
import { guardTurnCallbacks } from './turn_guard.js';
|
|
25
26
|
import { watchCycleStream } from './scheduler/cycle_events.js';
|
|
26
|
-
import { startBackgroundScheduler, loadTaskRuns } from './scheduler.js';
|
|
27
|
+
import { startBackgroundScheduler, loadTaskRuns, isRunnableService, runServiceNow } from './scheduler.js';
|
|
28
|
+
import { activeServiceRun } from './scheduler/service_runs.js';
|
|
27
29
|
import { fsRouter } from './fs.js';
|
|
28
30
|
import { activationStatus, resolvePlanningEnabled } from './scheduler/task_roles.js';
|
|
29
31
|
import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog, formKeyFor, KEY_WITHHELD_HINT, } from './voice_proxy.js';
|
|
@@ -153,8 +155,12 @@ export class WebSessionController {
|
|
|
153
155
|
this.inflight?.abort();
|
|
154
156
|
}
|
|
155
157
|
}
|
|
156
|
-
export async function startServer(port, host) {
|
|
158
|
+
export async function startServer(port, host, api = {}) {
|
|
157
159
|
const app = new Hono();
|
|
160
|
+
// Token-authenticated listener for clients outside the browser (api_access.ts).
|
|
161
|
+
const apiListener = { webPort: port, host: api.host ?? host, portOverride: api.port };
|
|
162
|
+
registerApiAccess(app, apiListener);
|
|
163
|
+
registerOpenApi(app);
|
|
158
164
|
app.route('/api/fs', fsRouter);
|
|
159
165
|
registerTaskBridge(app);
|
|
160
166
|
registerVoiceProxy(app);
|
|
@@ -423,23 +429,21 @@ export async function startServer(port, host) {
|
|
|
423
429
|
}
|
|
424
430
|
}
|
|
425
431
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
order: idx,
|
|
431
|
-
}));
|
|
432
|
+
// Items may arrive already ticked; one without a status starts pending.
|
|
433
|
+
const built = buildChecklist(checklist ?? [], 'pending');
|
|
434
|
+
if ('error' in built)
|
|
435
|
+
return c.json({ ok: false, error: built.error }, 400);
|
|
432
436
|
const config = await loadConfig();
|
|
433
437
|
const project = (config.projects || []).find((p) => p.id === projectId);
|
|
434
438
|
const taskPlanning = typeof planningEnabled === 'boolean' ? planningEnabled : null;
|
|
435
439
|
const startStatus = startActive
|
|
436
440
|
? (resolvePlanningEnabled({ planningEnabled: taskPlanning }, project) ? 'planning' : 'active')
|
|
437
441
|
: 'draft';
|
|
438
|
-
await createTask({
|
|
442
|
+
const task = await createTask({
|
|
439
443
|
projectId,
|
|
440
444
|
title,
|
|
441
445
|
objective,
|
|
442
|
-
checklist:
|
|
446
|
+
checklist: built.checklist,
|
|
443
447
|
status: startStatus,
|
|
444
448
|
blockedReason: null,
|
|
445
449
|
noProgressCount: 0,
|
|
@@ -453,7 +457,7 @@ export async function startServer(port, host) {
|
|
|
453
457
|
sddEnabled: typeof sddEnabled === 'boolean' ? sddEnabled : null,
|
|
454
458
|
maxRunSeconds: typeof maxRunSeconds === 'number' && maxRunSeconds > 0 ? maxRunSeconds : null,
|
|
455
459
|
});
|
|
456
|
-
return c.json({ ok: true });
|
|
460
|
+
return c.json({ ok: true, task });
|
|
457
461
|
});
|
|
458
462
|
app.get('/api/tasks/:id/messages', async (c) => {
|
|
459
463
|
const taskId = c.req.param('id');
|
|
@@ -648,6 +652,22 @@ export async function startServer(port, host) {
|
|
|
648
652
|
}
|
|
649
653
|
return c.json({ ok: true });
|
|
650
654
|
});
|
|
655
|
+
// Replace the whole checklist — same semantics as mcp__task__task_update_checklist:
|
|
656
|
+
// items with an id keep it, the others get a new one, order follows the array.
|
|
657
|
+
app.put('/api/tasks/:id/checklist', async (c) => {
|
|
658
|
+
const taskId = c.req.param('id');
|
|
659
|
+
const body = await c.req.json().catch(() => null);
|
|
660
|
+
const built = buildChecklist(body?.checklist);
|
|
661
|
+
if ('error' in built)
|
|
662
|
+
return c.json({ ok: false, error: built.error }, 400);
|
|
663
|
+
const task = await getTaskById(taskId);
|
|
664
|
+
if (!task)
|
|
665
|
+
return c.json({ ok: false, error: `Task ${taskId} not found` }, 404);
|
|
666
|
+
task.checklist = built.checklist;
|
|
667
|
+
task.updatedAt = new Date().toISOString();
|
|
668
|
+
await saveTask(task);
|
|
669
|
+
return c.json({ ok: true, checklist: task.checklist });
|
|
670
|
+
});
|
|
651
671
|
app.patch('/api/tasks/:id/agent', async (c) => {
|
|
652
672
|
const taskId = c.req.param('id');
|
|
653
673
|
const body = await c.req.json();
|
|
@@ -765,6 +785,8 @@ export async function startServer(port, host) {
|
|
|
765
785
|
port,
|
|
766
786
|
hostname: host,
|
|
767
787
|
});
|
|
788
|
+
// Fire-and-forget: a busy API port is reported in the settings, never fatal.
|
|
789
|
+
void applyApiListener(app, apiListener);
|
|
768
790
|
const bridgeHost = host === '0.0.0.0' || host === '::' ? '127.0.0.1' : host;
|
|
769
791
|
setTaskBridgeUrl(`http://${bridgeHost}:${port}/api/mcp/task`);
|
|
770
792
|
const wss = new WebSocketServer({ noServer: true });
|
|
@@ -1336,10 +1358,42 @@ export async function startServer(port, host) {
|
|
|
1336
1358
|
if (/^[A-Za-z0-9_-]+$/.test(msg.sessionId))
|
|
1337
1359
|
unwatchCycle(msg.sessionId);
|
|
1338
1360
|
return;
|
|
1361
|
+
case 'runService': {
|
|
1362
|
+
const service = (await loadConfig()).scheduler?.tasks?.find((t) => t.id === msg.serviceId);
|
|
1363
|
+
if (!service || !isRunnableService(service)) {
|
|
1364
|
+
post({ type: 'error', message: `Service "${msg.serviceId}" cannot be run manually` });
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
post({ type: 'serviceRunActive', serviceId: service.id, runId: runServiceNow(service) });
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
case 'watchServiceRun': {
|
|
1371
|
+
// A service run lives only in memory while running; its log is on disk after.
|
|
1372
|
+
const { runId } = msg;
|
|
1373
|
+
unwatchCycle(runId);
|
|
1374
|
+
const live = watchCycleStream(runId, (event) => post({ type: 'cycleEvent', sessionId: runId, event }));
|
|
1375
|
+
if (!live) {
|
|
1376
|
+
post({ type: 'cycleEvent', sessionId: runId, event: { type: 'done' } });
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
cycleWatchers.set(runId, live.unwatch);
|
|
1380
|
+
post({
|
|
1381
|
+
type: 'cycleLoaded',
|
|
1382
|
+
sessionId: runId,
|
|
1383
|
+
messages: live.prompt ? [toChatMessage(live.prompt)] : [],
|
|
1384
|
+
running: true,
|
|
1385
|
+
});
|
|
1386
|
+
for (const event of live.events)
|
|
1387
|
+
post({ type: 'cycleEvent', sessionId: runId, event });
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1339
1390
|
case 'getTaskRuns':
|
|
1340
1391
|
try {
|
|
1341
1392
|
const runs = await loadTaskRuns(msg.taskId);
|
|
1342
1393
|
post({ type: 'taskRunsLoaded', taskId: msg.taskId, runs });
|
|
1394
|
+
const runId = activeServiceRun(msg.taskId);
|
|
1395
|
+
if (runId)
|
|
1396
|
+
post({ type: 'serviceRunActive', serviceId: msg.taskId, runId });
|
|
1343
1397
|
}
|
|
1344
1398
|
catch (err) {
|
|
1345
1399
|
console.error('[web] failed to load task runs:', err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/task_tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAepD,eAAO,MAAM,gBAAgB,EAAE,IAmD9B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IAqCrC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"task_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/task_tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAepD,eAAO,MAAM,gBAAgB,EAAE,IAmD9B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IAqCrC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,IAuCjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,IAmEnC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAoC3B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IA2C3B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IA4B7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAgG5B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IA+B5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAoC9B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IA+CrC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAkC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,IA8B/B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IA0D5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAuC5B,CAAC"}
|