@kenkaiiii/ggcoder 4.3.224 → 4.3.226
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/auth.d.ts +4 -0
- package/dist/cli/auth.d.ts.map +1 -0
- package/dist/cli/auth.js +344 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/pixel.d.ts +27 -0
- package/dist/cli/pixel.d.ts.map +1 -0
- package/dist/cli/pixel.js +103 -0
- package/dist/cli/pixel.js.map +1 -0
- package/dist/cli/shared.d.ts +13 -0
- package/dist/cli/shared.d.ts.map +1 -0
- package/dist/cli/shared.js +82 -0
- package/dist/cli/shared.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -537
- package/dist/cli.js.map +1 -1
- package/dist/core/runtime-mode.js +1 -1
- package/dist/core/runtime-mode.js.map +1 -1
- package/dist/system-prompt.js +2 -2
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +2 -1
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/plan-mode.test.js +13 -1
- package/dist/tools/plan-mode.test.js.map +1 -1
- package/dist/tools/read-only-bash.d.ts +13 -0
- package/dist/tools/read-only-bash.d.ts.map +1 -0
- package/dist/tools/read-only-bash.js +155 -0
- package/dist/tools/read-only-bash.js.map +1 -0
- package/dist/tools/read-only-bash.test.d.ts +2 -0
- package/dist/tools/read-only-bash.test.d.ts.map +1 -0
- package/dist/tools/read-only-bash.test.js +47 -0
- package/dist/tools/read-only-bash.test.js.map +1 -0
- package/dist/ui/App.d.ts.map +1 -1
- package/dist/ui/App.js +123 -1039
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/assistant-stream-flush-parity.test.d.ts +2 -0
- package/dist/ui/assistant-stream-flush-parity.test.d.ts.map +1 -0
- package/dist/ui/assistant-stream-flush-parity.test.js +85 -0
- package/dist/ui/assistant-stream-flush-parity.test.js.map +1 -0
- package/dist/ui/components/ChatLayout.d.ts +8 -1
- package/dist/ui/components/ChatLayout.d.ts.map +1 -1
- package/dist/ui/components/ChatLayout.js +4 -2
- package/dist/ui/components/ChatLayout.js.map +1 -1
- package/dist/ui/components/ChatLivePane.d.ts.map +1 -1
- package/dist/ui/components/ChatLivePane.js +15 -1
- package/dist/ui/components/ChatLivePane.js.map +1 -1
- package/dist/ui/components/InputArea.d.ts.map +1 -1
- package/dist/ui/components/InputArea.js +1 -3
- package/dist/ui/components/InputArea.js.map +1 -1
- package/dist/ui/components/SelectList.d.ts.map +1 -1
- package/dist/ui/components/SelectList.js +5 -0
- package/dist/ui/components/SelectList.js.map +1 -1
- package/dist/ui/components/SlashStyledSelectList.d.ts.map +1 -1
- package/dist/ui/components/SlashStyledSelectList.js +5 -0
- package/dist/ui/components/SlashStyledSelectList.js.map +1 -1
- package/dist/ui/components/ToolGroupExecution.d.ts +5 -2
- package/dist/ui/components/ToolGroupExecution.d.ts.map +1 -1
- package/dist/ui/components/ToolGroupExecution.js +3 -3
- package/dist/ui/components/ToolGroupExecution.js.map +1 -1
- package/dist/ui/components/index.d.ts +1 -0
- package/dist/ui/components/index.d.ts.map +1 -1
- package/dist/ui/components/index.js +1 -0
- package/dist/ui/components/index.js.map +1 -1
- package/dist/ui/hooks/useChatLayoutMeasurements.d.ts.map +1 -1
- package/dist/ui/hooks/useChatLayoutMeasurements.js +4 -1
- package/dist/ui/hooks/useChatLayoutMeasurements.js.map +1 -1
- package/dist/ui/hooks/useContextCompaction.d.ts +41 -0
- package/dist/ui/hooks/useContextCompaction.d.ts.map +1 -0
- package/dist/ui/hooks/useContextCompaction.js +149 -0
- package/dist/ui/hooks/useContextCompaction.js.map +1 -0
- package/dist/ui/hooks/useGoalOrchestration.d.ts +81 -0
- package/dist/ui/hooks/useGoalOrchestration.d.ts.map +1 -0
- package/dist/ui/hooks/useGoalOrchestration.js +745 -0
- package/dist/ui/hooks/useGoalOrchestration.js.map +1 -0
- package/dist/ui/hooks/useModeState.d.ts +61 -0
- package/dist/ui/hooks/useModeState.d.ts.map +1 -0
- package/dist/ui/hooks/useModeState.js +86 -0
- package/dist/ui/hooks/useModeState.js.map +1 -0
- package/dist/ui/hooks/usePixelFixFlow.d.ts +57 -0
- package/dist/ui/hooks/usePixelFixFlow.d.ts.map +1 -0
- package/dist/ui/hooks/usePixelFixFlow.js +102 -0
- package/dist/ui/hooks/usePixelFixFlow.js.map +1 -0
- package/dist/ui/hooks/useSessionPersistence.d.ts +34 -0
- package/dist/ui/hooks/useSessionPersistence.d.ts.map +1 -0
- package/dist/ui/hooks/useSessionPersistence.js +67 -0
- package/dist/ui/hooks/useSessionPersistence.js.map +1 -0
- package/dist/ui/live-area-clamp.test.d.ts +2 -0
- package/dist/ui/live-area-clamp.test.d.ts.map +1 -0
- package/dist/ui/live-area-clamp.test.js +79 -0
- package/dist/ui/live-area-clamp.test.js.map +1 -0
- package/dist/ui/live-area-height.d.ts +35 -0
- package/dist/ui/live-area-height.d.ts.map +1 -0
- package/dist/ui/live-area-height.js +75 -0
- package/dist/ui/live-area-height.js.map +1 -0
- package/dist/ui/live-area-height.test.d.ts +2 -0
- package/dist/ui/live-area-height.test.d.ts.map +1 -0
- package/dist/ui/live-area-height.test.js +67 -0
- package/dist/ui/live-area-height.test.js.map +1 -0
- package/dist/ui/live-frame-height.test.d.ts +2 -0
- package/dist/ui/live-frame-height.test.d.ts.map +1 -0
- package/dist/ui/live-frame-height.test.js +91 -0
- package/dist/ui/live-frame-height.test.js.map +1 -0
- package/dist/ui/terminal-history.d.ts.map +1 -1
- package/dist/ui/terminal-history.js +13 -4
- package/dist/ui/terminal-history.js.map +1 -1
- package/dist/ui/terminal-history.test.js +63 -3
- package/dist/ui/terminal-history.test.js.map +1 -1
- package/dist/ui/tool-group-summary.d.ts +9 -1
- package/dist/ui/tool-group-summary.d.ts.map +1 -1
- package/dist/ui/tool-group-summary.js +7 -6
- package/dist/ui/tool-group-summary.js.map +1 -1
- package/dist/ui/transcript/TranscriptRenderer.d.ts.map +1 -1
- package/dist/ui/transcript/TranscriptRenderer.js +10 -2
- package/dist/ui/transcript/TranscriptRenderer.js.map +1 -1
- package/dist/ui/transcript/spacing.d.ts +15 -5
- package/dist/ui/transcript/spacing.d.ts.map +1 -1
- package/dist/ui/transcript/spacing.js +35 -9
- package/dist/ui/transcript/spacing.js.map +1 -1
- package/dist/ui/utils/assistant-stream-split.d.ts +17 -0
- package/dist/ui/utils/assistant-stream-split.d.ts.map +1 -1
- package/dist/ui/utils/assistant-stream-split.js +38 -1
- package/dist/ui/utils/assistant-stream-split.js.map +1 -1
- package/dist/ui/utils/assistant-stream-split.test.js +29 -6
- package/dist/ui/utils/assistant-stream-split.test.js.map +1 -1
- package/dist/ui/utils/terminal-input.d.ts +3 -0
- package/dist/ui/utils/terminal-input.d.ts.map +1 -0
- package/dist/ui/utils/terminal-input.js +28 -0
- package/dist/ui/utils/terminal-input.js.map +1 -0
- package/dist/ui/utils/terminal-input.test.d.ts +2 -0
- package/dist/ui/utils/terminal-input.test.d.ts.map +1 -0
- package/dist/ui/utils/terminal-input.test.js +15 -0
- package/dist/ui/utils/terminal-input.test.js.map +1 -0
- package/package.json +12 -4
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
import { useCallback, useEffect, } from "react";
|
|
2
|
+
import { log } from "../../core/logger.js";
|
|
3
|
+
import { appendGoalDecision, appendGoalEvidence, formatGoalBlockingPrerequisites, goalHasBlockingPrerequisites, loadGoalRuns, reconcileActiveGoalRuns, updateGoalTask, upsertGoalRun, } from "../../core/goal-store.js";
|
|
4
|
+
import { canCompleteGoalRun, decideGoalNextAction } from "../../core/goal-controller.js";
|
|
5
|
+
import { runGoalPrerequisiteChecks } from "../../core/goal-prerequisites.js";
|
|
6
|
+
import { runGoalVerifierCommand } from "../../core/goal-verifier.js";
|
|
7
|
+
import { checkGoalWorktreeIntegration, isGoalWorktreeDirtyError, } from "../../core/goal-worktree.js";
|
|
8
|
+
import { listGoalWorkers, startGoalWorker, stopGoalWorker, subscribeGoalWorkerCompletions, } from "../../core/goal-worker.js";
|
|
9
|
+
import { formatGoalVerifierCompletionEvent, formatGoalWorkerCompletionEvent, parseGoalSyntheticEvent, } from "../goal-events.js";
|
|
10
|
+
import { completedItemsWithDurableGoalTerminalProgress, formatGoalTerminalProgress, formatGoalWorkerFinishedTitle, getGoalContinuationChoiceKey, goalTerminalProgressId, routeGoalSyntheticEvent, summarizeGoalCompletion, } from "../goal-progress.js";
|
|
11
|
+
import { buildGoalDirtyWorktreePauseRun, buildGoalDirtyWorktreeUserPrompt, buildGoalTaskPromptWithReferences, buildGoalUserPauseRun, goalDirtyWorktreeInfoText, goalRunNeedsExplicitContinuationAfterWorker, goalTaskProgress, shouldKeepGoalRunTrackedAfterDecision, shouldRunGoalTaskInMainCheckout, } from "../goal-run-helpers.js";
|
|
12
|
+
import { toErrorItem } from "../error-item.js";
|
|
13
|
+
/**
|
|
14
|
+
* Owns the entire Goal orchestration lifecycle — synthetic-event routing,
|
|
15
|
+
* continuation, worker-completion handling, the worker-completion subscription,
|
|
16
|
+
* starting runs/tasks/workers, verifier execution, and pausing. Extracted
|
|
17
|
+
* verbatim from `App.tsx`; the mutual recursion between these callbacks is
|
|
18
|
+
* preserved via `startGoalRunRef`/`startTaskRef`.
|
|
19
|
+
*/
|
|
20
|
+
export function useGoalOrchestration({ cwd, resetUI, sessionStore, currentProvider, currentModel, thinkingLevel, agentLoop, appendGoalProgress, goalNumberForRun, clearGoalStatusEntry, upsertGoalStatusEntry, setGoalModeAndPrompt, clearGoalModeIfIdle, agentRunningRef, runningGoalIdsRef, activeVerifierRunIdsRef, queuedGoalSyntheticEventsRef, goalContinuationFlightsRef, goalContinuationRecentChoicesRef, startGoalRunRef, startTaskRef, messagesRef, persistedIndexRef, sessionManagerRef, sessionPathRef, cwdRef, setLiveItems, setHistory, setLastUserMessage, setDoneStatus, getId, clearPendingHistory, }) {
|
|
21
|
+
const runGoalSyntheticEvent = useCallback((eventText) => {
|
|
22
|
+
const eventInfo = parseGoalSyntheticEvent(eventText);
|
|
23
|
+
const detail = eventInfo?.kind === "worker"
|
|
24
|
+
? `Inspecting worker result${eventInfo.task ? ` for ${eventInfo.task}` : ""}.`
|
|
25
|
+
: `Inspecting verifier result${eventInfo?.status ? ` (${eventInfo.status})` : ""}.`;
|
|
26
|
+
const route = routeGoalSyntheticEvent({
|
|
27
|
+
agentRunning: agentRunningRef.current,
|
|
28
|
+
queuedSyntheticEvents: queuedGoalSyntheticEventsRef.current,
|
|
29
|
+
});
|
|
30
|
+
if (route.action === "queue") {
|
|
31
|
+
queuedGoalSyntheticEventsRef.current = route.nextQueuedSyntheticEvents;
|
|
32
|
+
void setGoalModeAndPrompt(route.nextGoalMode);
|
|
33
|
+
appendGoalProgress({
|
|
34
|
+
kind: "goal_progress",
|
|
35
|
+
phase: "orchestrator_reviewing",
|
|
36
|
+
title: "Goal update queued for orchestrator",
|
|
37
|
+
detail: `${detail} It will report back after the current turn.`,
|
|
38
|
+
workerId: eventInfo?.worker,
|
|
39
|
+
status: eventInfo?.status,
|
|
40
|
+
});
|
|
41
|
+
agentLoop.queueMessage(eventText);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
appendGoalProgress({
|
|
45
|
+
kind: "goal_progress",
|
|
46
|
+
phase: "orchestrator_reviewing",
|
|
47
|
+
title: "Orchestrator reviewing Goal update",
|
|
48
|
+
detail,
|
|
49
|
+
workerId: eventInfo?.worker,
|
|
50
|
+
status: eventInfo?.status,
|
|
51
|
+
});
|
|
52
|
+
setLastUserMessage("");
|
|
53
|
+
setDoneStatus(null);
|
|
54
|
+
void (async () => {
|
|
55
|
+
await setGoalModeAndPrompt("coordinator");
|
|
56
|
+
await agentLoop.run(eventText);
|
|
57
|
+
})().catch((err) => {
|
|
58
|
+
log("ERROR", "goal", err instanceof Error ? err.message : String(err));
|
|
59
|
+
setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
|
|
60
|
+
clearGoalModeIfIdle();
|
|
61
|
+
});
|
|
62
|
+
}, [agentLoop, appendGoalProgress, clearGoalModeIfIdle, setGoalModeAndPrompt]);
|
|
63
|
+
const continueGoalRun = useCallback((runId) => {
|
|
64
|
+
if (goalContinuationFlightsRef.current.has(runId))
|
|
65
|
+
return;
|
|
66
|
+
goalContinuationFlightsRef.current.add(runId);
|
|
67
|
+
void (async () => {
|
|
68
|
+
const latestRun = await reconcileActiveGoalRuns(cwd, {
|
|
69
|
+
isWorkerActive: (workerId) => listGoalWorkers(cwd).some((worker) => worker.id === workerId && worker.status === "running"),
|
|
70
|
+
}).then(({ runs }) => runs.find((item) => item.id === runId) ?? null);
|
|
71
|
+
if (!latestRun) {
|
|
72
|
+
runningGoalIdsRef.current.delete(runId);
|
|
73
|
+
clearGoalStatusEntry(runId);
|
|
74
|
+
clearGoalModeIfIdle();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const decision = decideGoalNextAction(latestRun);
|
|
78
|
+
if (!shouldKeepGoalRunTrackedAfterDecision(decision)) {
|
|
79
|
+
runningGoalIdsRef.current.delete(runId);
|
|
80
|
+
clearGoalModeIfIdle();
|
|
81
|
+
}
|
|
82
|
+
if (decision.kind === "wait")
|
|
83
|
+
return;
|
|
84
|
+
const choiceKey = getGoalContinuationChoiceKey({ runId: latestRun.id, decision });
|
|
85
|
+
const now = Date.now();
|
|
86
|
+
const recentChoiceAt = goalContinuationRecentChoicesRef.current.get(choiceKey);
|
|
87
|
+
if (recentChoiceAt !== undefined && now - recentChoiceAt < 5000)
|
|
88
|
+
return;
|
|
89
|
+
goalContinuationRecentChoicesRef.current.set(choiceKey, now);
|
|
90
|
+
if (goalContinuationRecentChoicesRef.current.size > 100) {
|
|
91
|
+
for (const [key, startedAt] of goalContinuationRecentChoicesRef.current) {
|
|
92
|
+
if (now - startedAt > 60_000)
|
|
93
|
+
goalContinuationRecentChoicesRef.current.delete(key);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (decision.kind === "terminal" ||
|
|
97
|
+
decision.kind === "blocked" ||
|
|
98
|
+
decision.kind === "pause") {
|
|
99
|
+
const status = decision.kind === "terminal"
|
|
100
|
+
? decision.status
|
|
101
|
+
: decision.kind === "blocked"
|
|
102
|
+
? "blocked"
|
|
103
|
+
: "paused";
|
|
104
|
+
const nextRun = {
|
|
105
|
+
...latestRun,
|
|
106
|
+
status,
|
|
107
|
+
continueRequestedAt: undefined,
|
|
108
|
+
blockers: decision.kind === "blocked" || decision.kind === "pause"
|
|
109
|
+
? Array.from(new Set([...latestRun.blockers, decision.reason]))
|
|
110
|
+
: latestRun.blockers,
|
|
111
|
+
};
|
|
112
|
+
await upsertGoalRun(cwd, nextRun);
|
|
113
|
+
await appendGoalDecision(cwd, latestRun.id, {
|
|
114
|
+
kind: "continuation_stopped",
|
|
115
|
+
reason: decision.reason,
|
|
116
|
+
content: `terminal=${status}`,
|
|
117
|
+
});
|
|
118
|
+
const terminalProgress = formatGoalTerminalProgress(nextRun);
|
|
119
|
+
if (terminalProgress) {
|
|
120
|
+
const item = { ...terminalProgress, id: goalTerminalProgressId(nextRun) };
|
|
121
|
+
setLiveItems((prev) => completedItemsWithDurableGoalTerminalProgress([...prev, item], [nextRun]));
|
|
122
|
+
}
|
|
123
|
+
runningGoalIdsRef.current.delete(runId);
|
|
124
|
+
clearGoalStatusEntry(runId);
|
|
125
|
+
clearGoalModeIfIdle();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let runForNextAction = latestRun;
|
|
129
|
+
if (latestRun.continueRequestedAt &&
|
|
130
|
+
!listGoalWorkers(cwd).some((worker) => worker.status === "running") &&
|
|
131
|
+
activeVerifierRunIdsRef.current.size === 0) {
|
|
132
|
+
await appendGoalDecision(cwd, latestRun.id, {
|
|
133
|
+
kind: "continuation_consumed",
|
|
134
|
+
reason: `Continuation request consumed by ${decision.kind}.`,
|
|
135
|
+
});
|
|
136
|
+
runForNextAction = await upsertGoalRun(cwd, {
|
|
137
|
+
...latestRun,
|
|
138
|
+
continueRequestedAt: undefined,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
appendGoalProgress({
|
|
142
|
+
kind: "goal_progress",
|
|
143
|
+
phase: "continuing",
|
|
144
|
+
title: `Choosing next Goal step: ${latestRun.title}`,
|
|
145
|
+
detail: "Latest result is recorded; starting the next worker task or verifier automatically.",
|
|
146
|
+
status: latestRun.status,
|
|
147
|
+
});
|
|
148
|
+
upsertGoalStatusEntry({
|
|
149
|
+
runId: latestRun.id,
|
|
150
|
+
label: latestRun.title,
|
|
151
|
+
phase: "orchestrating",
|
|
152
|
+
startedAt: Date.now(),
|
|
153
|
+
detail: "choosing next step",
|
|
154
|
+
});
|
|
155
|
+
startGoalRunRef.current(runForNextAction);
|
|
156
|
+
})()
|
|
157
|
+
.catch((err) => {
|
|
158
|
+
runningGoalIdsRef.current.delete(runId);
|
|
159
|
+
clearGoalStatusEntry(runId);
|
|
160
|
+
log("ERROR", "goal", err instanceof Error ? err.message : String(err));
|
|
161
|
+
setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
|
|
162
|
+
})
|
|
163
|
+
.finally(() => {
|
|
164
|
+
goalContinuationFlightsRef.current.delete(runId);
|
|
165
|
+
clearGoalModeIfIdle();
|
|
166
|
+
});
|
|
167
|
+
}, [appendGoalProgress, clearGoalModeIfIdle, clearGoalStatusEntry, cwd, upsertGoalStatusEntry]);
|
|
168
|
+
const handleGoalWorkerComplete = useCallback((run, completion) => {
|
|
169
|
+
const taskTitle = run.tasks.find((task) => task.id === completion.worker.goalTaskId)?.title ??
|
|
170
|
+
completion.worker.goalTaskId;
|
|
171
|
+
const eventText = formatGoalWorkerCompletionEvent(run, taskTitle, completion);
|
|
172
|
+
appendGoalProgress({
|
|
173
|
+
kind: "goal_progress",
|
|
174
|
+
phase: "worker_finished",
|
|
175
|
+
title: formatGoalWorkerFinishedTitle(taskTitle, completion.status),
|
|
176
|
+
detail: summarizeGoalCompletion(completion.summary),
|
|
177
|
+
workerId: completion.worker.id,
|
|
178
|
+
status: completion.status,
|
|
179
|
+
});
|
|
180
|
+
const taskProgress = goalTaskProgress(run, run.tasks.find((task) => task.id === completion.worker.goalTaskId));
|
|
181
|
+
upsertGoalStatusEntry({
|
|
182
|
+
runId: run.id,
|
|
183
|
+
label: run.title,
|
|
184
|
+
phase: completion.status === "done" ? "reviewing" : "failed",
|
|
185
|
+
startedAt: Date.now(),
|
|
186
|
+
detail: completion.status === "done" ? "reviewing result" : "task failed",
|
|
187
|
+
workerId: completion.worker.id,
|
|
188
|
+
goalNumber: goalNumberForRun(run.id),
|
|
189
|
+
...taskProgress,
|
|
190
|
+
});
|
|
191
|
+
runGoalSyntheticEvent(eventText);
|
|
192
|
+
void (async () => {
|
|
193
|
+
if (listGoalWorkers(completion.worker.projectPath).some((worker) => worker.status === "running"))
|
|
194
|
+
return;
|
|
195
|
+
if (activeVerifierRunIdsRef.current.size > 0)
|
|
196
|
+
return;
|
|
197
|
+
const runs = await loadGoalRuns(completion.worker.projectPath);
|
|
198
|
+
const queued = runs.find((item) => goalRunNeedsExplicitContinuationAfterWorker(item));
|
|
199
|
+
if (queued)
|
|
200
|
+
setTimeout(() => continueGoalRun(queued.id), 750);
|
|
201
|
+
})().catch((err) => log("ERROR", "goal", err instanceof Error ? err.message : String(err)));
|
|
202
|
+
}, [
|
|
203
|
+
appendGoalProgress,
|
|
204
|
+
continueGoalRun,
|
|
205
|
+
goalNumberForRun,
|
|
206
|
+
runGoalSyntheticEvent,
|
|
207
|
+
upsertGoalStatusEntry,
|
|
208
|
+
]);
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
return subscribeGoalWorkerCompletions((completion) => {
|
|
211
|
+
void (async () => {
|
|
212
|
+
const latestRun = (await loadGoalRuns(completion.worker.projectPath)).find((item) => item.id === completion.worker.goalRunId) ?? null;
|
|
213
|
+
if (!latestRun) {
|
|
214
|
+
log("WARN", "goal", `Worker completion for unknown Goal ${completion.worker.goalRunId}`);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
runningGoalIdsRef.current.add(latestRun.id);
|
|
218
|
+
handleGoalWorkerComplete(latestRun, completion);
|
|
219
|
+
})().catch((err) => {
|
|
220
|
+
log("ERROR", "goal", err instanceof Error ? err.message : String(err));
|
|
221
|
+
setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
|
|
222
|
+
});
|
|
223
|
+
}, cwd);
|
|
224
|
+
}, [handleGoalWorkerComplete, cwd]);
|
|
225
|
+
const startGoalRun = useCallback((run) => {
|
|
226
|
+
runningGoalIdsRef.current.add(run.id);
|
|
227
|
+
upsertGoalStatusEntry({
|
|
228
|
+
runId: run.id,
|
|
229
|
+
label: run.title,
|
|
230
|
+
phase: "orchestrating",
|
|
231
|
+
startedAt: Date.now(),
|
|
232
|
+
detail: "choosing next step",
|
|
233
|
+
goalNumber: goalNumberForRun(run.id),
|
|
234
|
+
});
|
|
235
|
+
void (async () => {
|
|
236
|
+
await setGoalModeAndPrompt("coordinator");
|
|
237
|
+
const currentRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
|
|
238
|
+
const prereqCheck = await runGoalPrerequisiteChecks(cwd, currentRun);
|
|
239
|
+
const checkedRun = prereqCheck.checkedCount > 0
|
|
240
|
+
? await upsertGoalRun(cwd, {
|
|
241
|
+
...prereqCheck.run,
|
|
242
|
+
status: goalHasBlockingPrerequisites(prereqCheck.run) ? "blocked" : "ready",
|
|
243
|
+
})
|
|
244
|
+
: currentRun;
|
|
245
|
+
if (goalHasBlockingPrerequisites(checkedRun)) {
|
|
246
|
+
const detail = formatGoalBlockingPrerequisites(checkedRun);
|
|
247
|
+
await upsertGoalRun(cwd, {
|
|
248
|
+
...checkedRun,
|
|
249
|
+
status: "blocked",
|
|
250
|
+
blockers: Array.from(new Set([...checkedRun.blockers, detail])),
|
|
251
|
+
});
|
|
252
|
+
appendGoalProgress({
|
|
253
|
+
kind: "goal_progress",
|
|
254
|
+
phase: "terminal",
|
|
255
|
+
title: `Goal blocked: ${checkedRun.title}`,
|
|
256
|
+
detail,
|
|
257
|
+
status: "blocked",
|
|
258
|
+
});
|
|
259
|
+
runningGoalIdsRef.current.delete(checkedRun.id);
|
|
260
|
+
clearGoalStatusEntry(checkedRun.id);
|
|
261
|
+
clearGoalModeIfIdle();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const decision = decideGoalNextAction(checkedRun);
|
|
265
|
+
await appendGoalDecision(cwd, checkedRun.id, decision);
|
|
266
|
+
if (!shouldKeepGoalRunTrackedAfterDecision(decision)) {
|
|
267
|
+
runningGoalIdsRef.current.delete(checkedRun.id);
|
|
268
|
+
}
|
|
269
|
+
if (decision.kind === "terminal") {
|
|
270
|
+
const terminalProgress = formatGoalTerminalProgress(checkedRun);
|
|
271
|
+
if (terminalProgress) {
|
|
272
|
+
const item = { ...terminalProgress, id: goalTerminalProgressId(checkedRun) };
|
|
273
|
+
setLiveItems((prev) => completedItemsWithDurableGoalTerminalProgress([...prev, item], [checkedRun]));
|
|
274
|
+
}
|
|
275
|
+
runningGoalIdsRef.current.delete(checkedRun.id);
|
|
276
|
+
clearGoalStatusEntry(checkedRun.id);
|
|
277
|
+
clearGoalModeIfIdle();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (decision.kind === "wait") {
|
|
281
|
+
appendGoalProgress({
|
|
282
|
+
kind: "goal_progress",
|
|
283
|
+
phase: "worker_started",
|
|
284
|
+
title: decision.workerId
|
|
285
|
+
? `Goal working: ${checkedRun.title}`
|
|
286
|
+
: `Goal needs orchestration: ${checkedRun.title}`,
|
|
287
|
+
detail: decision.workerId
|
|
288
|
+
? decision.reason
|
|
289
|
+
: `${decision.reason} Asking the orchestrator to unblock or revise the Goal plan.`,
|
|
290
|
+
workerId: decision.workerId,
|
|
291
|
+
});
|
|
292
|
+
upsertGoalStatusEntry({
|
|
293
|
+
runId: checkedRun.id,
|
|
294
|
+
label: checkedRun.title,
|
|
295
|
+
phase: decision.workerId ? "worker" : "orchestrating",
|
|
296
|
+
startedAt: Date.now(),
|
|
297
|
+
detail: decision.reason,
|
|
298
|
+
workerId: decision.workerId,
|
|
299
|
+
goalNumber: goalNumberForRun(checkedRun.id),
|
|
300
|
+
});
|
|
301
|
+
if (!decision.workerId) {
|
|
302
|
+
const eventText = `Goal continuation is waiting with no active worker for Goal ${checkedRun.id} (${checkedRun.title}).\n` +
|
|
303
|
+
`Reason: ${decision.reason}\n\n` +
|
|
304
|
+
`Inspect the durable Goal state with the goals tool, resolve blocked dependencies by creating or updating concrete worker tasks, and then continue the Goal. If no local/free action can proceed, record an explicit blocker with exact user instructions. Do not stop after only explaining the state.`;
|
|
305
|
+
setLastUserMessage("");
|
|
306
|
+
setDoneStatus(null);
|
|
307
|
+
await agentLoop.run(eventText);
|
|
308
|
+
}
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (decision.kind === "complete") {
|
|
312
|
+
await upsertGoalRun(cwd, { ...checkedRun, status: "passed" });
|
|
313
|
+
appendGoalProgress({
|
|
314
|
+
kind: "goal_progress",
|
|
315
|
+
phase: "terminal",
|
|
316
|
+
title: `Goal passed: ${checkedRun.title}`,
|
|
317
|
+
detail: decision.reason,
|
|
318
|
+
status: "passed",
|
|
319
|
+
});
|
|
320
|
+
runningGoalIdsRef.current.delete(checkedRun.id);
|
|
321
|
+
clearGoalStatusEntry(checkedRun.id);
|
|
322
|
+
clearGoalModeIfIdle();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (decision.kind === "run_verifier") {
|
|
326
|
+
await verifyGoalRun(checkedRun);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (decision.kind === "create_task") {
|
|
330
|
+
const latestRunBeforeCreate = (await loadGoalRuns(cwd)).find((item) => item.id === checkedRun.id) ?? checkedRun;
|
|
331
|
+
const existingSameTitleTask = latestRunBeforeCreate.tasks.find((item) => item.title === decision.title);
|
|
332
|
+
if (existingSameTitleTask) {
|
|
333
|
+
const runWithExistingTask = await upsertGoalRun(cwd, {
|
|
334
|
+
...latestRunBeforeCreate,
|
|
335
|
+
status: "ready",
|
|
336
|
+
});
|
|
337
|
+
appendGoalProgress({
|
|
338
|
+
kind: "goal_progress",
|
|
339
|
+
phase: "continuing",
|
|
340
|
+
title: `Goal task already exists: ${decision.title}`,
|
|
341
|
+
detail: "Reusing the existing Goal task instead of creating a duplicate.",
|
|
342
|
+
status: "ready",
|
|
343
|
+
});
|
|
344
|
+
startGoalRunRef.current(runWithExistingTask);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
await updateGoalTask(cwd, checkedRun.id, `auto-${Date.now()}`, {
|
|
348
|
+
title: decision.title,
|
|
349
|
+
prompt: decision.prompt,
|
|
350
|
+
status: "pending",
|
|
351
|
+
});
|
|
352
|
+
const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === checkedRun.id) ?? checkedRun;
|
|
353
|
+
const runWithTask = await upsertGoalRun(cwd, { ...latestRun, status: "ready" });
|
|
354
|
+
appendGoalProgress({
|
|
355
|
+
kind: "goal_progress",
|
|
356
|
+
phase: "continuing",
|
|
357
|
+
title: `Goal task created: ${decision.title}`,
|
|
358
|
+
detail: "Starting the new Goal task now.",
|
|
359
|
+
status: "ready",
|
|
360
|
+
});
|
|
361
|
+
startGoalRunRef.current(runWithTask);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (decision.kind === "blocked") {
|
|
365
|
+
await upsertGoalRun(cwd, {
|
|
366
|
+
...checkedRun,
|
|
367
|
+
status: "blocked",
|
|
368
|
+
blockers: [...checkedRun.blockers, decision.reason],
|
|
369
|
+
});
|
|
370
|
+
appendGoalProgress({
|
|
371
|
+
kind: "goal_progress",
|
|
372
|
+
phase: "terminal",
|
|
373
|
+
title: `Goal blocked: ${checkedRun.title}`,
|
|
374
|
+
detail: decision.reason,
|
|
375
|
+
status: "blocked",
|
|
376
|
+
});
|
|
377
|
+
runningGoalIdsRef.current.delete(checkedRun.id);
|
|
378
|
+
clearGoalStatusEntry(checkedRun.id);
|
|
379
|
+
clearGoalModeIfIdle();
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (decision.kind === "pause") {
|
|
383
|
+
const runWithBlockedTask = (await updateGoalTask(cwd, checkedRun.id, decision.task.id, {
|
|
384
|
+
status: "blocked",
|
|
385
|
+
attempts: decision.attempts,
|
|
386
|
+
lastSummary: "Paused after worker attempt limit.",
|
|
387
|
+
})) ?? checkedRun;
|
|
388
|
+
const runWithPauseEvidence = (await appendGoalEvidence(cwd, checkedRun.id, {
|
|
389
|
+
kind: "summary",
|
|
390
|
+
label: "Goal paused",
|
|
391
|
+
content: decision.reason,
|
|
392
|
+
})) ?? runWithBlockedTask;
|
|
393
|
+
await upsertGoalRun(cwd, {
|
|
394
|
+
...runWithPauseEvidence,
|
|
395
|
+
status: "paused",
|
|
396
|
+
continueRequestedAt: undefined,
|
|
397
|
+
blockers: Array.from(new Set([...runWithPauseEvidence.blockers, decision.reason])),
|
|
398
|
+
});
|
|
399
|
+
appendGoalProgress({
|
|
400
|
+
kind: "goal_progress",
|
|
401
|
+
phase: "terminal",
|
|
402
|
+
title: `Goal paused: ${checkedRun.title}`,
|
|
403
|
+
detail: decision.reason,
|
|
404
|
+
status: "paused",
|
|
405
|
+
});
|
|
406
|
+
runningGoalIdsRef.current.delete(checkedRun.id);
|
|
407
|
+
clearGoalStatusEntry(checkedRun.id);
|
|
408
|
+
clearGoalModeIfIdle();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const runWithAttempt = (await updateGoalTask(cwd, checkedRun.id, decision.task.id, {
|
|
412
|
+
attempts: decision.attempts,
|
|
413
|
+
})) ?? checkedRun;
|
|
414
|
+
const worker = await startGoalWorker({
|
|
415
|
+
cwd,
|
|
416
|
+
provider: currentProvider,
|
|
417
|
+
model: currentModel,
|
|
418
|
+
thinkingLevel,
|
|
419
|
+
goalRunId: checkedRun.id,
|
|
420
|
+
goalTaskId: decision.task.id,
|
|
421
|
+
taskTitle: decision.task.title,
|
|
422
|
+
prompt: buildGoalTaskPromptWithReferences(checkedRun, decision.task.prompt),
|
|
423
|
+
isolateWorktree: shouldRunGoalTaskInMainCheckout(decision.task.title) ? false : undefined,
|
|
424
|
+
});
|
|
425
|
+
const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === checkedRun.id) ?? runWithAttempt;
|
|
426
|
+
await upsertGoalRun(cwd, {
|
|
427
|
+
...latestRun,
|
|
428
|
+
status: "running",
|
|
429
|
+
activeWorkerId: worker.id,
|
|
430
|
+
continueRequestedAt: undefined,
|
|
431
|
+
tasks: latestRun.tasks.map((item) => item.id === decision.task.id
|
|
432
|
+
? { ...item, status: "running", workerId: worker.id, attempts: decision.attempts }
|
|
433
|
+
: item),
|
|
434
|
+
});
|
|
435
|
+
appendGoalProgress({
|
|
436
|
+
kind: "goal_progress",
|
|
437
|
+
phase: "worker_started",
|
|
438
|
+
title: `Worker started: ${decision.task.title}`,
|
|
439
|
+
detail: "Task is running in the background.",
|
|
440
|
+
workerId: worker.id,
|
|
441
|
+
status: worker.status,
|
|
442
|
+
});
|
|
443
|
+
upsertGoalStatusEntry({
|
|
444
|
+
runId: checkedRun.id,
|
|
445
|
+
label: checkedRun.title,
|
|
446
|
+
phase: "worker",
|
|
447
|
+
startedAt: Date.now(),
|
|
448
|
+
detail: "background worker running",
|
|
449
|
+
workerId: worker.id,
|
|
450
|
+
goalNumber: goalNumberForRun(checkedRun.id),
|
|
451
|
+
...goalTaskProgress(checkedRun, decision.task),
|
|
452
|
+
});
|
|
453
|
+
})().catch(async (err) => {
|
|
454
|
+
clearGoalStatusEntry(run.id);
|
|
455
|
+
clearGoalModeIfIdle();
|
|
456
|
+
log("ERROR", "goal", err instanceof Error ? err.message : String(err));
|
|
457
|
+
if (isGoalWorktreeDirtyError(err)) {
|
|
458
|
+
const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
|
|
459
|
+
const pausedRun = await upsertGoalRun(cwd, buildGoalDirtyWorktreePauseRun(latestRun, err));
|
|
460
|
+
runningGoalIdsRef.current.delete(pausedRun.id);
|
|
461
|
+
appendGoalProgress({
|
|
462
|
+
kind: "goal_progress",
|
|
463
|
+
phase: "terminal",
|
|
464
|
+
title: `Goal paused: ${pausedRun.title}`,
|
|
465
|
+
detail: "Working tree has uncommitted changes; waiting for the user to choose commit, stash, or pause.",
|
|
466
|
+
status: "paused",
|
|
467
|
+
});
|
|
468
|
+
setLiveItems((prev) => [
|
|
469
|
+
...prev,
|
|
470
|
+
{ kind: "info", text: goalDirtyWorktreeInfoText(), id: getId() },
|
|
471
|
+
]);
|
|
472
|
+
void agentLoop.run(buildGoalDirtyWorktreeUserPrompt(err)).catch((agentErr) => {
|
|
473
|
+
log("ERROR", "goal", agentErr instanceof Error ? agentErr.message : String(agentErr));
|
|
474
|
+
setLiveItems((prev) => [...prev, toErrorItem(agentErr, getId(), "Goal")]);
|
|
475
|
+
});
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
|
|
479
|
+
});
|
|
480
|
+
}, [
|
|
481
|
+
cwd,
|
|
482
|
+
currentProvider,
|
|
483
|
+
currentModel,
|
|
484
|
+
thinkingLevel,
|
|
485
|
+
agentLoop,
|
|
486
|
+
appendGoalProgress,
|
|
487
|
+
clearGoalModeIfIdle,
|
|
488
|
+
clearGoalStatusEntry,
|
|
489
|
+
goalNumberForRun,
|
|
490
|
+
setGoalModeAndPrompt,
|
|
491
|
+
upsertGoalStatusEntry,
|
|
492
|
+
]);
|
|
493
|
+
const verifyGoalRun = useCallback(async (run) => {
|
|
494
|
+
await setGoalModeAndPrompt("coordinator");
|
|
495
|
+
if (!run.verifier?.command) {
|
|
496
|
+
await appendGoalEvidence(cwd, run.id, {
|
|
497
|
+
kind: "summary",
|
|
498
|
+
label: "Missing verifier",
|
|
499
|
+
content: "No verifier command is configured.",
|
|
500
|
+
});
|
|
501
|
+
await upsertGoalRun(cwd, {
|
|
502
|
+
...run,
|
|
503
|
+
status: "blocked",
|
|
504
|
+
blockers: [...run.blockers, "No verifier command configured."],
|
|
505
|
+
});
|
|
506
|
+
appendGoalProgress({
|
|
507
|
+
kind: "goal_progress",
|
|
508
|
+
phase: "terminal",
|
|
509
|
+
title: `Goal blocked: ${run.title}`,
|
|
510
|
+
detail: "No verifier command is configured.",
|
|
511
|
+
status: "blocked",
|
|
512
|
+
});
|
|
513
|
+
runningGoalIdsRef.current.delete(run.id);
|
|
514
|
+
clearGoalStatusEntry(run.id);
|
|
515
|
+
clearGoalModeIfIdle();
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const integration = await checkGoalWorktreeIntegration(cwd, run);
|
|
519
|
+
if (!integration.ok) {
|
|
520
|
+
const runWithEvidence = (await appendGoalEvidence(cwd, run.id, {
|
|
521
|
+
kind: "summary",
|
|
522
|
+
label: "Goal worktree integration required",
|
|
523
|
+
content: integration.summary,
|
|
524
|
+
})) ?? run;
|
|
525
|
+
await upsertGoalRun(cwd, {
|
|
526
|
+
...runWithEvidence,
|
|
527
|
+
status: "blocked",
|
|
528
|
+
blockers: Array.from(new Set([...runWithEvidence.blockers, integration.summary])),
|
|
529
|
+
});
|
|
530
|
+
appendGoalProgress({
|
|
531
|
+
kind: "goal_progress",
|
|
532
|
+
phase: "terminal",
|
|
533
|
+
title: `Goal blocked before verifier: ${run.title}`,
|
|
534
|
+
detail: integration.summary,
|
|
535
|
+
status: "blocked",
|
|
536
|
+
});
|
|
537
|
+
runningGoalIdsRef.current.delete(run.id);
|
|
538
|
+
clearGoalStatusEntry(run.id);
|
|
539
|
+
clearGoalModeIfIdle();
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
activeVerifierRunIdsRef.current.add(run.id);
|
|
543
|
+
await upsertGoalRun(cwd, {
|
|
544
|
+
...run,
|
|
545
|
+
status: "verifying",
|
|
546
|
+
continueRequestedAt: undefined,
|
|
547
|
+
});
|
|
548
|
+
appendGoalProgress({
|
|
549
|
+
kind: "goal_progress",
|
|
550
|
+
phase: "verifier_started",
|
|
551
|
+
title: `Verifier started: ${run.title}`,
|
|
552
|
+
detail: run.verifier.command,
|
|
553
|
+
status: "verifying",
|
|
554
|
+
});
|
|
555
|
+
const startedAt = Date.now();
|
|
556
|
+
const verifierTimeoutMs = Number(process.env.GG_GOAL_VERIFIER_TIMEOUT_MS ?? 10 * 60 * 1000);
|
|
557
|
+
upsertGoalStatusEntry({
|
|
558
|
+
runId: run.id,
|
|
559
|
+
label: run.title,
|
|
560
|
+
phase: "verifier",
|
|
561
|
+
startedAt,
|
|
562
|
+
detail: run.verifier.command,
|
|
563
|
+
goalNumber: goalNumberForRun(run.id),
|
|
564
|
+
});
|
|
565
|
+
void runGoalVerifierCommand({
|
|
566
|
+
cwd: run.verifier.cwd ?? cwd,
|
|
567
|
+
runId: run.id,
|
|
568
|
+
command: run.verifier.command,
|
|
569
|
+
timeoutMs: verifierTimeoutMs,
|
|
570
|
+
now: () => startedAt,
|
|
571
|
+
})
|
|
572
|
+
.then(async ({ verification, failureClass, durationMs }) => {
|
|
573
|
+
activeVerifierRunIdsRef.current.delete(run.id);
|
|
574
|
+
const status = verification.status;
|
|
575
|
+
const summary = verification.summary;
|
|
576
|
+
const outputPath = verification.outputPath;
|
|
577
|
+
const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
|
|
578
|
+
const runWithVerifier = {
|
|
579
|
+
...latestRun,
|
|
580
|
+
verifier: {
|
|
581
|
+
...latestRun.verifier,
|
|
582
|
+
description: latestRun.verifier?.description ?? "Goal verifier",
|
|
583
|
+
command: run.verifier?.command,
|
|
584
|
+
...(run.verifier?.cwd ? { cwd: run.verifier.cwd } : {}),
|
|
585
|
+
lastResult: verification,
|
|
586
|
+
},
|
|
587
|
+
...(status === "pass"
|
|
588
|
+
? {
|
|
589
|
+
completionAudit: {
|
|
590
|
+
status: "unknown",
|
|
591
|
+
summary: "Final completion audit pending for latest verifier result.",
|
|
592
|
+
checkedAt: verification.checkedAt,
|
|
593
|
+
verifierCheckedAt: verification.checkedAt,
|
|
594
|
+
...(verification.outputPath ? { outputPath: verification.outputPath } : {}),
|
|
595
|
+
},
|
|
596
|
+
}
|
|
597
|
+
: {}),
|
|
598
|
+
};
|
|
599
|
+
const completionCheck = canCompleteGoalRun(runWithVerifier);
|
|
600
|
+
const verifiedRun = await upsertGoalRun(cwd, {
|
|
601
|
+
...runWithVerifier,
|
|
602
|
+
continueRequestedAt: latestRun.continueRequestedAt,
|
|
603
|
+
status: status === "pass" && completionCheck.ok ? "passed" : "ready",
|
|
604
|
+
});
|
|
605
|
+
await appendGoalEvidence(cwd, run.id, {
|
|
606
|
+
kind: "command",
|
|
607
|
+
label: `Verifier ${status}`,
|
|
608
|
+
content: `${failureClass}: ${summary}`.slice(0, 4000),
|
|
609
|
+
path: outputPath,
|
|
610
|
+
});
|
|
611
|
+
await appendGoalDecision(cwd, run.id, {
|
|
612
|
+
kind: `verifier_${status}`,
|
|
613
|
+
reason: `${failureClass}: verifier exited with code ${verification.exitCode ?? 1}.`,
|
|
614
|
+
content: `outputPath=${outputPath ?? ""}; cwd=${run.verifier?.cwd ?? cwd}; durationMs=${durationMs}`,
|
|
615
|
+
});
|
|
616
|
+
appendGoalProgress({
|
|
617
|
+
kind: "goal_progress",
|
|
618
|
+
phase: "verifier_finished",
|
|
619
|
+
title: `Verifier ${status}: ${run.title}`,
|
|
620
|
+
detail: summarizeGoalCompletion(summary),
|
|
621
|
+
status,
|
|
622
|
+
});
|
|
623
|
+
upsertGoalStatusEntry({
|
|
624
|
+
runId: run.id,
|
|
625
|
+
label: run.title,
|
|
626
|
+
phase: status === "pass" ? "reviewing" : "failed",
|
|
627
|
+
startedAt: Date.now(),
|
|
628
|
+
detail: status === "pass" ? "reviewing verifier evidence" : "verifier failed",
|
|
629
|
+
goalNumber: goalNumberForRun(run.id),
|
|
630
|
+
});
|
|
631
|
+
const eventText = formatGoalVerifierCompletionEvent(verifiedRun, status === "pass" ? "pass" : "fail", run.verifier?.command ?? "", verification.exitCode ?? 1, summary);
|
|
632
|
+
runGoalSyntheticEvent(eventText);
|
|
633
|
+
const continuationRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id);
|
|
634
|
+
if (continuationRun?.continueRequestedAt || status === "fail" || status === "pass") {
|
|
635
|
+
setTimeout(() => continueGoalRun(run.id), 500);
|
|
636
|
+
}
|
|
637
|
+
})
|
|
638
|
+
.catch((err) => {
|
|
639
|
+
activeVerifierRunIdsRef.current.delete(run.id);
|
|
640
|
+
clearGoalStatusEntry(run.id);
|
|
641
|
+
clearGoalModeIfIdle();
|
|
642
|
+
log("ERROR", "goal", err instanceof Error ? err.message : String(err));
|
|
643
|
+
setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal verifier")]);
|
|
644
|
+
});
|
|
645
|
+
}, [
|
|
646
|
+
cwd,
|
|
647
|
+
appendGoalProgress,
|
|
648
|
+
clearGoalModeIfIdle,
|
|
649
|
+
clearGoalStatusEntry,
|
|
650
|
+
goalNumberForRun,
|
|
651
|
+
runGoalSyntheticEvent,
|
|
652
|
+
setGoalModeAndPrompt,
|
|
653
|
+
upsertGoalStatusEntry,
|
|
654
|
+
]);
|
|
655
|
+
const pauseGoalRun = useCallback((run) => {
|
|
656
|
+
void (async () => {
|
|
657
|
+
runningGoalIdsRef.current.delete(run.id);
|
|
658
|
+
if (run.activeWorkerId)
|
|
659
|
+
await stopGoalWorker(run.activeWorkerId);
|
|
660
|
+
const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
|
|
661
|
+
await upsertGoalRun(cwd, buildGoalUserPauseRun(latestRun));
|
|
662
|
+
appendGoalProgress({
|
|
663
|
+
kind: "goal_progress",
|
|
664
|
+
phase: "terminal",
|
|
665
|
+
title: `Goal paused: ${run.title}`,
|
|
666
|
+
detail: "Auto-continuation stopped until resumed.",
|
|
667
|
+
status: "paused",
|
|
668
|
+
});
|
|
669
|
+
clearGoalStatusEntry(run.id);
|
|
670
|
+
clearGoalModeIfIdle();
|
|
671
|
+
})().catch((err) => {
|
|
672
|
+
log("ERROR", "goal", err instanceof Error ? err.message : String(err));
|
|
673
|
+
setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
|
|
674
|
+
});
|
|
675
|
+
}, [appendGoalProgress, clearGoalModeIfIdle, clearGoalStatusEntry, cwd]);
|
|
676
|
+
const startTask = useCallback((title, prompt, taskId) => {
|
|
677
|
+
const taskCwd = cwdRef.current;
|
|
678
|
+
const shortId = taskId.slice(0, 8);
|
|
679
|
+
const completionHint = `\n\n---\nWhen you have fully completed this task, call the tasks tool to mark it done:\n` +
|
|
680
|
+
`tasks({ action: "done", id: "${shortId}" })`;
|
|
681
|
+
const fullPrompt = prompt + completionHint;
|
|
682
|
+
if (resetUI && sessionStore) {
|
|
683
|
+
const sysMsg = messagesRef.current[0];
|
|
684
|
+
const newMessages = sysMsg && sysMsg.role === "system" ? [sysMsg] : messagesRef.current.slice(0, 1);
|
|
685
|
+
const taskItem = { kind: "task", title, id: getId() };
|
|
686
|
+
const sm = sessionManagerRef.current;
|
|
687
|
+
void (async () => {
|
|
688
|
+
let newSessionPath;
|
|
689
|
+
if (sm) {
|
|
690
|
+
try {
|
|
691
|
+
const session = await sm.create(taskCwd, currentProvider, currentModel);
|
|
692
|
+
newSessionPath = session.path;
|
|
693
|
+
log("INFO", "tasks", "New session for task", { path: session.path });
|
|
694
|
+
}
|
|
695
|
+
catch {
|
|
696
|
+
// Session creation is best-effort.
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (sessionStore)
|
|
700
|
+
sessionStore.overlay = null;
|
|
701
|
+
resetUI?.({
|
|
702
|
+
wipeSession: true,
|
|
703
|
+
messages: newMessages,
|
|
704
|
+
history: [{ kind: "banner", id: "banner" }, taskItem],
|
|
705
|
+
sessionPath: newSessionPath,
|
|
706
|
+
pendingAction: { prompt: fullPrompt },
|
|
707
|
+
});
|
|
708
|
+
})();
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
clearPendingHistory();
|
|
712
|
+
setHistory([{ kind: "banner", id: "banner" }]);
|
|
713
|
+
setLiveItems([]);
|
|
714
|
+
messagesRef.current = messagesRef.current.slice(0, 1);
|
|
715
|
+
agentLoop.reset();
|
|
716
|
+
persistedIndexRef.current = messagesRef.current.length;
|
|
717
|
+
const sm = sessionManagerRef.current;
|
|
718
|
+
if (sm) {
|
|
719
|
+
void sm.create(taskCwd, currentProvider, currentModel).then((session) => {
|
|
720
|
+
sessionPathRef.current = session.path;
|
|
721
|
+
log("INFO", "tasks", "New session for task", { path: session.path });
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
const taskItem = { kind: "task", title, id: getId() };
|
|
725
|
+
setLastUserMessage(title);
|
|
726
|
+
setDoneStatus(null);
|
|
727
|
+
setLiveItems([taskItem]);
|
|
728
|
+
void agentLoop.run(fullPrompt).catch((err) => {
|
|
729
|
+
setLiveItems((prev) => [...prev, toErrorItem(err, getId())]);
|
|
730
|
+
});
|
|
731
|
+
}, [agentLoop, currentModel, currentProvider, resetUI, sessionStore]);
|
|
732
|
+
// Keep refs in sync for access from stale closures (onDone).
|
|
733
|
+
startTaskRef.current = startTask;
|
|
734
|
+
startGoalRunRef.current = startGoalRun;
|
|
735
|
+
return {
|
|
736
|
+
runGoalSyntheticEvent,
|
|
737
|
+
continueGoalRun,
|
|
738
|
+
handleGoalWorkerComplete,
|
|
739
|
+
startGoalRun,
|
|
740
|
+
verifyGoalRun,
|
|
741
|
+
pauseGoalRun,
|
|
742
|
+
startTask,
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
//# sourceMappingURL=useGoalOrchestration.js.map
|