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
@@ -0,0 +1,188 @@
1
+ module Chat
2
+
3
+ # --- inbox strategy configuration ---
4
+
5
+ # Suffixes naming the inbox directories. Both are SIBLINGS of the chat's
6
+ # save_file, in that file's own directory: the save_file basename's LAST
7
+ # extension is stripped and the suffix appended.
8
+ #
9
+ # '<X>.files/agent.chat' -> '<X>.files/agent.inbox'
10
+ # -> '<X>.files/agent.inbox_removed'
11
+ # 'a.b.chat' -> 'a.b.inbox' / 'a.b.inbox_removed' (multi-dot
12
+ # basenames strip only the last extension)
13
+ # 'agent' (no extension) -> 'agent.inbox' / 'agent.inbox_removed'
14
+ #
15
+ # The same sibling rule derives the live-workload sidecar `<base>.jobs` (see
16
+ # `Chat.jobs_file`), so all chat-state siblings of a save_file share ONE
17
+ # stem derivation (`Chat.inbox_stem`).
18
+ #
19
+ # Both are invisible to the provenance globs (`'*.chat'`,
20
+ # `'*.society/**/*.chat'` in Chat::DIRECT_LOG_CHAT_GLOBS), so inbox files are
21
+ # never mistaken for chat logs.
22
+ INBOX_SUFFIX = '.inbox'
23
+ INBOX_REMOVED_SUFFIX = '.inbox_removed'
24
+
25
+ # Live-workload sidecar suffix: `<base>.jobs` is a SIBLING FILE of the chat
26
+ # save_file listing the workflow jobs currently in flight under it.
27
+ JOBS_SUFFIX = '.jobs'
28
+
29
+ # Reserved inbox filename. When pickup reaches a regular file with exactly
30
+ # this name it is consumed exactly once (moved into `.inbox_removed` like
31
+ # any other file, mtime preserved) and the inference is aborted by raising
32
+ # the framework-native `Aborted` exception; the file content NEVER reaches
33
+ # the model -- instead it becomes the abort reason. Files sorted before it
34
+ # in the same pickup are processed normally first; files sorted after it
35
+ # stay in the inbox for the next run.
36
+ INBOX_ABORT_FILE = 'abort'
37
+
38
+ # --- inbox strategy ---
39
+
40
+ # Consume-once message inbox.
41
+ #
42
+ # Unlike the `shorten_*` strategies, `inbox` is NOT purely ephemeral: on
43
+ # every real inference it consumes the regular files found in the inbox
44
+ # sibling of the chat's save_file (see `Chat.inbox_dir`), moving each into
45
+ # the matching `.inbox_removed` sibling (mtime preserved, numeric suffix on
46
+ # name collision) and appending one `{role: 'user'}` message carrying the
47
+ # file content to the outgoing prompt.
48
+ #
49
+ # The filename `abort` (see INBOX_ABORT_FILE) is reserved: reaching it ends
50
+ # the pickup by raising `Aborted` (the framework-native user-interrupt
51
+ # exception, see scout-essentials exceptions.rb / scout-gear step.rb, which
52
+ # records the job as :aborted instead of :error), with the file content as
53
+ # the abort reason. Messages collected from files sorted before it are
54
+ # appended first, but never sent anywhere because the raise happens before
55
+ # the strategy returns; files after it are not touched.
56
+ #
57
+ # Ordering is deliberate: a file is moved BEFORE its content is read and
58
+ # appended, so a crash between the two may drop a notice but can never
59
+ # deliver the same notice twice.
60
+ #
61
+ # Injected messages are seen by the model but never persisted into the chat
62
+ # transcript; `.inbox_removed` is the record of what was delivered.
63
+ #
64
+ # Gating: without a save_file, or when the inbox directory does not exist,
65
+ # this is a silent no-op that creates no directories (the read path never
66
+ # creates the inbox; writers create it themselves).
67
+ def self.inbox(messages, save_file: nil)
68
+ return messages if save_file.nil? || save_file.to_s.empty?
69
+
70
+ inbox_dir = Chat.inbox_dir(save_file)
71
+ return messages unless File.directory?(inbox_dir)
72
+
73
+ # Top-level regular files only (glob '*' skips dotfiles, subdirectories
74
+ # are filtered out), sorted by filename so delivery order is
75
+ # deterministic.
76
+ files = Dir.glob(File.join(inbox_dir, '*')).select{|f| File.file?(f) }.sort
77
+ return messages if files.empty?
78
+
79
+ additions = []
80
+ aborted_reason = nil
81
+ files.each do |file|
82
+ begin
83
+ # Unreadable files are skipped in place: moving one would take it out
84
+ # of reach while failing to deliver it.
85
+ next unless File.readable?(file)
86
+
87
+ mtime = File.mtime(file)
88
+ target = Chat.inbox_removed_target(file, save_file)
89
+ FileUtils.mv(file, target)
90
+ File.utime(mtime, mtime, target)
91
+
92
+ if File.basename(target) == INBOX_ABORT_FILE
93
+ # Reserved filename: consumed once, content becomes the abort
94
+ # reason, delivery of any remaining files is deferred to the next
95
+ # run, and nothing else is appended to the prompt.
96
+ content = Open.read(target)
97
+ aborted_reason = content.strip.empty? ? "Inbox abort: #{target}" : "Inbox abort: #{content.strip}"
98
+ break
99
+ end
100
+ additions << { role: 'user', content: Open.read(target) }
101
+ rescue Exception => e
102
+ # One bad file must never break the ask path: skip it and continue
103
+ # with the rest. The file stays wherever the failure caught it (in
104
+ # the inbox if the move failed, already in `.inbox_removed` if the
105
+ # read failed), so the next inference can still make progress.
106
+ Log.low "Inbox: skipping unreadable/unmovable file #{file}: #{e.message}"
107
+ next
108
+ end
109
+ end
110
+
111
+ if aborted_reason
112
+ Log.low "Inbox: aborting inference (#{aborted_reason})"
113
+ raise Aborted, aborted_reason
114
+ end
115
+
116
+ return messages if additions.empty?
117
+
118
+ Log.low "Inbox: appended #{additions.length} message(s) from #{inbox_dir}"
119
+
120
+ # ScoutCoder: Array#+ on a Chat-annotated array returns a plain Array --
121
+ # the Chat annotation is not carried through +, concat or flatten, so any
122
+ # strategy that rebuilds the message list must re-annotate with
123
+ # Chat.setup or downstream code (Chat.clean/purge/format_messages) sees a
124
+ # bare Array.
125
+ Chat.setup(messages + additions)
126
+ end
127
+
128
+ # Inbox directory of a chat save_file: SIBLING of the save_file in its own
129
+ # directory, named after the save_file basename with its LAST extension
130
+ # stripped plus '.inbox'. An extension-less basename keeps the whole name
131
+ # ('agent' -> 'agent.inbox'); a multi-dot basename strips only the last
132
+ # extension ('a.b.chat' -> 'a.b.inbox').
133
+ def self.inbox_dir(save_file)
134
+ File.join(File.dirname(save_file.to_s), Chat.inbox_stem(save_file) + INBOX_SUFFIX)
135
+ end
136
+
137
+ # Directory holding the record of delivered files: same sibling derivation
138
+ # as `Chat.inbox_dir`, with the '.inbox_removed' suffix.
139
+ def self.inbox_removed_dir(save_file)
140
+ File.join(File.dirname(save_file.to_s), Chat.inbox_stem(save_file) + INBOX_REMOVED_SUFFIX)
141
+ end
142
+
143
+ # Save_file basename with its LAST extension removed ('agent.chat' ->
144
+ # 'agent', 'a.b.chat' -> 'a.b', 'agent' -> 'agent').
145
+ def self.inbox_stem(save_file)
146
+ base = File.basename(save_file.to_s)
147
+ ext = File.extname(base)
148
+ ext.empty? ? base : base[0...-ext.length]
149
+ end
150
+
151
+ # Live-workload sidecar of a chat save_file: SIBLING FILE in the save_file's
152
+ # own directory, derived with the SAME trailing-strip rule as the inbox dirs
153
+ # (`Chat.inbox_stem`, which uses File.extname -- never a first-match sub).
154
+ #
155
+ # '<dir>/agent.chat' -> '<dir>/agent.jobs'
156
+ # '<job>.chat.files/agent.chat' -> '<job>.chat.files/agent.jobs'
157
+ # (trailing strip only: a '.chat' in an ANCESTOR component is never
158
+ # touched, unlike the historical unanchored sub)
159
+ # 'a.b.chat' / 'agent' -> 'a.b.jobs' / 'agent.jobs'
160
+ #
161
+ # Writers (LLM.process_calls) rewrite the file per round and remove it in an
162
+ # `ensure` once Workflow.produce returns; it is a snapshot, not an append log.
163
+ def self.jobs_file(save_file)
164
+ File.join(File.dirname(save_file.to_s), Chat.inbox_stem(save_file) + JOBS_SUFFIX)
165
+ end
166
+
167
+ # Return the `.inbox_removed/` target path for `file`, appending a numeric
168
+ # suffix on name collision so previous deliveries are never overwritten.
169
+ # `.inbox_removed/` is created lazily, only when a file is actually about to
170
+ # be moved; the read path never creates directories on its own.
171
+ def self.inbox_removed_target(file, save_file)
172
+ removed_dir = Chat.inbox_removed_dir(save_file)
173
+ FileUtils.mkdir_p(removed_dir) unless File.directory?(removed_dir)
174
+
175
+ name = File.basename(file)
176
+ target = File.join(removed_dir, name)
177
+ return target unless File.exist?(target)
178
+
179
+ ext = File.extname(name)
180
+ stem = ext.empty? ? name : name[0...-ext.length]
181
+ index = 1
182
+ loop do
183
+ target = File.join(removed_dir, "#{stem}.#{index}#{ext}")
184
+ return target unless File.exist?(target)
185
+ index += 1
186
+ end
187
+ end
188
+ end