refactor(tool-fs): drop per-tool subpath plugins; adopt single-tsconfig build

Adapt the four fs packages to master's single-tsconfig build convention
(lib/types outDir + types path + files allowlist), brought in by the merge.

While doing so, drop dsh-tool-fs's /read//write//edit subpath plugins. They
were the only subpath-export package in the tree and forced bespoke tsdown,
tsconfig path, package.json files, and workspace-constraint handling that no
sibling tool package (e.g. dsh-tool-bash) carries, for a focused-deployment
use case no consumer needed. dsh-tool-fs is now a single root plugin that
registers read/write/edit, mirroring dsh-tool-bash; the per-tool registration
helpers stay internal modules the root composes. The file-context event-gate
RFC is amended to record the narrowed scope.
This commit is contained in:
Dudu-0223
2026-06-28 17:43:29 +08:00
parent 89b27ad442
commit 4a1177093a
16 changed files with 34 additions and 189 deletions

View File

@@ -15,7 +15,9 @@
"./package.json": "./package.json"
},
"files": [
"lib",
"lib/index.js",
"lib/types/**/*.d.ts",
"lib/types/**/*.d.ts.map",
"src"
],
"license": "BSD-3-Clause",

View File

@@ -15,7 +15,9 @@
"./package.json": "./package.json"
},
"files": [
"lib",
"lib/index.js",
"lib/types/**/*.d.ts",
"lib/types/**/*.d.ts.map",
"src"
],
"license": "BSD-3-Clause",

View File

@@ -15,7 +15,9 @@
"./package.json": "./package.json"
},
"files": [
"lib",
"lib/index.js",
"lib/types/**/*.d.ts",
"lib/types/**/*.d.ts.map",
"src"
],
"license": "BSD-3-Clause",

View File

@@ -11,14 +11,6 @@ await ctx.plugin(ToolFs) // this package — re
`@deepseek-ai/dsh-file-context` is **optional**: omit it and the tools run against the bare provider (unconditional write/overwrite/edit, no observed-state). A deployment that loads these tools is expected to also load it, so the behavior is read-before-write/edit.
Each tool also ships as a subpath plugin for focused deployments (each injects `fs`, not a policy service):
```ts ignore-check
import * as readPlugin from '@deepseek-ai/dsh-tool-fs/read'
import * as writePlugin from '@deepseek-ai/dsh-tool-fs/write'
import * as editPlugin from '@deepseek-ai/dsh-tool-fs/edit'
```
## Tools (schemas per [the filesystem tool schemas RFC](../../../docs/rfc/implemented/feature/2026-06-17-filesystem-tool-schemas.md))
| Tool | Arguments | Behavior |

View File

@@ -11,23 +11,13 @@
"types": "./lib/types/index.d.ts",
"default": "./lib/index.js"
},
"./read": {
"types": "./lib/types/read.d.ts",
"default": "./lib/read.js"
},
"./write": {
"types": "./lib/types/write.d.ts",
"default": "./lib/write.js"
},
"./edit": {
"types": "./lib/types/edit.d.ts",
"default": "./lib/edit.js"
},
"./src/*": "./src/*",
"./package.json": "./package.json"
},
"files": [
"lib",
"lib/index.js",
"lib/types/**/*.d.ts",
"lib/types/**/*.d.ts.map",
"src"
],
"license": "BSD-3-Clause",

View File

@@ -10,7 +10,7 @@
* tool stats ZERO times either way; a missing target is reported by the provider
* as `FS_STALE_VERSION`.
*
* @module @deepseek-ai/dsh-tool-fs/edit
* @module @deepseek-ai/dsh-tool-fs/src/edit
*/
import type { Context } from 'cordis'
@@ -50,7 +50,7 @@ export function formatEditOutput(displayPath: string, outcome: FsEditOutcome): s
}
/** Register the `edit` tool and its system-prompt guidance. */
export function apply(ctx: Context): void {
export function applyEditTool(ctx: Context): void {
ctx.systemPrompt.section({
name: 'tool:edit',
order: 102,
@@ -84,12 +84,3 @@ export function apply(ctx: Context): void {
},
}))
}
/** Cordis plugin name used by loader diagnostics. */
export const name = 'fs-edit'
/** Services required by the `edit` tool plugin. */
export const inject = ['tools', 'fs', 'systemPrompt']
/** Named helper for direct registration in the root plugin and tests. */
export const applyEditTool = apply

