refactor(fs): split filesystem seam into provider ctx.fs + policy ctx.fileContext

Implements the split-the-filesystem-seam RFC. ctx.fs shrinks to a text-storage
provider seam (resolve/stat/readText/streamText/writeText/editText with branded
FsTargetKey/FsVersion and an explicit FsWriteExpectation); the new
dsh-file-context package owns the model-facing policy (read windowing,
observed-state, write/edit freshness) as the concrete ctx.fileContext service.

Authorization is now freshness-based rather than full/partial view: a windowed
read records the file version and authorizes a later edit when the file is
unchanged, removing the dead-end where reading lines 100-150 of a large file
could not edit line 120. editText stays a provider primitive so version guard +
literal match + atomic rewrite remain one critical section, and the stale check
runs before matching so a stale edit reports FS_STALE_VERSION. tool-fs injects
fileContext, never reaching around to ctx.fs (the no-bypass contract).
This commit is contained in:
Dudu-0223
2026-06-26 17:23:18 +08:00
parent c7a197fb5f
commit ef37ce3b9d
42 changed files with 1899 additions and 1466 deletions

View File

@@ -1,8 +1,8 @@
/**
* The model-facing `edit` tool: update an existing UTF-8 text file by replacing
* literal text, requiring a unique match by default. Execution goes through
* `ctx.fs`, which enforces prior observation and the stale-version guard and
* owns the literal-match semantics.
* `ctx.fileContext`, which enforces prior observation (the freshness policy)
* and delegates the literal-match + stale-guard critical section to `ctx.fs`.
*
* @module @deepseek-ai/dsh-tool-fs/edit
*/
@@ -60,8 +60,8 @@ export function apply(ctx: Context): void {
},
async execute(args, exec): Promise<ContentBlock[]> {
const input = parseEditArgs(args)
const target = await ctx.fs.resolve(input.filePath)
const outcome = await ctx.fs.edit(
const target = await ctx.fileContext.resolve(input.filePath)
const outcome = await ctx.fileContext.edit(
target,
{ oldString: input.oldString, newString: input.newString, replaceAll: input.replaceAll },
exec,
@@ -76,7 +76,7 @@ export function apply(ctx: Context): void {
export const name = 'fs-edit'
/** Services required by the `edit` tool plugin. */
export const inject = ['tools', 'fs', 'systemPrompt']
export const inject = ['tools', 'fileContext', 'systemPrompt']
/** Named helper for direct registration in the root plugin and tests. */
export const applyEditTool = apply