Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 32 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,37 @@ export function createPtyService({

if (requestedInitialInput.length > 0) {
const normalizedInitialInput = requestedInitialInput.replace(/\r\n?/g, "\n");
const requestedInitialInputReadyTimeoutMs = args.initialInputReadyTimeoutMs;
const parsedInitialInputReadyTimeoutMs = Math.floor(
Number(requestedInitialInputReadyTimeoutMs ?? AGENT_CLI_READY_TIMEOUT_MS) || 0,
);
const initialInputReadyTimeoutMs = Math.max(
AGENT_CLI_READY_TIMEOUT_MS,
Math.min(
300_000,
parsedInitialInputReadyTimeoutMs,
),
);
if (
requestedInitialInputReadyTimeoutMs != null
&& parsedInitialInputReadyTimeoutMs !== initialInputReadyTimeoutMs
) {
logger.warn("pty.initial_input_ready_timeout_clamped", {
ptyId,
sessionId,
requestedTimeoutMs: requestedInitialInputReadyTimeoutMs,
effectiveTimeoutMs: initialInputReadyTimeoutMs,
minTimeoutMs: AGENT_CLI_READY_TIMEOUT_MS,
maxTimeoutMs: 300_000,
});
}
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
61 changes: 35 additions & 26 deletions apps/desktop/src/renderer/components/app/LinearIssueBrowser.tsx
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 Expand Up @@ -417,6 +417,7 @@ export function LinearIssueBrowser({
actionBusyIssueId,
actionDisabled = false,
showBranchPreview = true,
singleSelect = false,
refreshKey = 0,
requestedIssueIdentifier,
requestedIssueRequestKey,
Expand All @@ -436,6 +437,7 @@ export function LinearIssueBrowser({
actionBusyIssueId?: string | null;
actionDisabled?: boolean;
showBranchPreview?: boolean;
singleSelect?: boolean;
refreshKey?: number;
requestedIssueIdentifier?: string | null;
requestedIssueRequestKey?: string | number | null;
Expand Down Expand Up @@ -474,7 +476,8 @@ export function LinearIssueBrowser({
const [selectedIssueId, setSelectedIssueId] = useState<string | null>(featuredIssue?.id ?? null);
const [selectedIssueIds, setSelectedIssueIds] = useState<Set<string>>(() => safeLoadSelection(projectRoot));
const [lastCheckedId, setLastCheckedId] = useState<string | null>(null);
const anyChecked = selectedIssueIds.size > 0;
const multiSelectEnabled = !singleSelect;
const anyChecked = multiSelectEnabled && selectedIssueIds.size > 0;
const [collapsedGroups, setCollapsedGroups] = useState<Record<string, boolean>>({});
const [error, setError] = useState<string | null>(null);
const quickViewRequestIdRef = useRef(0);
Expand Down Expand Up @@ -502,8 +505,9 @@ export function LinearIssueBrowser({
// the launch modal → back). Cleared automatically when the selection empties
// (safeSaveSelection removes the key) and when filters change (effect below).
useEffect(() => {
if (!multiSelectEnabled) return;
safeSaveSelection(projectRoot, selectedIssueIds);
}, [projectRoot, selectedIssueIds]);
}, [multiSelectEnabled, projectRoot, selectedIssueIds]);

useEffect(() => {
const nextFilters = safeLoadFilters(projectRoot);
Expand Down Expand Up @@ -983,7 +987,7 @@ export function LinearIssueBrowser({
</div>
</div>

{displayIssues.length > 0 && (
{multiSelectEnabled && displayIssues.length > 0 && (
<div className="flex shrink-0 items-center gap-2 border-b border-white/[0.05] px-3 py-1.5">
<span
role="checkbox"
Expand Down Expand Up @@ -1052,6 +1056,7 @@ export function LinearIssueBrowser({
busy={busyIssueId === issue.id}
checked={selectedIssueIds.has(issue.id)}
anyChecked={anyChecked}
showCheckbox={multiSelectEnabled}
conflict={conflicts?.get(issue.id) ?? null}
onToggleCheck={(e) => handleToggleCheck(issue.id, e)}
onClick={() => setSelectedIssueId(issue.id)}
Expand Down Expand Up @@ -1080,7 +1085,7 @@ export function LinearIssueBrowser({
</div>
</section>

{selectedIssueIds.size > 1 && onBatchLaunch ? (
{multiSelectEnabled && selectedIssueIds.size > 1 && onBatchLaunch ? (
<BatchActionView
selectedIssues={resolvedSelectedIssues}
onClearSelection={() => setSelectedIssueIds(new Set())}
Expand Down Expand Up @@ -1188,6 +1193,7 @@ function LinearBrowserIssueRow({
busy,
checked,
anyChecked: anyRowChecked,
showCheckbox,
conflict,
onToggleCheck,
onClick,
Expand All @@ -1198,6 +1204,7 @@ function LinearBrowserIssueRow({
busy?: boolean;
checked: boolean;
anyChecked: boolean;
showCheckbox: boolean;
conflict?: IssueConflict | null;
onToggleCheck: (event: React.MouseEvent) => void;
onClick: () => void;
Expand Down Expand Up @@ -1236,27 +1243,29 @@ function LinearBrowserIssueRow({
"bounce" when the row toggles. stopPropagation keeps the toggle from
also triggering the row's preview-select.
*/}
<button
type="button"
role="checkbox"
aria-checked={checked}
aria-label={checked ? `Deselect ${issue.identifier}` : `Select ${issue.identifier}`}
onClick={(e) => { e.stopPropagation(); onToggleCheck(e); }}
className="-ml-1 grid h-6 w-6 shrink-0 cursor-pointer place-items-center rounded-md outline-none focus-visible:bg-white/[0.06]"
>
<span
className={cn(
"flex h-[14px] w-[14px] items-center justify-center rounded-[3px] border transition-colors",
checked
? "border-[color:var(--color-accent,#A78BFA)] bg-[color:var(--color-accent,#A78BFA)]"
: anyRowChecked
? "border-white/[0.18] bg-transparent group-hover/row:border-white/35"
: "border-white/[0.12] bg-transparent group-hover/row:border-white/35",
)}
{showCheckbox ? (
<button
type="button"
role="checkbox"
aria-checked={checked}
aria-label={checked ? `Deselect ${issue.identifier}` : `Select ${issue.identifier}`}
onClick={(e) => { e.stopPropagation(); onToggleCheck(e); }}
className="-ml-1 grid h-6 w-6 shrink-0 cursor-pointer place-items-center rounded-md outline-none focus-visible:bg-white/[0.06]"
>
{checked ? <Check size={10} weight="bold" className="text-[#0F0D14]" /> : null}
</span>
</button>
<span
className={cn(
"flex h-[14px] w-[14px] items-center justify-center rounded-[3px] border transition-colors",
checked
? "border-[color:var(--color-accent,#A78BFA)] bg-[color:var(--color-accent,#A78BFA)]"
: anyRowChecked
? "border-white/[0.18] bg-transparent group-hover/row:border-white/35"
: "border-white/[0.12] bg-transparent group-hover/row:border-white/35",
)}
>
{checked ? <Check size={10} weight="bold" className="text-[#0F0D14]" /> : null}
</span>
</button>
) : null}
<span className="w-[54px] shrink-0 truncate font-mono text-[11px] text-muted-fg/50">
{issue.identifier}
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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}
singleSelect
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>
);
}
Loading
Loading