scout-ai 2.1.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 +133 -58
- 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 +319 -33
- 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 +388 -40
- 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 +13 -17
- 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 +77 -16
- data/lib/scout/llm/agent.rb +147 -31
- data/lib/scout/llm/ask.rb +28 -17
- 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 +127 -34
- 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 -49
- 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 +343 -676
- 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 +71 -27
- 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 +724 -59
- 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 +28 -27
- 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 +67 -28
- data/test/scout/llm/chat/test_agent_meta_tokens.rb +59 -8
- 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 +310 -15
- 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 +70 -26
- 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/provenance-continuation-accounting.md +0 -255
- data/research/synthesis-report.md +0 -487
- data/research/tools-system-analysis.md +0 -779
|
@@ -92,7 +92,7 @@ class TestProvCLI < Test::Unit::TestCase
|
|
|
92
92
|
# must be rendered as a chat root, never loaded as a Step.
|
|
93
93
|
saved = write_chat(dir, 'saved.chat',
|
|
94
94
|
"user: hi\nmeta: pt=1 ct=1 tt=2 inference_id=s1\nassistant: done\n")
|
|
95
|
-
society_chat = File.join(saved + '.files', '
|
|
95
|
+
society_chat = File.join(saved + '.files', 'agent.society', 'Worker', 'default', 'agent.chat')
|
|
96
96
|
FileUtils.mkdir_p(File.dirname(society_chat))
|
|
97
97
|
File.write(society_chat,
|
|
98
98
|
"user: work\nmeta: pt=5 ct=2 tt=7 inference_id=s2\nassistant: ok\n")
|
|
@@ -113,8 +113,9 @@ class TestProvCLI < Test::Unit::TestCase
|
|
|
113
113
|
assert_include root_line, 'prompt=6', out
|
|
114
114
|
assert_match(/root deduplicated_total=9 /, out)
|
|
115
115
|
|
|
116
|
-
# The society conversation is traversed and rendered as its own node
|
|
117
|
-
|
|
116
|
+
# The society conversation is traversed and rendered as its own node,
|
|
117
|
+
# labeled with its agent/conversation pair in the short form.
|
|
118
|
+
society_line = out.lines.find { |line| line.include?('society Worker/default') }
|
|
118
119
|
assert society_line, out
|
|
119
120
|
assert_match(/\A\s*chat\b/, society_line, out)
|
|
120
121
|
assert_include society_line, 'evidence=7', out
|
|
@@ -137,8 +138,8 @@ class TestProvCLI < Test::Unit::TestCase
|
|
|
137
138
|
end
|
|
138
139
|
|
|
139
140
|
# Receipt evidence keeps its parent output address and call id.
|
|
140
|
-
assert_match(/agent_meta parent\.chat:2\[
|
|
141
|
-
assert_match(/agent_meta parent\.chat:2\[
|
|
141
|
+
assert_match(/agent_meta parent\.chat:2\[meta,0\] call=a1/, out)
|
|
142
|
+
assert_match(/agent_meta parent\.chat:2\[meta,1\] call=a1/, out)
|
|
142
143
|
|
|
143
144
|
# Chat-side evidence for the merged events.
|
|
144
145
|
assert_match(/chat_meta agent\.chat:3/, out)
|
|
@@ -240,7 +241,7 @@ class TestProvCLI < Test::Unit::TestCase
|
|
|
240
241
|
|
|
241
242
|
def test_malformed_receipt_renders_with_warning
|
|
242
243
|
TmpFile.with_dir do |dir|
|
|
243
|
-
payload = {'id' => 'bad1', 'result' => 'x', '
|
|
244
|
+
payload = {'id' => 'bad1', 'result' => 'x', 'meta' => 'oops'}
|
|
244
245
|
text = "user: hi\n" +
|
|
245
246
|
'function_call: ' + %({"name":"ask","arguments":{},"id":"bad1"}) + "\n" +
|
|
246
247
|
'function_call_output: ' + JSON.generate(payload) + "\n" +
|
|
@@ -278,7 +279,7 @@ class TestProvCLI < Test::Unit::TestCase
|
|
|
278
279
|
assert status.success?
|
|
279
280
|
# Legacy receipt events show their receipt location instead of the raw
|
|
280
281
|
# address array, and they are flagged as possibly overcounted.
|
|
281
|
-
assert_match(/receipt=legacy\.chat:2\[
|
|
282
|
+
assert_match(/receipt=legacy\.chat:2\[meta,0\]/, out)
|
|
282
283
|
assert_include out, 'legacy unresolved'
|
|
283
284
|
assert_not_include out, 'receipt=["', out
|
|
284
285
|
end
|
|
@@ -354,22 +355,33 @@ class TestProvCLI < Test::Unit::TestCase
|
|
|
354
355
|
end
|
|
355
356
|
end
|
|
356
357
|
|
|
357
|
-
#
|
|
358
|
-
#
|
|
359
|
-
|
|
358
|
+
# Deliberate breakage (plan B2): the legacy `agent_meta` envelope key is no
|
|
359
|
+
# longer read. A worker log whose job= receipts travel under the legacy key
|
|
360
|
+
# produces NO delegated children (old chats intentionally lose those edges).
|
|
361
|
+
def test_job_root_legacy_agent_meta_receipt_has_no_children
|
|
360
362
|
TmpFile.with_dir do |dir|
|
|
361
363
|
child = make_job(dir, 'Worker/ask/Default_legacy')
|
|
362
364
|
worker_log = receipt_chat_text(
|
|
363
|
-
{'l1' => [{role: 'meta', content: "job=#{child}"}]}
|
|
365
|
+
{'l1' => [{role: 'meta', content: "job=#{child}"}]},
|
|
366
|
+
envelope: :agent_meta
|
|
364
367
|
)
|
|
365
|
-
# force the legacy key by hand: receipt_chat_text always writes agent_meta
|
|
366
|
-
text = worker_log.gsub('"agent_meta"', '"agent_meta"')
|
|
367
368
|
worker = make_job(dir, 'Planned/work/Default_wl',
|
|
368
|
-
logs: {'agent.chat' =>
|
|
369
|
+
logs: {'agent.chat' => worker_log})
|
|
369
370
|
|
|
370
371
|
out, _err, status = prov(worker)
|
|
371
372
|
assert status.success?
|
|
372
|
-
|
|
373
|
+
assert_not_include out, 'Default_legacy', out
|
|
374
|
+
assert_not_include out, 'delegated-job', out
|
|
375
|
+
|
|
376
|
+
# The same receipt under the current `meta` key DOES produce the child.
|
|
377
|
+
current = receipt_chat_text(
|
|
378
|
+
{'l1' => [{'job' => child}]}
|
|
379
|
+
)
|
|
380
|
+
worker2 = make_job(dir, 'Planned/work/Default_wc',
|
|
381
|
+
logs: {'agent.chat' => current})
|
|
382
|
+
out2, _err, status2 = prov(worker2)
|
|
383
|
+
assert status2.success?
|
|
384
|
+
assert_match(/delegated-job .*Default_legacy/, out2)
|
|
373
385
|
end
|
|
374
386
|
end
|
|
375
387
|
|
|
@@ -671,4 +683,287 @@ class TestProvCLI < Test::Unit::TestCase
|
|
|
671
683
|
end
|
|
672
684
|
end
|
|
673
685
|
|
|
686
|
+
# ---- Short-form jobname labels (delegated-job presentation) ------------
|
|
687
|
+
#
|
|
688
|
+
# Jobname-when-not-Default rule: a delegated job whose jobname differs from
|
|
689
|
+
# the `Default` sentinel labels with the jobname; a Default-named job keeps
|
|
690
|
+
# the historical hash-excerpt label.
|
|
691
|
+
def test_named_delegated_job_labels_with_jobname
|
|
692
|
+
TmpFile.with_dir do |dir|
|
|
693
|
+
child = make_job(dir, 'Cortex/continue/echo-worker_f44dbdeb0c47d569454e8276ea39de5e.chat',
|
|
694
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'echo-worker'})
|
|
695
|
+
worker_log = receipt_chat_text({'n1' => [meta_receipt("job=#{child}")]})
|
|
696
|
+
worker = make_job(dir, 'Planned/work/Default_wn',
|
|
697
|
+
info: {workflow: 'Planned', task_name: 'work'},
|
|
698
|
+
logs: {'agent.chat' => worker_log})
|
|
699
|
+
|
|
700
|
+
out, err, status = prov(worker)
|
|
701
|
+
assert status.success?, err
|
|
702
|
+
assert_match(/job delegated-job Cortex\/continue echo-worker\b/, out)
|
|
703
|
+
# The hash excerpt is no longer the label token for a named job.
|
|
704
|
+
assert_not_include out, 'Cortex/continue f44dbdeb'
|
|
705
|
+
end
|
|
706
|
+
end
|
|
707
|
+
|
|
708
|
+
def test_default_named_job_keeps_hash_excerpt_label
|
|
709
|
+
TmpFile.with_dir do |dir|
|
|
710
|
+
child = make_job(dir, 'Cortex/continue/Default_f44dbdeb0c47d569454e8276ea39de5e.chat',
|
|
711
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'Default'})
|
|
712
|
+
worker_log = receipt_chat_text({'d1' => [meta_receipt("job=#{child}")]})
|
|
713
|
+
worker = make_job(dir, 'Planned/work/Default_wd2',
|
|
714
|
+
info: {workflow: 'Planned', task_name: 'work'},
|
|
715
|
+
logs: {'agent.chat' => worker_log})
|
|
716
|
+
|
|
717
|
+
out, err, status = prov(worker)
|
|
718
|
+
assert status.success?, err
|
|
719
|
+
assert_match(/job delegated-job Cortex\/continue f44dbdeb\b/, out)
|
|
720
|
+
assert_not_include out, 'Cortex/continue Default'
|
|
721
|
+
end
|
|
722
|
+
end
|
|
723
|
+
|
|
724
|
+
# A failed named job produces a bare delegated-job line (no evidence/cost
|
|
725
|
+
# fields, since it contributed no tokens) carrying its jobname.
|
|
726
|
+
def test_failed_named_job_renders_bare_delegated_line_with_name
|
|
727
|
+
TmpFile.with_dir do |dir|
|
|
728
|
+
child = make_job(dir, 'Cortex/continue/cortex-bad-brief_11111111111111111111111111111111.chat',
|
|
729
|
+
result: {exception: 'boom'}.to_json,
|
|
730
|
+
info: {workflow: 'Cortex', task_name: 'continue',
|
|
731
|
+
clean_name: 'cortex-bad-brief', status: 'error'})
|
|
732
|
+
worker_log = receipt_chat_text({'f1' => [meta_receipt("job=#{child}")]})
|
|
733
|
+
worker = make_job(dir, 'Planned/work/Default_wf2',
|
|
734
|
+
info: {workflow: 'Planned', task_name: 'work'},
|
|
735
|
+
logs: {'agent.chat' => worker_log})
|
|
736
|
+
|
|
737
|
+
out, err, status = prov(worker)
|
|
738
|
+
assert status.success?, err
|
|
739
|
+
bare = out.lines.find { |line| line.include?('cortex-bad-brief') }
|
|
740
|
+
assert bare, out
|
|
741
|
+
assert_match(/\A\s*job delegated-job Cortex\/continue cortex-bad-brief\s*$/, bare)
|
|
742
|
+
%w[evidence= delta= prompt= cache= cont= reason=].each do |field|
|
|
743
|
+
assert_not_include bare, field, bare
|
|
744
|
+
end
|
|
745
|
+
end
|
|
746
|
+
end
|
|
747
|
+
|
|
748
|
+
# Two distinct jobs sharing one jobname stay distinguishable: each label
|
|
749
|
+
# carries the jobname plus its short hash.
|
|
750
|
+
def test_shared_jobname_disambiguated_with_short_hash
|
|
751
|
+
TmpFile.with_dir do |dir|
|
|
752
|
+
child1 = make_job(dir, 'Cortex/continue/echo-worker_f44dbdeb0c47d569454e8276ea39de5e.chat',
|
|
753
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'echo-worker'})
|
|
754
|
+
child2 = make_job(dir, 'Cortex/continue/echo-worker_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.chat',
|
|
755
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'echo-worker'})
|
|
756
|
+
worker_log = receipt_chat_text(
|
|
757
|
+
{'s1' => [meta_receipt("job=#{child1}"), meta_receipt("job=#{child2}")]}
|
|
758
|
+
)
|
|
759
|
+
worker = make_job(dir, 'Planned/work/Default_ws',
|
|
760
|
+
info: {workflow: 'Planned', task_name: 'work'},
|
|
761
|
+
logs: {'agent.chat' => worker_log})
|
|
762
|
+
|
|
763
|
+
out, err, status = prov(worker)
|
|
764
|
+
assert status.success?, err
|
|
765
|
+
assert_include out, 'Cortex/continue echo-worker f44dbdeb'
|
|
766
|
+
assert_include out, 'Cortex/continue echo-worker aaaaaaaa'
|
|
767
|
+
bare_lines = out.lines.select do |line|
|
|
768
|
+
line.include?('Cortex/continue echo-worker') &&
|
|
769
|
+
!line.include?('f44dbdeb') && !line.include?('aaaaaaaa')
|
|
770
|
+
end
|
|
771
|
+
assert_empty bare_lines, "no shared-name label without hash: #{bare_lines * ' | '}"
|
|
772
|
+
end
|
|
773
|
+
end
|
|
774
|
+
|
|
775
|
+
# Flow and dot share node_label, so the jobname rule reaches both; the flow
|
|
776
|
+
# table's separate id column keeps the hash.
|
|
777
|
+
def test_flow_and_dot_show_jobname_label
|
|
778
|
+
TmpFile.with_dir do |dir|
|
|
779
|
+
child = make_job(dir, 'Cortex/continue/echo-worker_f44dbdeb0c47d569454e8276ea39de5e.chat',
|
|
780
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'echo-worker'})
|
|
781
|
+
worker_log = receipt_chat_text({'fd1' => [meta_receipt("job=#{child}")]})
|
|
782
|
+
worker = make_job(dir, 'Planned/work/Default_wfd',
|
|
783
|
+
info: {workflow: 'Planned', task_name: 'work'},
|
|
784
|
+
logs: {'agent.chat' => worker_log})
|
|
785
|
+
|
|
786
|
+
out, _err, status = prov('--flow', worker)
|
|
787
|
+
assert status.success?
|
|
788
|
+
job_row = out.lines.find { |line| line =~ /Cortex\/continue/ }
|
|
789
|
+
assert job_row, out
|
|
790
|
+
assert_include job_row, 'Cortex/continue echo-worker'
|
|
791
|
+
assert_include job_row, 'f44dbdeb', "flow id column keeps the hash: #{job_row}"
|
|
792
|
+
|
|
793
|
+
dot_file = File.join(dir, 'prov.dot')
|
|
794
|
+
out2, _err2, status2 = prov('--dot', dot_file, worker)
|
|
795
|
+
assert status2.success?
|
|
796
|
+
assert_include File.read(dot_file), 'Cortex/continue echo-worker'
|
|
797
|
+
end
|
|
798
|
+
end
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
# ---- Short-form society chat labels ------------------------------------
|
|
802
|
+
#
|
|
803
|
+
# Society conversations saved under a `.society` directory label with
|
|
804
|
+
# `society <Agent>/<conversation>` derived from the LAST marker segment
|
|
805
|
+
# (`society` or any `<name>.society`), instead of their path. The rule is
|
|
806
|
+
# layout-based: it fires for chat-owned and job-owned societies alike, and
|
|
807
|
+
# in flow/dot output where the parent is unknown.
|
|
808
|
+
#
|
|
809
|
+
# Chat-owned society sidecar: compact pair, never the path.
|
|
810
|
+
def test_society_chat_labels_with_agent_conversation_pair
|
|
811
|
+
TmpFile.with_dir do |dir|
|
|
812
|
+
saved = write_chat(dir, 'saved.chat',
|
|
813
|
+
"user: hi\nmeta: pt=1 ct=1 tt=2 inference_id=s1\nassistant: done\n")
|
|
814
|
+
society_chat = File.join(saved + '.files', 'agent.society', 'Worker', 'mgr-social-smoke', 'agent.chat')
|
|
815
|
+
FileUtils.mkdir_p(File.dirname(society_chat))
|
|
816
|
+
File.write(society_chat,
|
|
817
|
+
"user: work\nmeta: pt=5 ct=2 tt=7 inference_id=s2\nassistant: ok\n")
|
|
818
|
+
|
|
819
|
+
out, err, status = prov(saved)
|
|
820
|
+
assert status.success?, err
|
|
821
|
+
|
|
822
|
+
society_line = out.lines.find { |line| line.include?('society Worker/mgr-social-smoke') }
|
|
823
|
+
assert society_line, out
|
|
824
|
+
assert_match(/\A\s*chat\b/, society_line, out)
|
|
825
|
+
assert_include society_line, 'evidence=7', out
|
|
826
|
+
assert_not_include out, 'agent.society/Worker/mgr-social-smoke/agent.chat'
|
|
827
|
+
end
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
# -l still prints full paths: the society line is byte-identical to the
|
|
831
|
+
# pre-change rendering, so the long form is untouched.
|
|
832
|
+
def test_society_long_form_shows_full_path
|
|
833
|
+
TmpFile.with_dir do |dir|
|
|
834
|
+
saved = write_chat(dir, 'saved.chat',
|
|
835
|
+
"user: hi\nmeta: pt=1 ct=1 tt=2 inference_id=s1\nassistant: done\n")
|
|
836
|
+
society_chat = File.join(saved + '.files', 'agent.society', 'Worker', 'mgr-social-smoke', 'agent.chat')
|
|
837
|
+
FileUtils.mkdir_p(File.dirname(society_chat))
|
|
838
|
+
File.write(society_chat,
|
|
839
|
+
"user: work\nmeta: pt=5 ct=2 tt=7 inference_id=s2\nassistant: ok\n")
|
|
840
|
+
|
|
841
|
+
long_out, err, status = prov('-l', saved)
|
|
842
|
+
assert status.success?, err
|
|
843
|
+
long_line = long_out.lines.find { |line| line.include?(society_chat) }
|
|
844
|
+
assert long_line, long_out
|
|
845
|
+
assert_include long_line, 'agent.society/Worker/mgr-social-smoke/agent.chat'
|
|
846
|
+
|
|
847
|
+
short_out, _err, _status = prov(saved)
|
|
848
|
+
assert_not_include short_out, society_chat
|
|
849
|
+
assert_include short_out, 'society Worker/mgr-social-smoke'
|
|
850
|
+
end
|
|
851
|
+
end
|
|
852
|
+
|
|
853
|
+
# The same pair saved under two parents stays distinguishable through the
|
|
854
|
+
# short path digest (the digest the flow id column already shows).
|
|
855
|
+
def test_duplicate_society_pair_disambiguated_with_digest
|
|
856
|
+
TmpFile.with_dir do |dir|
|
|
857
|
+
saved = write_chat(dir, 'saved.chat',
|
|
858
|
+
"user: hi\nmeta: pt=1 ct=1 tt=2 inference_id=s1\nassistant: done\n")
|
|
859
|
+
first = File.join(saved + '.files', 'agent.society', 'Worker', 'default', 'agent.chat')
|
|
860
|
+
second = File.join(saved + '.files', 'other.society', 'Worker', 'default', 'agent.chat')
|
|
861
|
+
[first, second].each do |path|
|
|
862
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
863
|
+
File.write(path, "user: work\nmeta: pt=5 ct=2 tt=7 inference_id=s2\nassistant: ok\n")
|
|
864
|
+
end
|
|
865
|
+
|
|
866
|
+
out, err, status = prov(saved)
|
|
867
|
+
assert status.success?, err
|
|
868
|
+
|
|
869
|
+
society_lines = out.lines.select { |line| line.include?('society Worker/default') }
|
|
870
|
+
assert_equal 2, society_lines.length, out
|
|
871
|
+
digests = society_lines.collect { |line| line[/society Worker\/default \(([0-9a-f]{8})\)/, 1] }
|
|
872
|
+
assert_equal 2, digests.compact.uniq.length, society_lines * "\n"
|
|
873
|
+
assert_equal [Misc.digest(first)[0, 8], Misc.digest(second)[0, 8]].sort, digests.sort
|
|
874
|
+
|
|
875
|
+
ambiguous = society_lines.reject { |line| line =~ /society Worker\/default \([0-9a-f]{8}\)/ }
|
|
876
|
+
assert_empty ambiguous, ambiguous * "\n"
|
|
877
|
+
end
|
|
878
|
+
end
|
|
879
|
+
|
|
880
|
+
# Nested societies label by their own agent/conversation: the LAST marker
|
|
881
|
+
# segment wins, both for the plain `society` basename and for the
|
|
882
|
+
# `<name>.society` sibling form of nested saves.
|
|
883
|
+
def test_nested_society_labels_by_last_marker
|
|
884
|
+
TmpFile.with_dir do |dir|
|
|
885
|
+
saved = write_chat(dir, 'saved.chat',
|
|
886
|
+
"user: hi\nmeta: pt=1 ct=1 tt=2 inference_id=s1\nassistant: done\n")
|
|
887
|
+
nested = File.join(saved + '.files', 'agent.society', 'Worker', 'w_A',
|
|
888
|
+
'society', 'Critic', 'c_1', 'agent.chat')
|
|
889
|
+
sibling = File.join(saved + '.files', 'agent.society', 'Worker', 'w_B',
|
|
890
|
+
'Worker.society', 'Critic', 'c_2', 'agent.chat')
|
|
891
|
+
[nested, sibling].each do |path|
|
|
892
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
893
|
+
File.write(path, "user: crit\nmeta: pt=3 ct=1 tt=4 inference_id=s3\nassistant: ok\n")
|
|
894
|
+
end
|
|
895
|
+
|
|
896
|
+
out, err, status = prov(saved)
|
|
897
|
+
assert status.success?, err
|
|
898
|
+
assert_include out, 'society Critic/c_1'
|
|
899
|
+
assert_include out, 'society Critic/c_2'
|
|
900
|
+
# The outer agent/conversation never leaks into the nested label.
|
|
901
|
+
assert_not_include out, 'society Worker/w_A'
|
|
902
|
+
assert_not_include out, 'society Worker/w_B'
|
|
903
|
+
|
|
904
|
+
# Flow and dot share node_label with no parent, so the compact pair
|
|
905
|
+
# reaches both automatically.
|
|
906
|
+
flow_out, _err, _status = prov('--flow', saved)
|
|
907
|
+
assert_include flow_out, 'society Critic/c_1'
|
|
908
|
+
dot_file = File.join(dir, 'prov.dot')
|
|
909
|
+
prov('--dot', dot_file, saved)
|
|
910
|
+
assert_include File.read(dot_file), 'society Critic/c_2'
|
|
911
|
+
end
|
|
912
|
+
end
|
|
913
|
+
|
|
914
|
+
# Job-owned societies get the compact label too, while ordinary job log
|
|
915
|
+
# chats (no marker segment) keep their basename rendering.
|
|
916
|
+
def test_job_log_children_and_job_owned_society_labels
|
|
917
|
+
TmpFile.with_dir do |dir|
|
|
918
|
+
job = make_job(dir, 'Cortex/continue/cortex-smoke_a8f0e48e0000000000000000000000000000.chat',
|
|
919
|
+
info: {workflow: 'Cortex', task_name: 'continue', clean_name: 'cortex-smoke'},
|
|
920
|
+
logs: {
|
|
921
|
+
'Worker.chat' => "user: work\nmeta: pt=5 ct=2 tt=7 inference_id=w1\nassistant: ok\n",
|
|
922
|
+
'agent.society/Worker/mgr-social-smoke/agent.chat' =>
|
|
923
|
+
"user: soc\nmeta: pt=4 ct=1 tt=5 inference_id=s1\nassistant: ok\n"
|
|
924
|
+
})
|
|
925
|
+
|
|
926
|
+
out, err, status = prov(job)
|
|
927
|
+
assert status.success?, err
|
|
928
|
+
|
|
929
|
+
# A log chat without a marker segment keeps the basename label.
|
|
930
|
+
worker_line = out.lines.find { |line| line.include?('Worker.chat') }
|
|
931
|
+
assert worker_line, out
|
|
932
|
+
assert_match(/\A\s*chat\b/, worker_line, out)
|
|
933
|
+
assert_not_include worker_line, 'society'
|
|
934
|
+
|
|
935
|
+
# The job-owned society conversation is compacted as well.
|
|
936
|
+
society_line = out.lines.find { |line| line.include?('society Worker/mgr-social-smoke') }
|
|
937
|
+
assert society_line, out
|
|
938
|
+
assert_match(/\A\s*chat\b/, society_line, out)
|
|
939
|
+
assert_not_include out, 'agent.society/Worker/mgr-social-smoke/agent.chat'
|
|
940
|
+
end
|
|
941
|
+
end
|
|
942
|
+
|
|
943
|
+
# Label changes must not touch accounting: the root footer stays byte
|
|
944
|
+
# identical between the pre- and post-change renderings of the same tree.
|
|
945
|
+
def test_society_tree_keeps_footer_accounting
|
|
946
|
+
TmpFile.with_dir do |dir|
|
|
947
|
+
saved = write_chat(dir, 'saved.chat',
|
|
948
|
+
"user: hi\nmeta: pt=1 ct=1 tt=2 inference_id=s1\nassistant: done\n")
|
|
949
|
+
society_chat = File.join(saved + '.files', 'agent.society', 'Worker', 'mgr-social-smoke', 'agent.chat')
|
|
950
|
+
FileUtils.mkdir_p(File.dirname(society_chat))
|
|
951
|
+
File.write(society_chat,
|
|
952
|
+
"user: work\nmeta: pt=5 ct=2 tt=7 inference_id=s2\nassistant: ok\n")
|
|
953
|
+
|
|
954
|
+
expected = Chat.provenance_token_totals(saved)
|
|
955
|
+
|
|
956
|
+
out, err, status = prov(saved)
|
|
957
|
+
assert status.success?, err
|
|
958
|
+
|
|
959
|
+
footer = out.lines.find { |line| line.start_with?('root deduplicated_total=') }
|
|
960
|
+
assert footer, out
|
|
961
|
+
assert_equal "root deduplicated_total=9 (2 events) prompt=6 cache=0@0.0% fresh=6 cont=3 " +
|
|
962
|
+
"(authoritative cost; per-node evidence=/direct= values overlap)",
|
|
963
|
+
footer.chomp, out
|
|
964
|
+
assert_equal expected[:tt], 9
|
|
965
|
+
assert_equal expected[:pt], 6
|
|
966
|
+
end
|
|
967
|
+
end
|
|
968
|
+
|
|
674
969
|
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Tests for the --live section of `scout-ai llm prov`: the unified live
|
|
2
|
+
# report (Chat.live_report) rendered as an appended section, captured work
|
|
3
|
+
# excluded, silent when nothing is live.
|
|
4
|
+
#
|
|
5
|
+
# Live job fixtures are synthetic on purpose: a running job is a directory
|
|
6
|
+
# plus a .info JSON whose pid is the test process itself (Chat.live_pid?
|
|
7
|
+
# accepts the current pid), exactly like test_live_workload.rb.
|
|
8
|
+
|
|
9
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
10
|
+
require 'scout/llm/chat'
|
|
11
|
+
require 'open3'
|
|
12
|
+
require 'rbconfig'
|
|
13
|
+
require 'timeout'
|
|
14
|
+
require_relative 'agent_meta_fixtures'
|
|
15
|
+
|
|
16
|
+
class TestProvCLILive < Test::Unit::TestCase
|
|
17
|
+
include AgentMetaFixtures
|
|
18
|
+
|
|
19
|
+
REPO_ROOT = File.expand_path('../../../../../', __FILE__)
|
|
20
|
+
|
|
21
|
+
# Run the real binary. By default the cwd is the fixture dir, because
|
|
22
|
+
# the live passes resolve short job references (WF/continue/one) against
|
|
23
|
+
# Workflow.directory, whose default 'var/jobs' is PWD-relative: fixtures
|
|
24
|
+
# write their jobs under <dir>/var/jobs and the subprocess must run from
|
|
25
|
+
# <dir> for resolution to match live_workload's in-process tests.
|
|
26
|
+
def prov(*args)
|
|
27
|
+
cwd = File.directory?(args.first.to_s) ? args.shift : REPO_ROOT
|
|
28
|
+
cmd = [RbConfig.ruby, File.join(REPO_ROOT, 'bin', 'scout-ai'), 'llm', 'prov'] + args.collect(&:to_s)
|
|
29
|
+
env = ENV.to_h.merge('SCOUT_DEV' => nil)
|
|
30
|
+
Timeout.timeout(120) do
|
|
31
|
+
out, err, status = Open3.capture3(env, *cmd, chdir: cwd)
|
|
32
|
+
[strip_ansi(out), strip_ansi(err), status]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def strip_ansi(text)
|
|
37
|
+
text.gsub(/\e\[[0-9;]*m/, '')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# One running job directory: `<wfdir>/<ref>` with a .info sidecar whose
|
|
41
|
+
# pid is this test process, so Chat.classify_live_job reports :running.
|
|
42
|
+
# Returns the full job path.
|
|
43
|
+
def running_job(wfdir, ref, type: 'string', dependencies: [])
|
|
44
|
+
path = File.join(wfdir, ref)
|
|
45
|
+
FileUtils.mkdir_p(path)
|
|
46
|
+
File.write(path + '.info',
|
|
47
|
+
{status: 'running', pid: Process.pid, type: type,
|
|
48
|
+
workflow: ref.split('/').first, task_name: ref.split('/')[1],
|
|
49
|
+
dependencies: dependencies}.to_json)
|
|
50
|
+
path
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# A running chat task with its agent save file inside the job's .files
|
|
54
|
+
# dir, as AgentWorkflow would keep it.
|
|
55
|
+
def running_chat_task(wfdir, ref)
|
|
56
|
+
path = running_job(wfdir, ref, type: 'chat')
|
|
57
|
+
files_dir = path + '.files'
|
|
58
|
+
FileUtils.mkdir_p(files_dir)
|
|
59
|
+
File.write(File.join(files_dir, 'agent.chat'),
|
|
60
|
+
"\nuser:\n\ndo the thing\n")
|
|
61
|
+
path
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_live_section_appends_running_inference
|
|
65
|
+
TmpFile.with_dir do |dir|
|
|
66
|
+
# A quiet parent chat plus a live delegation chain: the sidecar lists
|
|
67
|
+
# the wrapper job; the wrapper's dependency is the chat task.
|
|
68
|
+
chat = write_chat(dir, 'parent.chat',
|
|
69
|
+
"user: go\nmeta: pt=1 ct=1 tt=2 inference_id=q1\nassistant: done\n")
|
|
70
|
+
wfdir = File.join(dir, 'var', 'jobs')
|
|
71
|
+
task = running_chat_task(wfdir, 'WF/continue/one')
|
|
72
|
+
wrapper = running_job(wfdir, 'WF/cortex_continue/one',
|
|
73
|
+
dependencies: [task])
|
|
74
|
+
File.write(Chat.jobs_file(chat), "WF/cortex_continue/one\n")
|
|
75
|
+
|
|
76
|
+
out, err, status = prov(dir, '--live', chat)
|
|
77
|
+
assert status.success?, err
|
|
78
|
+
|
|
79
|
+
# The live section header is present once, after the normal report.
|
|
80
|
+
headers = out.lines.select { |l| l.include?('Live work') }
|
|
81
|
+
assert_equal 1, headers.length, out
|
|
82
|
+
|
|
83
|
+
# The chat task is the inference entry; the wrapper only shows as
|
|
84
|
+
# workload context; neither duplicates the forensic report's work.
|
|
85
|
+
task_line = out.lines.find { |l| l.include?('WF/continue/one') }
|
|
86
|
+
assert task_line, out
|
|
87
|
+
assert_include task_line, 'chat_task'
|
|
88
|
+
assert_include task_line, 'running'
|
|
89
|
+
assert_include task_line, "log=#{task}.files/agent.chat"
|
|
90
|
+
|
|
91
|
+
wrap_line = out.lines.find { |l| l.include?('WF/cortex_continue/one') }
|
|
92
|
+
assert wrap_line, out
|
|
93
|
+
assert_include wrap_line, 'workflow'
|
|
94
|
+
|
|
95
|
+
# Exactly one line per entry, sorted deterministically
|
|
96
|
+
# (inference before workload context).
|
|
97
|
+
section = out.lines[(out.lines.index { |l| l.include?('Live work') } || 0)..-1]
|
|
98
|
+
body = section.select { |l| l =~ /^\s{2}(chat_task|workflow|dangling_job|agent_active)\b/ }
|
|
99
|
+
assert_equal 2, body.length, out
|
|
100
|
+
|
|
101
|
+
# The normal report was not changed by --live: the forensic footer
|
|
102
|
+
# (token totals) is identical with and without the flag.
|
|
103
|
+
out_plain, _e, s2 = prov(dir, chat)
|
|
104
|
+
assert s2.success?
|
|
105
|
+
footer = ->(o) { o.lines.find { |l| l.start_with?('root deduplicated_total=') } }
|
|
106
|
+
assert_equal footer.(out_plain), footer.(out), out
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_quiescent_chat_live_adds_nothing
|
|
111
|
+
TmpFile.with_dir do |dir|
|
|
112
|
+
# Nothing anywhere: no .jobs sidecar, no .files, no society tree.
|
|
113
|
+
plain = write_chat(dir, 'plain.chat',
|
|
114
|
+
"user: go\nmeta: pt=1 ct=1 tt=2 inference_id=q1\nassistant: done\n")
|
|
115
|
+
|
|
116
|
+
out_plain, err, status = prov(dir, plain)
|
|
117
|
+
out_live, _err2, status2 = prov(dir, '--live', plain)
|
|
118
|
+
assert status.success?, err
|
|
119
|
+
assert status2.success?
|
|
120
|
+
|
|
121
|
+
assert_equal out_plain, out_live, 'quiescent chat: --live must add nothing'
|
|
122
|
+
assert_not_include out_live, 'Live work'
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_captured_job_is_not_repeated_in_live_section
|
|
127
|
+
TmpFile.with_dir do |dir|
|
|
128
|
+
# A finished delegation already in the forensic report (meta: job=)
|
|
129
|
+
# plus a live chat task under the same parent.
|
|
130
|
+
wfdir = File.join(dir, 'var', 'jobs')
|
|
131
|
+
done = running_chat_task(wfdir, 'WF/continue/done')
|
|
132
|
+
# make it terminal so the forensic report resolves it as a job
|
|
133
|
+
info = JSON.parse(File.read(done + '.info'))
|
|
134
|
+
info['status'] = 'done'
|
|
135
|
+
File.write(done + '.info', info.to_json)
|
|
136
|
+
|
|
137
|
+
chat = write_chat(dir, 'parent.chat',
|
|
138
|
+
"user: go\nmeta: job=WF/continue/done\nassistant: done\n")
|
|
139
|
+
live_task = running_chat_task(wfdir, 'WF/continue/live')
|
|
140
|
+
File.write(Chat.jobs_file(chat), "WF/continue/live\n")
|
|
141
|
+
|
|
142
|
+
out, err, status = prov(dir, '--live', chat)
|
|
143
|
+
assert status.success?, err
|
|
144
|
+
|
|
145
|
+
# The captured (done) job must not appear in the live section.
|
|
146
|
+
live_lines = out.lines.select { |l| l =~ /^\s{2}(chat_task|workflow|dangling_job|agent_active)\b/ }
|
|
147
|
+
assert live_lines.none? { |l| l.include?('WF/continue/done') }, out
|
|
148
|
+
# The live task does.
|
|
149
|
+
assert live_lines.any? { |l| l.include?('WF/continue/live') }, out
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|