Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion apps/ade-cli/src/adeRpcServer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
createAdeRpcRequestHandler,
_resetGlobalAskUserRateLimit,
Expand All @@ -11,6 +11,17 @@ import { JsonRpcError, JsonRpcErrorCode } from "./jsonrpc";

type RuntimeFixture = ReturnType<typeof createRuntime>;
const originalPlatform = process.platform;
const ADE_ENV_KEYS = [
"ADE_DEFAULT_ROLE",
"ADE_CHAT_SESSION_ID",
"ADE_RUN_ID",
"ADE_STEP_ID",
"ADE_ATTEMPT_ID",
"ADE_OWNER_ID",
] as const;
const originalAdeEnv = new Map<string, string | undefined>(
ADE_ENV_KEYS.map((key) => [key, process.env[key]]),
);

function setPlatform(value: NodeJS.Platform): void {
Object.defineProperty(process, "platform", {
Expand All @@ -19,8 +30,19 @@ function setPlatform(value: NodeJS.Platform): void {
});
}

beforeEach(() => {
for (const key of ADE_ENV_KEYS) {
delete process.env[key];
}
});

afterEach(() => {
setPlatform(originalPlatform);
for (const key of ADE_ENV_KEYS) {
const value = originalAdeEnv.get(key);
if (value == null) delete process.env[key];
else process.env[key] = value;
}
});

function createRuntime() {
Expand Down
3 changes: 2 additions & 1 deletion apps/ade-cli/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ describe("ADE CLI", () => {
});

it("allows explicit runtime socket overrides across build hashes", () => {
const currentVersion = process.env.ADE_CLI_VERSION?.trim() || "0.0.0";
const runtimeInfo = {
version: "0.0.0",
version: currentVersion,
buildHash: "other-build",
defaultRole: "agent",
packageChannel: null,
Expand Down
10 changes: 10 additions & 0 deletions apps/desktop/src/main/services/chat/agentChatCliLaunch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ describe("launchAgentChatCli worktree-path resolution", () => {
});

describe("launchAgentChatCli attached issue ids", () => {
it("awaits delayed kickoff input so slow CLI readiness cannot silently drop the prompt", async () => {
const deps = makeDeps();
await launchAgentChatCli(makeArgs(), deps);

const createArg = deps.create.mock.calls[0]?.[0] as PtyCreateArgs;
expect(createArg.initialInput).toContain("Resolve the attached issue");
expect(createArg.awaitInitialInput).toBe(true);
expect(createArg.initialInputReadyTimeoutMs).toBe(120_000);
});

it("returns only well-formed attached issue ids and drops malformed entries", async () => {
const deps = makeDeps();
const result = await launchAgentChatCli(
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop/src/main/services/chat/agentChatCliLaunch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type LoggerForCliLaunch = {
info: (message: string, meta?: Record<string, unknown>) => void;
};

const AGENT_CHAT_CLI_KICKOFF_READY_TIMEOUT_MS = 120_000;

export type AgentChatCliLaunchDeps = {
laneService: LaneServiceForCliLaunch;
ptyService: PtyServiceForCliLaunch;
Expand Down Expand Up @@ -118,6 +120,12 @@ export async function launchAgentChatCli(
...(launch.initialInputDelayMs !== undefined
? { initialInputDelayMs: launch.initialInputDelayMs }
: {}),
...(launch.initialInput !== undefined
? {
awaitInitialInput: true,
initialInputReadyTimeoutMs: AGENT_CHAT_CLI_KICKOFF_READY_TIMEOUT_MS,
}
: {}),
...(launch.env ? { env: launch.env } : {}),
});

Expand Down
19 changes: 15 additions & 4 deletions apps/desktop/src/main/services/pty/ptyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2964,8 +2964,12 @@ export function createPtyService({
return false;
};

const waitForAgentCliInputReady = async (sessionId: string, provider: TerminalResumeProvider): Promise<boolean> => {
const deadline = Date.now() + AGENT_CLI_READY_TIMEOUT_MS;
const waitForAgentCliInputReady = async (
sessionId: string,
provider: TerminalResumeProvider,
timeoutMs = AGENT_CLI_READY_TIMEOUT_MS,
): Promise<boolean> => {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const live = liveEntryBySessionId(sessionId);
if (!live) return false;
Expand All @@ -2985,7 +2989,7 @@ export function createPtyService({
}
await delay(AGENT_CLI_READY_POLL_MS);
}
logger.warn("pty.agent_cli_ready_wait_timeout", { sessionId, provider });
logger.warn("pty.agent_cli_ready_wait_timeout", { sessionId, provider, timeoutMs });
return false;
};

Expand Down Expand Up @@ -3751,13 +3755,20 @@ export function createPtyService({

if (requestedInitialInput.length > 0) {
const normalizedInitialInput = requestedInitialInput.replace(/\r\n?/g, "\n");
const initialInputReadyTimeoutMs = Math.max(
AGENT_CLI_READY_TIMEOUT_MS,
Math.min(
300_000,
Math.floor(Number(args.initialInputReadyTimeoutMs ?? AGENT_CLI_READY_TIMEOUT_MS) || 0),
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
),
);
const writeInitialInput = async (): Promise<void> => {
entry.initialInputTimer = null;
if (entry.disposed) throw new Error("Terminal session closed before initial input could be sent.");
const provider = providerFromTool(toolTypeHint);
try {
if (provider) {
const ready = await waitForAgentCliInputReady(sessionId, provider);
const ready = await waitForAgentCliInputReady(sessionId, provider, initialInputReadyTimeoutMs);
if (!ready) {
logger.warn("pty.initial_input_skipped_not_ready", {
ptyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import {
issueUpdatedLabel,
linearPriorityLabel,
toLaneLinearIssue,
} from "../lanes/LinearIssuePicker";
} from "../lanes/linearIssueDisplay";
import { LinearPriorityIcon, LinearStateIcon } from "../lanes/linearBrand";
import { LinearProjectIcon } from "../lanes/linearProjectIcon";
import { LinearIssueOpenLink } from "./LinearIssueResolveModals";
import type { IssueConflict } from "../../lib/linearBatchLaunch";

type BrowserIssue = NormalizedLinearIssue | LaneLinearIssue;
export type BrowserIssue = NormalizedLinearIssue | LaneLinearIssue;
type IssueSort = "updated_desc" | "created_desc" | "priority" | "due_soon" | "identifier_asc";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { useCallback, useState } from "react";
import { Check } from "@phosphor-icons/react";

import type { CtoLinearQuickView, LaneLinearIssue } from "../../../shared/types";
import { LinearIssueBrowser, linearBrowserIssueToLaneIssue } from "./LinearIssueBrowser";
import { LinearPaneModal } from "./LinearPaneModal";

export function LinearIssueSelectModal({
open,
ariaLabel = "Select Linear issue",
projectRoot,
selectedIssue,
pinnedIssue,
pinnedIssueLabel,
actionLabel = "Connect issue",
actionBusyLabel,
actionDisabled = false,
showBranchPreview = true,
onOpenChange,
onSelectIssue,
onOpenLinearSettings,
}: {
open: boolean;
ariaLabel?: string;
projectRoot?: string | null;
selectedIssue: LaneLinearIssue | null;
pinnedIssue?: LaneLinearIssue | null;
pinnedIssueLabel?: string;
actionLabel?: string;
actionBusyLabel?: string;
actionDisabled?: boolean;
showBranchPreview?: boolean;
onOpenChange: (open: boolean) => void;
onSelectIssue: (issue: LaneLinearIssue) => void;
onOpenLinearSettings?: () => void;
}) {
const featuredIssue = pinnedIssue ?? selectedIssue;
const [quickView, setQuickView] = useState<CtoLinearQuickView | null>(null);
const [browserLoading, setBrowserLoading] = useState(false);
const [refreshKey, setRefreshKey] = useState(0);

const close = useCallback(() => onOpenChange(false), [onOpenChange]);
const openLinearSettings = useCallback(() => {
onOpenChange(false);
onOpenLinearSettings?.();
}, [onOpenChange, onOpenLinearSettings]);

return (
<LinearPaneModal
open={open}
ariaLabel={ariaLabel}
quickView={quickView}
loading={browserLoading}
onRefresh={() => setRefreshKey((key) => key + 1)}
onClose={close}
>
<LinearIssueBrowser
projectRoot={projectRoot}
featuredIssue={featuredIssue}
featuredIssueLabel={pinnedIssueLabel ?? (pinnedIssue ? "Linked to this lane" : "Selected issue")}
actionLabel={actionLabel}
actionBusyLabel={actionBusyLabel}
actionIcon={<Check size={14} />}
actionDisabled={actionDisabled}
showBranchPreview={showBranchPreview}
refreshKey={refreshKey}
onOpenLinearSettings={openLinearSettings}
onQuickViewChange={setQuickView}
onLoadingChange={setBrowserLoading}
onIssueAction={(issue) => {
onSelectIssue(linearBrowserIssueToLaneIssue(issue));
onOpenChange(false);
}}
/>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
</LinearPaneModal>
);
}
82 changes: 13 additions & 69 deletions apps/desktop/src/renderer/components/chat/AgentChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
type AgentChatSlashCommand,
type CodexThreadTokenUsage,
type ComputerUseOwnerSnapshot,
type CtoLinearQuickView,
type ChatSurfaceMode,
type AppControlContextItem,
type BuiltInBrowserContextItem,
Expand Down Expand Up @@ -54,8 +53,7 @@ import {
type ChatAttachmentPendingImage,
} from "./ChatAttachmentTray";
import { ChatComposerShell } from "./ChatComposerShell";
import { LinearIssueBrowser, linearBrowserIssueToLaneIssue } from "../app/LinearIssueBrowser";
import { LinearPaneModal } from "../app/LinearPaneModal";
import { LinearIssueSelectModal } from "../app/LinearIssueSelectModal";
import { LinearMark, LINEAR_BRAND } from "../lanes/linearBrand";
import { getPendingInputQuestionCount, hasPendingInputOptions } from "./pendingInput";
import { CURSOR_MODE_LABELS } from "../../../shared/cursorModes";
Expand Down Expand Up @@ -729,68 +727,6 @@ function PendingSteerItem({
);
}

function LinearIssueContextDialog({
open,
selectedIssue,
pinnedIssue,
busy,
onOpenChange,
onAttach,
onOpenLinearSettings,
}: {
open: boolean;
selectedIssue: LaneLinearIssue | null;
pinnedIssue?: LaneLinearIssue | null;
busy?: boolean;
onOpenChange: (open: boolean) => void;
onAttach: (attachment: AgentChatContextAttachment) => void;
onOpenLinearSettings?: () => void;
}) {
const featuredIssue = pinnedIssue ?? selectedIssue;
const [quickView, setQuickView] = useState<CtoLinearQuickView | null>(null);
const [browserLoading, setBrowserLoading] = useState(false);
const [refreshKey, setRefreshKey] = useState(0);

const close = useCallback(() => onOpenChange(false), [onOpenChange]);
const openLinearSettings = useCallback(() => {
onOpenChange(false);
onOpenLinearSettings?.();
}, [onOpenChange, onOpenLinearSettings]);

return (
<LinearPaneModal
open={open}
ariaLabel="Attach Linear issue"
quickView={quickView}
loading={browserLoading}
onRefresh={() => setRefreshKey((key) => key + 1)}
onClose={close}
>
<LinearIssueBrowser
featuredIssue={featuredIssue}
featuredIssueLabel={pinnedIssue ? "Linked to this lane" : "Attached to chat"}
actionLabel="Attach issue"
actionBusyLabel="Attaching issue"
actionIcon={<Check size={14} />}
actionDisabled={busy}
showBranchPreview={false}
refreshKey={refreshKey}
onOpenLinearSettings={openLinearSettings}
onQuickViewChange={setQuickView}
onLoadingChange={setBrowserLoading}
onIssueAction={(issue) => {
const laneIssue = linearBrowserIssueToLaneIssue(issue);
onAttach(makeLinearIssueContextAttachment(
laneIssue,
pinnedIssue?.id === laneIssue.id ? "lane_link" : "manual",
));
onOpenChange(false);
}}
/>
</LinearPaneModal>
);
}

export function AgentChatComposer({
surfaceMode = "standard",
layoutVariant = "standard",
Expand Down Expand Up @@ -2940,18 +2876,26 @@ export function AgentChatComposer({
return (
<>
{issueContextMenu}
<LinearIssueContextDialog
<LinearIssueSelectModal
open={linearIssuePickerOpen}
ariaLabel="Attach Linear issue"
selectedIssue={
contextAttachments[0]?.type === "linear_issue"
? contextAttachments[0].issue
: null
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
pinnedIssue={pinnedLinearIssue}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
busy={busy || parallelLaunchBusy}
pinnedIssueLabel={pinnedLinearIssue ? "Linked to this lane" : "Attached to chat"}
actionLabel="Attach issue"
actionBusyLabel="Attaching issue"
actionDisabled={busy || parallelLaunchBusy}
showBranchPreview={false}
onOpenChange={setLinearIssuePickerOpen}
onAttach={(attachment) => {
onAddContextAttachment?.(attachment);
onSelectIssue={(laneIssue) => {
onAddContextAttachment?.(makeLinearIssueContextAttachment(
laneIssue,
pinnedLinearIssue?.id === laneIssue.id ? "lane_link" : "manual",
));
setLinearIssuePickerOpen(false);
}}
onOpenLinearSettings={onOpenLinearSettings}
Expand Down
Loading