View File

@@ -1,9 +1,6 @@
/**
* The model-facing filesystem tool suite (`read`, `write`, `edit`) over the
* `ctx.fs` provider seam. This root plugin registers all three tools by
* composing the per-tool registration helpers; each tool is also exposed as a
* subpath plugin (`@deepseek-ai/dsh-tool-fs/read`, `/write`, `/edit`) for focused
* deployments.
* `ctx.fs` provider seam. This single plugin registers all three tools.
*
* ## The tool is the executor; policy is an event gate
*

View File

@@ -8,7 +8,7 @@
* the model-facing schema, argument validation, read windowing, and result
* formatting; the freshness/observation policy is not its concern.
*
* @module @deepseek-ai/dsh-tool-fs/read
* @module @deepseek-ai/dsh-tool-fs/src/read
*/
import type { Context } from 'cordis'
@@ -72,7 +72,7 @@ ${body}
}
/** Register the `read` tool and its system-prompt guidance. */
export function apply(ctx: Context): void {
export function applyReadTool(ctx: Context): void {
ctx.systemPrompt.section({
name: 'tool:read',
order: 100,
@@ -119,12 +119,3 @@ export function apply(ctx: Context): void {
},
}))
}
/** Cordis plugin name used by loader diagnostics. */
export const name = 'fs-read'
/** Services required by the `read` tool plugin. */
export const inject = ['tools', 'fs', 'systemPrompt']
/** Named helper for direct registration in the root plugin and tests. */
export const applyReadTool = apply

View File

@@ -8,7 +8,7 @@
* returns `createIfAbsent`/`replaceIfVersion` instead. The tool stats ZERO
* times either way.
*
* @module @deepseek-ai/dsh-tool-fs/write
* @module @deepseek-ai/dsh-tool-fs/src/write
*/
import type { Context } from 'cordis'
@@ -36,7 +36,7 @@ ${verb} file
}
/** Register the `write` tool and its system-prompt guidance. */
export function apply(ctx: Context): void {
export function applyWriteTool(ctx: Context): void {
ctx.systemPrompt.section({
name: 'tool:write',
order: 101,
@@ -62,12 +62,3 @@ export function apply(ctx: Context): void {
},
}))
}
/** Cordis plugin name used by loader diagnostics. */
export const name = 'fs-write'
/** Services required by the `write` tool plugin. */
export const inject = ['tools', 'fs', 'systemPrompt']
/** Named helper for direct registration in the root plugin and tests. */
export const applyWriteTool = apply

View File

