feat: switch to managed Paseo Sprite agents, remote hosts, and Fly token exchange
This commit is contained in:
1 parent
9188bfc277
commit
32c02cb3cd
14 files changed
+1860
-446
No files matched your search
+168
-46
@@ -63,6 +63,7 @@ interface ActiveSpriteSession {
|
||||
syncWorkspace: boolean;
|
||||
checkpointAfterTurn: boolean;
|
||||
persistenceVersion: number;
|
||||
persistedAcpSessionId?: string;
|
||||
activeShellCmd: SpriteCommand | null;
|
||||
activeTurnId: string | null;
|
||||
canceledTurn: boolean;
|
||||
@@ -116,6 +117,32 @@ function toJsonRecord(value: unknown): Record<string, JsonValue> | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const HOST_ENV_BLOCKLIST = new Set([
|
||||
"HOME",
|
||||
"USER",
|
||||
"LOGNAME",
|
||||
"PATH",
|
||||
"PWD",
|
||||
"OLDPWD",
|
||||
"SHELL",
|
||||
"TMPDIR",
|
||||
"HOSTNAME",
|
||||
"SHLVL",
|
||||
"_",
|
||||
"PASEO_HOME",
|
||||
"NODE_ENV",
|
||||
]);
|
||||
|
||||
function sanitizeSpriteEnv(env: Readonly<Record<string, string>>): Record<string, string> {
|
||||
const filtered: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (!HOST_ENV_BLOCKLIST.has(key)) {
|
||||
filtered[key] = value;
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
const SUPPORTED_CAPABILITIES = [
|
||||
"prompt.message",
|
||||
"prompt.command",
|
||||
@@ -125,44 +152,61 @@ const SUPPORTED_CAPABILITIES = [
|
||||
"permission",
|
||||
] as const;
|
||||
|
||||
const SESSION_CONTROLS: readonly ProviderOptionControl[] = [
|
||||
{
|
||||
type: "toggle",
|
||||
key: "checkpointAfterTurn",
|
||||
label: "Checkpoint after turn",
|
||||
description: "Create a Fly Sprite checkpoint after each completed turn.",
|
||||
icon: "BookmarkCheck",
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
type: "toggle",
|
||||
key: "syncWorkspace",
|
||||
label: "Sync local workspace",
|
||||
description: "Sync the local workspace files into /workspace on the Sprite.",
|
||||
icon: "FolderSync",
|
||||
defaultValue: true,
|
||||
},
|
||||
];
|
||||
function buildControls(spriteName?: string): readonly ProviderOptionControl[] {
|
||||
const choices: Array<{ value: string; label: string; description?: string }> = [
|
||||
{ value: "", label: "Auto-create new Sprite" },
|
||||
];
|
||||
if (spriteName) {
|
||||
choices.push({ value: spriteName, label: spriteName, description: "Active Fly Sprite" });
|
||||
}
|
||||
return [
|
||||
{
|
||||
type: "select",
|
||||
key: "spriteName",
|
||||
label: "Fly Sprite",
|
||||
description: "Target Fly Sprite microVM for this agent.",
|
||||
icon: "Cpu",
|
||||
defaultValue: spriteName ?? "",
|
||||
choices,
|
||||
},
|
||||
{
|
||||
type: "toggle",
|
||||
key: "checkpointAfterTurn",
|
||||
label: "Checkpoint after turn",
|
||||
description: "Create a Fly Sprite checkpoint after each completed turn.",
|
||||
icon: "BookmarkCheck",
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
type: "toggle",
|
||||
key: "syncWorkspace",
|
||||
label: "Sync local workspace",
|
||||
description: "Sync the local workspace files into /workspace on the Sprite.",
|
||||
icon: "FolderSync",
|
||||
defaultValue: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function buildCatalog(defaultMode: WorkerMode): ProviderCatalog {
|
||||
return {
|
||||
models: [
|
||||
{
|
||||
id: "shell",
|
||||
label: "Remote Shell Worker",
|
||||
description: "Execute each prompt as a shell command inside the Fly Sprite.",
|
||||
isDefault: defaultMode === "shell",
|
||||
},
|
||||
{
|
||||
id: "acp",
|
||||
label: "Remote ACP Agent",
|
||||
description: "Run the configured ACP coding agent inside the Fly Sprite.",
|
||||
isDefault: defaultMode === "acp",
|
||||
},
|
||||
{
|
||||
id: "shell",
|
||||
label: "Remote Shell",
|
||||
description: "Execute each prompt as a bash command inside the Fly Sprite.",
|
||||
isDefault: defaultMode === "shell",
|
||||
},
|
||||
],
|
||||
modes: [
|
||||
{ id: "shell", label: "Shell Worker", description: "Direct bash execution on the Sprite" },
|
||||
{ id: "acp", label: "ACP Agent", description: "Remote ACP agent over WebSocket stdio" },
|
||||
{ id: "acp", label: "ACP Agent", description: "Remote ACP coding agent over WebSocket stdio" },
|
||||
{ id: "shell", label: "Shell", description: "Direct bash execution on the Sprite" },
|
||||
],
|
||||
defaultModel: defaultMode,
|
||||
defaultMode,
|
||||
@@ -177,8 +221,9 @@ function buildConfigState(session: ActiveSpriteSession): ProviderConfigState {
|
||||
models: catalog.models,
|
||||
modes: catalog.modes,
|
||||
thinkingOptions: [],
|
||||
controls: SESSION_CONTROLS,
|
||||
controls: buildControls(session.spriteName),
|
||||
providerOptions: {
|
||||
spriteName: session.spriteName,
|
||||
checkpointAfterTurn: session.checkpointAfterTurn,
|
||||
syncWorkspace: session.syncWorkspace,
|
||||
},
|
||||
@@ -187,6 +232,7 @@ function buildConfigState(session: ActiveSpriteSession): ProviderConfigState {
|
||||
|
||||
export interface FlySpritesProviderRegistration extends ProviderRegistration {
|
||||
getSpriteForSession(sessionId: string): string | undefined;
|
||||
getSessionSprites(): Record<string, string>;
|
||||
}
|
||||
|
||||
export function createFlySpritesProvider(
|
||||
@@ -271,7 +317,7 @@ export function createFlySpritesProvider(
|
||||
|
||||
const cmd = sprite.spawn("bash", ["-lc", promptText], {
|
||||
cwd: session.remoteDir,
|
||||
env: { ...session.env },
|
||||
env: sanitizeSpriteEnv(session.env),
|
||||
});
|
||||
session.activeShellCmd = cmd;
|
||||
session.activeTurnId = turnId;
|
||||
@@ -374,7 +420,7 @@ export function createFlySpritesProvider(
|
||||
|
||||
const cmd = sprite.spawn("bash", ["-lc", acpCmdText], {
|
||||
cwd: session.remoteDir,
|
||||
env: { ...session.env },
|
||||
env: sanitizeSpriteEnv(session.env),
|
||||
});
|
||||
|
||||
const stderrChunks: string[] = [];
|
||||
@@ -533,33 +579,103 @@ export function createFlySpritesProvider(
|
||||
const connection = new ClientSideConnection(() => clientHandler, stream);
|
||||
runtime.connection = connection;
|
||||
|
||||
let startupSettled = false;
|
||||
let rejectStartup: ((err: Error) => void) | null = null;
|
||||
const earlyExitPromise = new Promise<never>((_resolve, reject) => {
|
||||
rejectStartup = reject;
|
||||
});
|
||||
|
||||
cmd.on("error", (err) => {
|
||||
if (!startupSettled && rejectStartup) {
|
||||
rejectStartup(err instanceof Error ? err : new Error(String(err)));
|
||||
}
|
||||
});
|
||||
|
||||
cmd.on("exit", (code) => {
|
||||
const stderrText = stderrChunks.join("").trim();
|
||||
const message = `Remote ACP command '${acpCmdText}' exited (${code})${stderrText ? `: ${stderrText}` : ""}`;
|
||||
if (!startupSettled && rejectStartup) {
|
||||
rejectStartup(new Error(message));
|
||||
return;
|
||||
}
|
||||
if (session.acp === runtime) {
|
||||
session.acp = null;
|
||||
if (code !== 0) {
|
||||
emit({
|
||||
type: "session.runtime_failed",
|
||||
sessionId: session.sessionId,
|
||||
error: {
|
||||
message: `Remote ACP command '${acpCmdText}' exited (${code}): ${stderrChunks.join("").trim()}`,
|
||||
},
|
||||
error: { message },
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await connection.initialize({
|
||||
protocolVersion: PROTOCOL_VERSION,
|
||||
clientCapabilities: {},
|
||||
clientInfo: { name: "paseo-fly-sprites", version: "0.1.0" },
|
||||
});
|
||||
try {
|
||||
await Promise.race([
|
||||
(async () => {
|
||||
// Wait until the underlying WebSocket opens before ACP writes to cmd.stdin.
|
||||
await new Promise<void>((resolve) => {
|
||||
cmd.once("spawn", resolve);
|
||||
});
|
||||
|
||||
const created = await connection.newSession({
|
||||
cwd: session.remoteDir,
|
||||
mcpServers: [],
|
||||
});
|
||||
runtime.nativeSessionId = created.sessionId;
|
||||
await connection.initialize({
|
||||
protocolVersion: PROTOCOL_VERSION,
|
||||
clientCapabilities: {},
|
||||
clientInfo: { name: "paseo-fly-sprites", version: "0.1.0" },
|
||||
});
|
||||
|
||||
if (session.persistedAcpSessionId) {
|
||||
try {
|
||||
await connection.loadSession({
|
||||
sessionId: session.persistedAcpSessionId,
|
||||
cwd: session.remoteDir,
|
||||
mcpServers: [],
|
||||
});
|
||||
runtime.nativeSessionId = session.persistedAcpSessionId;
|
||||
} catch {
|
||||
const created = await connection.newSession({
|
||||
cwd: session.remoteDir,
|
||||
mcpServers: [],
|
||||
});
|
||||
runtime.nativeSessionId = created.sessionId;
|
||||
}
|
||||
} else {
|
||||
const created = await connection.newSession({
|
||||
cwd: session.remoteDir,
|
||||
mcpServers: [],
|
||||
});
|
||||
runtime.nativeSessionId = created.sessionId;
|
||||
}
|
||||
})(),
|
||||
earlyExitPromise,
|
||||
]);
|
||||
startupSettled = true;
|
||||
} catch (error) {
|
||||
startupSettled = true;
|
||||
try {
|
||||
cmd.kill("SIGTERM");
|
||||
cmd.close();
|
||||
} catch {
|
||||
// Ignore cleanup errors.
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
session.persistedAcpSessionId = runtime.nativeSessionId;
|
||||
session.acp = runtime;
|
||||
emit({
|
||||
type: "session.persistence",
|
||||
sessionId: session.sessionId,
|
||||
persistence: {
|
||||
version: 1,
|
||||
data: {
|
||||
spriteName: session.spriteName,
|
||||
remoteDir: session.remoteDir,
|
||||
mode: session.mode,
|
||||
acpSessionId: runtime.nativeSessionId,
|
||||
},
|
||||
},
|
||||
});
|
||||
return runtime;
|
||||
}
|
||||
|
||||
@@ -613,20 +729,23 @@ export function createFlySpritesProvider(
|
||||
}
|
||||
}
|
||||
|
||||
const registration: ProviderRegistration & { getSpriteForSession(sessionId: string): string | undefined } = {
|
||||
const registration: FlySpritesProviderRegistration = {
|
||||
id: "fly-sprites",
|
||||
label: "Fly Sprites",
|
||||
description: "Run shell workers or remote ACP agents inside Fly.io Sprites microVMs",
|
||||
description: "Run managed coding agents inside Fly.io Sprites microVMs",
|
||||
getSpriteForSession(sessionId: string) {
|
||||
return sessionSprites.get(sessionId);
|
||||
},
|
||||
getSessionSprites() {
|
||||
return Object.fromEntries(sessionSprites.entries());
|
||||
},
|
||||
async status() {
|
||||
const { source } = await manager.resolveToken();
|
||||
const { source } = await manager.resolveRawToken();
|
||||
if (source === "none") {
|
||||
return {
|
||||
available: false,
|
||||
diagnostic:
|
||||
"Sign in with Zitadel (OpenBao) or configure a token in Fly Sprites Workers settings.",
|
||||
"Sign in with Zitadel (OpenBao) or configure a token in Fly Sprites settings.",
|
||||
};
|
||||
}
|
||||
return { available: true };
|
||||
@@ -726,6 +845,7 @@ export function createFlySpritesProvider(
|
||||
syncWorkspace,
|
||||
checkpointAfterTurn,
|
||||
persistenceVersion: 1,
|
||||
persistedAcpSessionId: persisted?.acpSessionId,
|
||||
activeShellCmd: null,
|
||||
activeTurnId: null,
|
||||
canceledTurn: false,
|
||||
@@ -746,6 +866,7 @@ export function createFlySpritesProvider(
|
||||
spriteName: session.spriteName,
|
||||
remoteDir: session.remoteDir,
|
||||
mode: session.mode,
|
||||
...(session.persistedAcpSessionId ? { acpSessionId: session.persistedAcpSessionId } : {}),
|
||||
},
|
||||
},
|
||||
title: input.config.title ?? `Sprite ${session.spriteName}`,
|
||||
@@ -887,6 +1008,7 @@ export function createFlySpritesProvider(
|
||||
spriteName: session.spriteName,
|
||||
remoteDir: session.remoteDir,
|
||||
mode: session.mode,
|
||||
...(session.persistedAcpSessionId ? { acpSessionId: session.persistedAcpSessionId } : {}),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user