scout-ai 1.2.3 → 2.0.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 (174) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +138 -50
  3. data/README.md +171 -290
  4. data/Rakefile +17 -1
  5. data/VERSION +1 -1
  6. data/doc/Improvements.md +325 -0
  7. data/doc/StartHere.md +110 -0
  8. data/doc/developer/Architecture.md +126 -0
  9. data/doc/developer/Backends.md +199 -0
  10. data/doc/developer/ChatLifecycle.md +183 -0
  11. data/doc/developer/DelegationInternals.md +295 -0
  12. data/doc/developer/DesignPrinciples.md +245 -0
  13. data/doc/developer/PromptProcessing.md +292 -0
  14. data/doc/developer/Provenance.md +317 -0
  15. data/doc/user/BuildingAgents.md +345 -0
  16. data/doc/user/Cookbook.md +333 -0
  17. data/doc/user/CoreConcepts.md +181 -0
  18. data/doc/user/Delegation.md +191 -0
  19. data/doc/user/GettingStarted.md +159 -0
  20. data/doc/user/ManagingContext.md +163 -0
  21. data/doc/user/MultiAgentWorkflows.md +256 -0
  22. data/doc/user/Python.md +159 -0
  23. data/doc/user/RunningInference.md +200 -0
  24. data/doc/user/ToolCalling.md +193 -0
  25. data/doc/user/WritingChats.md +197 -0
  26. data/lib/scout/llm/agent/chat.rb +61 -11
  27. data/lib/scout/llm/agent/delegate.rb +274 -65
  28. data/lib/scout/llm/agent/iterate.rb +2 -2
  29. data/lib/scout/llm/agent/save.rb +273 -0
  30. data/lib/scout/llm/agent/workflow.rb +164 -0
  31. data/lib/scout/llm/agent.rb +86 -61
  32. data/lib/scout/llm/ask.rb +62 -17
  33. data/lib/scout/llm/backends/anthropic.rb +9 -2
  34. data/lib/scout/llm/backends/bedrock.rb +15 -3
  35. data/lib/scout/llm/backends/default.rb +183 -99
  36. data/lib/scout/llm/backends/glm.rb +58 -0
  37. data/lib/scout/llm/backends/huggingface.rb +196 -26
  38. data/lib/scout/llm/backends/ollama.rb +13 -1
  39. data/lib/scout/llm/backends/openai.rb +0 -2
  40. data/lib/scout/llm/backends/openwebui.rb +20 -13
  41. data/lib/scout/llm/backends/relay.rb +22 -22
  42. data/lib/scout/llm/backends/responses.rb +1 -1
  43. data/lib/scout/llm/chat/agent_meta.rb +264 -0
  44. data/lib/scout/llm/chat/annotation.rb +39 -10
  45. data/lib/scout/llm/chat/parse.rb +28 -6
  46. data/lib/scout/llm/chat/persist.rb +25 -0
  47. data/lib/scout/llm/chat/process/clear.rb +41 -6
  48. data/lib/scout/llm/chat/process/files.rb +21 -6
  49. data/lib/scout/llm/chat/process/meta.rb +421 -34
  50. data/lib/scout/llm/chat/process/options.rb +21 -1
  51. data/lib/scout/llm/chat/process/tools.rb +56 -15
  52. data/lib/scout/llm/chat/process.rb +4 -0
  53. data/lib/scout/llm/chat/prompt/shorten_tools.rb +125 -0
  54. data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +365 -0
  55. data/lib/scout/llm/chat/prompt.rb +48 -0
  56. data/lib/scout/llm/chat/provenance.rb +775 -0
  57. data/lib/scout/llm/chat/tool_calls.rb +76 -0
  58. data/lib/scout/llm/chat.rb +18 -2
  59. data/lib/scout/llm/embed.rb +11 -3
  60. data/lib/scout/llm/image.rb +86 -0
  61. data/lib/scout/llm/mcp.rb +10 -2
  62. data/lib/scout/llm/rag.rb +3 -3
  63. data/lib/scout/llm/tools/call.rb +160 -11
  64. data/lib/scout/llm/tools/knowledge_base.rb +1 -1
  65. data/lib/scout/llm/tools/workflow.rb +32 -16
  66. data/lib/scout/model/python/huggingface/causal.rb +23 -5
  67. data/lib/scout/model/python/huggingface.rb +2 -1
  68. data/lib/scout-ai.rb +1 -0
  69. data/python/README.md +197 -14
  70. data/python/scout_ai/huggingface/eval.py +245 -34
  71. data/python/tests/test_huggingface_eval.py +58 -0
  72. data/research/ChatAnalyst-required-changes.md +167 -0
  73. data/research/agent-delegation-analysis.md +810 -0
  74. data/research/agent-meta-provenance-integration-plan.md +622 -0
  75. data/research/agent-workflow-analysis.md +1120 -0
  76. data/research/backends-analysis.md +836 -0
  77. data/research/chat-core-analysis.md +946 -0
  78. data/research/chatanalyst-provenance/00-baseline.md +30 -0
  79. data/research/chatanalyst-provenance/01-repo-map.md +60 -0
  80. data/research/chatanalyst-provenance/02-event-reconstruction.md +55 -0
  81. data/research/chatanalyst-provenance/03-duplication-evidence.md +45 -0
  82. data/research/chatanalyst-provenance/04-tooling-root-cause.md +57 -0
  83. data/research/chatanalyst-provenance/05-fix-plan.md +46 -0
  84. data/research/chatanalyst-provenance/07-critic-review.md +25 -0
  85. data/research/chatanalyst-provenance/final-report.md +45 -0
  86. data/research/chatanalyst-provenance/resumption.md +37 -0
  87. data/research/coding-philosophy-analysis.md +928 -0
  88. data/research/commands-analysis.md +947 -0
  89. data/research/multi-agent-patterns-analysis.md +853 -0
  90. data/research/prompt-strategies-analysis.md +630 -0
  91. data/research/prov-verbosity-fix-notes.md +77 -0
  92. data/research/provenance-analysis.md +469 -0
  93. data/research/provenance-navigation-design.md +640 -0
  94. data/research/synthesis-report.md +487 -0
  95. data/research/tools-system-analysis.md +779 -0
  96. data/scout-ai.gemspec +100 -11
  97. data/scout_commands/agent/ask +13 -3
  98. data/scout_commands/agent/kb +2 -0
  99. data/scout_commands/llm/ask +11 -4
  100. data/scout_commands/llm/md +76 -0
  101. data/scout_commands/llm/process_queries +48 -0
  102. data/scout_commands/llm/prov +602 -0
  103. data/scout_commands/llm/word +71 -0
  104. data/scout_commands/workflow/mcp +43 -0
  105. data/share/word/reference.docx +0 -0
  106. data/test/etc/AI/mock.yaml +11 -0
  107. data/test/fixtures/backends/anthropic.json +19 -0
  108. data/test/fixtures/backends/anthropic_tool_use.json +24 -0
  109. data/test/fixtures/backends/bedrock.json +8 -0
  110. data/test/fixtures/backends/bedrock_embedding.json +3 -0
  111. data/test/fixtures/backends/bedrock_tool_use.json +17 -0
  112. data/test/fixtures/backends/ollama.json +16 -0
  113. data/test/fixtures/backends/ollama_tool_call.json +27 -0
  114. data/test/fixtures/backends/openai_chat.json +21 -0
  115. data/test/fixtures/backends/openai_chat_tool_call.json +31 -0
  116. data/test/fixtures/backends/responses.json +33 -0
  117. data/test/fixtures/backends/responses_tool_call.json +28 -0
  118. data/test/integration/README.md +32 -0
  119. data/test/integration/scout/llm/backends/test_endpoints.rb +34 -0
  120. data/test/integration/scout/llm/backends/test_openwebui.rb +61 -0
  121. data/test/integration/scout/llm/backends/test_relay.rb +52 -0
  122. data/test/integration/scout/llm/test_infrastructure.rb +74 -0
  123. data/test/{scout → integration/scout}/llm/test_mcp.rb +1 -1
  124. data/test/integration/scout/llm/tools/test_mcp.rb +42 -0
  125. data/test/integration/scout/model/test_base.rb +91 -0
  126. data/test/scout/llm/agent/test_chat.rb +8 -2
  127. data/test/scout/llm/agent/test_save.rb +413 -0
  128. data/test/scout/llm/agent/test_workflow.rb +110 -0
  129. data/test/scout/llm/backends/test_anthropic.rb +93 -10
  130. data/test/scout/llm/backends/test_bedrock.rb +118 -2
  131. data/test/scout/llm/backends/test_huggingface.rb +137 -42
  132. data/test/scout/llm/backends/test_ollama.rb +70 -20
  133. data/test/scout/llm/backends/test_openwebui.rb +42 -40
  134. data/test/scout/llm/backends/test_relay.rb +4 -2
  135. data/test/scout/llm/chat/agent_meta_fixtures.rb +131 -0
  136. data/test/scout/llm/chat/process/test_meta.rb +518 -0
  137. data/test/scout/llm/chat/process/test_normalize_usage.rb +183 -0
  138. data/test/scout/llm/chat/test_agent_meta.rb +357 -0
  139. data/test/scout/llm/chat/test_agent_meta_provenance.rb +467 -0
  140. data/test/scout/llm/chat/test_agent_meta_tokens.rb +594 -0
  141. data/test/scout/llm/chat/test_parse.rb +70 -15
  142. data/test/scout/llm/chat/test_prov_cli.rb +274 -0
  143. data/test/scout/llm/chat/test_provenance.rb +240 -0
  144. data/test/scout/llm/chat/test_tool_calls.rb +38 -0
  145. data/test/scout/llm/test_agent.rb +13 -36
  146. data/test/scout/llm/test_ask.rb +75 -52
  147. data/test/scout/llm/test_chat.rb +107 -13
  148. data/test/scout/llm/test_embed.rb +48 -0
  149. data/test/scout/llm/test_rag.rb +23 -16
  150. data/test/scout/llm/test_tools.rb +12 -1
  151. data/test/scout/llm/tools/test_knowledge_base.rb +0 -1
  152. data/test/scout/llm/tools/test_mcp.rb +5 -3
  153. data/test/scout/llm/tools/test_workflow.rb +23 -2
  154. data/test/scout/model/python/huggingface/causal/test_next_token.rb +11 -5
  155. data/test/scout/model/python/huggingface/test_causal.rb +9 -3
  156. data/test/scout/model/python/huggingface/test_classification.rb +11 -2
  157. data/test/scout/model/python/test_torch.rb +2 -0
  158. data/test/scout/model/python/torch/test_helpers.rb +4 -0
  159. data/test/scout/model/test_base.rb +4 -2
  160. data/test/support/availability.rb +231 -0
  161. data/test/support/fake_clients.rb +138 -0
  162. data/test/support/fixtures.rb +21 -0
  163. data/test/support/infrastructure_probes.rb +136 -0
  164. data/test/support/mock_backend.rb +215 -0
  165. data/test/test_helper.rb +32 -2
  166. metadata +99 -10
  167. data/doc/Agent.md +0 -327
  168. data/doc/Chat.md +0 -458
  169. data/doc/LLM.md +0 -340
  170. data/doc/RAG.md +0 -129
  171. data/scout_commands/documenter +0 -148
  172. data/test/scout/llm/backends/test_openai.rb +0 -192
  173. data/test/scout/llm/backends/test_responses.rb +0 -238
  174. data/test/scout/llm/test_parse.rb +0 -98
