mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-28 19:25:45 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa957c9ca9 | ||
|
|
a96a4d61f1 | ||
|
|
6916ceee47 |
@@ -217,6 +217,15 @@ jobs:
|
||||
- name: Verify website mockups
|
||||
run: npm run test:e2e --workspace=@getpaseo/website
|
||||
|
||||
- name: Upload website test artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: website-playwright-results
|
||||
path: packages/website/test-results/
|
||||
if-no-files-found: ignore
|
||||
retention-days: 7
|
||||
|
||||
- name: Verify public package contents
|
||||
run: |
|
||||
npm pack --dry-run --ignore-scripts --workspace=@getpaseo/protocol
|
||||
|
||||
@@ -233,6 +233,57 @@ test("opening an agent focuses the composer when a mouse drives the UI", async (
|
||||
}
|
||||
});
|
||||
|
||||
/** The composer frame's border colour once its border-color transition has finished. */
|
||||
async function readSettledFrameBorder(page: Page): Promise<string> {
|
||||
return composerLocator(page).evaluate(async (input) => {
|
||||
let frame = input.parentElement;
|
||||
while (frame && parseFloat(getComputedStyle(frame).borderTopWidth) < 1) {
|
||||
frame = frame.parentElement;
|
||||
}
|
||||
if (!frame) throw new Error("Composer frame has no border");
|
||||
while (frame.getAnimations().length > 0) {
|
||||
await new Promise((resolve) => requestAnimationFrame(resolve));
|
||||
}
|
||||
return getComputedStyle(frame).borderTopColor;
|
||||
});
|
||||
}
|
||||
|
||||
test("the composer frame shows hover and focus", async ({ page }) => {
|
||||
const agent = await seedMockAgentWorkspace({
|
||||
repoPrefix: "composer-frame-focus-",
|
||||
title: "Composer frame focus",
|
||||
});
|
||||
|
||||
try {
|
||||
await openAgentRoute(page, agent);
|
||||
const composer = composerLocator(page);
|
||||
await expectComposerVisible(page);
|
||||
await page.mouse.move(0, 0);
|
||||
await blurComposerInput(page);
|
||||
const rest = await readSettledFrameBorder(page);
|
||||
|
||||
await composer.hover();
|
||||
const hover = await readSettledFrameBorder(page);
|
||||
expect(hover).not.toBe(rest);
|
||||
|
||||
await composer.click();
|
||||
await page.mouse.move(0, 0);
|
||||
await expectComposerFocused(page);
|
||||
const focus = await readSettledFrameBorder(page);
|
||||
expect(focus).not.toBe(rest);
|
||||
expect(focus).not.toBe(hover);
|
||||
|
||||
await composer.hover();
|
||||
expect(await readSettledFrameBorder(page)).toBe(focus);
|
||||
|
||||
await page.mouse.move(0, 0);
|
||||
await blurComposerInput(page);
|
||||
expect(await readSettledFrameBorder(page)).toBe(rest);
|
||||
} finally {
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
async function waitForAnimationFrames(page: Page, count: number): Promise<void> {
|
||||
await page.evaluate(async (frames) => {
|
||||
for (let frame = 0; frame < frames; frame += 1) {
|
||||
|
||||
@@ -110,6 +110,7 @@ import {
|
||||
applyDictationTranscript,
|
||||
computeCanStartDictation,
|
||||
resolveAlternateSendAction,
|
||||
resolveComposerFramePhase,
|
||||
resolveComposerSurfacePresentation,
|
||||
resolveComposerSurfaceText,
|
||||
resolveMessageInputEnterAction,
|
||||
@@ -1368,6 +1369,8 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
const dictationToggleKeys = useShortcutKeys("dictation-toggle");
|
||||
const focusInputKeys = useShortcutKeys("focus-message-input");
|
||||
const [isInputFocused, setIsInputFocused] = useState(false);
|
||||
// Only the frame's pointer events set it, so hover stays a web thing; see docs/hover.md.
|
||||
const [isInputHovered, setIsInputHovered] = useState(false);
|
||||
useKeyboardFocusSurface("message-input", isInputFocused && isPaneFocused);
|
||||
// Web text is DOM-owned between deferred draft publications. The action button only needs
|
||||
// this boundary, so publish empty/non-empty transitions without rerendering for every key.
|
||||
@@ -2038,15 +2041,32 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
void handleStopRealtimeVoice();
|
||||
}, [handleStopRealtimeVoice]);
|
||||
|
||||
const handleInputWrapperPointerEnter = useCallback(() => setIsInputHovered(true), []);
|
||||
const handleInputWrapperPointerLeave = useCallback(() => setIsInputHovered(false), []);
|
||||
const framePhase = resolveComposerFramePhase({
|
||||
hovered: isInputHovered,
|
||||
focused: isInputFocused,
|
||||
readOnly,
|
||||
disabled,
|
||||
});
|
||||
const inputWrapperCombinedStyle = useMemo(
|
||||
() => [
|
||||
styles.inputWrapper,
|
||||
Platform.OS !== "ios" && isCompact && !isFullscreen && styles.inputWrapperCompact,
|
||||
readOnly && styles.inputWrapperReadOnly,
|
||||
framePhase === "hover" && styles.inputWrapperHovered,
|
||||
framePhase === "active" && styles.inputWrapperFocused,
|
||||
inputWrapperStyle,
|
||||
{ opacity: surfacePresentation.input.opacity },
|
||||
],
|
||||
[inputWrapperStyle, isCompact, isFullscreen, readOnly, surfacePresentation.input.opacity],
|
||||
[
|
||||
framePhase,
|
||||
inputWrapperStyle,
|
||||
isCompact,
|
||||
isFullscreen,
|
||||
readOnly,
|
||||
surfacePresentation.input.opacity,
|
||||
],
|
||||
);
|
||||
// `withUnistyles` maps this component's `style` into a `.hash > *` child
|
||||
// rule, which ties on specificity with react-native-web's own
|
||||
@@ -2394,6 +2414,8 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
onExit={exitFullscreen}
|
||||
inputWrapperRef={inputWrapperRef}
|
||||
inputWrapperStyle={inputWrapperCombinedStyle}
|
||||
onInputWrapperPointerEnter={handleInputWrapperPointerEnter}
|
||||
onInputWrapperPointerLeave={handleInputWrapperPointerLeave}
|
||||
inputPointerEvents={surfacePresentation.input.pointerEvents}
|
||||
attachmentSlot={attachmentSlot}
|
||||
showFullscreenButton={shouldShowFullscreenControl(
|
||||
@@ -2448,6 +2470,15 @@ const styles = StyleSheet.create((theme: Theme) => ({
|
||||
inputWrapperReadOnly: {
|
||||
borderStyle: "dotted",
|
||||
},
|
||||
// The rest border is already the `borderAccent` that `controlHover` gives other inputs, so
|
||||
// hover steps up one surface; focus takes the accent, like their focus ring. Colour only:
|
||||
// the border width stays put, so the frame never shifts under the pointer.
|
||||
inputWrapperHovered: {
|
||||
borderColor: theme.colors.surface4,
|
||||
},
|
||||
inputWrapperFocused: {
|
||||
borderColor: theme.colors.accent,
|
||||
},
|
||||
// The band the fullscreen glyph sits in is the input's own padding, so a tap
|
||||
// anywhere in it (under the glyph, or where the glyph would be) is a tap on the
|
||||
// editor: it focuses, shows the keyboard, and places the caret. Reserved whether
|
||||
|
||||
@@ -37,6 +37,8 @@ export function ComposerInputPresentation({
|
||||
onExit,
|
||||
inputWrapperRef,
|
||||
inputWrapperStyle,
|
||||
onInputWrapperPointerEnter,
|
||||
onInputWrapperPointerLeave,
|
||||
inputPointerEvents,
|
||||
attachmentSlot,
|
||||
showFullscreenButton,
|
||||
@@ -53,6 +55,9 @@ export function ComposerInputPresentation({
|
||||
onExit: () => void;
|
||||
inputWrapperRef: Ref<View>;
|
||||
inputWrapperStyle: ViewProps["style"];
|
||||
/** Hover tracking for the frame's border; the frame is a plain View, per docs/hover.md. */
|
||||
onInputWrapperPointerEnter: () => void;
|
||||
onInputWrapperPointerLeave: () => void;
|
||||
inputPointerEvents: ViewProps["pointerEvents"];
|
||||
attachmentSlot: ReactNode;
|
||||
showFullscreenButton: boolean;
|
||||
@@ -107,6 +112,8 @@ export function ComposerInputPresentation({
|
||||
ref={inputWrapperRef}
|
||||
style={fullscreen ? styles.fullscreenInputWrapper : inputWrapperStyle}
|
||||
pointerEvents={inputPointerEvents}
|
||||
onPointerEnter={onInputWrapperPointerEnter}
|
||||
onPointerLeave={onInputWrapperPointerLeave}
|
||||
>
|
||||
{fullscreen ? null : attachmentSlot}
|
||||
<View style={fullscreen ? styles.fullscreenTextSurface : styles.inlineTextSurface}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
computeCanStartDictation,
|
||||
type MessageInputEnterContext,
|
||||
resolveActiveSendBehavior,
|
||||
resolveComposerFramePhase,
|
||||
resolveComposerSurfacePresentation,
|
||||
resolveComposerSurfaceText,
|
||||
resolveGlyphRailOffset,
|
||||
@@ -614,3 +615,23 @@ describe("fullscreen glyph rail", () => {
|
||||
expect(offset + inkInset).toBeCloseTo(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("composer frame phase", () => {
|
||||
const rest = { hovered: false, focused: false, readOnly: false, disabled: false };
|
||||
|
||||
it("shows the focus border while the editor has focus, hovered or not", () => {
|
||||
expect(resolveComposerFramePhase({ ...rest, focused: true })).toBe("active");
|
||||
expect(resolveComposerFramePhase({ ...rest, focused: true, hovered: true })).toBe("active");
|
||||
});
|
||||
|
||||
it("shows the hover border only while the pointer is over an unfocused frame", () => {
|
||||
expect(resolveComposerFramePhase({ ...rest, hovered: true })).toBe("hover");
|
||||
expect(resolveComposerFramePhase(rest)).toBe("rest");
|
||||
});
|
||||
|
||||
it("keeps a read-only or disabled frame at rest", () => {
|
||||
const engaged = { ...rest, hovered: true, focused: true };
|
||||
expect(resolveComposerFramePhase({ ...engaged, readOnly: true })).toBe("rest");
|
||||
expect(resolveComposerFramePhase({ ...engaged, disabled: true })).toBe("rest");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,10 @@ import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { ActiveTurnBehavior } from "@getpaseo/protocol/messages";
|
||||
import type { MessagePayload, TextReplacement } from "@/composer/types";
|
||||
import type { MessageInputKeyboardActionKind } from "@/keyboard/actions";
|
||||
import {
|
||||
getControlInteractionPhase,
|
||||
type ControlInteractionPhase,
|
||||
} from "@/components/ui/control-geometry";
|
||||
|
||||
export type SendBehavior = ActiveTurnBehavior | "queue";
|
||||
|
||||
@@ -246,6 +250,23 @@ export function resolveGlyphRailOffset(input: {
|
||||
return -inkInset;
|
||||
}
|
||||
|
||||
/**
|
||||
* The composer frame follows the phases of the app's other inputs: focus wins over hover, and
|
||||
* a frame you can't type into (read-only, disabled) stays at rest.
|
||||
*/
|
||||
export function resolveComposerFramePhase(input: {
|
||||
hovered: boolean;
|
||||
focused: boolean;
|
||||
readOnly: boolean;
|
||||
disabled: boolean;
|
||||
}): ControlInteractionPhase {
|
||||
return getControlInteractionPhase({
|
||||
hovered: input.hovered,
|
||||
focused: input.focused,
|
||||
disabled: input.readOnly || input.disabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveComposerSurfaceText(
|
||||
liveText: string,
|
||||
replacement: TextReplacement,
|
||||
|
||||
@@ -2304,7 +2304,14 @@ class AcpRuntime {
|
||||
if (!active.deferred && wasOpenQualifying && !isOpen && this.toolKeepsTurnOpen(snapshot)) {
|
||||
active.crossedEndTurn = true;
|
||||
}
|
||||
if (isOpenQualifying) active.replyState = "idle";
|
||||
if (
|
||||
isOpenQualifying ||
|
||||
(!isOpen &&
|
||||
this.toolKeepsTurnOpen(snapshot) &&
|
||||
active.replyState === "settled_with_open_tools")
|
||||
) {
|
||||
active.replyState = "idle";
|
||||
}
|
||||
if (active.deferred) this.scheduleDeferredSettle();
|
||||
}
|
||||
|
||||
|
||||
@@ -5518,7 +5518,7 @@ describe("deferTurnOnRunningTools", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("settles on the reply timer when reply usage arrives before the final background tool completes", async () => {
|
||||
it("keeps the turn open after an interim status reply while another background tool is still running", async () => {
|
||||
const { connector, instances } = connectorHarness({
|
||||
handleRequest(instance, request) {
|
||||
if (request.method !== "session/prompt") return false;
|
||||
@@ -5526,9 +5526,9 @@ describe("deferTurnOnRunningTools", () => {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call",
|
||||
toolCallId: "bg-u1",
|
||||
toolCallId: "bg-interim-1",
|
||||
name: "run_command",
|
||||
title: "Job 1",
|
||||
title: "Build",
|
||||
status: "in_progress",
|
||||
},
|
||||
});
|
||||
@@ -5536,9 +5536,9 @@ describe("deferTurnOnRunningTools", () => {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call",
|
||||
toolCallId: "bg-u2",
|
||||
toolCallId: "bg-interim-2",
|
||||
name: "run_command",
|
||||
title: "Job 2",
|
||||
title: "Review",
|
||||
status: "in_progress",
|
||||
},
|
||||
});
|
||||
@@ -5547,12 +5547,12 @@ describe("deferTurnOnRunningTools", () => {
|
||||
},
|
||||
});
|
||||
const registration = runAcpProvider({
|
||||
id: "deferred-usage-before-tool",
|
||||
label: "Deferred Usage Before Tool",
|
||||
id: "deferred-interim-reply-two-tools",
|
||||
label: "Deferred Interim Reply Two Tools",
|
||||
connector,
|
||||
acpOptions: {
|
||||
deferTurnOnRunningTools: {
|
||||
settleDelayMs: 30,
|
||||
settleDelayMs: 40,
|
||||
quietLimitMs: 1_500,
|
||||
},
|
||||
},
|
||||
@@ -5570,9 +5570,9 @@ describe("deferTurnOnRunningTools", () => {
|
||||
type: "session.prompt",
|
||||
sessionId: "session-1",
|
||||
prompt: {
|
||||
clientMessageId: "usage-first-turn",
|
||||
clientMessageId: "interim-two-tools-turn",
|
||||
delivery: "auto",
|
||||
input: { type: "message", content: [{ type: "text", text: "run jobs" }] },
|
||||
input: { type: "message", content: [{ type: "text", text: "build and review" }] },
|
||||
},
|
||||
});
|
||||
await waitForEvent(
|
||||
@@ -5580,47 +5580,310 @@ describe("deferTurnOnRunningTools", () => {
|
||||
(event) =>
|
||||
event.type === "timeline.item" &&
|
||||
event.item.type === "tool_call" &&
|
||||
event.item.id === "bg-u2",
|
||||
event.item.id === "bg-interim-2",
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
|
||||
// Job 1 finishes, reply + usage_update arrive while Job 2 is still running.
|
||||
// Job 1 completes and the agent sends an interim status reply + usage while Job 2 is still running.
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: { sessionUpdate: "tool_call_update", toolCallId: "bg-u1", status: "completed" },
|
||||
update: {
|
||||
sessionUpdate: "tool_call_update",
|
||||
toolCallId: "bg-interim-1",
|
||||
status: "completed",
|
||||
},
|
||||
});
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: textChunk("All done."),
|
||||
update: textChunk("Build passed, waiting on review."),
|
||||
});
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: { sessionUpdate: "usage_update", used: 300, size: 1000 },
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
// Still running because Job 2 has not completed yet.
|
||||
await new Promise((resolve) => setTimeout(resolve, 60));
|
||||
expect(
|
||||
events.some(
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:usage-first-turn" &&
|
||||
event.turnId === "acp:interim-two-tools-turn" &&
|
||||
event.state !== "started",
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
// Job 2 completes -> should settle via settleDelayMs, not quietLimitMs.
|
||||
// Job 2 completes; pause longer than settleDelayMs to simulate LLM TTFB before wakeup chunks stream.
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call_update",
|
||||
toolCallId: "bg-interim-2",
|
||||
status: "completed",
|
||||
},
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 160));
|
||||
expect(
|
||||
events.some(
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:interim-two-tools-turn" &&
|
||||
event.state !== "started",
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
// Follow-up reply arrives after all tools are complete -> settles via settleDelayMs.
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "agent_thought_chunk",
|
||||
content: { type: "text", text: "Reviewing findings..." },
|
||||
},
|
||||
});
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: textChunk("Review complete and applied."),
|
||||
});
|
||||
const startedAt = Date.now();
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: { sessionUpdate: "tool_call_update", toolCallId: "bg-u2", status: "completed" },
|
||||
update: { sessionUpdate: "usage_update", used: 450, size: 1000 },
|
||||
});
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:usage-first-turn" &&
|
||||
event.turnId === "acp:interim-two-tools-turn" &&
|
||||
event.state === "completed",
|
||||
);
|
||||
expect(Date.now() - startedAt).toBeLessThan(400);
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps the turn open after a mid-wait status check reply on a single background tool", async () => {
|
||||
const { connector, instances } = connectorHarness({
|
||||
handleRequest(instance, request) {
|
||||
if (request.method !== "session/prompt") return false;
|
||||
instance.notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call",
|
||||
toolCallId: "bg-long",
|
||||
name: "run_command",
|
||||
title: "Long review",
|
||||
status: "in_progress",
|
||||
},
|
||||
});
|
||||
instance.respond(request, { stopReason: "end_turn" });
|
||||
return true;
|
||||
},
|
||||
});
|
||||
const registration = runAcpProvider({
|
||||
id: "deferred-interim-status-check",
|
||||
label: "Deferred Interim Status Check",
|
||||
connector,
|
||||
acpOptions: {
|
||||
deferTurnOnRunningTools: {
|
||||
settleDelayMs: 40,
|
||||
quietLimitMs: 1_500,
|
||||
},
|
||||
},
|
||||
});
|
||||
const connection = await registration.connect({
|
||||
versions: [1],
|
||||
capabilities: ["prompt.message"],
|
||||
});
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => events.push(event));
|
||||
try {
|
||||
await connection.send(openInput());
|
||||
await waitForEvent(events, (event) => event.type === "session.ready");
|
||||
await connection.send({
|
||||
type: "session.prompt",
|
||||
sessionId: "session-1",
|
||||
prompt: {
|
||||
clientMessageId: "interim-status-check-turn",
|
||||
delivery: "auto",
|
||||
input: { type: "message", content: [{ type: "text", text: "run long review" }] },
|
||||
},
|
||||
});
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) =>
|
||||
event.type === "timeline.item" &&
|
||||
event.item.type === "tool_call" &&
|
||||
event.item.id === "bg-long",
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
|
||||
// Mid-wait notification wakes the agent to inspect task status and send a progress update.
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call",
|
||||
toolCallId: "check-1",
|
||||
name: "manage_task",
|
||||
title: "Manage task",
|
||||
status: "in_progress",
|
||||
},
|
||||
});
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call_update",
|
||||
toolCallId: "check-1",
|
||||
status: "completed",
|
||||
},
|
||||
});
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: textChunk("Still running, continuing to wait."),
|
||||
});
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: { sessionUpdate: "usage_update", used: 250, size: 1000 },
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 60));
|
||||
|
||||
// Long background job finally completes; turn must remain open past settleDelayMs for follow-up.
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call_update",
|
||||
toolCallId: "bg-long",
|
||||
status: "completed",
|
||||
},
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 160));
|
||||
expect(
|
||||
events.some(
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:interim-status-check-turn" &&
|
||||
event.state !== "started",
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
// Final reply arrives -> settles quickly via settleDelayMs.
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: textChunk("Long review finished."),
|
||||
});
|
||||
const startedAt = Date.now();
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: { sessionUpdate: "usage_update", used: 400, size: 1000 },
|
||||
});
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:interim-status-check-turn" &&
|
||||
event.state === "completed",
|
||||
);
|
||||
expect(Date.now() - startedAt).toBeLessThan(400);
|
||||
} finally {
|
||||
await connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("settles on the reply timer when an open tool is reclassified as an excluded daemon after reply usage", async () => {
|
||||
const { connector, instances } = connectorHarness({
|
||||
handleRequest(instance, request) {
|
||||
if (request.method !== "session/prompt") return false;
|
||||
instance.notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call",
|
||||
toolCallId: "late-daemon",
|
||||
name: "run_command",
|
||||
title: "Dev server",
|
||||
status: "in_progress",
|
||||
},
|
||||
});
|
||||
instance.respond(request, { stopReason: "end_turn" });
|
||||
return true;
|
||||
},
|
||||
});
|
||||
const registration = runAcpProvider({
|
||||
id: "deferred-daemon-reclassify-after-usage",
|
||||
label: "Deferred Daemon Reclassify After Usage",
|
||||
connector,
|
||||
acpOptions: {
|
||||
deferTurnOnRunningTools: {
|
||||
settleDelayMs: 40,
|
||||
quietLimitMs: 1_500,
|
||||
keepsTurnOpen(toolCall) {
|
||||
const input = toolCall.input;
|
||||
if (typeof input !== "object" || input === null || Array.isArray(input)) return true;
|
||||
return input.IsDaemon !== true;
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const connection = await registration.connect({
|
||||
versions: [1],
|
||||
capabilities: ["prompt.message"],
|
||||
});
|
||||
const events: ProviderEvent[] = [];
|
||||
connection.onEvent((event) => events.push(event));
|
||||
try {
|
||||
await connection.send(openInput());
|
||||
await waitForEvent(events, (event) => event.type === "session.ready");
|
||||
await connection.send({
|
||||
type: "session.prompt",
|
||||
sessionId: "session-1",
|
||||
prompt: {
|
||||
clientMessageId: "daemon-reclassify-after-usage-turn",
|
||||
delivery: "auto",
|
||||
input: { type: "message", content: [{ type: "text", text: "start dev server" }] },
|
||||
},
|
||||
});
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) =>
|
||||
event.type === "timeline.item" &&
|
||||
event.item.type === "tool_call" &&
|
||||
event.item.id === "late-daemon",
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
|
||||
// Final reply + usage arrive before rawInput identifies the running tool as a daemon.
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: textChunk("Dev server is up."),
|
||||
});
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: { sessionUpdate: "usage_update", used: 200, size: 1000 },
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 60));
|
||||
expect(
|
||||
events.some(
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:daemon-reclassify-after-usage-turn" &&
|
||||
event.state !== "started",
|
||||
),
|
||||
).toBe(false);
|
||||
|
||||
// Reclassifying the still-running tool as a daemon releases the settled reply on settleDelayMs.
|
||||
const startedAt = Date.now();
|
||||
instances[1].notify("session/update", {
|
||||
sessionId: "connector-session",
|
||||
update: {
|
||||
sessionUpdate: "tool_call_update",
|
||||
toolCallId: "late-daemon",
|
||||
status: "in_progress",
|
||||
rawInput: { CommandLine: "npm run dev", IsDaemon: true },
|
||||
},
|
||||
});
|
||||
await waitForEvent(
|
||||
events,
|
||||
(event) =>
|
||||
event.type === "session.turn" &&
|
||||
event.turnId === "acp:daemon-reclassify-after-usage-turn" &&
|
||||
event.state === "completed",
|
||||
400,
|
||||
);
|
||||
expect(Date.now() - startedAt).toBeLessThan(400);
|
||||
} finally {
|
||||
|
||||
@@ -2847,18 +2847,37 @@ describe("ClaudeAgentClient.listImportableSessions", () => {
|
||||
await transcript.close();
|
||||
}
|
||||
|
||||
const childImports = `
|
||||
import { deepStrictEqual } from "node:assert";
|
||||
import { ClaudeAgentClient } from ${JSON.stringify(new URL("./agent.ts", import.meta.url).href)};
|
||||
import pino from ${JSON.stringify(import.meta.resolve("pino"))};
|
||||
`;
|
||||
// Cap the listing at its own budget on top of what loading the modules retains. A fixed
|
||||
// cap also counted the module graph, which grows with unrelated imports.
|
||||
const { stdout: loadedHeap } = await promisify(execFile)(process.execPath, [
|
||||
"--expose-gc",
|
||||
"--import",
|
||||
import.meta.resolve("tsx"),
|
||||
"--input-type=module",
|
||||
"--eval",
|
||||
`${childImports}
|
||||
globalThis.gc();
|
||||
console.log(process.memoryUsage().heapUsed);
|
||||
`,
|
||||
]);
|
||||
// Well under the 128 MiB transcript, so loading a whole history still runs out of heap.
|
||||
const listingBudgetMiB = 64;
|
||||
const heapCapMiB = Math.ceil(Number(loadedHeap) / (1024 * 1024)) + listingBudgetMiB;
|
||||
|
||||
const { stdout } = await promisify(execFile)(
|
||||
process.execPath,
|
||||
[
|
||||
"--max-old-space-size=96",
|
||||
`--max-old-space-size=${heapCapMiB}`,
|
||||
"--import",
|
||||
import.meta.resolve("tsx"),
|
||||
"--input-type=module",
|
||||
"--eval",
|
||||
`
|
||||
import { deepStrictEqual } from "node:assert";
|
||||
import { ClaudeAgentClient } from ${JSON.stringify(new URL("./agent.ts", import.meta.url).href)};
|
||||
import pino from ${JSON.stringify(import.meta.resolve("pino"))};
|
||||
`${childImports}
|
||||
import { mkdir, symlink } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
const clients = [];
|
||||
|
||||
@@ -26,6 +26,24 @@ async function centerMockup(mockup: Locator) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the scene clock until `shows` is visible. Bringing the mockup on screen starts the opening
|
||||
* scene a few page tasks later: the start line's IntersectionObserver fires, then React runs the
|
||||
* effect that starts the player. A clock advance sent right after the scroll can run before that.
|
||||
*/
|
||||
async function playUntilVisible(page: Page, shows: Locator) {
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
await page.clock.runFor(1000);
|
||||
return shows.isVisible();
|
||||
},
|
||||
// The page clock is paused, so waiting between checks only spends the test's time.
|
||||
{ intervals: [0], timeout: 15_000 },
|
||||
)
|
||||
.toBe(true);
|
||||
}
|
||||
|
||||
async function finishPanelSwap(page: Page, mockup: Locator, outgoingPanel: Locator) {
|
||||
await expect
|
||||
.poll(async () => {
|
||||
@@ -178,8 +196,7 @@ test("the opening scene waits until most of the mockup is on screen", async ({ p
|
||||
|
||||
await centerMockup(mockup);
|
||||
await expect(mockup).toBeInViewport({ ratio: 0.6 });
|
||||
await page.clock.runFor(4500);
|
||||
await expect(request).toBeVisible();
|
||||
await playUntilVisible(page, request);
|
||||
});
|
||||
|
||||
test("the opening scene starts in a window shorter than most of the mockup", async ({ page }) => {
|
||||
@@ -189,8 +206,7 @@ test("the opening scene starts in a window shorter than most of the mockup", asy
|
||||
await centerMockup(mockup);
|
||||
await expect(mockup).toBeInViewport();
|
||||
await expect(mockup).not.toBeInViewport({ ratio: 0.6 });
|
||||
await page.clock.runFor(4500);
|
||||
await expect(request).toBeVisible();
|
||||
await playUntilVisible(page, request);
|
||||
});
|
||||
|
||||
test("the plugins scene installs the panel, then changes it on request", async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user