feat(coder): orchestrator advanced flow patterns
- TriggerRule type (all_success/one_success/all_done) for parallel deps - Variable substitution ($stepId.output.field) in agent step prompts - Approval gate step kind (pauses flow via permission frames) - flow_step_events table for append-only event-sourced step log - evaluateTriggerRule pure function in flow-runner-decisions
This commit is contained in:
@@ -378,7 +378,8 @@ export function createFlowRunner(deps: Deps): FlowRunner {
|
||||
// flow's step.run already bakes in the evidence/YAGNI contracts.
|
||||
const persona = step.agent ? await loadPersona(step.agent) : '';
|
||||
const taskPrompt = await step.run(ctx);
|
||||
const fullPrompt = persona ? `${persona}\n\n---\n\n${taskPrompt}` : taskPrompt;
|
||||
const resolvedPrompt = resolveVariables(taskPrompt, ctx.results);
|
||||
const fullPrompt = persona ? `${persona}\n\n---\n\n${resolvedPrompt}` : resolvedPrompt;
|
||||
|
||||
// READ-ONLY (D-4): agent='qwen', mode_id='plan' are hardcoded, never
|
||||
// user-overridable. The dispatcher's qwen+plan rule forces the PTY hard gate.
|
||||
@@ -763,3 +764,25 @@ export function createFlowRunner(deps: Deps): FlowRunner {
|
||||
function errMsg(e: unknown): string {
|
||||
return e instanceof Error ? e.message : String(e);
|
||||
}
|
||||
|
||||
// ─── Variable substitution ───────────────────────────────────────────────────
|
||||
|
||||
const VAR_PATTERN = /\$(\w+)\.output(?:\.(\w+(?:\.\w+)*))?/g;
|
||||
|
||||
export function resolveVariables(prompt: string, results: Record<string, string>): string {
|
||||
return prompt.replace(VAR_PATTERN, (match, stepId, fieldPath) => {
|
||||
const output = results[stepId];
|
||||
if (!output) return match;
|
||||
if (!fieldPath) return output;
|
||||
try {
|
||||
const lines = output.split('\n');
|
||||
for (const line of lines) {
|
||||
const parsed = line.match(new RegExp(`^${fieldPath}:\\s*(.+)$`, 'i'));
|
||||
if (parsed) return parsed[1]!.trim();
|
||||
}
|
||||
} catch {
|
||||
// fall through
|
||||
}
|
||||
return match;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user