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
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
# The Path engine
|
|
2
|
+
|
|
3
|
+
This document explains how the Path engine (`lib/scout/llm/agent/path.rb`,
|
|
4
|
+
with the editing implementation in `lib/scout/llm/agent/path/edit.rb` and
|
|
5
|
+
the single-file diff applier in `lib/scout/llm/agent/path/patch.rb`)
|
|
6
|
+
exposes filesystem operations to agents: how to register a path kind, how
|
|
7
|
+
to declare the kinds a workflow provides (`PATH_KINDS`) so agents can
|
|
8
|
+
enable them through the `path_kind:` chat role, how to override a
|
|
9
|
+
built-in operation, how to introduce
|
|
10
|
+
a custom operation, how tool aggregation resolves conflicts, what the
|
|
11
|
+
callback contract and trust boundary are, how the single-file patch
|
|
12
|
+
operation behaves, and which `path` spellings select the kind root rather
|
|
13
|
+
than a file. It is intended for workflow and plugin authors; no
|
|
14
|
+
Scout internals knowledge is assumed beyond `LLM.agent`.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 1. Kinds require absolute roots
|
|
19
|
+
|
|
20
|
+
A path kind maps virtual paths (kind + path + location) to real
|
|
21
|
+
filesystem targets. Registration roots must be **absolute path strings**:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
agent.register_path_kind(
|
|
25
|
+
"scratch",
|
|
26
|
+
"description" => "Scratchpad files",
|
|
27
|
+
"roots" => {
|
|
28
|
+
"project" => File.expand_path("var/scratch", __dir__),
|
|
29
|
+
"tmp" => File.expand_path("tmp/scratch", __dir__)
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Relative roots are pinned against the effective path map at registration
|
|
35
|
+
time (see section 2), so by the time authorization runs every root is an
|
|
36
|
+
absolute path string. `path_authorize!` forwards absolute target and root
|
|
37
|
+
strings to `LLM::Sandbox.authorize_path`, which fails closed on anything
|
|
38
|
+
it cannot compare exactly (symlinks are resolved before comparison). There
|
|
39
|
+
is no fallback interpretation, so a relative root never widens access by
|
|
40
|
+
accident.
|
|
41
|
+
|
|
42
|
+
## 2. Path maps
|
|
43
|
+
|
|
44
|
+
Kinds may be declared with roots that are convenient relative spellings
|
|
45
|
+
(`"share/tasks"`, `"tmp/scratch"`) instead of pre-expanded absolute paths.
|
|
46
|
+
The engine resolves those spellings once, at registration, against a Scout
|
|
47
|
+
path map and stores the result as a pinned absolute `String`. The
|
|
48
|
+
filesystem boundary then never re-resolves: `resolve_path` joins
|
|
49
|
+
`root[path]` on the pinned string, and the read/write/edit boundary does
|
|
50
|
+
plain `File.*` on the result. Nothing downstream can fall back through
|
|
51
|
+
Scout's map order again.
|
|
52
|
+
|
|
53
|
+
**Never re-resolve a target through `Path#find` after authorization.**
|
|
54
|
+
Authorization compares the resolved absolute target against the pinned
|
|
55
|
+
root exactly; `Path#find` on a missing/unlocated path can fall back
|
|
56
|
+
through `map_order` to `:user` (`~/.scout`) or compressed alternatives
|
|
57
|
+
(`.gz`/`.bgz`/`.zip`), so a `find`-re-resolved target could point outside
|
|
58
|
+
the root that was just authorized. Handlers and overrides receive the
|
|
59
|
+
authorized absolute `String` and must treat it as final.
|
|
60
|
+
Why pinning exists: Scout's `Path#find` walks `map_order` for a path that
|
|
61
|
+
is unlocated and missing, and the final map in that order is
|
|
62
|
+
`:default => :user` (`~/.scout`). A relative root held as an unlocated
|
|
63
|
+
Scout `Path` therefore targeted `~/.scout` exactly in the "write a NEW
|
|
64
|
+
draft" case, where the checkout copy does not exist yet. Pinning removes
|
|
65
|
+
the fallback entirely.
|
|
66
|
+
|
|
67
|
+
Two configuration points govern resolution:
|
|
68
|
+
|
|
69
|
+
- **Agent-level default**: `LLM.agent(path_map: :current)`. The name is
|
|
70
|
+
`path_map`; it applies whenever a kind does not set its own map and also
|
|
71
|
+
governs the implicit project root used by `resolve_path`/`path_authorize!`
|
|
72
|
+
when no explicit `"project"` root is configured. The default is
|
|
73
|
+
`:current` (the checkout; identical semantics to `Scout.root.find(:current)`).
|
|
74
|
+
- **Per-kind override**: the `"path_map"` definition key
|
|
75
|
+
(`"path_map" => :lib`), which takes precedence over the agent default.
|
|
76
|
+
|
|
77
|
+
Resolution is `Scout.root.find(path_map)`; for `:current` this is a plain
|
|
78
|
+
`String` pinned to the checkout root.
|
|
79
|
+
|
|
80
|
+
Compatibility rule: a root that is already absolute today keeps its
|
|
81
|
+
placement unchanged. Whether it was declared absolute or produced by
|
|
82
|
+
libdir/workflow-root logic in `workflow_kinds.rb`, it passes through
|
|
83
|
+
verbatim — pinning is only applied to relative spellings, and it only
|
|
84
|
+
applies even when an agent-level `path_map` is configured. Live kinds with
|
|
85
|
+
absolute roots therefore keep their current placement; the new default
|
|
86
|
+
only changes behavior for roots that would otherwise be relative
|
|
87
|
+
(the leak case).
|
|
88
|
+
|
|
89
|
+
Validation at registration raises `ParameterException` for:
|
|
90
|
+
|
|
91
|
+
- a `"path_map"` (or agent `path_map:`) value that is not a `String` or
|
|
92
|
+
`Symbol`;
|
|
93
|
+
- a map name Scout cannot resolve (`Path#find` raises `RuntimeError:
|
|
94
|
+
Map not found ...`), which is wrapped into the same `ParameterException`
|
|
95
|
+
envelope with the offending name.
|
|
96
|
+
|
|
97
|
+
Any `StandardError` raised while resolving the map or the root is wrapped
|
|
98
|
+
the same way, so an invalid configuration can never surface as a raw Ruby
|
|
99
|
+
exception.
|
|
100
|
+
|
|
101
|
+
### Job-directory pinning
|
|
102
|
+
|
|
103
|
+
Separately from kind roots, chat-task workflows built by
|
|
104
|
+
`lib/scout/llm/agent/workflow.rb` (`AgentWorkflow` and the
|
|
105
|
+
`LLM::Agent#workflow` anonymous module) previously resolved their job
|
|
106
|
+
directory through `Workflow.directory`, whose default is the *unlocated*
|
|
107
|
+
`Path.setup("var/jobs")`; the first `.find` on a job path then fell back
|
|
108
|
+
to `~/.scout/var/jobs`. The module now pins its directory to the
|
|
109
|
+
checkout's `var/jobs` (`:current`) the first time a `chat_task` or the
|
|
110
|
+
module is used, unless the workflow already declares an explicit
|
|
111
|
+
directory (`directory =` beats pinning, so tests and deployments that set
|
|
112
|
+
`Workflow.directory` keep their configured location).
|
|
113
|
+
|
|
114
|
+
### Dormant limitation
|
|
115
|
+
|
|
116
|
+
`path_list` used to call `Path#glob` on the resolved target when it looked
|
|
117
|
+
Path-like. With roots pinned absolute, targets are always plain `String`s,
|
|
118
|
+
so the branch has been hardened to always use `Dir.glob` on the pinned
|
|
119
|
+
absolute string (never re-resolving through map order). No known caller
|
|
120
|
+
supplies a `Path`-like target today.
|
|
121
|
+
|
|
122
|
+
### Out-of-repo leaks (H3, recorded as follow-ups)
|
|
123
|
+
|
|
124
|
+
The tool-layer `TmpFile`/`Open.write` scratch traffic that lands in
|
|
125
|
+
`~/.scout/tmp` for relative tool paths originates in the
|
|
126
|
+
Workspace/ComputerUse tool layer (gem `scout-gear` `TmpFile.tmpdir`
|
|
127
|
+
override), not in this engine. No code in this repository resolves those
|
|
128
|
+
paths; the fix belongs in the tool layer and is recorded as a follow-up
|
|
129
|
+
there. The durable record of the engine-side behavior is
|
|
130
|
+
`test/scout/llm/agent/test_path.rb` (absolute roots pass through
|
|
131
|
+
untouched even with an agent-level map configured).
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## 3. Registering a kind
|
|
135
|
+
|
|
136
|
+
The full entry shape:
|
|
137
|
+
|
|
138
|
+
```ruby
|
|
139
|
+
agent.register_path_kind(
|
|
140
|
+
"my_kind",
|
|
141
|
+
"description" => "What this kind is for",
|
|
142
|
+
"roots" => {"project" => "/abs/root"},
|
|
143
|
+
"locations" => ["project"], # optional; defaults to root keys
|
|
144
|
+
"default_location" => "project", # optional
|
|
145
|
+
"path_map" => :current, # optional; see section 2
|
|
146
|
+
"capabilities" => {"edit" => true, "patch" => true},
|
|
147
|
+
"sandbox" => true, # true/false, or a responder
|
|
148
|
+
"resolve" => ->(agent, path, location) { ... }
|
|
149
|
+
)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- `capabilities` accepts an Array of enabled operation names or a Hash
|
|
153
|
+
merged over `DEFAULT_CAPABILITIES` (`read`, `write`, `edit`, `list`,
|
|
154
|
+
`move`, `rename`, `delete` on by default; `validate`, `test`,
|
|
155
|
+
`promote`, `smoke`, and `patch` off by default).
|
|
156
|
+
- `"resolve"` returns the real path for a virtual one; the default
|
|
157
|
+
joins the kind root, the location and the path.
|
|
158
|
+
- Kind hooks: `"list"`, `"validate"`, `"test"`, `"smoke"`,
|
|
159
|
+
`"promotion_destination"`, `"promotion_post_move"` (besides
|
|
160
|
+
`"resolve"`). Registration is instance-local: kinds registered on one
|
|
161
|
+
agent are invisible to other agents.
|
|
162
|
+
- `"sandbox"` gates path authorization per kind: when true (the default),
|
|
163
|
+
every operation is authorized against the kind roots through
|
|
164
|
+
`LLM::Sandbox.authorize_path` before any callback runs. The shared
|
|
165
|
+
sandbox model and its two layers are documented in
|
|
166
|
+
[Sandbox.md](Sandbox.md).
|
|
167
|
+
|
|
168
|
+
## 4. Declaring kinds in a workflow: `PATH_KINDS`
|
|
169
|
+
|
|
170
|
+
A workflow may declare the path kinds it provides as a `PATH_KINDS`
|
|
171
|
+
constant in its own namespace. An agent enables a workflow's kinds
|
|
172
|
+
through the `path_kind:` chat role (section 4.1); a whole-workflow
|
|
173
|
+
`tool: MyWorkflow` line still grants kinds, but only for agents without
|
|
174
|
+
a start_chat file (the back-compat path). Task-level imports
|
|
175
|
+
(`tool: MyWorkflow some_task`) register nothing.
|
|
176
|
+
|
|
177
|
+
The declaration is part of the workflow's Ruby, and the grant happens
|
|
178
|
+
when an agent enables the kinds: merely loading a workflow's files
|
|
179
|
+
registers nothing anywhere, and the constant alone grants nothing. The
|
|
180
|
+
two supported shapes are a Hash of kind name to definition, or an Array
|
|
181
|
+
of definition Hashes each carrying its own `"name"` key:
|
|
182
|
+
|
|
183
|
+
```ruby
|
|
184
|
+
module MyWorkflow
|
|
185
|
+
extend Workflow
|
|
186
|
+
|
|
187
|
+
PATH_KINDS = {
|
|
188
|
+
"notes" => {
|
|
189
|
+
"description" => "Agent-visible notes area",
|
|
190
|
+
"roots" => {"project" => File.expand_path("var/notes", __dir__)},
|
|
191
|
+
"capabilities" => {"read" => true, "edit" => true, "list" => true}
|
|
192
|
+
},
|
|
193
|
+
"scratch" => {
|
|
194
|
+
"description" => "Disposable scratch files",
|
|
195
|
+
"roots" => {"tmp" => File.expand_path("tmp/scratch", __dir__)}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
end
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The same content as an Array:
|
|
202
|
+
|
|
203
|
+
```ruby
|
|
204
|
+
module MyWorkflow
|
|
205
|
+
PATH_KINDS = [
|
|
206
|
+
{
|
|
207
|
+
"name" => "notes",
|
|
208
|
+
"description" => "Agent-visible notes area",
|
|
209
|
+
"roots" => {"project" => File.expand_path("var/notes", __dir__)}
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
end
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Each entry is exactly what `register_path_kind` accepts for a single
|
|
216
|
+
kind (section 3), so `roots`, `locations`, `capabilities`, `overrides`
|
|
217
|
+
and `operations` all mean the same thing here.
|
|
218
|
+
|
|
219
|
+
Behavior at incorporation:
|
|
220
|
+
|
|
221
|
+
- **Discovery is namespace-local.** The constant is looked up with
|
|
222
|
+
`const_defined?(:PATH_KINDS, false)` on the workflow's own namespace,
|
|
223
|
+
so a constant inherited from a parent module or superclass is not
|
|
224
|
+
discovered.
|
|
225
|
+
- **Enabling is chat-level and explicit.** A `path_kind: MyWorkflow`
|
|
226
|
+
line registers every kind of that workflow; `path_kind: MyWorkflow
|
|
227
|
+
notes` registers exactly `notes` (see section 4.1). A whole-workflow
|
|
228
|
+
`tool: MyWorkflow` line still registers the kinds, but only for an
|
|
229
|
+
agent without a start_chat file; task-level `tool:` lines, remote
|
|
230
|
+
`tool:` targets and unresolvable workflow names register nothing, and
|
|
231
|
+
a workflow with no `PATH_KINDS` constant is a silent no-op unless a
|
|
232
|
+
`path_kind:` line names one of its kinds (then that name is unknown
|
|
233
|
+
and fails loudly).
|
|
234
|
+
- **Definitions are deep-copied before registration.** `register_path_kind`
|
|
235
|
+
copies only one level and `Hash#freeze` is shallow, so the
|
|
236
|
+
incorporation path makes a full copy first; the shared frozen
|
|
237
|
+
`PATH_KINDS` constant is never mutated through the registry, and
|
|
238
|
+
mutating a registered definition never changes the workflow's
|
|
239
|
+
constant.
|
|
240
|
+
- **Provenance is recorded per kind.** Each enabled kind name is
|
|
241
|
+
mapped to its workflow in `agent.path_kind_sources` (bookkeeping
|
|
242
|
+
only; the authoritative registry is `agent.path_kind_registry`).
|
|
243
|
+
- **A kind name belongs to one workflow.** If two different workflows
|
|
244
|
+
supply the same kind name to one agent, enabling raises
|
|
245
|
+
`ParameterException` naming both workflows and the kind; the order of
|
|
246
|
+
the lines never decides. Enabling the same workflow again is
|
|
247
|
+
idempotent: the kind is re-registered in place and the aggregated
|
|
248
|
+
tools are refreshed without duplicates.
|
|
249
|
+
- **Malformed declarations fail loudly.** A `PATH_KINDS` that is not a
|
|
250
|
+
Hash (or Array of Hashes), or an entry that is not a Hash, raises
|
|
251
|
+
`ParameterException` naming the workflow, the kind and the actual
|
|
252
|
+
class, for example:
|
|
253
|
+
`Workflow "MyWorkflow" declares PATH_KINDS as a String; expected a
|
|
254
|
+
Hash of kind name => definition (or an Array of definition Hashes
|
|
255
|
+
with a "name" key)`.- **Malformed declarations fail loudly.** A `PATH_KINDS` that is not a
|
|
256
|
+
Hash (or Array of Hashes), or an entry that is not a Hash, raises
|
|
257
|
+
`ParameterException` naming the workflow, the kind and the actual
|
|
258
|
+
class, for example:
|
|
259
|
+
`Workflow "MyWorkflow" declares PATH_KINDS as a String; expected a
|
|
260
|
+
Hash of kind name => definition (or an Array of definition Hashes
|
|
261
|
+
with a "name" key)`.
|
|
262
|
+
|
|
263
|
+
Incorporation behavior is pinned by
|
|
264
|
+
`test/scout/llm/agent/test_path_workflow_integration.rb`
|
|
265
|
+
(`test_whole_workflow_tool_line_registers_kinds_and_installs_tools`,
|
|
266
|
+
`test_task_level_tool_line_registers_nothing`,
|
|
267
|
+
`test_conflict_between_two_workflows_raises_naming_both`,
|
|
268
|
+
`test_frozen_path_kinds_constant_is_never_mutated`,
|
|
269
|
+
`test_path_role_no_longer_installs_path_tools`); registration and
|
|
270
|
+
registry rollback by `test/scout/llm/agent/test_path.rb`
|
|
271
|
+
(`test_register_path_kind`,
|
|
272
|
+
`test_invalid_location_root_and_default_declarations_are_atomic`,
|
|
273
|
+
`test_failed_kind_registration_rolls_back_registry_and_tool_surface_recovers`,
|
|
274
|
+
`test_conflicting_contracts_are_rejected_at_installation`).
|
|
275
|
+
|
|
276
|
+
Enabling a kind directly in Ruby is still done with `register_path_kind`
|
|
277
|
+
(iterated over a mapping of kinds when needed) or `load_path_plugins`.
|
|
278
|
+
Authorization is unchanged in every case: every operation still goes
|
|
279
|
+
through `LLM::Sandbox.authorize_path`, which fails closed.
|
|
280
|
+
|
|
281
|
+
## 4.1 The `path_kind:` chat role
|
|
282
|
+
|
|
283
|
+
The `path_kind:` role is the chat-level channel for enabling a
|
|
284
|
+
workflow's kinds on an agent. Line syntax:
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
path_kind: <Workflow> [<kind>...]
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
- The first token names the workflow, resolved exactly like a
|
|
291
|
+
`tool:` line target (`Chat.load_workflow`); the remaining tokens are
|
|
292
|
+
kind names. `path_kind: ScoutCoder` with no kind names enables every
|
|
293
|
+
kind the workflow declares; `path_kind: ScoutCoder probe` enables
|
|
294
|
+
exactly `probe`. Multiple kinds on one line and multiple lines
|
|
295
|
+
accumulate.
|
|
296
|
+
- Explicit `path_kind:` lines are honored wherever they appear — in a
|
|
297
|
+
start_chat file or in the live chat.
|
|
298
|
+
- An agent **with a start_chat file** gets no implicit kinds at all: a
|
|
299
|
+
start_chat with no `path_kind:` lines enables zero kinds, and for
|
|
300
|
+
such agents a whole-workflow `tool: W` line configures tools only,
|
|
301
|
+
never kinds.
|
|
302
|
+
- An agent **without a start_chat file** defaults to load-all: every
|
|
303
|
+
kind of its own workflow (when it declares `PATH_KINDS`) plus the
|
|
304
|
+
whole-workflow `tool:` incorporation retained as back-compat.
|
|
305
|
+
- Failures are loud. A kind name the workflow does not declare, or a
|
|
306
|
+
workflow that cannot be loaded, raises `ParameterException` naming
|
|
307
|
+
the workflow, the offending kind(s) and the valid kind names; a
|
|
308
|
+
failed selection registers nothing.
|
|
309
|
+
- `path_kind:` lines are never model-visible: registration happens from
|
|
310
|
+
the full message list before the role is stripped, so `clear_tools`
|
|
311
|
+
or role removal cannot bypass it.
|
|
312
|
+
|
|
313
|
+
## 5. Overriding a built-in without changing its schema
|
|
314
|
+
|
|
315
|
+
A kind may replace a built-in's implementation through the `"overrides"`
|
|
316
|
+
key. The engine always owns the public tool schema: the agent still sees
|
|
317
|
+
the same `path_edit` (or `path_read`, ...) arguments, and the kind
|
|
318
|
+
capability gate still applies — an override cannot resurrect an
|
|
319
|
+
operation the kind lacks the capability for.
|
|
320
|
+
|
|
321
|
+
**Only `write`, `edit` and `patch` can be overridden.** These are the
|
|
322
|
+
built-ins whose dispatch actually consults the operation table, so an
|
|
323
|
+
override registered for any other built-in could never run. Such a
|
|
324
|
+
registration is rejected loudly at `register_path_kind` time with a
|
|
325
|
+
`ParameterException` naming the supported set. The remaining built-ins
|
|
326
|
+
are customized through their own hook mechanisms, not overrides:
|
|
327
|
+
`"list"` via the `"list"` definition key, `"validate"`/`"smoke"` via the
|
|
328
|
+
`"validate"`/`"smoke"` definition keys (dispatched by
|
|
329
|
+
`path_kind_operation`), and `"promote"` via the `"promotion_destination"`
|
|
330
|
+
and `"promotion_post_move"` definition keys (its legacy mover hook is
|
|
331
|
+
retired). `read`, `move`, `rename` and
|
|
332
|
+
`delete` have none at all.
|
|
333
|
+
|
|
334
|
+
Each overridable built-in accepts a specific set of handler types:
|
|
335
|
+
|
|
336
|
+
| operation | accepted `type` values | undeclared default |
|
|
337
|
+
|---|---|---|
|
|
338
|
+
| `write` | `:content`, `:full` | `:content` |
|
|
339
|
+
| `edit` | `:content`, `:full` | `:content` |
|
|
340
|
+
| `patch` | `:content` only | `:content` |
|
|
341
|
+
|
|
342
|
+
A `type` outside the operation's accepted set is rejected at
|
|
343
|
+
registration with a `ParameterException` naming the accepted values;
|
|
344
|
+
declaring `"type" => :full` for `patch` fails because patch dispatches
|
|
345
|
+
its override as a strict content transform (it applies a unified diff
|
|
346
|
+
and never hands the handler a write).
|
|
347
|
+
|
|
348
|
+
```ruby
|
|
349
|
+
agent.register_path_kind(
|
|
350
|
+
"fancy",
|
|
351
|
+
"roots" => {"/tmp/fancy" => "/tmp/fancy"},
|
|
352
|
+
"capabilities" => {"edit" => true},
|
|
353
|
+
"overrides" => {
|
|
354
|
+
"edit" => ->(content, args) { content.upcase }
|
|
355
|
+
}
|
|
356
|
+
)
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
The example above registers a `:content` edit override (the undeclared
|
|
360
|
+
default). Override call shapes follow the declared `type`:
|
|
361
|
+
|
|
362
|
+
- `:content` (the default): the engine resolves and authorizes the
|
|
363
|
+
target, reads it, calls `implementation.call(content, args)`, and
|
|
364
|
+
writes the result back through the same authorized
|
|
365
|
+
target. The handler receives **no path** and cannot redirect the
|
|
366
|
+
write. The result's final-newline state is normalized to the ORIGINAL
|
|
367
|
+
file's termination, whatever the handler returned. The handler **must
|
|
368
|
+
return a String**; a non-String return is converted to a
|
|
369
|
+
`ParameterException` naming the contract (see section 9).
|
|
370
|
+
- For `edit` specifically: under a `:content` edit override the
|
|
371
|
+
`selector` and `replacement` arguments are still **validated** (they
|
|
372
|
+
are required by the tool schema) but are **not applied** — the
|
|
373
|
+
handler's returned content IS the edited file, wholesale. A
|
|
374
|
+
`:content` edit override replaces the edit transform entirely; a
|
|
375
|
+
kind that wants selector semantics must not override `edit` at all.
|
|
376
|
+
- `:full`: `implementation.call(agent, target, args)` receives the
|
|
377
|
+
resolved, authorized target and must return a **Hash payload**; a
|
|
378
|
+
non-Hash return is converted to a `ParameterException` naming the
|
|
379
|
+
contract. The handler performs the write itself, but the canonical
|
|
380
|
+
result keys stay **engine-authoritative**: the engine composes
|
|
381
|
+
`doc_id`/`kind`/`path`/`location`/`target_file`/`written` (write) or
|
|
382
|
+
`doc_id`/`kind`/`path`/`changed`/`content` (edit) itself and
|
|
383
|
+
**ignores** any attempt by the payload to set them; other payload keys
|
|
384
|
+
are merged into the result additively. The engine verifies reality
|
|
385
|
+
instead of trusting the handler's claim: `write` reports `target_file`
|
|
386
|
+
as the authorized target and `written` as actual existence there;
|
|
387
|
+
`edit` reads `content`/`changed` back from the authorized target after
|
|
388
|
+
the handler returns. This is trusted plugin code (see section 9).
|
|
389
|
+
|
|
390
|
+
Authorization completes **before** any handler call, for both types: an
|
|
391
|
+
authorization failure invokes no override and mutates nothing.
|
|
392
|
+
|
|
393
|
+
## 6. Introducing a custom operation
|
|
394
|
+
|
|
395
|
+
New operations are declared under `"operations"`:
|
|
396
|
+
|
|
397
|
+
```ruby
|
|
398
|
+
agent.register_path_kind(
|
|
399
|
+
"notes",
|
|
400
|
+
"roots" => {"/tmp/notes" => "/tmp/notes"},
|
|
401
|
+
"operations" => {
|
|
402
|
+
"precise_edit" => {
|
|
403
|
+
"description" => "Replace exactly count occurrences",
|
|
404
|
+
"parameters" => {
|
|
405
|
+
"properties" => {
|
|
406
|
+
"old_text" => {"type" => "string"},
|
|
407
|
+
"new_text" => {"type" => "string"},
|
|
408
|
+
"count" => {"type" => "integer", "default" => 1}
|
|
409
|
+
},
|
|
410
|
+
"required" => ["old_text", "new_text"]
|
|
411
|
+
},
|
|
412
|
+
"implementation" => ->(agent, target, args) {
|
|
413
|
+
# :full handler; :content handlers get (content, args) instead
|
|
414
|
+
{ "replaced" => ... }
|
|
415
|
+
},
|
|
416
|
+
"authorization" => :write, # :read or :write; default :write
|
|
417
|
+
"type" => :full # :content or :full; default :full
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
)
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
The registered operation appears as one agent tool (`precise_edit`)
|
|
424
|
+
whose arguments are `kind` + `path` + `location` + the declared
|
|
425
|
+
parameters. Support, authorization mode and implementation are all read
|
|
426
|
+
from the canonical `operation_table` stored in the kind definition at
|
|
427
|
+
registration time: `path_operation_support?(kind, op)` and
|
|
428
|
+
`path_operation_implementation(kind, op)` wrap the table lookups
|
|
429
|
+
(`operation_table[op]["authorization"]` is the mode;
|
|
430
|
+
`path_kind_definition(kind)["operations"][op]` the custom spec;
|
|
431
|
+
`["overrides"][op]` the override).
|
|
432
|
+
|
|
433
|
+
Registration validation raises `ParameterException` for: an operation
|
|
434
|
+
name colliding with a built-in, a non-callable implementation, an
|
|
435
|
+
unknown authorization mode or handler type, an override whose target is
|
|
436
|
+
not a built-in, an override of a built-in outside the dispatchable set
|
|
437
|
+
(`write`/`edit`/`patch`, see section 5), an override whose declared
|
|
438
|
+
`type` is not accepted by its target operation, or a declared parameter
|
|
439
|
+
colliding with the reserved `kind`/`path`/`location` arguments.
|
|
440
|
+
|
|
441
|
+
## 7. Parameter collision policy
|
|
442
|
+
|
|
443
|
+
When several kinds register the same operation name, exactly one tool
|
|
444
|
+
is installed. Their parameter contracts must match exactly after
|
|
445
|
+
normalization:
|
|
446
|
+
|
|
447
|
+
- Hash keys are compared stringified.
|
|
448
|
+
- `type` entries must be equal.
|
|
449
|
+
- `required` and `enum` are compared as unordered sets.
|
|
450
|
+
- `default` values are compared by equality.
|
|
451
|
+
- Nested hashes (and lists of hashes) are compared recursively with the
|
|
452
|
+
same rules.
|
|
453
|
+
|
|
454
|
+
The `description` is **not** compared; the description of the tool is
|
|
455
|
+
the one from the **last registration** (registry insertion order). A
|
|
456
|
+
contract mismatch raises `ParameterException` naming the operation, both
|
|
457
|
+
kinds, and the concrete differences, e.g.
|
|
458
|
+
`parameters.properties.old_text.type differs: "string" vs "integer"`.
|
|
459
|
+
|
|
460
|
+
Tool installation is refreshed on every registration: custom tools
|
|
461
|
+
become available immediately and no previously installed tool is
|
|
462
|
+
dropped. Registration is atomic — if tool installation fails, the
|
|
463
|
+
half-registered kind is removed again.
|
|
464
|
+
|
|
465
|
+
The installed surface is `path_kinds` plus one tool per built-in
|
|
466
|
+
operation that at least one registered kind enables: the seven generic
|
|
467
|
+
operations (`read write edit list move rename delete`), the four special
|
|
468
|
+
operations (`validate promote smoke patch`), plus `path_kinds` itself —
|
|
469
|
+
at most 12 engine tools, before any kind-specific custom operations.
|
|
470
|
+
|
|
471
|
+
`path_kinds` takes an optional `kind`. With no `kind` (or an empty
|
|
472
|
+
string) it returns one entry per registered kind; with a `kind` it
|
|
473
|
+
returns exactly that kind's entry, in the same per-kind shape as the
|
|
474
|
+
full-map entries (`description`, `locations`, `default_location`,
|
|
475
|
+
`sandbox`, `capabilities`). An unknown `kind` raises `ParameterException`
|
|
476
|
+
(`Unknown path kind: <kind> (available: <sorted kind names>)`).
|
|
477
|
+
|
|
478
|
+
## 8. Root selectors address the kind root, never a file
|
|
479
|
+
|
|
480
|
+
The empty string, `"."` and `"./"` all address the kind **root as a
|
|
481
|
+
whole**. They are enumeration selectors, not file paths, and the ten
|
|
482
|
+
file-shaped built-in operations reject them at the argument-validation
|
|
483
|
+
point, before resolution or authorization:
|
|
484
|
+
|
|
485
|
+
- rejected by `path_read`, `path_write`, `path_patch`, `path_edit`,
|
|
486
|
+
`path_move`, `path_rename`, `path_delete`, `path_validate`,
|
|
487
|
+
`path_smoke` and `path_promote`;
|
|
488
|
+
- every rejection is `ParameterException`:
|
|
489
|
+
`Invalid path for <operation>: "<value>" addresses the kind root; use
|
|
490
|
+
a path relative to the root, or path_list to enumerate the root`.
|
|
491
|
+
Without the rejection, a `"."` on an extension-bearing kind would
|
|
492
|
+
resolve to the junk target `<root>/..<ext>` (previously a silent
|
|
493
|
+
create on write and an empty listing on read);
|
|
494
|
+
- `path_list` is the enumeration surface: a `.`/`./` prefix is
|
|
495
|
+
normalized to the empty prefix and lists the kind root, exactly like
|
|
496
|
+
an omitted path;
|
|
497
|
+
- `path_dispatch` is deliberately exempt. Custom operations own their
|
|
498
|
+
path grammar and may legitimately receive `"."` (for example a
|
|
499
|
+
suite-scope enumeration); the engine passes the value through as
|
|
500
|
+
given. A custom operation's `path` argument still names one file
|
|
501
|
+
unless that operation documents otherwise.
|
|
502
|
+
|
|
503
|
+
The grammar is pinned by
|
|
504
|
+
`test/scout/llm/agent/test_path_errors.rb`
|
|
505
|
+
(`test_error_matrix_root_selector_rejected_by_every_file_shaped_operation`,
|
|
506
|
+
`test_path_write_root_selector_creates_no_file`) and
|
|
507
|
+
`test/scout/llm/agent/test_path.rb`
|
|
508
|
+
(`test_path_list_root_selector_lists_the_kind_root`,
|
|
509
|
+
`test_path_dispatch_passes_root_selector_to_custom_operation`).
|
|
510
|
+
|
|
511
|
+
## 9. Callback contract and trust boundary
|
|
512
|
+
|
|
513
|
+
Callbacks run **only after** kind validation, path resolution,
|
|
514
|
+
capability checks and authorization have all succeeded. An
|
|
515
|
+
authorization failure invokes no callback and mutates nothing.
|
|
516
|
+
|
|
517
|
+
- `:content` handlers are engine-mediated: the engine reads the
|
|
518
|
+
authorized target, passes the content, and writes the result back to
|
|
519
|
+
the same target. The handler cannot name another file, and returned
|
|
520
|
+
text is content, never a redirection.
|
|
521
|
+
- `:full` handlers are trusted plugin code. The engine authorizes the
|
|
522
|
+
declared target before invoking, but cannot constrain what files the
|
|
523
|
+
handler touches after that; `:full` handlers default to write
|
|
524
|
+
authorization and their authors are responsible for staying inside
|
|
525
|
+
authorized roots.
|
|
526
|
+
|
|
527
|
+
Errors follow the engine contract: invalid arguments, missing files and
|
|
528
|
+
failed authorization raise `ParameterException` (a Scout exception).
|
|
529
|
+
The agent-facing tool callables serialize Scout exceptions as
|
|
530
|
+
`{"exception": ..., "exception_line": ...}`; non-Scout exceptions are
|
|
531
|
+
not caught there. Custom-operation handlers must therefore normalize
|
|
532
|
+
their own failures. The engine guards its own mediated call sites:
|
|
533
|
+
an override `:content` handler returning a non-String (for `write`,
|
|
534
|
+
`edit` or `patch`) or a `:full` handler returning a non-Hash is
|
|
535
|
+
converted to a `ParameterException` naming the contract and serialized
|
|
536
|
+
as an error envelope, never a raw `NoMethodError`/`ArgumentError`
|
|
537
|
+
escape.
|
|
538
|
+
|
|
539
|
+
The trust boundary is pinned by
|
|
540
|
+
`test/scout/llm/agent/test_path_filesystem.rb`
|
|
541
|
+
(`test_sandbox_denies_custom_operation_before_callback`,
|
|
542
|
+
`test_sandbox_fails_closed_when_authorizer_is_unavailable`,
|
|
543
|
+
`test_path_write_success_is_at_the_authorized_target`,
|
|
544
|
+
`test_path_write_denies_resolver_target_outside_root`,
|
|
545
|
+
`test_path_write_filesystem_failure_does_not_return_success`),
|
|
546
|
+
`test/scout/llm/agent/test_path.rb`
|
|
547
|
+
(`test_dispatch_authorization_failure_runs_no_callback_and_mutates_nothing`,
|
|
548
|
+
`test_dispatch_content_op_cannot_redirect_write_to_other_file`,
|
|
549
|
+
`test_dispatch_edit_override_authorization_failure_runs_no_override`,
|
|
550
|
+
`test_write_override_authorization_failure_runs_no_handler`) and
|
|
551
|
+
`test/scout/llm/agent/test_path_edit.rb`
|
|
552
|
+
(`test_full_edit_override_authorization_failure_runs_no_handler`).
|
|
553
|
+
|
|
554
|
+
The error surface per failure class is pinned by
|
|
555
|
+
`test/scout/llm/agent/test_path_errors.rb` (its `test_error_matrix_*`
|
|
556
|
+
cases: unknown kind/location, missing argument, invalid or malformed
|
|
557
|
+
selector, path outside grant, unsupported operation, the root-selector
|
|
558
|
+
rejections of section 8, and the `path_kinds` unknown-kind error of
|
|
559
|
+
section 7).
|
|
560
|
+
|
|
561
|
+
## 10. Single-file patch; multi-file changes are not supported
|
|
562
|
+
|
|
563
|
+
`patch` is a built-in operation, default-off (`"patch" => true` in
|
|
564
|
+
capabilities to enable). Its tool takes `kind`, `path`, optional
|
|
565
|
+
`location`, and `patch` — a standard single-file unified diff:
|
|
566
|
+
|
|
567
|
+
```
|
|
568
|
+
--- a/notes.txt
|
|
569
|
+
+++ b/notes.txt
|
|
570
|
+
@@ -1,3 +1,3 @@
|
|
571
|
+
alpha
|
|
572
|
+
-beta
|
|
573
|
+
+BETA
|
|
574
|
+
gamma
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
- Exactly one `---`/`+++` header pair; a second pair is rejected as a
|
|
578
|
+
multi-file patch before any mutation.
|
|
579
|
+
- Header filenames are ignored as target selectors: the target is
|
|
580
|
+
always the kind/path-resolved file, and a header naming another file
|
|
581
|
+
never redirects or creates it.
|
|
582
|
+
- `@@ -l[,s] +l[,s] @@` hunks with context, `-` and `+` lines; `\ No
|
|
583
|
+
newline at end of file` markers are honored on both sides.
|
|
584
|
+
- Application is strict: hunks apply in order with exact context
|
|
585
|
+
matching at the stated line (plus the accumulated offset of earlier
|
|
586
|
+
hunks). There is no fuzz and no offset search. Any mismatch rejects
|
|
587
|
+
the whole patch with `ParameterException` — all hunks apply or none,
|
|
588
|
+
and a failed patch writes zero bytes.
|
|
589
|
+
|
|
590
|
+
Multi-file patching is **not** part of the Path engine: coordinated
|
|
591
|
+
changes across several targets belong to the sandboxed terminal
|
|
592
|
+
mechanism (`bash` etc.), not to a Path operation.
|
|
593
|
+
|
|
594
|
+
The patch contract is pinned by `test/scout/llm/agent/test_path_patch.rb`
|
|
595
|
+
(`test_patch_applies_simple_diff_and_preserves_untouched_bytes`,
|
|
596
|
+
`test_patch_multi_file_rejected_before_mutation`,
|
|
597
|
+
`test_patch_header_filename_cannot_redirect_target`,
|
|
598
|
+
`test_patch_multi_hunk_is_all_or_nothing`,
|
|
599
|
+
`test_patch_no_newline_marker_adds_and_removes_final_newline`,
|
|
600
|
+
`test_patch_default_off_and_capability_enables`,
|
|
601
|
+
`test_patch_on_unauthorized_target_writes_nothing`).
|
|
602
|
+
|
|
603
|
+
## 11. `edit` selector semantics are byte-exact (pinned by tests)
|
|
604
|
+
|
|
605
|
+
`path_edit` never normalizes whitespace. Untouched content is copied
|
|
606
|
+
byte-identically; only the selected span changes. The contracts below are
|
|
607
|
+
pinned by the newline test matrix in
|
|
608
|
+
`test/scout/llm/agent/test_path_edit.rb` (the original 12-case matrix has
|
|
609
|
+
grown; any change to these behaviors must update those tests deliberately,
|
|
610
|
+
never by deleting them):
|
|
611
|
+
|
|
612
|
+
- `lines` selectors are 0-based with an **exclusive** `end`; each line
|
|
613
|
+
includes its terminator and the final line may lack one.
|
|
614
|
+
- `start == lines.length` (insertion-at-end) is allowed and appends;
|
|
615
|
+
`start > lines.length` raises. `end` beyond the document clamps to the
|
|
616
|
+
end (clamping is deliberate, not leniency).
|
|
617
|
+
- At an **interior** boundary (a line follows the span) the replacement is
|
|
618
|
+
terminated with exactly one newline: a missing one is added, repeated
|
|
619
|
+
ones collapse.
|
|
620
|
+
- At an **EOF-spanning** boundary the result's final-newline state is
|
|
621
|
+
inherited from the ORIGINAL document, bidirectionally: a replacement
|
|
622
|
+
ending in `\n` must not introduce a final newline the original lacked,
|
|
623
|
+
and deleting the last line of a file without a final newline must not
|
|
624
|
+
add one. A replacement's trailing newlines are stripped in that case.
|
|
625
|
+
- `regexp` selectors use `Regexp.new` with a narrow `RegexpError` rescue
|
|
626
|
+
(invalid patterns surface as `ParameterException`, never a raw Ruby
|
|
627
|
+
exception); `chars` selectors use byte/character-index splice with
|
|
628
|
+
`start <= end` enforced.
|