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
data/doc/developer/Provenance.md
CHANGED
|
@@ -20,33 +20,107 @@ The structural relations are:
|
|
|
20
20
|
| chat | `job` | job | A projected response was produced by a Workflow job. |
|
|
21
21
|
| chat | `agent_job` | job | A delegated tool call returned an agent whose receipt entry carries a `job` field naming the producer job. |
|
|
22
22
|
| job | `dependency` | job | A normal Scout Workflow dependency. |
|
|
23
|
-
| job | `log` | chat | A persisted agent conversation under `.files/*.chat
|
|
24
|
-
| chat | `log` | chat | A saved agent conversation under the chat's own `.files` sidecar, same
|
|
23
|
+
| job | `log` | chat | A persisted agent conversation under `.files/*.chat` or `.files/*.society/**/*.chat`. |
|
|
24
|
+
| chat | `log` | chat | A saved agent conversation under the chat's own `.files` sidecar, same two globs (byte-identical root copy excluded). |
|
|
25
25
|
| job | `result` | chat | The job result is itself a chat file. |
|
|
26
26
|
|
|
27
27
|
Relations describe root-outward discovery. A renderer may reverse `job` or `dependency` when drawing natural data flow.
|
|
28
28
|
|
|
29
|
-
The `log` relation covers exactly
|
|
29
|
+
The `log` relation covers exactly two globs under `.files`, nothing else:
|
|
30
30
|
|
|
31
31
|
- `.files/*.chat` — the new top-level chat files (`agent.chat` by default, `worker.chat`/`critic.chat` for named agents);
|
|
32
|
-
- `.files/*.society/**/*.chat` — the new society tree (nested societies keep the plain `society` basename deeper down)
|
|
33
|
-
- `.files/log/**/*.chat` — the **legacy** layout, still read for back-compat; nothing writes it anymore and old files are never migrated.
|
|
32
|
+
- `.files/*.society/**/*.chat` — the new society tree (nested societies keep the plain `society` basename deeper down).
|
|
34
33
|
|
|
35
|
-
Restart snapshots written by `Agent#start` live under `.files/resets/<timestamp>.chat`, directly under `.files` and **outside**
|
|
34
|
+
Restart snapshots written by `Agent#start` live under `.files/resets/<timestamp>.chat`, directly under `.files` and **outside** both globs: they are recovery artifacts, not logs, and provenance traversal does not follow them, for jobs and for chats alike. (A legacy `.files/log/` layout still exists on old trees but is no longer read.)
|
|
36
35
|
|
|
37
36
|
The two `log` parents are deliberately asymmetric:
|
|
38
37
|
|
|
39
|
-
- a **job** root includes its own top-level `<job>.files/<name>.chat` (`agent.chat` and friends
|
|
40
|
-
- a **chat** root
|
|
38
|
+
- a **job** root includes its own top-level `<job>.files/<name>.chat` (`agent.chat` and friends) as a real log node; renderers such as `scout-ai llm prov` hide it from the tree because it duplicates the job node itself;
|
|
39
|
+
- a **chat** root **includes** its top-level `<save_file>.files/<name>.chat` — that file is the agent **transcript**, written by `Agent#save` with the full agent conversation (system and tooling messages included), while the root file itself is appended by the caller. The transcript is what carries the `meta job=` references of delegated work, so following it is how a chat-root traversal reaches the job tree. Only a top-level file that is **byte-identical to the root conversation** is excluded: legacy trees (written by older scout-ai versions) and hand-made copies carry no extra information and would duplicate the root as its own child. Society conversations under `<name>.society/<agent>/<conversation>/agent.chat` are also named `agent.chat` and **are** included, never guarded.
|
|
41
40
|
|
|
42
41
|
Imported and continued chats are **not** provenance relations. They are a chat-compilation concern resolved during `Chat.parse` and `LLM.chat`. The persisted `.chat` file already contains the full inlined conversation. Provenance traversal therefore never follows `import`, `continue`, or `last` chat references.
|
|
43
42
|
|
|
43
|
+
Two consequences of that inlining are worth naming, because both are easy to
|
|
44
|
+
misread as provenance defects:
|
|
45
|
+
|
|
46
|
+
- **Byte-duplicated agent-log entries are inlined child-chat transcripts, not
|
|
47
|
+
double execution.** When a delegated tool call returns an `LLM::Agent`,
|
|
48
|
+
`LLM.process_calls` splices the child's returned messages into the parent's
|
|
49
|
+
current chat (`Chat#follow` via `LLM::Agent#chat`, `lib/scout/llm/tools/call.rb`)
|
|
50
|
+
before the parent log is persisted. The child transcript therefore appears
|
|
51
|
+
verbatim inside every parent that consumed it; the originals remain single
|
|
52
|
+
files. Token accounting is unaffected: deduplication is by `inference_id`, so
|
|
53
|
+
N copies of one inference are one event. Only record-counting readers inflate.
|
|
54
|
+
- **`meta: job=` is a second, cross-conversation channel that behaves like an
|
|
55
|
+
import.** Delegation with shared context (`adopt: :current`, surfaced as
|
|
56
|
+
`chat: current`) makes each participating job persist the shared conversation
|
|
57
|
+
as a `meta: job=` message, and `Chat.jobs` exposes **every** `meta job=`
|
|
58
|
+
reference to traversal through the `:job` relation. The "never follows
|
|
59
|
+
imports" rule above is therefore literally true while the closure still
|
|
60
|
+
crosses conversations: the meta schema carries only `job=` plus token fields,
|
|
61
|
+
with no discriminator that could say "this reference is shared context, not
|
|
62
|
+
this conversation's work".
|
|
63
|
+
|
|
44
64
|
## Safe persisted-chat loading
|
|
45
65
|
|
|
46
66
|
Provenance inspection uses `Chat.load(file)`. It parses the persisted messages without compiling the chat. It therefore does not execute `task`, `job`, `file`, `import`, tool, or other control roles.
|
|
47
67
|
|
|
48
68
|
Do not use `LLM.chat` to inspect historical evidence: that method compiles control roles for inference.
|
|
49
69
|
|
|
70
|
+
## Compact provenance index
|
|
71
|
+
|
|
72
|
+
`Chat.provenance_graph(root, root_type: nil, on_error: :collect)` answers "what
|
|
73
|
+
does THIS chat or job immediately point at" with lightweight data only:
|
|
74
|
+
|
|
75
|
+
{ type: :chat,
|
|
76
|
+
chats: { 3 => '/path/to/var/jobs/W/work/Default_agdfg' }, # index => job path
|
|
77
|
+
dependencies: [], # job roots only
|
|
78
|
+
delegation: { 5 => 'Workspace#default' }, # ask call index => conversation
|
|
79
|
+
live: ['/path/chat.files/agent.chat'], # sidecar paths, NOT traversed
|
|
80
|
+
warnings: [] }
|
|
81
|
+
|
|
82
|
+
`chats` merges both persisted reference forms — standalone `meta: job=`
|
|
83
|
+
messages (anchored at that message's own index) and job references lifted
|
|
84
|
+
from delegated-agent receipts (`meta` entries) inside `function_call_output`
|
|
85
|
+
envelopes (anchored at the outer output message's index). Every value is
|
|
86
|
+
the **resolved canonical absolute path** of the referenced job
|
|
87
|
+
(`load_job_reference` resolution plus realpath normalization), so it can be
|
|
88
|
+
passed straight back
|
|
89
|
+
to `Chat.provenance_graph` as the next root or to `Step.load`. A second,
|
|
90
|
+
different job at the same index turns the value into an array instead of
|
|
91
|
+
overwriting; repeated references to the same job collapse to one. Indexes
|
|
92
|
+
are Ruby's zero-based positions in the persisted message array.
|
|
93
|
+
|
|
94
|
+
`dependencies` lists the job's direct `Step#dependencies` as the same
|
|
95
|
+
canonical absolute paths, in declared order; chat roots always return `[]`.
|
|
96
|
+
`delegation` records only actual `ask` tool calls; an `ask` without a
|
|
97
|
+
persisted job reference stays a delegation entry and never enters `chats`.
|
|
98
|
+
|
|
99
|
+
`live` lists supplementary sidecar chats under the node's `.files`/files
|
|
100
|
+
directory — including a top-level `agent.chat` that byte-identically
|
|
101
|
+
duplicates the root, which the sidecar helper below deliberately filters.
|
|
102
|
+
These are mutable work in flight, not authoritative provenance: the index
|
|
103
|
+
never loads, counts or follows them (the strict review boundary). This is
|
|
104
|
+
also unrelated to `Chat.live_report`, which classifies transient workload.
|
|
105
|
+
|
|
106
|
+
One node per call: there is no `follow` option and no recursion. Feed any
|
|
107
|
+
returned job path back in as the next root. The return value contains
|
|
108
|
+
only strings, symbols, integers, arrays and hashes — no `Chat` or `Step`
|
|
109
|
+
instances, no message bodies. `on_error` behaves like the traversal's
|
|
110
|
+
(`:collect` into `warnings`, a callback, or `:raise`).
|
|
111
|
+
|
|
112
|
+
How the root's kind is decided is part of the contract:
|
|
113
|
+
|
|
114
|
+
- a **`Step` object** is always a job root;
|
|
115
|
+
- a **path** with `root_type: :job` is a job root;
|
|
116
|
+
- a **path** without `root_type` is a chat root, **even when the path is a
|
|
117
|
+
chat-producing job's result file** — for such a job, `Step#path` and the
|
|
118
|
+
output chat path are the same string, so the type cannot be inferred from
|
|
119
|
+
the path alone and is never guessed.
|
|
120
|
+
|
|
121
|
+
The recursive closure of the same graph is available as
|
|
122
|
+
`Chat.provenance_closure(root, ...)`; the collectors below are built on it.
|
|
123
|
+
|
|
50
124
|
## Structural traversal
|
|
51
125
|
|
|
52
126
|
`Chat.traverse_provenance` is the authoritative traversal primitive. It accepts a chat file or Step and yields native `Path` and `Step` values:
|
|
@@ -59,6 +133,16 @@ Do not use `LLM.chat` to inspect historical evidence: that method compiles contr
|
|
|
59
133
|
|
|
60
134
|
Without a block it returns an Enumerator.
|
|
61
135
|
|
|
136
|
+
There is also an optional seventh value: on `agent_job` edges the traversal
|
|
137
|
+
additionally yields `detail`, the `agent_meta` receipt entry
|
|
138
|
+
(`Chat.agent_meta_job_references` record) that produced the edge — so the
|
|
139
|
+
originating function output address, the receipt address, the call id and the
|
|
140
|
+
tool name stay auditable without re-parsing the parent chat. It is `nil` for
|
|
141
|
+
every other relation and is only delivered when the block can receive it
|
|
142
|
+
(`arity == -1` or `>= 7`); `provenance_edges` exposes it as `detail:` with the
|
|
143
|
+
full receipt record (`agent_meta_index`, `call_id`, `evidence_address`,
|
|
144
|
+
`evidence`, `job`, `output_address`, `raw_entry`, `reference`, `tool_name`).
|
|
145
|
+
|
|
62
146
|
The root has nil parent and relation. Every structural edge is yielded. When a shared dependency or cycle reaches an already visited node, `first_visit` is false and the node is not expanded again. Node identity includes both kind and path, because a chat-producing Step and its result chat can share a filesystem path.
|
|
63
147
|
|
|
64
148
|
A chat node expands its own `.files` sidecar logs with the `log` relation, exactly like a job does; a job node expands `dependency`, `log`, and `result`. Node identity is `[kind, realpath]`, so a file reachable through both a job log glob and a chat sidecar glob collapses to a single node (first visit wins).
|
|
@@ -88,14 +172,14 @@ Thin collectors use the same traversal:
|
|
|
88
172
|
- `Chat.provenance_edges(root)` returns typed structural edges;
|
|
89
173
|
- `Chat.tokens(root)` sums direct inference usage from discovered chats.
|
|
90
174
|
|
|
91
|
-
`Chat.provenance` remains as a
|
|
175
|
+
`Chat.provenance` remains as a legacy collector retained for existing callers. New code should use `Chat.provenance_graph`, `Chat.provenance_edges`, or the traversal directly: the legacy Hash does not represent job nodes and relation types fully.
|
|
92
176
|
|
|
93
177
|
### Direct-neighbour helpers
|
|
94
178
|
|
|
95
179
|
Direct readers do not recurse:
|
|
96
180
|
|
|
97
181
|
- `Chat.direct_job_chat_files(job)` returns chat logs owned directly by a job;
|
|
98
|
-
- `Chat.direct_chat_sidecar_files(path)` returns chat logs owned directly by a persisted chat's `.files` sidecar (
|
|
182
|
+
- `Chat.direct_chat_sidecar_files(path)` returns chat logs owned directly by a persisted chat's `.files` sidecar (both globs above), excluding the top-level root copies `<save_file>.files/<name>.chat`;
|
|
99
183
|
- `Chat.job_result_chat_file(job)` returns a chat result when present.
|
|
100
184
|
|
|
101
185
|
Recursion belongs only to `traverse_provenance`.
|
|
@@ -147,6 +231,27 @@ Scout-AI distinguishes two concepts:
|
|
|
147
231
|
|
|
148
232
|
Use lineage IDs for detecting copied history. Use addresses to retrieve exact persisted messages.
|
|
149
233
|
|
|
234
|
+
### Instance collectors over one chat
|
|
235
|
+
|
|
236
|
+
`process/meta.rb` (with one reader in `annotation.rb`) also annotates a single
|
|
237
|
+
`Chat` with thin readers over the same data — useful when you are already
|
|
238
|
+
holding one chat and want a quick answer without running a traversal:
|
|
239
|
+
|
|
240
|
+
| reader | returns |
|
|
241
|
+
|---|---|
|
|
242
|
+
| `chat.job_paths` / `chat.jobs` | `Path`s of every `meta job=` producer referenced by this chat |
|
|
243
|
+
| `chat.job_chat_files` | result and logged chat files reachable from this chat's jobs and their dependencies (`Chat.job_chat_files(job, seen)` walks the dependency graph once per job) |
|
|
244
|
+
| `chat.job_agent_chat_files` | the subset actually owned by the job (`.files/<name>.chat` and `.files/<name>.society/**` under the job's own files dir) |
|
|
245
|
+
| `chat.job_chats` / `chat.job_agent_chats` | the same two sets, loaded as `Chat` objects |
|
|
246
|
+
| `chat.message_index` | per-message lineage records (`id`, `role`, `prev`, `fingerprint`, parsed `meta`) |
|
|
247
|
+
| `chat.meta` | metadata hash of this chat's last meta message |
|
|
248
|
+
| `chat.last_job` | the `job` value of that last meta message |
|
|
249
|
+
|
|
250
|
+
They are the instance-level convenience forms of the class-level traversal and
|
|
251
|
+
collectors above: use them for inspection. For accounting use the
|
|
252
|
+
deduplicated `Chat.token_totals` path — these readers do not deduplicate
|
|
253
|
+
evidence that appears in several chats.
|
|
254
|
+
|
|
150
255
|
## Response tracing
|
|
151
256
|
|
|
152
257
|
`Chat.trace_chats(chats)` groups messages into response segments. A meta message opens a segment; another meta or a user/system turn closes it.
|
|
@@ -186,11 +291,38 @@ Provider call IDs are scoped to a chat; do not assume they are globally unique a
|
|
|
186
291
|
|
|
187
292
|
Calls named `ask` or `hand_off_to_*` provide semantic evidence of delegation. Workflow-backed calls have structural job/log links. A socialized call's association with a society log may still be inferred from naming conventions, so reports should label that association as inferred rather than authoritative.
|
|
188
293
|
|
|
189
|
-
##
|
|
294
|
+
## How a delegation chain is laid out on disk
|
|
295
|
+
|
|
296
|
+
An orchestrator round that delegates through `ask` produces four things at once:
|
|
297
|
+
|
|
298
|
+
1. a `function_call` with tool name `ask` in the orchestrator's chat, followed
|
|
299
|
+
by the paired `function_call_output`;
|
|
300
|
+
2. a Scout job (for example `Agent/Worker/ask`) whose `.files/agent.chat` (or
|
|
301
|
+
`<name>.chat` for a named agent) holds the specialist's **full** conversation
|
|
302
|
+
— system prompt, tooling, every round — each with its own direct-inference
|
|
303
|
+
metas;
|
|
304
|
+
3. the job's chat-typed **result**, holding only the new messages
|
|
305
|
+
(`current_chat - start_chat`) projected with a `meta job=` marker;
|
|
306
|
+
4. that projected result followed back into the orchestrator's chat, giving the
|
|
307
|
+
parent a zero-direct-token projection segment whose real cost lives in the
|
|
308
|
+
job's log.
|
|
309
|
+
|
|
310
|
+
Accounting must therefore be recursive: from the root chat follow every
|
|
311
|
+
`meta job=` to its job, read its logs and dependencies, and sum only the direct
|
|
312
|
+
token fields of deduplicated inference events. Never sum `*_c` or `*_s`
|
|
313
|
+
checkpoints along the chain — the same inference is reachable through several
|
|
314
|
+
of them and would be double-counted.
|
|
315
|
+
|
|
316
|
+
Delegation with a named `conversation` additionally persists a socialized chat
|
|
317
|
+
under the job's `.files`/`.society` tree. Those files carry the prompt, any
|
|
318
|
+
propagated options, the `meta job=` marker and the response — again with no
|
|
319
|
+
direct tokens; follow the job reference for the real cost.
|
|
320
|
+
|
|
321
|
+
## Delegated agent receipts (`meta`)
|
|
190
322
|
|
|
191
323
|
When a tool returns an `LLM::Agent`, `LLM.process_calls` embeds the child agent's inference evidence in the parent `function_call_output` JSON envelope. The envelope is generic: it is produced for any tool returning an agent, not only for `ask`.
|
|
192
324
|
|
|
193
|
-
|
|
325
|
+
One receipt format exists; the reader accepts only it:
|
|
194
326
|
|
|
195
327
|
- **Current format — the `meta` key.** The writer deserializes the child agent's `meta` messages (`LLM.meta_receipt_from_messages`) and emits an Array of plain field Hashes, each already parsed:
|
|
196
328
|
|
|
@@ -202,44 +334,31 @@ Two receipt formats exist, and the reader accepts both:
|
|
|
202
334
|
|
|
203
335
|
The same `function_call_output` may also carry auxiliary fields next to the receipt: `step` (the producing step of the same execution), `start_timestamp`, and `timestamp`. They are bookkeeping only: the sole receipt-driven provenance edge source is the `job` field of a receipt entry (`meta[].job`); the `step` field is never followed as a parent-child edge.
|
|
204
336
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
"agent_meta":[{"role":"meta","content":"pt=100 ct=50 tt=150 inference_id=aaa"}, ...]
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
This shape is **no longer written**, but it is still read: each `content` String is parsed with `Chat.parse_meta`, so historical chats remain fully addressable.
|
|
212
|
-
|
|
213
|
-
When both keys are present in one envelope the current `meta` key wins and the legacy one is ignored (the current writer emits exactly one of the two).
|
|
214
|
-
|
|
215
|
-
See [../../research/agent-meta-provenance-integration-plan.md](../../research/agent-meta-provenance-integration-plan.md) for the design record of the original (serialized) shape; the `meta` key replaced it in commit `efd8ebbc`.
|
|
337
|
+
A legacy serialized `agent_meta` key (Array of `{role: 'meta', content: '...'}` messages) is **no longer read**: envelopes carrying only that key contribute no receipt evidence and no warnings. Chats written by older versions lose their receipt-based provenance edges unless re-saved with the current shape.
|
|
216
338
|
|
|
217
339
|
Receipts are embedded provenance evidence, **not** parent-chat messages, and must never be injected into the parent chat. `Chat#meta`, `chat.role_messages(:meta)`, and `Chat.token_totals([chat])` keep describing the local chat only. A receipt is read as an observation attached to the paired tool output.
|
|
218
340
|
|
|
219
341
|
### Receipt extraction helpers
|
|
220
342
|
|
|
221
|
-
- `Chat.agent_meta_evidence(chat, source: nil, warnings: nil)` returns one Hash per valid receipt entry across the paired tool outputs of a chat. Pairing is delegated to `Chat.tool_calls`; raw text is never scanned. Records carry `origin: :agent_meta` (
|
|
343
|
+
- `Chat.agent_meta_evidence(chat, source: nil, warnings: nil)` returns one Hash per valid receipt entry across the paired tool outputs of a chat. Pairing is delegated to `Chat.tool_calls`; raw text is never scanned. Records carry `origin: :agent_meta` (the receipt origin symbol, unrelated to the persisted field name), the `meta` fields (already deserialized when written), `source`, `output_address`, `evidence_address`, `call_id`, `tool_name`, and `agent_meta_index`; `raw_message` is always nil. The evidence address suffix is `[:meta, index]`, pointing at the JSON element that is actually on disk.
|
|
222
344
|
- `Chat.meta_evidence(chat, source: nil, warnings: nil)` returns the local `meta` messages (`origin: :chat_meta`, with `meta_address`) followed by the receipt records.
|
|
223
345
|
- `Chat.agent_meta_job_references(chat, source: nil, warnings: nil)` filters receipt records whose parsed meta has a `job` key and adds the reference at the top level as `job:`.
|
|
224
346
|
|
|
225
347
|
Malformed receipts (the receipt key not holding an Array; an entry that is not a Hash, has the wrong role, has non-String content, parses to nothing, or — current format only — is a field Hash with no fields) are skipped and never reinterpreted as provenance. When the caller supplies a `warnings` Array, each malformed item appends one warning Hash with the reason, the output address, `call_id`, `tool_name`, and the raw entry. Warning reasons are:
|
|
226
348
|
|
|
227
|
-
| Reason |
|
|
228
|
-
|
|
229
|
-
| `:not_an_array` |
|
|
230
|
-
| `:not_a_hash` |
|
|
231
|
-
| `:
|
|
232
|
-
| `:invalid_content` | legacy | An entry's content is not a String. |
|
|
233
|
-
| `:unparseable_meta` | legacy | The content String parses to no fields. |
|
|
234
|
-
| `:empty_meta` | current | An already-deserialized field Hash carries no fields. |
|
|
349
|
+
| Reason | Meaning |
|
|
350
|
+
|---|---|
|
|
351
|
+
| `:not_an_array` | The receipt value is not an Array. |
|
|
352
|
+
| `:not_a_hash` | An entry is not a Hash. |
|
|
353
|
+
| `:empty_meta` | An already-deserialized field Hash carries no fields. |
|
|
235
354
|
|
|
236
|
-
Malformed warnings
|
|
355
|
+
Malformed warnings carry `origin: :agent_meta` (the receipt origin symbol, unrelated to the persisted field name) and use `[:meta, index]` addresses.
|
|
237
356
|
|
|
238
357
|
### The `agent_job` relation
|
|
239
358
|
|
|
240
359
|
`Chat::PROVENANCE_RELATIONS` includes `agent_job`: chat to delegated producer job, resolved from the `job` field of receipt entries (`meta[].job`; the auxiliary `step` field on the tool output is not an edge source). The child is a normal Step and follows `dependency`, `log`, and `result` as usual. A job reference whose Step path and `.info` sidecar both do not exist is not followed and is reported instead.
|
|
241
360
|
|
|
242
|
-
Diagnostics go through `Chat.provenance_error` with relation `:agent_job`; the error itself is a plain `ScoutException` whose message is built by `Chat.agent_meta_error_message`, and every structured fact (enclosing chat path, tool output address, receipt address, call id, tool name, malformed entry, reference, reason) travels in the `on_error` reference Hash. In strict mode (no `on_error`) a malformed receipt raises; with `on_error` each problem is reported once per receipt, while the rest of the chat's provenance still expands. Only output JSON that parses to a Hash carrying an explicit
|
|
361
|
+
Diagnostics go through `Chat.provenance_error` with relation `:agent_job`; the error itself is a plain `ScoutException` whose message is built by `Chat.agent_meta_error_message`, and every structured fact (enclosing chat path, tool output address, receipt address, call id, tool name, malformed entry, reference, reason) travels in the `on_error` reference Hash. In strict mode (no `on_error`) a malformed receipt raises; with `on_error` each problem is reported once per receipt, while the rest of the chat's provenance still expands. Only output JSON that parses to a Hash carrying an explicit `meta` key is ever inspected: unparseable tool outputs are never scanned for the substring `meta`.
|
|
243
362
|
|
|
244
363
|
### Provenance-aware token accounting
|
|
245
364
|
|
|
@@ -278,6 +397,7 @@ Usage:
|
|
|
278
397
|
scout-ai llm prov path/to/chat --dot flow.dot
|
|
279
398
|
scout-ai llm prov path/to/chat --plot flow.svg
|
|
280
399
|
scout-ai llm prov path/to/chat --evidence
|
|
400
|
+
scout-ai llm prov path/to/chat --live
|
|
281
401
|
|
|
282
402
|
Root classification uses the `.info` sidecar only: a path is a job iff `<path>.info` exists, and is loaded with `Step.load`. The presence of a `.files` sidecar is **not** evidence of a job, because saved agent chats also carry one; a chat root is simply `Path.setup`'d.
|
|
283
403
|
|
|
@@ -291,13 +411,194 @@ The prompt axis is contiguous and uses one canonical field order in node lines a
|
|
|
291
411
|
|
|
292
412
|
The bare unqualified `total=` printed inside `--component` scope lines and `--evidence` rows is retained deliberately as coverage-line vocabulary: it is never summed and is not a cost figure.
|
|
293
413
|
|
|
294
|
-
Delegated calls are reported from receipts (
|
|
295
|
-
|
|
296
|
-
`--evidence` prints the deduplicated direct inference events behind the totals: identity, raw token values, evidence locations (parent output address plus call id), and status (`counted once`, `receipt-only`, `legacy unresolved`, `conflict`), followed by receipt-only, legacy-unresolved, identity-conflict, and job-projection sections.
|
|
414
|
+
Delegated calls are reported from receipts (the `meta` key). The tree labels a job reached through a receipt as `delegated-job`, adds one `delegated receipt: N events, total=<tt>, <tools>` annotation line under chats that carry receipts, and `--component` prints `scope local:` / `scope receipt:` / `scope aggregate:` lines when receipt evidence exists. Flow and DOT render receipt edges as `delegated_result`.
|
|
415
|
+
|
|
416
|
+
`--evidence` prints the deduplicated direct inference events behind the totals: identity, raw token values, evidence locations (parent output address plus call id), and status (`counted once`, `receipt-only`, `legacy unresolved`, `conflict`), followed by receipt-only, legacy-unresolved, identity-conflict, and job-projection sections. `legacy unresolved` marks receipt events with no identity to deduplicate on (no `inference_id`); it is an accounting status, not a format marker. Receipt addresses print as `base:idx[meta,i]`, mirroring the persisted key. Receipt problems and identity conflicts are listed in the trailing warnings block.
|
|
417
|
+
|
|
418
|
+
## Live workload (`--live`)
|
|
419
|
+
|
|
420
|
+
Everything above is **forensic**: it needs concluded work, because receipts and
|
|
421
|
+
saved transcripts only exist after a round completes. `--live` adds the one
|
|
422
|
+
view that exists *while inference runs*: the transient `<base>.jobs` sidecar
|
|
423
|
+
that `LLM.process_calls` maintains for the agent whose save_file base is
|
|
424
|
+
`<base>`.
|
|
425
|
+
|
|
426
|
+
Contract (see [DelegationInternals.md](DelegationInternals.md) for the full
|
|
427
|
+
sibling-state convention):
|
|
428
|
+
|
|
429
|
+
- **Discovery** — for save_file `<dir>/<base>.chat`, the sidecar is
|
|
430
|
+
`<dir>/<base>.jobs`, derived by `Chat.jobs_file` (strip only a *trailing*
|
|
431
|
+
`.chat`, append `.jobs`; a base with no `.chat` extension keeps its whole
|
|
432
|
+
name). `Chat.live_workload(reference)` accepts a chat file, a job path or a
|
|
433
|
+
bare save_file and reads the sidecar opportunistically: the file exists only
|
|
434
|
+
while `Workflow.produce` blocks inside a tool round of this chat's agent, so
|
|
435
|
+
an absent file is a **non-event** (returns `[]`, prints nothing — silence,
|
|
436
|
+
never an error).
|
|
437
|
+
- **Content** — newline-separated job **short paths** (e.g.
|
|
438
|
+
`ProbeP5WF/slow_child/one`) of *all* in-flight workflow jobs, not only
|
|
439
|
+
chat_tasks; it is a snapshot rewritten per round and removed in an `ensure`
|
|
440
|
+
when produce returns (success or failure). Consumers classify; the writer
|
|
441
|
+
does not filter.
|
|
442
|
+
- **Classification** — the live chat_task discriminator is
|
|
443
|
+
`step.type.to_s == 'chat'` (the `chat_task` annotation; a hand-written task
|
|
444
|
+
declaring `:chat` is inference by definition). This is deliberately
|
|
445
|
+
different from the concluded-work discriminator used by the forensic
|
|
446
|
+
traversal (output JSON with exactly the `meta` and `content` keys), which is
|
|
447
|
+
*not* re-checked here: the sidecar only ever lists in-flight jobs.
|
|
448
|
+
- **Reconciliation** — each entry is resolved with
|
|
449
|
+
`Chat.load_live_job_reference` (the run's `Workflow.directory` is tried
|
|
450
|
+
first, because `Step.load` can relocate a bare short path onto an empty
|
|
451
|
+
mirror of the jobs tree) and its `.info` read: terminal status
|
|
452
|
+
(`done|error|aborted|cleaned`) → `finished`; non-terminal + live pid
|
|
453
|
+
(`/proc/<pid>` exists and is not a zombie) → `running`; non-terminal + dead
|
|
454
|
+
or absent pid → `crashed`.
|
|
455
|
+
- **Caveats** — `kill -9` leaves `.info` non-terminal forever, so the observer
|
|
456
|
+
must reconcile through pid liveness; the LocalExecutor can resurrect a
|
|
457
|
+
"dead" job by overwriting `.info` with a new pid; and a listed job may
|
|
458
|
+
finish between the sidecar read and the `.info` read — snapshot races are
|
|
459
|
+
expected, and the renderer reports what it saw instead of erroring.
|
|
460
|
+
|
|
461
|
+
`Chat.live_workload` is the sidecar half only; the CLI renders the unified
|
|
462
|
+
live report, `Chat.live_report` (next section), which folds this pass with
|
|
463
|
+
two more. It changes nothing else: no forensic output, receipt format or
|
|
464
|
+
default CLI behaviour is touched, and a `--live` run over a root chat that
|
|
465
|
+
is not yet on disk still works (empty forensic graph, live section only).
|
|
466
|
+
|
|
467
|
+
## Live work (`--live`)
|
|
468
|
+
|
|
469
|
+
`Chat.live_report(save_file, captured:)` is the unified, data-only live unit
|
|
470
|
+
the CLI renders. It folds three passes and returns:
|
|
471
|
+
|
|
472
|
+
Chat.live_report(save_file, captured: ids)
|
|
473
|
+
# => {entries: [...], scanned: {sidecar:, agent_view:, society:}}
|
|
474
|
+
|
|
475
|
+
| Pass | Reads | Closes |
|
|
476
|
+
|---|---|---|
|
|
477
|
+
| sidecar | `<base>.jobs` through `Chat.live_workload` (contract above), then `Chat.expand_live_jobs` | running dependencies of a listed wrapper (way 5) |
|
|
478
|
+
| agent view | the root agent save file, `Chat.agent_view_live` (through `Chat.live_chat_state`, one parse per file) | plain-agent activity and dangling `job=` metas (ways 2 and 3) |
|
|
479
|
+
| society | `<base>.society/**`, `Chat.society_live` | delegated conversations the forensic `:log` relation excludes (way 4) |
|
|
480
|
+
|
|
481
|
+
The "ways" are those of the five-ways table in
|
|
482
|
+
[Delegation.md](../user/Delegation.md#the-five-ways-of-asking-and-what-you-can-see).
|
|
483
|
+
|
|
484
|
+
### Sidecar pass with dependency expansion
|
|
485
|
+
|
|
486
|
+
`Chat.expand_live_jobs` walks each sidecar entry through its **direct**
|
|
487
|
+
`dependencies` (`Chat.walk_live_job`) — deliberately not `rec_dependencies`,
|
|
488
|
+
which is itself a recursive, cycle-safe flattener and would return the whole
|
|
489
|
+
transitive closure on the first hop, making the depth cap dead code —
|
|
490
|
+
collecting only `classify_live_job == :running` jobs. A visited-path cycle
|
|
491
|
+
guard and `LIVE_DEPENDENCY_DEPTH_LIMIT` (5) are two independent bounds.
|
|
492
|
+
Running chat tasks become the inference entries, with
|
|
493
|
+
`Chat.live_chat_task_agent_log` attaching `<job>.files/<name>.chat` and its
|
|
494
|
+
activity; running non-chat jobs stay as workload context, so nothing the
|
|
495
|
+
sidecar view reported before disappears. `via:` records which sidecar entry
|
|
496
|
+
reached each job, keeping the wrapper visible without duplicating the
|
|
497
|
+
inference.
|
|
498
|
+
|
|
499
|
+
**Waiting-wrapper fallback.** Scout-gear writes a job's `dependencies:` into
|
|
500
|
+
`.info` only at `reset_info(status: :setup)`, which runs *after*
|
|
501
|
+
`run_dependencies` returns: while a chat_task dependency runs, the wrapper
|
|
502
|
+
`.info` is still `{"status":"waiting"}` with no pid and no dependencies, so
|
|
503
|
+
the plain pid rule classifies it `:crashed` and there are no recorded edges
|
|
504
|
+
to walk. `Chat.live_dependency_candidates` covers exactly that window: when
|
|
505
|
+
a step has no recorded dependencies and no terminal status, it scans the
|
|
506
|
+
wrapper's own **workflow namespace** (`var/jobs/<Workflow>/*/*.info`, sibling
|
|
507
|
+
task directories — globbing `.info` files, not directories, because a
|
|
508
|
+
chat_task job path is itself a file) for running jobs. The workflow
|
|
509
|
+
definition is never loaded (the `workflows` pathmap cannot see an arbitrary
|
|
510
|
+
jobs tree), attribution stays bounded to the wrapper's own workflow
|
|
511
|
+
directory, and the scan is read-only and fail-soft. `Chat.live_report` then
|
|
512
|
+
reports the wrapper once as workload context with `state: :waiting`.
|
|
513
|
+
|
|
514
|
+
### Agent view pass
|
|
515
|
+
|
|
516
|
+
`Chat.agent_log_activity` classifies an agent save file from its trailing
|
|
517
|
+
messages, skipping control roles (`meta`, `option`, `sticky_option`,
|
|
518
|
+
`previous_response_id`, `agent`, `import`, `socialize`, `attachments`):
|
|
519
|
+
|
|
520
|
+
| trailing conversational message | verdict |
|
|
521
|
+
|---|---|
|
|
522
|
+
| `user` | active, `:dispatched` |
|
|
523
|
+
| `function_call` with no later `function_call_output` | active, `:tool_round_in_flight` |
|
|
524
|
+
| `function_call_output` | active, `:next_round_pending` |
|
|
525
|
+
| `assistant` with no open call | inactive, `:idle` |
|
|
526
|
+
| empty file / unreadable or missing file | inactive, `:no_messages` / `:unreadable` |
|
|
527
|
+
| any other role (system, introduce, tool) | inactive, `:no_inference` |
|
|
528
|
+
|
|
529
|
+
`rounds:` counts `assistant` messages. Accepted false negative: an
|
|
530
|
+
`assistant`-terminated file reads idle during the round-boundary window in
|
|
531
|
+
which a completed round is already saved but the next dispatch is not
|
|
532
|
+
flushed yet, so a mid-conversation agent can be missed for that instant
|
|
533
|
+
(never a false positive). The predicate is sound because two writers rewrite
|
|
534
|
+
the file on that cadence: the backend with the outgoing transcript at every
|
|
535
|
+
round boundary, and the agent layer with the completed round afterwards
|
|
536
|
+
(`Agent#chat` ensure → `save_if_configured`).
|
|
537
|
+
|
|
538
|
+
`Chat.dangling_agent_job_metas` reads the save file's `job=` metas with
|
|
539
|
+
`Chat#jobs` — the same reader the forensic traversal uses for the captured
|
|
540
|
+
set, not receipt-borne `:agent_job` references, which stay forensic-only —
|
|
541
|
+
and follows each reference to a running job. The `job=` meta is written at
|
|
542
|
+
dispatch, before `job.produce` blocks, so it dangles for exactly the
|
|
543
|
+
duration of the child run; references to terminal jobs and to already
|
|
544
|
+
captured ids are not reported.
|
|
545
|
+
|
|
546
|
+
### Society pass
|
|
547
|
+
|
|
548
|
+
The forensic `:log` relation for a chat root excludes society files
|
|
549
|
+
(`direct_chat_sidecar_files`); society conversations are live-only territory,
|
|
550
|
+
visible to the main report only once their receipt lands in the parent chat.
|
|
551
|
+
`Chat.society_dir_of` reuses the agent layer's society layout rules (with a
|
|
552
|
+
literal fallback while the agent class is not loaded), `Chat.society_agent_chats`
|
|
553
|
+
scans `<base>.society/` for files named `agent.chat` — bounded to
|
|
554
|
+
`SOCIETY_SCAN_DEPTH_LIMIT` (128) directory levels, symlinks skipped, sorted
|
|
555
|
+
output — and `Chat.society_live` reports each child whole: `kind:
|
|
556
|
+
:dangling_job` when the child is workflow-backed (its own save file holds
|
|
557
|
+
the dangling `job=` meta) and `kind: :agent_activity` otherwise, the
|
|
558
|
+
activity hash riding along either way. A child whose job reference is
|
|
559
|
+
already captured is skipped entirely — its whole current turn *is* that job.
|
|
560
|
+
|
|
561
|
+
### Folding, dedup and rendering
|
|
562
|
+
|
|
563
|
+
Entries are keyed by job id (the sidecar short path, the same form a `job=`
|
|
564
|
+
meta stores, so cross-pass matching is plain string equality) or by
|
|
565
|
+
agent-log path when no job exists. Rules:
|
|
566
|
+
|
|
567
|
+
- a job id in `captured` — ids normalized by `Chat.live_captured_ids` from
|
|
568
|
+
the forensic report's job nodes — is dropped in **every** pass: the main
|
|
569
|
+
report already holds it;
|
|
570
|
+
- the same job arriving from two passes merges into one entry
|
|
571
|
+
(`Chat.merge_live_entries`): hashes are deep-merged, `source` tags are
|
|
572
|
+
united, and scalar facts of the earlier entry win unless empty — so a
|
|
573
|
+
sidecar `:inference` entry keeps its kind when an agent-side entry names
|
|
574
|
+
the same job;
|
|
575
|
+
- per agent-log file the two agent-side signals collapse to one entry
|
|
576
|
+
(`Chat.reconcile_agent_log_entries`), the dangling job winning as the
|
|
577
|
+
kind, and every outstanding `job=` reference being kept;
|
|
578
|
+
- a log file whose running `job=` references are all captured drops its bare
|
|
579
|
+
activity entry too; files with no running reference at all (the plain
|
|
580
|
+
agent, way 2) keep it.
|
|
581
|
+
|
|
582
|
+
The CLI appends a `Live work (in-flight while this prov run executes)`
|
|
583
|
+
section after the normal report, one line per entry:
|
|
584
|
+
`<kind label> <reference> <state or reason> <sources> [log=<path>]
|
|
585
|
+
[info=<status>]`, kinds relabelled `chat_task` (`:inference`),
|
|
586
|
+
`dangling_job`, `agent_active` (`:agent_activity`) and `workflow`
|
|
587
|
+
(`:workload_context`), inference first. The section — header included — is
|
|
588
|
+
omitted when there are no entries, so a quiescent `--live` run is identical
|
|
589
|
+
to plain `prov`; a `--live` run on a chat root that is not yet on disk
|
|
590
|
+
proceeds with an empty forensic graph and renders the live section alone.
|
|
591
|
+
|
|
592
|
+
`.jobs` short references resolve through `Workflow.directory`, whose default
|
|
593
|
+
is the PWD-relative `var/jobs`: the observer must run in the working
|
|
594
|
+
directory that owns the jobs tree. Live entries carry no token figures:
|
|
595
|
+
in-flight jobs have no receipts yet, and the offline mock backend emits no
|
|
596
|
+
usage or cost fields at all, so live cost attribution is deferred to a
|
|
597
|
+
backend that reports usage.
|
|
297
598
|
|
|
298
599
|
## ChatAnalyst
|
|
299
600
|
|
|
300
|
-
ChatAnalyst uses the same core
|
|
601
|
+
ChatAnalyst uses the same core primitives. It does not define Session, ChatGraph, ProvenanceContext, or node wrapper classes. Its Workflow tasks collect report state in ordinary Hashes and Arrays and apply shared Chat operations — the compact index, the traversal collectors, message indexing, tracing, tool-call pairing, and token accounting.
|
|
301
602
|
|
|
302
603
|
This keeps responsibilities separate:
|
|
303
604
|
|
|
@@ -306,20 +607,67 @@ This keeps responsibilities separate:
|
|
|
306
607
|
- `prov` owns human and Graphviz rendering;
|
|
307
608
|
- Workflow Step info owns execution lifecycle and failure provenance.
|
|
308
609
|
|
|
309
|
-
ChatAnalyst is expected to consume the receipt primitives above — `Chat.agent_meta_evidence`, `Chat.meta_evidence`, `Chat.agent_meta_job_references`, and the `:agent_job` relation — instead of re-deriving delegated inference evidence.
|
|
610
|
+
ChatAnalyst is expected to consume the receipt primitives above — `Chat.agent_meta_evidence`, `Chat.meta_evidence`, `Chat.agent_meta_job_references`, and the `:agent_job` relation — instead of re-deriving delegated inference evidence.
|
|
310
611
|
|
|
311
612
|
## Key source files
|
|
312
613
|
|
|
313
614
|
| File | Responsibility |
|
|
314
615
|
|---|---|
|
|
315
|
-
| `lib/scout/llm/chat/provenance.rb` |
|
|
616
|
+
| `lib/scout/llm/chat/provenance.rb` | Compact provenance index, structural traversal, direct neighbours, and collectors. || `lib/scout/llm/chat/provenance.rb` | Compact provenance index, structural traversal, direct neighbours, and collectors. |
|
|
617
|
+
| `lib/scout/llm/chat/provenance/tokens.rb` | Provenance-aware token accounting (events, identity, deduplication, scopes). |
|
|
618
|
+
| `lib/scout/llm/chat/provenance/live.rb` | Live workload and agent/society activity reports. |
|
|
316
619
|
| `lib/scout/llm/chat/agent_meta.rb` | Delegated-agent receipt evidence extraction. |
|
|
317
620
|
| `lib/scout/llm/chat/process/meta.rb` | Meta parsing, lineage, source-aware tracing, projections, and token totals. |
|
|
318
621
|
| `lib/scout/llm/chat/tool_calls.rb` | Tool-call pairing and common status interpretation. |
|
|
319
622
|
| `lib/scout/llm/backends/default.rb` | Direct token metadata and inference identities. |
|
|
320
623
|
| `lib/scout/llm/agent/workflow.rb` | Agent log persistence and chat-task projection. |
|
|
624
|
+
| `lib/scout/llm/agent/save.rb` | Save-file and society-tree layout the live passes read. |
|
|
625
|
+
| `lib/scout/llm/tools/call.rb` | `<base>.jobs` sidecar writer/removal in `LLM.process_calls`. |
|
|
321
626
|
| `scout_commands/llm/prov` | Tree, flow, DOT, and plot rendering. |
|
|
322
627
|
|
|
628
|
+
## Tests
|
|
629
|
+
|
|
630
|
+
The provenance contract is pinned by five test files:
|
|
631
|
+
|
|
632
|
+
- `test/scout/llm/chat/test_provenance_index.rb` — the compact index:
|
|
633
|
+
canonical resolved job paths, message-index anchoring for both reference
|
|
634
|
+
forms, scalar/array handling at one index, `ask`-only delegation, the
|
|
635
|
+
`live` boundary (listed, never traversed, byte-identical copy included),
|
|
636
|
+
job-root identification, and the follow-up workflow from a chat root
|
|
637
|
+
through a job root to its dependencies.
|
|
638
|
+
|
|
639
|
+
- `test/scout/llm/chat/test_provenance.rb` — traversal relations and layout
|
|
640
|
+
globs: `test_does_not_follow_imports`,
|
|
641
|
+
`test_does_not_follow_continue_or_last`,
|
|
642
|
+
`test_provenance_relations_does_not_include_import`,
|
|
643
|
+
`test_traverses_job_and_log_relations`,
|
|
644
|
+
`test_new_layout_society_sidecar_is_traversed_with_log_relation`,
|
|
645
|
+
`test_new_layout_root_copy_is_not_traversed`,
|
|
646
|
+
`test_new_layout_top_level_transcript_is_traversed_from_chat_root`,
|
|
647
|
+
`test_both_layouts_coexist_without_duplicates`,
|
|
648
|
+
`test_files_outside_the_glob_families_are_not_swept`.
|
|
649
|
+
- `test/scout/llm/chat/test_agent_meta_provenance.rb` — the `agent_job`
|
|
650
|
+
relation and receipt hygiene:
|
|
651
|
+
`test_agent_job_edge_links_receipt_job_to_enclosing_chat`,
|
|
652
|
+
`test_follow_agent_job_includes_only_the_agent_job_edge`,
|
|
653
|
+
`test_nested_receipt_chain_terminates_with_both_delegation_edges`,
|
|
654
|
+
`test_deliberate_receipt_cycle_does_not_hang`,
|
|
655
|
+
`test_malformed_receipts_become_agent_job_warnings`,
|
|
656
|
+
`test_saved_chat_sidecar_society_chats_are_traversed_with_log_relation`.
|
|
657
|
+
- `test/scout/llm/chat/test_agent_meta.rb` / `test_agent_meta_tokens.rb` —
|
|
658
|
+
receipt parsing, token events, and malformed-entry tolerance.
|
|
659
|
+
- `test/scout/llm/chat/test_prov_cli.rb` (plus the live/plot/timeline
|
|
660
|
+
siblings) — CLI rendering over the same traversal.
|
|
661
|
+
|
|
662
|
+
## Environment trap: checkout vs installed gem
|
|
663
|
+
|
|
664
|
+
`Chat.live_report`, `Chat.provenance_graph` and the rest of this document's
|
|
665
|
+
machinery live in this repository's `lib/scout/llm/chat/provenance.rb`. If
|
|
666
|
+
`require 'scout-ai'` resolves to an **older installed gem** instead of the
|
|
667
|
+
checkout, those methods raise `NoMethodError`. When probing from a checkout,
|
|
668
|
+
run with `-I<checkout>/lib` (or `RUBYOPT=-I<checkout>/lib`) so the checkout
|
|
669
|
+
wins the load path.
|
|
670
|
+
|
|
323
671
|
## Cross-references
|
|
324
672
|
|
|
325
673
|
- [ChatLifecycle.md](ChatLifecycle.md) — Chat data and compilation.
|