Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4419ba0e0c | ||
|
|
8c4d76f7eb |
No files matched your search
@@ -6,10 +6,12 @@ import type {
|
||||
} from "@t3tools/contracts";
|
||||
import * as Context from "effect/Context";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import {
|
||||
@@ -20,6 +22,7 @@ import {
|
||||
} from "./ProcessDiagnostics.ts";
|
||||
|
||||
const SAMPLE_INTERVAL_MS = 5_000;
|
||||
const SAMPLE_INTERVAL = Duration.millis(SAMPLE_INTERVAL_MS);
|
||||
const RETENTION_MS = 60 * 60_000;
|
||||
const MAX_RETAINED_SAMPLES = 20_000;
|
||||
|
||||
@@ -274,9 +277,7 @@ export const make = Effect.fn("makeProcessResourceMonitor")(function* () {
|
||||
),
|
||||
);
|
||||
|
||||
yield* Effect.forever(sampleOnce.pipe(Effect.andThen(Effect.sleep(SAMPLE_INTERVAL_MS)))).pipe(
|
||||
Effect.forkScoped,
|
||||
);
|
||||
yield* sampleOnce.pipe(Effect.repeat(Schedule.spaced(SAMPLE_INTERVAL)), Effect.forkScoped);
|
||||
|
||||
const readHistory: ProcessResourceMonitorShape["readHistory"] = (input) =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -67,4 +67,24 @@ describe("VcsProjectConfig", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.layer(TestLayer)("falls back to auto when config is invalid", (it) => {
|
||||
it.effect("returns auto", () =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const root = yield* fileSystem.makeTempDirectoryScoped({
|
||||
prefix: "t3-vcs-config-test-",
|
||||
});
|
||||
const configDir = path.join(root, ".t3code");
|
||||
yield* fileSystem.makeDirectory(configDir, { recursive: true });
|
||||
yield* fileSystem.writeFileString(path.join(configDir, "vcs.json"), "{");
|
||||
|
||||
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||
const kind = yield* config.resolveKind({ cwd: root });
|
||||
|
||||
assert.equal(kind, "auto");
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -16,9 +16,9 @@ const ProjectVcsConfig = Schema.Struct({
|
||||
),
|
||||
vcsKind: Schema.optional(VcsDriverKind),
|
||||
});
|
||||
const decodeProjectVcsConfig = Schema.decodeUnknownOption(Schema.fromJsonString(ProjectVcsConfig));
|
||||
type ProjectVcsConfigFile = Schema.Schema.Type<typeof ProjectVcsConfig>;
|
||||
|
||||
type ProjectVcsConfigFile = typeof ProjectVcsConfig.Type;
|
||||
const decodeProjectVcsConfig = Schema.decodeUnknownEffect(Schema.fromJsonString(ProjectVcsConfig));
|
||||
|
||||
export interface VcsProjectConfigResolveInput {
|
||||
readonly cwd: string;
|
||||
@@ -39,10 +39,6 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
|
||||
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
||||
}
|
||||
|
||||
function parseConfig(raw: string): Option.Option<ProjectVcsConfigFile> {
|
||||
return decodeProjectVcsConfig(raw);
|
||||
}
|
||||
|
||||
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
@@ -79,7 +75,7 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
return "auto" as const;
|
||||
}
|
||||
|
||||
const parsed = parseConfig(raw.value);
|
||||
const parsed = yield* decodeProjectVcsConfig(raw.value).pipe(Effect.option);
|
||||
if (Option.isNone(parsed)) {
|
||||
yield* Effect.logWarning("invalid VCS project config", {
|
||||
configPath,
|
||||
@@ -98,11 +94,10 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||
}
|
||||
|
||||
const configPath = yield* findConfigPath(input.cwd);
|
||||
if (Option.isNone(configPath)) {
|
||||
return "auto";
|
||||
}
|
||||
|
||||
return yield* readConfiguredKind(configPath.value);
|
||||
return yield* Option.match(configPath, {
|
||||
onNone: () => Effect.succeed("auto" as const),
|
||||
onSome: readConfiguredKind,
|
||||
});
|
||||
});
|
||||
|
||||
return VcsProjectConfig.of({
|
||||
|
||||
Reference in new issue
Block a user