mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`, `verify-translation-pairing --write` for the touched bilingual pairs, `gen-doc-graphs`, and one typert snapshot whose ids embed character offsets. `pnpm run rescope-vendor --check` verifies the result. Renames nine vendored packages (cordis, cosmokit, schemastery and the six @cordisjs plugins) and every reference that resolves them: manifest names and dependency keys, module specifiers including declare-module merges, cordis.yml plugin names, tsconfig paths, every Markdown fence, and `docs/` prose. Directory names, upstream versions, and dependency ranges are unchanged, so vendor/README.md still reads as an upstream snapshot; its manifest table gains an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed at each fork's origin. The tutorial tier follows the rename end to end: its yaml fences named plugins the Loader can no longer resolve, its `ts ignore-check` fences disagreed with the compiled fences beside them, and its prose quoted both. The contracts that told readers to keep upstream names — the root convention and the vendoring cookbook's tree comment and manifest invariant — now say to rescope instead. Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle purity gate now names the vendored libraries a browser bundle inlines, and the files where a bare `cordis` is an agent-preset id keep that product data.
73 lines
3.1 KiB
TypeScript
73 lines
3.1 KiB
TypeScript
/**
|
|
* Model-facing read, write, and edit tools over `ctx.fs`. This package owns schemas, validation,
|
|
* read windows, formatting, and observation events, never a concrete provider. An optional
|
|
* event policy supplies mutation guards; without one the tools use unconditional provider calls.
|
|
* @module @deepseek-ai/dsh-tool-fs
|
|
*/
|
|
|
|
import type { Context } from '@deepseek-ai/cordis'
|
|
import z from '@deepseek-ai/schemastery'
|
|
import type {} from '@deepseek-ai/dsh-user-approval'
|
|
import { applyReadTool, READ_LIMIT, STREAM_MIN_SIZE } from './read.ts'
|
|
import { applyWriteTool } from './write.ts'
|
|
import { applyEditTool } from './edit.ts'
|
|
import { READ_MAX_BYTES, READ_MAX_LINE_LENGTH } from './read-render.ts'
|
|
import { FsSandboxSurface } from './sandbox.ts'
|
|
|
|
/** Cordis plugin name used by loader diagnostics. */
|
|
export const name = 'tool-fs'
|
|
|
|
/** Services required by the filesystem tool suite. */
|
|
export const inject = ['tools', 'fs', 'systemPrompt']
|
|
|
|
/** Plugin config (all optional — `Config` supplies the defaults). */
|
|
export interface Config {
|
|
/** Default and maximum number of lines returned by one `read` call. */
|
|
readLimit?: number
|
|
/** Maximum characters returned for a single line before truncation. */
|
|
readMaxLineLength?: number
|
|
/** Maximum bytes returned for the selected lines of one `read` call. */
|
|
readMaxBytes?: number
|
|
/** Files at or above this size stream instead of loading whole into memory. */
|
|
readStreamMinSize?: number
|
|
}
|
|
|
|
export const Config: z<Config> = z.object({
|
|
readLimit: z.number().default(READ_LIMIT),
|
|
readMaxLineLength: z.number().default(READ_MAX_LINE_LENGTH),
|
|
readMaxBytes: z.number().default(READ_MAX_BYTES),
|
|
readStreamMinSize: z.number().default(STREAM_MIN_SIZE),
|
|
})
|
|
|
|
/** The shape after schemastery applied the defaults. */
|
|
type ResolvedConfig = Required<Config>
|
|
|
|
/** Every read cap counts lines/chars/bytes — a positive integer, or windowing arithmetic misbehaves silently. */
|
|
function assertPositiveInteger(name: string, value: number): void {
|
|
if (!Number.isInteger(value) || value < 1) {
|
|
throw new Error(`tool-fs: ${name} must be a positive integer`)
|
|
}
|
|
}
|
|
|
|
/** Register the full `read`/`write`/`edit` filesystem tool suite. */
|
|
export function apply(ctx: Context, config: Config): void {
|
|
// schemastery (Config) has already filled every defaulted field.
|
|
const resolved = config as ResolvedConfig
|
|
assertPositiveInteger('readLimit', resolved.readLimit)
|
|
assertPositiveInteger('readMaxLineLength', resolved.readMaxLineLength)
|
|
assertPositiveInteger('readMaxBytes', resolved.readMaxBytes)
|
|
assertPositiveInteger('readStreamMinSize', resolved.readStreamMinSize)
|
|
applyReadTool(ctx, {
|
|
limit: resolved.readLimit,
|
|
maxLineLength: resolved.readMaxLineLength,
|
|
maxBytes: resolved.readMaxBytes,
|
|
streamMinSize: resolved.readStreamMinSize,
|
|
})
|
|
// One escalation surface shared by both mutating tools: advertisement gating,
|
|
// per-call policy resolution, and denial-marker mapping, all keyed off whether
|
|
// the mounted ctx.fs confines (ctx.fs.sandboxMode).
|
|
const sandbox = new FsSandboxSurface(ctx)
|
|
applyWriteTool(ctx, sandbox)
|
|
applyEditTool(ctx, sandbox)
|
|
}
|