Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion packages/api-client/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,8 @@ export interface components {
workspace_name: string;
agent_kind: string;
/** @enum {string} */
execution_type: "agent" | "code";
/** @enum {string} */
state: "queued" | "reserved" | "starting" | "running" | "blocked" | "stopping" | "succeeded" | "failed" | "stopped" | "done" | "ignored";
provider: string;
backend_kind: string;
Expand Down Expand Up @@ -1856,6 +1858,8 @@ export interface components {
workspace_name: string;
agent_kind: string;
/** @enum {string} */
execution_type: "agent" | "code";
/** @enum {string} */
state: "queued" | "reserved" | "starting" | "running" | "blocked" | "stopping" | "succeeded" | "failed" | "stopped" | "done" | "ignored";
provider: string;
backend_kind: string;
Expand Down Expand Up @@ -2029,6 +2033,11 @@ export interface components {
agent_name: string;
workspace_name: string;
agent_kind: string;
/**
* @default agent
* @enum {string}
*/
execution_type: "agent" | "code";
/** @enum {string} */
state: "queued" | "reserved" | "starting" | "running" | "blocked" | "stopping" | "succeeded" | "failed" | "stopped" | "done" | "ignored";
provider: string;
Expand Down Expand Up @@ -2090,6 +2099,11 @@ export interface components {
vm_cleanup_attempt: number;
cleanup_next_at: string | null;
vm_cleanup_complete: boolean;
/** @default null */
execution_script: string | null;
execution_configuration: {
[key: string]: unknown;
};
prompt: string;
context: {
[key: string]: unknown;
Expand Down Expand Up @@ -2186,7 +2200,11 @@ export interface components {
projectId?: string;
name: string;
slug: string;
/** @enum {string} */
executionType?: "agent" | "code";
/** @default */
promptTemplate: string;
script?: string;
runNameTemplate?: string;
/** @default 1 */
concurrencyLimit: number;
Expand Down Expand Up @@ -4316,6 +4334,8 @@ export interface operations {
model: string;
effort: string;
agentKind: string;
/** @enum {string} */
executionType: "agent" | "code";
concurrencyLimit: number;
runningCount: number;
lastRunState: ("queued" | "reserved" | "starting" | "running" | "blocked" | "stopping" | "succeeded" | "failed" | "stopped" | "done" | "ignored") | null;
Expand Down Expand Up @@ -4950,7 +4970,10 @@ export interface operations {
name: string;
slug: string;
enabled: boolean;
/** @enum {string} */
executionType?: "agent" | "code";
promptTemplate: string;
script?: string;
runNameTemplate: string;
tags?: string[];
model: string;
Expand All @@ -4961,6 +4984,9 @@ export interface operations {
cwd?: string;
agentKind: string;
image?: string;
/** @enum {string} */
executionType?: "agent" | "code";
script?: string;
};
executionConfigId: string;
agentKind: string;
Expand Down Expand Up @@ -5133,6 +5159,8 @@ export interface operations {
tags: string[];
/** @enum {string} */
agentKind: "codex" | "claude" | "pi";
/** @enum {string} */
executionType?: "agent" | "code";
};
};
};
Expand Down Expand Up @@ -5230,7 +5258,10 @@ export interface operations {
name: string;
slug: string;
enabled: boolean;
/** @enum {string} */
executionType?: "agent" | "code";
promptTemplate: string;
script?: string;
runNameTemplate: string;
tags?: string[];
model: string;
Expand All @@ -5241,6 +5272,9 @@ export interface operations {
cwd?: string;
agentKind: string;
image?: string;
/** @enum {string} */
executionType?: "agent" | "code";
script?: string;
};
executionConfigId: string;
agentKind: string;
Expand Down Expand Up @@ -5424,7 +5458,10 @@ export interface operations {
name: string;
slug: string;
enabled: boolean;
/** @enum {string} */
executionType?: "agent" | "code";
promptTemplate: string;
script?: string;
runNameTemplate: string;
tags?: string[];
model: string;
Expand All @@ -5435,6 +5472,9 @@ export interface operations {
cwd?: string;
agentKind: string;
image?: string;
/** @enum {string} */
executionType?: "agent" | "code";
script?: string;
};
executionConfigId: string;
agentKind: string;
Expand Down Expand Up @@ -5900,7 +5940,10 @@ export interface operations {
name: string;
slug: string;
enabled: boolean;
/** @enum {string} */
executionType?: "agent" | "code";
promptTemplate: string;
script?: string;
runNameTemplate: string;
tags?: string[];
model: string;
Expand All @@ -5911,6 +5954,9 @@ export interface operations {
cwd?: string;
agentKind: string;
image?: string;
/** @enum {string} */
executionType?: "agent" | "code";
script?: string;
};
executionConfigId: string;
agentKind: string;
Expand Down Expand Up @@ -6083,7 +6129,11 @@ export interface operations {
projectId?: string;
name: string;
slug: string;
promptTemplate: string;
/** @enum {string} */
executionType?: "agent" | "code";
/** @default */
promptTemplate?: string;
script?: string;
runNameTemplate?: string;
/** @default 1 */
concurrencyLimit?: number;
Expand Down Expand Up @@ -6210,7 +6260,10 @@ export interface operations {
name: string;
slug: string;
enabled: boolean;
/** @enum {string} */
executionType?: "agent" | "code";
promptTemplate: string;
script?: string;
runNameTemplate: string;
tags?: string[];
model: string;
Expand All @@ -6221,6 +6274,9 @@ export interface operations {
cwd?: string;
agentKind: string;
image?: string;
/** @enum {string} */
executionType?: "agent" | "code";
script?: string;
};
executionConfigId: string;
agentKind: string;
Expand Down Expand Up @@ -6590,6 +6646,11 @@ export interface operations {
project_name?: string;
/** @enum {string} */
state: "queued" | "reserved" | "starting" | "running" | "blocked" | "stopping" | "succeeded" | "failed" | "stopped";
/**
* @default agent
* @enum {string}
*/
execution_type: "agent" | "code";
run_name: string;
job_name: string;
destination_url: string | null;
Expand Down
15 changes: 7 additions & 8 deletions packages/api/src/exe-vm-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class ExeVmBackend implements ExecutionBackend {
}
}

async verifyImage(verificationId: string, image: string, agentKind: "codex" | "claude" | "pi", progress: (phase: string) => Promise<void> = async () => {}): Promise<void> {
async verifyImage(verificationId: string, image: string, agentKind: "codex" | "claude" | "pi", progress: (phase: string) => Promise<void> = async () => {}, executionType: "agent" | "code" = "agent"): Promise<void> {
const vm = vmNameFor(`verify-${verificationId}`);
const tags = [...new Set(this.connection.tags)].map(tag => `--tag=${shellAtom(tag)}`).join(" ");
const command = `new --name=${shellAtom(vm)} --no-email --comment=${shellAtom(`Factorize VM ${vm}`)}${tags ? ` ${tags}` : ""} --image=${shellAtom(image)}`;
Expand Down Expand Up @@ -139,9 +139,9 @@ export class ExeVmBackend implements ExecutionBackend {
for (let attempt = 1; (!ssh || !ssh.ok) && attempt < 6; attempt++) ssh = await this.api(`ssh ${shellAtom(vm)} ${shellAtom("true")}`).catch(() => null);
if (!ssh?.ok) throw new ExeIntegrationError(`ssh: VM was created from the image, but SSH access failed (${ssh?.status ?? "timeout"}). Ensure the image boots an exe.dev-compatible system with SSH enabled.`);
await progress("checking_agent");
const check = `command -v ${shellAtom(agentKind)} >/dev/null 2>&1 && command -v curl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1`;
const check = executionType === "code" ? "command -v bash >/dev/null 2>&1 && command -v curl >/dev/null 2>&1" : `command -v ${shellAtom(agentKind)} >/dev/null 2>&1 && command -v curl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1`;
const agent = await this.api(`ssh ${shellAtom(vm)} ${shellAtom(check)}`).catch(() => null);
if (!agent?.ok) throw new ExeIntegrationError(`agent: SSH works, but the selected ${agentKind} harness prerequisites are missing. Use an image with ${agentKind}, curl, and jq installed.`);
if (!agent?.ok) throw new ExeIntegrationError(executionType === "code" ? "agent: SSH works, but bash and curl prerequisites are missing. Use an exe.dev-compatible image with bash and curl installed." : `agent: SSH works, but the selected ${agentKind} harness prerequisites are missing. Use an image with ${agentKind}, curl, and jq installed.`);
} finally {
await progress("cleaning_up");
const removed = await this.deleteVm(vm);
Expand All @@ -151,8 +151,7 @@ export class ExeVmBackend implements ExecutionBackend {

async launch(request: LaunchRequest): Promise<LaunchReceipt> {
const connection = this.connection as ExeRunConnection;
if (!connection.agentKind) throw new Error("The job is missing its agent configuration");
if (!request.harness) throw new Error("The run is missing its agent harness launch plan");
if (!request.code && (!connection.agentKind || !request.harness)) throw new Error("The job is missing its agent harness launch plan");
if (request.traceSources) validateTraceSources(request.traceSources);
const vm = vmNameFor(request.runId);
const handle: RunHandle = { backendKind: this.kind, id: vm };
Expand Down Expand Up @@ -189,15 +188,15 @@ export class ExeVmBackend implements ExecutionBackend {
}
}

const prompt = base64(request.prompt), output = request.traceSources?.primary.formatVersion === "codex-exec-jsonl" ? request.traceSources.primary.path : "/tmp/factorize.log", unit = vm;
const prompt = base64(request.prompt), code = request.code, output = request.traceSources?.primary.formatVersion === "codex-exec-jsonl" ? request.traceSources.primary.path : "/tmp/factorize.log", unit = vm;
const work = [
"set -eu",
"mkdir -p /home/exedev/workspace",
"cd /home/exedev/workspace",
...(request.traceSources?.primary.kind === "execution_stream" ? [`mkdir -p -- ${shellAtom(request.traceSources.primary.path.slice(0, request.traceSources.primary.path.lastIndexOf("/")) || "/")}`, `touch -- ${shellAtom(request.traceSources.primary.path)}`] : []),
`printf '%s' ${shellAtom(prompt)} | base64 -d > /tmp/factorize-prompt.md`,
"sudo install -d -o exedev -g exedev -m 0700 /home/exedev/.factorize-job",
`if [ "$(sudo systemctl show ${shellAtom(unit)} --property=LoadState --value 2>/dev/null || true)" != loaded ]; then sudo systemd-run --quiet --uid=exedev --gid=exedev --unit=${shellAtom(unit)} --property=Type=exec --property=RemainAfterExit=yes --property=WorkingDirectory=/home/exedev/workspace --property=StandardInput=file:/tmp/factorize-prompt.md --property=StandardOutput=${output === "/tmp/factorize.log" ? `append:${output}` : shellAtom(`append:${output}`)} --property=StandardError=append:/tmp/factorize.stderr ${harnessCommand(request.harness)}; fi`,
...(code ? [`printf '%s' ${shellAtom(base64(code.script))} | base64 -d > /tmp/factorize-code-job.sh`, `printf '%s' ${shellAtom(base64(JSON.stringify(code.context)))} | base64 -d > /home/exedev/.factorize-job/input.json`, "sudo chown exedev:exedev /home/exedev/.factorize-job/input.json"] : [`printf '%s' ${shellAtom(prompt)} | base64 -d > /tmp/factorize-prompt.md`]),
`if [ "$(sudo systemctl show ${shellAtom(unit)} --property=LoadState --value 2>/dev/null || true)" != loaded ]; then sudo systemd-run --quiet --uid=exedev --gid=exedev --unit=${shellAtom(unit)} --property=Type=exec --property=RemainAfterExit=yes --property=WorkingDirectory=/home/exedev/workspace --property=StandardInput=${code ? "/dev/null" : "file:/tmp/factorize-prompt.md"} --property=StandardOutput=${output === "/tmp/factorize.log" ? `append:${output}` : shellAtom(`append:${output}`)} --property=StandardError=append:/tmp/factorize.stderr ${code ? "env FACTORIZE_RESULT_PATH=/home/exedev/.factorize-job/results.json FACTORIZE_INPUT_PATH=/home/exedev/.factorize-job/input.json bash /tmp/factorize-code-job.sh" : harnessCommand(request.harness!)}; fi`,
"echo started",
].join("; ");
if (request.traceSources?.primary.formatVersion === "codex-exec-jsonl") {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface LaunchRequest {
runProxy?: { targetOrigin: string; credential: string };
traceSources?: TraceSources;
harness?: { executable: string; args: string[]; env: Record<string, string> };
code?: { script: string; context: Record<string, unknown> };
}

/** Opaque to orchestration. Only the backend that created it may interpret id. */
Expand Down
11 changes: 8 additions & 3 deletions packages/api/src/flow-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const jobInputSchema = z.object({
projectId: z.guid().optional(),
name: z.string().trim().min(1).max(120),
slug: z.string().regex(/^[a-z][a-z0-9_-]{0,29}$/),
promptTemplate: z.string().min(1).max(50_000),
executionType: z.enum(["agent", "code"]).optional(),
promptTemplate: z.string().max(50_000).default(""),
script: z.string().max(50_000).optional(),
runNameTemplate: z.string().max(500).optional(),
concurrencyLimit: z.number().int().min(1).max(50).default(1),
executionConfigId: z.string().min(1),
Expand All @@ -72,12 +74,15 @@ export const jobInputSchema = z.object({
effort: z.string().trim().max(40).optional(),
triggers: z.array(triggerSchema).max(50).default([]),
skillIds: z.array(z.guid()).max(50).optional(),
}).strict();
}).strict().superRefine((value, context) => {
if (value.executionType !== "code" && !value.promptTemplate?.trim()) context.addIssue({ code: "custom", path: ["promptTemplate"], message: "Agent jobs require a prompt template." });
if (value.executionType === "code" && !value.script?.trim()) context.addIssue({ code: "custom", path: ["script"], message: "Code jobs require a script." });
});
export const vmImageVerificationInput = z.object({
connectionId: z.string().min(1).max(200),
image: publicVmImage(false),
tags: z.array(z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/)).max(20),
agentKind: z.enum(["codex", "claude", "pi"]),
agentKind: z.enum(["codex", "claude", "pi"]), executionType: z.enum(["agent", "code"]).optional(),
}).strict();
export const vmImageVerificationResponse = z.object({ id: z.guid(), status: z.enum(["queued", "creating", "checking_ssh", "checking_agent", "cleaning_up", "succeeded", "failed", "cleanup_failed"]), phase: z.string(), errorKind: z.string().nullable(), error: z.string().nullable(), createdAt: z.string(), updatedAt: z.string() });
export const jobIdSchema = z.object({ jobId: z.string().min(1) });
Expand Down
Loading
Loading