fix(core): allow reads of registered skill resources by kitlangton · Pull Request #47554 · anomalyco/opencode · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/core/src/permission.ts
27 changes: 20 additions & 7 deletions packages/core/src/tool/plugin/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SessionInstructions } from "../../session/instructions.js"
import { AbsolutePath } from "../../schema.js"
import { ReadToolFileSystem } from "../read-filesystem.js"
import { Environment } from "../../environment/index.js"
import { Skill } from "../../skill.js"

export const name = "read"
const FILENAME = "AGENTS.md"
Expand All @@ -36,6 +37,7 @@ export const Plugin = {
const sessionInstructions = yield* SessionInstructions.Service
const fs = yield* FSUtil.Service
const location = yield* Location.Service
const skills = yield* Skill.Service

yield* ctx.tool
.transform((editor) =>
Expand All @@ -55,13 +57,24 @@ export const Plugin = {
}
const authorize = (target: LocationMutation.Target, authorizeExternal = true) =>
Effect.gen(function* () {
if (target.externalDirectory && authorizeExternal)
yield* permission.assert({
...LocationMutation.externalDirectoryPermission(target.externalDirectory),
sessionID: context.sessionID,
agent: context.agent,
source,
})
if (target.externalDirectory && authorizeExternal) {
// Directory skills advertise supporting paths outside the project.
// Authorize only this read's boundary, not edits or shell access there.
const supporting = (yield* skills.list()).some(
(skill) =>
basename(skill.location) === "SKILL.md" &&
FSUtil.contains(dirname(skill.location), target.absolute),
)
yield* permission.assert(
{
...LocationMutation.externalDirectoryPermission(target.externalDirectory),
sessionID: context.sessionID,
agent: context.agent,
source,
},
supporting ? [target.externalDirectory.resource] : undefined,
)
}
yield* permission.assert({
action: name,
resources: [target.resource],
Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/session-instructions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from "fs/promises"
import path from "path"
import { DateTime, Effect, Layer } from "effect"
import { Agent } from "@opencode-ai/core/agent"
import { Skill } from "@opencode-ai/core/skill"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
import { LayerNode } from "@opencode-ai/util/effect/layer-node"
import { Config } from "@opencode-ai/core/config"
Expand Down Expand Up @@ -40,6 +41,7 @@ const readToolNode = makeLocationNode({
name: "test/read-tool-plugin",
layer: Layer.effectDiscard(registerToolPlugin(ReadTool.Plugin)),
deps: [
Skill.node,
Tool.node,
ReadToolFileSystem.node,
LocationMutation.node,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/tool-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { beforeEach, describe, expect } from "bun:test"
import path from "path"
import { Effect, Exit, Layer } from "effect"
import { Config } from "@opencode-ai/core/config"
import { Skill } from "@opencode-ai/core/skill"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
import { LayerNode } from "@opencode-ai/util/effect/layer-node"
import { FileSystem } from "@opencode-ai/core/filesystem"
Expand All @@ -28,6 +29,7 @@ const readToolNode = makeLocationNode({
name: "test/read-tool-plugin",
layer: Layer.effectDiscard(registerToolPlugin(ReadTool.Plugin)),
deps: [
Skill.node,
Tool.node,
ReadToolFileSystem.node,
LocationMutation.node,
Expand Down
253 changes: 253 additions & 0 deletions packages/core/test/tool-skill-resource.test.ts
Loading