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.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +133 -58
  3. data/README.md +2 -1
  4. data/VERSION +1 -1
  5. data/doc/Improvements.md +490 -148
  6. data/doc/Model.md +53 -10
  7. data/doc/StartHere.md +44 -19
  8. data/doc/developer/Architecture.md +25 -6
  9. data/doc/developer/Backends.md +207 -48
  10. data/doc/developer/ChatLifecycle.md +121 -20
  11. data/doc/developer/DelegationInternals.md +319 -33
  12. data/doc/developer/DesignPrinciples.md +205 -16
  13. data/doc/developer/PathEngine.md +628 -0
  14. data/doc/developer/PromptProcessing.md +332 -82
  15. data/doc/developer/Provenance.md +388 -40
  16. data/doc/developer/Sandbox.md +213 -0
  17. data/doc/user/BuildingAgents.md +130 -18
  18. data/doc/user/Cookbook.md +29 -8
  19. data/doc/user/CoreConcepts.md +7 -6
  20. data/doc/user/Delegation.md +166 -15
  21. data/doc/user/GettingStarted.md +20 -16
  22. data/doc/user/ManagingContext.md +155 -17
  23. data/doc/user/MultiAgentWorkflows.md +105 -15
  24. data/doc/user/Python.md +11 -1
  25. data/doc/user/RunningInference.md +90 -47
  26. data/doc/user/ToolCalling.md +134 -29
  27. data/doc/user/WritingChats.md +56 -27
  28. data/lib/scout/llm/agent/attach.rb +13 -17
  29. data/lib/scout/llm/agent/chat.rb +32 -0
  30. data/lib/scout/llm/agent/construction.rb +64 -0
  31. data/lib/scout/llm/agent/conversation.rb +304 -0
  32. data/lib/scout/llm/agent/delegate.rb +56 -238
  33. data/lib/scout/llm/agent/path/edit.rb +230 -0
  34. data/lib/scout/llm/agent/path/patch.rb +252 -0
  35. data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
  36. data/lib/scout/llm/agent/path.rb +1777 -0
  37. data/lib/scout/llm/agent/save.rb +11 -9
  38. data/lib/scout/llm/agent/workflow.rb +77 -16
  39. data/lib/scout/llm/agent.rb +147 -31
  40. data/lib/scout/llm/ask.rb +28 -17
  41. data/lib/scout/llm/backends/anthropic.rb +1 -1
  42. data/lib/scout/llm/backends/bedrock.rb +3 -2
  43. data/lib/scout/llm/backends/default.rb +127 -34
  44. data/lib/scout/llm/backends/glm.rb +28 -1
  45. data/lib/scout/llm/backends/huggingface.rb +1 -1
  46. data/lib/scout/llm/backends/ollama.rb +1 -1
  47. data/lib/scout/llm/backends/openai.rb +7 -6
  48. data/lib/scout/llm/backends/openwebui.rb +14 -7
  49. data/lib/scout/llm/backends/relay.rb +8 -2
  50. data/lib/scout/llm/chat/agent_meta.rb +24 -60
  51. data/lib/scout/llm/chat/parse.rb +1 -1
  52. data/lib/scout/llm/chat/process/files.rb +10 -0
  53. data/lib/scout/llm/chat/process/meta.rb +5 -7
  54. data/lib/scout/llm/chat/process/tools.rb +104 -49
  55. data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
  56. data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
  57. data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
  58. data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
  59. data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
  60. data/lib/scout/llm/chat/prompt.rb +24 -10
  61. data/lib/scout/llm/chat/provenance/live.rb +1080 -0
  62. data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
  63. data/lib/scout/llm/chat/provenance.rb +343 -676
  64. data/lib/scout/llm/chat.rb +8 -2
  65. data/lib/scout/llm/embed.rb +15 -3
  66. data/lib/scout/llm/image.rb +4 -1
  67. data/lib/scout/llm/mcp.rb +4 -2
  68. data/lib/scout/llm/request_context.rb +234 -0
  69. data/lib/scout/llm/sandbox.rb +263 -0
  70. data/lib/scout/llm/tools/call.rb +163 -42
  71. data/lib/scout/llm/tools/definition.rb +48 -0
  72. data/lib/scout/llm/tools/knowledge_base.rb +1 -0
  73. data/lib/scout/llm/tools/mcp.rb +50 -43
  74. data/lib/scout/llm/tools/workflow.rb +90 -20
  75. data/lib/scout/llm/tools.rb +14 -41
  76. data/lib/scout/model/decision/base.rb +43 -0
  77. data/lib/scout/model/decision/jev.rb +161 -0
  78. data/lib/scout/model/python/torch.rb +1 -1
  79. data/research/clear-tools-inherit.md +171 -0
  80. data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
  81. data/research/path-kind-chat-role.md +96 -0
  82. data/research/path-kind-contract-fixes-engine.md +307 -0
  83. data/research/scout-ai-runtime-availability.md +65 -0
  84. data/research/subsys/README.md +127 -0
  85. data/research/subsys/agent-delegation.md +201 -0
  86. data/research/subsys/agent-society.md +275 -0
  87. data/research/subsys/agentworkflow.md +233 -0
  88. data/research/subsys/backends.md +221 -0
  89. data/research/subsys/chat.md +314 -0
  90. data/research/subsys/embed-image.md +244 -0
  91. data/research/subsys/entry-cli.md +253 -0
  92. data/research/subsys/model-ml.md +326 -0
  93. data/research/subsys/provenance.md +290 -0
  94. data/research/subsys/tools.md +334 -0
  95. data/scout-ai.gemspec +71 -27
  96. data/scout_commands/agent/ask +8 -7
  97. data/scout_commands/llm/abridged +40 -0
  98. data/scout_commands/llm/ask +9 -9
  99. data/scout_commands/llm/md +2 -0
  100. data/scout_commands/llm/prov +724 -59
  101. data/scout_commands/llm/word +4 -0
  102. data/share/word/reference.docx +0 -0
  103. data/test/integration/scout/model/decision/test_jev.rb +144 -0
  104. data/test/scout/llm/agent/test_attach.rb +117 -0
  105. data/test/scout/llm/agent/test_conversation.rb +407 -0
  106. data/test/scout/llm/agent/test_delegate.rb +209 -0
  107. data/test/scout/llm/agent/test_path.rb +1812 -0
  108. data/test/scout/llm/agent/test_path_edit.rb +908 -0
  109. data/test/scout/llm/agent/test_path_errors.rb +390 -0
  110. data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
  111. data/test/scout/llm/agent/test_path_patch.rb +233 -0
  112. data/test/scout/llm/agent/test_path_promotion.rb +386 -0
  113. data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
  114. data/test/scout/llm/agent/test_save.rb +70 -15
  115. data/test/scout/llm/agent/test_workflow.rb +130 -4
  116. data/test/scout/llm/backends/test_anthropic.rb +4 -4
  117. data/test/scout/llm/backends/test_bedrock.rb +4 -4
  118. data/test/scout/llm/backends/test_format_other.rb +43 -0
  119. data/test/scout/llm/backends/test_ollama.rb +2 -2
  120. data/test/scout/llm/backends/test_openwebui.rb +12 -8
  121. data/test/scout/llm/backends/test_reasoning.rb +114 -0
  122. data/test/scout/llm/chat/agent_meta_fixtures.rb +28 -27
  123. data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
  124. data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
  125. data/test/scout/llm/chat/test_agent_meta.rb +40 -80
  126. data/test/scout/llm/chat/test_agent_meta_provenance.rb +67 -28
  127. data/test/scout/llm/chat/test_agent_meta_tokens.rb +59 -8
  128. data/test/scout/llm/chat/test_agent_view.rb +178 -0
  129. data/test/scout/llm/chat/test_live_report.rb +282 -0
  130. data/test/scout/llm/chat/test_live_workload.rb +193 -0
  131. data/test/scout/llm/chat/test_parse.rb +32 -2
  132. data/test/scout/llm/chat/test_prompt.rb +411 -0
  133. data/test/scout/llm/chat/test_prov_cli.rb +310 -15
  134. data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
  135. data/test/scout/llm/chat/test_prov_plot.rb +213 -0
  136. data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
  137. data/test/scout/llm/chat/test_provenance.rb +67 -22
  138. data/test/scout/llm/chat/test_provenance_index.rb +479 -0
  139. data/test/scout/llm/chat/test_society_view.rb +159 -0
  140. data/test/scout/llm/test_agent.rb +1 -1
  141. data/test/scout/llm/test_embed.rb +103 -1
  142. data/test/scout/llm/test_request_context.rb +299 -0
  143. data/test/scout/llm/test_sandbox.rb +249 -0
  144. data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
  145. data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
  146. data/test/scout/llm/tools/test_definition.rb +332 -0
  147. data/test/scout/llm/tools/test_jobs_file.rb +211 -0
  148. data/test/scout/llm/tools/test_mcp.rb +37 -8
  149. data/test/scout/llm/tools/test_workflow.rb +45 -1
  150. data/test/scout/model/decision/test_jev.rb +453 -0
  151. data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
  152. data/test/scout/model/python/huggingface/test_causal.rb +11 -2
  153. data/test/scout/model/python/huggingface/test_classification.rb +5 -3
  154. data/test/scout/model/python/test_availability.rb +116 -0
  155. data/test/scout/model/python/test_torch.rb +54 -2
  156. data/test/support/availability.rb +72 -174
  157. data/test/support/fake_clients.rb +18 -9
  158. data/test/support/fixtures.rb +75 -6
  159. data/test/support/mock_backend.rb +9 -1
  160. data/test/support/test_fixtures.rb +156 -0
  161. data/test/test_helper.rb +14 -4
  162. metadata +70 -26
  163. data/research/ChatAnalyst-required-changes.md +0 -167
  164. data/research/agent-delegation-analysis.md +0 -810
  165. data/research/agent-meta-provenance-integration-plan.md +0 -622
  166. data/research/agent-workflow-analysis.md +0 -1120
  167. data/research/backends-analysis.md +0 -836
  168. data/research/chat-core-analysis.md +0 -946
  169. data/research/chatanalyst-provenance/00-baseline.md +0 -30
  170. data/research/chatanalyst-provenance/01-repo-map.md +0 -60
  171. data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
  172. data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
  173. data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
  174. data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
  175. data/research/chatanalyst-provenance/07-critic-review.md +0 -25
  176. data/research/chatanalyst-provenance/final-report.md +0 -45
  177. data/research/chatanalyst-provenance/resumption.md +0 -37
  178. data/research/coding-philosophy-analysis.md +0 -928
  179. data/research/commands-analysis.md +0 -947
  180. data/research/multi-agent-patterns-analysis.md +0 -853
  181. data/research/prompt-strategies-analysis.md +0 -630
  182. data/research/prov-verbosity-fix-notes.md +0 -77
  183. data/research/provenance-analysis.md +0 -469
  184. data/research/provenance-continuation-accounting.md +0 -255
  185. data/research/synthesis-report.md +0 -487
  186. data/research/tools-system-analysis.md +0 -779
