MCPcopy Index your code
hub / github.com/anomalyco/opencode / decode

Function decode

packages/core/src/config/plugin/agent.ts:116–142  ·  view source on GitHub ↗
(file: { directory: string; filepath: string; primary: boolean }, content: string)

Source from the content-addressed store, hash-verified

114}
115
116function decode(file: { directory: string; filepath: string; primary: boolean }, content: string) {
117 const markdown = ConfigMarkdown.parseOption(content)
118 if (!markdown) return
119 const name = path
120 .relative(file.directory, file.filepath)
121 .replaceAll("\\", "/")
122 .replace(/^(agent|agents|mode|modes)\//, "")
123 .replace(/\.md$/, "")
124 const body = markdown.content.trim()
125 const legacy = Object.keys(markdown.data).some((key) => !agentKeys.has(key))
126 const agent = Option.getOrUndefined(
127 legacy
128 ? Option.map(
129 decodeLegacyAgent({ name, ...markdown.data, prompt: body }, { errors: "all", propertyOrder: "original" }),
130 ConfigMigrateV1.migrateAgent,
131 )
132 : decodeAgent({ ...markdown.data, system: body }, { errors: "all", propertyOrder: "original" }),
133 )
134 if (!agent) return
135 const info = Option.getOrUndefined(
136 decodeConfig({
137 agents: { [name]: file.primary ? { ...agent, mode: "primary" } : agent },
138 }),
139 )
140 if (!info) return
141 return new Config.Document({ type: "document", path: file.filepath, info })
142}

Callers 4

agent.tsFile · 0.70
decodeMessageRowFunction · 0.50
revert.tsFile · 0.50
makeFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected