(file: { directory: string; filepath: string; primary: boolean }, content: string)
| 114 | } |
| 115 | |
| 116 | function 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 | } |
no outgoing calls
no test coverage detected