GeezerVison is showing github.com — fix(acp): fix a batch of ACP issues (#66631) · erickwill/opencode@1917f0e
File treeExpand file treeCollapse file tree Open diff view settings services/site/src/docs/content/cli
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/catalog.ts +20-3Lines changed: 20 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,8 @@ import type { OpenCodeClient, OpenCodeEvent } from "@opencode/client/effect" | 2 | 2 | import type { Agent } from "@opencode/schema/agent" | 3 | 3 | import type { Command } from "@opencode/schema/command" | 4 | 4 | import type { Model } from "@opencode/schema/model" | | 5 | +import type { Provider } from "@opencode/schema/provider" | | 6 | +import type { Skill } from "@opencode/schema/skill" | 5 | 7 | import { FSUtil } from "@opencode/util/fs-util" | 6 | 8 | import { Cause, Deferred, Effect, Exit, Schedule, Semaphore, Stream, SubscriptionRef } from "effect" | 7 | 9 | import { ACPError } from "./error" | @@ -16,6 +18,9 @@ export type Catalog = { | 16 | 18 | readonly modes: ReadonlyArray<{ id: Agent.ID; name: string; description?: string }> | 17 | 19 | readonly defaultModeID: Agent.ID | 18 | 20 | readonly commands: ReadonlyArray<Command.Info> | | 21 | + /** Skills whose ID no command or built-in command already claims. */ | | 22 | + readonly skills: ReadonlyArray<Skill.Info> | | 23 | + readonly providerNames: ReadonlyMap<Provider.ID, string> | 19 | 24 | } | 20 | 25 |
| 21 | 26 | export function findModel(models: ReadonlyArray<Model.Info>, ref: Model.Ref) { | @@ -36,7 +41,13 @@ type Entry = { | 36 | 41 | loadedGeneration: number | 37 | 42 | } | 38 | 43 |
| 39 | | -const reloadOn = new Set<OpenCodeEvent["type"]>(["model.updated", "agent.updated", "command.updated"]) | | 44 | +const reloadOn = new Set<OpenCodeEvent["type"]>([ | | 45 | + "model.updated", | | 46 | + "agent.updated", | | 47 | + "command.updated", | | 48 | + "skill.updated", | | 49 | + "provider.updated", | | 50 | +]) | 40 | 51 |
| 41 | 52 | export const make = Effect.fnUntraced(function* (client: OpenCodeClient) { | 42 | 53 | const scope = yield* Effect.scope | @@ -138,12 +149,14 @@ const load = Effect.fn("cli.acp.catalog.load")(function* (client: OpenCodeClient | 138 | 149 |
| 139 | 150 | const read = Effect.fnUntraced(function* (client: OpenCodeClient, cwd: string) { | 140 | 151 | const location = { directory: cwd } | 141 | | - const [modelResult, defaultResult, agentResult, commandResult] = yield* Effect.all( | | 152 | + const [modelResult, defaultResult, agentResult, commandResult, skillResult, providerResult] = yield* Effect.all( | 142 | 153 | [ | 143 | 154 | client.model.list({ location }), | 144 | 155 | client.model.default({ location }), | 145 | 156 | client.agent.list({ location }), | 146 | 157 | client.command.list({ location }), | | 158 | + client.skill.list({ location }), | | 159 | + client.provider.list({ location }), | 147 | 160 | ], | 148 | 161 | { concurrency: "unbounded" }, | 149 | 162 | ).pipe(Effect.mapError((cause) => new ACPError.CatalogLoadError({ cause }))) | @@ -156,6 +169,8 @@ const read = Effect.fnUntraced(function* (client: OpenCodeClient, cwd: string) { | 156 | 169 | // Core lists its resolved default agent first, the same one a new session runs. | 157 | 170 | const defaultAgent = agents[0] | 158 | 171 | if (!defaultAgent) return yield* new ACPError.CatalogNotReadyError({ reason: "agents" }) | | 172 | + const commands = commandResult.data.filter((command) => !builtinCommands.has(command.name)) | | 173 | + const commandNames = new Set(commands.map((command) => command.name)) | 159 | 174 | return { | 160 | 175 | models, | 161 | 176 | defaultModel: { | @@ -165,7 +180,9 @@ const read = Effect.fnUntraced(function* (client: OpenCodeClient, cwd: string) { | 165 | 180 | }, | 166 | 181 | modes: agents.map((agent) => ({ id: agent.id, name: agent.name, description: agent.description })), | 167 | 182 | defaultModeID: defaultAgent.id, | 168 | | - commands: commandResult.data.filter((command) => !builtinCommands.has(command.name)), | | 183 | + commands, | | 184 | + skills: skillResult.data.filter((skill) => !builtinCommands.has(skill.id) && !commandNames.has(skill.id)), | | 185 | + providerNames: new Map(providerResult.data.map((provider) => [provider.id, provider.name])), | 169 | 186 | } satisfies Catalog | 170 | 187 | }) | 171 | 188 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/child.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { SessionUpdate } from "@agentclientprotocol/sdk" | 2 | 2 |
| 3 | 3 | export const UpdateMethod = "opencode/session/child_update" | | 4 | +export const MetaKey = "opencode/child-session" | 4 | 5 |
| 5 | 6 | export type Session = { | 6 | 7 | readonly id: string | @@ -48,7 +49,7 @@ export function project(sessionUpdate: SessionUpdate, child: Session) { | 48 | 49 |
| 49 | 50 | export function meta(child: Session) { | 50 | 51 | return { | 51 | | - "opencode/child-session": { | | 52 | + [MetaKey]: { | 52 | 53 | id: child.id, | 53 | 54 | parentID: child.parentID, | 54 | 55 | depth: child.depth, | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/client.ts +18-1Lines changed: 18 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { ClientError } from "@opencode/client/effect" | 2 | | -import { InvalidCursorError, InvalidRequestError, SessionNotFoundError } from "@opencode/protocol/errors" | | 2 | +import { | | 3 | + CommandExecutionError, | | 4 | + CommandNotFoundError, | | 5 | + InvalidCursorError, | | 6 | + InvalidRequestError, | | 7 | + SessionNotFoundError, | | 8 | +} from "@opencode/protocol/errors" | 3 | 9 | import { Session } from "@opencode/schema/session" | 4 | 10 | import { Effect, Schema } from "effect" | 5 | 11 | import { HttpClientError } from "effect/http" | @@ -20,6 +26,17 @@ export function classify(error: unknown): Effect.Effect<never, ACPError.Error> { | 20 | 26 | return Effect.fail(new ACPError.InvalidRequestError({ message: error.message, field: error.field })) | 21 | 27 | if (error instanceof InvalidCursorError) | 22 | 28 | return Effect.fail(new ACPError.InvalidRequestError({ message: error.message, field: "cursor" })) | | 29 | + if (error instanceof CommandNotFoundError) | | 30 | + return Effect.fail(new ACPError.InvalidRequestError({ message: error.message, field: "prompt" })) | | 31 | + // The message is the command's own, such as its usage, so the client shows it instead of a generic failure. | | 32 | + if (error instanceof CommandExecutionError) | | 33 | + return Effect.fail( | | 34 | + new ACPError.ServiceFailureError({ | | 35 | + safeMessage: error.message, | | 36 | + service: "command", | | 37 | + errorName: "CommandExecutionError", | | 38 | + }), | | 39 | + ) | 23 | 40 | return Effect.die(error) | 24 | 41 | } | 25 | 42 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/config-option.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,10 @@ export function configOptions(catalog: Catalog, selection: Selection): SessionCo | 31 | 31 | currentValue: advertisedModel(model), | 32 | 32 | options: catalog.models | 33 | 33 | .toSorted((a, b) => Order.String(a.providerID, b.providerID) || a.name.localeCompare(b.name)) | 34 | | - .map((item) => ({ value: advertisedModel(item), name: `${item.providerID}/${item.name}` })), | | 34 | + .map((item) => ({ | | 35 | + value: advertisedModel(item), | | 36 | + name: `${catalog.providerNames.get(item.providerID) ?? item.providerID} / ${item.name}`, | | 37 | + })), | 35 | 38 | }, | 36 | 39 | ...(variants.length > 0 | 37 | 40 | ? [ | @@ -71,6 +74,7 @@ export function availableCommands(catalog: Catalog) { | 71 | 74 | return [ | 72 | 75 | ...catalog.commands.map((command) => ({ name: command.name, description: command.description ?? "" })), | 73 | 76 | ...Array.from(builtinCommands, ([name, command]) => ({ name, description: command.description })), | | 77 | + ...catalog.skills.map((skill) => ({ name: skill.id, description: skill.description ?? "" })), | 74 | 78 | ] | 75 | 79 | } | 76 | 80 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/content.ts +22-10Lines changed: 22 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,7 +34,7 @@ function contentBlockToParts(block: ContentBlock): PromptPart[] { | 34 | 34 | } | 35 | 35 | case "resource_link": | 36 | 36 | return [resourceLinkToPart(block)] | 37 | | - case "resource": | | 37 | + case "resource": { | 38 | 38 | if ("text" in block.resource) { | 39 | 39 | const parsed = URL.canParse(block.resource.uri) ? new URL(block.resource.uri) : undefined | 40 | 40 | const decoded = | @@ -50,17 +50,20 @@ function contentBlockToParts(block: ContentBlock): PromptPart[] { | 50 | 50 | const filepath = path.sep === "\\" ? decoded.replace(/\\/g, "/") : decoded | 51 | 51 | return [{ type: "text", text: `[${filepath}${line ? `:${line}` : ""}]\n${block.resource.text}` }] | 52 | 52 | } | 53 | | - if (!block.resource.mimeType) return [] | | 53 | + const filename = filenameFromUri(block.resource.uri) ?? "file" | | 54 | + // ACP makes `mimeType` optional, so infer it from the name rather than dropping the bytes. | | 55 | + const mime = block.resource.mimeType || Bun.file(filename).type.split(";")[0] || "application/octet-stream" | 54 | 56 | return [ | 55 | 57 | { | 56 | 58 | type: "file", | 57 | 59 | url: block.resource.uri.startsWith("data:") | 58 | 60 | ? block.resource.uri | 59 | | - : `data:${block.resource.mimeType};base64,${block.resource.blob}`, | 60 | | - filename: filenameFromUri(block.resource.uri) ?? "file", | 61 | | - mime: block.resource.mimeType, | | 61 | + : `data:${mime};base64,${block.resource.blob}`, | | 62 | + filename, | | 63 | + mime, | 62 | 64 | }, | 63 | 65 | ] | | 66 | + } | 64 | 67 | default: | 65 | 68 | return [] | 66 | 69 | } | @@ -136,16 +139,18 @@ export function partsToContentChunks(parts: readonly ReplayPart[]): ContentChunk | 136 | 139 | } | 137 | 140 |
| 138 | 141 | function resourceLinkToPart(link: ResourceLink): PromptPart { | 139 | | - if (link.uri.startsWith("file://")) { | | 142 | + const parsed = URL.canParse(link.uri) ? new URL(link.uri) : undefined | | 143 | + // `file:/path` and `file:///path` name the same file; the parsed URL spells both as the latter. | | 144 | + if (parsed?.protocol === "file:") { | 140 | 145 | return { | 141 | 146 | type: "file", | 142 | | - url: link.uri, | | 147 | + url: parsed.href, | 143 | 148 | filename: link.name || filenameFromUri(link.uri) || "file", | 144 | 149 | mime: link.mimeType ?? "text/plain", | 145 | 150 | } | 146 | 151 | } | 147 | | - if (link.uri.startsWith("zed://") && URL.canParse(link.uri)) { | 148 | | - const pathname = new URL(link.uri).searchParams.get("path") | | 152 | + if (parsed?.protocol === "zed:") { | | 153 | + const pathname = parsed.searchParams.get("path") | 149 | 154 | if (pathname) | 150 | 155 | return { | 151 | 156 | type: "file", | @@ -165,7 +170,14 @@ function filenameFromUri(uri: string | undefined): string | undefined { | 165 | 170 | if (!uri || uri.startsWith("data:")) return undefined | 166 | 171 | if (URL.canParse(uri)) { | 167 | 172 | const url = new URL(uri) | 168 | | - return path.basename((url.protocol === "zed:" && url.searchParams.get("path")) || url.pathname) || undefined | | 173 | + // Zed's `path` query is already decoded; a URL path is not. | | 174 | + const zedPath = url.protocol === "zed:" ? url.searchParams.get("path") : null | | 175 | + if (zedPath) return path.basename(zedPath) || undefined | | 176 | + return decodeComponent(path.basename(url.pathname)) || undefined | 169 | 177 | } | 170 | 178 | return path.basename(uri) || undefined | 171 | 179 | } | | 180 | + | | 181 | +function decodeComponent(value: string) { | | 182 | + return Result.try(() => decodeURIComponent(value)).pipe(Result.getOrElse(() => value)) | | 183 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/elicitation.ts +20-3Lines changed: 20 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,8 +50,9 @@ function cancel(client: OpenCodeClient, form: Form.Info, message?: string) { | 50 | 50 | export function requestedSchema(form: AskedForm, capabilities: Capabilities): ElicitationSchema | undefined { | 51 | 51 | if (!capabilities.formElicitation) return undefined | 52 | 52 | if (Option.isNone(Schema.decodeUnknownOption(ElicitedKind)(form.metadata))) return undefined | 53 | | - if (form.fields.some(credentialLike)) return undefined | 54 | | - const fields = form.fields.filter((field): field is InputField => field.type !== "external") | | 53 | + const elicitedFields = form.fields.map(elicited) | | 54 | + if (elicitedFields.some(collectsSecret)) return undefined | | 55 | + const fields = elicitedFields.filter((field): field is InputField => field.type !== "external") | 55 | 56 | if (fields.length !== form.fields.length || fields.some((field) => field.when?.length)) return undefined | 56 | 57 | if (fields.some((field) => field.hidden && field.required && field.default === undefined)) return undefined | 57 | 58 | const keys = new Set(fields.map((field) => field.key)) | @@ -76,7 +77,7 @@ function answer(form: AskedForm, response: CreateElicitationResponse): Form.Answ | 76 | 77 | const content = Schema.decodeUnknownOption(Form.Answer)(response.content ?? {}) | 77 | 78 | if (Option.isNone(content)) return undefined | 78 | 79 | return Object.fromEntries( | 79 | | - form.fields.flatMap((field) => { | | 80 | + form.fields.map(elicited).flatMap((field) => { | 80 | 81 | const value = fieldAnswer(field, content.value) | 81 | 82 | return value === undefined ? [] : [[field.key, value]] | 82 | 83 | }), | @@ -108,6 +109,22 @@ export function respond(input: Input, outcome: Form.Answer | "cancel") { | 108 | 109 | ) | 109 | 110 | } | 110 | 111 |
| | 112 | +// A choice can't carry a secret, so a choice worded like one is still asked, without its typed answer. | | 113 | +function elicited(field: Form.Field): Form.Field { | | 114 | + if (!isSelect(field) || !field.custom || !credentialLike(field)) return field | | 115 | + return { ...field, custom: false } | | 116 | +} | | 117 | + | | 118 | +function collectsSecret(field: Form.Field) { | | 119 | + if (field.type === "boolean") return false | | 120 | + if (isSelect(field) && !field.custom) return false | | 121 | + return credentialLike(field) | | 122 | +} | | 123 | + | | 124 | +function isSelect(field: Form.Field): field is SelectField { | | 125 | + return (field.type === "string" || field.type === "multiselect") && hasOptions(field) | | 126 | +} | | 127 | + | 111 | 128 | function credentialLike(field: Form.Field) { | 112 | 129 | const labels = | 113 | 130 | field.type === "string" || field.type === "multiselect" ? (field.options ?? []).map((option) => option.label) : [] | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/error.ts +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ export class SessionNotFoundError extends Schema.TaggedError<SessionNotFoundErro | 7 | 7 |
| 8 | 8 | export class SessionDirectoryMismatchError extends Schema.TaggedError<SessionDirectoryMismatchError>()( | 9 | 9 | "ACPSessionDirectoryMismatchError", | 10 | | - { sessionId: Schema.String, cwd: Schema.String }, | | 10 | + { sessionId: Schema.String, cwd: Schema.String, directory: Schema.String }, | 11 | 11 | ) {} | 12 | 12 |
| 13 | 13 | export class InvalidConfigOptionError extends Schema.TaggedError<InvalidConfigOptionError>()( | @@ -48,6 +48,8 @@ export class ServiceFailureError extends Schema.TaggedError<ServiceFailureError> | 48 | 48 | safeMessage: Schema.String, | 49 | 49 | service: Schema.optional(Schema.String), | 50 | 50 | errorName: Schema.optional(Schema.String), | | 51 | + status: Schema.optional(Schema.Number), | | 52 | + retryAfterMs: Schema.optional(Schema.Number), | 51 | 53 | }) {} | 52 | 54 |
| 53 | 55 | export class ServerUnavailableError extends Schema.TaggedError<ServerUnavailableError>()( | @@ -91,7 +93,7 @@ export function toRequestError(error: Error): RequestError { | 91 | 93 | return RequestError.invalidParams({ sessionId: error.sessionId }, `session not found: ${error.sessionId}`) | 92 | 94 | case "ACPSessionDirectoryMismatchError": | 93 | 95 | return RequestError.invalidParams( | 94 | | - { sessionId: error.sessionId, cwd: error.cwd }, | | 96 | + { sessionId: error.sessionId, cwd: error.cwd, directory: error.directory }, | 95 | 97 | `session ${error.sessionId} does not belong to cwd: ${error.cwd}`, | 96 | 98 | ) | 97 | 99 | case "ACPInvalidConfigOptionError": | @@ -121,6 +123,8 @@ export function toRequestError(error: Error): RequestError { | 121 | 123 | { | 122 | 124 | ...(error.service ? { service: error.service } : {}), | 123 | 125 | ...(error.errorName ? { errorName: error.errorName } : {}), | | 126 | + ...(error.status !== undefined ? { status: error.status } : {}), | | 127 | + ...(error.retryAfterMs !== undefined ? { retryAfterMs: error.retryAfterMs } : {}), | 124 | 128 | }, | 125 | 129 | error.safeMessage, | 126 | 130 | ) | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/permission.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,7 +97,8 @@ export const withCompletedDiffs = Effect.fnUntraced(function* ( | 97 | 97 | const path = absolutePath(file.file, cwd) | 98 | 98 | const newText = file.status === "deleted" ? "" : yield* Effect.tryPromise(() => Bun.file(path).text()) | 99 | 99 | if (file.status === "added") return [diff(path, null, newText)] | 100 | | - const recorded = parsePatch(file.patch)[0] | | 100 | + // A file name with a newline breaks the patch header, and `parsePatch` throws on it. | | 101 | + const recorded = (yield* Effect.try(() => parsePatch(file.patch)))[0] | 101 | 102 | if (!recorded) return [] | 102 | 103 | const oldText = yield* Effect.try(() => applyPatch(newText, reversePatch(recorded))) | 103 | 104 | if (oldText !== false) return [diff(path, oldText, newText)] | @@ -109,7 +110,7 @@ export const withCompletedDiffs = Effect.fnUntraced(function* ( | 109 | 110 | return [] | 110 | 111 | const chunks = hunk.chunks.map((chunk) => ({ ...chunk, oldLines: chunk.newLines, newLines: chunk.oldLines })) | 111 | 112 | const rebuilt = (yield* Effect.try(() => Patch.derive(hunk.path, chunks, newText))).content | 112 | | - return ranges(structuredPatch(path, path, rebuilt, newText)) === ranges(recorded) | | 113 | + return ranges(yield* Effect.try(() => structuredPatch(path, path, rebuilt, newText))) === ranges(recorded) | 113 | 114 | ? [diff(path, rebuilt, newText)] | 114 | 115 | : [] | 115 | 116 | }).pipe(Effect.orElseSucceed((): Preview[] => [])), | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/prompt.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { ContentBlock } from "@agentclientprotocol/sdk" | 2 | 2 | import type { Command } from "@opencode/schema/command" | | 3 | +import type { Skill } from "@opencode/schema/skill" | 3 | 4 | import { SessionMessage } from "@opencode/schema/session-message" | 4 | 5 | import { Effect } from "effect" | 5 | 6 | import { access, constants } from "node:fs/promises" | @@ -16,6 +17,8 @@ export type Prepared = { | 16 | 17 | readonly synthetic: ReadonlyArray<string> | 17 | 18 | readonly slash?: { readonly name: string; readonly args: string } | 18 | 19 | readonly command?: Command.Info | | 20 | + /** A `/skill` prompt sends its text with the skill attached, as an `@skill` mention does elsewhere. */ | | 21 | + readonly skills: ReadonlyArray<{ readonly id: Skill.ID }> | 19 | 22 | } | 20 | 23 |
| 21 | 24 | export const prepare = Effect.fnUntraced(function* (catalog: Catalog, content: readonly ContentBlock[]) { | @@ -39,6 +42,7 @@ export const prepare = Effect.fnUntraced(function* (catalog: Catalog, content: r | 39 | 42 | synthetic: parts.flatMap((part) => (part.type === "text" && part.synthetic ? [part.text] : [])), | 40 | 43 | slash, | 41 | 44 | command: slash ? catalog.commands.find((item) => item.name === slash.name) : undefined, | | 45 | + skills: catalog.skills.flatMap((skill) => (skill.id === slash?.name ? [{ id: skill.id }] : [])), | 42 | 46 | } satisfies Prepared | 43 | 47 | }) | 44 | 48 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/acp/service.ts +24-3Lines changed: 24 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { OpenCodeClient } from "@opencode/client/effect" | | 2 | +import { Project } from "@opencode/schema/project" | 2 | 3 | import { AbsolutePath } from "@opencode/schema/schema" | 3 | 4 | import { Session } from "@opencode/schema/session" | 4 | 5 | import { FSUtil } from "@opencode/util/fs-util" | @@ -36,6 +37,7 @@ import type { | 36 | 37 | import { OPENCODE_VERSION } from "../version" | 37 | 38 | import { ACPCapabilities, type Capabilities } from "./capabilities" | 38 | 39 | import type { ACPCatalog } from "./catalog" | | 40 | +import { ACPChild } from "./child" | 39 | 41 | import { ACPClient } from "./client" | 40 | 42 | import { configOptions, resolveChange } from "./config-option" | 41 | 43 | import type { ACPConnection } from "./connection" | @@ -98,9 +100,17 @@ export function make(input: { | 98 | 100 | const getSession = Effect.fnUntraced(function* (sessionId: string, cwd: string) { | 99 | 101 | const sessionID = yield* ACPClient.decodeSessionID(sessionId) | 100 | 102 | const session = yield* input.client.session.get({ sessionID }).pipe(Effect.catch(ACPClient.classify)) | 101 | | - if (FSUtil.resolve(cwd) !== FSUtil.resolve(session.location.directory)) | 102 | | - return yield* new ACPError.SessionDirectoryMismatchError({ sessionId, cwd }) | 103 | | - return session | | 103 | + if (FSUtil.resolve(cwd) === FSUtil.resolve(session.location.directory)) return session | | 104 | + // A session moved into a worktree keeps the client's original cwd, which names the same project. | | 105 | + const location = yield* input.client.location | | 106 | + .get({ location: { directory: AbsolutePath.make(cwd) } }) | | 107 | + .pipe(Effect.catch(ACPClient.classify)) | | 108 | + if (location.project.id !== Project.ID.global && location.project.id === session.projectID) return session | | 109 | + return yield* new ACPError.SessionDirectoryMismatchError({ | | 110 | + sessionId, | | 111 | + cwd, | | 112 | + directory: session.location.directory, | | 113 | + }) | 104 | 114 | }) | 105 | 115 |
| 106 | 116 | // Clients often open a session and close it without prompting; closing removes those instead of keeping an empty session. | @@ -201,6 +211,17 @@ export function make(input: { | 201 | 211 | time: { created: DateTime.toEpochMillis(session.time.created) }, | 202 | 212 | }), | 203 | 213 | updatedAt: DateTime.formatIso(session.time.updated), | | 214 | + ...(session.parentID | | 215 | + ? { | | 216 | + _meta: { | | 217 | + [ACPChild.MetaKey]: { | | 218 | + id: session.id, | | 219 | + parentID: session.parentID, | | 220 | + ...(session.title ? { title: session.title } : {}), | | 221 | + }, | | 222 | + }, | | 223 | + } | | 224 | + : {}), | 204 | 225 | } | 205 | 226 | }), | 206 | 227 | ...(page.cursor.next ? { nextCursor: page.cursor.next } : {}), | |
|