Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83a00449c8 | ||
|
|
669d274bf9 | ||
|
|
3666f713e4 |
No files matched your search
@@ -12,7 +12,6 @@ import { ProviderDriverKind } from "@t3tools/contracts";
|
||||
import type * as EffectAcpSchema from "effect-acp/schema";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
@@ -20,7 +19,6 @@ import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Result from "effect/Result";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
import {
|
||||
@@ -55,8 +53,8 @@ const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({
|
||||
optionDescriptors: [],
|
||||
});
|
||||
|
||||
const CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT = Duration.seconds(15);
|
||||
const CURSOR_ACP_MODEL_CAPABILITY_TIMEOUT = Duration.seconds(4);
|
||||
const CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS = 15_000;
|
||||
const CURSOR_ACP_MODEL_CAPABILITY_TIMEOUT = "4 seconds";
|
||||
const CURSOR_ACP_MODEL_DISCOVERY_CONCURRENCY = 4;
|
||||
const CURSOR_PARAMETERIZED_MODEL_PICKER_MIN_VERSION_DATE = 2026_04_08;
|
||||
export const CURSOR_PARAMETERIZED_MODEL_PICKER_CAPABILITIES = {
|
||||
@@ -758,22 +756,11 @@ export function buildCursorProviderSnapshot(input: {
|
||||
});
|
||||
}
|
||||
|
||||
const CursorCliConfigJson = Schema.Struct({
|
||||
channel: Schema.optional(Schema.String),
|
||||
});
|
||||
const decodeCursorCliConfigJson = Schema.decodeUnknownOption(
|
||||
Schema.fromJsonString(CursorCliConfigJson),
|
||||
);
|
||||
|
||||
const CursorAboutJsonPayload = Schema.Struct({
|
||||
cliVersion: Schema.optional(Schema.Unknown),
|
||||
subscriptionTier: Schema.optional(Schema.Unknown),
|
||||
userEmail: Schema.optional(Schema.Unknown),
|
||||
});
|
||||
type CursorAboutJsonPayload = typeof CursorAboutJsonPayload.Type;
|
||||
const decodeCursorAboutJsonPayload = Schema.decodeUnknownOption(
|
||||
Schema.fromJsonString(CursorAboutJsonPayload),
|
||||
);
|
||||
interface CursorAboutJsonPayload {
|
||||
readonly cliVersion?: unknown;
|
||||
readonly subscriptionTier?: unknown;
|
||||
readonly userEmail?: unknown;
|
||||
}
|
||||
|
||||
export function parseCursorVersionDate(version: string | null | undefined): number | undefined {
|
||||
const match = version?.trim().match(/^(\d{4})\.(\d{2})\.(\d{2})(?:\b|-|$)/);
|
||||
@@ -785,13 +772,21 @@ export function parseCursorVersionDate(version: string | null | undefined): numb
|
||||
}
|
||||
|
||||
export function parseCursorCliConfigChannel(raw: string): string | undefined {
|
||||
const parsed = decodeCursorCliConfigJson(raw);
|
||||
if (Option.isNone(parsed)) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
if (
|
||||
typeof parsed === "object" &&
|
||||
parsed !== null &&
|
||||
"channel" in parsed &&
|
||||
typeof parsed.channel === "string"
|
||||
) {
|
||||
const channel = parsed.channel.trim().toLowerCase();
|
||||
return channel.length > 0 ? channel : undefined;
|
||||
}
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const channel = parsed.value.channel?.trim().toLowerCase();
|
||||
return channel && channel.length > 0 ? channel : undefined;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function toTitleCaseWords(value: string): string {
|
||||
@@ -840,7 +835,15 @@ function parseCursorAboutJsonPayload(raw: string): CursorAboutJsonPayload | unde
|
||||
if (!trimmed.startsWith("{")) {
|
||||
return undefined;
|
||||
}
|
||||
return Option.getOrUndefined(decodeCursorAboutJsonPayload(trimmed));
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed) as unknown;
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
return undefined;
|
||||
}
|
||||
return parsed as CursorAboutJsonPayload;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function hasOwn(record: object, key: string): boolean {
|
||||
@@ -1181,7 +1184,7 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(
|
||||
if (parsed.auth.status !== "unauthenticated") {
|
||||
const discoveryExit = yield* Effect.exit(
|
||||
discoverCursorModelsViaAcp(cursorSettings, environment).pipe(
|
||||
Effect.timeoutOption(CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT),
|
||||
Effect.timeoutOption(CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS),
|
||||
),
|
||||
);
|
||||
if (Exit.isFailure(discoveryExit)) {
|
||||
@@ -1190,7 +1193,7 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(
|
||||
});
|
||||
discoveryWarning = "Cursor ACP model discovery failed. Check server logs for details.";
|
||||
} else if (Option.isNone(discoveryExit.value)) {
|
||||
discoveryWarning = `Cursor ACP model discovery timed out after ${Duration.toMillis(CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT)}ms.`;
|
||||
discoveryWarning = `Cursor ACP model discovery timed out after ${CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS}ms.`;
|
||||
} else if (discoveryExit.value.value.length === 0) {
|
||||
discoveryWarning = "Cursor ACP model discovery returned no built-in models.";
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,6 @@ import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
@@ -16,9 +15,16 @@ const ProjectVcsConfig = Schema.Struct({
|
||||
),
|
||||
vcsKind: Schema.optional(VcsDriverKind),
|
||||
});
|
||||
const decodeProjectVcsConfig = Schema.decodeUnknownOption(Schema.fromJsonString(ProjectVcsConfig));
|
||||
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
|
||||
|
||||
type ProjectVcsConfigFile = typeof ProjectVcsConfig.Type;
|
||||
interface ProjectVcsConfigFile {
|
||||
readonly vcs?:
|
||||
| {
|
||||
readonly kind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
| undefined;
|
||||
readonly vcsKind?: VcsDriverKindType | undefined;
|
||||
}
|
||||
|
||||
export interface VcsProjectConfigResolveInput {
|
||||
readonly cwd: string;
|
||||
@@ -39,8 +45,13 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
|
||||
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
||||
}
|
||||
|
||||
function parseConfig(raw: string): Option.Option<ProjectVcsConfigFile> {
|
||||
return decodeProjectVcsConfig(raw);
|
||||
function parseConfig(raw: string): ProjectVcsConfigFile | null {
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
return isProjectVcsConfig(parsed) ? parsed : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
@@ -52,12 +63,12 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
while (true) {
|
||||
const candidate = path.join(current, ".t3code", "vcs.json");
|
||||
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
|
||||
return Option.some(candidate);
|
||||
return candidate;
|
||||
}
|
||||
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) {
|
||||
return Option.none<string>();
|
||||
return null;
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
@@ -67,27 +78,26 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
configPath: string,
|
||||
) {
|
||||
const raw = yield* fileSystem.readFileString(configPath).pipe(
|
||||
Effect.map(Option.some),
|
||||
Effect.catch((error) =>
|
||||
Effect.logWarning("failed to read VCS project config", {
|
||||
configPath,
|
||||
error,
|
||||
}).pipe(Effect.as(Option.none<string>())),
|
||||
}).pipe(Effect.as(null)),
|
||||
),
|
||||
);
|
||||
if (Option.isNone(raw)) {
|
||||
if (raw === null) {
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
const parsed = parseConfig(raw.value);
|
||||
if (Option.isNone(parsed)) {
|
||||
const parsed = parseConfig(raw);
|
||||
if (parsed === null) {
|
||||
yield* Effect.logWarning("invalid VCS project config", {
|
||||
configPath,
|
||||
});
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
return configuredKind(parsed.value);
|
||||
return configuredKind(parsed);
|
||||
});
|
||||
|
||||
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
||||
@@ -98,11 +108,11 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
}
|
||||
|
||||
const configPath = yield* findConfigPath(input.cwd);
|
||||
if (Option.isNone(configPath)) {
|
||||
if (configPath === null) {
|
||||
return "auto";
|
||||
}
|
||||
|
||||
return yield* readConfiguredKind(configPath.value);
|
||||
return yield* readConfiguredKind(configPath);
|
||||
});
|
||||
|
||||
return VcsProjectConfig.of({
|
||||
|
||||
@@ -68,7 +68,10 @@ import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
|
||||
import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel";
|
||||
import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
|
||||
import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner";
|
||||
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
|
||||
import {
|
||||
resolveComposerMenuActiveItemId,
|
||||
resolveComposerMenuNudgedItemId,
|
||||
} from "./composerMenuHighlight";
|
||||
import { searchSlashCommandItems } from "./composerSlashCommandSearch";
|
||||
import {
|
||||
getComposerProviderState,
|
||||
@@ -1134,35 +1137,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
composerTerminalContextsRef.current = composerTerminalContexts;
|
||||
}, [composerTerminalContexts, composerTerminalContextsRef]);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Composer menu highlight sync
|
||||
// ------------------------------------------------------------------
|
||||
useEffect(() => {
|
||||
if (!composerMenuOpen) {
|
||||
setComposerHighlightedItemId(null);
|
||||
setComposerHighlightedSearchKey(null);
|
||||
return;
|
||||
}
|
||||
const nextActiveItemId = resolveComposerMenuActiveItemId({
|
||||
items: composerMenuItems,
|
||||
highlightedItemId: composerHighlightedItemId,
|
||||
currentSearchKey: composerMenuSearchKey,
|
||||
highlightedSearchKey: composerHighlightedSearchKey,
|
||||
});
|
||||
setComposerHighlightedItemId((existing) =>
|
||||
existing === nextActiveItemId ? existing : nextActiveItemId,
|
||||
);
|
||||
setComposerHighlightedSearchKey((existing) =>
|
||||
existing === composerMenuSearchKey ? existing : composerMenuSearchKey,
|
||||
);
|
||||
}, [
|
||||
composerHighlightedItemId,
|
||||
composerHighlightedSearchKey,
|
||||
composerMenuItems,
|
||||
composerMenuOpen,
|
||||
composerMenuSearchKey,
|
||||
]);
|
||||
|
||||
const lastSyncedPendingInputRef = useRef<{
|
||||
requestId: string | null;
|
||||
questionId: string | null;
|
||||
@@ -1576,18 +1550,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
const nudgeComposerMenuHighlight = useCallback(
|
||||
(key: "ArrowDown" | "ArrowUp") => {
|
||||
if (composerMenuItems.length === 0) return;
|
||||
const highlightedIndex = composerMenuItems.findIndex(
|
||||
(item) => item.id === composerHighlightedItemId,
|
||||
setComposerHighlightedItemId(
|
||||
resolveComposerMenuNudgedItemId({
|
||||
items: composerMenuItems,
|
||||
activeItemId: activeComposerMenuItem?.id ?? null,
|
||||
direction: key === "ArrowDown" ? "next" : "previous",
|
||||
}),
|
||||
);
|
||||
const normalizedIndex =
|
||||
highlightedIndex >= 0 ? highlightedIndex : key === "ArrowDown" ? -1 : 0;
|
||||
const offset = key === "ArrowDown" ? 1 : -1;
|
||||
const nextIndex =
|
||||
(normalizedIndex + offset + composerMenuItems.length) % composerMenuItems.length;
|
||||
const nextItem = composerMenuItems[nextIndex];
|
||||
setComposerHighlightedItemId(nextItem?.id ?? null);
|
||||
setComposerHighlightedSearchKey(composerMenuSearchKey);
|
||||
},
|
||||
[composerHighlightedItemId, composerMenuItems],
|
||||
[activeComposerMenuItem?.id, composerMenuItems, composerMenuSearchKey],
|
||||
);
|
||||
|
||||
const blurMobileComposerAfterSend = useCallback(() => {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
|
||||
import {
|
||||
resolveComposerMenuActiveItemId,
|
||||
resolveComposerMenuNudgedItemId,
|
||||
} from "./composerMenuHighlight";
|
||||
|
||||
describe("resolveComposerMenuActiveItemId", () => {
|
||||
const items = [{ id: "top" }, { id: "second" }, { id: "third" }] as const;
|
||||
@@ -49,3 +52,61 @@ describe("resolveComposerMenuActiveItemId", () => {
|
||||
).toBe("top");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveComposerMenuNudgedItemId", () => {
|
||||
const items = [{ id: "top" }, { id: "second" }, { id: "third" }] as const;
|
||||
|
||||
it("moves from the active item", () => {
|
||||
expect(
|
||||
resolveComposerMenuNudgedItemId({
|
||||
items,
|
||||
activeItemId: "second",
|
||||
direction: "next",
|
||||
}),
|
||||
).toBe("third");
|
||||
|
||||
expect(
|
||||
resolveComposerMenuNudgedItemId({
|
||||
items,
|
||||
activeItemId: "second",
|
||||
direction: "previous",
|
||||
}),
|
||||
).toBe("top");
|
||||
});
|
||||
|
||||
it("wraps around at either edge", () => {
|
||||
expect(
|
||||
resolveComposerMenuNudgedItemId({
|
||||
items,
|
||||
activeItemId: "third",
|
||||
direction: "next",
|
||||
}),
|
||||
).toBe("top");
|
||||
|
||||
expect(
|
||||
resolveComposerMenuNudgedItemId({
|
||||
items,
|
||||
activeItemId: "top",
|
||||
direction: "previous",
|
||||
}),
|
||||
).toBe("third");
|
||||
});
|
||||
|
||||
it("starts from the first visible item when active state is stale", () => {
|
||||
expect(
|
||||
resolveComposerMenuNudgedItemId({
|
||||
items,
|
||||
activeItemId: "missing",
|
||||
direction: "next",
|
||||
}),
|
||||
).toBe("top");
|
||||
|
||||
expect(
|
||||
resolveComposerMenuNudgedItemId({
|
||||
items,
|
||||
activeItemId: "missing",
|
||||
direction: "previous",
|
||||
}),
|
||||
).toBe("third");
|
||||
});
|
||||
});
|
||||
@@ -18,3 +18,20 @@ export function resolveComposerMenuActiveItemId(input: {
|
||||
|
||||
return input.items[0]?.id ?? null;
|
||||
}
|
||||
|
||||
export function resolveComposerMenuNudgedItemId(input: {
|
||||
items: ReadonlyArray<{ id: string }>;
|
||||
activeItemId: string | null;
|
||||
direction: "next" | "previous";
|
||||
}): string | null {
|
||||
if (input.items.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const activeIndex = input.items.findIndex((item) => item.id === input.activeItemId);
|
||||
const normalizedIndex = activeIndex >= 0 ? activeIndex : input.direction === "next" ? -1 : 0;
|
||||
const offset = input.direction === "next" ? 1 : -1;
|
||||
const nextIndex = (normalizedIndex + offset + input.items.length) % input.items.length;
|
||||
|
||||
return input.items[nextIndex]?.id ?? null;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user