@@ -0,0 +1,167 @@
1
+ # ChatAnalyst — required changes for the new scout-ai save layout
2
+
3
+ Commentary only (NOT an implementation plan executed here). Grounded in the
4
+ actual files of `/home/mvazque2/git/workflows/ChatAnalyst` (workflow.rb,
5
+ README.md, test/, tmp/ verify scripts) and in the scout-ai changes of steps
6
+ 1-3b (artifacts `var/cortex/artifacts/society-save/*.md`).
7
+
8
+ New layout recap: `<chat>.files/<name>.chat` (`agent.chat` default,
9
+ `worker.chat` for named), society tree `<name>.society/<Agent>/<conv>/agent.chat`
10
+ (plain `society` sibling at depth >= 1). Legacy `.files/log/**` stays readable,
11
+ never written, never migrated.
12
+
13
+ ## 1. What already works for free (no change needed)
14
+
15
+ `workflow.rb` contains **no layout hardcoding at all**. Its only `.files`
16
+ mention is a comment in `helper :resolve_root` ("a `.files` directory alone is
17
+ not evidence: saved agent chats carry one too. Only the `.info` test decides,
18
+ and the chat branch then relies on scout-ai provenance to scan the sidecar"),
19
+ and that reasoning is layout-independent and still correct: the new layout
20
+ also gives saved chats a `.files` dir without `.info`, while jobs keep `.info`.
21
+
22
+ All discovery goes through the shared scout-ai APIs, which are now
23
+ dual-layout:
24
+
25
+ - `Chat.provenance_token_events` / `Chat.provenance_edges` /
26
+ `Chat.provenance_chat_files` / `Chat.provenance_jobs` (called in
27
+ `helper :provenance_data`, lines ~194-228) all wrap
28
+ `Chat.traverse_provenance`, which now globs `*.files/*.chat`,
29
+ `*.files/*.society/**/*.chat` and the legacy `*.files/log/**/*.chat`,
30
+ de-duplicated and sorted;
31
+ - job-vs-chat classification, the root-copy exclusion
32
+ (`Chat.direct_chat_sidecar_files`) and the `:log` relation semantics live in
33
+ scout-ai (`lib/scout/llm/chat/provenance.rb`), not here;
34
+ - no task input consumes a log path, no task globs `.files` itself
35
+ (`grep -n "task :"` shows only `file/ids/role/…` inputs; the only path
36
+ computation is `resolve_root`, which resolves a *chat or job path*, never a
37
+ log path);
38
+ - `short_path` only collapses `$HOME`, so the longer
39
+ `<name>.society/<Agent>/<conv>/agent.chat` paths just render fully — no
40
+ truncation or matching by suffix anywhere.
41
+
42
+ Consequence: every task that takes a chat or job root (message_index,
43
+ message_content, chat_overview, chat_tool_calls, chat_tokens, chat_agents,
44
+ meta_evidence, chat_reasoning, chat_report, provenance_relationships,
45
+ chat_accounting) keeps working on chats produced by the new layout, and on
46
+ mixed old+new trees, with zero code change.
47
+
48
+ ## 2. What WOULD break (if scout-ai had not been dual-layout)
49
+
50
+ Nothing in ChatAnalyst hardcodes `log/`, so nothing breaks outright. The
51
+ failure mode the scout-ai change guards against — and which ChatAnalyst would
52
+ have inherited if it had hardcoded anything — is:
53
+
54
+ - assuming society chats live under `.files/log/society/...`: a glob or
55
+ regex pinned to that prefix would silently find nothing in new trees;
56
+ - assuming a chat's own copy is exactly `<chat>.files/log/agent.chat`: the
57
+ new equivalent is any top-level `<chat>.files/<name>.chat` (and named agents
58
+ write `<name>.chat`);
59
+ - assuming `resets/` is the only sibling of `log/`: in the new layout the
60
+ society dir is `<name>.society`, so any "everything under `.files` except
61
+ `resets`" sweep would now also pick up society trees twice.
62
+
63
+ ## 3. README is outdated (real gap)
64
+
65
+ `README.md` states the OLD layout as current:
66
+
67
+ - line 5: "all `.files/log/**/*.chat` files — including the regular
68
+ `log/agent.chat` logs";
69
+ - lines 9-11: "`<chat>.files/log/society/<agent>/<conversation>/agent.chat`
70
+ appear as chats (the chat's own root copy at `log/agent.chat` is skipped)";
71
+ - line 70: `<caller_job>.files/log/chats/<AgentName>/<conversation_name>.chat`
72
+ for socialized chat *projections* (this is a different, older projection
73
+ mechanism that predates the society tree; it should be described as
74
+ historical/legacy).
75
+
76
+ Needed: describe the three glob families (`*.files/*.chat`,
77
+ `*.files/*.society/**/*.chat`, legacy `*.files/log/**/*.chat` read-only), the
78
+ named-file rule (`agent.chat` default, `worker.chat` for named agents), the
79
+ nested plain-`society` sibling rule, and label `log/chats/…` projections and
80
+ the whole `log/` layout as legacy. Recommended wording for the projection
81
+ path: keep the `<caller_job>.files/log/chats/...` line but prefix it with
82
+ "(legacy mechanism)" and add the current society path
83
+ `<caller_job>.files/<name>.society/<AgentName>/<conversation>/agent.chat`.
84
+
85
+ ## 4. Tests: keep the legacy fixtures, they are on purpose
86
+
87
+ `test/scout/agent_meta_fixtures.rb` builds the OLD layout deliberately:
88
+
89
+ - `make_job(..., logs: {...})` writes `<job>.files/log/<name>` — this is the
90
+ **legacy job-log emulation** and must keep working: traversal stays
91
+ dual-layout, so these fixtures keep passing unchanged. This is exactly the
92
+ read-only compatibility guarantee step 3 added tests for
93
+ (`test/scout/llm/chat/test_new_layout_provenance.rb` in scout-ai).
94
+ - `make_saved_chat(...)` writes the root copy at `log/agent.chat` plus society
95
+ under `log/society/<agent>/<conv>/agent.chat` — again the legacy chat
96
+ sidecar shape.
97
+ - `test/test_agent_meta_tasks.rb` line ~193 asserts
98
+ `%r{files/log/society/Worker/default/agent\.chat}` and line ~199 counts
99
+ copies matching `%r{\.files/log/agent\.chat\z}`; both still pass because
100
+ the fixtures are legacy and the traversal reads legacy.
101
+
102
+ What to do if new-layout coverage is ever wanted (commentary, not done here):
103
+
104
+ - add `make_job`/`make_saved_chat` keyword variants (e.g. `layout: :new`) or
105
+ two new builders writing `<job>.files/agent.chat` +
106
+ `<job>.files/agent.society/...`, rather than changing the existing ones —
107
+ the existing ones ARE the legacy coverage;
108
+ - keep the regexes layout-agnostic where the intent is layout-independent,
109
+ e.g. `%r{\.files/(?:agent\.society|log/society)/Worker/default/agent\.chat}`
110
+ and `%r{\.files/(?:agent|log/agent)\.chat\z}`;
111
+ - add one fixture where both layouts coexist in one `.files` dir to cover the
112
+ de-duplication guarantee (a chat must be counted once).
113
+
114
+ ## 5. tmp/ verify scripts use old-layout fixtures (scratch only)
115
+
116
+ All five are one-off scratch scripts, not part of any suite:
117
+
118
+ - `tmp/verify_society_dedupe.rb` — builds `base + '.files/log/society/Worker/default/agent.chat'`;
119
+ - `tmp/verify_root_sidecar.rb` — root chat + `log/agent.chat` + legacy society;
120
+ - `tmp/check_current_format.rb` — `job + '.files/log/agent.chat'`;
121
+ - `tmp/check_resets_visibility.rb` — `root_save = job + '.files/log/agent.chat'`;
122
+ - `tmp/verify_resets2.rb` — `base + '.files/log/agent.chat'` and a deliberately
123
+ mis-placed `log/resets/…` snapshot to prove `resets/` under `log/` IS swept.
124
+
125
+ None of them needs a fix to keep running (they still exercise the legacy
126
+ read path), but note for `verify_resets2.rb`: the "hypothetical wrong
127
+ placement" it tests is now doubly legacy — in the new layout a wrongly placed
128
+ reset would be `<name>.society/resets/…` or a top-level `<name>.chat`-adjacent
129
+ path, so if the script is ever refreshed, add the new-layout equivalents
130
+ (resets next to `agent.society/`, resets next to top-level `agent.chat`) to
131
+ keep the "resets are invisible" guarantee meaningful.
132
+
133
+ ## 6. Task-input / tooling implications
134
+
135
+ - **Inputs are unaffected.** Every task takes a chat file or job path as
136
+ `file`; the new layout only changes what is *inside* `<that path>.files`.
137
+ - **Consuming new-layout chats is automatic.** A chat saved by the new
138
+ `scout-ai llm ask -c` / `agent ask -c` (root copy at
139
+ `<chat>.files/agent.chat`, society under `<chat>.files/agent.society/…`) is
140
+ resolved by `resolve_root` exactly like before, and its society
141
+ conversations appear in `:chats` via the shared traversal.
142
+ - **The hidden top-level `agent.chat` rule affects tooling that assumes job
143
+ log visibility.** `scout-ai llm prov` hides a basename `agent.chat` whose
144
+ parent is `<something>.files` or a legacy `.../log` dir, because it
145
+ duplicates the job node. ChatAnalyst does NOT apply that rule — it reports
146
+ every chat `provenance_chat_files` returns, including a job's own
147
+ `<job>.files/agent.chat` — which is intentional there (the analyst is
148
+ supposed to show the full conversation per file), but any tooling copied
149
+ from `prov`'s tree renderer must replicate the hiding rule or it will show a
150
+ job twice. Conversely, any tooling that assumed "a job always has a visible
151
+ `log/agent.chat` child" now sees nothing under `log/` for new jobs and must
152
+ look at top-level `agent.chat` / `<name>.society/` instead.
153
+ - **Mixed trees are the norm during rollout.** Old `.files/log/**` next to new
154
+ `*.files/*.chat` in the same dir yields a single de-duplicated visit per
155
+ chat (scout-ai guarantee), so reports do not double count; ChatAnalyst's own
156
+ `warning_key` deduplication of warnings is unaffected.
157
+
158
+ ## 7. Summary of concrete actions (for the ChatAnalyst owner)
159
+
160
+ 1. Update `README.md` sections quoted in §3 to the new layout, labeling
161
+ `log/**` (and `log/chats/…` projections) as legacy/read-only. **Only real
162
+ change needed.**
163
+ 2. Optionally add new-layout fixtures + assertions to
164
+ `test/test_agent_meta_tasks.rb` following §4 (add, do not rewrite).
165
+ 3. Optionally refresh the five `tmp/verify_*` scripts per §5.
166
+ 4. No `workflow.rb` change required: it is fully layout-agnostic through the
167
+ shared `Chat.traverse_provenance` / `Chat.provenance_*` APIs.