Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/architecture/rust-agent/plugins/WorkspaceTools.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ empty live preview and unavailable historical captures.

## FileReads

Owner: [workspace_tools/file_reads.rs](../../../../crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs).
Owner: [workspace_tools/file_reads.rs](../../../../crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs). The owner's target contract is [FileReads](../../../design/plugins/FileReads.md); this page describes the current implementation.
Records canonical-path bindings for files read on this branch: raw-byte revision,
encoding, BOM and line endings. Existing-file `edit` admission requires a binding
established by that branch. Existing-file `write` admission requires one whose
Expand Down
4 changes: 2 additions & 2 deletions docs/design/compaction-quality.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ The tool description says that Recall reads history from before a compaction, an

**Owner:** WorkspaceTools (FileReads); implemented under [#524](https://github.com/arcships/dim/issues/524).

A `write` that replaces an existing file needs a read that is still in the context. After a completed compaction cuts out the operation that bound the file, `write` refuses until any read of the file, a part included. `edit` keeps its binding, because its exact `oldText` match checks the content itself. A read in the kept tail still counts. A binding is what the model has seen of a file on this branch, and the bindings live in branch memory, which compaction never touches ([file_reads.rs](../../crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs)). The owner designs how, from the branch's own facts.
A `write` that replaces an existing file needs a read that is still in the context. After a completed compaction cuts out the operation that bound the file, `write` refuses until any read of the file, a part included. `edit` keeps its binding, because its exact `oldText` match checks the content itself. A read in the kept tail still counts. A binding is what the model has seen of a file on this branch, and the bindings live in branch memory, which compaction never touches ([file_reads.rs](../../crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs)). The owner's operations and its rule for rebuilding the bindings from the branch's own facts are in the [FileReads owner contract](plugins/FileReads.md).

### 7.4 ToolRegistry (the tool contract)

Expand Down Expand Up @@ -161,7 +161,7 @@ Against [design rules §4](../architecture/rust-agent/principles.md#4-通过时
**Rule 8, with evidence.** No requirement reaches infrastructure:

- Class 2 uses the compaction record's existing `replacement` and replay rule ([ContextCompaction §2.2](plugins/ContextCompaction.md#22-extension-points), [§4.3](plugins/ContextCompaction.md#43-events)).
- FileReads folds the existing public `context/compaction` fact on its own branch; it needs no new event and no new service.
- FileReads reads the latest completed `context/compaction` on its own branch at `binding` with `write`; it needs no new event and no new service ([FileReads](plugins/FileReads.md)).
- Nothing is added to the Timeline for the UI: the TUI reads the existing `context/compaction-start` and `context/compaction`, which [§4.3](plugins/ContextCompaction.md#43-events) already lists for clients.

**Rules 1 and 7.** No requirement has one plugin decide for another or read another's state: ContextCompaction does not call FileReads, FileReads reacts to the public fact, and the TUI uses the existing session method.
Expand Down
2 changes: 1 addition & 1 deletion docs/design/contracts/runtime-owner-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ substitutes a newer head.
| --- | --- |
| ToolBinding, Session language and Agent configuration → `prompt` | `prompt.initialCompletion({}) → void or opening error`; `prompt.configure({sources, model?}) → unchanged, adopted or superseded`. |
| Prompt and guide adoption → `contextPreparation` | `contextPreparation.publish({adopted, changes, model?, toolAdoption?, inputs}) → sequence or null`; `awaitPublished({sequence}) → sequence`. Publication commits adoption atomically. |
| File read/edit/write tools → branch FileReads | `binding({path}) → TextFileBinding or null`, `writeBinding({path}) → absent, compacted or bound`, `record({path, binding, established}) → void`. The original read supplies the established sequence; file I/O stays on the file node. |
| File read/edit/write tools → branch FileReads | `binding({path, purpose}) → BindingReply` (`bound {binding}` or `unavailable {reason: neverRead\|compacted}`; `path` is canonical), `record({path, binding, established, ordinal}) → void` ([FileReads](../plugins/FileReads.md)). The call that establishes the binding supplies its own call event's `step/tool-call` sequence and its position in the batch; a batch's calls share that event, and a parent and its Code Mode child are ordered by their own events. The pair orders two operations on one path. File I/O stays on the file node. |

### Model preparation, history and tools

Expand Down
367 changes: 367 additions & 0 deletions docs/design/plugins/FileReads.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/design/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A plugin is split by the owner of its state into parts, each placed in its owner

| Plugin | Process part | Session part | Branch part | Phase / issue |
| --- | --- | --- | --- | --- |
| [FileReads](FileReads.md) (owner contract) | — | — | a line's text bindings and their context rule behind the `fileReads` operations | [#2028](https://github.com/arcships/dim/issues/2028) |
| [Migration](Migration.md) | on-demand import tasks, source mappings, progress and retry records; unloaded after settlement | — | — | [Delivery plan](../../plan/analysis/legacy-migration.md) |
| [Provider management](../appserver/provider-management.md) | existing Provider: configuration, catalogs, client preferences and management methods | — | — | #329 |
| [Questions](Questions.md) | — | `ask_user` tool, `session.question.respond`, waiters of running `ask_user` calls; no events | — | M2; #262 |
Expand Down Expand Up @@ -53,4 +54,4 @@ A plugin is split by the owner of its state into parts, each placed in its owner
| --- | --- |
| Process parts | Provider (management supplement), Scheduler, Workflow, ExternalAgent, Modality, PluginManager, RuntimeManager, RemoteGateway, Skills (installation), PromptSuggestion (the Settings source), `CodeMode` when installed, light-ocr in the daemon, EventHub, Report; AcpGateway in its client host process; ClientView (the connection's viewed line) |
| Session parts | Questions, ShellInput, Attachments, SessionTitle, Report, PromptSuggestion, Goal, Web, Recall, ImageUnderstanding, EventHub, Hooks, Scheduler, Workflow, PromptSources, Prompt (the entries table), Code Mode when enabled, SettingsTool (the one `settings` tool, registered by ExecutionSettings in v1) |
| Branch parts | Goal (with Pursuit), ModelRecovery (proposed), Hooks, Prompt, Code Mode when enabled, EnvironmentClientsBranch (registered by Connection), SettingsSnapshotBranch (registered by ExecutionSettings) |
| Branch parts | FileReads, Goal (with Pursuit), ModelRecovery (proposed), Hooks, Prompt, Code Mode when enabled, EnvironmentClientsBranch (registered by Connection), SettingsSnapshotBranch (registered by ExecutionSettings) |
12 changes: 6 additions & 6 deletions docs/design/resource-faces.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,12 @@ or changed one:
image.
- `write` and `edit` keep their refusals (`text_binding_required`, `file_modified_since_read`,
`is_directory`, `write_error`, `edit_target_file_too_large`) and their `effects: [fileWritten]`
declaration; the binding the control side holds from the branch's last read of that file travels
with the request, so the node normalizes and encodes exactly what the model's context was based
on. A file that changed since the read is `file_modified_since_read`. The reply's `binding` is
what the call installed.
- The control side records the returned binding in `FileReads` for the branch; that record stays
branch memory on the control node and is not reconstructed from the node.
declaration; the binding the control side holds from the branch's last operation that bound that
file travels with the request ([owner contract](plugins/FileReads.md)), so the node normalizes and
encodes exactly what the model's context was based on. A file that changed since that operation is
`file_modified_since_read`. The reply's `binding` is what the call installed.
- The control side records the returned binding in `FileReads` for the branch ([owner contract](plugins/FileReads.md)); that record stays
branch memory on the control node and is rebuilt from the branch's facts on reload, not from the node.
- `write` and `edit` are admitted before they run, so their `path` is the resolved path `resolve`
returned. `ToolHost.resolve_write` asks `fsHost.resolve` for a remote Session instead of
resolving locally; the resolved call is what approval and execution receive, as today.
Expand Down
2 changes: 1 addition & 1 deletion docs/design/service-faces.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Proposed target operations: [Session and branch operations](contracts/runtime-ow
| `toolExecutor` | branch | ToolExecutor | hot-path | 待迁移;按 #1292 定义操作面 |
| `configurationPublisher` | branch | ContextPreparation | hot-path | 待迁移;按 #1292 定义操作面 |
| `configureControl` | branch | Prompt | hot-path | 待迁移;按 #1292 定义操作面 |
| `fileReads` | branch | FileReads | hot-path | 待迁移;按 #1292 定义操作面 |
| `fileReads` | branch | FileReads | hot-path | 数据面见 [FileReads](plugins/FileReads.md) |
| `historyRenderer` | session | SessionScope | hot-path | 待迁移;按 #1292 定义操作面 |
| `contextModelHost` | session | SessionScope | hot-path | 待迁移;按 #1292 定义操作面 |
| `prepareModelHost` | session | PrepareModelHost | hot-path | 待迁移;按 #1292 定义操作面 |
Expand Down
4 changes: 2 additions & 2 deletions docs/design/timeline-branches.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ Why this changes no Goal behavior:

Lines share the Session's workspace. No line can know who changed a file, and the design does not try to attribute changes. The guard that already exists is enough:

- FileReads keeps a read binding per line.
- `edit` and `write` refuse with `file_modified_since_read` when a file changed after this line last read it, whoever changed it ([edit.rs](../../crates/dim-agent-capabilities/src/workspace_tools/files/edit.rs), [write.rs](../../crates/dim-agent-capabilities/src/workspace_tools/files/write.rs)).
- FileReads keeps a text binding per canonical path.
- `edit` and `write` refuse with `file_modified_since_read` when a file changed after the last operation that bound it, whoever changed it ([edit.rs](../../crates/dim-agent-capabilities/src/workspace_tools/files/edit.rs), [write.rs](../../crates/dim-agent-capabilities/src/workspace_tools/files/write.rs), [FileReads](plugins/FileReads.md)).

The rest is protocol, carried by the tool line's identity and by the tool description:

Expand Down
4 changes: 2 additions & 2 deletions docs/zh/design/compaction-quality.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

**所有者:** WorkspaceTools(FileReads);在 [#524](https://github.com/arcships/dim/issues/524) 下实现。

覆盖写已有文件的 `write` 需要一次仍在上下文里的读取。一次已完成的压缩把绑定该文件的那个操作切出去之后,`write` 会拒绝,直到重新读到这个文件的任意一部分。`edit` 保留它的绑定,因为它用精确的 `oldText` 匹配核对内容本身。留在尾部里的读取仍然算数。绑定是"这条分支上模型看过这个文件的什么",绑定放在内存里、压缩从不碰它([file_reads.rs](../../../crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs))。具体怎么判断由所有者设计,依据是分支自己的事实。
覆盖写已有文件的 `write` 需要一次仍在上下文里的读取。一次已完成的压缩把绑定该文件的那个操作切出去之后,`write` 会拒绝,直到重新读到这个文件的任意一部分。`edit` 保留它的绑定,因为它用精确的 `oldText` 匹配核对内容本身。留在尾部里的读取仍然算数。绑定是"这条分支上模型看过这个文件的什么",绑定放在内存里、压缩从不碰它([file_reads.rs](../../../crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs))。所有者的操作以及从分支自己的事实重建绑定的规则见 [FileReads 所有者契约](../../design/plugins/FileReads.md)。

### 7.4 ToolRegistry(工具合同)

Expand Down Expand Up @@ -161,7 +161,7 @@
**规则 8 的证据。** 没有哪条需求触到基础设施:

- 第 2 类用的是压缩记录现有的 `replacement` 与重放规则([ContextCompaction §2.2](plugins/ContextCompaction.md#22-扩展点)、[§4.3](plugins/ContextCompaction.md#43-事件))。
- FileReads 在自己分支上折叠公开的 `context/compaction` 事实;不需要新事件,也不需要新服务。
- FileReads 在 `binding` 且用途为 `write` 时读取自己分支上最新的已完成 `context/compaction`;不需要新事件,也不需要新服务([FileReads](../../design/plugins/FileReads.md))。
- 没有为 UI 往 Timeline 加任何东西:TUI 读的是现有的 `context/compaction-start` 和 `context/compaction`,[§4.3](plugins/ContextCompaction.md#43-事件) 本来就把它们列为客户端可见。

**规则 1 和 7。** 没有哪条需求让一个插件替另一个插件决定,或去读另一个插件的状态:ContextCompaction 不调用 FileReads,FileReads 是对公开事实作出反应;TUI 用的是现有的 session 方法。
Expand Down
3 changes: 2 additions & 1 deletion docs/zh/design/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

| 插件 | 进程部件 | Session 部件 | 分支部件 | 阶段 / issue |
| --- | --- | --- | --- | --- |
| [FileReads](../../../design/plugins/FileReads.md)(所有者契约) | — | — | 由 `fileReads` 操作承载的一条线的文本绑定及其上下文规则 | [#2028](https://github.com/arcships/dim/issues/2028) |
| [Migration](../../../design/plugins/Migration.md) | 按需加载的导入任务、来源映射、进度与重试记录;结算后卸载 | — | — | [实施计划](../../../plan/analysis/legacy-migration.md) |
| [Provider 管理](../appserver/provider-management.md) | 现有 Provider:配置、目录、客户端偏好与管理方法 | — | — | #329 |
| [Questions](Questions.md) | — | `ask_user` 工具、`session.question.respond`、运行中 `ask_user` 调用的等待者;没有事件 | — | M2;#262 |
Expand Down Expand Up @@ -46,4 +47,4 @@
| --- | --- |
| 进程部件 | daemon 内的 Provider(管理补充提案)、Scheduler、Workflow、ExternalAgent、Modality、PluginManager、RuntimeManager、RemoteGateway、Skills(安装)、PromptSuggestion(Settings 来源)、`CodeMode`(安装时)、light-ocr、EventHub;接入方宿主进程内的 AcpGateway |
| Session 部件 | Questions、ShellInput、Attachments、SessionTitle、PromptSuggestion、Goal、Web、Recall、EventHub、Hooks、Scheduler、Workflow、PromptSources、Prompt(条目表)、Code Mode(启用时) |
| 分支部件 | Goal(含 Pursuit)、ModelRecovery(拟议)、Hooks、Prompt、Code Mode(启用时) |
| 分支部件 | FileReads、Goal(含 Pursuit)、ModelRecovery(拟议)、Hooks、Prompt、Code Mode(启用时) |
4 changes: 2 additions & 2 deletions docs/zh/design/timeline-branches.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ key 与模式互不相关([history.rs](../../../crates/dim-agent-capabilities/

各线共用 Session 的工作区。没有哪条线能知道文件是谁改的,本设计也不去归属改动。现有的保护已经够用:

- FileReads 按线保留读取绑定。
- 文件在这条线上次读取之后改变时,`edit` 和 `write` 以 `file_modified_since_read` 拒绝,不管是谁改的([edit.rs](../../../crates/dim-agent-capabilities/src/workspace_tools/files/edit.rs)、[write.rs](../../../crates/dim-agent-capabilities/src/workspace_tools/files/write.rs))。
- FileReads 按 canonical path 保留文本绑定。
- 文件在这条线上最后一次建立绑定的操作之后改变时,`edit` 和 `write` 以 `file_modified_since_read` 拒绝,不管是谁改的([edit.rs](../../../crates/dim-agent-capabilities/src/workspace_tools/files/edit.rs)、[write.rs](../../../crates/dim-agent-capabilities/src/workspace_tools/files/write.rs)、[FileReads](../../design/plugins/FileReads.md))。

其余靠协议,写在线的身份块和工具描述里:

Expand Down