feat: support creating worktrees from GitHub pull requests
This commit is contained in:
@@ -413,6 +413,133 @@ describe("DaemonClient", () => {
|
||||
await expect(createPromise).rejects.toThrow("attachment test sentinel");
|
||||
});
|
||||
|
||||
test("sends worktree base-ref fields in create_agent_request git options", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
clientId: "clsk_unit_test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const createPromise = client.createAgent({
|
||||
provider: "codex",
|
||||
cwd: "/tmp/project",
|
||||
requestId: "req-agent-ref",
|
||||
git: {
|
||||
createWorktree: true,
|
||||
worktreeSlug: "review-pr-123",
|
||||
refName: "feature/worktree-base-ref",
|
||||
action: "checkout",
|
||||
githubPrNumber: 123,
|
||||
},
|
||||
});
|
||||
|
||||
expect(mock.sent).toHaveLength(1);
|
||||
const request = JSON.parse(String(mock.sent[0])) as {
|
||||
type: "session";
|
||||
message: {
|
||||
type: "create_agent_request";
|
||||
requestId: string;
|
||||
git: {
|
||||
createWorktree: boolean;
|
||||
worktreeSlug: string;
|
||||
refName: string;
|
||||
action: string;
|
||||
githubPrNumber: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
expect(request.message.git).toEqual({
|
||||
createWorktree: true,
|
||||
worktreeSlug: "review-pr-123",
|
||||
refName: "feature/worktree-base-ref",
|
||||
action: "checkout",
|
||||
githubPrNumber: 123,
|
||||
});
|
||||
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "status",
|
||||
payload: {
|
||||
status: "agent_create_failed",
|
||||
requestId: request.message.requestId,
|
||||
error: "git ref fields sentinel",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(createPromise).rejects.toThrow("git ref fields sentinel");
|
||||
});
|
||||
|
||||
test("omitting create_agent_request worktree base-ref fields preserves legacy wire shape", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
clientId: "clsk_unit_test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const createPromise = client.createAgent({
|
||||
provider: "codex",
|
||||
cwd: "/tmp/project",
|
||||
requestId: "req-agent-legacy",
|
||||
git: {
|
||||
createWorktree: true,
|
||||
worktreeSlug: "feature-a",
|
||||
},
|
||||
});
|
||||
|
||||
expect(String(mock.sent[0])).toBe(
|
||||
JSON.stringify({
|
||||
type: "session",
|
||||
message: {
|
||||
type: "create_agent_request",
|
||||
config: {
|
||||
provider: "codex",
|
||||
cwd: "/tmp/project",
|
||||
},
|
||||
git: {
|
||||
createWorktree: true,
|
||||
worktreeSlug: "feature-a",
|
||||
},
|
||||
labels: {},
|
||||
requestId: "req-agent-legacy",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "status",
|
||||
payload: {
|
||||
status: "agent_create_failed",
|
||||
requestId: "req-agent-legacy",
|
||||
error: "legacy git shape sentinel",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(createPromise).rejects.toThrow("legacy git shape sentinel");
|
||||
});
|
||||
|
||||
test("sends structured attachments with create_paseo_worktree_request", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
@@ -483,6 +610,134 @@ describe("DaemonClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("sends worktree base-ref fields in create_paseo_worktree_request", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
clientId: "clsk_unit_test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const createPromise = client.createPaseoWorktree(
|
||||
{
|
||||
cwd: "/tmp/project",
|
||||
worktreeSlug: "review-pr-123",
|
||||
refName: "feature/worktree-base-ref",
|
||||
action: "checkout",
|
||||
githubPrNumber: 123,
|
||||
},
|
||||
"req-worktree-ref",
|
||||
);
|
||||
|
||||
expect(mock.sent).toHaveLength(1);
|
||||
const request = JSON.parse(String(mock.sent[0])) as {
|
||||
type: "session";
|
||||
message: {
|
||||
type: "create_paseo_worktree_request";
|
||||
requestId: string;
|
||||
cwd: string;
|
||||
worktreeSlug: string;
|
||||
refName: string;
|
||||
action: string;
|
||||
githubPrNumber: number;
|
||||
};
|
||||
};
|
||||
expect(request.message).toEqual({
|
||||
type: "create_paseo_worktree_request",
|
||||
cwd: "/tmp/project",
|
||||
worktreeSlug: "review-pr-123",
|
||||
refName: "feature/worktree-base-ref",
|
||||
action: "checkout",
|
||||
githubPrNumber: 123,
|
||||
requestId: "req-worktree-ref",
|
||||
});
|
||||
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "create_paseo_worktree_response",
|
||||
payload: {
|
||||
requestId: request.message.requestId,
|
||||
workspace: null,
|
||||
error: "worktree ref fields sentinel",
|
||||
setupTerminalId: null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(createPromise).resolves.toEqual({
|
||||
requestId: request.message.requestId,
|
||||
workspace: null,
|
||||
error: "worktree ref fields sentinel",
|
||||
setupTerminalId: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("omitting create_paseo_worktree_request worktree base-ref fields preserves legacy wire shape", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
clientId: "clsk_unit_test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const createPromise = client.createPaseoWorktree(
|
||||
{
|
||||
cwd: "/tmp/project",
|
||||
worktreeSlug: "feature-a",
|
||||
},
|
||||
"req-worktree-legacy",
|
||||
);
|
||||
|
||||
expect(String(mock.sent[0])).toBe(
|
||||
JSON.stringify({
|
||||
type: "session",
|
||||
message: {
|
||||
type: "create_paseo_worktree_request",
|
||||
cwd: "/tmp/project",
|
||||
worktreeSlug: "feature-a",
|
||||
requestId: "req-worktree-legacy",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "create_paseo_worktree_response",
|
||||
payload: {
|
||||
requestId: "req-worktree-legacy",
|
||||
workspace: null,
|
||||
error: "legacy worktree shape sentinel",
|
||||
setupTerminalId: null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(createPromise).resolves.toEqual({
|
||||
requestId: "req-worktree-legacy",
|
||||
workspace: null,
|
||||
error: "legacy worktree shape sentinel",
|
||||
setupTerminalId: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("sends explicit shutdown_server_request via shutdownServer", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
@@ -16,8 +16,8 @@ import type {
|
||||
AgentSnapshotPayload,
|
||||
ProjectPlacementPayload,
|
||||
AgentPermissionResolvedMessage,
|
||||
AgentAttachment,
|
||||
CreateAgentRequestMessage,
|
||||
CreatePaseoWorktreeRequest,
|
||||
FileDownloadTokenResponse,
|
||||
FileExplorerResponse,
|
||||
FetchAgentTimelineResponseMessage,
|
||||
@@ -37,6 +37,7 @@ import type {
|
||||
ValidateBranchResponse,
|
||||
BranchSuggestionsResponse,
|
||||
GitHubSearchResponse,
|
||||
GitHubSearchRequest,
|
||||
DirectorySuggestionsResponse,
|
||||
PaseoWorktreeListResponse,
|
||||
PaseoWorktreeArchiveResponse,
|
||||
@@ -206,7 +207,7 @@ export type SendMessageOptions = {
|
||||
|
||||
type AgentConfigOverrides = Partial<Omit<AgentSessionConfig, "provider" | "cwd">>;
|
||||
|
||||
export type CreateAgentRequestOptions = {
|
||||
export interface CreateAgentRequestOptions extends AgentConfigOverrides {
|
||||
config?: AgentSessionConfig;
|
||||
provider?: AgentProvider;
|
||||
cwd?: string;
|
||||
@@ -220,7 +221,13 @@ export type CreateAgentRequestOptions = {
|
||||
worktreeName?: string;
|
||||
requestId?: string;
|
||||
labels?: Record<string, string>;
|
||||
} & AgentConfigOverrides;
|
||||
}
|
||||
|
||||
export interface CreatePaseoWorktreeInput
|
||||
extends Pick<
|
||||
CreatePaseoWorktreeRequest,
|
||||
"cwd" | "worktreeSlug" | "attachments" | "refName" | "action" | "githubPrNumber"
|
||||
> {}
|
||||
|
||||
type CheckoutStatusPayload = CheckoutStatusResponse["payload"];
|
||||
type SubscribeCheckoutDiffPayload = Extract<
|
||||
@@ -2576,11 +2583,7 @@ export class DaemonClient {
|
||||
}
|
||||
|
||||
async createPaseoWorktree(
|
||||
input: {
|
||||
cwd: string;
|
||||
worktreeSlug?: string;
|
||||
attachments?: AgentAttachment[];
|
||||
},
|
||||
input: CreatePaseoWorktreeInput,
|
||||
requestId?: string,
|
||||
): Promise<CreatePaseoWorktreePayload> {
|
||||
return this.sendCorrelatedSessionRequest({
|
||||
@@ -2592,6 +2595,9 @@ export class DaemonClient {
|
||||
...(input.attachments && input.attachments.length > 0
|
||||
? { attachments: input.attachments }
|
||||
: {}),
|
||||
...(input.refName !== undefined ? { refName: input.refName } : {}),
|
||||
...(input.action !== undefined ? { action: input.action } : {}),
|
||||
...(input.githubPrNumber !== undefined ? { githubPrNumber: input.githubPrNumber } : {}),
|
||||
},
|
||||
responseType: "create_paseo_worktree_response",
|
||||
timeout: 60000,
|
||||
@@ -2632,7 +2638,7 @@ export class DaemonClient {
|
||||
}
|
||||
|
||||
async searchGitHub(
|
||||
options: { cwd: string; query: string; limit?: number },
|
||||
options: { cwd: string; query: string; limit?: number; kinds?: GitHubSearchRequest["kinds"] },
|
||||
requestId?: string,
|
||||
): Promise<GitHubSearchPayload> {
|
||||
return this.sendCorrelatedSessionRequest({
|
||||
@@ -2642,6 +2648,7 @@ export class DaemonClient {
|
||||
cwd: options.cwd,
|
||||
query: options.query,
|
||||
limit: options.limit,
|
||||
kinds: options.kinds,
|
||||
},
|
||||
responseType: "github_search_response",
|
||||
timeout: 15000,
|
||||
|
||||
Reference in New Issue
Block a user