roast-ai 0.4.10 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/commands/docs/write-comments.md +36 -0
  3. data/.github/CODEOWNERS +1 -1
  4. data/.github/workflows/ci.yaml +10 -6
  5. data/.gitignore +0 -1
  6. data/.rubocop.yml +7 -1
  7. data/.ruby-version +1 -1
  8. data/CLAUDE.md +2 -2
  9. data/CONTRIBUTING.md +2 -0
  10. data/Gemfile +19 -18
  11. data/Gemfile.lock +35 -58
  12. data/README.md +118 -1432
  13. data/README_LEGACY.md +1464 -0
  14. data/Rakefile +39 -4
  15. data/dev.yml +29 -0
  16. data/dsl/agent_sessions.rb +20 -0
  17. data/dsl/async_cogs.rb +49 -0
  18. data/dsl/async_cogs_complex.rb +67 -0
  19. data/dsl/call.rb +44 -0
  20. data/dsl/collect_from.rb +72 -0
  21. data/dsl/json_output.rb +28 -0
  22. data/dsl/map.rb +55 -0
  23. data/dsl/map_reduce.rb +37 -0
  24. data/dsl/map_with_index.rb +49 -0
  25. data/dsl/next_break.rb +45 -0
  26. data/dsl/next_break_parallel.rb +44 -0
  27. data/dsl/outputs.rb +39 -0
  28. data/dsl/outputs_bang.rb +36 -0
  29. data/dsl/parallel_map.rb +37 -0
  30. data/dsl/prompts/simple_prompt.md.erb +3 -0
  31. data/dsl/prototype.rb +5 -7
  32. data/dsl/repeat_loop_results.rb +53 -0
  33. data/dsl/ruby_cog.rb +72 -0
  34. data/dsl/simple_agent.rb +18 -0
  35. data/dsl/simple_chat.rb +15 -1
  36. data/dsl/simple_repeat.rb +29 -0
  37. data/dsl/skip.rb +36 -0
  38. data/dsl/step_communication.rb +2 -3
  39. data/dsl/targets_and_params.rb +57 -0
  40. data/dsl/temperature.rb +17 -0
  41. data/dsl/temporary_directory.rb +22 -0
  42. data/dsl/tutorial/01_your_first_workflow/README.md +179 -0
  43. data/dsl/tutorial/01_your_first_workflow/configured_chat.rb +33 -0
  44. data/dsl/tutorial/01_your_first_workflow/hello.rb +23 -0
  45. data/dsl/tutorial/02_chaining_cogs/README.md +310 -0
  46. data/dsl/tutorial/02_chaining_cogs/code_review.rb +104 -0
  47. data/dsl/tutorial/02_chaining_cogs/session_resumption.rb +92 -0
  48. data/dsl/tutorial/02_chaining_cogs/simple_chain.rb +84 -0
  49. data/dsl/tutorial/03_targets_and_params/README.md +230 -0
  50. data/dsl/tutorial/03_targets_and_params/multiple_targets.rb +65 -0
  51. data/dsl/tutorial/03_targets_and_params/single_target.rb +65 -0
  52. data/dsl/tutorial/04_configuration_options/README.md +209 -0
  53. data/dsl/tutorial/04_configuration_options/control_display_and_temperature.rb +104 -0
  54. data/dsl/tutorial/04_configuration_options/simple_config.rb +68 -0
  55. data/dsl/tutorial/05_control_flow/README.md +156 -0
  56. data/dsl/tutorial/05_control_flow/conditional_execution.rb +62 -0
  57. data/dsl/tutorial/05_control_flow/handling_failures.rb +77 -0
  58. data/dsl/tutorial/06_reusable_scopes/README.md +172 -0
  59. data/dsl/tutorial/06_reusable_scopes/accessing_scope_outputs.rb +126 -0
  60. data/dsl/tutorial/06_reusable_scopes/basic_scope.rb +63 -0
  61. data/dsl/tutorial/06_reusable_scopes/parameterized_scope.rb +78 -0
  62. data/dsl/tutorial/07_processing_collections/README.md +152 -0
  63. data/dsl/tutorial/07_processing_collections/basic_map.rb +70 -0
  64. data/dsl/tutorial/07_processing_collections/parallel_map.rb +74 -0
  65. data/dsl/tutorial/08_iterative_workflows/README.md +231 -0
  66. data/dsl/tutorial/08_iterative_workflows/basic_repeat.rb +57 -0
  67. data/dsl/tutorial/08_iterative_workflows/conditional_break.rb +57 -0
  68. data/dsl/tutorial/09_async_cogs/README.md +197 -0
  69. data/dsl/tutorial/09_async_cogs/basic_async.rb +38 -0
  70. data/dsl/tutorial/README.md +222 -0
  71. data/dsl/working_directory.rb +16 -0
  72. data/exe/roast +1 -1
  73. data/internal/documentation/architectural-notes.md +115 -0
  74. data/internal/documentation/doc-comments-external.md +686 -0
  75. data/internal/documentation/doc-comments-internal.md +342 -0
  76. data/internal/documentation/doc-comments.md +211 -0
  77. data/lib/roast/dsl/cog/config.rb +274 -3
  78. data/lib/roast/dsl/cog/input.rb +53 -10
  79. data/lib/roast/dsl/cog/output.rb +297 -8
  80. data/lib/roast/dsl/cog/registry.rb +35 -3
  81. data/lib/roast/dsl/cog/stack.rb +1 -1
  82. data/lib/roast/dsl/cog/store.rb +5 -5
  83. data/lib/roast/dsl/cog.rb +70 -14
  84. data/lib/roast/dsl/cog_input_context.rb +36 -1
  85. data/lib/roast/dsl/cog_input_manager.rb +116 -7
  86. data/lib/roast/dsl/cogs/agent/config.rb +465 -0
  87. data/lib/roast/dsl/cogs/agent/input.rb +81 -0
  88. data/lib/roast/dsl/cogs/agent/output.rb +59 -0
  89. data/lib/roast/dsl/cogs/agent/provider.rb +51 -0
  90. data/lib/roast/dsl/cogs/agent/providers/claude/claude_invocation.rb +185 -0
  91. data/lib/roast/dsl/cogs/agent/providers/claude/message.rb +73 -0
  92. data/lib/roast/dsl/cogs/agent/providers/claude/messages/assistant_message.rb +36 -0
  93. data/lib/roast/dsl/cogs/agent/providers/claude/messages/result_message.rb +61 -0
  94. data/lib/roast/dsl/cogs/agent/providers/claude/messages/system_message.rb +47 -0
  95. data/lib/roast/dsl/cogs/agent/providers/claude/messages/text_message.rb +36 -0
  96. data/lib/roast/dsl/cogs/agent/providers/claude/messages/tool_result_message.rb +47 -0
  97. data/lib/roast/dsl/cogs/agent/providers/claude/messages/tool_use_message.rb +46 -0
  98. data/lib/roast/dsl/cogs/agent/providers/claude/messages/unknown_message.rb +27 -0
  99. data/lib/roast/dsl/cogs/agent/providers/claude/messages/user_message.rb +37 -0
  100. data/lib/roast/dsl/cogs/agent/providers/claude/tool_result.rb +51 -0
  101. data/lib/roast/dsl/cogs/agent/providers/claude/tool_use.rb +48 -0
  102. data/lib/roast/dsl/cogs/agent/providers/claude.rb +31 -0
  103. data/lib/roast/dsl/cogs/agent/stats.rb +92 -0
  104. data/lib/roast/dsl/cogs/agent/usage.rb +62 -0
  105. data/lib/roast/dsl/cogs/agent.rb +75 -0
  106. data/lib/roast/dsl/cogs/chat/config.rb +453 -0
  107. data/lib/roast/dsl/cogs/chat/input.rb +92 -0
  108. data/lib/roast/dsl/cogs/chat/output.rb +64 -0
  109. data/lib/roast/dsl/cogs/chat/session.rb +68 -0
  110. data/lib/roast/dsl/cogs/chat.rb +59 -56
  111. data/lib/roast/dsl/cogs/cmd.rb +251 -61
  112. data/lib/roast/dsl/cogs/ruby.rb +171 -0
  113. data/lib/roast/dsl/command_runner.rb +191 -0
  114. data/lib/roast/dsl/config_manager.rb +58 -11
  115. data/lib/roast/dsl/control_flow.rb +41 -0
  116. data/lib/roast/dsl/execution_manager.rb +162 -32
  117. data/lib/roast/dsl/nil_assertions.rb +23 -0
  118. data/lib/roast/dsl/system_cog/params.rb +32 -0
  119. data/lib/roast/dsl/system_cog.rb +36 -0
  120. data/lib/roast/dsl/system_cogs/call.rb +163 -0
  121. data/lib/roast/dsl/system_cogs/map.rb +454 -0
  122. data/lib/roast/dsl/system_cogs/repeat.rb +242 -0
  123. data/lib/roast/dsl/workflow.rb +26 -16
  124. data/lib/roast/dsl/workflow_context.rb +20 -0
  125. data/lib/roast/dsl/workflow_params.rb +24 -0
  126. data/lib/roast/helpers/minitest_coverage_runner.rb +1 -1
  127. data/lib/roast/sorbet_runtime_stub.rb +154 -0
  128. data/lib/roast/tools/apply_diff.rb +1 -3
  129. data/lib/roast/tools/cmd.rb +4 -3
  130. data/lib/roast/tools/read_file.rb +1 -1
  131. data/lib/roast/tools/update_files.rb +1 -1
  132. data/lib/roast/tools/write_file.rb +1 -1
  133. data/lib/roast/version.rb +1 -1
  134. data/lib/roast/workflow/base_workflow.rb +4 -0
  135. data/lib/roast/workflow/step_loader.rb +14 -2
  136. data/lib/roast-ai.rb +4 -0
  137. data/lib/roast.rb +58 -21
  138. data/{roast.gemspec → roast-ai.gemspec} +9 -13
  139. data/sorbet/rbi/gems/async@2.34.0.rbi +1577 -0
  140. data/sorbet/rbi/gems/cli-kit@5.2.0.rbi +2063 -0
  141. data/sorbet/rbi/gems/{cli-ui@2.3.0.rbi → cli-ui@2.7.0-6bdefd1d06305e5d6ae312ac76f9c88f88658dda.rbi} +1418 -1013
  142. data/sorbet/rbi/gems/console@1.34.2.rbi +1193 -0
  143. data/sorbet/rbi/gems/fiber-annotation@0.2.0.rbi +50 -0
  144. data/sorbet/rbi/gems/fiber-local@1.1.0.rbi +35 -0
  145. data/sorbet/rbi/gems/fiber-storage@1.0.1.rbi +41 -0
  146. data/sorbet/rbi/gems/io-event@1.14.0.rbi +724 -0
  147. data/sorbet/rbi/gems/metrics@0.15.0.rbi +9 -0
  148. data/sorbet/rbi/gems/traces@0.18.2.rbi +9 -0
  149. data/sorbet/rbi/shims/lib/roast/dsl/cog_input_context.rbi +1185 -5
  150. data/sorbet/rbi/shims/lib/roast/dsl/config_context.rbi +311 -5
  151. data/sorbet/rbi/shims/lib/roast/dsl/execution_context.rbi +486 -5
  152. data/sorbet/tapioca/config.yml +6 -0
  153. data/sorbet/tapioca/require.rb +2 -0
  154. metadata +157 -30
  155. data/dsl/less_simple.rb +0 -112
  156. data/dsl/scoped_executors.rb +0 -28
  157. data/dsl/simple.rb +0 -8
  158. data/lib/roast/dsl/cogs/execute.rb +0 -46
  159. data/lib/roast/dsl/cogs/graph.rb +0 -53
  160. data/sorbet/rbi/gems/cgi@0.5.0.rbi +0 -2961
  161. data/sorbet/rbi/gems/claude_swarm@0.1.19.rbi +0 -568
  162. data/sorbet/rbi/gems/cli-kit@5.0.1.rbi +0 -1991
  163. data/sorbet/rbi/gems/dry-configurable@1.3.0.rbi +0 -672
  164. data/sorbet/rbi/gems/dry-core@1.1.0.rbi +0 -1894
  165. data/sorbet/rbi/gems/dry-inflector@1.2.0.rbi +0 -659
  166. data/sorbet/rbi/gems/dry-initializer@3.2.0.rbi +0 -781
  167. data/sorbet/rbi/gems/dry-logic@1.6.0.rbi +0 -1127
  168. data/sorbet/rbi/gems/dry-schema@1.14.1.rbi +0 -3727
  169. data/sorbet/rbi/gems/dry-types@1.8.3.rbi +0 -3969
  170. data/sorbet/rbi/gems/fast-mcp-annotations@1.5.3.rbi +0 -1588
  171. data/sorbet/rbi/gems/mime-types-data@3.2025.0617.rbi +0 -136
  172. data/sorbet/rbi/gems/mime-types@3.7.0.rbi +0 -1342
  173. data/sorbet/rbi/gems/rack@2.2.19.rbi +0 -5676
  174. data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +0 -435
  175. data/sorbet/rbi/gems/yard@0.9.37.rbi +0 -18492
