GeezerVison is showing github.com — feat(core): add project reference guidance (#31601) · c0debrain/opencode@8a2cfc0
File treeExpand file treeCollapse file tree Open diff view settings server/routes/instance/httpapi/handlers
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .opencode/opencode.jsonc +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | "$schema": "https://opencode.ai/config.json", | 3 | 3 | "provider": {}, | 4 | 4 | "permission": {}, | 5 | | - "reference": { | 6 | | - "effect": "github.com/Effect-TS/effect-smol", | | 5 | + "references": { | | 6 | + "effect": { | | 7 | + "repository": "github.com/Effect-TS/effect-smol", | | 8 | + "description": "Use for Effect v4 and effect-smol implementation details", | | 9 | + }, | | 10 | + "opencode-local": { | | 11 | + "path": "~/.local/share/opencode", | | 12 | + "description": "Contains opencode logs and data", | | 13 | + }, | 7 | 14 | }, | 8 | 15 | "mcp": {}, | 9 | 16 | "tools": { | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/config/plugin/reference.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,11 +33,15 @@ export const Plugin = { | 33 | 33 | path: AbsolutePath.make( | 34 | 34 | localPath(directory, global.home, typeof entry === "string" ? entry : entry.path), | 35 | 35 | ), | | 36 | + description: typeof entry === "string" ? undefined : entry.description, | | 37 | + hidden: typeof entry === "string" ? undefined : entry.hidden, | 36 | 38 | }) | 37 | 39 | : new Reference.GitSource({ | 38 | 40 | type: "git", | 39 | 41 | repository: typeof entry === "string" ? entry : entry.repository, | 40 | 42 | branch: typeof entry === "string" ? undefined : entry.branch, | | 43 | + description: typeof entry === "string" ? undefined : entry.description, | | 44 | + hidden: typeof entry === "string" ? undefined : entry.hidden, | 41 | 45 | }), | 42 | 46 | ) | 43 | 47 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/config/reference.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,10 +5,14 @@ import { Schema } from "effect" | 5 | 5 | export class Git extends Schema.Class<Git>("ConfigV2.Reference.Git")({ | 6 | 6 | repository: Schema.String, | 7 | 7 | branch: Schema.String.pipe(Schema.optional), | | 8 | + description: Schema.String.pipe(Schema.optional), | | 9 | + hidden: Schema.Boolean.pipe(Schema.optional), | 8 | 10 | }) {} | 9 | 11 |
| 10 | 12 | export class Local extends Schema.Class<Local>("ConfigV2.Reference.Local")({ | 11 | 13 | path: Schema.String, | | 14 | + description: Schema.String.pipe(Schema.optional), | | 15 | + hidden: Schema.Boolean.pipe(Schema.optional), | 12 | 16 | }) {} | 13 | 17 |
| 14 | 18 | export const Entry = Schema.Union([Schema.String, Git, Local]) | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/location-layer.ts +20-4Lines changed: 20 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { Layer, LayerMap } from "effect" | | 1 | +import { Effect, Layer, LayerMap } from "effect" | 2 | 2 | import { Location } from "./location" | 3 | 3 | import { Policy } from "./policy" | 4 | 4 | import { Config } from "./config" | @@ -23,6 +23,7 @@ import { Watcher } from "./filesystem/watcher" | 23 | 23 | import { LocationMutation } from "./location-mutation" | 24 | 24 | import { FileMutation } from "./file-mutation" | 25 | 25 | import { Reference } from "./reference" | | 26 | +import { ReferenceGuidance } from "./reference/guidance" | 26 | 27 | import { RepositoryCache } from "./repository-cache" | 27 | 28 | import { Pty } from "./pty" | 28 | 29 | import { SkillV2 } from "./skill" | @@ -45,6 +46,9 @@ import { FetchHttpClient } from "effect/unstable/http" | 45 | 46 |
| 46 | 47 | export class LocationServiceMap extends LayerMap.Service<LocationServiceMap>()("@opencode/example/LocationServiceMap", { | 47 | 48 | lookup: (ref: Location.Ref) => { | | 49 | + const boot = Layer.effectDiscard( | | 50 | + Effect.logInfo("booting location services", { directory: ref.directory, workspaceID: ref.workspaceID }), | | 51 | + ) | 48 | 52 | const location = Location.layer(ref) | 49 | 53 | const systemContext = SystemContextBuiltIns.locationLayer | 50 | 54 | const base = Layer.mergeAll( | @@ -74,6 +78,7 @@ export class LocationServiceMap extends LayerMap.Service<LocationServiceMap>()(" | 74 | 78 | const image = Image.layer.pipe(Layer.provide(services)) | 75 | 79 | const mutation = FileMutation.locationLayer.pipe(Layer.provide(services)) | 76 | 80 | const skillGuidance = SkillGuidance.locationLayer.pipe(Layer.provide(services)) | | 81 | + const referenceGuidance = ReferenceGuidance.locationLayer.pipe(Layer.provide(services)) | 77 | 82 | const todos = SessionTodo.layer.pipe(Layer.provide(services)) | 78 | 83 | const questions = QuestionV2.locationLayer.pipe(Layer.provide(services)) | 79 | 84 | const builtInTools = BuiltInTools.locationLayer.pipe( | @@ -89,10 +94,21 @@ export class LocationServiceMap extends LayerMap.Service<LocationServiceMap>()(" | 89 | 94 | Layer.provide(services), | 90 | 95 | Layer.provide(model), | 91 | 96 | Layer.provide(skillGuidance), | | 97 | + Layer.provide(referenceGuidance), | 92 | 98 | ) | 93 | | - return Layer.mergeAll(services, image, mutation, resources, todos, questions, model, runner, builtInTools).pipe( | 94 | | - Layer.fresh, | 95 | | - ) | | 99 | + return Layer.mergeAll( | | 100 | + boot, | | 101 | + services, | | 102 | + image, | | 103 | + mutation, | | 104 | + resources, | | 105 | + todos, | | 106 | + questions, | | 107 | + model, | | 108 | + runner, | | 109 | + builtInTools, | | 110 | + referenceGuidance, | | 111 | + ).pipe(Layer.fresh) | 96 | 112 | }, | 97 | 113 | idleTimeToLive: "60 minutes", | 98 | 114 | dependencies: [ | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/location.ts +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,11 +5,10 @@ import { WorkspaceV2 } from "./workspace" | 5 | 5 |
| 6 | 6 | export * as Location from "./location" | 7 | 7 |
| 8 | | -export const Ref = Schema.Struct({ | | 8 | +export class Ref extends Schema.Class<Ref>("Location.Ref")({ | 9 | 9 | directory: AbsolutePath, | 10 | | - workspaceID: Schema.optional(WorkspaceV2.ID), | 11 | | -}).annotate({ identifier: "Location.Ref" }) | 12 | | -export type Ref = typeof Ref.Type | | 10 | + workspaceID: Schema.optional(WorkspaceV2.ID).pipe(Schema.withConstructorDefault(Effect.succeed(undefined))), | | 11 | +}) {} | 13 | 12 |
| 14 | 13 | export class Info extends Schema.Class<Info>("Location.Info")({ | 15 | 14 | directory: AbsolutePath, | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/plugin/skill/customize-opencode.md +46Lines changed: 46 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -73,6 +73,19 @@ Every field is optional. | 73 | 73 | "urls": ["https://example.com/.well-known/skills/"] | 74 | 74 | }, | 75 | 75 |
| | 76 | + "references": { | | 77 | + "docs": { | | 78 | + "path": "../docs", | | 79 | + "description": "Use for product behavior and documentation conventions" | | 80 | + }, | | 81 | + "sdk": { | | 82 | + "repository": "owner/sdk", | | 83 | + "branch": "main", | | 84 | + "description": "Use for SDK implementation details", | | 85 | + "hidden": true | | 86 | + } | | 87 | + }, | | 88 | + | 76 | 89 | "agent": { | 77 | 90 | "my-agent": { | 78 | 91 | "model": "anthropic/claude-sonnet-4-6", | @@ -136,6 +149,7 @@ Shape notes worth being explicit about: | 136 | 149 |
| 137 | 150 | - `model` always carries a provider prefix: `"anthropic/claude-sonnet-4-6"`. | 138 | 151 | - `skills` is an object with `paths` and/or `urls`, not an array. | | 152 | +- `references` is an object keyed by alias. Each value is a local path, Git repository, or string shorthand. | 139 | 153 | - `agent` is an object keyed by agent name, not an array. | 140 | 154 | - `plugin` is an array of strings or `[name, options]` tuples, not an object. | 141 | 155 | - `mcp[name].command` is an array of strings, never a single string. `type` is required. | @@ -172,6 +186,38 @@ Register skills from non-default locations via `skills.paths` (scanned | 172 | 186 | recursively for `**/SKILL.md`) and `skills.urls` (each URL serves a list of | 173 | 187 | skills). | 174 | 188 |
| | 189 | +## References | | 190 | + | | 191 | +References make local directories and Git repositories outside the active | | 192 | +project available as supporting context. Configure them under `references`, | | 193 | +keyed by the alias used in `@` autocomplete: | | 194 | + | | 195 | +```json | | 196 | +{ | | 197 | + "references": { | | 198 | + "docs": { | | 199 | + "path": "../product-docs", | | 200 | + "description": "Use for product behavior and terminology" | | 201 | + }, | | 202 | + "effect": { | | 203 | + "repository": "Effect-TS/effect", | | 204 | + "branch": "main", | | 205 | + "description": "Use for Effect implementation details" | | 206 | + } | | 207 | + } | | 208 | +} | | 209 | +``` | | 210 | + | | 211 | +Local `path` values may be relative to the declaring config, absolute, or use | | 212 | +`~/`. Git `repository` values accept Git URLs, host/path references, and GitHub | | 213 | +`owner/repo` shorthand; `branch` is optional. Both forms support optional | | 214 | +`description` and `hidden` fields. | | 215 | + | | 216 | +- Only references with a `description` are advertised to agents in system context. | | 217 | +- `hidden: true` removes a reference from TUI `@` autocomplete only. It remains available to agents and by direct path. | | 218 | +- Reference directories are automatically allowed through the external-directory boundary; normal read/edit/tool permissions still apply. | | 219 | +- String shorthand is supported: use `"docs": "../docs"` for local paths or `"effect": "Effect-TS/effect"` for Git repositories. | | 220 | + | 175 | 221 | ## Agents | 176 | 222 |
| 177 | 223 | Two ways to define an agent. Use the file form for anything non-trivial. | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/reference.ts +32-8Lines changed: 32 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,21 +9,19 @@ import { RepositoryCache } from "./repository-cache" | 9 | 9 | import { AbsolutePath } from "./schema" | 10 | 10 | import { State } from "./state" | 11 | 11 |
| 12 | | -export class Info extends Schema.Class<Info>("Reference.Info")({ | 13 | | - name: Schema.String, | 14 | | - path: AbsolutePath, | 15 | | - source: Schema.suspend(() => Source), | 16 | | -}) {} | 17 | | - | 18 | 12 | export class LocalSource extends Schema.Class<LocalSource>("Reference.LocalSource")({ | 19 | 13 | type: Schema.Literal("local"), | 20 | 14 | path: AbsolutePath, | | 15 | + description: Schema.String.pipe(Schema.optional), | | 16 | + hidden: Schema.Boolean.pipe(Schema.optional), | 21 | 17 | }) {} | 22 | 18 |
| 23 | 19 | export class GitSource extends Schema.Class<GitSource>("Reference.GitSource")({ | 24 | 20 | type: Schema.Literal("git"), | 25 | 21 | repository: Schema.String, | 26 | 22 | branch: Schema.String.pipe(Schema.optional), | | 23 | + description: Schema.String.pipe(Schema.optional), | | 24 | + hidden: Schema.Boolean.pipe(Schema.optional), | 27 | 25 | }) {} | 28 | 26 |
| 29 | 27 | export const Source = Schema.Union([LocalSource, GitSource]).pipe(Schema.toTaggedUnion("type")) | @@ -33,6 +31,14 @@ export const Event = { | 33 | 31 | Updated: EventV2.define({ type: "reference.updated", schema: {} }), | 34 | 32 | } | 35 | 33 |
| | 34 | +export class Info extends Schema.Class<Info>("Reference.Info")({ | | 35 | + name: Schema.String, | | 36 | + path: AbsolutePath, | | 37 | + description: Schema.String.pipe(Schema.optional), | | 38 | + hidden: Schema.Boolean.pipe(Schema.optional), | | 39 | + source: Source, | | 40 | +}) {} | | 41 | + | 36 | 42 | type Data = { | 37 | 43 | sources: Map<string, Source> | 38 | 44 | } | @@ -71,7 +77,16 @@ export const layer = Layer.effect( | 71 | 77 | const seen = new Map<string, string | undefined>() | 72 | 78 | for (const [name, source] of editor.list()) { | 73 | 79 | if (source.type === "local") { | 74 | | - materialized.set(name, new Info({ name, path: source.path, source })) | | 80 | + materialized.set( | | 81 | + name, | | 82 | + new Info({ | | 83 | + name, | | 84 | + path: source.path, | | 85 | + description: source.description, | | 86 | + hidden: source.hidden, | | 87 | + source, | | 88 | + }), | | 89 | + ) | 75 | 90 | continue | 76 | 91 | } | 77 | 92 | const repository = Repository.parse(source.repository) | @@ -86,7 +101,16 @@ export const layer = Layer.effect( | 86 | 101 | const target = Repository.cachePath(global.repos, repository) | 87 | 102 | if (seen.has(target) && seen.get(target) !== source.branch) continue | 88 | 103 | seen.set(target, source.branch) | 89 | | - materialized.set(name, new Info({ name, path: AbsolutePath.make(target), source })) | | 104 | + materialized.set( | | 105 | + name, | | 106 | + new Info({ | | 107 | + name, | | 108 | + path: AbsolutePath.make(target), | | 109 | + description: source.description, | | 110 | + hidden: source.hidden, | | 111 | + source, | | 112 | + }), | | 113 | + ) | 90 | 114 | yield* cache.ensure({ reference: repository, branch: source.branch, refresh: true }).pipe( | 91 | 115 | Effect.catchCause((cause) => | 92 | 116 | Effect.logWarning("failed to materialize reference", { | |
Collapse file Copy file name to clipboard +69Lines changed: 69 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +export * as ReferenceGuidance from "./guidance" | | 2 | + | | 3 | +import { Context, Effect, Layer, Schema } from "effect" | | 4 | +import { PluginBoot } from "../plugin/boot" | | 5 | +import { Reference } from "../reference" | | 6 | +import { SystemContext } from "../system-context/index" | | 7 | + | | 8 | +const Summary = Schema.Struct({ | | 9 | + name: Schema.String, | | 10 | + path: Schema.String, | | 11 | + description: Schema.String.pipe(Schema.optional), | | 12 | +}) | | 13 | + | | 14 | +const render = (references: ReadonlyArray<typeof Summary.Type>) => | | 15 | + [ | | 16 | + "Project references provide additional directories that can be accessed when relevant.", | | 17 | + "<available_references>", | | 18 | + ...references.flatMap((reference) => [ | | 19 | + " <reference>", | | 20 | + ` <name>${reference.name}</name>`, | | 21 | + ` <path>${reference.path}</path>`, | | 22 | + ...(reference.description === undefined ? [] : [` <description>${reference.description}</description>`]), | | 23 | + " </reference>", | | 24 | + ]), | | 25 | + "</available_references>", | | 26 | + ].join("\n") | | 27 | + | | 28 | +export interface Interface { | | 29 | + readonly load: () => Effect.Effect<SystemContext.SystemContext> | | 30 | +} | | 31 | + | | 32 | +export class Service extends Context.Service<Service, Interface>()("@opencode/v2/ReferenceGuidance") {} | | 33 | + | | 34 | +export const layer = Layer.effect( | | 35 | + Service, | | 36 | + Effect.gen(function* () { | | 37 | + const boot = yield* PluginBoot.Service | | 38 | + const references = yield* Reference.Service | | 39 | + | | 40 | + return Service.of({ | | 41 | + load: Effect.fn("ReferenceGuidance.load")(function* () { | | 42 | + yield* boot.wait() | | 43 | + const available = (yield* references.list()) | | 44 | + .filter((reference) => reference.description !== undefined) | | 45 | + .map((reference) => ({ | | 46 | + name: reference.name, | | 47 | + path: reference.path, | | 48 | + description: reference.description, | | 49 | + })) | | 50 | + .toSorted((a, b) => a.name.localeCompare(b.name)) | | 51 | + if (available.length === 0) return SystemContext.empty | | 52 | + return SystemContext.make({ | | 53 | + key: SystemContext.Key.make("core/reference-guidance"), | | 54 | + codec: Schema.toCodecJson(Schema.Array(Summary)), | | 55 | + load: Effect.succeed(available), | | 56 | + baseline: render, | | 57 | + update: (_previous, current) => | | 58 | + [ | | 59 | + "The available project references have changed. This list supersedes the previous reference list.", | | 60 | + render(current), | | 61 | + ].join("\n"), | | 62 | + removed: () => "Project reference guidance is no longer available. Do not use previously listed references.", | | 63 | + }) | | 64 | + }), | | 65 | + }) | | 66 | + }), | | 67 | +) | | 68 | + | | 69 | +export const locationLayer = layer |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/ripgrep.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -161,10 +161,10 @@ export const layer = Layer.effect( | 161 | 161 | args: [ | 162 | 162 | "--no-config", | 163 | 163 | "--files", | 164 | | - "--glob=!**/.git/**", | 165 | 164 | ...(input.hidden ? ["--hidden"] : []), | 166 | 165 | ...(input.follow ? ["--follow"] : []), | 167 | 166 | `--glob=${input.pattern}`, | | 167 | + "--glob=!**/.git/**", | 168 | 168 | ".", | 169 | 169 | ], | 170 | 170 | parse: (line) => | @@ -195,10 +195,10 @@ export const layer = Layer.effect( | 195 | 195 | args: [ | 196 | 196 | "--no-config", | 197 | 197 | "--files", | 198 | | - "--glob=!**/.git/**", | 199 | 198 | ...(input.hidden ? ["--hidden"] : []), | 200 | 199 | ...(input.follow ? ["--follow"] : []), | 201 | | - `--glob=${input.pattern}`, | | 200 | + ...(input.pattern === "*" ? [] : [`--glob=${input.pattern}`]), | | 201 | + "--glob=!**/.git/**", | 202 | 202 | ".", | 203 | 203 | ], | 204 | 204 | parse: (line) => { | @@ -226,9 +226,9 @@ export const layer = Layer.effect( | 226 | 226 | "--no-config", | 227 | 227 | "--json", | 228 | 228 | "--hidden", | 229 | | - "--glob=!**/.git/**", | 230 | 229 | "--no-messages", | 231 | 230 | ...(input.include ? [`--glob=${input.include}`] : []), | | 231 | + "--glob=!**/.git/**", | 232 | 232 | "--", | 233 | 233 | input.pattern, | 234 | 234 | input.file ?? ".", | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/session/runner/llm.ts +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ import { QuestionV2 } from "../../question" | 19 | 19 | import { SystemContext } from "../../system-context/index" | 20 | 20 | import { SystemContextRegistry } from "../../system-context/registry" | 21 | 21 | import { SkillGuidance } from "../../skill/guidance" | | 22 | +import { ReferenceGuidance } from "../../reference/guidance" | 22 | 23 | import { ToolRegistry } from "../../tool/registry" | 23 | 24 | import { ToolOutputStore } from "../../tool-output-store" | 24 | 25 | import { SessionContextEpoch } from "../context-epoch" | @@ -98,6 +99,7 @@ export const layer = Layer.effect( | 98 | 99 | const location = yield* Location.Service | 99 | 100 | const systemContext = yield* SystemContextRegistry.Service | 100 | 101 | const skillGuidance = yield* SkillGuidance.Service | | 102 | + const referenceGuidance = yield* ReferenceGuidance.Service | 101 | 103 | const config = yield* Config.Service | 102 | 104 | const db = (yield* Database.Service).db | 103 | 105 | const compaction = SessionCompaction.make({ events, llm, config: yield* config.entries() }) | @@ -166,9 +168,9 @@ export const layer = Layer.effect( | 166 | 168 |
| 167 | 169 | const sameModel = Schema.toEquivalence(Schema.UndefinedOr(ModelV2.Ref)) | 168 | 170 | const loadSystemContext = (agent: AgentV2.Selection) => | 169 | | - Effect.all([systemContext.load(), skillGuidance.load(agent)], { concurrency: "unbounded" }).pipe( | 170 | | - Effect.map(SystemContext.combine), | 171 | | - ) | | 171 | + Effect.all([systemContext.load(), skillGuidance.load(agent), referenceGuidance.load()], { | | 172 | + concurrency: "unbounded", | | 173 | + }).pipe(Effect.map(SystemContext.combine)) | 172 | 174 |
| 173 | 175 | const runTurnAttempt = Effect.fn("SessionRunner.runTurn")(function* ( | 174 | 176 | sessionID: SessionSchema.ID, | |
|