mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
feat(ui): /swarm in the task composer sends a structured swarm request
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c2b64e5223
commit
083403c65f
7 files changed
+92
-12
No files matched your search
@@ -734,10 +734,12 @@ export const issuesApi = {
|
||||
interrupt?: boolean,
|
||||
attachmentIds?: string[],
|
||||
clientRequestId?: string,
|
||||
nativeCommand?: "swarm",
|
||||
) =>
|
||||
confirmedCommentResponse(
|
||||
api.post<IssueComment>(`/issues/${id}/comments`, {
|
||||
body,
|
||||
...(nativeCommand ? { nativeCommand } : {}),
|
||||
...(clientRequestId ? { clientRequestId } : {}),
|
||||
...(reopen === undefined ? {} : { reopen }),
|
||||
...(interrupt === undefined ? {} : { interrupt }),
|
||||
|
||||
@@ -643,6 +643,7 @@ interface IssueChatThreadProps {
|
||||
attachmentIds?: string[],
|
||||
clientRequestId?: string,
|
||||
runSettings?: ComposerRunSettings,
|
||||
nativeCommand?: "swarm",
|
||||
) => Promise<void>;
|
||||
onCancelRun?: () => Promise<void>;
|
||||
stopPending?: boolean;
|
||||
@@ -6226,12 +6227,14 @@ export function IssueChatThread({
|
||||
onRefresh: onRefreshLatestComments,
|
||||
});
|
||||
const sendComposerComment = useCallback<IssueChatThreadProps["onAdd"]>(
|
||||
async (body, reopen, reassignment, attachmentIds, clientRequestId, runSettings) => {
|
||||
async (body, reopen, reassignment, attachmentIds, clientRequestId, runSettings, nativeCommand) => {
|
||||
pendingSubmitScrollRef.current = true;
|
||||
clientRequestId ??= createUuid();
|
||||
const attempt = beginSubmission(clientRequestId, undefined, reopen);
|
||||
try {
|
||||
await (runSettings
|
||||
await (nativeCommand
|
||||
? onAdd(body, reopen, reassignment, attachmentIds, clientRequestId, runSettings, nativeCommand)
|
||||
: runSettings
|
||||
? onAdd(body, reopen, reassignment, attachmentIds, clientRequestId, runSettings)
|
||||
: onAdd(body, reopen, reassignment, attachmentIds, clientRequestId));
|
||||
} catch (error) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
instanceExperimentalSettingsSchema,
|
||||
} from "@paperclipai/shared";
|
||||
import { parsePlanCommand, parseRunnerGoalCommand, TaskChatComposer } from "./TaskChatComposer";
|
||||
import { planSubmission } from "./composer-commands";
|
||||
import { parseSwarmCommand, planSubmission } from "./composer-commands";
|
||||
import { ComposerAddMenu } from "./ComposerAddMenu";
|
||||
import { QuestionForm } from "./QuestionForm";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
@@ -2003,6 +2003,47 @@ describe("TaskChatComposer", () => {
|
||||
expect(editable().textContent).toBe(`[/deploy](${SLASH_HREF}) `);
|
||||
});
|
||||
|
||||
describe("/swarm command", () => {
|
||||
it("matches only the user's leading /swarm token, through the shared rule", () => {
|
||||
expect(parseSwarmCommand(" /swarm two helpers write a.txt and b.txt ")).toEqual({ request: "two helpers write a.txt and b.txt" });
|
||||
expect(parseSwarmCommand("[/sw](</swarm write a.txt>)")).toEqual({ request: "write a.txt" });
|
||||
expect(parseSwarmCommand("/swarm")).toEqual({ request: "" });
|
||||
expect(parseSwarmCommand("Please /swarm this")).toBeNull();
|
||||
expect(parseSwarmCommand("> /swarm from a pasted email")).toBeNull();
|
||||
expect(parseSwarmCommand("```\n/swarm\n```")).toBeNull();
|
||||
expect(parseSwarmCommand("/swarms")).toBeNull();
|
||||
expect(parseSwarmCommand("/Swarm do it")).toBeNull();
|
||||
});
|
||||
|
||||
it("sends the request as a structured swarm request, without the command text", async () => {
|
||||
const onAdd = vi.fn().mockResolvedValue(undefined);
|
||||
renderComposer({ onAdd, workMode: "standard", onWorkModeChange: vi.fn() });
|
||||
typeText("/swarm two helpers write a.txt and b.txt");
|
||||
pressKey("Enter", { metaKey: true });
|
||||
await flushAsync();
|
||||
expect(onAdd).toHaveBeenCalledWith("two helpers write a.txt and b.txt", undefined, undefined, undefined, expect.any(String), undefined, "swarm");
|
||||
});
|
||||
|
||||
it("asks for a request instead of sending a bare /swarm", async () => {
|
||||
const onAdd = vi.fn().mockResolvedValue(undefined);
|
||||
renderComposer({ onAdd, workMode: "standard", onWorkModeChange: vi.fn() });
|
||||
typeText("/swarm");
|
||||
pressKey("Enter", { metaKey: true });
|
||||
await flushAsync();
|
||||
expect(onAdd).not.toHaveBeenCalled();
|
||||
expect(container.textContent).toContain("Write what the swarm should do after /swarm.");
|
||||
});
|
||||
|
||||
it("leaves a /swarm inside the message as ordinary text", async () => {
|
||||
const onAdd = vi.fn().mockResolvedValue(undefined);
|
||||
renderComposer({ onAdd, workMode: "standard", onWorkModeChange: vi.fn() });
|
||||
typeText("Please /swarm this");
|
||||
pressKey("Enter", { metaKey: true });
|
||||
await flushAsync();
|
||||
expect(onAdd).toHaveBeenCalledWith("Please /swarm this", undefined, undefined, undefined, expect.any(String));
|
||||
});
|
||||
});
|
||||
|
||||
describe("/plan command", () => {
|
||||
it("matches only the user's leading /plan token", () => {
|
||||
expect(parsePlanCommand(" /plan Add a greeting file ")).toEqual({ matched: true, request: "Add a greeting file" });
|
||||
|
||||
@@ -72,7 +72,7 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import type { MentionOption } from "@/components/MarkdownEditor";
|
||||
import type { IssueAttachment, IssueWorkMode } from "@paperclipai/shared";
|
||||
import type { RunnerGoalCapability } from "@paperclipai/shared";
|
||||
import { parseRunnerGoalCommand, planSubmission, type RunnerGoalComposerCommand } from "./composer-commands";
|
||||
import { parseRunnerGoalCommand, parseSwarmCommand, planSubmission, type RunnerGoalComposerCommand } from "./composer-commands";
|
||||
import type { ActionCommandOption } from "@/context/EditorAutocompleteContext";
|
||||
import { TaskChatComposerTakeoverActionsContext } from "./TaskChatComposerTakeoverContext";
|
||||
|
||||
@@ -115,6 +115,8 @@ interface TaskChatComposerProps {
|
||||
attachmentIds?: string[],
|
||||
clientRequestId?: string,
|
||||
runSettings?: ComposerRunSettings,
|
||||
/** A native command the user started with a leading `/name`; only "swarm" exists. */
|
||||
nativeCommand?: "swarm",
|
||||
) => Promise<void> | void;
|
||||
/** New tasks share the editor and controls, but retain their draft until creation succeeds. */
|
||||
creation?: {
|
||||
@@ -912,7 +914,17 @@ export function TaskChatComposer({
|
||||
return;
|
||||
}
|
||||
const sendMode = planCommand.kind === "send" ? "planning" : pendingMode;
|
||||
const trimmed = planCommand.kind === "send" ? planCommand.text : submittedBody.trim();
|
||||
// A queued edit keeps its exact text; everywhere else a leading /swarm is a request.
|
||||
const swarmCommand = queuedEdit ? null : parseSwarmCommand(submittedBody);
|
||||
if (swarmCommand && !swarmCommand.request) {
|
||||
setActionError("Write what the swarm should do after /swarm.");
|
||||
return;
|
||||
}
|
||||
if (swarmCommand && showAssignee && assigneeValue !== currentAssigneeValue) {
|
||||
setActionError("Send /swarm without changing the assignee.");
|
||||
return;
|
||||
}
|
||||
const trimmed = swarmCommand ? swarmCommand.request : planCommand.kind === "send" ? planCommand.text : submittedBody.trim();
|
||||
const goalCommand = queuedEdit
|
||||
? ({ matched: false } as const)
|
||||
: parseRunnerGoalCommand(submittedBody);
|
||||
@@ -1075,6 +1087,7 @@ export function TaskChatComposer({
|
||||
...(reassignment ? { reassignment } : {}),
|
||||
...(attachmentIds.length ? { attachmentIds } : {}),
|
||||
...(runSettings ? { runSettings: runSettings as unknown as Record<string, unknown> } : {}),
|
||||
...(swarmCommand ? { nativeCommand: "swarm" } : {}),
|
||||
};
|
||||
if (draftKey) {
|
||||
saveDraft(draftKey, submittedBody);
|
||||
@@ -1083,7 +1096,9 @@ export function TaskChatComposer({
|
||||
changeBody(bodyRef.current);
|
||||
}
|
||||
sentModeChoice.current = { attemptId, generation: submittedModeGeneration };
|
||||
if (runSettings) {
|
||||
if (swarmCommand) {
|
||||
await onAdd(fullBody, reopen, reassignment, attachmentIds.length ? attachmentIds : undefined, attemptId, runSettings ?? undefined, "swarm");
|
||||
} else if (runSettings) {
|
||||
await onAdd(fullBody, reopen, reassignment, attachmentIds.length ? attachmentIds : undefined, attemptId, runSettings);
|
||||
} else {
|
||||
await onAdd(fullBody, reopen, reassignment, attachmentIds.length ? attachmentIds : undefined, attemptId);
|
||||
@@ -1178,7 +1193,8 @@ export function TaskChatComposer({
|
||||
submission.attemptId,
|
||||
] as const;
|
||||
try {
|
||||
if (request.runSettings) await onAdd(...args, request.runSettings as unknown as ComposerRunSettings);
|
||||
if (request.nativeCommand === "swarm") await onAdd(...args, request.runSettings as unknown as ComposerRunSettings | undefined, "swarm");
|
||||
else if (request.runSettings) await onAdd(...args, request.runSettings as unknown as ComposerRunSettings);
|
||||
else await onAdd(...args);
|
||||
} catch (error) {
|
||||
if (!isCurrentAccount()) return "pending";
|
||||
|
||||
@@ -20,14 +20,14 @@ export type ParsedRunnerGoalCommand =
|
||||
| { matched: true; command: RunnerGoalComposerCommand }
|
||||
| { matched: true; error: string };
|
||||
|
||||
function normalizeActionCommandText(value: string, command: "goal" | "plan"): string {
|
||||
function normalizeActionCommandText(value: string, command: "goal" | "plan" | "swarm"): string {
|
||||
const trimmed = value.trim();
|
||||
// MDXEditor's link extension can reinterpret a selected action command plus
|
||||
// its subsequently typed argument as one relative autolink. Accept only the
|
||||
// exact whole-document shape it generates so the action still cannot fall
|
||||
// through as a comment. Ordinary Markdown links remain ordinary comments.
|
||||
// The label is any prefix of the command typed before it was selected.
|
||||
const label = command === "goal" ? "(?:go(?:al)?)?" : "(?:p(?:l(?:an?)?)?)?";
|
||||
const label = command === "goal" ? "(?:go(?:al)?)?" : command === "swarm" ? "(?:s(?:w(?:a(?:rm?)?)?)?)?" : "(?:p(?:l(?:an?)?)?)?";
|
||||
const relativeAutolink = trimmed.match(
|
||||
new RegExp(`^\\[\\/${label}[ \\t\\u00a0]*\\]\\(<(\\/${command}(?:[ \\t\\u00a0].*)?)>\\)$`, "s"),
|
||||
);
|
||||
@@ -55,6 +55,16 @@ export function parsePlanCommand(value: string): { matched: false } | { matched:
|
||||
return command ? { matched: true, request: command.argument } : { matched: false };
|
||||
}
|
||||
|
||||
/**
|
||||
* `/swarm <request>` asks a Google Antigravity agent for its native swarm. The
|
||||
* request is sent as a structured `nativeCommand`, never as command text; the
|
||||
* server decides whether a swarm can run and says why when it cannot.
|
||||
*/
|
||||
export function parseSwarmCommand(value: string): { request: string } | null {
|
||||
const command = parseLeadingUserCommand(normalizeActionCommandText(value, "swarm"), ["swarm"]);
|
||||
return command ? { request: command.argument } : null;
|
||||
}
|
||||
|
||||
export type PlanSubmission =
|
||||
| { kind: "none" }
|
||||
/** Select Plan mode and send nothing. */
|
||||
|
||||
@@ -106,6 +106,8 @@ export interface ComposerSendRequest {
|
||||
attachmentIds?: string[];
|
||||
/** Composer run settings, passed back unchanged. */
|
||||
runSettings?: Record<string, unknown>;
|
||||
/** A structured native command ("swarm"), resent unchanged so a retry stays a swarm request. */
|
||||
nativeCommand?: "swarm";
|
||||
}
|
||||
|
||||
export interface ComposerDraftSubmission {
|
||||
|
||||
@@ -5148,8 +5148,8 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS
|
||||
});
|
||||
|
||||
const addComment = useAccountBoundMutation({
|
||||
mutationFn: async ({ body, reopen, interrupt, attachmentIds, clientRequestId, runSettings }: {
|
||||
body: string; reopen?: boolean; interrupt?: boolean; attachmentIds?: string[]; clientRequestId?: string; runSettings?: ComposerRunSettings;
|
||||
mutationFn: async ({ body, reopen, interrupt, attachmentIds, clientRequestId, runSettings, nativeCommand }: {
|
||||
body: string; reopen?: boolean; interrupt?: boolean; attachmentIds?: string[]; clientRequestId?: string; runSettings?: ComposerRunSettings; nativeCommand?: "swarm";
|
||||
}, { assertCurrentAccount }) => {
|
||||
if (issue?.conversationAgentId) clearLegacyChatMessageRequests(`${issue.companyId}:${currentUserId}:${issue.conversationAgentId}`);
|
||||
const writableIssueId = await resolveWritableIssueId();
|
||||
@@ -5171,7 +5171,7 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS
|
||||
assertCurrentAccount();
|
||||
queryClient.setQueryData(queryKeys.issues.detail(writableIssueId), updated);
|
||||
}
|
||||
return issuesApi.addComment(writableIssueId, body, reopen, interrupt, attachmentIds, clientRequestId ?? createUuid());
|
||||
return issuesApi.addComment(writableIssueId, body, reopen, interrupt, attachmentIds, clientRequestId ?? createUuid(), nativeCommand);
|
||||
},
|
||||
onMutate: async ({ body, reopen, interrupt }) => {
|
||||
// Start cache cancellation immediately but do not put it in front of the
|
||||
@@ -7042,7 +7042,13 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS
|
||||
attachmentIds?: string[],
|
||||
clientRequestId?: string,
|
||||
runSettings?: ComposerRunSettings,
|
||||
nativeCommand?: "swarm",
|
||||
) => {
|
||||
// A swarm request always uses the comments endpoint, which checks it.
|
||||
if (nativeCommand) {
|
||||
await addComment.mutateAsync({ body, reopen, attachmentIds, clientRequestId, nativeCommand });
|
||||
return;
|
||||
}
|
||||
if (!issue?.conversationAgentId && (reassignment || runSettings)) {
|
||||
await addCommentAndReassign.mutateAsync({
|
||||
body,
|
||||
|
||||
Reference in new issue
Block a user