mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-02 21:26:57 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c37a407bc8 | ||
|
|
ef8de256ce | ||
|
|
68a1cd9a33 | ||
|
|
d4d8441f06 | ||
|
|
515392cd7b | ||
|
|
230037c03b | ||
|
|
0d9e960d10 |
+5
-3
@@ -216,9 +216,11 @@ its own.
|
||||
grew once its data arrived left the menu clipped, or hanging over its anchor, until it moved
|
||||
again. `AnchoredSurface` plays the same keyframes through the Web Animations API on web, which
|
||||
leaves no inline style; native keeps the Reanimated `Keyframe`.
|
||||
- **Animate only once placed.** `AnchoredSurface` remounts the surface when its position resolves,
|
||||
so the entering animation runs at the final position rather than ending unseen at the
|
||||
off-screen measuring position.
|
||||
- **Animate only once placed.** The entering animation must run at the final position, not end
|
||||
unseen at the off-screen measuring position. Native remounts the surface when its position
|
||||
resolves, because Reanimated's `entering` runs only on mount. Web keeps the surface mounted and
|
||||
starts its Web Animations entering animation on placement, so a popover's content mounts once
|
||||
per open.
|
||||
- **Sheets size to content.** `enableDynamicSizing`, not fixed snap points. A pushed page is
|
||||
rarely the height of the page before it. A fill page is the one exception.
|
||||
- **The sheet's content is teleported out of the menu's subtree**, so `MenuSheetSurface` rebuilds
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { gateNextAgentMessage } from "../support/helpers/agent-message-gate";
|
||||
import { expectComposerDraft, submitMessage } from "../support/helpers/composer";
|
||||
import { expectAgentIdle } from "../support/helpers/agent-stream";
|
||||
import { test, expect, type Page } from "../support/fixtures";
|
||||
import { seedMockAgentWorkspace, openAgentRoute } from "../support/helpers/mock-agent";
|
||||
import { openChangesPanel, openChangesTreePanel } from "../support/helpers/workspace-tabs";
|
||||
@@ -55,3 +58,45 @@ for (const width of [1400, 390]) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function addChangedFileToChat(page: Page) {
|
||||
await openChangesPanel(page);
|
||||
await page.getByTestId("diff-file-0-toggle").click({ button: "right" });
|
||||
await page.getByTestId("diff-file-0-add-to-chat").click();
|
||||
}
|
||||
|
||||
async function expectFollowUpAttachment(page: Page) {
|
||||
await expect(page.getByTestId("composer-workspace-file-attachment-pill")).toContainText(
|
||||
"follow-up.ts",
|
||||
);
|
||||
}
|
||||
|
||||
test("keeps a file added from Changes when an earlier send fails", async ({ page }) => {
|
||||
const gate = await gateNextAgentMessage(page);
|
||||
const workspace = await seedMockAgentWorkspace({
|
||||
repoPrefix: "attachment-during-send-",
|
||||
title: "Target chat",
|
||||
featureValues: { mockPromptRejections: 1 },
|
||||
});
|
||||
|
||||
try {
|
||||
await writeFile(path.join(workspace.cwd, "follow-up.ts"), "export const followUp = true;\n");
|
||||
await workspace.client.checkoutRefresh(workspace.cwd);
|
||||
await openAgentRoute(page, workspace);
|
||||
await expectAgentIdle(page);
|
||||
await submitMessage(page, "Send this first.");
|
||||
await gate.waitForRequest();
|
||||
|
||||
await addChangedFileToChat(page);
|
||||
await expectFollowUpAttachment(page);
|
||||
|
||||
gate.accept();
|
||||
await expect(
|
||||
page.getByRole("alert").filter({ hasText: "Requested mock prompt rejection" }),
|
||||
).toBeVisible();
|
||||
await expectFollowUpAttachment(page);
|
||||
await expectComposerDraft(page, "");
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1219,6 +1219,30 @@ test.describe("Agent message submission", () => {
|
||||
await retryRestoredSubmission(page, prompt);
|
||||
});
|
||||
|
||||
test("keeps a follow-up draft after the earlier send is rejected", async ({ page }, testInfo) => {
|
||||
const gate = await gateNextAgentMessage(page);
|
||||
const agent = await seedMockAgentWorkspace({
|
||||
repoPrefix: `pending-rejection-${testInfo.workerIndex}-`,
|
||||
title: "Pending rejection",
|
||||
model: "ten-second-stream",
|
||||
featureValues: { mockPromptRejections: 1 },
|
||||
});
|
||||
try {
|
||||
await openAgentRoute(page, { workspaceId: agent.workspaceId, agentId: agent.agentId });
|
||||
await expectAgentIdle(page);
|
||||
await submitMessage(page, "Send this first.");
|
||||
await gate.waitForRequest();
|
||||
await fillComposerDraft(page, "Keep this follow-up.");
|
||||
gate.accept();
|
||||
await expect(
|
||||
page.getByRole("alert").filter({ hasText: "Requested mock prompt rejection" }),
|
||||
).toBeVisible();
|
||||
await expectComposerDraft(page, "Keep this follow-up.");
|
||||
} finally {
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("restores an ambiguous Steer failure without retrying or interrupting", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
|
||||
@@ -45,6 +45,9 @@ function Details({ workspaceId, theme, layout, close }) {
|
||||
owner.subscribe({ snapshot(value) { setOwnerId(value.subscriptionId); }, update() { setUpdates((n) => n + 1); } });
|
||||
return () => { void owner.release(); };
|
||||
}, [paseo]);
|
||||
React.useEffect(() => {
|
||||
globalThis.__buttonContentMounts = (globalThis.__buttonContentMounts ?? 0) + 1;
|
||||
}, []);
|
||||
const rpc = useRpc(summary);
|
||||
const query = useQuery({ queryKey: ["summary"], queryFn: () => rpc({}) });
|
||||
if (failed) throw new Error("Button content failed");
|
||||
@@ -198,6 +201,13 @@ async function expectDetails(page: Page) {
|
||||
await expect(page.getByText("All systems operational", { exact: true })).toBeInViewport();
|
||||
}
|
||||
|
||||
/** How many times button content has mounted on the page, counted by the content itself. */
|
||||
async function contentMounts(page: Page): Promise<number> {
|
||||
return page.evaluate(
|
||||
() => (globalThis as { __buttonContentMounts?: number }).__buttonContentMounts ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
// The details render before the daemon answers their event subscription, and reopened
|
||||
// details show the cached summary at once, so wait for the subscription id to arrive.
|
||||
async function readContentObservation(page: Page): Promise<string> {
|
||||
@@ -231,14 +241,17 @@ async function expectCompactDetails(page: Page) {
|
||||
await expect(menu.getByText("Presentation: compact", { exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
/** Resolves once `subject` renders the same pixels twice in a row: entering animations are done. */
|
||||
/**
|
||||
* Resolves once `subject` renders the same pixels twice in a row: entering animations are done.
|
||||
* A remount detaches the element mid-screenshot; that is not still yet, so the poll starts over.
|
||||
*/
|
||||
async function expectStill(subject: Locator) {
|
||||
let previous: Buffer | null = null;
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const current = await subject.screenshot();
|
||||
const still = previous !== null && current.equals(previous);
|
||||
const current = await screenshotAttached(subject);
|
||||
const still = previous !== null && current !== null && current.equals(previous);
|
||||
previous = current;
|
||||
return still;
|
||||
},
|
||||
@@ -247,6 +260,17 @@ async function expectStill(subject: Locator) {
|
||||
.toBe(true);
|
||||
}
|
||||
|
||||
async function screenshotAttached(subject: Locator): Promise<Buffer | null> {
|
||||
try {
|
||||
return await subject.screenshot();
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("Element is not attached to the DOM")) {
|
||||
return null;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/** Attaches the screen once per colour scheme, for review alongside the run. */
|
||||
async function captureSchemes(page: Page, info: TestInfo, name: string, subject: Locator) {
|
||||
for (const colorScheme of ["light", "dark"] as const) {
|
||||
@@ -360,15 +384,18 @@ export async function withButtonShowcase(
|
||||
await run({
|
||||
verifyObservationLifetime: () =>
|
||||
test.step("closing and crashing content release its owner while sibling buttons and app remain live", async () => {
|
||||
const mountsBefore = await contentMounts(page);
|
||||
await press(page, "Header status");
|
||||
await expectDetails(page);
|
||||
const first = await readContentObservation(page);
|
||||
expect(await contentMounts(page)).toBe(mountsBefore + 1);
|
||||
await press(page, "Close deployment details");
|
||||
await expect.poll(() => released.has(first)).toBe(true);
|
||||
await press(page, "Composer status");
|
||||
await expectDetails(page);
|
||||
const second = await readContentObservation(page);
|
||||
expect(second).not.toBe(first);
|
||||
expect(await contentMounts(page)).toBe(mountsBefore + 2);
|
||||
await workspace.client.renameProject(workspace.projectId, "Observer control");
|
||||
await expect(page.getByText("Observed updates: 1", { exact: true })).toBeVisible();
|
||||
await press(page, "Fail button content");
|
||||
|
||||
@@ -55,6 +55,47 @@ it("keeps unavailable probes and external paths on the existing file-open path",
|
||||
}
|
||||
});
|
||||
|
||||
it("opens an existing absolute folder outside the workspace without a trailing slash", async () => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "outside-folder-link-"));
|
||||
roots.push(root);
|
||||
const workspaceRoot = path.join(root, "workspace");
|
||||
const folder = path.join(root, "reports").split(path.sep).join("/");
|
||||
const file = path.join(root, "notes.txt").split(path.sep).join("/");
|
||||
await mkdir(workspaceRoot);
|
||||
await mkdir(folder);
|
||||
await writeFile(file, "notes");
|
||||
|
||||
const { classifyForResolution } = await import("./resolver");
|
||||
const { resolveInlinePathDestination } = await import("./path-open");
|
||||
const client = {
|
||||
listDirectory: (cwd: string, requestedPath: string) => {
|
||||
const absolute = path.resolve(cwd, requestedPath);
|
||||
if (path.relative(cwd, absolute).split(path.sep)[0] === "..") {
|
||||
throw new Error("Access outside of workspace is not allowed");
|
||||
}
|
||||
return readdir(absolute);
|
||||
},
|
||||
getDirectorySuggestions: async () => ({ entries: [], error: null }),
|
||||
};
|
||||
const destination = async (href: string) => {
|
||||
const resolution = classifyForResolution({ href, text: "Open path" }, { workspaceRoot });
|
||||
if (resolution.kind !== "resolved" || resolution.value.kind !== "file") {
|
||||
throw new Error("Expected an explicit path link");
|
||||
}
|
||||
return resolveInlinePathDestination({ target: resolution.value.target, workspaceRoot, client });
|
||||
};
|
||||
|
||||
await expect(destination(file)).resolves.toMatchObject({
|
||||
kind: "file",
|
||||
location: { path: file },
|
||||
});
|
||||
await expect(destination(folder + "/")).resolves.toEqual({
|
||||
kind: "outsideDirectory",
|
||||
path: folder,
|
||||
});
|
||||
await expect(destination(folder)).resolves.toEqual({ kind: "outsideDirectory", path: folder });
|
||||
});
|
||||
|
||||
it("ignores an older probe after a newer file link opens", async () => {
|
||||
const { createInlinePathOpener } = await import("./path-open");
|
||||
let rejectProbe!: (error: Error) => void;
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
type WorkspaceFileLocation,
|
||||
type OpenFileDisposition,
|
||||
} from "@/workspace/file-open";
|
||||
import { resolveFilePreviewReadTarget } from "@/file-explorer/preview-target";
|
||||
import { isAbsolutePath } from "@/utils/path";
|
||||
import { resolveMissingNestedRelativeFile, type GetDirectorySuggestions } from "./resolver";
|
||||
|
||||
@@ -26,27 +27,30 @@ function isOutsideWorkspacePath(pathValue: string): boolean {
|
||||
return isAbsolutePath(pathValue) || pathValue === "~" || pathValue.startsWith("~/");
|
||||
}
|
||||
|
||||
/** Resolve workspace folders from filesystem facts, including names that contain dots. */
|
||||
/** Resolve folders from filesystem facts, including names that contain dots. */
|
||||
export async function resolveInlinePathOpen(input: PathOpenInput): Promise<PathOpenTarget> {
|
||||
if (!input.file) {
|
||||
return isOutsideWorkspacePath(input.directory)
|
||||
? { kind: "outsideDirectory", directoryPath: input.directory }
|
||||
: { kind: "directory", directoryPath: input.directory };
|
||||
}
|
||||
if (
|
||||
input.lineStart !== undefined ||
|
||||
isAbsolutePath(input.file) ||
|
||||
!input.workspaceRoot.trim() ||
|
||||
!input.client
|
||||
) {
|
||||
if (input.lineStart !== undefined || !input.workspaceRoot.trim() || !input.client) {
|
||||
return { kind: "file" };
|
||||
}
|
||||
const outside = isOutsideWorkspacePath(input.file);
|
||||
const probe = outside
|
||||
? resolveFilePreviewReadTarget({ path: input.file, workspaceRoot: input.workspaceRoot })
|
||||
: { cwd: input.workspaceRoot, path: input.file };
|
||||
if (!probe) return { kind: "file" };
|
||||
try {
|
||||
await input.client.listDirectory(input.workspaceRoot, input.file);
|
||||
await input.client.listDirectory(probe.cwd, probe.path);
|
||||
} catch {
|
||||
return { kind: "file" };
|
||||
}
|
||||
return { kind: "directory", directoryPath: input.file };
|
||||
return {
|
||||
kind: outside ? "outsideDirectory" : "directory",
|
||||
directoryPath: input.file,
|
||||
};
|
||||
}
|
||||
|
||||
export type InlinePathDestination =
|
||||
|
||||
@@ -120,6 +120,27 @@ describe("anchored menu surface on web", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("mounts its content once per open", async () => {
|
||||
const lifecycle: string[] = [];
|
||||
function RecordsMounts() {
|
||||
useEffect(() => {
|
||||
lifecycle.push("mount");
|
||||
return () => {
|
||||
lifecycle.push("unmount");
|
||||
};
|
||||
}, []);
|
||||
return <View testID="body" style={SHORT} />;
|
||||
}
|
||||
mountMenuAbovePill(<RecordsMounts />);
|
||||
|
||||
await wait(SETTLE_MS);
|
||||
|
||||
expect(element("panel").getBoundingClientRect().bottom).toBeLessThanOrEqual(
|
||||
element("pill").getBoundingClientRect().top,
|
||||
);
|
||||
expect(lifecycle).toEqual(["mount"]);
|
||||
});
|
||||
|
||||
it("widens when its content widens after the entering animation", async () => {
|
||||
mountMenuAbovePill(<GrowsAfterOpen afterMs={GROWS_BEFORE_CLEANUP_MS} from={SHORT} to={WIDE} />);
|
||||
|
||||
|
||||
@@ -284,9 +284,12 @@ export function AnchoredSurface({
|
||||
|
||||
// The surface is placed once both measurements land. Until then it sits off-screen so it can
|
||||
// be measured, and it must not animate: an entering animation that ran there would be over
|
||||
// before anyone saw the menu. Remounting on placement starts the native animation from the
|
||||
// final position; web starts its own animation on placement.
|
||||
// before anyone saw the menu. Native remounts the surface on placement so Reanimated's
|
||||
// `entering` starts from the final position. Web keeps it mounted and starts its own animation
|
||||
// on placement: a remount would mount the content twice per open, running its effects and
|
||||
// requests again and dropping its first state.
|
||||
const placed = position !== null;
|
||||
const surfaceKey = isWeb || placed ? "placed" : "measuring";
|
||||
|
||||
useWebContentEntering({ placed, surfaceNativeID });
|
||||
|
||||
@@ -365,7 +368,7 @@ export function AnchoredSurface({
|
||||
) : null}
|
||||
<View pointerEvents="box-none" style={frame.holder}>
|
||||
<FloatingSurface
|
||||
key={placed ? "placed" : "measuring"}
|
||||
key={surfaceKey}
|
||||
collapsable={false}
|
||||
tabIndex={-1}
|
||||
nativeID={surfaceNativeID}
|
||||
|
||||
@@ -467,6 +467,7 @@ export function WorkspaceSetupDialog() {
|
||||
attachments={chatDraft.attachments}
|
||||
onChangeAttachments={chatDraft.setAttachments}
|
||||
cwd={sourceDirectory}
|
||||
getDraftRevision={chatDraft.getRevision}
|
||||
clearDraft={chatDraft.clear}
|
||||
autoFocus
|
||||
commandDraft={composerState?.commandDraft}
|
||||
|
||||
@@ -68,6 +68,7 @@ export interface AgentInputDraft {
|
||||
textReplacement: TextReplacement;
|
||||
attachments: UserComposerAttachment[];
|
||||
setAttachments: (updater: AttachmentUpdater) => void;
|
||||
getRevision: () => number;
|
||||
clear: (lifecycle: "sent" | "abandoned") => void;
|
||||
isHydrated: boolean;
|
||||
attachmentFocusRequestId: number;
|
||||
@@ -195,6 +196,11 @@ export function useAgentInputDraft(input: UseAgentInputDraftInput): AgentInputDr
|
||||
[draftKey],
|
||||
);
|
||||
|
||||
const getRevision = useCallback(
|
||||
() => useDraftStore.getState().getDraftRevision(draftKey),
|
||||
[draftKey],
|
||||
);
|
||||
|
||||
const clear = useCallback(
|
||||
(lifecycle: "sent" | "abandoned") => {
|
||||
useDraftStore.getState().clearDraftInput({ draftKey, lifecycle });
|
||||
@@ -381,6 +387,7 @@ export function useAgentInputDraft(input: UseAgentInputDraftInput): AgentInputDr
|
||||
textReplacement,
|
||||
attachments,
|
||||
setAttachments,
|
||||
getRevision,
|
||||
clear,
|
||||
isHydrated,
|
||||
attachmentFocusRequestId,
|
||||
|
||||
@@ -587,6 +587,7 @@ export function WorkspaceDraftComposer({
|
||||
onOpenWorkspaceAttachment={handleOpenWorkspaceAttachment}
|
||||
onChangeAttachments={draftInput.setAttachments}
|
||||
cwd={composerState.workingDir}
|
||||
getDraftRevision={draftInput.getRevision}
|
||||
clearDraft={draftInput.clear}
|
||||
editingSession={editingSession}
|
||||
autoFocus={shouldAutoFocusWorkspaceDraftComposer({ isPaneFocused, isSubmitting })}
|
||||
|
||||
@@ -952,6 +952,7 @@ interface ComposerProps {
|
||||
onForgeChangeRequestDetected?: () => void;
|
||||
onForgeChangeRequestAutoAttach?: (item: ForgeSearchItem) => void;
|
||||
cwd: string;
|
||||
getDraftRevision: () => number;
|
||||
clearDraft: (lifecycle: "sent" | "abandoned") => void;
|
||||
/** When true, auto-focuses the text input on web. */
|
||||
autoFocus?: boolean;
|
||||
@@ -1280,6 +1281,7 @@ function ComposerContentImpl({
|
||||
onForgeChangeRequestDetected,
|
||||
onForgeChangeRequestAutoAttach,
|
||||
cwd,
|
||||
getDraftRevision,
|
||||
clearDraft,
|
||||
autoFocus = false,
|
||||
autoFocusKey,
|
||||
@@ -1882,6 +1884,7 @@ function ComposerContentImpl({
|
||||
await submitMessage(submitText, submitAttachments);
|
||||
},
|
||||
clearDraft,
|
||||
getDraftRevision,
|
||||
setUserInput: replaceUserInput,
|
||||
setAttachments: (nextAttachments) => {
|
||||
setSelectedAttachments(composerWorkspaceAttachment.userAttachmentsOnly(nextAttachments));
|
||||
@@ -1904,6 +1907,7 @@ function ComposerContentImpl({
|
||||
clearDraft,
|
||||
completeSubmit,
|
||||
enqueueMessage,
|
||||
getDraftRevision,
|
||||
hasExternalContent,
|
||||
isAgentRunning,
|
||||
supportsQueue,
|
||||
|
||||
@@ -35,6 +35,7 @@ describe("submitAgentInput", () => {
|
||||
canSubmit: true,
|
||||
queueMessage,
|
||||
submitMessage,
|
||||
getDraftRevision: () => 0,
|
||||
clearDraft,
|
||||
setUserInput,
|
||||
setAttachments,
|
||||
@@ -59,6 +60,53 @@ describe("submitAgentInput", () => {
|
||||
expect(clearDraft).toHaveBeenCalledWith("sent");
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ delivery: "send", outcome: "failed" },
|
||||
{ delivery: "send", outcome: "submitted" },
|
||||
{ delivery: "queue", outcome: "failed" },
|
||||
{ delivery: "queue", outcome: "queued" },
|
||||
] as const)(
|
||||
"preserves edits made while a $delivery is pending ($outcome)",
|
||||
async ({ delivery, outcome }) => {
|
||||
let revision = 0;
|
||||
let text = "first message";
|
||||
let attachments = ["first.txt"];
|
||||
const setUserInput = (next: string) => {
|
||||
text = next;
|
||||
revision++;
|
||||
};
|
||||
const setAttachments = (next: string[]) => {
|
||||
attachments = next;
|
||||
revision++;
|
||||
};
|
||||
const deferred = createDeferredPromise<void>();
|
||||
const result = submitAgentInput({
|
||||
message: text,
|
||||
attachments,
|
||||
isAgentRunning: delivery === "queue",
|
||||
canSubmit: true,
|
||||
queueMessage: () => deferred.promise,
|
||||
submitMessage: () => deferred.promise,
|
||||
clearDraft: () => {
|
||||
setUserInput("");
|
||||
setAttachments([]);
|
||||
},
|
||||
setUserInput,
|
||||
setAttachments,
|
||||
getDraftRevision: () => revision,
|
||||
setSendError: vi.fn(),
|
||||
setIsProcessing: vi.fn(),
|
||||
});
|
||||
setUserInput("follow-up");
|
||||
setAttachments(["second.txt"]);
|
||||
if (outcome === "failed") deferred.reject(new Error("offline"));
|
||||
else deferred.resolve();
|
||||
expect(await result).toBe(outcome);
|
||||
expect(text).toBe("follow-up");
|
||||
expect(attachments).toEqual(["second.txt"]);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves the composer before an in-flight submit resolves when requested", async () => {
|
||||
const deferred = createDeferredPromise<void>();
|
||||
const attachments = [{ id: "img-1" }];
|
||||
@@ -80,6 +128,7 @@ describe("submitAgentInput", () => {
|
||||
canSubmit: true,
|
||||
queueMessage,
|
||||
submitMessage,
|
||||
getDraftRevision: () => 0,
|
||||
clearDraft,
|
||||
setUserInput,
|
||||
setAttachments,
|
||||
@@ -123,6 +172,7 @@ describe("submitAgentInput", () => {
|
||||
submitMessage: async ({ message }) => {
|
||||
sent.push(message);
|
||||
},
|
||||
getDraftRevision: () => 0,
|
||||
clearDraft: (lifecycle) => {
|
||||
composer.draft = lifecycle;
|
||||
},
|
||||
@@ -193,6 +243,7 @@ describe("submitAgentInput", () => {
|
||||
canSubmit: true,
|
||||
queueMessage,
|
||||
submitMessage,
|
||||
getDraftRevision: () => 0,
|
||||
clearDraft,
|
||||
setUserInput,
|
||||
setAttachments,
|
||||
@@ -232,6 +283,7 @@ describe("submitAgentInput", () => {
|
||||
submitMessage: async () => {
|
||||
throw error;
|
||||
},
|
||||
getDraftRevision: () => 0,
|
||||
clearDraft: vi.fn(),
|
||||
setUserInput,
|
||||
setAttachments,
|
||||
@@ -265,6 +317,7 @@ describe("submitAgentInput", () => {
|
||||
canSubmit: true,
|
||||
queueMessage,
|
||||
submitMessage,
|
||||
getDraftRevision: () => 0,
|
||||
clearDraft,
|
||||
setUserInput,
|
||||
setAttachments,
|
||||
|
||||
@@ -17,6 +17,7 @@ export interface AgentInputSubmitActionInput<TAttachment> {
|
||||
clearDraft: (lifecycle: "sent" | "abandoned") => void;
|
||||
setUserInput: (text: string) => void;
|
||||
setAttachments: (attachments: TAttachment[]) => void;
|
||||
getDraftRevision: () => number;
|
||||
setSendError: (message: string | null) => void;
|
||||
setIsProcessing: (isProcessing: boolean) => void;
|
||||
onSubmitError?: (error: unknown) => void;
|
||||
@@ -50,18 +51,21 @@ export async function submitAgentInput<TAttachment>(
|
||||
input.setUserInput("");
|
||||
input.setAttachments([]);
|
||||
}
|
||||
const submittedRevision = shouldClearOnSubmit ? input.getDraftRevision() : null;
|
||||
input.setSendError(null);
|
||||
input.setIsProcessing(true);
|
||||
|
||||
try {
|
||||
const deliver = shouldQueue ? input.queueMessage : input.submitMessage;
|
||||
await deliver({ message: trimmedMessage, attachments });
|
||||
input.clearDraft("sent");
|
||||
if (!shouldClearOnSubmit || input.getDraftRevision() === submittedRevision) {
|
||||
input.clearDraft("sent");
|
||||
}
|
||||
input.setIsProcessing(false);
|
||||
return shouldQueue ? "queued" : "submitted";
|
||||
} catch (error) {
|
||||
input.onSubmitError?.(error);
|
||||
if (shouldClearOnSubmit) {
|
||||
if (shouldClearOnSubmit && input.getDraftRevision() === submittedRevision) {
|
||||
input.setUserInput(trimmedMessage);
|
||||
input.setAttachments(attachments);
|
||||
}
|
||||
|
||||
@@ -1192,6 +1192,7 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
textReplacement,
|
||||
attachments,
|
||||
setAttachments,
|
||||
getRevision,
|
||||
clear,
|
||||
isHydrated,
|
||||
attachmentFocusRequestId,
|
||||
@@ -1205,6 +1206,7 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
textReplacement,
|
||||
attachments,
|
||||
setAttachments,
|
||||
getRevision,
|
||||
clear,
|
||||
isHydrated,
|
||||
attachmentFocusRequestId,
|
||||
@@ -1217,6 +1219,7 @@ const ChatAgentReadyContent = memo(function ChatAgentReadyContent({
|
||||
textReplacement,
|
||||
attachments,
|
||||
setAttachments,
|
||||
getRevision,
|
||||
clear,
|
||||
isHydrated,
|
||||
attachmentFocusRequestId,
|
||||
@@ -1859,6 +1862,7 @@ function ActiveAgentComposer({
|
||||
onOpenWorkspaceAttachment={handleOpenWorkspaceAttachment}
|
||||
onChangeAttachments={agentInputDraft.setAttachments}
|
||||
cwd={cwd}
|
||||
getDraftRevision={agentInputDraft.getRevision}
|
||||
clearDraft={agentInputDraft.clear}
|
||||
editingSession={editingSession}
|
||||
autoFocus
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Session } from "node:inspector/promises";
|
||||
import { getPluginClientApi } from "./client-state/api";
|
||||
import { filePanelTitle } from "@/file-panels/choice/presentation";
|
||||
import { i18n } from "@/i18n/i18next";
|
||||
@@ -236,3 +237,27 @@ test("locale snapshots preserve installation state and observations, then releas
|
||||
expect(listeners.size).toBe(0);
|
||||
await expect.poll(() => h.open.size).toBe(0);
|
||||
});
|
||||
|
||||
test("reloading a plugin releases the previous installation", async () => {
|
||||
const h = registry();
|
||||
const options = { client: h.client, audio };
|
||||
const entry = catalog("reloaded");
|
||||
h.plugins.installCatalog("host", [entry], options);
|
||||
// The published snapshot is a copy. Its lifetime belongs to the installation itself.
|
||||
const previous = new WeakRef(h.plugins.getSnapshot()[0]!.lifetime);
|
||||
|
||||
h.plugins.installCatalog("host", [entry], { ...options, replacePluginId: entry.id });
|
||||
expect(h.plugins.getSnapshot()[0]?.lifetime).not.toBe(previous.deref());
|
||||
|
||||
const inspector = new Session();
|
||||
inspector.connect();
|
||||
try {
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
await inspector.post("HeapProfiler.collectGarbage");
|
||||
expect(previous.deref() === undefined).toBe(true);
|
||||
expect(h.plugins.getSnapshot()).toHaveLength(1);
|
||||
} finally {
|
||||
inspector.disconnect();
|
||||
h.plugins.removeHost("host");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -89,91 +89,15 @@ export class PluginRegistry {
|
||||
this.publish();
|
||||
for (const plugin of removed) this.dispose(plugin);
|
||||
}
|
||||
const installed = catalog.flatMap((entry) => {
|
||||
const key = `${serverId}/${entry.id}`;
|
||||
let installation: InstalledPlugin | undefined;
|
||||
try {
|
||||
if (!entry.clientBundle) return [];
|
||||
assertPluginCompatibility({ ...entry, version: this.dependencies.version, runtime: "app" });
|
||||
const existing = preserved.find(
|
||||
(plugin) => plugin.id === entry.id && plugin.clientBundle === entry.clientBundle,
|
||||
);
|
||||
if (existing) {
|
||||
this.evaluationErrors.delete(key);
|
||||
return [existing];
|
||||
}
|
||||
const client = options.client;
|
||||
const lifetime = new AbortController();
|
||||
installation = {
|
||||
lifetime,
|
||||
locale: this.dependencies.localeSource.getLocale(),
|
||||
i18n: new PluginTranslationRuntime(this.dependencies.localeSource),
|
||||
paseo: createPaseoApi(client),
|
||||
invoke: (method, input) => client.invokePluginRpc(entry.id, method, input),
|
||||
subscribe: createPluginSubscribe({
|
||||
client,
|
||||
pluginId: entry.id,
|
||||
lifetime: lifetime.signal,
|
||||
}),
|
||||
id: entry.id,
|
||||
serverId,
|
||||
clientBundle: entry.clientBundle,
|
||||
requirements: entry.requirements,
|
||||
queryClient: new QueryClient(),
|
||||
cleanup: () => undefined,
|
||||
surfaces: [],
|
||||
settingsScreens: [],
|
||||
sidebarViews: [],
|
||||
sidebarItems: { header: [], footer: [] },
|
||||
legacySidebarItems: [],
|
||||
workspaceRowBadgeItems: [],
|
||||
filePanels: [],
|
||||
composerItems: [],
|
||||
newWorkspaceItems: [],
|
||||
workspacePanels: [],
|
||||
commandCenterItems: [],
|
||||
clientSlashCommands: [],
|
||||
attachmentSources: [],
|
||||
themes: [],
|
||||
timelineTransformers: [],
|
||||
timelineRenderers: [],
|
||||
notificationOpenHandlers: [],
|
||||
};
|
||||
const unsubscribeTranslations = installation.i18n.subscribe(() => this.publish());
|
||||
installation.lifetime.signal.addEventListener("abort", unsubscribeTranslations, {
|
||||
once: true,
|
||||
});
|
||||
const runtime = this.dependencies.createRuntime(installation, options.audio);
|
||||
const evaluated = runPluginClientBundle(
|
||||
{ serverId, pluginId: entry.id },
|
||||
entry.clientBundle,
|
||||
runtime,
|
||||
() => this.publish(),
|
||||
);
|
||||
Object.assign(installation, evaluated);
|
||||
const paseo = installation.paseo;
|
||||
installation.cleanup = async () => {
|
||||
const results = await Promise.allSettled([paseo.dispose(), evaluated.cleanup()]);
|
||||
const failures = results.filter((result) => result.status === "rejected");
|
||||
if (failures.length)
|
||||
throw new AggregateError(
|
||||
failures.map((result) => result.reason),
|
||||
"Plugin cleanup failed",
|
||||
);
|
||||
};
|
||||
this.evaluationErrors.delete(key);
|
||||
return [installation];
|
||||
} catch (error) {
|
||||
installation?.lifetime.abort();
|
||||
installation?.i18n.dispose();
|
||||
void installation?.paseo
|
||||
.dispose()
|
||||
.catch((failure) => console.warn(`[Plugins] API cleanup failed for ${key}`, failure));
|
||||
this.evaluationErrors.set(key, error instanceof Error ? error.message : String(error));
|
||||
console.warn(`[Plugins] Failed to evaluate ${serverId}/${entry.id}`, error);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
const installed = catalog.flatMap((entry) =>
|
||||
this.installPlugin({
|
||||
serverId,
|
||||
entry,
|
||||
preserved,
|
||||
client: options.client,
|
||||
audio: options.audio,
|
||||
}),
|
||||
);
|
||||
const configuredIds = new Set(catalog.map((entry) => entry.id));
|
||||
for (const key of this.evaluationErrors.keys()) {
|
||||
if (key.startsWith(`${serverId}/`) && !configuredIds.has(key.slice(serverId.length + 1))) {
|
||||
@@ -215,6 +139,104 @@ export class PluginRegistry {
|
||||
this.publish();
|
||||
}
|
||||
|
||||
// Keep the closures for one installation out of the scope that holds the previous catalog.
|
||||
private installPlugin({
|
||||
serverId,
|
||||
entry,
|
||||
preserved,
|
||||
client,
|
||||
audio,
|
||||
}: {
|
||||
serverId: string;
|
||||
entry: CatalogPlugin;
|
||||
preserved: InstalledPlugin[];
|
||||
client: DaemonClient;
|
||||
audio: Pick<AudioEngine, "play">;
|
||||
}): InstalledPlugin[] {
|
||||
const key = `${serverId}/${entry.id}`;
|
||||
let installation: InstalledPlugin | undefined;
|
||||
try {
|
||||
if (!entry.clientBundle) return [];
|
||||
assertPluginCompatibility({ ...entry, version: this.dependencies.version, runtime: "app" });
|
||||
const existing = preserved.find(
|
||||
(plugin) => plugin.id === entry.id && plugin.clientBundle === entry.clientBundle,
|
||||
);
|
||||
if (existing) {
|
||||
this.evaluationErrors.delete(key);
|
||||
return [existing];
|
||||
}
|
||||
const lifetime = new AbortController();
|
||||
installation = {
|
||||
lifetime,
|
||||
locale: this.dependencies.localeSource.getLocale(),
|
||||
i18n: new PluginTranslationRuntime(this.dependencies.localeSource),
|
||||
paseo: createPaseoApi(client),
|
||||
invoke: (method, input) => client.invokePluginRpc(entry.id, method, input),
|
||||
subscribe: createPluginSubscribe({
|
||||
client,
|
||||
pluginId: entry.id,
|
||||
lifetime: lifetime.signal,
|
||||
}),
|
||||
id: entry.id,
|
||||
serverId,
|
||||
clientBundle: entry.clientBundle,
|
||||
requirements: entry.requirements,
|
||||
queryClient: new QueryClient(),
|
||||
cleanup: () => undefined,
|
||||
surfaces: [],
|
||||
settingsScreens: [],
|
||||
sidebarViews: [],
|
||||
sidebarItems: { header: [], footer: [] },
|
||||
legacySidebarItems: [],
|
||||
workspaceRowBadgeItems: [],
|
||||
filePanels: [],
|
||||
composerItems: [],
|
||||
newWorkspaceItems: [],
|
||||
workspacePanels: [],
|
||||
commandCenterItems: [],
|
||||
clientSlashCommands: [],
|
||||
attachmentSources: [],
|
||||
themes: [],
|
||||
timelineTransformers: [],
|
||||
timelineRenderers: [],
|
||||
notificationOpenHandlers: [],
|
||||
};
|
||||
const unsubscribeTranslations = installation.i18n.subscribe(() => this.publish());
|
||||
installation.lifetime.signal.addEventListener("abort", unsubscribeTranslations, {
|
||||
once: true,
|
||||
});
|
||||
const runtime = this.dependencies.createRuntime(installation, audio);
|
||||
const evaluated = runPluginClientBundle(
|
||||
{ serverId, pluginId: entry.id },
|
||||
entry.clientBundle,
|
||||
runtime,
|
||||
() => this.publish(),
|
||||
);
|
||||
Object.assign(installation, evaluated);
|
||||
const paseo = installation.paseo;
|
||||
installation.cleanup = async () => {
|
||||
const results = await Promise.allSettled([paseo.dispose(), evaluated.cleanup()]);
|
||||
const failures = results.filter((result) => result.status === "rejected");
|
||||
if (failures.length)
|
||||
throw new AggregateError(
|
||||
failures.map((result) => result.reason),
|
||||
"Plugin cleanup failed",
|
||||
);
|
||||
};
|
||||
this.evaluationErrors.delete(key);
|
||||
return [installation];
|
||||
} catch (error) {
|
||||
installation?.lifetime.abort();
|
||||
installation?.i18n.dispose();
|
||||
void installation?.paseo
|
||||
.dispose()
|
||||
.catch((failure) => console.warn(`[Plugins] API cleanup failed for ${key}`, failure));
|
||||
this.evaluationErrors.set(key, error instanceof Error ? error.message : String(error));
|
||||
console.warn(`[Plugins] Failed to evaluate ${serverId}/${entry.id}`, error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private hostEvaluationErrors(serverId: string): string {
|
||||
const prefix = `${serverId}/`;
|
||||
return JSON.stringify(
|
||||
|
||||
@@ -200,6 +200,7 @@ interface NewWorkspaceScreenProps {
|
||||
const NO_TERMINAL_ATTACHMENTS: UserComposerAttachment[] = [];
|
||||
function noopChangeAttachments() {}
|
||||
function noopClearDraft() {}
|
||||
const getTerminalDraftRevision = () => 0;
|
||||
|
||||
// Stable reference so the keyboard-action handler doesn't re-register each render.
|
||||
const PROJECT_PICK_ACTIONS: readonly KeyboardActionId[] = [
|
||||
@@ -1685,6 +1686,7 @@ export function NewWorkspaceScreen({
|
||||
attachments={NO_TERMINAL_ATTACHMENTS}
|
||||
onChangeAttachments={noopChangeAttachments}
|
||||
cwd={workingDirectory ?? ""}
|
||||
getDraftRevision={getTerminalDraftRevision}
|
||||
clearDraft={noopClearDraft}
|
||||
autoFocus={terminalTakesPrompt}
|
||||
autoFocusKey={launchFocusKey}
|
||||
@@ -1716,6 +1718,7 @@ export function NewWorkspaceScreen({
|
||||
onForgeChangeRequestDetected={handleForgeChangeRequestDetected}
|
||||
onForgeChangeRequestAutoAttach={handleForgeChangeRequestAutoAttach}
|
||||
cwd={workingDirectory ?? ""}
|
||||
getDraftRevision={chatDraft.getRevision}
|
||||
clearDraft={handleClearDraft}
|
||||
autoFocus
|
||||
autoFocusKey={launchFocusKey}
|
||||
|
||||
@@ -45,6 +45,7 @@ import { hasDraftContent } from "@/composer/draft/input-draft-core";
|
||||
export type { DraftInput, DraftLifecycleState } from "./state";
|
||||
|
||||
interface DraftStoreActions {
|
||||
getDraftRevision: (draftKey: string) => number;
|
||||
getDraftInput: (draftKey: string) => DraftInput | undefined;
|
||||
hydrateDraftInput: (input: { draftKey: string }) => Promise<DraftInput | undefined>;
|
||||
saveDraftInput: (input: { draftKey: string; draft: DraftInput }) => void;
|
||||
@@ -283,6 +284,11 @@ export const useDraftStore = create<DraftStore>()(
|
||||
textReplacementRequestByDraftKey: {},
|
||||
metadataByDraftKey: {},
|
||||
|
||||
getDraftRevision: (draftKey) => {
|
||||
get().flushDraftText(draftKey);
|
||||
return get().drafts[draftKey]?.version ?? 0;
|
||||
},
|
||||
|
||||
getDraftInput: (draftKey) => {
|
||||
const record = get().drafts[draftKey];
|
||||
return toDraftInputIfReady(record);
|
||||
|
||||
@@ -28,6 +28,12 @@ describe("draft-store lifecycle", () => {
|
||||
expect(editDraftRecordText(edited, "", 3).lifecycle).toBe("active");
|
||||
expect(editDraftRecordText(undefined, "", 3).lifecycle).toBe("abandoned");
|
||||
});
|
||||
it("keeps the version when a cleared draft publishes empty text again", () => {
|
||||
const cleared = editDraftRecordText(undefined, "", 1);
|
||||
expect(editDraftRecordText(cleared, "", 2)).toBe(cleared);
|
||||
expect(editDraftRecordText(cleared, "follow-up", 2).version).toBe(cleared.version + 1);
|
||||
});
|
||||
|
||||
it("prunes finalized tombstones after TTL", () => {
|
||||
const nowMs = 1_000_000;
|
||||
const drafts = {
|
||||
|
||||
@@ -38,7 +38,11 @@ export function editDraftRecordText(
|
||||
text: string,
|
||||
now: number,
|
||||
): DraftRecord {
|
||||
if (record?.lifecycle === "active" && record.input.text === text) return record;
|
||||
if (
|
||||
record?.input.text === text &&
|
||||
(record.lifecycle === "active" || record.lifecycle === "abandoned")
|
||||
)
|
||||
return record;
|
||||
const attachments = record?.lifecycle === "active" ? record.input.attachments : [];
|
||||
return {
|
||||
input: { text, attachments },
|
||||
|
||||
@@ -17,11 +17,7 @@ export async function connectTerminalClient(target: DaemonTarget) {
|
||||
try {
|
||||
const daemonClient = await connectToDaemon({ target });
|
||||
const terminals = createTerminalActions(daemonClient, async (workspaceId) => {
|
||||
const result = await daemonClient.fetchWorkspaces({
|
||||
filter: { idPrefix: workspaceId, includeBackground: true },
|
||||
page: { limit: 10 },
|
||||
});
|
||||
const workspace = result.entries.find((entry) => entry.id === workspaceId);
|
||||
const workspace = await daemonClient.findWorkspace(workspaceId);
|
||||
if (!workspace?.workspaceDirectory) {
|
||||
throw new Error(`Workspace ${workspaceId} is not active or has no available directory`);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,18 @@ try {
|
||||
await cli(["terminal", "kill", feature.id]);
|
||||
assert.deepEqual(await cli(["terminal", "ls", "--workspace", second.id]), []);
|
||||
assert.deepEqual(await cli(["terminal", "ls", "--workspace", first.id]), [main]);
|
||||
for (let i = 0; i < 9; i++) {
|
||||
await sdk.workspaces.create({
|
||||
source: { kind: "directory", path: ctx.workDir },
|
||||
title: `extra-${i}`,
|
||||
});
|
||||
}
|
||||
const workspaces = await cli(["workspace", "ls"]);
|
||||
assert.equal(workspaces.length, 11);
|
||||
const { workspaceId, cwd } = workspaces[10];
|
||||
const created = await cli(["terminal", "create", "--workspace", workspaceId, "--name", "Older"]);
|
||||
assert.deepEqual(created, { id: created.id, name: "Older", workspaceId, cwd });
|
||||
await cli(["terminal", "kill", created.id]);
|
||||
console.log("Terminal workspace CLI: ownership, lists, input, capture, kill, and errors passed");
|
||||
} finally {
|
||||
await sdk.close();
|
||||
|
||||
@@ -669,9 +669,10 @@ async function clickGuestElement(page, client, browserId, selector) {
|
||||
}
|
||||
|
||||
async function selectDeviceSize(page, label) {
|
||||
await page.locator('[aria-label="Device size"]').click();
|
||||
const item = page.getByText(label, { exact: true });
|
||||
await item.waitFor({ state: "visible", timeout: timeoutMs });
|
||||
const trigger = page.getByLabel("Device size", { exact: true });
|
||||
const item = page.getByRole("menuitem", { name: label, exact: true });
|
||||
await trigger.click();
|
||||
await item.click({ trial: true, timeout: timeoutMs });
|
||||
const rect = await item.boundingBox();
|
||||
assert(rect, `Device size menu item ${label} had no bounds`);
|
||||
const clip = {
|
||||
@@ -685,9 +686,9 @@ async function selectDeviceSize(page, label) {
|
||||
await item.waitFor({ state: "hidden", timeout: timeoutMs });
|
||||
const closedPixels = await page.screenshot({ clip });
|
||||
|
||||
await page.locator('[aria-label="Device size"]').click();
|
||||
await item.waitFor({ state: "visible", timeout: timeoutMs });
|
||||
await page.mouse.click(rect.x + rect.width / 2, rect.y + rect.height / 2);
|
||||
await trigger.click();
|
||||
// The reopened menu renders off-screen while measuring. Click its current position after layout.
|
||||
await item.click({ timeout: timeoutMs });
|
||||
await page.keyboard.press("Escape");
|
||||
return !openPixels.equals(closedPixels);
|
||||
}
|
||||
|
||||
@@ -4583,6 +4583,7 @@ describe("ClaudeAgentSession context window usage", () => {
|
||||
[
|
||||
notification("code-mode-opt-in", "Code Mode isn't available.", "medium"),
|
||||
notification("urgent", "Something needs attention.", "immediate"),
|
||||
notification("stop-hook-error", "stop hook problem · ctrl+o to see", "immediate"),
|
||||
createSuccessResult(),
|
||||
],
|
||||
]),
|
||||
@@ -4600,6 +4601,7 @@ describe("ClaudeAgentSession context window usage", () => {
|
||||
).toEqual([
|
||||
{ type: "notification", level: "info", message: "Code Mode isn't available." },
|
||||
{ type: "notification", level: "warning", message: "Something needs attention." },
|
||||
{ type: "notification", level: "warning", message: "stop hook problem" },
|
||||
]);
|
||||
expect(
|
||||
logs
|
||||
@@ -4608,6 +4610,7 @@ describe("ClaudeAgentSession context window usage", () => {
|
||||
).toEqual([
|
||||
{ level: 30, key: "code-mode-opt-in", text: "Code Mode isn't available." },
|
||||
{ level: 40, key: "urgent", text: "Something needs attention." },
|
||||
{ level: 40, key: "stop-hook-error", text: "stop hook problem · ctrl+o to see" },
|
||||
]);
|
||||
} finally {
|
||||
await session.close();
|
||||
|
||||
@@ -5525,10 +5525,16 @@ class ClaudeAgentSession implements AgentSession {
|
||||
const fields = { key: message.key, priority: message.priority, text: message.text };
|
||||
if (urgent) this.logger.warn(fields, "claude.notification");
|
||||
else this.logger.info(fields, "claude.notification");
|
||||
// Claude Code's transcript shortcut only works in its terminal UI.
|
||||
const transcriptHint = " · ctrl+o to see";
|
||||
const text =
|
||||
message.key === "stop-hook-error" && message.text.endsWith(transcriptHint)
|
||||
? message.text.slice(0, -transcriptHint.length)
|
||||
: message.text;
|
||||
events.push({
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
item: { type: "notification", level: urgent ? "warning" : "info", message: message.text },
|
||||
item: { type: "notification", level: urgent ? "warning" : "info", message: text },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user