@hyperwindmill/caretaker-cli 0.25.1 → 0.26.1
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 +47 -54
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +75 -11
- 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 +10 -4
- 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/webview/standalone.css +80 -25
- package/dist/webview/standalone.css.map +2 -2
- package/dist/webview/standalone.js +983 -850
- 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,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO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AAC,QAAQ,EAAE,aAAa,EAAE,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAGrF;AAED;;yDAEyD;AACzD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,aAAa,EAAE,GACxB,KAAK,CAAC;IAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAoBpD;AAED;;mDAEmD;AACnD,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;AAEpF;;;;;;sDAMsD;AACtD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,oBAAoB,GAAG,WAAW,CA8B1E;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;8EAE8E;AAC9E,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,oBAAoB,EAC9B,SAAS,EAAE,WAAW,GACrB,OAAO,CAAC,WAAW,CAAC,CA4JtB;AAMD;6EAC6E;AAC7E,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,IAAI,EACT,iBAAiB,CAAC,EAAE,WAAW,GAC9B,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED,eAAO,MAAM,oBAAoB;aACtB,IAAI;CAKd,CAAC"}
|
|
@@ -195,13 +195,18 @@ export async function sweepMemory(resolved, summarize) {
|
|
|
195
195
|
scannedAt: '',
|
|
196
196
|
updatedAt: '',
|
|
197
197
|
};
|
|
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,KAAK,IAAI,EACT,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAK9B,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AAE7D,4EAA4E;AAC5E,eAAO,MAAM,aAAa,qCAAsC,CAAC;AAEjE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAExE;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE;IACrC,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,GAAG,YAAY,CAQf;AAED;mEACmE;AACnE,wBAAgB,UAAU,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAcrF;AAOD,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,cAAc,GAAG,WAAW,CAAC,CAAC;IACtG,KAAK,CAAC,CAAC,EAAE;QAAE,OAAO,EAAE,YAAY,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAED,wBAAsB,SAAS,CAAC,CAAC,EAAE;IACjC,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,aAAa,CAAC,CA6FzB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Task cycle recorder: every autonomous cycle (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":"AA8HA,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';
|
|
@@ -41,12 +42,15 @@ On each invocation:
|
|
|
41
42
|
- which tools you used and what the results were
|
|
42
43
|
- what the recommended next step is
|
|
43
44
|
- any issues encountered or decisions made
|
|
44
|
-
7.
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
7. End the invocation with exactly ONE of these, in this order of checks:
|
|
46
|
+
- **The objective is met and every checklist item is done → call \`task_complete\`.**
|
|
47
|
+
Never \`task_yield\` a finished task: a yielded task stays active and runs again.
|
|
48
|
+
- You need human input to proceed → call \`task_block\` with a clear explanation.
|
|
49
|
+
- Work remains → call \`task_yield\` with a short note on the next step (or simply stop);
|
|
50
|
+
you will continue in the next cycle.
|
|
47
51
|
|
|
48
|
-
Do
|
|
49
|
-
|
|
52
|
+
Do ONE meaningful step per invocation, then document and end it as above.
|
|
53
|
+
If that step finishes the objective, complete the task now — do not leave it for another cycle.
|
|
50
54
|
|
|
51
55
|
TASK ID: ${taskId}
|
|
52
56
|
TITLE: ${taskTitle}`;
|
|
@@ -111,7 +115,6 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
111
115
|
task.lockedAt = new Date().toISOString();
|
|
112
116
|
task.updatedAt = new Date().toISOString();
|
|
113
117
|
await saveTask(task);
|
|
114
|
-
let liveMsgId = null;
|
|
115
118
|
try {
|
|
116
119
|
// 2. Load Config & Project
|
|
117
120
|
const config = await loadConfig();
|
|
@@ -322,35 +325,11 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
322
325
|
effectivePrompt = `${prompt}${env}`;
|
|
323
326
|
}
|
|
324
327
|
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
|
|
328
|
+
// Load full history for replay: handoffs only, never cycle transcripts.
|
|
349
329
|
const historyMessages = (await runQuery(`SELECT * FROM task_messages WHERE taskId = '${task.id}'`));
|
|
350
330
|
historyMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
351
331
|
// 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')
|
|
332
|
+
const historyRecords = filterHandoffMessages(historyMessages)
|
|
354
333
|
.map((m) => ({
|
|
355
334
|
id: randomUUID(),
|
|
356
335
|
v: 1,
|
|
@@ -415,6 +394,20 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
415
394
|
console.warn('[tasks] acp agent without task bridge URL — task tools unavailable this run');
|
|
416
395
|
}
|
|
417
396
|
}
|
|
397
|
+
// The cycle is a chat session of its own; the task gets a `cycle` timeline
|
|
398
|
+
// message pointing at it. Capture the role-resolved agent behind this cycle,
|
|
399
|
+
// so the thread shows who actually ran (planner during planning, developer
|
|
400
|
+
// during active) — as text of the moment, not resolved live in the UI.
|
|
401
|
+
// Opened right before the try: the finally below must always close it.
|
|
402
|
+
const cycleRole = planning ? 'planner' : 'developer';
|
|
403
|
+
const cycle = await openCycle({
|
|
404
|
+
task,
|
|
405
|
+
agent,
|
|
406
|
+
role: cycleRole,
|
|
407
|
+
agentLabel: `${agent.name} · ${agent.model}`,
|
|
408
|
+
prompt: effectivePrompt,
|
|
409
|
+
});
|
|
410
|
+
let runFailed = false;
|
|
418
411
|
try {
|
|
419
412
|
await harness.run({
|
|
420
413
|
agent: effectiveAgent,
|
|
@@ -431,31 +424,24 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
431
424
|
dockerContainer,
|
|
432
425
|
signal,
|
|
433
426
|
}, {
|
|
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
|
-
},
|
|
427
|
+
...cycle.callbacks,
|
|
447
428
|
confirmTool: async () => 'once', // Autonomous execution auto-approves tools
|
|
448
429
|
});
|
|
449
430
|
}
|
|
431
|
+
catch (runErr) {
|
|
432
|
+
// A Pause or wall-clock abort is an outcome, not a failure.
|
|
433
|
+
if (!signal.aborted)
|
|
434
|
+
runFailed = true;
|
|
435
|
+
throw runErr;
|
|
436
|
+
}
|
|
450
437
|
finally {
|
|
451
438
|
if (bridgeToken)
|
|
452
439
|
revokeBridgeToken(bridgeToken);
|
|
453
440
|
clearTimeout(runTimer);
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
liveMsgId = null;
|
|
441
|
+
const statusAfter = (await getTaskById(task.id))?.status ?? null;
|
|
442
|
+
await cycle.close({
|
|
443
|
+
outcome: resolveCycleOutcome({ role: cycleRole, statusAfter, aborted: signal.aborted, failed: runFailed }),
|
|
444
|
+
});
|
|
459
445
|
}
|
|
460
446
|
// 6. Reload task to evaluate checklist progress
|
|
461
447
|
const refreshedTask = await getTaskById(task.id);
|
|
@@ -527,9 +513,6 @@ export async function runTaskHeartbeatTick(now) {
|
|
|
527
513
|
catch (err) {
|
|
528
514
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
529
515
|
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
516
|
await addTaskMessage({
|
|
534
517
|
taskId: task.id,
|
|
535
518
|
role: 'assistant',
|
|
@@ -612,6 +595,7 @@ async function runReviewCycle(opts) {
|
|
|
612
595
|
const round = priorReviews + 1;
|
|
613
596
|
let verdict = 'pass';
|
|
614
597
|
let reviewText = '';
|
|
598
|
+
let cycle;
|
|
615
599
|
try {
|
|
616
600
|
const review = await runDoneReview({
|
|
617
601
|
agent,
|
|
@@ -626,19 +610,27 @@ async function runReviewCycle(opts) {
|
|
|
626
610
|
maxRunSeconds,
|
|
627
611
|
dockerContainer,
|
|
628
612
|
dockerHasGit,
|
|
613
|
+
openCycle: (prompt) => openCycle({ task, agent, role: 'reviewer', agentLabel: `${agent.name} · ${agent.model}`, prompt }),
|
|
629
614
|
});
|
|
630
615
|
verdict = review.verdict;
|
|
631
616
|
reviewText = review.text;
|
|
617
|
+
cycle = review.cycle;
|
|
632
618
|
}
|
|
633
619
|
catch (reviewErr) {
|
|
634
620
|
// A broken review must not trap the task in reviewing — finalize as pass.
|
|
635
621
|
console.error(`[task_heartbeat] Task #${task.id} review failed, finalizing:`, reviewErr);
|
|
636
622
|
verdict = 'pass';
|
|
637
623
|
}
|
|
624
|
+
// The review cycle's session closes once its verdict is written (the recap
|
|
625
|
+
// is the review text), or at once when a Pause lands mid-review.
|
|
626
|
+
const closeCycle = () => cycle?.close({
|
|
627
|
+
outcome: resolveCycleOutcome({ role: 'reviewer', verdict, statusAfter: null, aborted: signal?.aborted ?? false, failed: false }),
|
|
628
|
+
});
|
|
638
629
|
// Respect a Pause that arrived mid-review: only transition if still reviewing.
|
|
639
630
|
const current = await getTaskById(task.id);
|
|
640
631
|
if (!current || current.status !== 'reviewing') {
|
|
641
632
|
console.log(`[task_heartbeat] Task #${task.id} left reviewing mid-review (now ${current?.status}); skipping transition.`);
|
|
633
|
+
await closeCycle();
|
|
642
634
|
return;
|
|
643
635
|
}
|
|
644
636
|
if (reviewText) {
|
|
@@ -652,6 +644,7 @@ async function runReviewCycle(opts) {
|
|
|
652
644
|
agentLabel: `${agent.name} · ${agent.model}`,
|
|
653
645
|
});
|
|
654
646
|
}
|
|
647
|
+
await closeCycle();
|
|
655
648
|
console.log(`[task_heartbeat] Task #${task.id} review round ${round}: ${verdict}`);
|
|
656
649
|
if (verdict === 'changes' && round < MAX_REVIEW_ROUNDS) {
|
|
657
650
|
// 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,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