scout-ai 2.0.0 → 2.2.0

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 (185) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +135 -55
  3. data/README.md +2 -1
  4. data/VERSION +1 -1
  5. data/doc/Improvements.md +490 -148
  6. data/doc/Model.md +53 -10
  7. data/doc/StartHere.md +44 -19
  8. data/doc/developer/Architecture.md +25 -6
  9. data/doc/developer/Backends.md +207 -48
  10. data/doc/developer/ChatLifecycle.md +121 -20
  11. data/doc/developer/DelegationInternals.md +320 -34
  12. data/doc/developer/DesignPrinciples.md +205 -16
  13. data/doc/developer/PathEngine.md +628 -0
  14. data/doc/developer/PromptProcessing.md +332 -82
  15. data/doc/developer/Provenance.md +402 -44
  16. data/doc/developer/Sandbox.md +213 -0
  17. data/doc/user/BuildingAgents.md +130 -18
  18. data/doc/user/Cookbook.md +29 -8
  19. data/doc/user/CoreConcepts.md +7 -6
  20. data/doc/user/Delegation.md +166 -15
  21. data/doc/user/GettingStarted.md +20 -16
  22. data/doc/user/ManagingContext.md +155 -17
  23. data/doc/user/MultiAgentWorkflows.md +105 -15
  24. data/doc/user/Python.md +11 -1
  25. data/doc/user/RunningInference.md +90 -47
  26. data/doc/user/ToolCalling.md +134 -29
  27. data/doc/user/WritingChats.md +56 -27
  28. data/lib/scout/llm/agent/attach.rb +64 -0
  29. data/lib/scout/llm/agent/chat.rb +32 -0
  30. data/lib/scout/llm/agent/construction.rb +64 -0
  31. data/lib/scout/llm/agent/conversation.rb +304 -0
  32. data/lib/scout/llm/agent/delegate.rb +56 -238
  33. data/lib/scout/llm/agent/path/edit.rb +230 -0
  34. data/lib/scout/llm/agent/path/patch.rb +252 -0
  35. data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
  36. data/lib/scout/llm/agent/path.rb +1777 -0
  37. data/lib/scout/llm/agent/save.rb +11 -9
  38. data/lib/scout/llm/agent/workflow.rb +79 -17
  39. data/lib/scout/llm/agent.rb +151 -27
  40. data/lib/scout/llm/ask.rb +37 -27
  41. data/lib/scout/llm/backends/anthropic.rb +1 -1
  42. data/lib/scout/llm/backends/bedrock.rb +3 -2
  43. data/lib/scout/llm/backends/default.rb +131 -32
  44. data/lib/scout/llm/backends/glm.rb +28 -1
  45. data/lib/scout/llm/backends/huggingface.rb +1 -1
  46. data/lib/scout/llm/backends/ollama.rb +1 -1
  47. data/lib/scout/llm/backends/openai.rb +7 -6
  48. data/lib/scout/llm/backends/openwebui.rb +14 -7
  49. data/lib/scout/llm/backends/relay.rb +8 -2
  50. data/lib/scout/llm/chat/agent_meta.rb +24 -60
  51. data/lib/scout/llm/chat/parse.rb +1 -1
  52. data/lib/scout/llm/chat/process/files.rb +10 -0
  53. data/lib/scout/llm/chat/process/meta.rb +5 -7
  54. data/lib/scout/llm/chat/process/tools.rb +104 -52
  55. data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
  56. data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
  57. data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
  58. data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
  59. data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
  60. data/lib/scout/llm/chat/prompt.rb +24 -10
  61. data/lib/scout/llm/chat/provenance/live.rb +1080 -0
  62. data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
  63. data/lib/scout/llm/chat/provenance.rb +352 -626
  64. data/lib/scout/llm/chat.rb +8 -2
  65. data/lib/scout/llm/embed.rb +15 -3
  66. data/lib/scout/llm/image.rb +4 -1
  67. data/lib/scout/llm/mcp.rb +4 -2
  68. data/lib/scout/llm/request_context.rb +234 -0
  69. data/lib/scout/llm/sandbox.rb +263 -0
  70. data/lib/scout/llm/tools/call.rb +163 -42
  71. data/lib/scout/llm/tools/definition.rb +48 -0
  72. data/lib/scout/llm/tools/knowledge_base.rb +1 -0
  73. data/lib/scout/llm/tools/mcp.rb +50 -43
  74. data/lib/scout/llm/tools/workflow.rb +90 -20
  75. data/lib/scout/llm/tools.rb +14 -41
  76. data/lib/scout/model/decision/base.rb +43 -0
  77. data/lib/scout/model/decision/jev.rb +161 -0
  78. data/lib/scout/model/python/torch.rb +1 -1
  79. data/research/clear-tools-inherit.md +171 -0
  80. data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
  81. data/research/path-kind-chat-role.md +96 -0
  82. data/research/path-kind-contract-fixes-engine.md +307 -0
  83. data/research/scout-ai-runtime-availability.md +65 -0
  84. data/research/subsys/README.md +127 -0
  85. data/research/subsys/agent-delegation.md +201 -0
  86. data/research/subsys/agent-society.md +275 -0
  87. data/research/subsys/agentworkflow.md +233 -0
  88. data/research/subsys/backends.md +221 -0
  89. data/research/subsys/chat.md +314 -0
  90. data/research/subsys/embed-image.md +244 -0
  91. data/research/subsys/entry-cli.md +253 -0
  92. data/research/subsys/model-ml.md +326 -0
  93. data/research/subsys/provenance.md +290 -0
  94. data/research/subsys/tools.md +334 -0
  95. data/scout-ai.gemspec +72 -26
  96. data/scout_commands/agent/ask +8 -7
  97. data/scout_commands/llm/abridged +40 -0
  98. data/scout_commands/llm/ask +9 -9
  99. data/scout_commands/llm/md +2 -0
  100. data/scout_commands/llm/prov +845 -80
  101. data/scout_commands/llm/word +4 -0
  102. data/share/word/reference.docx +0 -0
  103. data/test/integration/scout/model/decision/test_jev.rb +144 -0
  104. data/test/scout/llm/agent/test_attach.rb +117 -0
  105. data/test/scout/llm/agent/test_conversation.rb +407 -0
  106. data/test/scout/llm/agent/test_delegate.rb +209 -0
  107. data/test/scout/llm/agent/test_path.rb +1812 -0
  108. data/test/scout/llm/agent/test_path_edit.rb +908 -0
  109. data/test/scout/llm/agent/test_path_errors.rb +390 -0
  110. data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
  111. data/test/scout/llm/agent/test_path_patch.rb +233 -0
  112. data/test/scout/llm/agent/test_path_promotion.rb +386 -0
  113. data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
  114. data/test/scout/llm/agent/test_save.rb +70 -15
  115. data/test/scout/llm/agent/test_workflow.rb +130 -4
  116. data/test/scout/llm/backends/test_anthropic.rb +4 -4
  117. data/test/scout/llm/backends/test_bedrock.rb +4 -4
  118. data/test/scout/llm/backends/test_format_other.rb +43 -0
  119. data/test/scout/llm/backends/test_ollama.rb +2 -2
  120. data/test/scout/llm/backends/test_openwebui.rb +12 -8
  121. data/test/scout/llm/backends/test_reasoning.rb +114 -0
  122. data/test/scout/llm/chat/agent_meta_fixtures.rb +109 -22
  123. data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
  124. data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
  125. data/test/scout/llm/chat/test_agent_meta.rb +40 -80
  126. data/test/scout/llm/chat/test_agent_meta_provenance.rb +200 -28
  127. data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
  128. data/test/scout/llm/chat/test_agent_view.rb +178 -0
  129. data/test/scout/llm/chat/test_live_report.rb +282 -0
  130. data/test/scout/llm/chat/test_live_workload.rb +193 -0
  131. data/test/scout/llm/chat/test_parse.rb +32 -2
  132. data/test/scout/llm/chat/test_prompt.rb +411 -0
  133. data/test/scout/llm/chat/test_prov_cli.rb +708 -13
  134. data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
  135. data/test/scout/llm/chat/test_prov_plot.rb +213 -0
  136. data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
  137. data/test/scout/llm/chat/test_provenance.rb +67 -22
  138. data/test/scout/llm/chat/test_provenance_index.rb +479 -0
  139. data/test/scout/llm/chat/test_society_view.rb +159 -0
  140. data/test/scout/llm/test_agent.rb +1 -1
  141. data/test/scout/llm/test_embed.rb +103 -1
  142. data/test/scout/llm/test_request_context.rb +299 -0
  143. data/test/scout/llm/test_sandbox.rb +249 -0
  144. data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
  145. data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
  146. data/test/scout/llm/tools/test_definition.rb +332 -0
  147. data/test/scout/llm/tools/test_jobs_file.rb +211 -0
  148. data/test/scout/llm/tools/test_mcp.rb +37 -8
  149. data/test/scout/llm/tools/test_workflow.rb +45 -1
  150. data/test/scout/model/decision/test_jev.rb +453 -0
  151. data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
  152. data/test/scout/model/python/huggingface/test_causal.rb +11 -2
  153. data/test/scout/model/python/huggingface/test_classification.rb +5 -3
  154. data/test/scout/model/python/test_availability.rb +116 -0
  155. data/test/scout/model/python/test_torch.rb +54 -2
  156. data/test/support/availability.rb +72 -174
  157. data/test/support/fake_clients.rb +18 -9
  158. data/test/support/fixtures.rb +75 -6
  159. data/test/support/mock_backend.rb +9 -1
  160. data/test/support/test_fixtures.rb +156 -0
  161. data/test/test_helper.rb +14 -4
  162. metadata +71 -25
  163. data/research/ChatAnalyst-required-changes.md +0 -167
  164. data/research/agent-delegation-analysis.md +0 -810
  165. data/research/agent-meta-provenance-integration-plan.md +0 -622
  166. data/research/agent-workflow-analysis.md +0 -1120
  167. data/research/backends-analysis.md +0 -836
  168. data/research/chat-core-analysis.md +0 -946
  169. data/research/chatanalyst-provenance/00-baseline.md +0 -30
  170. data/research/chatanalyst-provenance/01-repo-map.md +0 -60
  171. data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
  172. data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
  173. data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
  174. data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
  175. data/research/chatanalyst-provenance/07-critic-review.md +0 -25
  176. data/research/chatanalyst-provenance/final-report.md +0 -45
  177. data/research/chatanalyst-provenance/resumption.md +0 -37
  178. data/research/coding-philosophy-analysis.md +0 -928
  179. data/research/commands-analysis.md +0 -947
  180. data/research/multi-agent-patterns-analysis.md +0 -853
  181. data/research/prompt-strategies-analysis.md +0 -630
  182. data/research/prov-verbosity-fix-notes.md +0 -77
  183. data/research/provenance-analysis.md +0 -469
  184. data/research/synthesis-report.md +0 -487
  185. data/research/tools-system-analysis.md +0 -779
