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.
- checksums.yaml +4 -4
- data/.vimproject +135 -55
- data/README.md +2 -1
- data/VERSION +1 -1
- data/doc/Improvements.md +490 -148
- data/doc/Model.md +53 -10
- data/doc/StartHere.md +44 -19
- data/doc/developer/Architecture.md +25 -6
- data/doc/developer/Backends.md +207 -48
- data/doc/developer/ChatLifecycle.md +121 -20
- data/doc/developer/DelegationInternals.md +320 -34
- data/doc/developer/DesignPrinciples.md +205 -16
- data/doc/developer/PathEngine.md +628 -0
- data/doc/developer/PromptProcessing.md +332 -82
- data/doc/developer/Provenance.md +402 -44
- data/doc/developer/Sandbox.md +213 -0
- data/doc/user/BuildingAgents.md +130 -18
- data/doc/user/Cookbook.md +29 -8
- data/doc/user/CoreConcepts.md +7 -6
- data/doc/user/Delegation.md +166 -15
- data/doc/user/GettingStarted.md +20 -16
- data/doc/user/ManagingContext.md +155 -17
- data/doc/user/MultiAgentWorkflows.md +105 -15
- data/doc/user/Python.md +11 -1
- data/doc/user/RunningInference.md +90 -47
- data/doc/user/ToolCalling.md +134 -29
- data/doc/user/WritingChats.md +56 -27
- data/lib/scout/llm/agent/attach.rb +64 -0
- data/lib/scout/llm/agent/chat.rb +32 -0
- data/lib/scout/llm/agent/construction.rb +64 -0
- data/lib/scout/llm/agent/conversation.rb +304 -0
- data/lib/scout/llm/agent/delegate.rb +56 -238
- data/lib/scout/llm/agent/path/edit.rb +230 -0
- data/lib/scout/llm/agent/path/patch.rb +252 -0
- data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
- data/lib/scout/llm/agent/path.rb +1777 -0
- data/lib/scout/llm/agent/save.rb +11 -9
- data/lib/scout/llm/agent/workflow.rb +79 -17
- data/lib/scout/llm/agent.rb +151 -27
- data/lib/scout/llm/ask.rb +37 -27
- data/lib/scout/llm/backends/anthropic.rb +1 -1
- data/lib/scout/llm/backends/bedrock.rb +3 -2
- data/lib/scout/llm/backends/default.rb +131 -32
- data/lib/scout/llm/backends/glm.rb +28 -1
- data/lib/scout/llm/backends/huggingface.rb +1 -1
- data/lib/scout/llm/backends/ollama.rb +1 -1
- data/lib/scout/llm/backends/openai.rb +7 -6
- data/lib/scout/llm/backends/openwebui.rb +14 -7
- data/lib/scout/llm/backends/relay.rb +8 -2
- data/lib/scout/llm/chat/agent_meta.rb +24 -60
- data/lib/scout/llm/chat/parse.rb +1 -1
- data/lib/scout/llm/chat/process/files.rb +10 -0
- data/lib/scout/llm/chat/process/meta.rb +5 -7
- data/lib/scout/llm/chat/process/tools.rb +104 -52
- data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
- data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
- data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
- data/lib/scout/llm/chat/prompt.rb +24 -10
- data/lib/scout/llm/chat/provenance/live.rb +1080 -0
- data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
- data/lib/scout/llm/chat/provenance.rb +352 -626
- data/lib/scout/llm/chat.rb +8 -2
- data/lib/scout/llm/embed.rb +15 -3
- data/lib/scout/llm/image.rb +4 -1
- data/lib/scout/llm/mcp.rb +4 -2
- data/lib/scout/llm/request_context.rb +234 -0
- data/lib/scout/llm/sandbox.rb +263 -0
- data/lib/scout/llm/tools/call.rb +163 -42
- data/lib/scout/llm/tools/definition.rb +48 -0
- data/lib/scout/llm/tools/knowledge_base.rb +1 -0
- data/lib/scout/llm/tools/mcp.rb +50 -43
- data/lib/scout/llm/tools/workflow.rb +90 -20
- data/lib/scout/llm/tools.rb +14 -41
- data/lib/scout/model/decision/base.rb +43 -0
- data/lib/scout/model/decision/jev.rb +161 -0
- data/lib/scout/model/python/torch.rb +1 -1
- data/research/clear-tools-inherit.md +171 -0
- data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
- data/research/path-kind-chat-role.md +96 -0
- data/research/path-kind-contract-fixes-engine.md +307 -0
- data/research/scout-ai-runtime-availability.md +65 -0
- data/research/subsys/README.md +127 -0
- data/research/subsys/agent-delegation.md +201 -0
- data/research/subsys/agent-society.md +275 -0
- data/research/subsys/agentworkflow.md +233 -0
- data/research/subsys/backends.md +221 -0
- data/research/subsys/chat.md +314 -0
- data/research/subsys/embed-image.md +244 -0
- data/research/subsys/entry-cli.md +253 -0
- data/research/subsys/model-ml.md +326 -0
- data/research/subsys/provenance.md +290 -0
- data/research/subsys/tools.md +334 -0
- data/scout-ai.gemspec +72 -26
- data/scout_commands/agent/ask +8 -7
- data/scout_commands/llm/abridged +40 -0
- data/scout_commands/llm/ask +9 -9
- data/scout_commands/llm/md +2 -0
- data/scout_commands/llm/prov +845 -80
- data/scout_commands/llm/word +4 -0
- data/share/word/reference.docx +0 -0
- data/test/integration/scout/model/decision/test_jev.rb +144 -0
- data/test/scout/llm/agent/test_attach.rb +117 -0
- data/test/scout/llm/agent/test_conversation.rb +407 -0
- data/test/scout/llm/agent/test_delegate.rb +209 -0
- data/test/scout/llm/agent/test_path.rb +1812 -0
- data/test/scout/llm/agent/test_path_edit.rb +908 -0
- data/test/scout/llm/agent/test_path_errors.rb +390 -0
- data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
- data/test/scout/llm/agent/test_path_patch.rb +233 -0
- data/test/scout/llm/agent/test_path_promotion.rb +386 -0
- data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
- data/test/scout/llm/agent/test_save.rb +70 -15
- data/test/scout/llm/agent/test_workflow.rb +130 -4
- data/test/scout/llm/backends/test_anthropic.rb +4 -4
- data/test/scout/llm/backends/test_bedrock.rb +4 -4
- data/test/scout/llm/backends/test_format_other.rb +43 -0
- data/test/scout/llm/backends/test_ollama.rb +2 -2
- data/test/scout/llm/backends/test_openwebui.rb +12 -8
- data/test/scout/llm/backends/test_reasoning.rb +114 -0
- data/test/scout/llm/chat/agent_meta_fixtures.rb +109 -22
- data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
- data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
- data/test/scout/llm/chat/test_agent_meta.rb +40 -80
- data/test/scout/llm/chat/test_agent_meta_provenance.rb +200 -28
- data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
- data/test/scout/llm/chat/test_agent_view.rb +178 -0
- data/test/scout/llm/chat/test_live_report.rb +282 -0
- data/test/scout/llm/chat/test_live_workload.rb +193 -0
- data/test/scout/llm/chat/test_parse.rb +32 -2
- data/test/scout/llm/chat/test_prompt.rb +411 -0
- data/test/scout/llm/chat/test_prov_cli.rb +708 -13
- data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
- data/test/scout/llm/chat/test_prov_plot.rb +213 -0
- data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
- data/test/scout/llm/chat/test_provenance.rb +67 -22
- data/test/scout/llm/chat/test_provenance_index.rb +479 -0
- data/test/scout/llm/chat/test_society_view.rb +159 -0
- data/test/scout/llm/test_agent.rb +1 -1
- data/test/scout/llm/test_embed.rb +103 -1
- data/test/scout/llm/test_request_context.rb +299 -0
- data/test/scout/llm/test_sandbox.rb +249 -0
- data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
- data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
- data/test/scout/llm/tools/test_definition.rb +332 -0
- data/test/scout/llm/tools/test_jobs_file.rb +211 -0
- data/test/scout/llm/tools/test_mcp.rb +37 -8
- data/test/scout/llm/tools/test_workflow.rb +45 -1
- data/test/scout/model/decision/test_jev.rb +453 -0
- data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
- data/test/scout/model/python/huggingface/test_causal.rb +11 -2
- data/test/scout/model/python/huggingface/test_classification.rb +5 -3
- data/test/scout/model/python/test_availability.rb +116 -0
- data/test/scout/model/python/test_torch.rb +54 -2
- data/test/support/availability.rb +72 -174
- data/test/support/fake_clients.rb +18 -9
- data/test/support/fixtures.rb +75 -6
- data/test/support/mock_backend.rb +9 -1
- data/test/support/test_fixtures.rb +156 -0
- data/test/test_helper.rb +14 -4
- metadata +71 -25
- data/research/ChatAnalyst-required-changes.md +0 -167
- data/research/agent-delegation-analysis.md +0 -810
- data/research/agent-meta-provenance-integration-plan.md +0 -622
- data/research/agent-workflow-analysis.md +0 -1120
- data/research/backends-analysis.md +0 -836
- data/research/chat-core-analysis.md +0 -946
- data/research/chatanalyst-provenance/00-baseline.md +0 -30
- data/research/chatanalyst-provenance/01-repo-map.md +0 -60
- data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
- data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
- data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
- data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
- data/research/chatanalyst-provenance/07-critic-review.md +0 -25
- data/research/chatanalyst-provenance/final-report.md +0 -45
- data/research/chatanalyst-provenance/resumption.md +0 -37
- data/research/coding-philosophy-analysis.md +0 -928
- data/research/commands-analysis.md +0 -947
- data/research/multi-agent-patterns-analysis.md +0 -853
- data/research/prompt-strategies-analysis.md +0 -630
- data/research/prov-verbosity-fix-notes.md +0 -77
- data/research/provenance-analysis.md +0 -469
- data/research/synthesis-report.md +0 -487
- data/research/tools-system-analysis.md +0 -779
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require 'scout/llm/chat'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'rbconfig'
|
|
6
|
+
require 'timeout'
|
|
7
|
+
require 'tmpdir'
|
|
8
|
+
require_relative 'agent_meta_fixtures'
|
|
9
|
+
require_relative 'prov_plot_fixtures'
|
|
10
|
+
|
|
11
|
+
# Execution-timeline tests (`--timeline`) for `scout-ai llm prov`.
|
|
12
|
+
#
|
|
13
|
+
# Companion class to TestProvExplanatoryPlot (same file convention, same
|
|
14
|
+
# CLI driver): these assert on the timeline dot the CLI writes through
|
|
15
|
+
# `--timeline FILE.dot`, plus one graphviz geometry check (`dot -Tplain`).
|
|
16
|
+
#
|
|
17
|
+
# The fixture (ProvPlotFixtures#explanatory_fixture) stamps every node
|
|
18
|
+
# with BOTH a chat-content meta `timestamp=` pair and a coherent
|
|
19
|
+
# File.utime (job mtime = end of its chat), so the chat-content priority
|
|
20
|
+
# and the mtime fallback agree on the order. Root and the error job
|
|
21
|
+
# carry no chat timestamps on purpose: they exercise the mtime fallback.
|
|
22
|
+
# Every sequence-dependent expectation below is RECOMPUTED from the
|
|
23
|
+
# fixture's returned `schedule` map, never hard-coded from the spec's
|
|
24
|
+
# ASSUMED sequence.
|
|
25
|
+
class TestProvTimeline < Test::Unit::TestCase
|
|
26
|
+
include AgentMetaFixtures
|
|
27
|
+
include ProvPlotFixtures
|
|
28
|
+
|
|
29
|
+
REPO_ROOT = File.expand_path('../../../..', __dir__)
|
|
30
|
+
|
|
31
|
+
def self.startup
|
|
32
|
+
Log.severity = 5
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def prov(*args)
|
|
36
|
+
cmd = [RbConfig.ruby, '-I', File.join(REPO_ROOT, 'lib'),
|
|
37
|
+
File.join(REPO_ROOT, 'bin', 'scout-ai'), 'llm', 'prov',
|
|
38
|
+
'--nocolor', *args.collect(&:to_s)]
|
|
39
|
+
Open3.capture3(*cmd)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def timeline_for(root, name = 'timeline')
|
|
43
|
+
@prov_count += 1
|
|
44
|
+
target = File.join(@dir, "#{name}_#{@prov_count}.dot")
|
|
45
|
+
out, err, status = prov('--timeline', target, root)
|
|
46
|
+
assert status.success?, err
|
|
47
|
+
[File.read(target), out]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Recompute the expected time sequence from the fixture schedule,
|
|
51
|
+
# exactly as the CLI's time model does (spec S3):
|
|
52
|
+
# job -> chat interval [first meta, last meta] (start = first)
|
|
53
|
+
# job chat -> its own mtime (the fixture stamps end) (start = end)
|
|
54
|
+
# root/bad -> mtime (no chat timestamps) (start = end)
|
|
55
|
+
# society -> its own chat interval (single stamp)
|
|
56
|
+
# Returns [ordered_paths, time_by_path] with [start, end] pairs.
|
|
57
|
+
def expected_sequence(root, jobs, society, schedule)
|
|
58
|
+
time_by_path = {}
|
|
59
|
+
time_by_path[root] = schedule[root]
|
|
60
|
+
time_by_path[jobs[:bad]] = schedule[jobs[:bad]]
|
|
61
|
+
[jobs[:echo], *jobs[:smoke], jobs[:unknown]].each do |job|
|
|
62
|
+
chat = File.join(job + '.files', 'Worker.chat')
|
|
63
|
+
# the job uses the chat interval; the chat NODE uses its own file's
|
|
64
|
+
# chat timestamps too, which for the cumulative replays is
|
|
65
|
+
# [first-turn stamp, own stamp]
|
|
66
|
+
time_by_path[job] = schedule[chat]
|
|
67
|
+
time_by_path[chat] = schedule[chat]
|
|
68
|
+
end
|
|
69
|
+
society.each { |chat| time_by_path[chat] = schedule[chat] }
|
|
70
|
+
# the CLI sorts on the full time key [start, end, path]
|
|
71
|
+
ordered = time_by_path.keys.sort_by { |path| [*time_by_path[path], path] }
|
|
72
|
+
[ordered, time_by_path]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Parse the timeline dot into {node id => {label:, tooltip:, attrs:}}
|
|
76
|
+
# and [[from, to, attrs], ...].
|
|
77
|
+
def parse_dot(dot)
|
|
78
|
+
nodes = {}
|
|
79
|
+
dot.lines.each do |line|
|
|
80
|
+
next unless line =~ /^\s*(n\d+) \[(.*)\];?\s*$/
|
|
81
|
+
id, attrs = Regexp.last_match(1), Regexp.last_match(2)
|
|
82
|
+
label = attrs[/label="((?:[^"\\]|\\.)*)"/, 1]
|
|
83
|
+
tooltip = attrs[/tooltip="((?:[^"\\]|\\.)*)"/, 1]
|
|
84
|
+
nodes[id] = {label: label && label.gsub('\n', "\n"), tooltip: tooltip, attrs: attrs}
|
|
85
|
+
end
|
|
86
|
+
edges = dot.lines.filter_map do |line|
|
|
87
|
+
next unless line =~ /^\s*(n\d+) -> (n\d+) \[(.*)\];?\s*$/
|
|
88
|
+
[Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
|
|
89
|
+
end
|
|
90
|
+
[nodes, edges]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Ids are numbered along the sequence, so n0 is the earliest event.
|
|
94
|
+
def id_for_path(nodes, path)
|
|
95
|
+
id, = nodes.find { |_id, node| node[:tooltip] == path }
|
|
96
|
+
raise "no node with tooltip #{path}" unless id
|
|
97
|
+
id
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
setup do
|
|
101
|
+
@prov_count = 0
|
|
102
|
+
@dir = Dir.mktmpdir('prov-timeline')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
teardown do
|
|
106
|
+
FileUtils.remove_entry @dir if @dir && File.directory?(@dir)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
test 'T1 rank separation: one event per rank, no rank=same' do
|
|
110
|
+
TmpFile.with_dir do |dir|
|
|
111
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]
|
|
112
|
+
dot, = timeline_for(root)
|
|
113
|
+
assert_not_include dot, '{rank=same', dot
|
|
114
|
+
assert_include dot, 'rankdir=TB', dot
|
|
115
|
+
assert_include dot, 'ranksep=0.45', dot
|
|
116
|
+
# the only rank directive is the root pinned to the source rank
|
|
117
|
+
assert_equal 1, dot.scan(/\{rank=source;/).length, dot
|
|
118
|
+
root_id = id_for_path(parse_dot(dot)[0], root)
|
|
119
|
+
assert dot.include?("{rank=source; #{root_id};}"), dot
|
|
120
|
+
# and the root must be the earliest event
|
|
121
|
+
fx2 = explanatory_fixture(dir); schedule2 = fx2[:schedule]
|
|
122
|
+
ordered, = expected_sequence(root, jobs, society, schedule2)
|
|
123
|
+
assert_equal root, ordered.first, dot
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
test 'T2/T3 spine: consecutive time neighbours, reused segments' do
|
|
128
|
+
TmpFile.with_dir do |dir|
|
|
129
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]; schedule = fx[:schedule]
|
|
130
|
+
dot, = timeline_for(root)
|
|
131
|
+
nodes, edges = parse_dot(dot)
|
|
132
|
+
ordered, = expected_sequence(root, jobs, society, schedule)
|
|
133
|
+
# the ids ARE the sequence order (n0 = earliest)
|
|
134
|
+
ordered.each_with_index do |path, index|
|
|
135
|
+
assert_equal "n#{index}", id_for_path(nodes, path), "#{path} should be n#{index}"
|
|
136
|
+
end
|
|
137
|
+
# every consecutive pair is joined by exactly one constraint=true edge
|
|
138
|
+
ordered.each_cons(2) do |first, second|
|
|
139
|
+
joined = edges.select { |f, t, attrs| f == id_for_path(nodes, first) && t == id_for_path(nodes, second) && attrs.include?('constraint=true') }
|
|
140
|
+
assert_equal 1, joined.length, "#{first} -> #{second}\n#{dot}"
|
|
141
|
+
end
|
|
142
|
+
# no other edge carries constraint=true
|
|
143
|
+
assert_equal ordered.length - 1, edges.count { |_f, _t, attrs| attrs.include?('constraint=true') }, dot
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
test 'T4 chain integrity: chain arcs follow the time order' do
|
|
148
|
+
TmpFile.with_dir do |dir|
|
|
149
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]; schedule = fx[:schedule]
|
|
150
|
+
dot, = timeline_for(root)
|
|
151
|
+
nodes, = parse_dot(dot)
|
|
152
|
+
turns = jobs[:smoke]
|
|
153
|
+
time = {}
|
|
154
|
+
turns.each_with_index { |job, index| time[job] = schedule[job].first }
|
|
155
|
+
ordered_turns = turns.sort_by { |job| [time[job], job] }
|
|
156
|
+
continues = dot.scan(/label="continues"/).length
|
|
157
|
+
assert_equal 2, continues, dot
|
|
158
|
+
(ordered_turns[0...-1]).zip(ordered_turns[1..-1]).each do |first, second|
|
|
159
|
+
assert dot.include?("#{id_for_path(nodes, first)} -> #{id_for_path(nodes, second)} [label=\"continues\""), dot
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
test 'T5 ports: delegates headport=w, continues tailport=e headport=w' do
|
|
165
|
+
TmpFile.with_dir do |dir|
|
|
166
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]
|
|
167
|
+
dot, = timeline_for(root)
|
|
168
|
+
assert dot.scan(/class="delegated_result"[^\]]*headport=w/).length +
|
|
169
|
+
dot.scan(/headport=w[^\]]*class="delegated_result"/).length >= 6, dot
|
|
170
|
+
assert_equal 2, dot.scan(/constraint=false, tailport=e, headport=w/).length, dot
|
|
171
|
+
assert_not_include dot, 'tailport=s'
|
|
172
|
+
assert_not_include dot, 'headport=n'
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
test 'T6 error job: time line present, token line absent' do
|
|
177
|
+
TmpFile.with_dir do |dir|
|
|
178
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]
|
|
179
|
+
dot, = timeline_for(root)
|
|
180
|
+
bad = dot.lines.find { |l| l.include?("tooltip=#{jobs[:bad].inspect}") }
|
|
181
|
+
assert bad, dot
|
|
182
|
+
assert_include bad, 't='
|
|
183
|
+
assert_include bad, '⚠ error'
|
|
184
|
+
assert_not_include bad, 'tokens'
|
|
185
|
+
assert_include bad, 'prov-error'
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
test 'T7 cluster rule: chain cluster iff contiguous, no society cluster' do
|
|
190
|
+
TmpFile.with_dir do |dir|
|
|
191
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]; schedule = fx[:schedule]
|
|
192
|
+
dot, = timeline_for(root)
|
|
193
|
+
nodes, = parse_dot(dot)
|
|
194
|
+
assert_not_include dot, 'cluster_society', dot
|
|
195
|
+
assert_include dot, 'cortex-smoke continuation chain', dot
|
|
196
|
+
# recomputed contiguity: the chain cluster appears iff the chain's
|
|
197
|
+
# jobs + produced chats form a contiguous block of the sequence
|
|
198
|
+
ordered, = expected_sequence(root, jobs, society, schedule)
|
|
199
|
+
smoke = [jobs[:smoke], jobs[:smoke].collect { |j| File.join(j + '.files', 'Worker.chat') }].flatten
|
|
200
|
+
indexes = smoke.collect { |path| ordered.index(path) }.compact.sort
|
|
201
|
+
contiguous = indexes.each_cons(2).all? { |a, b| b == a + 1 }
|
|
202
|
+
cluster_blocks = dot.scan(/subgraph cluster_cortex_smoke \{.*?\n \}/m)
|
|
203
|
+
if contiguous
|
|
204
|
+
assert_equal 1, cluster_blocks.length, dot
|
|
205
|
+
ids_in_cluster = cluster_blocks[0].scan(/n\d+/)
|
|
206
|
+
smoke.each { |path| assert_include ids_in_cluster, id_for_path(nodes, path), dot }
|
|
207
|
+
assert_equal smoke.length, ids_in_cluster.length, dot
|
|
208
|
+
else
|
|
209
|
+
assert cluster_blocks.empty?, dot
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
test 'T9 y-monotonic order via dot -Tplain' do
|
|
215
|
+
TmpFile.with_dir do |dir|
|
|
216
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]; schedule = fx[:schedule]
|
|
217
|
+
dot_file = File.join(dir, 'timeline.dot')
|
|
218
|
+
prov('--timeline', dot_file, root)
|
|
219
|
+
dot = File.read(dot_file)
|
|
220
|
+
skip 'graphviz dot not installed' unless Open.exists?('/usr/bin/dot')
|
|
221
|
+
plain, err, status = Open3.capture3('dot', '-Tplain', dot_file)
|
|
222
|
+
assert status.success?, err
|
|
223
|
+
ordered, = expected_sequence(root, jobs, society, schedule)
|
|
224
|
+
nodes, = parse_dot(dot)
|
|
225
|
+
# -Tplain has a bottom-left origin, so EARLIER events must have
|
|
226
|
+
# LARGER y coordinates (monotone non-increasing down the sequence).
|
|
227
|
+
y_by_path = {}
|
|
228
|
+
plain.lines.each do |line|
|
|
229
|
+
next unless line =~ /^node (n\d+) [\d.]+ ([\d.]+)/
|
|
230
|
+
y_by_path[Regexp.last_match(1)] = Regexp.last_match(2).to_f
|
|
231
|
+
end
|
|
232
|
+
ys = ordered.collect { |path| y_by_path[id_for_path(nodes, path)] }
|
|
233
|
+
ys.each_cons(2) { |first, second| assert_operator first, :>=, second, "y not monotone: #{ys.inspect}" }
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
test 'T10 badges and time lines match the computed order' do
|
|
238
|
+
TmpFile.with_dir do |dir|
|
|
239
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]; schedule = fx[:schedule]
|
|
240
|
+
dot, = timeline_for(root)
|
|
241
|
+
nodes, = parse_dot(dot)
|
|
242
|
+
# root: mtime fallback => point badge `t=` without arrow
|
|
243
|
+
root_line = nodes[id_for_path(nodes, root)][:label]
|
|
244
|
+
assert root_line.lines[1] =~ /^t=\d\d:\d\d:\d\d$/, root_line
|
|
245
|
+
# stamped nodes: interval badge with duration
|
|
246
|
+
turn3 = File.join(jobs[:smoke][2] + '.files', 'Worker.chat')
|
|
247
|
+
label = nodes[id_for_path(nodes, turn3)][:label]
|
|
248
|
+
assert label.lines[1] =~ /^t=\d\d:\d\d:\d\d→\d\d:\d\d:\d\d · \d+s$/, label
|
|
249
|
+
# every visible node carries exactly one time line
|
|
250
|
+
nodes.each_value do |node|
|
|
251
|
+
time_lines = node[:label].lines.count { |l| l =~ /^t=/ }
|
|
252
|
+
assert_equal 1, time_lines, node[:label]
|
|
253
|
+
end
|
|
254
|
+
# timestamps only in the time line: no absolute paths in labels
|
|
255
|
+
nodes.each_value do |node|
|
|
256
|
+
assert_not_include node[:label], dir, node[:label]
|
|
257
|
+
assert_not_include node[:label], '.files/', node[:label]
|
|
258
|
+
assert_not_include node[:label], 'agent.society', node[:label]
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
test 'T11 tooltips carry full paths, labels carry none' do
|
|
264
|
+
TmpFile.with_dir do |dir|
|
|
265
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]
|
|
266
|
+
dot, = timeline_for(root)
|
|
267
|
+
nodes, = parse_dot(dot)
|
|
268
|
+
assert_equal 15, nodes.length, dot
|
|
269
|
+
nodes.each_value do |node|
|
|
270
|
+
assert node[:tooltip]&.include?('/'), node.inspect
|
|
271
|
+
assert_not_include node[:label], dir, node[:label]
|
|
272
|
+
assert_not_include node[:label], '.files/', node[:label]
|
|
273
|
+
assert_not_include node[:label], 'agent.society', node[:label]
|
|
274
|
+
next unless node[:label].include?('/')
|
|
275
|
+
assert_match(/\A(?:[^"\/]|\\.)*\/(?:[^"\/]|\\.)*\z/m, node[:label], node[:label])
|
|
276
|
+
end
|
|
277
|
+
# every fixture node (root, jobs, produced chats, society chats) has
|
|
278
|
+
# its own node with its own tooltip
|
|
279
|
+
expected = [root, jobs[:echo], jobs[:unknown], jobs[:bad], *jobs[:smoke],
|
|
280
|
+
*society,
|
|
281
|
+
*[jobs[:echo], jobs[:unknown], *jobs[:smoke]].collect { |j| File.join(j + '.files', 'Worker.chat') }]
|
|
282
|
+
tooltips = nodes.values.collect { |node| node[:tooltip] }
|
|
283
|
+
expected.each { |path| assert_include tooltips, path }
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
test 'T12 render: --timeline svg produces a renderable document' do
|
|
288
|
+
TmpFile.with_dir do |dir|
|
|
289
|
+
fx = explanatory_fixture(dir); root = fx[:root]
|
|
290
|
+
svg_file = File.join(dir, 'timeline.svg')
|
|
291
|
+
out, err, status = prov('--timeline', svg_file, root)
|
|
292
|
+
assert status.success?, err
|
|
293
|
+
assert File.file?(svg_file), out
|
|
294
|
+
svg = File.read(svg_file)
|
|
295
|
+
assert svg.start_with?('<?xml'), svg[0, 100]
|
|
296
|
+
assert_operator svg.scan(/<title>/).length, :>=, 15, svg[0, 400]
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
test 'T13 budgets: no rank=same, bounded natural width' do
|
|
301
|
+
TmpFile.with_dir do |dir|
|
|
302
|
+
fx = explanatory_fixture(dir); root = fx[:root]
|
|
303
|
+
svg_file = File.join(dir, 'timeline.svg')
|
|
304
|
+
prov('--timeline', svg_file, root)
|
|
305
|
+
skip 'graphviz dot not installed' unless Open.exists?('/usr/bin/dot')
|
|
306
|
+
svg = File.read(svg_file)
|
|
307
|
+
width = svg[/width="([\d.]+)pt"/, 1].to_f
|
|
308
|
+
assert_operator width, :<=, 900, "natural width #{width}pt too wide for a single column"
|
|
309
|
+
height = svg[/height="([\d.]+)pt"/, 1].to_f
|
|
310
|
+
assert_operator height, :>, 200, height
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
test 'T14 census: exact node/edge class census' do
|
|
315
|
+
TmpFile.with_dir do |dir|
|
|
316
|
+
fx = explanatory_fixture(dir); root = fx[:root]; jobs = fx[:jobs]; society = fx[:society]; schedule = fx[:schedule]
|
|
317
|
+
dot, = timeline_for(root)
|
|
318
|
+
nodes, edges = parse_dot(dot)
|
|
319
|
+
# node class census, counted by parsing the class attribute rather
|
|
320
|
+
# than by substring so prov-overlap flags do not double-count
|
|
321
|
+
classes = nodes.values.collect { |node| node[:attrs][/class="([^"]*)"/, 1] }
|
|
322
|
+
assert_equal 15, nodes.length, dot
|
|
323
|
+
assert_equal 6, classes.count { |c| c.include?('prov-job') }, classes.inspect
|
|
324
|
+
assert_equal 1, classes.count { |c| c.include?('prov-error') }, classes.inspect
|
|
325
|
+
assert_equal 1, classes.count { |c| c.include?('prov-root') }, classes.inspect
|
|
326
|
+
assert_equal 3, classes.count { |c| c.include?('prov-society') }, classes.inspect
|
|
327
|
+
assert_equal 5, classes.count { |c| c.include?('prov-chat') && !c.include?('prov-society') }, classes.inspect
|
|
328
|
+
# label census: only continues arcs carry labels
|
|
329
|
+
assert_equal 2, dot.scan(/label="continues"/).length, dot
|
|
330
|
+
assert_equal 0, dot.scan(/label="delegates"/).length, dot
|
|
331
|
+
assert_equal 0, dot.scan(/label="produces"/).length, dot
|
|
332
|
+
assert_equal 0, dot.scan(/label="result"/).length, dot
|
|
333
|
+
# spine census: 14 consecutive pairs, one constraint=true each
|
|
334
|
+
ordered, time_by_path = expected_sequence(root, jobs, society, schedule)
|
|
335
|
+
assert_equal ordered.length - 1, edges.count { |_f, _t, a| a.include?('constraint=true') }, dot
|
|
336
|
+
# synthetic spine segments carry the timeline class
|
|
337
|
+
synthetic = dot.scan(/class="timeline"/).length
|
|
338
|
+
assert_operator synthetic, :>=, 1, dot
|
|
339
|
+
# overlap flags recomputed from the same time keys the CLI uses
|
|
340
|
+
# (job key = its chat interval, chat node key = its own interval,
|
|
341
|
+
# fallback nodes are points); [start,end) pairwise overlap.
|
|
342
|
+
expected_overlap = ordered.select do |path|
|
|
343
|
+
span = time_by_path[path]
|
|
344
|
+
ordered.any? do |other|
|
|
345
|
+
next false if other == path
|
|
346
|
+
other_span = time_by_path[other]
|
|
347
|
+
span.first < other_span.last && other_span.first < span.last
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
flagged = nodes.count { |_id, node| node[:attrs].include?('prov-overlap') }
|
|
351
|
+
assert_equal expected_overlap.length, flagged,
|
|
352
|
+
"expected #{expected_overlap.collect { |p| File.basename(p) }.inspect}"
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
end
|
|
@@ -78,7 +78,7 @@ require_relative 'agent_meta_fixtures'
|
|
|
78
78
|
#
|
|
79
79
|
# direct delegated chat <chat>.files/agent.chat (or <name>.chat)
|
|
80
80
|
# society chats <chat>.files/agent.society/<Agent>/<conv>/agent.chat
|
|
81
|
-
#
|
|
81
|
+
# The legacy `.files/log/**` tree is no longer read.
|
|
82
82
|
#
|
|
83
83
|
# These tests only exercise the traversal/read side; writing the new layout is
|
|
84
84
|
# covered by test/scout/llm/agent/test_save.rb.
|
|
@@ -124,18 +124,17 @@ class TestNewLayoutProvenance < Test::Unit::TestCase
|
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
# (b)
|
|
127
|
+
# (b) canonical root copy not traversed; legacy .files/log tree invisible
|
|
128
128
|
def test_new_layout_root_copy_is_not_traversed
|
|
129
129
|
TmpFile.with_dir do |dir|
|
|
130
130
|
chat = write_chat(dir, 'saved.chat', ROOT_CHAT)
|
|
131
131
|
|
|
132
132
|
files = File.expand_path(chat + '.files')
|
|
133
133
|
FileUtils.mkdir_p(File.join(files, 'agent.society', 'Direct', 'harness_test'))
|
|
134
|
+
# Leftover legacy tree: full root copy plus an old society projection.
|
|
134
135
|
FileUtils.mkdir_p(File.join(files, 'log', 'society', 'Worker', 'default'))
|
|
135
|
-
# Root copies in BOTH layouts: full copy of the root conversation.
|
|
136
136
|
File.write(File.join(files, 'agent.chat'), ROOT_CHAT)
|
|
137
137
|
File.write(File.join(files, 'log', 'agent.chat'), ROOT_CHAT)
|
|
138
|
-
# Independent society conversations in both layouts.
|
|
139
138
|
File.write(File.join(files, 'agent.society', 'Direct', 'harness_test', 'agent.chat'),
|
|
140
139
|
"user: work\nmeta: pt=10 ct=5 tt=15 inference_id=w1\nassistant: ok\n")
|
|
141
140
|
File.write(File.join(files, 'log', 'society', 'Worker', 'default', 'agent.chat'),
|
|
@@ -144,22 +143,72 @@ class TestNewLayoutProvenance < Test::Unit::TestCase
|
|
|
144
143
|
paths = visits_paths(chat)
|
|
145
144
|
|
|
146
145
|
new_root_copy = File.join(files, 'agent.chat')
|
|
147
|
-
legacy_root_copy = File.join(files, 'log', 'agent.chat')
|
|
148
146
|
assert_not_include paths, new_root_copy,
|
|
149
|
-
'
|
|
150
|
-
assert_not_include paths, legacy_root_copy,
|
|
151
|
-
'legacy root copy must stay excluded'
|
|
147
|
+
'canonical root copy must not become its own node'
|
|
152
148
|
assert_include paths, File.join(files, 'agent.society', 'Direct', 'harness_test', 'agent.chat')
|
|
153
|
-
|
|
149
|
+
|
|
150
|
+
# The legacy tree is no longer read at all: neither its root copy nor
|
|
151
|
+
# its society projections appear anywhere in the traversal.
|
|
152
|
+
assert_empty paths.select { |path| path.include?(File.join(files, 'log')) },
|
|
153
|
+
'legacy .files/log tree must be invisible to traversal'
|
|
154
154
|
|
|
155
155
|
edges = Chat.provenance_edges(chat).collect { |e| [e[:from].to_s, e[:to].to_s, e[:relation]] }
|
|
156
156
|
assert_empty edges.select { |_from, to, _r| to == new_root_copy }
|
|
157
|
-
assert_empty edges.select { |_from, to, _r| to == legacy_root_copy }
|
|
158
157
|
end
|
|
159
158
|
end
|
|
160
159
|
|
|
161
|
-
# (
|
|
162
|
-
#
|
|
160
|
+
# (b2) the Lean regression: the top-level file is the agent TRANSCRIPT
|
|
161
|
+
# (differs from the root conversation) and carries the meta job=
|
|
162
|
+
# references of delegated work. A chat-root traversal must include
|
|
163
|
+
# the transcript itself and follow its reference into the job tree.
|
|
164
|
+
def test_new_layout_top_level_transcript_is_traversed_from_chat_root
|
|
165
|
+
TmpFile.with_dir do |dir|
|
|
166
|
+
job = make_job(dir, 'Planned/work/Default_1',
|
|
167
|
+
logs: {'agent.chat' =>
|
|
168
|
+
"user: work\nmeta: pt=10 ct=5 tt=15 inference_id=w1\nassistant: ok\n"})
|
|
169
|
+
chat = write_chat(dir, 'session.chat',
|
|
170
|
+
"user: hi\nmeta: pt=2 ct=1 tt=3 inference_id=s0\nassistant: done\n")
|
|
171
|
+
|
|
172
|
+
files = File.expand_path(chat + '.files')
|
|
173
|
+
FileUtils.mkdir_p(files)
|
|
174
|
+
# Transcript: same session but not a copy -- the agent conversation
|
|
175
|
+
# carries the delegated job reference the root file does not.
|
|
176
|
+
File.write(File.join(files, 'agent.chat'),
|
|
177
|
+
"system: you are the harness\n" \
|
|
178
|
+
"user: hi\nmeta: pt=2 ct=1 tt=3 inference_id=s0\nassistant: done\n" \
|
|
179
|
+
"user: go\nmeta: job=#{job}\nassistant: done\n")
|
|
180
|
+
|
|
181
|
+
visits = Chat.traverse_provenance(chat).to_a
|
|
182
|
+
paths = visits.collect { |_k, object, _pk, _p, _r, _f| object.to_s }
|
|
183
|
+
job_paths = visits.select { |kind, *_| kind == :job }
|
|
184
|
+
.collect { |_k, object, *_| object.path.to_s }
|
|
185
|
+
|
|
186
|
+
transcript = File.join(files, 'agent.chat')
|
|
187
|
+
assert_include paths, transcript,
|
|
188
|
+
'the top-level agent transcript must be traversed from the chat root'
|
|
189
|
+
assert_include job_paths, job,
|
|
190
|
+
'the job referenced by the transcript must be reached'
|
|
191
|
+
assert_include paths, File.join(job + '.files', 'agent.chat'),
|
|
192
|
+
'the job log chat must be reached through the transcript ref'
|
|
193
|
+
|
|
194
|
+
edges = Chat.provenance_edges(chat)
|
|
195
|
+
.collect { |e| [e[:from].to_s,
|
|
196
|
+
e[:to].respond_to?(:path) ? e[:to].path.to_s : e[:to].to_s,
|
|
197
|
+
e[:relation]] }
|
|
198
|
+
assert_include edges, [File.expand_path(chat), transcript, :log],
|
|
199
|
+
'the transcript must be linked to its chat root with a :log edge'
|
|
200
|
+
assert_include edges, [transcript, job, :job],
|
|
201
|
+
'the transcript job reference must produce a chat->job edge'
|
|
202
|
+
|
|
203
|
+
# The transcript meta (s0 duplicated, plus w1 through the job log) still
|
|
204
|
+
# aggregates without double counting: identity grouping keeps s0 once.
|
|
205
|
+
assert_equal({pt: 12, ct: 6, tt: 18, cct: 0, cwt: 0, rt: 0},
|
|
206
|
+
Chat.provenance_token_totals(chat))
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# (c) a leftover legacy tree contributes nothing: no duplicate visits and
|
|
211
|
+
# no tokens from the legacy files.
|
|
163
212
|
def test_both_layouts_coexist_without_duplicates
|
|
164
213
|
TmpFile.with_dir do |dir|
|
|
165
214
|
chat = write_chat(dir, 'saved.chat', ROOT_CHAT)
|
|
@@ -175,17 +224,13 @@ class TestNewLayoutProvenance < Test::Unit::TestCase
|
|
|
175
224
|
|
|
176
225
|
visits = Chat.traverse_provenance(chat).to_a
|
|
177
226
|
paths = visits.collect { |_k, object, _pk, _p, _r, _f| object.to_s }
|
|
178
|
-
assert_equal paths.uniq.length, paths.length, 'duplicate visits
|
|
227
|
+
assert_equal paths.uniq.length, paths.length, 'duplicate visits'
|
|
179
228
|
|
|
180
|
-
#
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
assert_equal :chat, legacy[0]
|
|
186
|
-
|
|
187
|
-
# Tokens are counted exactly once.
|
|
188
|
-
assert_equal({pt: 32, ct: 16, tt: 48, cct: 0, cwt: 0, rt: 0},
|
|
229
|
+
# Only the canonical society chat was traversed; the legacy file was
|
|
230
|
+
# never swept and contributes no tokens.
|
|
231
|
+
assert_include paths, File.join(files, 'agent.society', 'Direct', 'harness_test', 'agent.chat')
|
|
232
|
+
assert_not_include paths, File.join(files, 'log', 'society', 'Worker', 'default', 'agent.chat')
|
|
233
|
+
assert_equal({pt: 12, ct: 6, tt: 18, cct: 0, cwt: 0, rt: 0},
|
|
189
234
|
Chat.provenance_token_totals(chat))
|
|
190
235
|
end
|
|
191
236
|
end
|