Remove legacy orchestration payload coercions
- Simplify orchestration contracts to canonical model-selection shapes - Add a Cursor ACP probe for listing available models
This commit is contained in:
1 parent
0a1e9b0d98
commit
23dfe7d0a0
4 files changed
+213
-431
No files matched your search
@@ -116,24 +116,6 @@ it.effect("decodes historical project.created payloads with a default provider",
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy project.created payloads into defaultModelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeProjectCreatedPayload({
|
||||
projectId: "project-legacy-1",
|
||||
title: "Project Title",
|
||||
workspaceRoot: "/tmp/workspace",
|
||||
defaultModel: "gpt-5.4",
|
||||
scripts: [],
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.defaultModelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes project.meta-updated payloads with explicit default provider", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeProjectMetaUpdatedPayload({
|
||||
@@ -148,21 +130,6 @@ it.effect("decodes project.meta-updated payloads with explicit default provider"
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy project.meta-updated payloads into defaultModelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeProjectMetaUpdatedPayload({
|
||||
projectId: "project-legacy-2",
|
||||
defaultProvider: "claudeAgent",
|
||||
defaultModel: "claude-opus-4-6",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.defaultModelSelection, {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("rejects command fields that become empty after trim", () =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* Effect.exit(
|
||||
@@ -246,29 +213,6 @@ it.effect("decodes thread.created runtime mode for historical events", () =>
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy thread.created payloads into modelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadCreatedPayload({
|
||||
threadId: "thread-legacy-1",
|
||||
projectId: "project-1",
|
||||
title: "Thread title",
|
||||
model: "claude-opus-4-6",
|
||||
provider: "claudeAgent",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(parsed.modelSelection, {
|
||||
provider: "claudeAgent",
|
||||
model: "claude-opus-4-6",
|
||||
});
|
||||
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes thread.meta-updated payloads with explicit provider", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadMetaUpdatedPayload({
|
||||
@@ -283,20 +227,6 @@ it.effect("decodes thread.meta-updated payloads with explicit provider", () =>
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy thread.meta-updated payloads into modelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadMetaUpdatedPayload({
|
||||
threadId: "thread-legacy-2",
|
||||
model: "gpt-5.4",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.modelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("accepts provider-scoped model options in thread.turn.start", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadTurnStartCommand({
|
||||
@@ -384,21 +314,6 @@ it.effect("decodes thread.turn-start-requested source proposed plan metadata whe
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes legacy thread.turn-start-requested payloads into modelSelection", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeThreadTurnStartRequestedPayload({
|
||||
threadId: "thread-legacy-3",
|
||||
messageId: "msg-legacy-3",
|
||||
model: "gpt-5.4",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
assert.deepStrictEqual(parsed.modelSelection, {
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("decodes latest turn source proposed plan metadata when present", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeOrchestrationLatestTurn({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation, Struct } from "effect";
|
||||
import { Option, Schema, SchemaIssue, Struct } from "effect";
|
||||
import { ClaudeModelOptions, CodexModelOptions } from "./model";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
@@ -60,96 +60,6 @@ export type ClaudeModelSelection = typeof ClaudeModelSelection.Type;
|
||||
|
||||
export const ModelSelection = Schema.Union([CodexModelSelection, ClaudeModelSelection]);
|
||||
export type ModelSelection = typeof ModelSelection.Type;
|
||||
const decodeModelSelectionSync = Schema.decodeUnknownSync(ModelSelection);
|
||||
|
||||
const LegacyDefaultModelSelectionFields = {
|
||||
defaultProvider: Schema.optional(ProviderKind),
|
||||
defaultModel: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
defaultModelOptions: Schema.optional(Schema.NullOr(Schema.Unknown)),
|
||||
} as const;
|
||||
|
||||
const LegacyThreadModelSelectionFields = {
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
modelOptions: Schema.optional(Schema.NullOr(Schema.Unknown)),
|
||||
} as const;
|
||||
|
||||
function invalidLegacyModelSelectionIssue(
|
||||
value: unknown,
|
||||
title: string,
|
||||
cause: unknown,
|
||||
): SchemaIssue.InvalidValue {
|
||||
return new SchemaIssue.InvalidValue(Option.some(value), {
|
||||
title,
|
||||
...(Schema.isSchemaError(cause)
|
||||
? { description: SchemaIssue.makeFormatterDefault()(cause.issue) }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
type LegacyDefaultModelSelectionInput = {
|
||||
readonly defaultModelSelection?: ModelSelection | null | undefined;
|
||||
readonly defaultProvider?: ProviderKind | undefined;
|
||||
readonly defaultModel?: string | null | undefined;
|
||||
readonly defaultModelOptions?: unknown | null | undefined;
|
||||
};
|
||||
|
||||
type LegacyThreadModelSelectionInput = {
|
||||
readonly modelSelection?: ModelSelection | undefined;
|
||||
readonly provider?: ProviderKind | undefined;
|
||||
readonly model?: string | undefined;
|
||||
readonly modelOptions?: unknown | null | undefined;
|
||||
};
|
||||
|
||||
function normalizeLegacyDefaultModelSelection(
|
||||
input: LegacyDefaultModelSelectionInput,
|
||||
): Effect.Effect<ModelSelection | null, SchemaIssue.InvalidValue> {
|
||||
if (input.defaultModelSelection !== undefined) {
|
||||
return Effect.succeed(input.defaultModelSelection);
|
||||
}
|
||||
if (input.defaultModel === undefined || input.defaultModel === null) {
|
||||
return Effect.succeed(null);
|
||||
}
|
||||
return Effect.try({
|
||||
try: () =>
|
||||
decodeModelSelectionSync({
|
||||
provider: input.defaultProvider ?? DEFAULT_PROVIDER_KIND,
|
||||
model: input.defaultModel,
|
||||
...(input.defaultModelOptions != null ? { options: input.defaultModelOptions } : {}),
|
||||
}),
|
||||
catch: (cause) =>
|
||||
invalidLegacyModelSelectionIssue(
|
||||
input,
|
||||
"Invalid legacy default model selection payload",
|
||||
cause,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeLegacyThreadModelSelection(
|
||||
input: LegacyThreadModelSelectionInput,
|
||||
): Effect.Effect<ModelSelection | undefined, SchemaIssue.InvalidValue> {
|
||||
if (input.modelSelection !== undefined) {
|
||||
return Effect.succeed(input.modelSelection);
|
||||
}
|
||||
if (input.model === undefined) {
|
||||
return Effect.succeed<ModelSelection | undefined>(undefined);
|
||||
}
|
||||
return Effect.try({
|
||||
try: () =>
|
||||
decodeModelSelectionSync({
|
||||
provider: input.provider ?? DEFAULT_PROVIDER_KIND,
|
||||
model: input.model,
|
||||
...(input.modelOptions != null ? { options: input.modelOptions } : {}),
|
||||
}),
|
||||
catch: (cause) =>
|
||||
invalidLegacyModelSelectionIssue(
|
||||
input,
|
||||
"Invalid legacy thread model selection payload",
|
||||
cause,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export const CodexProviderStartOptions = Schema.Struct({
|
||||
binaryPath: Schema.optional(TrimmedNonEmptyString),
|
||||
@@ -709,7 +619,7 @@ export const OrchestrationAggregateKind = Schema.Literals(["project", "thread"])
|
||||
export type OrchestrationAggregateKind = typeof OrchestrationAggregateKind.Type;
|
||||
export const OrchestrationActorKind = Schema.Literals(["client", "server", "provider"]);
|
||||
|
||||
const ProjectCreatedPayloadCanonical = Schema.Struct({
|
||||
export const ProjectCreatedPayload = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
workspaceRoot: TrimmedNonEmptyString,
|
||||
@@ -718,48 +628,8 @@ const ProjectCreatedPayloadCanonical = Schema.Struct({
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
const ProjectCreatedPayloadSource = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
workspaceRoot: TrimmedNonEmptyString,
|
||||
defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
|
||||
...LegacyDefaultModelSelectionFields,
|
||||
scripts: Schema.Array(ProjectScript),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ProjectCreatedPayloadSource = typeof ProjectCreatedPayloadSource.Type;
|
||||
export const ProjectCreatedPayload = ProjectCreatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ProjectCreatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input) =>
|
||||
normalizeLegacyDefaultModelSelection(input).pipe(
|
||||
Effect.map((defaultModelSelection) => ({
|
||||
projectId: input.projectId,
|
||||
title: input.title,
|
||||
workspaceRoot: input.workspaceRoot,
|
||||
defaultModelSelection,
|
||||
scripts: input.scripts,
|
||||
createdAt: input.createdAt,
|
||||
updatedAt: input.updatedAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical) =>
|
||||
Effect.succeed({
|
||||
projectId: canonical.projectId,
|
||||
title: canonical.title,
|
||||
workspaceRoot: canonical.workspaceRoot,
|
||||
defaultModelSelection: canonical.defaultModelSelection,
|
||||
scripts: canonical.scripts,
|
||||
createdAt: canonical.createdAt,
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ProjectCreatedPayloadSource),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const ProjectMetaUpdatedPayloadCanonical = Schema.Struct({
|
||||
export const ProjectMetaUpdatedPayload = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
workspaceRoot: Schema.optional(TrimmedNonEmptyString),
|
||||
@@ -767,60 +637,13 @@ const ProjectMetaUpdatedPayloadCanonical = Schema.Struct({
|
||||
scripts: Schema.optional(Schema.Array(ProjectScript)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ProjectMetaUpdatedPayloadCanonical = typeof ProjectMetaUpdatedPayloadCanonical.Type;
|
||||
const ProjectMetaUpdatedPayloadSource = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
workspaceRoot: Schema.optional(TrimmedNonEmptyString),
|
||||
defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
|
||||
...LegacyDefaultModelSelectionFields,
|
||||
scripts: Schema.optional(Schema.Array(ProjectScript)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ProjectMetaUpdatedPayloadSource = typeof ProjectMetaUpdatedPayloadSource.Type;
|
||||
export const ProjectMetaUpdatedPayload = ProjectMetaUpdatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ProjectMetaUpdatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input: ProjectMetaUpdatedPayloadSource) =>
|
||||
normalizeLegacyDefaultModelSelection(input).pipe(
|
||||
Effect.map((defaultModelSelection) => ({
|
||||
projectId: input.projectId,
|
||||
...(input.title !== undefined ? { title: input.title } : {}),
|
||||
...(input.workspaceRoot !== undefined ? { workspaceRoot: input.workspaceRoot } : {}),
|
||||
...(input.defaultModelSelection !== undefined ||
|
||||
input.defaultModel !== undefined ||
|
||||
input.defaultProvider !== undefined ||
|
||||
input.defaultModelOptions !== undefined
|
||||
? { defaultModelSelection }
|
||||
: {}),
|
||||
...(input.scripts !== undefined ? { scripts: input.scripts } : {}),
|
||||
updatedAt: input.updatedAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical: ProjectMetaUpdatedPayloadCanonical) =>
|
||||
Effect.succeed({
|
||||
projectId: canonical.projectId,
|
||||
...(canonical.title !== undefined ? { title: canonical.title } : {}),
|
||||
...(canonical.workspaceRoot !== undefined
|
||||
? { workspaceRoot: canonical.workspaceRoot }
|
||||
: {}),
|
||||
...(canonical.defaultModelSelection !== undefined
|
||||
? { defaultModelSelection: canonical.defaultModelSelection }
|
||||
: {}),
|
||||
...(canonical.scripts !== undefined ? { scripts: canonical.scripts } : {}),
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ProjectMetaUpdatedPayloadSource),
|
||||
} as any),
|
||||
),
|
||||
);
|
||||
|
||||
export const ProjectDeletedPayload = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
deletedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
const ThreadCreatedPayloadCanonical = Schema.Struct({
|
||||
export const ThreadCreatedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
@@ -834,72 +657,13 @@ const ThreadCreatedPayloadCanonical = Schema.Struct({
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
const ThreadCreatedPayloadSource = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
projectId: ProjectId,
|
||||
title: TrimmedNonEmptyString,
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
...LegacyThreadModelSelectionFields,
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
Schema.withDecodingDefault(() => DEFAULT_PROVIDER_INTERACTION_MODE),
|
||||
),
|
||||
branch: Schema.NullOr(TrimmedNonEmptyString),
|
||||
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ThreadCreatedPayloadSource = typeof ThreadCreatedPayloadSource.Type;
|
||||
export const ThreadCreatedPayload = ThreadCreatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ThreadCreatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input) =>
|
||||
normalizeLegacyThreadModelSelection(input).pipe(
|
||||
Effect.flatMap((modelSelection) =>
|
||||
modelSelection === undefined
|
||||
? Effect.fail(
|
||||
new SchemaIssue.InvalidValue(Option.some(input), {
|
||||
title: "Legacy thread.created payload is missing a model selection",
|
||||
}),
|
||||
)
|
||||
: Effect.succeed({
|
||||
threadId: input.threadId,
|
||||
projectId: input.projectId,
|
||||
title: input.title,
|
||||
modelSelection,
|
||||
runtimeMode: input.runtimeMode,
|
||||
interactionMode: input.interactionMode,
|
||||
branch: input.branch,
|
||||
worktreePath: input.worktreePath,
|
||||
createdAt: input.createdAt,
|
||||
updatedAt: input.updatedAt,
|
||||
}),
|
||||
),
|
||||
),
|
||||
encode: (canonical) =>
|
||||
Effect.succeed({
|
||||
threadId: canonical.threadId,
|
||||
projectId: canonical.projectId,
|
||||
title: canonical.title,
|
||||
modelSelection: canonical.modelSelection,
|
||||
runtimeMode: canonical.runtimeMode,
|
||||
interactionMode: canonical.interactionMode,
|
||||
branch: canonical.branch,
|
||||
worktreePath: canonical.worktreePath,
|
||||
createdAt: canonical.createdAt,
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ThreadCreatedPayloadSource),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
export const ThreadDeletedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
deletedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
const ThreadMetaUpdatedPayloadCanonical = Schema.Struct({
|
||||
export const ThreadMetaUpdatedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
@@ -907,46 +671,6 @@ const ThreadMetaUpdatedPayloadCanonical = Schema.Struct({
|
||||
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ThreadMetaUpdatedPayloadCanonical = typeof ThreadMetaUpdatedPayloadCanonical.Type;
|
||||
const ThreadMetaUpdatedPayloadSource = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
title: Schema.optional(TrimmedNonEmptyString),
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
...LegacyThreadModelSelectionFields,
|
||||
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
type ThreadMetaUpdatedPayloadSource = typeof ThreadMetaUpdatedPayloadSource.Type;
|
||||
export const ThreadMetaUpdatedPayload = ThreadMetaUpdatedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ThreadMetaUpdatedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input: ThreadMetaUpdatedPayloadSource) =>
|
||||
normalizeLegacyThreadModelSelection(input).pipe(
|
||||
Effect.map((modelSelection) => ({
|
||||
threadId: input.threadId,
|
||||
...(input.title !== undefined ? { title: input.title } : {}),
|
||||
...(modelSelection !== undefined ? { modelSelection } : {}),
|
||||
...(input.branch !== undefined ? { branch: input.branch } : {}),
|
||||
...(input.worktreePath !== undefined ? { worktreePath: input.worktreePath } : {}),
|
||||
updatedAt: input.updatedAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical: ThreadMetaUpdatedPayloadCanonical) =>
|
||||
Effect.succeed({
|
||||
threadId: canonical.threadId,
|
||||
...(canonical.title !== undefined ? { title: canonical.title } : {}),
|
||||
...(canonical.modelSelection !== undefined
|
||||
? { modelSelection: canonical.modelSelection }
|
||||
: {}),
|
||||
...(canonical.branch !== undefined ? { branch: canonical.branch } : {}),
|
||||
...(canonical.worktreePath !== undefined ? { worktreePath: canonical.worktreePath } : {}),
|
||||
updatedAt: canonical.updatedAt,
|
||||
} as ThreadMetaUpdatedPayloadSource),
|
||||
} as any),
|
||||
),
|
||||
);
|
||||
|
||||
export const ThreadRuntimeModeSetPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
@@ -974,7 +698,7 @@ export const ThreadMessageSentPayload = Schema.Struct({
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
const ThreadTurnStartRequestedPayloadCanonical = Schema.Struct({
|
||||
export const ThreadTurnStartRequestedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
messageId: MessageId,
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
@@ -987,70 +711,6 @@ const ThreadTurnStartRequestedPayloadCanonical = Schema.Struct({
|
||||
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
|
||||
createdAt: IsoDateTime,
|
||||
});
|
||||
type ThreadTurnStartRequestedPayloadCanonical =
|
||||
typeof ThreadTurnStartRequestedPayloadCanonical.Type;
|
||||
const ThreadTurnStartRequestedPayloadSource = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
messageId: MessageId,
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
...LegacyThreadModelSelectionFields,
|
||||
providerOptions: Schema.optional(ProviderStartOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
interactionMode: ProviderInteractionMode.pipe(
|
||||
Schema.withDecodingDefault(() => DEFAULT_PROVIDER_INTERACTION_MODE),
|
||||
),
|
||||
sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
|
||||
createdAt: IsoDateTime,
|
||||
});
|
||||
type ThreadTurnStartRequestedPayloadSource = typeof ThreadTurnStartRequestedPayloadSource.Type;
|
||||
export const ThreadTurnStartRequestedPayload = ThreadTurnStartRequestedPayloadSource.pipe(
|
||||
Schema.decodeTo(
|
||||
Schema.toType(ThreadTurnStartRequestedPayloadCanonical),
|
||||
SchemaTransformation.transformOrFail({
|
||||
decode: (input: ThreadTurnStartRequestedPayloadSource) =>
|
||||
normalizeLegacyThreadModelSelection(input).pipe(
|
||||
Effect.map((modelSelection) => ({
|
||||
threadId: input.threadId,
|
||||
messageId: input.messageId,
|
||||
...(modelSelection !== undefined ? { modelSelection } : {}),
|
||||
...(input.providerOptions !== undefined
|
||||
? { providerOptions: input.providerOptions }
|
||||
: {}),
|
||||
...(input.assistantDeliveryMode !== undefined
|
||||
? { assistantDeliveryMode: input.assistantDeliveryMode }
|
||||
: {}),
|
||||
runtimeMode: input.runtimeMode,
|
||||
interactionMode: input.interactionMode,
|
||||
...(input.sourceProposedPlan !== undefined
|
||||
? { sourceProposedPlan: input.sourceProposedPlan }
|
||||
: {}),
|
||||
createdAt: input.createdAt,
|
||||
})),
|
||||
),
|
||||
encode: (canonical: ThreadTurnStartRequestedPayloadCanonical) =>
|
||||
Effect.succeed({
|
||||
threadId: canonical.threadId,
|
||||
messageId: canonical.messageId,
|
||||
...(canonical.modelSelection !== undefined
|
||||
? { modelSelection: canonical.modelSelection }
|
||||
: {}),
|
||||
...(canonical.providerOptions !== undefined
|
||||
? { providerOptions: canonical.providerOptions }
|
||||
: {}),
|
||||
...(canonical.assistantDeliveryMode !== undefined
|
||||
? { assistantDeliveryMode: canonical.assistantDeliveryMode }
|
||||
: {}),
|
||||
runtimeMode: canonical.runtimeMode,
|
||||
interactionMode: canonical.interactionMode,
|
||||
...(canonical.sourceProposedPlan !== undefined
|
||||
? { sourceProposedPlan: canonical.sourceProposedPlan }
|
||||
: {}),
|
||||
createdAt: canonical.createdAt,
|
||||
} as ThreadTurnStartRequestedPayloadSource),
|
||||
} as any),
|
||||
),
|
||||
);
|
||||
|
||||
export const ThreadTurnInterruptRequestedPayload = Schema.Struct({
|
||||
threadId: ThreadId,
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* Probe: connect to Cursor Agent via ACP (stdio NDJSON JSON-RPC 2.0)
|
||||
* and retrieve the available model list.
|
||||
*
|
||||
* Usage: bun run scripts/cursor-acp-models-probe.ts
|
||||
*/
|
||||
|
||||
import { spawn, type Subprocess } from "bun"
|
||||
|
||||
// ── JSON-RPC helpers ──────────────────────────────────────────────
|
||||
|
||||
interface JsonRpcRequest {
|
||||
jsonrpc: "2.0"
|
||||
id: number
|
||||
method: string
|
||||
params: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface JsonRpcResponse {
|
||||
jsonrpc: "2.0"
|
||||
id?: number
|
||||
method?: string
|
||||
result?: unknown
|
||||
error?: { code: number; message: string; data?: unknown }
|
||||
params?: unknown
|
||||
}
|
||||
|
||||
// ── NDJSON reader ─────────────────────────────────────────────────
|
||||
|
||||
async function* readNdjson(
|
||||
stream: ReadableStream<Uint8Array>,
|
||||
): AsyncGenerator<JsonRpcResponse> {
|
||||
const reader = stream.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let buf = ""
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
buf += decoder.decode(value, { stream: true })
|
||||
|
||||
let nl: number
|
||||
while ((nl = buf.indexOf("\n")) !== -1) {
|
||||
const line = buf.slice(0, nl).trim()
|
||||
buf = buf.slice(nl + 1)
|
||||
if (line.length === 0) continue
|
||||
try {
|
||||
yield JSON.parse(line) as JsonRpcResponse
|
||||
} catch {
|
||||
console.error("[probe] unparseable line:", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
reader.releaseLock()
|
||||
}
|
||||
}
|
||||
|
||||
// ── Main ──────────────────────────────────────────────────────────
|
||||
|
||||
const AGENT_BIN = process.env.CURSOR_AGENT ?? "cursor-agent"
|
||||
const TIMEOUT_MS = 30_000
|
||||
|
||||
console.log(`[probe] spawning: ${AGENT_BIN} acp`)
|
||||
|
||||
const proc: Subprocess = spawn([AGENT_BIN, "acp"], {
|
||||
stdin: "pipe",
|
||||
stdout: "pipe",
|
||||
stderr: "inherit",
|
||||
})
|
||||
|
||||
const writer = proc.stdin!
|
||||
const messages = readNdjson(proc.stdout as ReadableStream<Uint8Array>)
|
||||
|
||||
let nextId = 1
|
||||
|
||||
async function send(method: string, params: Record<string, unknown> = {}) {
|
||||
const msg: JsonRpcRequest = {
|
||||
jsonrpc: "2.0",
|
||||
id: nextId++,
|
||||
method,
|
||||
params,
|
||||
}
|
||||
const line = JSON.stringify(msg) + "\n"
|
||||
writer.write(new TextEncoder().encode(line))
|
||||
writer.flush()
|
||||
return msg.id
|
||||
}
|
||||
|
||||
async function waitForResponse(
|
||||
id: number,
|
||||
iter: AsyncGenerator<JsonRpcResponse>,
|
||||
): Promise<JsonRpcResponse> {
|
||||
for await (const msg of iter) {
|
||||
// skip notifications (no id)
|
||||
if (msg.id === id) return msg
|
||||
// log interesting notifications
|
||||
if (msg.method) {
|
||||
console.log(`[probe] notification: ${msg.method}`)
|
||||
}
|
||||
}
|
||||
throw new Error(`stream ended before response id=${id}`)
|
||||
}
|
||||
|
||||
// ── Run the probe ─────────────────────────────────────────────────
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
console.error("[probe] timed out after", TIMEOUT_MS, "ms")
|
||||
proc.kill()
|
||||
process.exit(1)
|
||||
}, TIMEOUT_MS)
|
||||
|
||||
try {
|
||||
// 1. Initialize
|
||||
console.log("[probe] → initialize")
|
||||
const initId = await send("initialize", {
|
||||
protocolVersion: 1,
|
||||
clientInfo: { name: "t3-acp-probe", version: "0.1.0" },
|
||||
clientCapabilities: {
|
||||
fs: { readTextFile: false, writeTextFile: false },
|
||||
terminal: false,
|
||||
},
|
||||
})
|
||||
const initResp = await waitForResponse(initId, messages)
|
||||
if (initResp.error) {
|
||||
console.error("[probe] initialize error:", initResp.error)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log("[probe] ← initialize response:")
|
||||
console.log(JSON.stringify(initResp.result, null, 2))
|
||||
|
||||
const initResult = initResp.result as Record<string, unknown>
|
||||
const agentInfo = (initResult.agentInfo ?? initResult.agent_info ?? initResult.serverInfo ?? initResult.server_info) as
|
||||
| { name: string; version: string }
|
||||
| undefined
|
||||
if (agentInfo) {
|
||||
console.log(`[probe] agent: ${agentInfo.name} v${agentInfo.version}`)
|
||||
}
|
||||
|
||||
// 2. Create session → models come back in the response
|
||||
console.log("[probe] → session/new")
|
||||
const sessionId = await send("session/new", {
|
||||
cwd: process.cwd(),
|
||||
mcpServers: [],
|
||||
})
|
||||
const sessionResp = await waitForResponse(sessionId, messages)
|
||||
if (sessionResp.error) {
|
||||
console.error("[probe] session/new error:", sessionResp.error)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const session = sessionResp.result as {
|
||||
sessionId: string
|
||||
models?: {
|
||||
currentModelId: string
|
||||
availableModels: Array<{ modelId: string; name: string }>
|
||||
}
|
||||
configOptions?: Array<{
|
||||
id: string
|
||||
name: string
|
||||
type: string
|
||||
currentValue?: string
|
||||
options?: Array<{ value: string; name: string }>
|
||||
}>
|
||||
}
|
||||
|
||||
console.log(`[probe] ← session: ${session.sessionId}`)
|
||||
|
||||
// 3. Print models from top-level models field
|
||||
if (session.models) {
|
||||
console.log(
|
||||
`\n── models (top-level) ── current: ${session.models.currentModelId}`,
|
||||
)
|
||||
for (const m of session.models.availableModels) {
|
||||
console.log(` ${m.modelId.padEnd(40)} ${m.name}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Print model config option (may have richer variant info)
|
||||
const modelConfig = session.configOptions?.find((c) => c.id === "model")
|
||||
if (modelConfig?.options) {
|
||||
console.log(
|
||||
`\n── models (config option) ── current: ${modelConfig.currentValue}`,
|
||||
)
|
||||
for (const opt of modelConfig.options) {
|
||||
console.log(` ${opt.value.padEnd(40)} ${opt.name}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Print other config options for reference
|
||||
const otherConfigs = session.configOptions?.filter((c) => c.id !== "model")
|
||||
if (otherConfigs?.length) {
|
||||
console.log("\n── other config options ──")
|
||||
for (const c of otherConfigs) {
|
||||
console.log(` ${c.id}: ${c.currentValue} (${c.type})`)
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Also dump raw JSON for inspection
|
||||
console.log("\n── raw session response ──")
|
||||
console.log(JSON.stringify(session, null, 2))
|
||||
} finally {
|
||||
clearTimeout(timeout)
|
||||
proc.kill()
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
"prepare": "effect-language-service patch",
|
||||
"claude-fast-mode-probe": "bun run claude-fast-mode-probe.ts",
|
||||
"claude-haiku-thinking-probe": "bun run claude-haiku-thinking-probe.ts",
|
||||
"cursor-acp-models-probe": "bun run cursor-acp-models-probe.ts",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user