@@ -4,8 +4,8 @@ This document explains the coding philosophy and idioms that make Scout-AI
4
4
  elegant and expressive. It is intended for framework contributors who want to
5
5
  write code that fits the existing style.
6
6
 
7
- > For detailed examples and analysis of idiomatic vs. non-idiomatic patterns,
8
- > see [../../research/coding-philosophy-analysis.md](../../research/coding-philosophy-analysis.md).
7
+ > This page is the normative summary of the coding philosophy; every rule here
8
+ > is self-contained and no external investigation is needed to apply it.
9
9
 
10
10
  ---
11
11
 
@@ -26,15 +26,23 @@ always: *what abstraction does this feature belong to?*
26
26
 
27
27
  ## Module composition over inheritance
28
28
 
29
- Scout-AI avoids deep class hierarchies. Behavior is composed through Ruby
30
- modules:
29
+ Scout-AI avoids deep class hierarchies, and the dependency direction stays
30
+ one-way — Agent → Chat → Annotation; backends depend on Chat (through
31
+ `Backend::ClassMethods`) but never on Agent, and `AgentWorkflow` depends on
32
+ Agent and Chat but not on any particular backend.
33
+
34
+ Behavior is composed through Ruby modules:
31
35
 
32
36
  ```ruby
33
37
  # Agent's behavior is split across multiple files that reopen the class:
34
38
  # lib/scout/llm/agent.rb — core (ask, prompt, workflow)
35
39
  # lib/scout/llm/agent/chat.rb — chat management
40
+ # lib/scout/llm/agent/construction.rb — clone_agent/build (template-clone pattern)
36
41
  # lib/scout/llm/agent/iterate.rb — iteration patterns
37
42
  # lib/scout/llm/agent/delegate.rb — multi-agent delegation
43
+ # lib/scout/llm/agent/conversation.rb — conversation save/load
44
+ # lib/scout/llm/agent/attach.rb — attachment tool wiring
45
+ # lib/scout/llm/agent/save.rb — persisted conversation files
38
46
  # lib/scout/llm/agent/workflow.rb — AgentWorkflow mixin + chat_task DSL
39
47
  ```
