Skip to content

Commit b021c11

Browse files
committed
feat(workflow): add engine authentication fallback logic
Implement fallback mechanism when specified engine is not authenticated. The system will now: - Check if override engine is authenticated - Fall back to first authenticated engine if needed - Use registry default as last resort - Log appropriate messages for each scenario
1 parent d2da55c commit b021c11

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/workflows/execution/workflow.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,44 @@ export async function runWorkflow(options: RunWorkflowOptions = {}): Promise<voi
8888
let engineType: string;
8989
if (step.engine) {
9090
engineType = step.engine;
91+
92+
// If an override is provided but not authenticated, log and fall back
93+
const overrideEngine = registry.get(engineType);
94+
const isOverrideAuthed = overrideEngine ? await overrideEngine.auth.isAuthenticated() : false;
95+
if (!isOverrideAuthed) {
96+
const pretty = overrideEngine?.metadata.name ?? engineType;
97+
console.error(
98+
formatAgentLog(
99+
step.agentId,
100+
`${pretty} override is not authenticated; falling back to first authenticated engine by order. Run 'codemachine auth login' to use ${pretty}.`,
101+
),
102+
);
103+
104+
// Find first authenticated engine by order
105+
const engines = registry.getAll();
106+
let fallbackEngine = null as typeof overrideEngine | null;
107+
for (const eng of engines) {
108+
if (await eng.auth.isAuthenticated()) {
109+
fallbackEngine = eng;
110+
break;
111+
}
112+
}
113+
114+
// If none authenticated, fall back to registry default (may still require auth)
115+
if (!fallbackEngine) {
116+
fallbackEngine = registry.getDefault() ?? null;
117+
}
118+
119+
if (fallbackEngine) {
120+
engineType = fallbackEngine.metadata.id;
121+
console.log(
122+
formatAgentLog(
123+
step.agentId,
124+
`Falling back to ${fallbackEngine.metadata.name} (${engineType})`,
125+
),
126+
);
127+
}
128+
}
91129
} else {
92130
// Fallback: find first authenticated engine by order
93131
const engines = registry.getAll();

templates/workflows/codemachine.workflow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default {
22
name: 'CodeMachine Workflow',
33
steps: [
4-
resolveStep('git-commit', { executeOnce: true }), // Commit the initial project specification to git
5-
resolveStep('arch-agent', { executeOnce: true }), // Define system architecture and technical design decisions
4+
resolveStep('git-commit', { executeOnce: true, engine: 'claude' }), // Commit the initial project specification to git
5+
resolveStep('arch-agent', { executeOnce: true, engine: 'claude' }), // Define system architecture and technical design decisions
66
resolveStep('plan-agent', { executeOnce: true }), // Generate comprehensive iterative development plan with architectural artifacts
77
resolveStep('task-breakdown', { executeOnce: true }), // Extract and structure tasks from project plan into JSON format
88
resolveStep('git-commit', { executeOnce: true }), // Commit the task breakdown to git

0 commit comments

Comments
 (0)