@@ -5,10 +5,9 @@
*
* - DEFAULT — with the real `dsh-file-context` policy gate plugin: read-before-
* write/edit, version-guarded mutation, FS_NOT_OBSERVED for unread edits.
* - BARE — WITHOUT the policy plugin, loading only SUBPATH plugins: every
* `fs/*` waterfall falls through to its undefined default, so write/edit are
* unconditional. This proves the subpaths (not just the root) carry no policy
* dependency.
* - BARE — WITHOUT the policy plugin: every `fs/*` waterfall falls through to
* its undefined default, so write/edit are unconditional. This proves the
* tool carries no dependency on the policy plugin.
*
* These verify the WORLD — files are read back from disk and asserted
* byte-for-byte — not the tool's self-report.
@@ -25,9 +24,6 @@ import ToolRegistry from '@deepseek-ai/dsh-tools'
import { LocalFileSystem } from '@deepseek-ai/dsh-fs-local'
import * as FileContext from '@deepseek-ai/dsh-file-context'
import * as ToolFs from '@deepseek-ai/dsh-tool-fs'
import * as readPlugin from '@deepseek-ai/dsh-tool-fs/read'
import * as writePlugin from '@deepseek-ai/dsh-tool-fs/write'
import * as editPlugin from '@deepseek-ai/dsh-tool-fs/edit'
let dir: string
let ctx: Context
@@ -243,18 +239,16 @@ describe('default deployment (with dsh-file-context)', () => {
})
// --------------------------------------------------------------------------
// BARE deployment: SUBPATH plugins only, NO policy gate.
// BARE deployment: the tool suite WITHOUT the policy gate.
// --------------------------------------------------------------------------
describe('bare provider (subpath plugins, no dsh-file-context)', () => {
describe('bare provider (no dsh-file-context)', () => {
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), 'dsh-tool-fs-bare-'))
ctx = new Context()
await ctx.plugin(SystemPrompt)
await ctx.plugin(ToolRegistry)
await ctx.plugin(LocalFileSystem, { cwd: dir })
await ctx.plugin(readPlugin)
await ctx.plugin(writePlugin)
fiber = await ctx.plugin(editPlugin)
fiber = await ctx.plugin(ToolFs)
})
it('read works (it never needed policy)', async () => {

View File

@@ -1,83 +0,0 @@
/**
* Tests for the per-tool subpath plugins (`@deepseek-ai/dsh-tool-fs/read`,
* `/write`, `/edit`): each registers exactly one tool, injects the same services
* (`tools`, `fs`, `systemPrompt`) — NOT a policy service — and cleans up on
* disposal. They boot over the bare `ctx.fs` provider with NO
* `@deepseek-ai/dsh-file-context`, proving each subpath carries no policy-plugin
* dependency.
*/
import { describe, expect, it } from 'vitest'
import { Context } from 'cordis'
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
import ToolRegistry from '@deepseek-ai/dsh-tools'
import { FileSystem, FsTargetKey, FsVersion } from '@deepseek-ai/dsh-fs'
import type {
FsEditOutcome,
FsInfo,
FsTarget,
FsWriteOutcome,
} from '@deepseek-ai/dsh-fs'
import * as readPlugin from '@deepseek-ai/dsh-tool-fs/read'
import * as writePlugin from '@deepseek-ai/dsh-tool-fs/write'
import * as editPlugin from '@deepseek-ai/dsh-tool-fs/edit'
class StubFs extends FileSystem {
override async resolve(path: string): Promise<FsTarget> {
return { inputPath: path, targetKey: FsTargetKey(path), displayPath: path }
}
override async stat(): Promise<FsInfo | undefined> {
return { version: FsVersion('v'), type: 'file', size: 0 }
}
override async readText(): Promise<string> {
return ''
}
override async streamText(): Promise<AsyncIterable<string>> {
return (async function* () { yield '' })()
}
override async writeText(): Promise<FsWriteOutcome> {
return { operation: 'create', version: FsVersion('v') }
}
override async editText(): Promise<FsEditOutcome> {
return { replacements: 1, replaceAll: false, version: FsVersion('v') }
}
}
async function base() {
const ctx = new Context()
await ctx.plugin(SystemPrompt)
await ctx.plugin(ToolRegistry)
await ctx.plugin(StubFs)
return ctx
}
describe('subpath plugins', () => {
it('each registers exactly its one tool (over the bare provider, no policy plugin)', async () => {
const cases: Array<[unknown, string]> = [
[readPlugin, 'read'],
[writePlugin, 'write'],
[editPlugin, 'edit'],
]
for (const [plugin, toolName] of cases) {
const ctx = await base()
await ctx.plugin(plugin as Parameters<Context['plugin']>[0])
expect(ctx.tools.schemas().map(s => s.name)).toEqual([toolName])
}
})
it('cleans up on disposal (HMR safety)', async () => {
const ctx = await base()
const fiber = await ctx.plugin(readPlugin as Parameters<Context['plugin']>[0])
expect(ctx.tools.schemas()).toHaveLength(1)
await fiber.dispose()
expect(ctx.tools.schemas()).toHaveLength(0)
})
it('stays pending without a ctx.fs provider', async () => {
const ctx = new Context()
await ctx.plugin(SystemPrompt)
await ctx.plugin(ToolRegistry)
await ctx.plugin(writePlugin as Parameters<Context['plugin']>[0])
expect(ctx.tools.schemas()).toHaveLength(0)
})
})

View File

@@ -1,21 +0,0 @@
import { defineConfig } from 'tsdown'
/**
* tool-fs exposes one package root plus one entry per tool plugin, so each tool
* can be loaded or replaced independently as a subpath plugin
* (`@deepseek-ai/dsh-tool-fs/read`, `/write`, `/edit`). The root tsdown builds
* only `lib/types/index.js`, so this override adds the per-tool entries. tsdown
* reads the emitted JS under `lib/types` (from `tsc -b`); declarations come from
* `tsc -b` too (dts: false), matching every package.
*/
export default defineConfig({
entry: ['lib/types/index.js', 'lib/types/read.js', 'lib/types/write.js', 'lib/types/edit.js'],
outDir: 'lib',
format: ['esm'],
platform: 'node',
target: 'es2024',
fixedExtension: false,
dts: false,
clean: false,
})