@hyperwindmill/caretaker-cli 0.25.0 → 0.26.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/web/scheduler/cycle_events.d.ts +32 -0
- package/dist/cli/web/scheduler/cycle_events.d.ts.map +1 -0
- package/dist/cli/web/scheduler/cycle_events.js +42 -0
- package/dist/cli/web/scheduler/memory_sweep.d.ts.map +1 -1
- package/dist/cli/web/scheduler/memory_sweep.js +11 -4
- package/dist/cli/web/scheduler/task_cycle.d.ts +33 -0
- package/dist/cli/web/scheduler/task_cycle.d.ts.map +1 -0
- package/dist/cli/web/scheduler/task_cycle.js +137 -0
- package/dist/cli/web/scheduler/task_review.d.ts +5 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +10 -1
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +39 -49
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +75 -11
- package/dist/harness/acp_pool.d.ts +1 -0
- package/dist/harness/acp_pool.d.ts.map +1 -1
- package/dist/harness/acp_pool.js +8 -2
- package/dist/harness/acp_runner.d.ts.map +1 -1
- package/dist/harness/acp_runner.js +39 -1
- package/dist/harness/memory_recall.d.ts.map +1 -1
- package/dist/harness/memory_recall.js +5 -0
- package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/task_tools.js +2 -1
- package/dist/session/store.d.ts +4 -0
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +6 -0
- package/dist/session/types.d.ts +8 -0
- package/dist/session/types.d.ts.map +1 -1
- package/dist/store/db.d.ts +13 -1
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +23 -0
- package/dist/store/json.d.ts +10 -0
- package/dist/store/json.d.ts.map +1 -1
- package/dist/store/json.js +9 -0
- package/dist/tui/providers.js +5 -5
- package/dist/webview/standalone.css +80 -25
- package/dist/webview/standalone.css.map +2 -2
- package/dist/webview/standalone.js +983 -855
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MessageRecord } from '../../../session/types.js';
|
|
2
|
+
export type CycleEvent = {
|
|
3
|
+
type: 'chunk';
|
|
4
|
+
text: string;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'thinking';
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'tool_call';
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
args: unknown;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'tool_result';
|
|
15
|
+
id: string;
|
|
16
|
+
content: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'done';
|
|
19
|
+
} | {
|
|
20
|
+
type: 'error';
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function beginCycleStream(sessionId: string, prompt: MessageRecord): void;
|
|
24
|
+
export declare function emitCycleEvent(sessionId: string, ev: CycleEvent): void;
|
|
25
|
+
/** Attach to a running cycle. Snapshot and attach happen synchronously, so no
|
|
26
|
+
* event can fall between them. `null` when the cycle is not running. */
|
|
27
|
+
export declare function watchCycleStream(sessionId: string, listener: (ev: CycleEvent) => void): {
|
|
28
|
+
prompt: MessageRecord;
|
|
29
|
+
events: CycleEvent[];
|
|
30
|
+
unwatch: () => void;
|
|
31
|
+
} | null;
|
|
32
|
+
//# sourceMappingURL=cycle_events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cycle_events.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/cycle_events.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,MAAM,UAAU,GAClB;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,CAE/E;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,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG,IAAI,CAW7E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// In-process live channel for running task cycles. The cycle recorder emits
|
|
2
|
+
// the chat's own stream events keyed by session id; WebSocket watchers attach
|
|
3
|
+
// to a running cycle and replay what has happened so far, then follow it.
|
|
4
|
+
// Finished cycles are dropped from the map — watchers then load from disk.
|
|
5
|
+
const running = new Map();
|
|
6
|
+
export function beginCycleStream(sessionId, prompt) {
|
|
7
|
+
running.set(sessionId, { prompt, events: [], listeners: new Set() });
|
|
8
|
+
}
|
|
9
|
+
export function emitCycleEvent(sessionId, ev) {
|
|
10
|
+
const cycle = running.get(sessionId);
|
|
11
|
+
if (!cycle)
|
|
12
|
+
return;
|
|
13
|
+
const last = cycle.events[cycle.events.length - 1];
|
|
14
|
+
if (ev.type === 'chunk' && last?.type === 'chunk') {
|
|
15
|
+
cycle.events[cycle.events.length - 1] = { type: 'chunk', text: last.text + ev.text };
|
|
16
|
+
}
|
|
17
|
+
else if (ev.type === 'thinking' && last?.type === 'thinking') {
|
|
18
|
+
cycle.events[cycle.events.length - 1] = { type: 'thinking', text: last.text + ev.text };
|
|
19
|
+
}
|
|
20
|
+
else if (ev.type !== 'done' && ev.type !== 'error') {
|
|
21
|
+
cycle.events.push(ev);
|
|
22
|
+
}
|
|
23
|
+
for (const listener of cycle.listeners)
|
|
24
|
+
listener(ev);
|
|
25
|
+
if (ev.type === 'done' || ev.type === 'error')
|
|
26
|
+
running.delete(sessionId);
|
|
27
|
+
}
|
|
28
|
+
/** Attach to a running cycle. Snapshot and attach happen synchronously, so no
|
|
29
|
+
* event can fall between them. `null` when the cycle is not running. */
|
|
30
|
+
export function watchCycleStream(sessionId, listener) {
|
|
31
|
+
const cycle = running.get(sessionId);
|
|
32
|
+
if (!cycle)
|
|
33
|
+
return null;
|
|
34
|
+
cycle.listeners.add(listener);
|
|
35
|
+
return {
|
|
36
|
+
prompt: cycle.prompt,
|
|
37
|
+
events: [...cycle.events],
|
|
38
|
+
unwatch: () => {
|
|
39
|
+
cycle.listeners.delete(listener);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory_sweep.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/memory_sweep.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAa/D,OAAO,EAML,KAAK,cAAc,EACnB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|
|
198
|
-
|
|
198
|
+
// Task cycle sessions: only the recap reaches the model (tool output and
|
|
199
|
+
// retries never do), and each recap is its own debounce unit.
|
|
200
|
+
const isTask = !!session.meta.taskId;
|
|
201
|
+
const messages = isTask ? session.messages.filter((m) => m.recap) : session.messages;
|
|
202
|
+
const threshold = isTask ? 1 : resolved.minNewMessages;
|
|
203
|
+
const idx = locateCursor(messages, record.lastMessageId);
|
|
199
204
|
if (record.lastMessageId && idx === -1) {
|
|
200
205
|
// Cursor lost (rewritten/truncated file): restart from message zero.
|
|
201
206
|
record = { ...record, lastMessageId: '', messageCount: 0, summary: '', model: '' };
|
|
202
207
|
}
|
|
203
|
-
const fresh =
|
|
204
|
-
if (fresh.length <
|
|
208
|
+
const fresh = messages.slice(idx + 1);
|
|
209
|
+
if (fresh.length < threshold) {
|
|
205
210
|
// Debounce: arm the mtime gate and wait for the next append.
|
|
206
211
|
await saveSessionDigest({ ...record, agentId, scannedAt });
|
|
207
212
|
continue;
|
|
@@ -209,7 +214,9 @@ export async function sweepMemory(resolved, summarize) {
|
|
|
209
214
|
// Scope + dedup context, once per session. `dedup` is mutated as new
|
|
210
215
|
// memories are saved so the NEXT chunk of this session sees them too;
|
|
211
216
|
// across sessions the fresh listMemories() covers it.
|
|
212
|
-
|
|
217
|
+
// Task sessions carry their project explicitly: a worktree or managed
|
|
218
|
+
// repo dir never prefix-matches the project's workingDir.
|
|
219
|
+
const projectId = session.meta.projectId || resolveProjectId(agentId, resolved.agents, resolved.projects);
|
|
213
220
|
const dedup = (await listMemories())
|
|
214
221
|
.filter((m) => m.projectId === '' || m.projectId === projectId)
|
|
215
222
|
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RunCallbacks } from '../../../harness/loop.js';
|
|
2
|
+
import type { AgentConfig } from '../../../types.js';
|
|
3
|
+
import { type CycleOutcome, type Task, type TaskMessage } from '../../../store/db.js';
|
|
4
|
+
export type CycleRole = 'developer' | 'planner' | 'reviewer';
|
|
5
|
+
/** Message types the agent sees as history: handoffs, never transcripts. */
|
|
6
|
+
export declare const HISTORY_TYPES: readonly ["chat", "review", "plan"];
|
|
7
|
+
export declare function filterHandoffMessages(msgs: TaskMessage[]): TaskMessage[];
|
|
8
|
+
export declare function resolveCycleOutcome(i: {
|
|
9
|
+
role: CycleRole;
|
|
10
|
+
statusAfter: Task['status'] | null;
|
|
11
|
+
aborted: boolean;
|
|
12
|
+
failed: boolean;
|
|
13
|
+
verdict?: 'pass' | 'changes';
|
|
14
|
+
}): CycleOutcome;
|
|
15
|
+
/** Handoff text produced during a cycle: agent notes, yields, blocks, plans
|
|
16
|
+
* and reviews, in order. `fallback` (when non-null) closes it. */
|
|
17
|
+
export declare function buildRecap(sinceCycle: TaskMessage[], fallback: string | null): string;
|
|
18
|
+
export interface CycleRecorder {
|
|
19
|
+
sessionId: string;
|
|
20
|
+
agentId: string;
|
|
21
|
+
callbacks: Pick<RunCallbacks, 'onChunk' | 'onThinking' | 'onToolCall' | 'onToolResult' | 'onMessage'>;
|
|
22
|
+
close(i: {
|
|
23
|
+
outcome: CycleOutcome;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare function openCycle(i: {
|
|
27
|
+
task: Task;
|
|
28
|
+
agent: AgentConfig;
|
|
29
|
+
role: CycleRole;
|
|
30
|
+
agentLabel: string;
|
|
31
|
+
prompt: string;
|
|
32
|
+
}): Promise<CycleRecorder>;
|
|
33
|
+
//# sourceMappingURL=task_cycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task_cycle.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_cycle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAIL,KAAK,YAAY,EACjB,KA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le (developer, planner, review) is a
|
|
2
|
+
// chat session under its agent, plus a `cycle` timeline message on the task
|
|
3
|
+
// that points at it. Persistence is caller-side via the run's `onMessage`
|
|
4
|
+
// records — the session is never passed to harness.run (claude-code --resume
|
|
5
|
+
// and ACP pooling would otherwise apply to every cycle).
|
|
6
|
+
import { addTaskMessage, runQuery, setCycleOutcome, } from '../../../store/db.js';
|
|
7
|
+
import { appendMessage, assistantMessage, createSession, userMessage } from '../../../session/store.js';
|
|
8
|
+
import { beginCycleStream, emitCycleEvent } from './cycle_events.js';
|
|
9
|
+
/** Message types the agent sees as history: handoffs, never transcripts. */
|
|
10
|
+
export const HISTORY_TYPES = ['chat', 'review', 'plan'];
|
|
11
|
+
export function filterHandoffMessages(msgs) {
|
|
12
|
+
return msgs.filter((m) => HISTORY_TYPES.includes(m.messageType));
|
|
13
|
+
}
|
|
14
|
+
export function resolveCycleOutcome(i) {
|
|
15
|
+
if (i.failed)
|
|
16
|
+
return 'failed';
|
|
17
|
+
if (i.aborted)
|
|
18
|
+
return 'aborted';
|
|
19
|
+
if (i.role === 'reviewer')
|
|
20
|
+
return i.verdict === 'changes' ? 'review-changes' : 'review-pass';
|
|
21
|
+
if (i.statusAfter === 'reviewing' || i.statusAfter === 'done')
|
|
22
|
+
return 'completed';
|
|
23
|
+
if (i.statusAfter === 'blocked')
|
|
24
|
+
return 'blocked';
|
|
25
|
+
if (i.role === 'planner' && i.statusAfter === 'active')
|
|
26
|
+
return 'plan';
|
|
27
|
+
return 'handoff';
|
|
28
|
+
}
|
|
29
|
+
/** Handoff text produced during a cycle: agent notes, yields, blocks, plans
|
|
30
|
+
* and reviews, in order. `fallback` (when non-null) closes it. */
|
|
31
|
+
export function buildRecap(sinceCycle, fallback) {
|
|
32
|
+
const parts = sinceCycle
|
|
33
|
+
.filter((m) => (m.messageType === 'chat' && m.role === 'assistant') ||
|
|
34
|
+
(m.messageType === 'system' && m.content.startsWith('Yield:')) ||
|
|
35
|
+
m.messageType === 'block' ||
|
|
36
|
+
m.messageType === 'plan' ||
|
|
37
|
+
m.messageType === 'review')
|
|
38
|
+
.map((m) => m.content)
|
|
39
|
+
.filter((c) => c.trim());
|
|
40
|
+
if (fallback !== null)
|
|
41
|
+
parts.push(fallback);
|
|
42
|
+
return parts.join('\n\n');
|
|
43
|
+
}
|
|
44
|
+
function fallbackNote(outcome, lastText) {
|
|
45
|
+
const last = lastText.trim() ? lastText.slice(0, 2000) : '(none)';
|
|
46
|
+
return `Cycle ended without a handoff note (${outcome}). Last output: ${last}`;
|
|
47
|
+
}
|
|
48
|
+
export async function openCycle(i) {
|
|
49
|
+
const { task, agent, role, agentLabel, prompt } = i;
|
|
50
|
+
const meta = await createSession({
|
|
51
|
+
agentId: agent.id,
|
|
52
|
+
title: `${task.id} · ${role}`,
|
|
53
|
+
taskId: task.id,
|
|
54
|
+
projectId: task.projectId,
|
|
55
|
+
taskRole: role,
|
|
56
|
+
});
|
|
57
|
+
// The live stream opens before the prompt is persisted, so a watcher that
|
|
58
|
+
// attaches right now already sees the prompt.
|
|
59
|
+
const promptMsg = userMessage(prompt);
|
|
60
|
+
beginCycleStream(meta.id, promptMsg);
|
|
61
|
+
let cycleMsg;
|
|
62
|
+
try {
|
|
63
|
+
await appendMessage(meta, promptMsg);
|
|
64
|
+
cycleMsg = await addTaskMessage({
|
|
65
|
+
taskId: task.id,
|
|
66
|
+
role: 'assistant',
|
|
67
|
+
messageType: 'cycle',
|
|
68
|
+
content: '',
|
|
69
|
+
sessionId: meta.id,
|
|
70
|
+
sessionAgentId: agent.id,
|
|
71
|
+
cycleRole: role,
|
|
72
|
+
cycleOutcome: 'running',
|
|
73
|
+
agentLabel,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
// Never leave a watcher waiting on a stream nobody will finish.
|
|
78
|
+
emitCycleEvent(meta.id, { type: 'error', message: 'Cycle could not start' });
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
let lastText = '';
|
|
82
|
+
// Text streamed since the last persisted assistant turn: an aborted turn never
|
|
83
|
+
// reaches onMessage, so this is the only trace of what the agent was doing.
|
|
84
|
+
let partialText = '';
|
|
85
|
+
// Messages written by this cycle, in order: everything after its `cycle` row.
|
|
86
|
+
const cycleSince = async () => {
|
|
87
|
+
const rows = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${task.id}'`));
|
|
88
|
+
return rows
|
|
89
|
+
.filter((m) => Number(m.id) > Number(cycleMsg.id))
|
|
90
|
+
.sort((a, b) => Number(a.id) - Number(b.id));
|
|
91
|
+
};
|
|
92
|
+
const close = async ({ outcome }) => {
|
|
93
|
+
try {
|
|
94
|
+
await setCycleOutcome(cycleMsg.id, outcome);
|
|
95
|
+
const since = await cycleSince();
|
|
96
|
+
let fallback = null;
|
|
97
|
+
// Developer and planner cycles must leave a handoff the next cycle replays:
|
|
98
|
+
// an agent note or a submitted plan. Without one (aborted, turn limit,
|
|
99
|
+
// forgot), the host writes the fallback.
|
|
100
|
+
const hasHandoff = since.some((m) => (m.messageType === 'chat' && m.role === 'assistant') || m.messageType === 'plan');
|
|
101
|
+
if (role !== 'reviewer' && !hasHandoff) {
|
|
102
|
+
fallback = fallbackNote(outcome, partialText.trim() ? partialText : lastText);
|
|
103
|
+
await addTaskMessage({ taskId: task.id, role: 'assistant', messageType: 'chat', content: fallback, agentLabel });
|
|
104
|
+
}
|
|
105
|
+
const recap = buildRecap(since, fallback);
|
|
106
|
+
if (recap) {
|
|
107
|
+
await appendMessage(meta, { ...assistantMessage([{ type: 'text', text: recap }]), recap: true });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
console.error(`[task_cycle] Task #${task.id} cycle ${meta.id} close failed:`, err);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
// Terminal event only after the recap is on disk: a watcher that loads
|
|
115
|
+
// from disk on `done` sees the complete session.
|
|
116
|
+
emitCycleEvent(meta.id, outcome === 'failed' ? { type: 'error', message: 'Cycle failed' } : { type: 'done' });
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const callbacks = {
|
|
120
|
+
onChunk: (text) => {
|
|
121
|
+
partialText += text;
|
|
122
|
+
emitCycleEvent(meta.id, { type: 'chunk', text });
|
|
123
|
+
},
|
|
124
|
+
onThinking: (text) => emitCycleEvent(meta.id, { type: 'thinking', text }),
|
|
125
|
+
onToolCall: (id, name, args) => emitCycleEvent(meta.id, { type: 'tool_call', id, name, args }),
|
|
126
|
+
onToolResult: (id, content) => emitCycleEvent(meta.id, { type: 'tool_result', id, content }),
|
|
127
|
+
onMessage: async (msg) => {
|
|
128
|
+
await appendMessage(meta, msg);
|
|
129
|
+
if (msg.role === 'assistant') {
|
|
130
|
+
if (msg.content)
|
|
131
|
+
lastText = msg.content;
|
|
132
|
+
partialText = '';
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
return { sessionId: meta.id, agentId: agent.id, callbacks, close };
|
|
137
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentConfig, ProviderConfig } from '../../../types.js';
|
|
2
2
|
import type { Tool } from '../../../harness/tools/types.js';
|
|
3
|
+
import { type CycleRecorder } from './task_cycle.js';
|
|
3
4
|
export declare const MAX_REVIEW_ROUNDS = 3;
|
|
4
5
|
export declare function reviewPrompt(objective: string, branch: string, round: number): string;
|
|
5
6
|
export declare function parseReviewVerdict(text: string): 'pass' | 'changes';
|
|
@@ -23,8 +24,12 @@ export declare function runDoneReview(opts: {
|
|
|
23
24
|
dockerContainer?: string;
|
|
24
25
|
/** Whether git is available inside the container; drives a prompt hint. */
|
|
25
26
|
dockerHasGit?: boolean;
|
|
27
|
+
/** Opens the review's chat session once the prompt is final. The caller
|
|
28
|
+
* closes the returned recorder; a throwing review closes it here. */
|
|
29
|
+
openCycle?: (prompt: string) => Promise<CycleRecorder>;
|
|
26
30
|
}): Promise<{
|
|
27
31
|
verdict: 'pass' | 'changes';
|
|
28
32
|
text: string;
|
|
33
|
+
cycle?: CycleRecorder;
|
|
29
34
|
}>;
|
|
30
35
|
//# sourceMappingURL=task_review.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"task_review.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_review.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAI5D,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA2BrF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMnE;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB;yEACqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;wDAEoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;0EACsE;IACtE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CACxD,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAAE,CAAC,CAsFhF"}
|
|
@@ -2,6 +2,7 @@ import * as harness from '../../../harness/index.js';
|
|
|
2
2
|
import { CLAUDE_CODE_DEFAULT_RUN_SECONDS } from './task_roles.js';
|
|
3
3
|
import { dockerDevAllowlist } from '../../../lib/docker.js';
|
|
4
4
|
import { getTaskBridgeUrl, issueBridgeToken, revokeBridgeToken } from '../mcp_bridge.js';
|
|
5
|
+
import { resolveCycleOutcome } from './task_cycle.js';
|
|
5
6
|
export const MAX_REVIEW_ROUNDS = 3;
|
|
6
7
|
export function reviewPrompt(objective, branch, round) {
|
|
7
8
|
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.
|
|
@@ -92,6 +93,7 @@ export async function runDoneReview(opts) {
|
|
|
92
93
|
prompt += ` Note: \`git\` is NOT available in this container — inspect the changes by reading the files directly instead of running git commands.`;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
96
|
+
const cycle = opts.openCycle ? await opts.openCycle(prompt) : undefined;
|
|
95
97
|
try {
|
|
96
98
|
const result = await harness.run({
|
|
97
99
|
agent: { ...opts.agent, permissionMode: 'bypassPermissions' }, // unattended: mirror the auto-approve confirm gate
|
|
@@ -106,9 +108,16 @@ export async function runDoneReview(opts) {
|
|
|
106
108
|
...(claudeCode ? { claudeCode } : {}),
|
|
107
109
|
...(acp ? { acp } : {}),
|
|
108
110
|
}, {
|
|
111
|
+
...cycle?.callbacks,
|
|
109
112
|
confirmTool: async () => 'once', // unattended
|
|
110
113
|
});
|
|
111
|
-
return { verdict: parseReviewVerdict(result.text), text: result.text };
|
|
114
|
+
return { verdict: parseReviewVerdict(result.text), text: result.text, cycle };
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
await cycle?.close({
|
|
118
|
+
outcome: resolveCycleOutcome({ role: 'reviewer', statusAfter: null, aborted: signal.aborted, failed: !signal.aborted }),
|
|
119
|
+
});
|
|
120
|
+
throw err;
|
|
112
121
|
}
|
|
113
122
|
finally {
|
|
114
123
|
clearTimeout(runTimer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"task_strategy.d.ts","sourceRoot":"","sources":["../../../../src/cli/web/scheduler/task_strategy.ts"],"names":[],"mappings":"AA2HA,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAidnE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import * as harness from '../../../harness/index.js';
|
|
3
3
|
import { loadAgents, loadConfig } from '../../../store/json.js';
|
|
4
|
-
import { getTaskById, saveTask, addTaskMessage,
|
|
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
7
|
import { runDoneReview, MAX_REVIEW_ROUNDS } from './task_review.js';
|
|
8
|
+
import { openCycle, filterHandoffMessages, resolveCycleOutcome } from './task_cycle.js';
|
|
8
9
|
import { claudeCodeTaskExtras } from '../../../harness/claude_code_runner.js';
|
|
9
10
|
import { acpTaskExtras } from '../../../harness/acp_policy.js';
|
|
10
11
|
import { issueBridgeToken, revokeBridgeToken, getTaskBridgeUrl } from '../mcp_bridge.js';
|
|
@@ -111,7 +112,6 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
111
112
|
task.lockedAt = new Date().toISOString();
|
|
112
113
|
task.updatedAt = new Date().toISOString();
|
|
113
114
|
await saveTask(task);
|
|
114
|
-
let liveMsgId = null;
|
|
115
115
|
try {
|
|
116
116
|
// 2. Load Config & Project
|
|
117
117
|
const config = await loadConfig();
|
|
@@ -322,35 +322,11 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
322
322
|
effectivePrompt = `${prompt}${env}`;
|
|
323
323
|
}
|
|
324
324
|
const checklistBefore = (task.checklist || []).filter((item) => item.status !== 'pending').length;
|
|
325
|
-
//
|
|
326
|
-
const liveMsg = await addTaskMessage({
|
|
327
|
-
taskId: task.id,
|
|
328
|
-
role: 'assistant',
|
|
329
|
-
messageType: 'heartbeat_live',
|
|
330
|
-
content: '',
|
|
331
|
-
// Capture the role-resolved agent behind this cycle, so the thread shows
|
|
332
|
-
// who actually ran (planner during planning, developer during active) —
|
|
333
|
-
// as text of the moment, not resolved live in the UI.
|
|
334
|
-
agentLabel: `${agent.name} · ${agent.model}`,
|
|
335
|
-
});
|
|
336
|
-
liveMsgId = liveMsg.id;
|
|
337
|
-
let buffer = '';
|
|
338
|
-
let lastWrite = 0;
|
|
339
|
-
const updateLiveContent = async (force = false) => {
|
|
340
|
-
if (liveMsgId === null)
|
|
341
|
-
return;
|
|
342
|
-
const nowMs = Date.now();
|
|
343
|
-
if (force || nowMs - lastWrite > 2500) {
|
|
344
|
-
lastWrite = nowMs;
|
|
345
|
-
await updateTaskMessageContent(liveMsgId, buffer);
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
// Load full history for replay
|
|
325
|
+
// Load full history for replay: handoffs only, never cycle transcripts.
|
|
349
326
|
const historyMessages = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${task.id}'`));
|
|
350
327
|
historyMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
351
328
|
// Map history to loop-compatible message records
|
|
352
|
-
const historyRecords = historyMessages
|
|
353
|
-
.filter((m) => m.messageType === 'chat' || m.messageType === 'heartbeat' || m.messageType === 'tool_call' || m.messageType === 'review' || m.messageType === 'plan')
|
|
329
|
+
const historyRecords = filterHandoffMessages(historyMessages)
|
|
354
330
|
.map((m) => ({
|
|
355
331
|
id: randomUUID(),
|
|
356
332
|
v: 1,
|
|
@@ -415,6 +391,20 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
415
391
|
console.warn('[tasks] acp agent without task bridge URL — task tools unavailable this run');
|
|
416
392
|
}
|
|
417
393
|
}
|
|
394
|
+
// The cycle is a chat session of its own; the task gets a `cycle` timeline
|
|
395
|
+
// message pointing at it. Capture the role-resolved agent behind this cycle,
|
|
396
|
+
// so the thread shows who actually ran (planner during planning, developer
|
|
397
|
+
// during active) — as text of the moment, not resolved live in the UI.
|
|
398
|
+
// Opened right before the try: the finally below must always close it.
|
|
399
|
+
const cycleRole = planning ? 'planner' : 'developer';
|
|
400
|
+
const cycle = await openCycle({
|
|
401
|
+
task,
|
|
402
|
+
agent,
|
|
403
|
+
role: cycleRole,
|
|
404
|
+
agentLabel: `${agent.name} · ${agent.model}`,
|
|
405
|
+
prompt: effectivePrompt,
|
|
406
|
+
});
|
|
407
|
+
let runFailed = false;
|
|
418
408
|
try {
|
|
419
409
|
await harness.run({
|
|
420
410
|
agent: effectiveAgent,
|
|
@@ -431,31 +421,24 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
431
421
|
dockerContainer,
|
|
432
422
|
signal,
|
|
433
423
|
}, {
|
|
434
|
-
|
|
435
|
-
buffer += chunk;
|
|
436
|
-
void updateLiveContent();
|
|
437
|
-
},
|
|
438
|
-
onToolCall: (id, name, args) => {
|
|
439
|
-
void addTaskMessage({
|
|
440
|
-
taskId: task.id,
|
|
441
|
-
role: 'assistant',
|
|
442
|
-
messageType: 'tool_call',
|
|
443
|
-
content: `${name} ${JSON.stringify(args)}`,
|
|
444
|
-
toolCallId: id,
|
|
445
|
-
});
|
|
446
|
-
},
|
|
424
|
+
...cycle.callbacks,
|
|
447
425
|
confirmTool: async () => 'once', // Autonomous execution auto-approves tools
|
|
448
426
|
});
|
|
449
427
|
}
|
|
428
|
+
catch (runErr) {
|
|
429
|
+
// A Pause or wall-clock abort is an outcome, not a failure.
|
|
430
|
+
if (!signal.aborted)
|
|
431
|
+
runFailed = true;
|
|
432
|
+
throw runErr;
|
|
433
|
+
}
|
|
450
434
|
finally {
|
|
451
435
|
if (bridgeToken)
|
|
452
436
|
revokeBridgeToken(bridgeToken);
|
|
453
437
|
clearTimeout(runTimer);
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
liveMsgId = null;
|
|
438
|
+
const statusAfter = (await getTaskById(task.id))?.status ?? null;
|
|
439
|
+
await cycle.close({
|
|
440
|
+
outcome: resolveCycleOutcome({ role: cycleRole, statusAfter, aborted: signal.aborted, failed: runFailed }),
|
|
441
|
+
});
|
|
459
442
|
}
|
|
460
443
|
// 6. Reload task to evaluate checklist progress
|
|
461
444
|
const refreshedTask = await getTaskById(task.id);
|
|
@@ -527,9 +510,6 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
527
510
|
catch (err) {
|
|
528
511
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
529
512
|
console.error(`[task_heartbeat] Task #${task.id} run failed:`, errorMsg);
|
|
530
|
-
if (liveMsgId !== null) {
|
|
531
|
-
await updateTaskMessageContent(liveMsgId, `⚠️ Heartbeat cycle failed: ${errorMsg}`, 'heartbeat');
|
|
532
|
-
}
|
|
533
513
|
await addTaskMessage({
|
|
534
514
|
taskId: task.id,
|
|
535
515
|
role: 'assistant',
|
|
@@ -612,6 +592,7 @@ async function runReviewCycle(opts) {
|
|
|
612
592
|
const round = priorReviews + 1;
|
|
613
593
|
let verdict = 'pass';
|
|
614
594
|
let reviewText = '';
|
|
595
|
+
let cycle;
|
|
615
596
|
try {
|
|
616
597
|
const review = await runDoneReview({
|
|
617
598
|
agent,
|
|
@@ -626,19 +607,27 @@ async function runReviewCycle(opts) {
|
|
|
626
607
|
maxRunSeconds,
|
|
627
608
|
dockerContainer,
|
|
628
609
|
dockerHasGit,
|
|
610
|
+
openCycle: (prompt) => openCycle({ task, agent, role: 'reviewer', agentLabel: `${agent.name} · ${agent.model}`, prompt }),
|
|
629
611
|
});
|
|
630
612
|
verdict = review.verdict;
|
|
631
613
|
reviewText = review.text;
|
|
614
|
+
cycle = review.cycle;
|
|
632
615
|
}
|
|
633
616
|
catch (reviewErr) {
|
|
634
617
|
// A broken review must not trap the task in reviewing — finalize as pass.
|
|
635
618
|
console.error(`[task_heartbeat] Task #${task.id} review failed, finalizing:`, reviewErr);
|
|
636
619
|
verdict = 'pass';
|
|
637
620
|
}
|
|
621
|
+
// The review cycle's session closes once its verdict is written (the recap
|
|
622
|
+
// is the review text), or at once when a Pause lands mid-review.
|
|
623
|
+
const closeCycle = () => cycle?.close({
|
|
624
|
+
outcome: resolveCycleOutcome({ role: 'reviewer', verdict, statusAfter: null, aborted: signal?.aborted ?? false, failed: false }),
|
|
625
|
+
});
|
|
638
626
|
// Respect a Pause that arrived mid-review: only transition if still reviewing.
|
|
639
627
|
const current = await getTaskById(task.id);
|
|
640
628
|
if (!current || current.status !== 'reviewing') {
|
|
641
629
|
console.log(`[task_heartbeat] Task #${task.id} left reviewing mid-review (now ${current?.status}); skipping transition.`);
|
|
630
|
+
await closeCycle();
|
|
642
631
|
return;
|
|
643
632
|
}
|
|
644
633
|
if (reviewText) {
|
|
@@ -652,6 +641,7 @@ async function runReviewCycle(opts) {
|
|
|
652
641
|
agentLabel: `${agent.name} · ${agent.model}`,
|
|
653
642
|
});
|
|
654
643
|
}
|
|
644
|
+
await closeCycle();
|
|
655
645
|
console.log(`[task_heartbeat] Task #${task.id} review round ${round}: ${verdict}`);
|
|
656
646
|
if (verdict === 'changes' && round < MAX_REVIEW_ROUNDS) {
|
|
657
647
|
// Reopen: keep the worktree; the review message is replayed to the agent next cycle.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA4ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAe,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AA+B9F,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,CAA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