Files
paseo/plugin-examples/lifecycle-actions/index.server.ts
T
Mohamed BoudraandJacek Tomaszewski af6ca46ae3 fix(plugin)!: drop the always-empty timeline from agent.turn.after (#9573)
agent.turn.after no longer declares timeline; plugins read the turn with
timeline.refetch({ direction: "tail", limit: 1, wholeTurns: true }) filtered by event.turnId.
Plugins built against the old SDK keep receiving timeline: [] behind COMPAT(pluginTurnTimeline).

Closes #9315

Co-authored-by: Jacek Tomaszewski <jacek@fullstack.house>
2026-11-13 15:22:53 +07:00

99 lines
2.8 KiB
TypeScript

import type { PluginServerContext } from "@getpaseo/plugin/server";
import { latestOutputText, shellCommand } from "./server/inspect";
export default function contribute(server: PluginServerContext) {
server.addHook("workspace.create.before", async ({ request }) => {
if (request.title === "Isolated lifecycle example" && request.source.kind === "directory") {
return {
...request,
source: {
kind: "worktree",
cwd: request.source.path,
action: "branch-off",
branchName: "lifecycle-example",
},
};
}
return request;
});
server.addHook("agent.turn.after", async (event, context) => {
// A background agent reports to the agent that created it, which decides whether to retry.
if (event.outcome.kind === "canceled" || event.agent.background) {
return;
}
const agent = context.paseo.agents.ref(event.agent.id);
const page = await agent.timeline.refetch({ direction: "tail", limit: 1, wholeTurns: true });
const turn = page.entries.filter((entry) => entry.turnId === event.turnId);
const text = latestOutputText(turn.map(({ item }) => item));
if (/out of credits/i.test(text)) {
console.log("Sending a follow-up after out of credits", event.agent.id);
await agent.send("Try again.");
}
});
server.addHook("agent.permission.before", async (event, context) => {
const command = shellCommand(event.request);
if (command === null) {
return;
}
const agent = context.paseo.agents.ref(event.agent.id);
if (/\brm\s+-rf\b/.test(command)) {
await agent.respondToPermission({
requestId: event.request.id,
response: {
behavior: "deny",
message: "Recursive deletion is blocked by the example plugin.",
},
});
return;
}
if (command.trim() === "git status") {
await agent.respondToPermission({
requestId: event.request.id,
response: { behavior: "allow" },
});
}
});
server.addHook("agent.create.before", async ({ request }) => {
return {
...request,
env: {
...request.env,
PASEO_HOOK_CREATE_EXAMPLE: "created",
},
};
});
server.addHook("agent.create.before", async ({ request }) => {
if (request.config.provider === "codex") {
return {
...request,
config: {
...request.config,
provider: "claude",
model: "haiku",
modeId: "default",
providerOptions: undefined,
},
};
}
return request;
});
server.addHook("agent.open.before", async ({ request }) => {
return {
...request,
env: {
...request.env,
PASEO_HOOK_OPEN_EXAMPLE: "opened",
},
};
});
return () => {};
}