@@ -1,255 +0,0 @@
1
- # Provenance token accounting for continued conversations (design, not implemented)
2
-
3
- Step 3, Part 2 of the provenance-gap plan. Part 1 (provenance follows `job=`
4
- receipt edges) is done and validated; this document designs token accounting
5
- for continuation chains (Cortex `continue` jobs and any `chat_task` that
6
- follows a previously projected chat). No library code was changed for this
7
- design; probes live in `tmp/prov-cont/measure*.rb` and
8
- `tmp/cortex-continuation-accounting-probes.md`.
9
-
10
- All numbers below are measured on the real example chain unless marked
11
- otherwise. Jobs live under `/home/mvazque2/.scout/var/jobs/Cortex/continue/`.
12
-
13
- ## Evidence
14
-
15
- ### The example chain
16
-
17
- Three sequential continuations of one conversation, `fin_fixes_recon`
18
- (workspace copy not found in this environment, see Open questions):
19
-
20
- | job | result chat (`Default_<k>.chat`) | inference metas | pt sum |
21
- |-----|----------------------------------|-----------------|--------|
22
- | `c0b45189` | 445 messages, 1 `job=` marker, 147 metas | 147 | 6,297,210 |
23
- | `68b5b7fa` | 711 messages, 1 `job=` marker, 237 metas | 237 | 10,707,400 |
24
- | `80070846` | 60 messages, 1 `job=` marker, 20 metas | 20 | 1,124,684 |
25
-
26
- Each result chat starts with its own `job=` meta marker followed by exactly
27
- that job's own new inferences (this is `Chat.project(self.short_path, result)`
28
- with `result = agent.current_chat - agent.start_chat`,
29
- lib/scout/llm/agent/workflow.rb:127-139, projection at
30
- lib/scout/llm/chat/process/meta.rb:410).
31
-
32
- ### What the agent log actually contains (replay measured)
33
-
34
- `Default_80070846...chat.files/agent.chat` (the third, latest job):
35
-
36
- - 404 inference metas, 404 *distinct* `inference_id`s, 0 duplicated ids
37
- (`tmp/prov-cont/measure41.rb`).
38
- - Organized in projected segments delimited by `job=` meta markers:
39
- - segment `job=...c0b45189...chat`: 147 metas, pt 6,297,210,
40
- timestamps 2026-09-02T20:32:48Z .. 21:53:59Z;
41
- - segment `job=...68b5b7fa...chat`: 257 metas, pt 11,832,084,
42
- timestamps 21:54:59Z .. 22:48:55Z
43
- (`measure43.rb`, `measure47.rb`).
44
- - The last segment is MIXED: 257 = 237 inferences authored by job
45
- `68b5b7fa` + 20 authored by `80070846` itself. There is no marker between
46
- the second job's projected result and the third job's own new turns; the
47
- third job appended its turns after `start_chat.follow chat`
48
- (lib/scout/llm/agent/workflow.rb:85-87) of the projected second result.
49
- - `Default_68b5b7fa...files/agent.chat`: 384 metas, all inside the
50
- `job=c0b45189` segment (147 replayed + 237 own new, unmarked).
51
- - `Default_c0b45189...files/agent.chat`: 147 unmarked metas, nothing replayed.
52
-
53
- So: a continuation log carries the entire grown conversation; every replayed
54
- inference retains its original per-call token fields (`pt`, `ct`, `tt`,
55
- `cct`, `cwt`, `rt`, plus cumulative `*_c` and session `*_s` keys, all 404
56
- rows), original `inference_id`, `provider_response_id` and `timestamp`.
57
-
58
- ### Inference identity is stable across copies
59
-
60
- Shared `inference_id`s between the second and third logs: 384; token-field
61
- (`pt/ct/tt/cct`) mismatches among them: 0 (`measure39.rb`). The third log's
62
- inherited rows sum to pt 17,004,610 / cct 16,288,896, byte-identical totals
63
- to the second job's own log content. Identity, not position, is the reliable
64
- key.
65
-
66
- ### Traversal already reaches the whole chain
67
-
68
- `Chat.provenance_chat_files(third result chat)` returns 6 files: the three
69
- result chats plus the three `.files/agent.chat` logs (`measure44.rb`), via
70
- the `job=` marker edges (Part 1). Per-call meta keys observed in the third
71
- log, all 404 rows: `inference_id`, `timestamp`, `provider_response_id`,
72
- `pt/ct/tt/cct/cwt/rt`, `pt_c...rt_c`, `pt_s...rt_s`, plus `reas` on 12 rows.
73
-
74
- ## Current behavior (measured)
75
-
76
- `Chat.provenance_token_totals(root)` (lib/scout/llm/chat/provenance.rb:729)
77
- collects per-inference events (`provenance_token_events`, line 499),
78
- deduplicates them by identity (`[:inference_id, id]`, else
79
- `provider_response_id`, else lineage, else receipt address; lines 577-608),
80
- then sums the canonical event's tokens (lines 706-708).
81
-
82
- Measured per-root totals (`measure44.rb`):
83
-
84
- | root | pt | interpretation |
85
- |------|----|----------------|
86
- | `c0b45189` | 6,297,210 | own only |
87
- | `68b5b7fa` | 17,004,610 | cumulative: own 10,707,400 + first's 6,297,210 |
88
- | `80070846` | 18,129,294 | cumulative: own 1,124,684 + 17,004,610 |
89
-
90
- Verdicts:
91
-
92
- 1. Global deduplicated total does NOT double count. 18,129,294 =
93
- 6,297,210 + 10,707,400 + 1,124,684 exactly. Replayed copies of the same
94
- inference in later logs collapse onto one event; the code's `next if
95
- meta[:job]` filters (lines 534, 557) plus identity grouping do their job.
96
- 2. Per-job root totals ARE cumulative. A continuation job's root total
97
- includes every ancestor inference, so summing per-root totals across a
98
- chain double counts (6,297,210 would be counted three times), and a
99
- naive per-job cost read overstates job `68b5b7fa` by 6.3M pt. Today
100
- there is no per-job "owned" breakdown: scope symbols
101
- (`:deduplicated_total`, `:chat_evidence`, `:receipt_evidence`,
102
- `:receipt_only`, lines 737-750) partition evidence coverage, not authorship.
103
- 3. Re-send cost is present but unseparated. The third job's own 20 calls
104
- cost pt 1,124,684 with cct 1,028,352 (91.5% of prompt tokens served from
105
- cache; uncached prompt = pt - cct = 96,332). Per-call `pt` already
106
- includes re-sent history for every call, which is the honest provider
107
- view, but nothing at job level separates "what this job authored" from
108
- "history this job re-paid for".
109
- 4. Degraded case (missing child `81e265cf`): root
110
- `Planned/work/Default_de207a52...chat` totals pt 37,969,140 with 2
111
- warnings, both `unresolved_job_reference` for
112
- `Cortex/continue/Default_81e265cf...chat` (file absent on disk). The
113
- parent's log carries that job's projected segment with 0 inference metas
114
- (its result was an exception receipt), so nothing is silently counted or
115
- lost; the missing job's own cost is simply unknown, reported only as a
116
- warning.
117
-
118
- ## Attribution rules
119
-
120
- Core rule: **an inference belongs to exactly one job - the job that issued
121
- the model call - and its tokens are attributed to that job only; any other
122
- copy of the same `inference_id` is evidence, never a second charge.**
123
-
124
- 1. Ownership set of a job J = the `inference_id`s of the inference metas in
125
- J's persisted result chat (for `chat` result-type jobs, `job_result_chat_file`,
126
- provenance.rb:83). Measured: this reproduces the exact deltas above
127
- (147 / 237 / 20).
128
- 2. Fallback ownership (result chat absent, e.g. non-chat jobs or pruned
129
- results): inference metas in J's own logs (`direct_job_chat_files`,
130
- provenance.rb:44) whose `timestamp` >= J's start time. Measured: job
131
- `68b5b7fa` issued 2026-09-02T21:54:53Z; the 237 rows with
132
- `timestamp >= issued` equal its result-chat set exactly (set difference 0).
133
- 3. Rows in J's logs belonging to other jobs are labeled inherited, with
134
- provenance `{owning job id -> count}` derived from the `job=` segment
135
- markers around them; they never enter J's owned sums.
136
- 4. Global total = sum over distinct `inference_id`s (unchanged; already
137
- correct today). Per-job owned totals must sum to the global total when
138
- the chain is complete; the residual (global - sum of known owners) is
139
- attributed to `unknown`, driven by missing jobs.
140
- 5. A missing job referenced by a receipt keeps its `unresolved_job_reference`
141
- warning; its contribution is reported as `missing`, never as zero-owned
142
- and never dropped from the residual.
143
-
144
- ## Continuation-point detection
145
-
146
- Three independent signals, used in this priority:
147
-
148
- 1. **Inference identity** (primary). `inference_id` is unique per call and
149
- stable across copies (0 token-field mismatches over 384 shared ids).
150
- Ownership from the result chat (Attribution rule 1) needs no markers at
151
- all and survives arbitrary re-projection.
152
- 2. **Timestamps** (secondary/corroborating). Every inference meta carries
153
- `timestamp`; job issue time bounds the owned set. Use to cross-check rule
154
- 1 and to recover ownership when a result chat is missing. Measured
155
- boundary in the chain: first's rows end 21:53:59Z, second starts 21:54:59Z,
156
- second job issued 21:54:53Z.
157
- 3. **`job=` segment markers** (structural, not authoritative). Markers delimit
158
- projected segments and are what the traversal follows, but the FINAL
159
- segment of a continuation log mixes the parent's projected result with the
160
- current job's own turns (measured: 257 = 237 + 20). Therefore markers
161
- alone can only give an upper bound on inherited content; they must not be
162
- the sole attribution mechanism. Markers are also where duplicate/cycle
163
- safety and re-projection idempotence already live
164
- (`Chat.project` `seen_inference` guard, meta.rb:410-431).
165
-
166
- ## Cost vs content (honest cost model)
167
-
168
- Two quantities must both stay visible and stay distinct:
169
-
170
- - **Authored (content) cost**: tokens of inferences the job itself issued.
171
- Report per job: owned `{pt, ct, tt, cct, cwt, rt}` over its owned set.
172
- - **Re-send (transmission) cost**: history re-paid on each of the job's own
173
- calls. It is already inside per-call `pt`; surface it as a derived view per
174
- job: `uncached_prompt = sum(pt) - sum(cct)` over owned calls, plus
175
- `cache_read = sum(cct)`, `cache_write = sum(cwt)`. Example, job `80070846`:
176
- pt 1,124,684, cache_read 1,028,352, uncached 96,332 - the continuation was
177
- cheap precisely because history was cached, and that is now legible.
178
- - Do NOT hide re-send by subtracting history tokens from per-call `pt`: each
179
- call really did pay its prompt; the cache fields carry the discount.
180
- - Do NOT add inherited rows into the job's cost "because they were sent":
181
- they were paid inside the job's own calls' `pt` already; adding them again
182
- is exactly the double count being removed.
183
- - Cumulative keys (`pt_c` etc.) stay out of all sums; they are linear-chat
184
- checkpoints (`Chat.meta`, meta.rb:140-160), not per-call evidence.
185
-
186
- ## Safety (dupes / cycles / degraded)
187
-
188
- - **Duplicate inference copies**: already handled by identity grouping in
189
- `provenance_token_events`; the attribution layer only adds an owner label
190
- per event, so a row replayed into N logs is still one event with N
191
- evidence records.
192
- - **Conflicting token fields across copies**: existing conflict machinery
193
- (immutable core `pt/ct/tt` + distinct `provider_response_id`, lines
194
- 632-662) stays authoritative; ownership never overrides a conflict, and
195
- `strict:` keeps raising.
196
- - **Cycles / self-edges**: traversal visited-set (`provenance_key`, lines
197
- 227-231) and the sidecar root-copy exclusion (`direct_chat_sidecar_files`,
198
- provenance.rb:68-76) already prevent infinite recursion and self-duplication.
199
- - **Mixed final segment**: attribution by identity/timestamp (not markers)
200
- is immune; if both identity and timestamps were missing, fall back to
201
- markers and flag the final segment as `ambiguous_tail` rather than
202
- guessing.
203
- - **Missing jobs**: unresolved receipt references produce warnings (measured
204
- 2 for `81e265cf`); attribution reports the job as `missing` with its
205
- reference, and the residual accounting keeps global honesty (unknown, not
206
- zero).
207
- - **Log inspectability**: unchanged. Nothing is trimmed from logs; only the
208
- accounting view filters.
209
-
210
- ## Future implementation surface (not implemented)
211
-
212
- - `lib/scout/llm/chat/provenance.rb`
213
- - new `Chat.provenance_token_attribution(root, warnings: nil, **opts)`:
214
- reuse `provenance_token_events` (no new traversal), then resolve owners:
215
- per job node from the same traversal, owned set = inference ids in
216
- `job_result_chat_file` (fallback: log metas with `timestamp >= job
217
- start`, from `Step#started`/info), inherited counts from `job=` markers.
218
- - optional `scope: :owned` (or `attribution:` keyword) on
219
- `provenance_token_totals` that filters events by owner == root job.
220
- - Data shape: hash keyed by job path:
221
- `{owned: {pt:, ct:, tt:, cct:, cwt:, rt:, uncached_prompt:, cache_read:},
222
- inferences: n, inherited: {job_id => count}, missing: [refs],
223
- ambiguous_tail: bool, warnings: [...]}`.
224
- - CLI: `scout llm prov --tokens=owned` (and an `--attribution` table view),
225
- reusing the existing totals plumbing.
226
- - Flag/feature name suggestion: `token_attribution` (no env/config knob
227
- needed; it is a view, not a change of evidence collection).
228
- - Tests would mirror `test/scout/llm/chat/test_agent_meta_tokens.rb` with
229
- fixture chats containing projected segments, a mixed final segment, a
230
- missing referenced job, and a re-projected chat.
231
-
232
- ## Open questions
233
-
234
- - **Unverified** - `pt` semantics vs `cct`: whether `pt` includes cached
235
- tokens (provider convention) or excludes them. The uncached_prompt
236
- derivation assumes inclusion; confirm against the API adapter code before
237
- implementing.
238
- - **Unverified** - `fin_fixes_recon` workspace copy: not found under
239
- `/bulk` or `/home` (only `.scout/tmp` chat copies exist); the design rests
240
- on job artifacts only. If the Cortex store reappears, confirm its
241
- conversation file carries the same projected segments.
242
- - **Unverified** - parentage claimed in the task brief (continuations as
243
- children of `Planned/work 4bf865b6`): not measured; the measured structure
244
- is a linear chain `c0b45189 -> 68b5b7fa -> 80070846` plus the separate
245
- `de207a52 -> (missing) 81e265cf` case.
246
- - **Open** - job start time source for the timestamp fallback: `Step` info
247
- fields vs file mtime vs first owned inference timestamp; pick the most
248
- robust and document it.
249
- - **Open** - whether ownership should also attach to non-`chat` jobs whose
250
- logs contain inference metas (e.g. `:json`/`:text` tasks that ran an
251
- agent); the fallback rule covers them, but naming the owner for log-only
252
- jobs needs a decision.
253
- - **Open** - should `receipt_only` and owned views be combined in one CLI
254
- table, or kept separate reports to avoid the documented non-additivity of
255
- the coverage scopes?