40
48
 
@@ -42,6 +50,13 @@ Each module adds a cohesive set of methods to the same class. There is no
42
50
  inheritance tree — just flat composition. This keeps each concern in its own
43
51
  file while sharing `@other_options`, `@current_chat`, etc.
44
52
 
53
+ Modules also serve double duty as **namespace and mixin** at the same time:
54
+ `LLM` is both the entry point namespace (`LLM.ask`, `LLM.chat`,
55
+ `LLM.load_agent`) and the host of `LLM::Backend::ClassMethods`, the mixin that
56
+ every provider adapter includes into its singleton class. When adding a
57
+ subsystem, keep the same split: namespace at the top, behaviour as a nested
58
+ `ClassMethods`-style mixin so other modules can compose it.
59
+
45
60
  ---
46
61
 
47
62
  ## Chat-as-data (annotate, don't wrap)
@@ -65,10 +80,19 @@ chat.select { |m| m[:role] == 'system' } # standard Array operations work
65
80
  The annotation:
66
81
  - Adds methods to the **singleton class** of the specific object instance.
67
82
  - Does **not** change the object's class.
68
- - Is **removable** via `Annotation.purge(obj)`.
83
+ - Is **removable**: `Annotation.purge(obj)` returns a plain duplicate with the
84
+ annotation instance variables stripped (recursively for nested Arrays/Hashes).
85
+ - Records the applied annotations in `annotation_types`.
86
+
87
+ The pattern is not Chat-specific: `Step` annotates a path `String` with job
88
+ metadata the same way. Annotating is the house style for "attach rich behaviour
89
+ to plain data".
69
90
 
