fix: workflow e2e working

This commit is contained in:
Dallin Romney 2025-10-03 19:46:06 -07:00
parent 475aa95e44
commit 99095bdcbd
6 changed files with 75 additions and 31 deletions

View file

@ -12,7 +12,11 @@ import * as logging from "../logging.js";
import { sentryService } from "../sentry.js";
import { initializeServices, services } from "../services/index.js";
import { serviceContainer } from "../services/ServiceContainer.js";
import { ModelServiceState, SERVICE_NAMES } from "../services/types.js";
import {
ModelServiceState,
SERVICE_NAMES,
WorkflowServiceState,
} from "../services/types.js";
import {
loadSession,
updateSessionHistory,
@ -474,9 +478,15 @@ async function runHeadlessMode(
const { processAndCombinePrompts } = await import(
"../util/promptProcessor.js"
);
const workflowState = await serviceContainer.get<WorkflowServiceState>(
SERVICE_NAMES.WORKFLOW,
);
const initialPrompt =
`${workflowState?.workflowFile?.prompt ?? ""}\n\n${prompt ?? ""}`.trim() ||
undefined;
const initialUserInput = await processAndCombinePrompts(
options.prompt,
prompt,
initialPrompt,
);
let isFirstMessage = true;
@ -528,11 +538,13 @@ export async function chat(prompt?: string, options: ChatOptions = {}) {
// Start active time tracking
telemetryService.startActiveTime();
options.workflow = "peter-parker/workflow-48";
// options.headless = true;
// If not in headless mode, use unified initialization with TUI
if (!options.headless) {
// Process flags for TUI mode
const { permissionOverrides } = processCommandFlags(options);
// Initialize services with onboarding handled internally
await initializeServices({
options,
@ -540,9 +552,17 @@ export async function chat(prompt?: string, options: ChatOptions = {}) {
toolPermissionOverrides: permissionOverrides,
});
const workflowState = await serviceContainer.get<WorkflowServiceState>(
SERVICE_NAMES.WORKFLOW,
);
const initialPrompt =
`${workflowState?.workflowFile?.prompt ?? ""}\n\n${prompt ?? ""}`.trim() ||
undefined;
// Start TUI with skipOnboarding since we already handled it
const tuiOptions: any = {
initialPrompt: prompt,
initialPrompt,
resume: options.resume,
fork: options.fork,
config: options.config,

View file

@ -22,7 +22,7 @@ export class ConfigEnhancer {
// added this for lint complexity rule
private async enhanceConfigFromWorkflow(
config: AssistantUnrolled,
_options: BaseCommandOptions,
_options: BaseCommandOptions | undefined,
workflowState?: WorkflowServiceState,
) {
const enhancedConfig = { ...config };
@ -32,33 +32,51 @@ export class ConfigEnhancer {
const { rules, model, tools, prompt } = workflowState?.workflowFile;
if (rules) {
options.rule = [
...rules.split(",").filter(Boolean),
...rules
.split(",")
.filter(Boolean)
.map((r) => r.trim()),
...(options.rule || []),
];
}
if (tools) {
const parsedTools = parseWorkflowTools(tools);
if (parsedTools.mcpServers.length > 0) {
options.mcp = [...parsedTools.mcpServers, ...(options.mcp || [])];
try {
const parsedTools = parseWorkflowTools(tools);
if (parsedTools.mcpServers.length > 0) {
options.mcp = [...parsedTools.mcpServers, ...(options.mcp || [])];
}
} catch (e) {
logger.error("Failed to parse workflow tools", e);
}
}
// --model takes precedence over workflow model
if (model) {
const workflowModel = await loadPackageFromHub(model, modelProcessor);
enhancedConfig.models = [
workflowModel,
...(enhancedConfig.models ?? []),
];
workflowState?.workflowService?.setWorkflowModelName(
workflowModel.name,
);
try {
const workflowModel = await loadPackageFromHub(model, modelProcessor);
enhancedConfig.models = [
workflowModel,
...(enhancedConfig.models ?? []),
];
workflowState?.workflowService?.setWorkflowModelName(
workflowModel.name,
);
} catch (e) {
logger.error("Failed to load workflow model", e);
}
}
// Add workflow prompt as prefix (see processAndCombinePrompts)
// Workflow prompt is included as a slash command, initial kickoff is handled elsewhere
if (prompt) {
options.prompt = [prompt, ...(options.prompt || [])];
enhancedConfig.prompts = [
{
name: `Workflow prompt (${workflowState.workflowFile.name})`,
prompt,
description: workflowState.workflowFile.description,
},
...(enhancedConfig.prompts ?? []),
];
}
}
return { options, enhancedConfig };
@ -68,7 +86,7 @@ export class ConfigEnhancer {
*/
async enhanceConfig(
config: AssistantUnrolled,
_options: BaseCommandOptions,
_options?: BaseCommandOptions,
workflowState?: WorkflowServiceState,
): Promise<AssistantUnrolled> {
const enhanced = await this.enhanceConfigFromWorkflow(

View file

@ -66,8 +66,8 @@ export class ConfigService
// Apply injected config if provided
if (
injectedConfigOptions &&
this.hasInjectedConfig(injectedConfigOptions)
workflowState?.workflowFile ||
(injectedConfigOptions && this.hasInjectedConfig(injectedConfigOptions))
) {
config = await configEnhancer.enhanceConfig(
config,

View file

@ -82,13 +82,6 @@ export class ToolPermissionService
}
const policies: ToolPermissionPolicy[] = [];
if (parsedTools.allBuiltIn) {
policies.push({ tool: "*", permission: "allow" });
policies.push({ tool: "mcp:*", permission: "exclude" });
} else {
policies.push({ tool: "*", permission: "exclude" });
}
for (const toolRef of parsedTools.tools) {
if (toolRef.mcpServer) {
if (toolRef.toolName) {
@ -111,6 +104,13 @@ export class ToolPermissionService
logger.debug(`Generated ${policies.length} workflow tool policies`);
}
if (parsedTools.allBuiltIn) {
policies.push({ tool: "*", permission: "allow" });
policies.push({ tool: "mcp:*", permission: "exclude" });
} else {
policies.push({ tool: "*", permission: "exclude" });
}
return policies;
}

View file

@ -2,6 +2,7 @@ import { loadPackageFromHub, workflowProcessor } from "../hubLoader.js";
import { logger } from "../util/logger.js";
import { BaseService } from "./BaseService.js";
import { serviceContainer } from "./ServiceContainer.js";
import { WorkflowServiceState } from "./types.js";
/**
@ -69,4 +70,9 @@ export class WorkflowService extends BaseService<WorkflowServiceState> {
};
}
}
protected override setState(newState: Partial<WorkflowServiceState>): void {
super.setState(newState);
serviceContainer.set("update", this.currentState);
}
}

View file

@ -212,10 +212,10 @@ export async function initializeServices(
return configService.initialize({
authConfig: finalAuthState.authConfig,
configPath,
organizationIde: finalAuthState.organizationId || null,
// organizationId: finalAuthState.organizationId || null,
apiClient: apiClientState.apiClient,
workflowState,
commandOptions,
injectedConfigOptions: commandOptions,
});
},
[SERVICE_NAMES.AUTH, SERVICE_NAMES.API_CLIENT, SERVICE_NAMES.WORKFLOW], // Dependencies