Skip to content

Commit cb07d5f

Browse files
committed
fix(core): keep session move errors typed
1 parent 583c48d commit cb07d5f

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

‎packages/core/src/tool/plugin/opencode.ts‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,29 @@ import type { Context } from "@opencode/plugin/effect/plugin"
55
import type { SessionHooks } from "@opencode/plugin/effect/session"
66
import { Model } from "@opencode/schema/model"
77
import { AbsolutePath } from "@opencode/schema/schema"
8-
import { Session } from "@opencode/schema/session"
98
import { Effect, Schema } from "effect"
109
import { FileAccess } from "../../file-access.js"
1110
import { Git } from "../../git.js"
1211
import { Permission } from "../../permission.js"
13-
import { SessionErrors } from "../../session/error.js"
14-
import { SessionMove } from "../../session/move.js"
12+
import { Session } from "../../session.js"
13+
import { SessionSchema } from "../../session/schema.js"
1514
import { Worktree } from "../../worktree.js"
1615

1716
export const RenameInput = Schema.Struct({
18-
sessionID: Schema.optionalKey(Session.ID).annotate({ description: "Omit to rename the current session." }),
17+
sessionID: Schema.optionalKey(SessionSchema.ID).annotate({ description: "Omit to rename the current session." }),
1918
title: Schema.String.check(Schema.isMinLength(1)).annotate({ description: "New session title." }),
2019
})
2120

22-
const RenameOutput = Schema.Struct({ sessionID: Session.ID, title: Schema.String })
21+
const RenameOutput = Schema.Struct({ sessionID: SessionSchema.ID, title: Schema.String })
2322

2423
export const MoveInput = Schema.Struct({
25-
sessionID: Schema.optionalKey(Session.ID).annotate({ description: "Omit to move the current session." }),
24+
sessionID: Schema.optionalKey(SessionSchema.ID).annotate({ description: "Omit to move the current session." }),
2625
directory: AbsolutePath.check(Schema.isMinLength(1)).annotate({
2726
description: "Destination directory, relative to the target session's directory or absolute. Supports ~.",
2827
}),
2928
})
3029

31-
const MoveOutput = Schema.Struct({ sessionID: Session.ID, directory: AbsolutePath })
30+
const MoveOutput = Schema.Struct({ sessionID: SessionSchema.ID, directory: AbsolutePath })
3231

3332
export const WorktreeCreateInput = Schema.Struct({
3433
name: Schema.Trim.check(Schema.isNonEmpty()).annotate({ description: "Worktree name." }),
@@ -91,11 +90,12 @@ export const Plugin = {
9190
effect: Effect.fn("OpenCodeTools.Plugin")(function* (ctx: Context) {
9291
const access = yield* FileAccess.Service
9392
const permission = yield* Permission.Service
93+
const sessions = yield* Session.Service
9494
const hook = (event: SessionHooks["context"]) =>
9595
Effect.sync(() => {
9696
event.system.push(
9797
SystemPart.make(
98-
"When you create a worktree outside the current working directory and intend to use it as your primary working directory, wait for the command creating it to finish before using `execute` to call `tools.opencode.session_move`.",
98+
"When you create a worktree outside the current working directory and intend to use it as your primary working directory, consider using `execute` to call `tools.opencode.session_move` to make the worktree the session's working directory after the command creating it has finished.",
9999
),
100100
)
101101
})
@@ -139,7 +139,7 @@ export const Plugin = {
139139
execute: (input, context) =>
140140
Effect.gen(function* () {
141141
const sessionID = input.sessionID ?? context.sessionID
142-
yield* ctx.session.move({
142+
yield* sessions.move({
143143
sessionID,
144144
directory: input.directory,
145145
delivery: "steer",
@@ -149,21 +149,18 @@ export const Plugin = {
149149
content: `Moved session ${sessionID} to ${input.directory}.`,
150150
}
151151
}).pipe(
152-
Effect.catch((error) => {
153-
if (error instanceof SessionErrors.NotFoundError)
154-
return Effect.fail(new ToolFailure({ message: `Session not found: ${error.sessionID}`, error }))
155-
if (error instanceof SessionMove.DestinationNotFoundError)
156-
return Effect.fail(
157-
new ToolFailure({ message: `Directory does not exist: ${error.directory}`, error }),
158-
)
159-
if (error instanceof SessionMove.DestinationNotDirectoryError)
160-
return Effect.fail(new ToolFailure({ message: `Not a directory: ${error.directory}`, error }))
161-
if (error instanceof SessionMove.DestinationUnavailableError)
162-
return Effect.fail(
163-
new ToolFailure({ message: `Directory is unavailable: ${error.directory}`, error }),
164-
)
165-
return Effect.die(error)
166-
}),
152+
Effect.catchTag("Session.NotFoundError", (error) =>
153+
Effect.fail(new ToolFailure({ message: `Session not found: ${error.sessionID}`, error })),
154+
),
155+
Effect.catchTag("Session.DestinationNotFoundError", (error) =>
156+
Effect.fail(new ToolFailure({ message: `Directory does not exist: ${error.directory}`, error })),
157+
),
158+
Effect.catchTag("Session.DestinationNotDirectoryError", (error) =>
159+
Effect.fail(new ToolFailure({ message: `Not a directory: ${error.directory}`, error })),
160+
),
161+
Effect.catchTag("Session.DestinationUnavailableError", (error) =>
162+
Effect.fail(new ToolFailure({ message: `Directory is unavailable: ${error.directory}`, error })),
163+
),
167164
),
168165
})
169166
draft.add({

0 commit comments

Comments
 (0)