forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
This feature adds inheritance support to Markdown-based agent definitions in Opencode, allowing agents to extend and override parent agents.
Context
packages/opencode/src/config/config.ts:203-244currently loads Markdown-Based agent definitions but only builds flat objects; nested folders simply prefix the agent name. There is no notion of inheritance between agent files.packages/opencode/src/config/config.ts:348-370defines theAgentzod schema without anextendsfield, so frontmatter cannot declare parentage.packages/opencode/src/agent/agent.ts:97-172merges built-in agents with user-defined entries. This would be the point where resolved inheritance chains need to be flattened into the final runtimeAgent.Infomap.packages/opencode/src/config/markdown.ts:6-32holds the existing path token logic (@references) used elsewhere for file/wiki-like references; a similar resolver (but using[[wiki/style]]tokens with shortest-unique paths) is needed for the newextendssyntax.
Requirements
- Support an optional
extendsfrontmatter field inside agent Markdown files. The value uses wiki-link syntax ([[agent-path]]) that should resolve to another agent file. - Path resolution must allow referencing agents by the shortest unique suffix (e.g.,
[[auth]],[[nested/auth]]). When two different folders containauth.md, automatically expand the link to the minimal path segments needed to uniquely identify the target, similar to Obsidian-style wiki links. - When
extendsis present, the child agent inherits all prompt content, metadata, permissions, tools, and options from the referenced parent unless explicitly overridden in the child file. Circular references must be detected and reported as a configuration error. - Update runtime agent assembly so inherited properties are merged before
Agent.Infoobjects are consumed by the TUI, commands, or SDK consumers. Ensuredisable: truestill removes agents even if other agents attempt to extend them. - Document the new capability (docs page + sample snippet) and add automated tests (unit tests in
packages/opencode/test/config) that cover successful inheritance, conflict resolution when duplicates exist, and error cases for unresolved/ambiguous wiki links.
Definition of Done
- Agent schema validates
extendsvalues and errors with helpful messages for invalid wiki links or circular parentage. - Wiki-link resolver can find any agent Markdown file via the shortest unambiguous
[[path]], even when duplicate filenames exist under different folders. - Child agent inherits parent settings and prompt text before being exposed through
Agent.list()/ CLI UI; overrides replace the inherited values as expected. - Comprehensive tests cover resolver behavior, inheritance merging, and failure paths, and all existing tests continue to pass.
- Documentation (docs + changelog/README snippet if applicable) explains how to declare
extends: [[agent-name]]and how conflicts are handled.
Implementation Files Referenced
packages/opencode/src/config/config.ts:203-244packages/opencode/src/config/config.ts:348-370packages/opencode/src/agent/agent.ts:97-172packages/opencode/src/config/markdown.ts:6-32
Metadata
Metadata
Assignees
Labels
No labels