@@ -0,0 +1,342 @@
1
+ # Developer-Facing Documentation Guidelines
2
+
3
+ This document provides guidelines for writing developer-facing documentation comments in Roast. Developer-facing documentation appears in internal implementation code that Roast core contributors work with directly.
4
+
5
+ ## Where This Applies
6
+
7
+ Developer-facing documentation can be more concise since developers have the code right in front of them.
8
+
9
+ **Applies to:**
10
+
11
+ - Cog classes themselves (e.g., `Agent`, `Chat`, `Cmd`)
12
+ - All `Params` classes for system cogs (e.g., `SystemCog::Params`)
13
+ - Standard cog methods like `execute`, `initialize`
14
+ - Internal helper methods and utilities
15
+ - Private methods (if documented at all)
16
+
17
+ ## Documentation Requirements
18
+
19
+ Developer-facing documentation should be concise and focused:
20
+
21
+ - Focus on usage, interface guarantees, and expectations
22
+ - Do **NOT** describe implementation details
23
+ - Do **NOT** include `#### See Also` sections (code is right there)
24
+ - Keep it concise - one-line summary is often sufficient
25
+ - Only add additional context when interface contracts aren't obvious from the method signature
26
+
27
+ ## Basic Format
28
+
29
+ Documentation comments follow this minimal structure:
30
+
31
+ ```ruby
32
+ # [One-line summary of what the method does]
33
+ #
34
+ #: (ParamType) -> ReturnType # Type signatures are enforced by Sorbet/RuboCop
35
+ def method_name(param)
36
+ # implementation
37
+ end
38
+ ```
39
+
40
+ For methods where the interface contract is clear from the signature, a one-line description is sufficient:
41
+
42
+ ```ruby
43
+ # Execute the agent with the given input and return the output
44
+ #
45
+ #: (Input) -> Output
46
+ def execute(input)
47
+ # implementation
48
+ end
49
+ ```
50
+
51
+ ## Writing Clear Descriptions
52
+
53
+ ### One-Line Descriptions
54
+
55
+ Start with a clear, action-oriented description in imperative mood. The first line should **not** end with a period:
56
+
57
+ ```ruby
58
+ # Execute the chat completion with the given input and return the output
59
+ #
60
+ #: (Input) -> Output
61
+ def execute(input)
62
+ # implementation
63
+ end
64
+ ```
65
+
66
+ **Good patterns:**
67
+
68
+ - "Execute..."
69
+ - "Initialize..."
70
+ - "Get..."
71
+ - "Create..."
72
+
73
+ **Avoid:**
74
+
75
+ - Passive voice: "The input is executed..."
76
+ - Redundant phrases: "This method executes..."
77
+ - Implementation details: "Calls the provider's invoke method..."
78
+ - Ending with a period
79
+
80
+ ### When to Add Additional Context
81
+
82
+ Only add additional lines when the interface contract isn't obvious from the method signature and one-line description:
83
+
84
+ ```ruby
85
+ # Get the RubyLLM context configured for this chat cog
86
+ #
87
+ # Returns a cached context object that is lazily initialized on first access
88
+ # and reused for subsequent calls.
89
+ #
90
+ #: () -> RubyLLM::Context
91
+ def ruby_llm_context
92
+ @ruby_llm_context ||= RubyLLM.context do |context|
93
+ # configuration
94
+ end
95
+ end
96
+ ```
97
+
98
+ In this example, the additional context about caching and lazy initialization is valuable because it's not obvious from the signature.
99
+
100
+ ## Class Documentation
101
+
102
+ Document cog classes with a brief description of their purpose:
103
+
104
+ ```ruby
105
+ # Agent cog for executing AI agent workflows
106
+ #
107
+ # Enables interaction with AI agent providers to perform complex reasoning
108
+ # and tool-using tasks. Unlike the simpler chat cog, agents can use tools,
109
+ # maintain session state, and track detailed execution statistics.
110
+ class Agent < Cog
111
+ # ...
112
+ end
113
+ ```
114
+
115
+ **Key points:**
116
+
117
+ - Describe the cog's purpose concisely
118
+ - Mention key capabilities that distinguish it from other cogs
119
+ - Do NOT include `#### See Also` sections
120
+ - Do NOT describe implementation details
121
+
122
+ ## Error Class Documentation
123
+
124
+ Document error classes with brief descriptions of when they're raised:
125
+
126
+ ```ruby
127
+ # Parent class for all agent cog errors
128
+ class AgentCogError < Roast::Error; end
129
+
130
+ # Raised when an unknown or unsupported provider is specified
131
+ class UnknownProviderError < AgentCogError; end
132
+
133
+ # Raised when a required provider is not configured
134
+ class MissingProviderError < AgentCogError; end
135
+ ```
136
+
137
+ **Key points:**
138
+
139
+ - One line is sufficient
140
+ - Describe when the error is raised
141
+ - No need for extensive context
142
+
143
+ ## Attribute Documentation
144
+
145
+ Document public attributes with brief descriptions:
146
+
147
+ ```ruby
148
+ # The configuration object for this agent cog instance
149
+ #
150
+ #: Agent::Config
151
+ attr_reader :config
152
+ ```
153
+
154
+ **Key points:**
155
+
156
+ - One line is usually sufficient
157
+ - Do NOT include `#### See Also` sections
158
+ - Type signature provides most of the needed information
159
+
160
+ ## Standard Method Patterns
161
+
162
+ ### Execute Methods
163
+
164
+ All cog `execute` methods should have minimal documentation:
165
+
166
+ ```ruby
167
+ # Execute the agent with the given input and return the output
168
+ #
169
+ #: (Input) -> Output
170
+ def execute(input)
171
+ # implementation
172
+ end
173
+ ```
174
+
175
+ **Do NOT document:**
176
+ - What happens internally (provider invocation, display logic, etc.)
177
+ - Configuration options (those are documented in Config class)
178
+ - Implementation details
179
+
180
+ ### Initialize Methods
181
+
182
+ Rarely need documentation beyond type signature since constructor behavior is standard:
183
+
184
+ ```ruby
185
+ #: (String response) -> void
186
+ def initialize(response)
187
+ super()
188
+ @response = response
189
+ end
190
+ ```
191
+
192
+ Only add a comment if the initialization does something non-obvious.
193
+
194
+ ## What Not to Document
195
+
196
+ Avoid documenting:
197
+
198
+ - **Implementation details** - How the method accomplishes its goal
199
+ - **Obvious information** - What's clear from the method name and signature
200
+ - **Private methods** - Generally don't need documentation comments
201
+ - **Internal mechanics** - Instance variable usage, caching strategies, etc.
202
+ - **Cross-references** - Code is right there, no need for `#### See Also`
203
+
204
+ **Bad example:**
205
+
206
+ ```ruby
207
+ # Execute the agent by calling the provider's invoke method with the input,
208
+ # then checking the config to see if we should print the prompt, response,
209
+ # and stats to the console, and finally returning the output object
210
+ #
211
+ #: (Input) -> Output
212
+ def execute(input)
213
+ # implementation
214
+ end
215
+ ```
216
+
217
+ This is too detailed and describes implementation rather than interface.
218
+
219
+ **Good example:**
220
+
221
+ ```ruby
222
+ # Execute the agent with the given input and return the output
223
+ #
224
+ #: (Input) -> Output
225
+ def execute(input)
226
+ # implementation
227
+ end
228
+ ```
229
+
230
+ ## Markdown Formatting
231
+
232
+ Use minimal markdown formatting in developer-facing documentation:
233
+
234
+ ### Inline Code
235
+
236
+ Use backticks for:
237
+
238
+ - Method names: `` `execute` ``
239
+ - Values: `` `true` ``, `` `:claude` ``
240
+ - Cog names: `` `call` ``, `` `map` ``, `` `agent` `` (they appear as methods from a user's perspective)
241
+ - Class names: Use **fully qualified names** (e.g., `` `Roast::DSL::Cogs::Agent::Input` ``)
242
+
243
+ **Important:** Always use fully qualified class/module names in documentation to avoid ambiguity.
244
+ Due to significant name overlap in the system (e.g., multiple `Input`, `Output`, `Config` classes),
245
+ shortened names can be confusing. Use the complete module path.
246
+
247
+ **Note:** "System" cogs (like `call`, `map`, `repeat`) are an internal implementation detail that inherit from `SystemCog` rather than `Cog`. This distinction is irrelevant in documentation - all cogs should be presented consistently regardless of their base class.
248
+
249
+ ```ruby
250
+ # Get a RubyLLM context configured for this chat cog
251
+ #
252
+ #: () -> RubyLLM::Context
253
+ def ruby_llm_context
254
+ # implementation
255
+ end
256
+ ```
257
+
258
+ **Examples:**
259
+ - ✅ Good: `` `Roast::DSL::SystemCogs::Call::Output` ``
260
+ - ❌ Bad: `` `Call::Output` `` (ambiguous)
261
+
262
+ ### Bold Emphasis
263
+
264
+ Use sparingly, only for critical negations if needed:
265
+
266
+ ```ruby
267
+ # Execute the agent but do __not__ display progress to the console
268
+ #
269
+ #: (Input) -> Output
270
+ def execute_silently(input)
271
+ # implementation
272
+ end
273
+ ```
274
+
275
+ ### No Subsections
276
+
277
+ Do **NOT** use subsections like `#### See Also` in developer-facing documentation. Developers can see related methods in the code.
278
+
279
+ ## Review Checklist
280
+
281
+ Before finalizing developer-facing documentation, verify:
282
+
283
+ - [ ] One-line description is clear and action-oriented
284
+ - [ ] First line does not end with a period
285
+ - [ ] Focus is on interface contract (what it does), not implementation (how it does it)
286
+ - [ ] No `#### See Also` sections are included (code is right there)
287
+ - [ ] Documentation is concise - additional context only when interface isn't obvious
288
+ - [ ] No implementation details are exposed
289
+ - [ ] Error conditions are mentioned only if not obvious from signature
290
+ - [ ] Markdown formatting is correct
291
+
292
+ ## Examples
293
+
294
+ ### Minimal Documentation (Preferred)
295
+
296
+ ```ruby
297
+ # Execute the chat completion with the given input and return the output
298
+ #
299
+ #: (Input) -> Output
300
+ def execute(input)
301
+ # implementation
302
+ end
303
+ ```
304
+
305
+ ### With Necessary Context
306
+
307
+ ```ruby
308
+ # Get the RubyLLM context configured for this chat cog
309
+ #
310
+ # Returns a cached context object that is lazily initialized on first access
311
+ # and reused for subsequent calls.
312
+ #
313
+ #: () -> RubyLLM::Context
314
+ def ruby_llm_context
315
+ @ruby_llm_context ||= RubyLLM.context do |context|
316
+ context.openai_api_key = config.valid_api_key!
317
+ context.openai_api_base = config.valid_base_url
318
+ end
319
+ end
320
+ ```
321
+
322
+ ### Class Documentation
323
+
324
+ ```ruby
325
+ # Chat cog for executing simple LLM chat completions
326
+ #
327
+ # Provides a straightforward interface for single-turn interactions with
328
+ # language models without tool use or conversation state management.
329
+ class Chat < Cog
330
+ # ...
331
+ end
332
+ ```
333
+
334
+ ### Error Class Documentation
335
+
336
+ ```ruby
337
+ # Parent class for all agent cog errors
338
+ class AgentCogError < Roast::Error; end
339
+
340
+ # Raised when an unknown or unsupported provider is specified
341
+ class UnknownProviderError < AgentCogError; end
342
+ ```
@@ -0,0 +1,211 @@
1
+ # Documentation Comment Guidelines
2
+
3
+ This document establishes standards for writing documentation comments in the Roast DSL codebase. Well-documented interfaces are critical for both internal development and community contributions.
4
+
5
+ ## Purpose and Audience
6
+
7
+ Documentation comments should serve developers who will use these interfaces, not just those who will maintain them.
8
+ Write for:
9
+
10
+ - Roast core contributors
11
+ - Community contributors
12
+ - Users extending Roast with custom cogs
13
+
14
+ ## Architectural Context
15
+
16
+ Before writing documentation, consult [architectural-notes.md](./architectural-notes.md) for key architectural decisions and distinctions that should guide how we talk about cogs and their functionality. This file captures important context such as:
17
+
18
+ - The distinction between `agent` and `chat` cogs
19
+ - Design decisions that affect how we describe cog capabilities
20
+ - Guidelines for avoiding misleading characterizations
21
+
22
+ Always ensure your documentation aligns with the architectural guidance in that file.
23
+
24
+ ## Two Types of Documentation
25
+
26
+ Roast has two distinct types of documentation with different thoroughness requirements. Understanding which type you're writing is essential to creating appropriate documentation.
27
+
28
+ ### User-Facing Documentation (External)
29
+
30
+ **For workflows users interact with directly.**
31
+
32
+ User-facing documentation appears in interfaces that Roast users write in their workflow files. These require the **most thorough documentation** and should **NOT assume knowledge** of how Roast works internally.
33
+
34
+ **Where user-facing documentation appears:**
35
+
36
+ - All `Config` classes for cogs (e.g., `Agent::Config`, `Chat::Config`, `Cmd::Config`)
37
+ - All `Input` classes for cogs (e.g., `Agent::Input`, `Chat::Input`)
38
+ - All `Output` classes for cogs (e.g., `Agent::Output`, `Chat::Output`)
39
+ - `.rbi` shims in `sorbet/rbi/shims/lib/roast/` - **These are critically important!**
40
+
41
+ #### Why .rbi Shims Are Critical
42
+
43
+ The `.rbi` shim files contain some of the most important user-facing documentation in Roast. These files define the methods that users call when writing workflows, and the documentation in these files is what users see in their IDE when they invoke these methods.
44
+
45
+ **Key .rbi shim files and their purposes:**
46
+
47
+ - **`execution_context.rbi`**: Documents methods users call when defining cogs in `execute` blocks (e.g., `agent!`, `chat!`, `cmd!`, `call!`, `map!`, `repeat!`)
48
+ - **`config_context.rbi`**: Documents methods users call when configuring cogs in `config` blocks (e.g., `agent { ... }`, `chat { ... }`, `cmd { ... }`)
49
+ - **This is the primary way users discover what configuration options are available**
50
+ - Must document ALL user-facing configuration methods on each cog's Config object (excluding internal methods like `valid_*`)
51
+ - Configuration options should be grouped by purpose using `####` subsection headers (e.g., "Configure the LLM provider", "Configure the working directory")
52
+ - **`cog_input_context.rbi`**: Documents methods users call in cog input blocks to access outputs from other cogs (e.g., `from`, `collect`, `reduce`)
53
+
54
+ These files provide the primary interface between users and Roast. The documentation must be exceptional because it's what users see at the exact moment they need help.
55
+
56
+ **Requirements:**
57
+
58
+ - Be extremely thorough
59
+ - Include comprehensive `#### See Also` sections with cross-references
60
+ - Explain default behaviors and edge cases
61
+ - Document error conditions
62
+ - Provide context about what the method does and why you'd use it
63
+ - Don't assume the reader understands Roast internals
64
+
65
+ **📖 See [doc-comments-external.md](./doc-comments-external.md) for complete user-facing documentation guidelines.**
66
+
67
+ **Example:**
68
+
69
+ ```ruby
70
+ # Configure the cog to use a specified provider when invoking an agent
71
+ #
72
+ # The provider is the source of the agent tool itself.
73
+ # If no provider is specified, Anthropic Claude Code (`:claude`) will be used as the default provider.
74
+ #
75
+ # A provider must be properly installed on your system in order for Roast to be able to use it.
76
+ #
77
+ # #### See Also
78
+ # - `use_default_provider!`
79
+ #
80
+ #: (Symbol) -> void
81
+ def provider(provider)
82
+ @values[:provider] = provider
83
+ end
84
+ ```
85
+
86
+ ### Developer-Facing Documentation (Internal)
87
+
88
+ **For Roast core implementation code.**
89
+
90
+ Developer-facing documentation appears in internal implementation code that Roast core contributors work with directly. These can be **more concise** since developers have the code right in front of them.
91
+
92
+ **Where developer-facing documentation appears:**
93
+
94
+ - Cog classes themselves (e.g., `Agent`, `Chat`, `Cmd`)
95
+ - All `Params` classes for system cogs (e.g., `SystemCog::Params`)
96
+ - Standard cog methods like `execute`, `initialize`
97
+ - Internal helper methods and utilities
98
+ - Private methods (if documented at all)
99
+
100
+ **Requirements:**
101
+
102
+ - Focus on usage, interface guarantees, and expectations
103
+ - Do **NOT** describe implementation details
104
+ - Do **NOT** include `#### See Also` sections (code is right there)
105
+ - Keep it concise - one-line summary is often sufficient
106
+ - Only add additional context when interface contracts aren't obvious from the method signature
107
+
108
+ **📖 See [doc-comments-internal.md](./doc-comments-internal.md) for complete developer-facing documentation guidelines.**
109
+
110
+ **Example:**
111
+
112
+ ```ruby
113
+ # Execute the agent with the given input and return the output
114
+ #
115
+ #: (Input) -> Output
116
+ def execute(input)
117
+ # implementation
118
+ end
119
+ ```
120
+
121
+ Notice: no `#### See Also`, no detailed explanation of what happens internally, just the interface contract.
122
+
123
+ ## Quick Reference
124
+
125
+ ### When to Use External Guidelines
126
+
127
+ Use [doc-comments-external.md](./doc-comments-external.md) when documenting:
128
+
129
+ - ✅ `Config` class methods (all configuration setters, getters, predicates)
130
+ - ✅ `Input` class methods and attributes
131
+ - ✅ `Output` class methods and attributes
132
+ - ✅ `.rbi` shim definitions (especially `execution_context.rbi`, `config_context.rbi`, `cog_input_context.rbi`)
133
+
134
+ ### When to Use Internal Guidelines
135
+
136
+ Use [doc-comments-internal.md](./doc-comments-internal.md) when documenting:
137
+
138
+ - ✅ Cog class definitions (e.g., `class Agent < Cog`)
139
+ - ✅ `Params` class methods and attributes (e.g., `SystemCog::Params`)
140
+ - ✅ `execute` methods on cog classes
141
+ - ✅ `initialize` methods on cog classes
142
+ - ✅ Private helper methods
143
+ - ✅ Internal utilities and support classes
144
+
145
+ ## General Principles
146
+
147
+ Regardless of which type of documentation you're writing, follow these universal principles:
148
+
149
+ ### One-Line Descriptions
150
+
151
+ - Start with a clear, action-oriented description in imperative mood
152
+ - The first line should **NOT** end with a period
153
+ - Use active voice, not passive
154
+ - Be specific and precise
155
+
156
+ ### Multi-Line Descriptions
157
+
158
+ - Separate paragraphs with blank comment lines
159
+ - All lines after the first line should be complete sentences ending with a period
160
+ - Add context and details after the one-line summary
161
+
162
+ ### Markdown Formatting
163
+
164
+ - Use double underscores (`__word__`) for bold emphasis on critical negating words
165
+ - Use backticks (`` `code` ``) for method names, values, symbols, class names, and cog names
166
+ - **Cog names should always be stylized with backticks** (e.g., `` `call` ``, `` `map` ``, `` `agent` ``) since they appear as methods from a user's perspective
167
+ - **Always use fully qualified class/module names** (e.g., `Roast::DSL::SystemCogs::Call::Output`, not `Call::Output`) to avoid ambiguity
168
+ - Use `####` for subsection headers in user-facing documentation only
169
+ - Use `-` for bullet lists
170
+
171
+ **Note:** "System" cogs are an internal implementation detail. From the user's perspective, all cogs provided by core Roast should be presented the same way. Never distinguish between "system cogs" and "regular cogs" in user-facing documentation.
172
+
173
+ **Note:** `ExecutionManager` is an internal implementation detail. Never mention execution managers in user-facing documentation (Config, Input, Output classes). Focus on what the user can do with the output, not on the internal mechanisms.
174
+
175
+ ### Type Signatures
176
+
177
+ - Always include inline RBS type signatures using `#:` comments
178
+ - Type signatures are enforced by Sorbet and RuboCop
179
+ - Place type signatures immediately before the method definition
180
+
181
+ ### What Not to Document
182
+
183
+ - **Implementation details** - Focus on behavior, not how it's achieved
184
+ - **Obvious information** - Don't state what's clear from the method name
185
+ - **Internal mechanics** - How instance variables work, caching strategies, etc.
186
+
187
+ ## Getting Started
188
+
189
+ 1. **Identify which type of documentation you need:**
190
+ - Are you documenting a Config/Input/Output class or .rbi shim? → Use [external guidelines](./doc-comments-external.md)
191
+ - Are you documenting a Params class, cog class, or internal method? → Use [internal guidelines](./doc-comments-internal.md)
192
+
193
+ 2. **Read the appropriate guide:**
194
+ - [doc-comments-external.md](./doc-comments-external.md) - Comprehensive user-facing documentation
195
+ - [doc-comments-internal.md](./doc-comments-internal.md) - Concise developer-facing documentation
196
+
197
+ 3. **Follow the examples and patterns** in your chosen guide
198
+
199
+ 4. **Review your documentation** using the checklist at the end of your guide
200
+
201
+ ## Questions?
202
+
203
+ If you're unsure which type of documentation applies:
204
+
205
+ - **Ask yourself:** "Will a Roast user call this method directly in their workflow file or see this documentation in their IDE?"
206
+ - If YES → Use external (user-facing) guidelines
207
+ - If NO → Use internal (developer-facing) guidelines
208
+
209
+ - **.rbi shim files are always user-facing** - If you're documenting anything in `sorbet/rbi/shims/lib/roast/`, use external guidelines
210
+
211
+ - **Still unsure?** Default to external guidelines - it's better to be thorough than too brief.