Skip to content

Commit dcad61e

Browse files
committed
refactor(agent): improve notification handling and prompt processing
- Replace ctx.notify() with ctx.notifyImmediate() for immediate UI updates - Enhance NEXT action to use queued prompts when available - Prefer formatted stdout over raw JSON in agent execution - Add debug logging for chained prompts loading
1 parent 5e8f988 commit dcad61e

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/agents/runner/runner.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ export async function executeAgent(
407407
});
408408

409409
// Store output in memory
410-
const stdout = result.stdout || totalStdout;
410+
// Prefer totalStdout (formatted text from onData) over result.stdout (raw JSON)
411+
const stdout = totalStdout || result.stdout;
411412
const slice = stdout.slice(-2000);
412413
await store.append({
413414
agentId,
@@ -426,15 +427,16 @@ export async function executeAgent(
426427
// Always load on fresh execution; on resume, workflow.ts decides whether to use them
427428
// based on chain resume state (chainResumeInfo)
428429
let chainedPrompts: ChainedPrompt[] | undefined;
430+
debug(`[ChainedPrompts] agentConfig.chainedPromptsPath: ${agentConfig.chainedPromptsPath}`);
429431
if (agentConfig.chainedPromptsPath) {
430432
chainedPrompts = await loadChainedPrompts(
431433
agentConfig.chainedPromptsPath,
432434
projectRoot ?? workingDir,
433435
selectedConditions ?? []
434436
);
435-
if (chainedPrompts.length > 0) {
436-
debug(`Loaded ${chainedPrompts.length} chained prompts for agent '${agentId}'`);
437-
}
437+
debug(`[ChainedPrompts] Loaded ${chainedPrompts.length} chained prompts for agent '${agentId}'`);
438+
} else {
439+
debug(`[ChainedPrompts] No chainedPromptsPath for agent '${agentId}'`);
438440
}
439441

440442
return {

src/cli/tui/routes/workflow/context/ui-state/actions/agent-actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function createAgentActions(ctx: AgentActionsContext) {
5353
agent.id === agentId ? { ...agent, engine } : agent,
5454
),
5555
})
56-
ctx.notify()
56+
ctx.notifyImmediate()
5757
}
5858

5959
function updateAgentModel(agentId: string, model: string): void {
@@ -64,7 +64,7 @@ export function createAgentActions(ctx: AgentActionsContext) {
6464
agent.id === agentId ? { ...agent, model } : agent,
6565
),
6666
})
67-
ctx.notify()
67+
ctx.notifyImmediate()
6868
}
6969

7070
function updateAgentTelemetry(

src/workflows/input/controller.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,22 @@ export class ControllerInputProvider implements InputProvider {
143143
debug('[Controller] Action detected: %s', action);
144144

145145
switch (action) {
146-
case 'NEXT':
147-
this.emitter.emitReceived({ input: '', source: 'controller' });
148-
return { type: 'input', value: '' };
146+
case 'NEXT': {
147+
// Use next queued prompt content to advance
148+
const hasQueuedPrompt = context.promptQueue.length > 0 &&
149+
context.promptQueueIndex < context.promptQueue.length;
150+
const nextPrompt = hasQueuedPrompt
151+
? context.promptQueue[context.promptQueueIndex].content
152+
: '';
153+
debug('[Controller] ACTION: NEXT with prompt: %s', nextPrompt ? nextPrompt.slice(0, 50) + '...' : '(empty)');
154+
this.emitter.emitReceived({ input: nextPrompt, source: 'controller' });
155+
return {
156+
type: 'input',
157+
value: nextPrompt,
158+
resumeMonitoringId: context.stepOutput.monitoringId,
159+
source: 'controller',
160+
};
161+
}
149162
case 'SKIP':
150163
this.emitter.emitReceived({ input: '', source: 'controller' });
151164
return { type: 'skip' };

0 commit comments

Comments
 (0)