70
91
  **Implication:** Don't create wrapper classes for data that is already a Hash
71
- or Array. Annotate it instead.
92
+ or Array. Annotate it instead. Because a chat stays a plain Array it is
93
+ serializable to the `.chat` text format, composable by concatenation,
94
+ introspectable with ordinary Array/Hash operations, and cacheable by
95
+ `Persist.persist` hashing the message array.
72
96
 
73
97
  ---
74
98
 
@@ -79,13 +103,18 @@ Scout-AI discovers components by convention rather than registration:
79
103
  | Convention | Resolution |
80
104
  |---|---|
81
105
  | Agent directory `Agent/<Name>/` | Auto-discovered via `Scout.Agent`, `Scout.chats.Agent`, etc. |
106
+ | `agent.rb` | `load`-ed; its last expression must be an `Agent`. |
82
107
  | `start_chat` file | Loaded as initial conversation. |
83
108
  | `workflow.rb` | Loaded as the agent's workflow. |
84
109
  | `knowledge_base/` | Loaded as the agent's KB. |
85
110
  | `python/*.py` | Loaded as Python-backed tools. |
111
+ | Endpoint file `etc/AI/<name>.yaml` | Merged as option defaults when `endpoint: <name>` is used. |
86
112
 
87
113
  There are no registration calls or plugin manifests. Put files in the right
