Create agents in worktrees with auto-archive (#1120)

* Add daemon worktree auto-archive spawning

* Refactor create agent lifecycle dispatch

* Stabilize Claude autonomous turn test
This commit is contained in:
Mohamed Boudra
2026-05-20 22:41:15 +08:00
committed by GitHub
parent 68d88f0928
commit 3bca1a72e8
10 changed files with 722 additions and 9 deletions
@@ -0,0 +1,59 @@
import { describe, expect, test } from "vitest";
import { SessionInboundMessageSchema } from "./messages.js";
describe("create_agent_request worktree and autoArchive fields", () => {
test("accepts optional worktree branch-off target and autoArchive", () => {
const parsed = SessionInboundMessageSchema.parse({
type: "create_agent_request",
requestId: "create-agent-worktree",
config: {
provider: "codex",
cwd: "/repo/app",
},
worktree: {
mode: "branch-off",
newBranch: "agent-lifecycle-dispatch",
base: "main",
},
autoArchive: true,
});
expect(parsed).toEqual({
type: "create_agent_request",
requestId: "create-agent-worktree",
config: {
provider: "codex",
cwd: "/repo/app",
},
worktree: {
mode: "branch-off",
newBranch: "agent-lifecycle-dispatch",
base: "main",
},
autoArchive: true,
labels: {},
});
});
test("keeps legacy create_agent_request defaults unchanged", () => {
const parsed = SessionInboundMessageSchema.parse({
type: "create_agent_request",
requestId: "legacy-create-agent",
config: {
provider: "codex",
cwd: "/repo/app",
},
});
expect(parsed).toEqual({
type: "create_agent_request",
requestId: "legacy-create-agent",
config: {
provider: "codex",
cwd: "/repo/app",
},
labels: {},
});
});
});
+20
View File
@@ -1058,6 +1058,24 @@ const GitSetupOptionsSchema = z.object({
export type GitSetupOptions = z.infer<typeof GitSetupOptionsSchema>;
export const CreateAgentWorktreeTargetSchema = z.discriminatedUnion("mode", [
z.object({
mode: z.literal("branch-off"),
newBranch: z.string().min(1),
base: z.string().min(1).optional(),
}),
z.object({
mode: z.literal("checkout-branch"),
branch: z.string().min(1),
}),
z.object({
mode: z.literal("checkout-pr"),
prNumber: z.number().int().positive(),
}),
]);
export type CreateAgentWorktreeTarget = z.infer<typeof CreateAgentWorktreeTargetSchema>;
export const CreateAgentRequestMessageSchema = z.object({
type: z.literal("create_agent_request"),
config: AgentSessionConfigSchema,
@@ -1070,6 +1088,8 @@ export const CreateAgentRequestMessageSchema = z.object({
images: z.array(ImageAttachmentSchema).optional(),
attachments: AgentAttachmentsSchema,
git: GitSetupOptionsSchema.optional(),
worktree: CreateAgentWorktreeTargetSchema.optional(),
autoArchive: z.boolean().optional(),
labels: z.record(z.string()).default({}),
requestId: z.string(),
});