fix(plugins): keep agent.create.before's workspace and metadata after the rebase

Rebased onto main after #8744 added metadata to agent.create.before. A
result that omits workspaceId or metadata keeps the request's; a changed
workspaceId is still rejected. The session's command lifecycle moves to a
getter so its constructor stays under the complexity limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Josh Bendavid
2026-11-15 23:59:05 +01:00
co-authored by Claude Opus 5.5
parent 6d5fcf87e5
commit 416d706144
2 changed files with 17 additions and 5 deletions
@@ -403,11 +403,19 @@ test("terminal and command hooks can change only what Paseo runs", async () => {
test("agent creation hooks keep the workspace, including from plugins that omit it", async () => {
const request = {
config: { provider: "claude", cwd: "/work/a" },
metadata: { "issues.id": "ENG-1" },
workspaceId: "wks_a",
};
// A result built before either field existed keeps both.
await expect(
validateBeforeResult("agent.create.before", request, { config: request.config }),
).resolves.toEqual(request);
await expect(
validateBeforeResult("agent.create.before", request, {
config: request.config,
metadata: { "issues.id": "ENG-2" },
}),
).resolves.toEqual({ ...request, metadata: { "issues.id": "ENG-2" } });
await expect(
validateBeforeResult("agent.create.before", request, { ...request, workspaceId: "wks_b" }),
).rejects.toThrow("agent.create.before hooks cannot change the workspace");
+9 -5
View File
@@ -814,6 +814,10 @@ export class Session {
private readonly daemonConfigStore: DaemonConfigStore;
private readonly pushNotifications: PushNotifications;
private readonly pluginRuntime: SessionOptions["pluginRuntime"];
// What worktree setup and teardown commands run through: the plugins' hooks, or none.
private get commandLifecycle(): NonNullable<SessionOptions["pluginRuntime"]> | null {
return this.pluginRuntime ?? null;
}
private readonly orchestrationSkills: SessionOptions["orchestrationSkills"];
private unsubscribeAgentEvents: (() => void) | null = null;
private unsubscribeProjectMutations: (() => void) | null = null;
@@ -1249,7 +1253,7 @@ export class Session {
logger: this.sessionLogger,
});
this.createAgentLifecycleDispatch = new CreateAgentLifecycleDispatch({
lifecycle: this.pluginRuntime ?? null,
lifecycle: this.commandLifecycle,
paseoHome: this.paseoHome,
worktreesRoot: this.worktreesRoot,
agentManager: this.agentManager,
@@ -5709,7 +5713,7 @@ export class Session {
): Promise<void> {
return handleWorktreeArchiveRequest(
{
lifecycle: this.pluginRuntime ?? null,
lifecycle: this.commandLifecycle,
paseoHome: this.paseoHome,
paseoWorktreesBaseRoot: this.worktreesRoot,
github: this.github,
@@ -7964,7 +7968,7 @@ export class Session {
): Promise<CreatePaseoWorktreeWorkflowResult> {
return createWorktreeWorkflow(
{
lifecycle: this.pluginRuntime ?? null,
lifecycle: this.commandLifecycle,
paseoHome: this.paseoHome,
worktreesRoot: this.worktreesRoot,
createPaseoWorktree: (workflowInput, serviceOptions) =>
@@ -8018,7 +8022,7 @@ export class Session {
): Promise<void> {
return handleWorkspaceSetupRunRequestMessage(
{
lifecycle: this.pluginRuntime ?? null,
lifecycle: this.commandLifecycle,
getWorkspace: (workspaceId) => this.workspaceRegistry.get(workspaceId),
clearAutomationBlock: (workspaceId) =>
clearWorkspaceAutomationBlock(this.workspaceRegistry, workspaceId),
@@ -8060,7 +8064,7 @@ export class Session {
}
return archiveByScope(
{
lifecycle: this.pluginRuntime ?? null,
lifecycle: this.commandLifecycle,
paseoHome: this.paseoHome,
paseoWorktreesBaseRoot: this.worktreesRoot,
github: this.github,