88
- place and they are found.
114
+ place and they are found. The one deliberate exception is backends: a new
115
+ provider is registered explicitly with `LLM.register_backend(name, mod)` (or
116
+ added to the `case` in `LLM.ask`), because nothing about a module name tells
117
+ the dispatcher where to find it.
89
118
 
90
119
  ---
91
120
 
@@ -116,6 +145,18 @@ agent.chat
116
145
  The `method_missing` proxy on Agent forwards unknown methods to
117
146
  `current_chat`, so all Chat methods work directly on the Agent.
118
147
 
148
+ Because the DSL is just methods on a module, extending it is reopening the
149
+ module — a new role or convenience method added to `Chat` is immediately
150
+ available on every annotated Array and, through the proxy, on every Agent:
151
+
152
+ ```ruby
153
+ module Chat
154
+ def screenshot(file)
155
+ message(:image, file)
156
+ end
157
+ end
158
+ ```
159
+
119
160
  ### Workflow DSL (chat_task)
120
161
 
121
162
  ```ruby
@@ -131,6 +172,39 @@ module MyPipeline
131
172
  end
132
173
  ```
133
174
 
175
+ `self.include_workflow AgentWorkflow` is required: `extend Workflow` alone does
176
+ not define `chat_task`, and the helpers the mixin adds (`helper :agent`,
177
+ `helper :log_agent`) only reach the module through `include_workflow`.
178
+
179
+ ### Backend composition DSL
180
+
181
+ ```ruby
182
+ module LLM
183
+ module MyProviderMethods
184
+ def query(client, messages, tools = [], parameters = {})
185
+ # override: translate messages/tools to the provider call
186
+ end
187
+ end
188
+
189
+ module MyProvider
190
+ TAG = 'myprovider'
191
+ DEFAULT_MODEL = 'my-model-v1'
192
+
193
+ class << self
194
+ prepend MyProviderMethods # overrides, dispatched first
195
+ include Backend::ClassMethods # shared ask/embed loop
196
+ end
197
+ end
198
+ end
199
+ ```
200
+
201
+ The prepend runs before the included base, so `Backend::ClassMethods#ask` can
202
+ call `query` and reach the provider override. A new backend is dispatched by a
203
+ `case` branch in `LLM.ask` or `LLM.register_backend(:myprovider, MyProvider)`.
204
+ Every adapter also exposes `TAG` and `DEFAULT_MODEL` constants; name-based
205
+ module resolution is deliberately absent, so an unregistered name is an
206
+ `Unknown backend` error rather than a guessed constant.
207
+
134
208
  ---
135
209
 
136
210
  ## Lazy initialization
@@ -170,6 +244,20 @@ options['model'] # also works
170
244
  This eliminates a whole class of symbol-vs-string bugs. When building option
171
245
  hashes, use `IndiferentHash.setup(hash)` rather than a plain Hash.
172
246
 
247
+ The same library carries the option idioms used throughout the codebase:
248
+ `IndiferentHash.add_defaults(hash, defaults)` fills missing keys without
249
+ overwriting, `process_options(hash, :a, :b)` extracts and removes several keys
250
+ in one call, and `IndiferentHash.parse_options("model=x backend=y")` turns a
251
+ `key=value` string into a hash. `Scout::Config.get(:key, *tokens, env:,
252
+ default:)` resolves configuration through the same cascade: explicit option →
253
+ environment variable → config file tokens → default.
254
+
255
+ API keys ride the same cascade rather than being read by the provider gems'
256
+ own env vars: each adapter looks its `key` up through `Scout::Config.get` with
257
+ its `TAG` token (`OPENAI_KEY`/`ANTHROPIC_KEY`/…). Exporting
258
+ `OPENAI_API_KEY` alone configures nothing — set `<TAG>_KEY` or put `key:` in
259
+ the endpoint YAML.
260
+
173
261
  ---
174
262
 
175
263
  ## Idiomatic patterns to follow
