@golba98/codexa 1.0.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/README.md +320 -0
- package/bin/codexa.js +445 -0
- package/package.json +45 -0
- package/scripts/audit-codexa-capabilities.mjs +466 -0
- package/scripts/smoke-terminal-bench.mjs +35 -0
- package/src/app.tsx +4561 -0
- package/src/appRenderStability.test.ts +131 -0
- package/src/commands/handler.test.ts +643 -0
- package/src/commands/handler.ts +875 -0
- package/src/config/launchArgs.test.ts +158 -0
- package/src/config/launchArgs.ts +186 -0
- package/src/config/layeredConfig.test.ts +143 -0
- package/src/config/layeredConfig.ts +836 -0
- package/src/config/persistence.test.ts +110 -0
- package/src/config/persistence.ts +311 -0
- package/src/config/runtimeConfig.test.ts +218 -0
- package/src/config/runtimeConfig.ts +554 -0
- package/src/config/settings.test.ts +155 -0
- package/src/config/settings.ts +401 -0
- package/src/config/toml-serialize.ts +98 -0
- package/src/config/trustStore.test.ts +29 -0
- package/src/config/trustStore.ts +68 -0
- package/src/core/attachments.test.ts +155 -0
- package/src/core/attachments.ts +71 -0
- package/src/core/auth/codexAuth.test.ts +68 -0
- package/src/core/auth/codexAuth.ts +359 -0
- package/src/core/cleanupFastFail.test.ts +76 -0
- package/src/core/cleanupFastFail.ts +67 -0
- package/src/core/clipboard.ts +24 -0
- package/src/core/codex.ts +124 -0
- package/src/core/codexExecArgs.test.ts +195 -0
- package/src/core/codexExecArgs.ts +152 -0
- package/src/core/codexLaunch.test.ts +205 -0
- package/src/core/codexLaunch.ts +162 -0
- package/src/core/codexPrompt.test.ts +252 -0
- package/src/core/codexPrompt.ts +428 -0
- package/src/core/executables/claudeExecutable.ts +63 -0
- package/src/core/executables/codexExecutable.test.ts +212 -0
- package/src/core/executables/codexExecutable.ts +159 -0
- package/src/core/executables/executableResolver.test.ts +129 -0
- package/src/core/executables/executableResolver.ts +138 -0
- package/src/core/executables/geminiExecutable.test.ts +116 -0
- package/src/core/executables/geminiExecutable.ts +78 -0
- package/src/core/executables/pathSanityScan.test.ts +47 -0
- package/src/core/githubDiagnostics.test.ts +92 -0
- package/src/core/githubDiagnostics.ts +222 -0
- package/src/core/hollowResponseFormat.test.ts +58 -0
- package/src/core/hollowResponseFormat.ts +39 -0
- package/src/core/inputDebug.ts +51 -0
- package/src/core/launchContext.test.ts +157 -0
- package/src/core/launchContext.ts +266 -0
- package/src/core/models/codexCapabilities.test.ts +45 -0
- package/src/core/models/codexCapabilities.ts +95 -0
- package/src/core/models/codexModelCapabilities.test.ts +246 -0
- package/src/core/models/codexModelCapabilities.ts +571 -0
- package/src/core/models/modelSpecs.test.ts +283 -0
- package/src/core/models/modelSpecs.ts +300 -0
- package/src/core/perf/profiler.ts +125 -0
- package/src/core/perf/renderDebug.test.ts +230 -0
- package/src/core/perf/renderDebug.ts +373 -0
- package/src/core/planStorage.test.ts +143 -0
- package/src/core/planStorage.ts +141 -0
- package/src/core/process/CommandRunner.test.ts +105 -0
- package/src/core/process/CommandRunner.ts +269 -0
- package/src/core/process/processValidation.ts +101 -0
- package/src/core/projectInstructions.test.ts +50 -0
- package/src/core/projectInstructions.ts +54 -0
- package/src/core/providerLauncher/launcher.test.ts +238 -0
- package/src/core/providerLauncher/launcher.ts +203 -0
- package/src/core/providerLauncher/registry.test.ts +324 -0
- package/src/core/providerLauncher/registry.ts +253 -0
- package/src/core/providerLauncher/types.ts +84 -0
- package/src/core/providerLauncher/workspaceConfig.test.ts +638 -0
- package/src/core/providerLauncher/workspaceConfig.ts +407 -0
- package/src/core/providerRuntime/anthropic.test.ts +1120 -0
- package/src/core/providerRuntime/anthropic.ts +576 -0
- package/src/core/providerRuntime/capabilityProfile.test.ts +311 -0
- package/src/core/providerRuntime/capabilityProfile.ts +288 -0
- package/src/core/providerRuntime/claudeCodeDiscovery.ts +446 -0
- package/src/core/providerRuntime/contextMetadata.test.ts +468 -0
- package/src/core/providerRuntime/contextMetadata.ts +409 -0
- package/src/core/providerRuntime/gemini.test.ts +437 -0
- package/src/core/providerRuntime/gemini.ts +784 -0
- package/src/core/providerRuntime/lmstudio.test.ts +168 -0
- package/src/core/providerRuntime/lmstudio.ts +118 -0
- package/src/core/providerRuntime/local.test.ts +787 -0
- package/src/core/providerRuntime/local.ts +754 -0
- package/src/core/providerRuntime/models.ts +150 -0
- package/src/core/providerRuntime/reasoning.ts +17 -0
- package/src/core/providerRuntime/registry.test.ts +233 -0
- package/src/core/providerRuntime/registry.ts +203 -0
- package/src/core/providerRuntime/types.ts +103 -0
- package/src/core/providers/codexJsonStream.test.ts +148 -0
- package/src/core/providers/codexJsonStream.ts +305 -0
- package/src/core/providers/codexSubprocess.test.ts +68 -0
- package/src/core/providers/codexSubprocess.ts +372 -0
- package/src/core/providers/codexTranscript.test.ts +284 -0
- package/src/core/providers/codexTranscript.ts +695 -0
- package/src/core/providers/openaiNative.ts +13 -0
- package/src/core/providers/registry.ts +21 -0
- package/src/core/providers/types.ts +59 -0
- package/src/core/terminal/terminalCapabilities.test.ts +93 -0
- package/src/core/terminal/terminalCapabilities.ts +100 -0
- package/src/core/terminal/terminalControl.test.ts +75 -0
- package/src/core/terminal/terminalControl.ts +147 -0
- package/src/core/terminal/terminalSanitize.test.ts +22 -0
- package/src/core/terminal/terminalSanitize.ts +147 -0
- package/src/core/terminal/terminalSelection.test.ts +42 -0
- package/src/core/terminal/terminalSelection.ts +66 -0
- package/src/core/terminal/terminalTitle.test.ts +328 -0
- package/src/core/terminal/terminalTitle.ts +483 -0
- package/src/core/workspaceActivity.test.ts +163 -0
- package/src/core/workspaceActivity.ts +380 -0
- package/src/core/workspaceGuard.test.ts +151 -0
- package/src/core/workspaceGuard.ts +288 -0
- package/src/core/workspaceRoot.test.ts +23 -0
- package/src/core/workspaceRoot.ts +47 -0
- package/src/exec.test.ts +13 -0
- package/src/exec.ts +72 -0
- package/src/headless/execArgs.test.ts +147 -0
- package/src/headless/execArgs.ts +294 -0
- package/src/headless/execRunner.test.ts +434 -0
- package/src/headless/execRunner.ts +304 -0
- package/src/index.test.tsx +618 -0
- package/src/index.tsx +296 -0
- package/src/session/appSession.test.ts +897 -0
- package/src/session/appSession.ts +761 -0
- package/src/session/chatLifecycle.test.ts +64 -0
- package/src/session/chatLifecycle.ts +951 -0
- package/src/session/liveRenderScheduler.test.ts +201 -0
- package/src/session/liveRenderScheduler.ts +214 -0
- package/src/session/planFlow.test.ts +103 -0
- package/src/session/planFlow.ts +149 -0
- package/src/session/planTranscript.test.ts +65 -0
- package/src/session/planTranscript.ts +15 -0
- package/src/session/promptRunSchedule.test.ts +36 -0
- package/src/session/promptRunSchedule.ts +26 -0
- package/src/session/types.ts +228 -0
- package/src/test/runtimeTestUtils.ts +14 -0
- package/src/types/react-dom.d.ts +3 -0
- package/src/ui/ActionRequiredBlock.tsx +38 -0
- package/src/ui/ActivityBars.tsx +68 -0
- package/src/ui/ActivityIndicator.test.tsx +58 -0
- package/src/ui/ActivityIndicator.tsx +58 -0
- package/src/ui/AgentBlock.test.ts +6 -0
- package/src/ui/AgentBlock.tsx +130 -0
- package/src/ui/AnimatedStatusText.test.ts +16 -0
- package/src/ui/AnimatedStatusText.tsx +69 -0
- package/src/ui/AppShell.test.tsx +1739 -0
- package/src/ui/AppShell.tsx +698 -0
- package/src/ui/AttachmentImportPanel.test.tsx +204 -0
- package/src/ui/AttachmentImportPanel.tsx +98 -0
- package/src/ui/AuthPanel.tsx +113 -0
- package/src/ui/BackendPicker.tsx +28 -0
- package/src/ui/BottomComposer.test.ts +674 -0
- package/src/ui/BottomComposer.tsx +1028 -0
- package/src/ui/CodexLogo.tsx +55 -0
- package/src/ui/DashCard.tsx +82 -0
- package/src/ui/Markdown.test.ts +157 -0
- package/src/ui/Markdown.tsx +310 -0
- package/src/ui/ModePicker.tsx +27 -0
- package/src/ui/ModelPicker.tsx +31 -0
- package/src/ui/ModelPickerProviderScope.test.tsx +411 -0
- package/src/ui/ModelPickerScreen.test.tsx +99 -0
- package/src/ui/ModelPickerScreen.tsx +416 -0
- package/src/ui/ModelPickerState.test.tsx +151 -0
- package/src/ui/ModelReasoningPicker.test.tsx +447 -0
- package/src/ui/ModelReasoningPicker.tsx +458 -0
- package/src/ui/Panel.tsx +51 -0
- package/src/ui/PermissionsPanel.tsx +78 -0
- package/src/ui/PlanActionPicker.tsx +119 -0
- package/src/ui/PlanReviewPanel.test.tsx +267 -0
- package/src/ui/PlanReviewPanel.tsx +212 -0
- package/src/ui/PromptCardBorder.test.tsx +161 -0
- package/src/ui/ProviderPicker.test.tsx +289 -0
- package/src/ui/ProviderPicker.tsx +321 -0
- package/src/ui/ProviderShortcut.test.tsx +143 -0
- package/src/ui/ReasoningPicker.tsx +46 -0
- package/src/ui/RunFooter.tsx +65 -0
- package/src/ui/SelectionPanel.tsx +67 -0
- package/src/ui/SettingsPanel.test.tsx +233 -0
- package/src/ui/SettingsPanel.tsx +156 -0
- package/src/ui/Spinner.tsx +25 -0
- package/src/ui/StaticIntroItem.tsx +54 -0
- package/src/ui/StaticTranscriptItem.tsx +56 -0
- package/src/ui/TextEntryPanel.tsx +139 -0
- package/src/ui/ThemePicker.tsx +31 -0
- package/src/ui/ThinkingBlock.tsx +100 -0
- package/src/ui/Timeline.test.ts +2067 -0
- package/src/ui/Timeline.tsx +1472 -0
- package/src/ui/TimelineNavigation.test.tsx +201 -0
- package/src/ui/TopHeader.test.tsx +239 -0
- package/src/ui/TopHeader.tsx +257 -0
- package/src/ui/TurnGroup.test.tsx +365 -0
- package/src/ui/TurnGroup.tsx +657 -0
- package/src/ui/busyStatusAnimation.test.ts +30 -0
- package/src/ui/busyStatusAnimation.ts +11 -0
- package/src/ui/commandNormalize.test.ts +142 -0
- package/src/ui/commandNormalize.ts +66 -0
- package/src/ui/diffRenderer.test.ts +102 -0
- package/src/ui/diffRenderer.ts +116 -0
- package/src/ui/focus.ts +61 -0
- package/src/ui/focusFlow.test.tsx +1098 -0
- package/src/ui/inputBuffer.test.ts +151 -0
- package/src/ui/inputBuffer.ts +203 -0
- package/src/ui/layout.test.ts +145 -0
- package/src/ui/layout.ts +287 -0
- package/src/ui/modeDisplay.test.ts +42 -0
- package/src/ui/modeDisplay.ts +52 -0
- package/src/ui/outputPipeline.ts +64 -0
- package/src/ui/progressEntries.ts +156 -0
- package/src/ui/runActivityView.test.ts +89 -0
- package/src/ui/runActivityView.ts +37 -0
- package/src/ui/runLifecycleView.test.tsx +237 -0
- package/src/ui/slashCommands.ts +41 -0
- package/src/ui/statusRenderIsolation.test.tsx +654 -0
- package/src/ui/terminalAnswerFormat.test.ts +19 -0
- package/src/ui/terminalAnswerFormat.ts +128 -0
- package/src/ui/textLayout.test.ts +18 -0
- package/src/ui/textLayout.ts +338 -0
- package/src/ui/theme.tsx +395 -0
- package/src/ui/themeFlow.test.ts +53 -0
- package/src/ui/themeFlow.ts +41 -0
- package/src/ui/timelineMeasure.ts +3088 -0
- package/src/ui/timelineMeasureCache.test.ts +986 -0
- package/src/ui/useThrottledValue.ts +31 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createLiveRenderScheduler, type LiveRenderUpdate } from "./liveRenderScheduler.js";
|
|
4
|
+
|
|
5
|
+
type FakeTimer = {
|
|
6
|
+
callback: () => void;
|
|
7
|
+
delayMs: number;
|
|
8
|
+
cleared: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function createFakeTimers() {
|
|
12
|
+
const timers: FakeTimer[] = [];
|
|
13
|
+
return {
|
|
14
|
+
timers,
|
|
15
|
+
setTimer(callback: () => void, delayMs: number) {
|
|
16
|
+
const timer: FakeTimer = { callback, delayMs, cleared: false };
|
|
17
|
+
timers.push(timer);
|
|
18
|
+
return timer as unknown as ReturnType<typeof setTimeout>;
|
|
19
|
+
},
|
|
20
|
+
clearTimer(timer: ReturnType<typeof setTimeout>) {
|
|
21
|
+
(timer as unknown as FakeTimer).cleared = true;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function progress(id: string, text: string): LiveRenderUpdate {
|
|
27
|
+
return { type: "progress", update: { id, source: "reasoning", text } };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function tool(id: string, status: "running" | "completed"): LiveRenderUpdate {
|
|
31
|
+
return {
|
|
32
|
+
type: "tool",
|
|
33
|
+
activity: {
|
|
34
|
+
id,
|
|
35
|
+
command: "Get-Content README.md",
|
|
36
|
+
status,
|
|
37
|
+
startedAt: 1,
|
|
38
|
+
completedAt: status === "completed" ? 2 : undefined,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test("coalesces adjacent assistant chunks at the cadence flush", () => {
|
|
44
|
+
const flushed: LiveRenderUpdate[][] = [];
|
|
45
|
+
const fakeTimers = createFakeTimers();
|
|
46
|
+
const scheduler = createLiveRenderScheduler({
|
|
47
|
+
assistantFlushMs: 50,
|
|
48
|
+
progressOnlyFlushMs: 50,
|
|
49
|
+
flush: (updates) => flushed.push(updates),
|
|
50
|
+
setTimer: fakeTimers.setTimer,
|
|
51
|
+
clearTimer: fakeTimers.clearTimer,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
scheduler.enqueue({ type: "assistant", chunk: "Hello" });
|
|
55
|
+
scheduler.enqueue({ type: "assistant", chunk: ", world" });
|
|
56
|
+
|
|
57
|
+
assert.equal(flushed.length, 0);
|
|
58
|
+
assert.equal(fakeTimers.timers.length, 1);
|
|
59
|
+
assert.equal(fakeTimers.timers[0]?.delayMs, 50);
|
|
60
|
+
fakeTimers.timers[0]!.callback();
|
|
61
|
+
|
|
62
|
+
assert.equal(flushed.length, 1);
|
|
63
|
+
assert.deepEqual(flushed[0], [{ type: "assistant", chunk: "Hello, world" }]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("first progress-only update waits for the progress cadence", () => {
|
|
67
|
+
const flushed: LiveRenderUpdate[][] = [];
|
|
68
|
+
const fakeTimers = createFakeTimers();
|
|
69
|
+
const scheduler = createLiveRenderScheduler({
|
|
70
|
+
assistantFlushMs: 50,
|
|
71
|
+
progressOnlyFlushMs: 50,
|
|
72
|
+
flush: (updates) => flushed.push(updates),
|
|
73
|
+
setTimer: fakeTimers.setTimer,
|
|
74
|
+
clearTimer: fakeTimers.clearTimer,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
scheduler.enqueue(tool("t1", "running"));
|
|
78
|
+
|
|
79
|
+
assert.equal(flushed.length, 0);
|
|
80
|
+
assert.equal(fakeTimers.timers.length, 1);
|
|
81
|
+
assert.equal(fakeTimers.timers[0]?.delayMs, 50);
|
|
82
|
+
|
|
83
|
+
fakeTimers.timers[0]!.callback();
|
|
84
|
+
assert.deepEqual(flushed[0]?.map((update) => update.type), ["tool"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("preserves event order while keeping only the latest same-id progress update", () => {
|
|
88
|
+
const flushed: LiveRenderUpdate[][] = [];
|
|
89
|
+
const scheduler = createLiveRenderScheduler({
|
|
90
|
+
assistantFlushMs: 50,
|
|
91
|
+
progressOnlyFlushMs: 50,
|
|
92
|
+
flush: (updates) => flushed.push(updates),
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
scheduler.enqueue(progress("p1", "Thinking"));
|
|
96
|
+
scheduler.enqueue(tool("t1", "running"));
|
|
97
|
+
scheduler.enqueue({ type: "assistant", chunk: "First" });
|
|
98
|
+
scheduler.enqueue({ type: "assistant", chunk: " segment" });
|
|
99
|
+
scheduler.enqueue(progress("p1", "Thinking harder"));
|
|
100
|
+
scheduler.flushNow();
|
|
101
|
+
|
|
102
|
+
assert.deepEqual(flushed[0]?.map((update) => update.type), ["progress", "tool", "assistant"]);
|
|
103
|
+
assert.equal((flushed[0]?.[2] as Extract<LiveRenderUpdate, { type: "assistant" }>).chunk, "First segment");
|
|
104
|
+
assert.equal((flushed[0]?.[0] as Extract<LiveRenderUpdate, { type: "progress" }>).update.text, "Thinking harder");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("coalesces repeated keyed progress and tool updates across a noisy flush window", () => {
|
|
108
|
+
const flushed: LiveRenderUpdate[][] = [];
|
|
109
|
+
const scheduler = createLiveRenderScheduler({
|
|
110
|
+
assistantFlushMs: 50,
|
|
111
|
+
progressOnlyFlushMs: 175,
|
|
112
|
+
flush: (updates) => flushed.push(updates),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
scheduler.enqueue(progress("p1", "Reading file 1"));
|
|
116
|
+
scheduler.enqueue(tool("t1", "running"));
|
|
117
|
+
scheduler.enqueue(progress("p1", "Reading file 2"));
|
|
118
|
+
scheduler.enqueue(tool("t1", "completed"));
|
|
119
|
+
scheduler.enqueue(progress("p2", "Listing files"));
|
|
120
|
+
scheduler.flushNow();
|
|
121
|
+
|
|
122
|
+
assert.deepEqual(flushed[0]?.map((update) => update.type), ["progress", "tool", "progress"]);
|
|
123
|
+
assert.equal((flushed[0]?.[0] as Extract<LiveRenderUpdate, { type: "progress" }>).update.text, "Reading file 2");
|
|
124
|
+
assert.equal((flushed[0]?.[1] as Extract<LiveRenderUpdate, { type: "tool" }>).activity.status, "completed");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("records scheduler flush diagnostics", () => {
|
|
128
|
+
const flushed: LiveRenderUpdate[][] = [];
|
|
129
|
+
const fakeTimers = createFakeTimers();
|
|
130
|
+
const scheduler = createLiveRenderScheduler({
|
|
131
|
+
assistantFlushMs: 50,
|
|
132
|
+
progressOnlyFlushMs: 175,
|
|
133
|
+
flush: (updates) => flushed.push(updates),
|
|
134
|
+
setTimer: fakeTimers.setTimer,
|
|
135
|
+
clearTimer: fakeTimers.clearTimer,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
scheduler.enqueue(progress("p1", "Listing files"));
|
|
139
|
+
assert.equal(scheduler.getStats().providerEvents, 1);
|
|
140
|
+
assert.equal(fakeTimers.timers[0]?.delayMs, 175);
|
|
141
|
+
fakeTimers.timers[0]!.callback();
|
|
142
|
+
|
|
143
|
+
scheduler.enqueue({ type: "assistant", chunk: "hello" });
|
|
144
|
+
assert.equal(fakeTimers.timers[1]?.delayMs, 50);
|
|
145
|
+
fakeTimers.timers[1]!.callback();
|
|
146
|
+
|
|
147
|
+
const stats = scheduler.getStats();
|
|
148
|
+
assert.equal(stats.providerEvents, 2);
|
|
149
|
+
assert.equal(stats.flushes, 2);
|
|
150
|
+
assert.ok(stats.maxFlushIntervalMs >= 0);
|
|
151
|
+
assert.ok(stats.averageFlushIntervalMs >= 0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("prevents reentrant flushes when a producer enqueues during a flush", () => {
|
|
155
|
+
const flushed: LiveRenderUpdate[][] = [];
|
|
156
|
+
let inFlush = false;
|
|
157
|
+
let scheduler: ReturnType<typeof createLiveRenderScheduler>;
|
|
158
|
+
|
|
159
|
+
scheduler = createLiveRenderScheduler({
|
|
160
|
+
assistantFlushMs: 50,
|
|
161
|
+
progressOnlyFlushMs: 50,
|
|
162
|
+
flush: (updates) => {
|
|
163
|
+
assert.equal(inFlush, false, "flush should not reenter itself");
|
|
164
|
+
inFlush = true;
|
|
165
|
+
flushed.push(updates);
|
|
166
|
+
if (flushed.length === 1) {
|
|
167
|
+
scheduler.enqueue({ type: "assistant", chunk: "queued during flush" });
|
|
168
|
+
}
|
|
169
|
+
inFlush = false;
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
scheduler.enqueue({ type: "assistant", chunk: "first" });
|
|
174
|
+
|
|
175
|
+
assert.equal(scheduler.flushNow(), true);
|
|
176
|
+
assert.equal(flushed.length, 2);
|
|
177
|
+
assert.equal((flushed[0]?.[0] as Extract<LiveRenderUpdate, { type: "assistant" }>).chunk, "first");
|
|
178
|
+
assert.equal((flushed[1]?.[0] as Extract<LiveRenderUpdate, { type: "assistant" }>).chunk, "queued during flush");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("flushNow drains queued updates before finalization", () => {
|
|
182
|
+
const flushed: LiveRenderUpdate[][] = [];
|
|
183
|
+
const fakeTimers = createFakeTimers();
|
|
184
|
+
const scheduler = createLiveRenderScheduler({
|
|
185
|
+
assistantFlushMs: 50,
|
|
186
|
+
progressOnlyFlushMs: 50,
|
|
187
|
+
flush: (updates) => flushed.push(updates),
|
|
188
|
+
setTimer: fakeTimers.setTimer,
|
|
189
|
+
clearTimer: fakeTimers.clearTimer,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
scheduler.enqueue({ type: "assistant", chunk: "final chunk" });
|
|
193
|
+
|
|
194
|
+
assert.equal(scheduler.flushNow(), true);
|
|
195
|
+
assert.equal(flushed.length, 1);
|
|
196
|
+
assert.equal(scheduler.hasPendingUpdates(), false);
|
|
197
|
+
|
|
198
|
+
assert.equal(fakeTimers.timers[0]?.cleared, true);
|
|
199
|
+
fakeTimers.timers[0]?.callback();
|
|
200
|
+
assert.equal(flushed.length, 1);
|
|
201
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { BackendProgressUpdate } from "../core/providers/types.js";
|
|
2
|
+
import type { RunFileActivity } from "../core/workspaceActivity.js";
|
|
3
|
+
import type { RunToolActivity } from "./types.js";
|
|
4
|
+
import * as renderDebug from "../core/perf/renderDebug.js";
|
|
5
|
+
|
|
6
|
+
export type LiveRenderUpdate =
|
|
7
|
+
| { type: "assistant"; chunk: string }
|
|
8
|
+
| { type: "plan"; chunk: string }
|
|
9
|
+
| { type: "progress"; update: BackendProgressUpdate }
|
|
10
|
+
| { type: "activity"; activity: RunFileActivity[] }
|
|
11
|
+
| { type: "tool"; activity: RunToolActivity };
|
|
12
|
+
|
|
13
|
+
type TimerHandle = ReturnType<typeof setTimeout>;
|
|
14
|
+
|
|
15
|
+
export interface LiveRenderSchedulerOptions {
|
|
16
|
+
flush: (updates: LiveRenderUpdate[]) => void;
|
|
17
|
+
assistantFlushMs: number;
|
|
18
|
+
progressOnlyFlushMs: number;
|
|
19
|
+
setTimer?: (callback: () => void, delayMs: number) => TimerHandle;
|
|
20
|
+
clearTimer?: (timer: TimerHandle) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LiveRenderScheduler {
|
|
24
|
+
enqueue: (update: LiveRenderUpdate) => void;
|
|
25
|
+
flushNow: () => boolean;
|
|
26
|
+
cancel: () => void;
|
|
27
|
+
hasPendingUpdates: () => boolean;
|
|
28
|
+
getStats: () => LiveRenderSchedulerStats;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface LiveRenderSchedulerStats {
|
|
32
|
+
providerEvents: number;
|
|
33
|
+
flushes: number;
|
|
34
|
+
averageFlushIntervalMs: number;
|
|
35
|
+
maxFlushIntervalMs: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ─── Update coalescing ───────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
function findPendingUpdateIndex(
|
|
41
|
+
updates: LiveRenderUpdate[],
|
|
42
|
+
predicate: (update: LiveRenderUpdate) => boolean,
|
|
43
|
+
): number {
|
|
44
|
+
for (let index = updates.length - 1; index >= 0; index -= 1) {
|
|
45
|
+
if (predicate(updates[index]!)) return index;
|
|
46
|
+
}
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function mergeLiveRenderUpdate(updates: LiveRenderUpdate[], update: LiveRenderUpdate): boolean {
|
|
51
|
+
const previous = updates[updates.length - 1];
|
|
52
|
+
|
|
53
|
+
if (update.type === "assistant" || update.type === "plan") {
|
|
54
|
+
if (previous?.type === update.type) {
|
|
55
|
+
previous.chunk += update.chunk;
|
|
56
|
+
} else {
|
|
57
|
+
updates.push({ ...update });
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (update.type === "progress") {
|
|
63
|
+
const index = findPendingUpdateIndex(
|
|
64
|
+
updates,
|
|
65
|
+
(pending) => pending.type === "progress" && pending.update.id === update.update.id,
|
|
66
|
+
);
|
|
67
|
+
if (index >= 0 && updates[index]?.type === "progress") {
|
|
68
|
+
updates[index] = update;
|
|
69
|
+
} else {
|
|
70
|
+
updates.push(update);
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (update.type === "tool") {
|
|
76
|
+
const index = findPendingUpdateIndex(
|
|
77
|
+
updates,
|
|
78
|
+
(pending) => pending.type === "tool" && pending.activity.id === update.activity.id,
|
|
79
|
+
);
|
|
80
|
+
if (index >= 0 && updates[index]?.type === "tool") {
|
|
81
|
+
const previousTool = updates[index];
|
|
82
|
+
updates[index] = {
|
|
83
|
+
type: "tool",
|
|
84
|
+
activity: { ...previousTool.activity, ...update.activity },
|
|
85
|
+
};
|
|
86
|
+
} else {
|
|
87
|
+
updates.push(update);
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const activityIndex = findPendingUpdateIndex(updates, (pending) => pending.type === "activity");
|
|
93
|
+
if (activityIndex >= 0 && updates[activityIndex]?.type === "activity") {
|
|
94
|
+
updates[activityIndex].activity.push(...update.activity);
|
|
95
|
+
} else {
|
|
96
|
+
updates.push({ type: "activity", activity: [...update.activity] });
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ─── Scheduler ───────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
export function createLiveRenderScheduler({
|
|
104
|
+
flush,
|
|
105
|
+
assistantFlushMs,
|
|
106
|
+
progressOnlyFlushMs,
|
|
107
|
+
setTimer = setTimeout,
|
|
108
|
+
clearTimer = clearTimeout,
|
|
109
|
+
}: LiveRenderSchedulerOptions): LiveRenderScheduler {
|
|
110
|
+
let pendingUpdates: LiveRenderUpdate[] = [];
|
|
111
|
+
let hasPendingAssistantDelta = false;
|
|
112
|
+
let timer: TimerHandle | null = null;
|
|
113
|
+
let isFlushing = false;
|
|
114
|
+
let flushAgain = false;
|
|
115
|
+
let providerEvents = 0;
|
|
116
|
+
let flushes = 0;
|
|
117
|
+
let totalFlushIntervalMs = 0;
|
|
118
|
+
let maxFlushIntervalMs = 0;
|
|
119
|
+
let lastFlushMonotonicMs: number | null = null;
|
|
120
|
+
|
|
121
|
+
const cancelScheduledFlush = () => {
|
|
122
|
+
if (timer) {
|
|
123
|
+
clearTimer(timer);
|
|
124
|
+
timer = null;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const drain = (): boolean => {
|
|
129
|
+
if (isFlushing) {
|
|
130
|
+
flushAgain = true;
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
cancelScheduledFlush();
|
|
135
|
+
|
|
136
|
+
if (pendingUpdates.length === 0) {
|
|
137
|
+
hasPendingAssistantDelta = false;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
isFlushing = true;
|
|
142
|
+
let flushed = false;
|
|
143
|
+
try {
|
|
144
|
+
do {
|
|
145
|
+
flushAgain = false;
|
|
146
|
+
const updates = pendingUpdates;
|
|
147
|
+
pendingUpdates = [];
|
|
148
|
+
hasPendingAssistantDelta = false;
|
|
149
|
+
if (updates.length > 0) {
|
|
150
|
+
flushed = true;
|
|
151
|
+
const startedAt = performance.now();
|
|
152
|
+
flush(updates);
|
|
153
|
+
flushes += 1;
|
|
154
|
+
if (lastFlushMonotonicMs !== null) {
|
|
155
|
+
const intervalMs = Math.max(0, Math.round(startedAt - lastFlushMonotonicMs));
|
|
156
|
+
totalFlushIntervalMs += intervalMs;
|
|
157
|
+
maxFlushIntervalMs = Math.max(maxFlushIntervalMs, intervalMs);
|
|
158
|
+
}
|
|
159
|
+
lastFlushMonotonicMs = startedAt;
|
|
160
|
+
renderDebug.traceSchedulerFlush({
|
|
161
|
+
reason: updates.some((update) => update.type === "assistant" || update.type === "plan") ? "stream" : "progress",
|
|
162
|
+
updates: updates.length,
|
|
163
|
+
assistantChunks: updates.filter((update) => update.type === "assistant").length,
|
|
164
|
+
progressUpdates: updates.filter((update) => update.type === "progress").length,
|
|
165
|
+
toolUpdates: updates.filter((update) => update.type === "tool").length,
|
|
166
|
+
activityUpdates: updates.filter((update) => update.type === "activity").length,
|
|
167
|
+
durationMs: Math.round(performance.now() - startedAt),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
} while (flushAgain || pendingUpdates.length > 0);
|
|
171
|
+
} finally {
|
|
172
|
+
isFlushing = false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return flushed;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const schedule = () => {
|
|
179
|
+
if (timer || isFlushing) return;
|
|
180
|
+
|
|
181
|
+
const interval = hasPendingAssistantDelta ? assistantFlushMs : progressOnlyFlushMs;
|
|
182
|
+
timer = setTimer(() => {
|
|
183
|
+
timer = null;
|
|
184
|
+
drain();
|
|
185
|
+
}, interval);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
enqueue(update) {
|
|
190
|
+
providerEvents += 1;
|
|
191
|
+
const addedAssistant = mergeLiveRenderUpdate(pendingUpdates, update);
|
|
192
|
+
hasPendingAssistantDelta ||= addedAssistant;
|
|
193
|
+
schedule();
|
|
194
|
+
},
|
|
195
|
+
flushNow: drain,
|
|
196
|
+
cancel() {
|
|
197
|
+
cancelScheduledFlush();
|
|
198
|
+
pendingUpdates = [];
|
|
199
|
+
hasPendingAssistantDelta = false;
|
|
200
|
+
},
|
|
201
|
+
hasPendingUpdates() {
|
|
202
|
+
return pendingUpdates.length > 0;
|
|
203
|
+
},
|
|
204
|
+
getStats() {
|
|
205
|
+
const intervalCount = Math.max(0, flushes - 1);
|
|
206
|
+
return {
|
|
207
|
+
providerEvents,
|
|
208
|
+
flushes,
|
|
209
|
+
averageFlushIntervalMs: intervalCount > 0 ? Math.round(totalFlushIntervalMs / intervalCount) : 0,
|
|
210
|
+
maxFlushIntervalMs,
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
approvePlanExecution,
|
|
5
|
+
beginPlanFeedback,
|
|
6
|
+
cancelPlanFeedback,
|
|
7
|
+
createInitialPlanFlowState,
|
|
8
|
+
finishPlanGeneration,
|
|
9
|
+
resetPlanFlow,
|
|
10
|
+
startPlanGeneration,
|
|
11
|
+
submitPlanFeedback,
|
|
12
|
+
} from "./planFlow.js";
|
|
13
|
+
|
|
14
|
+
test("starts a fresh plan generation flow from idle", () => {
|
|
15
|
+
const state = startPlanGeneration("Build a hello world script", "auto-edit");
|
|
16
|
+
|
|
17
|
+
assert.deepEqual(createInitialPlanFlowState(), { kind: "idle" });
|
|
18
|
+
assert.equal(state.kind, "generating");
|
|
19
|
+
assert.equal(state.originalPrompt, "Build a hello world script");
|
|
20
|
+
assert.equal(state.executionMode, "auto-edit");
|
|
21
|
+
assert.deepEqual(state.constraints, []);
|
|
22
|
+
assert.equal(state.planFilePath, null);
|
|
23
|
+
assert.equal(state.currentPlan, null);
|
|
24
|
+
assert.equal(state.pendingFeedback, null);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("finishes plan generation into an awaiting-action state with a plan file path", () => {
|
|
28
|
+
const state = finishPlanGeneration(
|
|
29
|
+
startPlanGeneration("Build a hello world script", "auto-edit"),
|
|
30
|
+
"## Files\n- hello_world.py",
|
|
31
|
+
"C:\\Workspace\\.codexa\\last-plan.md",
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
assert.equal(state.kind, "awaiting_action");
|
|
35
|
+
assert.equal(state.currentPlan, "## Files\n- hello_world.py");
|
|
36
|
+
assert.equal(state.planFilePath, "C:\\Workspace\\.codexa\\last-plan.md");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("revising the plan keeps constraints and records revision feedback", () => {
|
|
40
|
+
const awaiting = finishPlanGeneration(
|
|
41
|
+
startPlanGeneration("Build a hello world script", "auto-edit"),
|
|
42
|
+
"Plan v1",
|
|
43
|
+
"C:\\Workspace\\.codexa\\last-plan.md",
|
|
44
|
+
);
|
|
45
|
+
const collecting = beginPlanFeedback(awaiting, "revise");
|
|
46
|
+
const generating = submitPlanFeedback(collecting, "Keep it to a single file.");
|
|
47
|
+
|
|
48
|
+
assert.equal(collecting.kind, "collecting_feedback");
|
|
49
|
+
assert.equal(collecting.mode, "revise");
|
|
50
|
+
assert.equal(generating.kind, "generating");
|
|
51
|
+
assert.equal(generating.currentPlan, "Plan v1");
|
|
52
|
+
assert.equal(generating.planFilePath, "C:\\Workspace\\.codexa\\last-plan.md");
|
|
53
|
+
assert.deepEqual(generating.constraints, []);
|
|
54
|
+
assert.deepEqual(generating.pendingFeedback, {
|
|
55
|
+
mode: "revise",
|
|
56
|
+
text: "Keep it to a single file.",
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("adding constraints accumulates them before the next plan pass", () => {
|
|
61
|
+
const awaiting = finishPlanGeneration(
|
|
62
|
+
startPlanGeneration("Build a hello world script", "auto-edit"),
|
|
63
|
+
"Plan v1",
|
|
64
|
+
"C:\\Workspace\\.codexa\\last-plan.md",
|
|
65
|
+
);
|
|
66
|
+
const collecting = beginPlanFeedback(awaiting, "constraints");
|
|
67
|
+
const generating = submitPlanFeedback(collecting, "Do not touch any other files.");
|
|
68
|
+
|
|
69
|
+
assert.equal(generating.kind, "generating");
|
|
70
|
+
assert.deepEqual(generating.constraints, ["Do not touch any other files."]);
|
|
71
|
+
assert.deepEqual(generating.pendingFeedback, {
|
|
72
|
+
mode: "constraints",
|
|
73
|
+
text: "Do not touch any other files.",
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("canceling feedback returns to the action picker without losing the plan", () => {
|
|
78
|
+
const awaiting = finishPlanGeneration(
|
|
79
|
+
startPlanGeneration("Build a hello world script", "auto-edit"),
|
|
80
|
+
"Plan v1",
|
|
81
|
+
"C:\\Workspace\\.codexa\\last-plan.md",
|
|
82
|
+
);
|
|
83
|
+
const collecting = beginPlanFeedback(awaiting, "revise");
|
|
84
|
+
const canceled = cancelPlanFeedback(collecting);
|
|
85
|
+
|
|
86
|
+
assert.equal(canceled.kind, "awaiting_action");
|
|
87
|
+
assert.equal(canceled.currentPlan, "Plan v1");
|
|
88
|
+
assert.equal(canceled.planFilePath, "C:\\Workspace\\.codexa\\last-plan.md");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("approving execution moves to executing and reset returns to idle", () => {
|
|
92
|
+
const awaiting = finishPlanGeneration(
|
|
93
|
+
startPlanGeneration("Build a hello world script", "auto-edit"),
|
|
94
|
+
"Plan v1",
|
|
95
|
+
"C:\\Workspace\\.codexa\\last-plan.md",
|
|
96
|
+
);
|
|
97
|
+
const executing = approvePlanExecution(awaiting);
|
|
98
|
+
|
|
99
|
+
assert.equal(executing.kind, "executing");
|
|
100
|
+
assert.equal(executing.executionMode, "auto-edit");
|
|
101
|
+
assert.equal(executing.planFilePath, "C:\\Workspace\\.codexa\\last-plan.md");
|
|
102
|
+
assert.deepEqual(resetPlanFlow(), { kind: "idle" });
|
|
103
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { AvailableMode } from "../config/settings.js";
|
|
2
|
+
|
|
3
|
+
export type PlanFeedbackMode = "revise" | "constraints";
|
|
4
|
+
|
|
5
|
+
export interface PlanFeedbackRequest {
|
|
6
|
+
mode: PlanFeedbackMode;
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface PlanFlowContext {
|
|
11
|
+
originalPrompt: string;
|
|
12
|
+
executionMode: AvailableMode;
|
|
13
|
+
constraints: string[];
|
|
14
|
+
planFilePath: string | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type PlanFlowState =
|
|
18
|
+
| { kind: "idle" }
|
|
19
|
+
| (PlanFlowContext & {
|
|
20
|
+
kind: "generating";
|
|
21
|
+
currentPlan: string | null;
|
|
22
|
+
pendingFeedback: PlanFeedbackRequest | null;
|
|
23
|
+
})
|
|
24
|
+
| (PlanFlowContext & {
|
|
25
|
+
kind: "awaiting_action";
|
|
26
|
+
currentPlan: string;
|
|
27
|
+
})
|
|
28
|
+
| (PlanFlowContext & {
|
|
29
|
+
kind: "collecting_feedback";
|
|
30
|
+
currentPlan: string;
|
|
31
|
+
mode: PlanFeedbackMode;
|
|
32
|
+
})
|
|
33
|
+
| (PlanFlowContext & {
|
|
34
|
+
kind: "executing";
|
|
35
|
+
currentPlan: string;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type PlanGeneratingState = Extract<PlanFlowState, { kind: "generating" }>;
|
|
39
|
+
export type PlanAwaitingActionState = Extract<PlanFlowState, { kind: "awaiting_action" }>;
|
|
40
|
+
export type PlanCollectingFeedbackState = Extract<PlanFlowState, { kind: "collecting_feedback" }>;
|
|
41
|
+
export type PlanExecutingState = Extract<PlanFlowState, { kind: "executing" }>;
|
|
42
|
+
|
|
43
|
+
export function createInitialPlanFlowState(): PlanFlowState {
|
|
44
|
+
return { kind: "idle" };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function startPlanGeneration(originalPrompt: string, executionMode: AvailableMode): PlanGeneratingState {
|
|
48
|
+
return {
|
|
49
|
+
kind: "generating",
|
|
50
|
+
originalPrompt,
|
|
51
|
+
executionMode,
|
|
52
|
+
constraints: [],
|
|
53
|
+
planFilePath: null,
|
|
54
|
+
currentPlan: null,
|
|
55
|
+
pendingFeedback: null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function finishPlanGeneration(
|
|
60
|
+
state: PlanFlowState,
|
|
61
|
+
currentPlan: string,
|
|
62
|
+
planFilePath: string | null,
|
|
63
|
+
): PlanFlowState {
|
|
64
|
+
if (state.kind !== "generating") {
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
kind: "awaiting_action",
|
|
70
|
+
originalPrompt: state.originalPrompt,
|
|
71
|
+
executionMode: state.executionMode,
|
|
72
|
+
constraints: state.constraints,
|
|
73
|
+
currentPlan,
|
|
74
|
+
planFilePath,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function beginPlanFeedback(state: PlanFlowState, mode: PlanFeedbackMode): PlanFlowState {
|
|
79
|
+
if (state.kind !== "awaiting_action") {
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
kind: "collecting_feedback",
|
|
85
|
+
originalPrompt: state.originalPrompt,
|
|
86
|
+
executionMode: state.executionMode,
|
|
87
|
+
constraints: state.constraints,
|
|
88
|
+
currentPlan: state.currentPlan,
|
|
89
|
+
planFilePath: state.planFilePath,
|
|
90
|
+
mode,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function submitPlanFeedback(state: PlanFlowState, text: string): PlanFlowState {
|
|
95
|
+
if (state.kind !== "collecting_feedback") {
|
|
96
|
+
return state;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const nextConstraints = state.mode === "constraints"
|
|
100
|
+
? [...state.constraints, text]
|
|
101
|
+
: state.constraints;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
kind: "generating",
|
|
105
|
+
originalPrompt: state.originalPrompt,
|
|
106
|
+
executionMode: state.executionMode,
|
|
107
|
+
constraints: nextConstraints,
|
|
108
|
+
planFilePath: state.planFilePath,
|
|
109
|
+
currentPlan: state.currentPlan,
|
|
110
|
+
pendingFeedback: {
|
|
111
|
+
mode: state.mode,
|
|
112
|
+
text,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function cancelPlanFeedback(state: PlanFlowState): PlanFlowState {
|
|
118
|
+
if (state.kind !== "collecting_feedback") {
|
|
119
|
+
return state;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
kind: "awaiting_action",
|
|
124
|
+
originalPrompt: state.originalPrompt,
|
|
125
|
+
executionMode: state.executionMode,
|
|
126
|
+
constraints: state.constraints,
|
|
127
|
+
currentPlan: state.currentPlan,
|
|
128
|
+
planFilePath: state.planFilePath,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function approvePlanExecution(state: PlanFlowState): PlanFlowState {
|
|
133
|
+
if (state.kind !== "awaiting_action") {
|
|
134
|
+
return state;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
kind: "executing",
|
|
139
|
+
originalPrompt: state.originalPrompt,
|
|
140
|
+
executionMode: state.executionMode,
|
|
141
|
+
constraints: state.constraints,
|
|
142
|
+
currentPlan: state.currentPlan,
|
|
143
|
+
planFilePath: state.planFilePath,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function resetPlanFlow(): PlanFlowState {
|
|
148
|
+
return createInitialPlanFlowState();
|
|
149
|
+
}
|