@@ -206,19 +294,38 @@ chat.follow(step(:plan).load)
206
294
  chat = step(:plan).load + chat
207
295
  ```
208
296
 
297
+ ### Branch before diverging
298
+
299
+ `chat.branch` returns an annotated duplicate of the conversation, so an
300
+ exploration can run without mutating the original — the cheap way to try two
301
+ prompt variants off the same history.
302
+
303
+ ```ruby
304
+ variant = chat.branch
305
+ variant.system("Answer in one word")
306
+ ```
307
+
209
308
  ### Prefer `proc` blocks for tools
210
309
 
211
310
  ```ruby
212
- # Good — Proc-based tool
213
- LLM.add_tool(
214
- "my_tool",
215
- "Does something useful",
216
- {"type" => "object", "properties" => {...}}
217
- ) do |name, params|
218
- # tool implementation
219
- end
311
+ # Good — a Proc executor paired with an LLM.tool_definition schema
312
+ block = ->(name, params) { ... } # receives (tool_name, arguments)
313
+ definition = LLM.tool_definition(
314
+ 'my_tool', 'Does something useful',
315
+ { query: { type: 'string' } }, required: [:query]
316
+ )
317
+ agent.other_options[:tools]['my_tool'] = [block, definition] # [executor, definition]
220
318
  ```
221
319
 
320
+ The registry entry is always the pair `[executor, definition]`; a `Proc`
321
+ executor is the plainest kind and is what the agent-layer tools (`attach`,
322
+ `ask`, `hand_off_to_*`) use.
323
+
324
+ Note the merge order the agent applies: per-call `options[:tools]` is merged
325
+ over the agent's construction-time tools, and the auto-wired workflow and
326
+ knowledge-base tools are merged **last**, so a name you register explicitly
327
+ wins over an auto-generated one with the same name.
328
+
222
329
  ---
223
330
 
224
331
  ## Anti-patterns to avoid
@@ -235,6 +342,89 @@ end
235
342
  use `social_duplicate` patterns.
236
343
  8. **Hard-coding agent names in delegation logic** — Let the model choose via
237
344
  `socialize`, or use `delegate` with explicit instances.
345
+ 9. **Treating a `false` option as "unset"** — `opt ||= default` silently
346
+ discards an explicit `false`. Use `opt = default if opt.nil?` when the
347
+ caller must be able to opt out (this bit `persist: false`).
348
+ 10. **Adding a new backend through name-mangling** — `LLM::BACKENDS` +
349
+ `LLM.register_backend(name, mod)` is the only extension seam; an
350
+ unregistered symbol raises, it is not resolved as a module name.
351
+ 11. **Scattering file I/O on plain Strings** — Use `Path` for anything that
352
+ participates in Scout's path system (`Scout.var`, `Scout.chats`,
353
+ `.find`, `.exists?`) and `Open` for reads/writes and `Open.remote?`, so
354
+ the same code works from a workflow job, the CLI, and an agent society.
355
+ 12. **Parsing chat text yourself** — a new role belongs in the Chat annotation
356
+ module (plus `chat/parse.rb` / `chat/process/` if it needs compilation
357
+ rules); ad-hoc regex rewriting of message content bypasses the pipeline.
358
+ 13. **Reimplementing what scout-essentials ships** — `TSV.traverse` for
359
+ parallel iteration over a TSV (or any index), `Open.remote?` for URL
360
+ checks, `Persist.persist` for the compute-once cache. Writing a local
361
+ replacement duplicates a battle-tested path system.
362
+ 14. **Reading a plain `Hash` of user options with symbol keys** — `options[:model]`
363
+ misses a caller's `'model'`. `IndiferentHash.setup` any hash that came
364
+ from user input, parsed JSON, or kwargs before reading it.
365
+ 15. **Mixing a class-state mixin with plain `include`** — `include_workflow`
366
+ merges helpers and task state into the receiving Workflow module; a plain
367
+ `include` copies no class-level state, so `self.agent`/`self.chat` are
368
+ missing at run time even though the file loads.
369
+
370
+ Several anti-patterns are pinned by regression tests: delegation behavior by
371
+ `test/scout/llm/agent/` (`test_delegate.rb`, `test_conversation.rb`,
372
+ `test_save.rb`, `test_workflow.rb`), backend registration and dispatch by
373
+ `test/scout/llm/test_request_context.rb` (a test backend registered via
374
+ `LLM.register_backend`) plus the provider suites in
375
+ `test/scout/llm/backends/`, and prompt ephemerality (#6) by
376
+ `test/scout/llm/chat/test_prompt.rb`.
377
+
378
+ ---
379
+
380
+ ## File and method naming
381
+
382
+ File paths mirror module nesting: `LLM::Agent` lives in
383
+ `lib/scout/llm/agent.rb`, and a behavior extension of the same class lives in
384
+ `lib/scout/llm/agent/<aspect>.rb` (`agent/delegate.rb`, `agent/conversation.rb`).
385
+ Annotation bodies sit in `<name>/annotation.rb`, per-aspect chat processing
386
+ in `chat/process/<aspect>.rb`, and provider adapters in
387
+ `backends/<provider>.rb`. Agent directory files are lowercase and
388
+ extension-free except `workflow.rb` and `agent.rb`.
389
+
390
+ Method names follow the role they play: DSL actions are verbs
391
+ (`user`, `system`, `ask`, `follow`), queries are nouns or predicates
392
+ (`current_chat`, `answer`, `exists?`), Workflow helpers are declared with
393
+ `helper :name do ... end`, predicates end in `?` (`exists?`, `remote?`,
394
+ `is_filename?`), and the `setup` class method always means "annotate this
395
+ plain object" (`Chat.setup`, `IndiferentHash.setup`).
396
+
397
+ Variable names carry the same conventions: `messages`/`chat` for conversation
398
+ arrays, `options` (always an `IndiferentHash`) for option hashes,
399
+ `path`/`dir`/`file` for `Path` objects, and `agent` for `LLM::Agent`
400
+ instances.
401
+
402
+ ---
403
+
404
+ ## The Scout-AI coding mindset
405
+
406
+ 1. **Data is plain.** Chats are Arrays, options are Hashes. Annotate, don't wrap.
407
+ 2. **Compose, don't inherit.** Use modules, `extend`, `include`, `prepend`.
408
+ 3. **One abstraction, one responsibility.** Chat holds conversation. Agent
409
+ holds state. Backend adapts to a provider. Tools define callable actions.
410
+ 4. **Convention discovers.** Directory structures and file names are the registry.
411
+ 5. **DSLs are methods on annotated objects.** Add methods to modules, get them
412
+ everywhere through annotation and `method_missing`.
413
+ 6. **Use the full stack.** `IndiferentHash` for options, `Path` for files,
414
+ `Scout::Config` for configuration, `Persist` for caching, `Log` for
415
+ logging. Don't reimplement.
416
+ 7. **Keep it serializable.** Everything can be written to disk and read back.
417
+ This is a feature, not a limitation.
418
+ 8. **Small files, clear boundaries.** `agent.rb` → `agent/chat.rb` →
419
+ `agent/delegate.rb`. Each file adds one concern.
420
+ 9. **Treat `false` as a value, not as "unset"** (see the anti-pattern list).
421
+ 10. **Derive, don't transcribe.** When a number or a claim can be produced by
422
+ code, make the code produce it and cite the job that produced it —
423
+ transcribed numbers rot and cannot be audited.
424
+
425
+ The guiding question when writing Scout-AI code: *can this be expressed as a
426
+ composition of existing abstractions, or does it need a new one — and if new,
427
+ is its boundary crisp?*
238
428
 
239
429
  ---
240
430
 
@@ -242,4 +432,3 @@ end
242
432
 
243
433
  - [Architecture.md](Architecture.md) — Overall system architecture.
244
434
  - [ChatLifecycle.md](ChatLifecycle.md) — Chat data model.
245
- - [../../research/coding-philosophy-analysis.md](../../research/coding-philosophy-analysis.md) — Deep investigation.