@deepseek-ai/dsh-tool-fs 0.0.1-rc.1
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.
- package/LICENSE +28 -0
- package/README.i18n.yaml +6 -0
- package/README.md +153 -0
- package/README.zh.md +153 -0
- package/lib/index.js +979 -0
- package/lib/invariant.js +23 -0
- package/lib/types/diff.d.ts +38 -0
- package/lib/types/edit.d.ts +43 -0
- package/lib/types/error.d.ts +20 -0
- package/lib/types/index.d.ts +27 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/read-render.d.ts +108 -0
- package/lib/types/read.d.ts +49 -0
- package/lib/types/sandbox.d.ts +81 -0
- package/lib/types/session-cwd.d.ts +30 -0
- package/lib/types/write.d.ts +36 -0
- package/package.json +68 -0
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/**
|
|
3
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-tool-fs`.
|
|
4
|
+
* @module @deepseek-ai/dsh-tool-fs/invariant
|
|
5
|
+
*/
|
|
6
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-tool-fs";
|
|
7
|
+
/** Cordis companion plugin name. */
|
|
8
|
+
const name = "tool-fs-invariant";
|
|
9
|
+
/** Service required before the companion can reserve package ownership. */
|
|
10
|
+
const inject = ["invariants"];
|
|
11
|
+
/**
|
|
12
|
+
* No runtime invariant: this model-facing adapter has no independent lifecycle stream; execution
|
|
13
|
+
* relations are owned by the capability seam it calls.
|
|
14
|
+
*/
|
|
15
|
+
const install = () => {};
|
|
16
|
+
/**
|
|
17
|
+
* Register this package's invariant companion.
|
|
18
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
19
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
20
|
+
*/
|
|
21
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result-time contextual diff presentation for write and edit. Storage returns before/after
|
|
3
|
+
* text; this model-facing layer derives one three-line-context card per applied hunk.
|
|
4
|
+
* @module @deepseek-ai/dsh-tool-fs/src/diff
|
|
5
|
+
*/
|
|
6
|
+
import type { FileDiff } from '@deepseek-ai/dsh-tools';
|
|
7
|
+
/** Context lines shown on each side of an applied hunk. */
|
|
8
|
+
export declare const DIFF_CONTEXT = 3;
|
|
9
|
+
/**
|
|
10
|
+
* The `write`/`edit` tools' private `tool/result` `meta` payload: the applied
|
|
11
|
+
* contextual-diff hunks. Attached opaquely (as `unknown`) on the tool result and
|
|
12
|
+
* persisted with the session log — it must be JSON-serializable (the session
|
|
13
|
+
* validates this at `append`), so `presentResult` reproduces the diff card on
|
|
14
|
+
* replay. The producing tool owns and narrows this opaque shape.
|
|
15
|
+
*/
|
|
16
|
+
export type FsDiffMeta = {
|
|
17
|
+
diffs: FileDiff[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Compute one {@link FileDiff} per hunk between `before` and `after`, each carrying the
|
|
21
|
+
* applied change plus {@link DIFF_CONTEXT} context lines. Pure insertions use `oldText: null`,
|
|
22
|
+
* patch-only no-newline markers are omitted, and scattered replacements remain separate hunks.
|
|
23
|
+
*
|
|
24
|
+
* @param path - the path stamped on every produced diff (the model-facing `file_path`; the
|
|
25
|
+
* bridge relativizes it).
|
|
26
|
+
* @param before - the file text before the change (the backend's LF-normalized diff basis).
|
|
27
|
+
* @param after - the file text after the change, on the same basis.
|
|
28
|
+
* @returns one diff per applied hunk, in file order; empty when the texts are identical.
|
|
29
|
+
*/
|
|
30
|
+
export declare function computeHunkDiffs(path: string, before: string, after: string): FileDiff[];
|
|
31
|
+
/**
|
|
32
|
+
* Narrow opaque live or replayed result metadata to non-empty file diffs. Malformed metadata
|
|
33
|
+
* returns `undefined` so presentation can fall back instead of throwing during replay.
|
|
34
|
+
* @param meta - result metadata.
|
|
35
|
+
* @returns validated hunks, or `undefined` for absent or malformed data.
|
|
36
|
+
*/
|
|
37
|
+
export declare function diffsFromMeta(meta: unknown): FileDiff[] | undefined;
|
|
38
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing literal edit, unique-match by default. It obtains an optional guard from the
|
|
3
|
+
* single intent slot, calls `ctx.fs.editText` without a separate stat, then records the observed
|
|
4
|
+
* version; no policy means an unconditional atomic edit.
|
|
5
|
+
* @module @deepseek-ai/dsh-tool-fs/src/edit
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import type { FsSandboxSurface } from './sandbox.ts';
|
|
9
|
+
/** Validated `edit` arguments after defaulting. */
|
|
10
|
+
interface EditInput {
|
|
11
|
+
filePath: string;
|
|
12
|
+
oldString: string;
|
|
13
|
+
newString: string;
|
|
14
|
+
replaceAll: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validate value constraints the schema DSL can't express: a non-blank
|
|
18
|
+
* `file_path`, a non-empty `old_string`, and `old_string !== new_string`
|
|
19
|
+
* (an equal pair would be a guaranteed no-op edit).
|
|
20
|
+
* @param args - the schema-validated raw tool arguments.
|
|
21
|
+
* @returns the camelCased input with `replace_all` defaulted to false.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseEditArgs(args: {
|
|
24
|
+
file_path: string;
|
|
25
|
+
old_string: string;
|
|
26
|
+
new_string: string;
|
|
27
|
+
replace_all?: boolean;
|
|
28
|
+
}): EditInput;
|
|
29
|
+
/**
|
|
30
|
+
* Format an edit success (single-match or replace-all) as a Claude-style model-facing message.
|
|
31
|
+
* @param displayPath - the backend-resolved path shown to the model.
|
|
32
|
+
* @param replaceAll - selects the all-occurrences wording over the single-replacement one.
|
|
33
|
+
* @returns the confirmation sentence the model sees as the tool result.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatEditOutput(displayPath: string, replaceAll: boolean): string;
|
|
36
|
+
/**
|
|
37
|
+
* Register the `edit` tool and its system-prompt guidance.
|
|
38
|
+
* @param ctx - the plugin context; registrations are effects scoped to it, and execution uses its `fs` service.
|
|
39
|
+
* @param sandbox - the shared sandbox-escalation surface (advertisement, mode stamping, denial mapping).
|
|
40
|
+
*/
|
|
41
|
+
export declare function applyEditTool(ctx: Context, sandbox: FsSandboxSurface): void;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing remediation for guarded-mutation failures. The provider's
|
|
3
|
+
* `FS_STALE_VERSION` and `FS_NOT_OBSERVED` messages state the condition but
|
|
4
|
+
* not the only correct recovery (re-read / read the file), so this package
|
|
5
|
+
* appends the remedy at the model boundary; provider messages stay
|
|
6
|
+
* machine-oriented and unchanged.
|
|
7
|
+
* @module @deepseek-ai/dsh-tool-fs/src/error
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Append the correct recovery instruction to a guarded-mutation failure's
|
|
11
|
+
* message. `FS_STALE_VERSION` (the file changed since this session's last
|
|
12
|
+
* observation, including a missing target) recovers only by re-reading;
|
|
13
|
+
* `FS_NOT_OBSERVED` (no prior read by this session) by reading. The `FsError`
|
|
14
|
+
* code is preserved so retry/permission/UI layers keep routing on it, and the
|
|
15
|
+
* original error chains as `cause`. Anything else passes through untouched.
|
|
16
|
+
* @param error - the caught value from a write/edit execution.
|
|
17
|
+
* @returns a remediated `FsError` for the two guarded-mutation codes, else the original value.
|
|
18
|
+
*/
|
|
19
|
+
export declare function remediateFsError(error: unknown): unknown;
|
|
20
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing read, write, and edit tools over `ctx.fs`. This package owns schemas, validation,
|
|
3
|
+
* read windows, formatting, and observation events, never a concrete provider. An optional
|
|
4
|
+
* event policy supplies mutation guards; without one the tools use unconditional provider calls.
|
|
5
|
+
* @module @deepseek-ai/dsh-tool-fs
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import z from '@deepseek-ai/schemastery';
|
|
9
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
10
|
+
export declare const name = "tool-fs";
|
|
11
|
+
/** Services required by the filesystem tool suite. */
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
/** Plugin config (all optional — `Config` supplies the defaults). */
|
|
14
|
+
export interface Config {
|
|
15
|
+
/** Default and maximum number of lines returned by one `read` call. */
|
|
16
|
+
readLimit?: number;
|
|
17
|
+
/** Maximum characters returned for a single line before truncation. */
|
|
18
|
+
readMaxLineLength?: number;
|
|
19
|
+
/** Maximum bytes returned for the selected lines of one `read` call. */
|
|
20
|
+
readMaxBytes?: number;
|
|
21
|
+
/** Files at or above this size stream instead of loading whole into memory. */
|
|
22
|
+
readStreamMinSize?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare const Config: z<Config>;
|
|
25
|
+
/** Register the full `read`/`write`/`edit` filesystem tool suite. */
|
|
26
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-tool-fs`.
|
|
3
|
+
* @module @deepseek-ai/dsh-tool-fs/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "tool-fs-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure read presentation: turn provider-decoded text into a bounded, line-numbered window and
|
|
3
|
+
* model-facing envelope. Chunk scanning caps the current line, so even one newline-free giant
|
|
4
|
+
* line cannot grow memory without bound.
|
|
5
|
+
* @module @deepseek-ai/dsh-tool-fs/read-render
|
|
6
|
+
*/
|
|
7
|
+
/** Default maximum characters returned for a single line (the `readMaxLineLength` config). */
|
|
8
|
+
export declare const READ_MAX_LINE_LENGTH = 2000;
|
|
9
|
+
/** Default maximum bytes returned for selected file lines (the `readMaxBytes` config). */
|
|
10
|
+
export declare const READ_MAX_BYTES: number;
|
|
11
|
+
/** Resolved read window. The consumer applies its defaults/caps before calling. */
|
|
12
|
+
export interface ReadWindow {
|
|
13
|
+
/** 1-based first line to return. */
|
|
14
|
+
offset: number;
|
|
15
|
+
/** Maximum number of lines to return. */
|
|
16
|
+
limit: number;
|
|
17
|
+
/** Maximum characters returned for a single line; overflow is truncated with a suffix. */
|
|
18
|
+
maxLineLength: number;
|
|
19
|
+
/** Maximum bytes of selected output; overflow stops the scan and marks `truncatedByBytes`. */
|
|
20
|
+
maxBytes: number;
|
|
21
|
+
}
|
|
22
|
+
/** One line returned from a text file. */
|
|
23
|
+
export interface FileTextLine {
|
|
24
|
+
/** 1-based line number in the file. */
|
|
25
|
+
number: number;
|
|
26
|
+
/** Line text without its trailing newline. */
|
|
27
|
+
text: string;
|
|
28
|
+
}
|
|
29
|
+
/** The windowed result {@link buildWindow} produces from a file's decoded text. */
|
|
30
|
+
export interface WindowResult {
|
|
31
|
+
/** Returned lines, already numbered. */
|
|
32
|
+
lines: FileTextLine[];
|
|
33
|
+
/** Exact total line count in the file. */
|
|
34
|
+
totalLines: number;
|
|
35
|
+
/** Whether selected output hit the byte cap. */
|
|
36
|
+
truncatedByBytes: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Outcome of a bounded text read — what {@link formatReadOutput} renders. */
|
|
39
|
+
export interface FileReadOutcome {
|
|
40
|
+
/** 1-based first line requested. */
|
|
41
|
+
offset: number;
|
|
42
|
+
/** Returned lines, already numbered. */
|
|
43
|
+
lines: FileTextLine[];
|
|
44
|
+
/** Exact total line count in the file. */
|
|
45
|
+
totalLines: number;
|
|
46
|
+
/** Whether selected output hit the byte cap. */
|
|
47
|
+
truncatedByBytes?: true;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build one window from streamed or whole-file chunks, enforcing line and byte caps while still
|
|
51
|
+
* scanning to an exact total line count, and throwing `FS_NOT_FOUND` when the requested offset is
|
|
52
|
+
* past EOF.
|
|
53
|
+
* @param chunks - decoded text chunks in file order; chunk boundaries carry no meaning.
|
|
54
|
+
* @param request - the resolved window; the caller has already applied its defaults and caps.
|
|
55
|
+
* @param displayPath - the caller-facing path used in the offset-out-of-range error.
|
|
56
|
+
* @returns the numbered window lines, the total line count seen, and the byte-cap truncation flag.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildWindow(chunks: AsyncIterable<string> | Iterable<string>, request: ReadWindow, displayPath: string): Promise<WindowResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Format a read outcome as one OpenCode-style line-numbered text block body.
|
|
61
|
+
* @param displayPath - the backend-resolved path rendered in the envelope's `<path>` element.
|
|
62
|
+
* @param outcome - the windowed read to render.
|
|
63
|
+
* @returns the model-facing envelope: numbered lines plus a continuation or end-of-file footer.
|
|
64
|
+
*/
|
|
65
|
+
export declare function formatReadOutput(displayPath: string, outcome: FileReadOutcome): string;
|
|
66
|
+
/**
|
|
67
|
+
* Derive a syntax-highlighting language hint from a read path's file extension.
|
|
68
|
+
* Pure and case-insensitive on the extension; a dotfile with no extension
|
|
69
|
+
* (`.gitignore`) and an unknown extension both yield `undefined`.
|
|
70
|
+
* @param path - the model-facing path the read reported.
|
|
71
|
+
* @returns the language hint for {@link LANG_BY_EXTENSION}, or `undefined` when the extension maps to none.
|
|
72
|
+
*/
|
|
73
|
+
export declare function langFromPath(path: string): string | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* The `read` tool's private `tool/result` `meta` payload: the structured
|
|
76
|
+
* line-numbered window a capable UI renders as a code view. Attached opaquely (as
|
|
77
|
+
* `unknown`) on the tool result and persisted with the session log — it must be
|
|
78
|
+
* JSON-serializable (the session validates this at `append`), so `presentResult`
|
|
79
|
+
* reproduces the read card on replay when the raw structured output is no longer
|
|
80
|
+
* on the wire. The producing tool owns and narrows this opaque shape.
|
|
81
|
+
*/
|
|
82
|
+
export interface FsReadMeta {
|
|
83
|
+
/** The read file's model-facing path. */
|
|
84
|
+
path: string;
|
|
85
|
+
/** The 1-based first line the window requested, kept even when `lines` is empty. */
|
|
86
|
+
offset: number;
|
|
87
|
+
/** The returned window's lines, each keeping its file line number. */
|
|
88
|
+
lines: FileTextLine[];
|
|
89
|
+
/** Exact total line count in the file. */
|
|
90
|
+
totalLines: number;
|
|
91
|
+
/** Syntax-highlighting language hint from the extension, or omitted for plain text. */
|
|
92
|
+
lang?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Narrow opaque live or replayed result metadata to a structured read window.
|
|
96
|
+
* Malformed metadata returns `undefined` so presentation can fall back to the
|
|
97
|
+
* generic text card instead of throwing during replay. Beyond shape, the
|
|
98
|
+
* semantic contract of a read window is enforced against replayed JSON that is
|
|
99
|
+
* well-typed but out of range: `offset` must be a 1-based integer, `totalLines`
|
|
100
|
+
* must be a non-negative integer, each line number must be a 1-based integer no
|
|
101
|
+
* less than `offset`, the line numbers must strictly increase, and no line number
|
|
102
|
+
* may exceed `totalLines`. Any violation declines to the generic fallback rather
|
|
103
|
+
* than emitting a card that misnumbers or overcounts.
|
|
104
|
+
* @param meta - result metadata.
|
|
105
|
+
* @returns the validated read window, or `undefined` for absent, malformed, or semantically invalid data.
|
|
106
|
+
*/
|
|
107
|
+
export declare function readMetaFromMeta(meta: unknown): FsReadMeta | undefined;
|
|
108
|
+
//# sourceMappingURL=read-render.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing UTF-8 read. It performs one provider stat for type, routing, and observed version,
|
|
3
|
+
* streams large or size-unknown files, renders a bounded window, then emits the observation.
|
|
4
|
+
* @module @deepseek-ai/dsh-tool-fs/src/read
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
/** Default and maximum number of lines returned by one `read` call (the `readLimit` config). */
|
|
8
|
+
export declare const READ_LIMIT = 2000;
|
|
9
|
+
/**
|
|
10
|
+
* Default streaming threshold (the `readStreamMinSize` config): files at or
|
|
11
|
+
* above this size stream; smaller files read whole into memory.
|
|
12
|
+
*/
|
|
13
|
+
export declare const STREAM_MIN_SIZE: number;
|
|
14
|
+
/** Resolved read-tool caps — plugin config after defaulting (see `Config` in index.ts). */
|
|
15
|
+
export interface ReadToolCaps {
|
|
16
|
+
/** Default and maximum number of lines returned by one call. */
|
|
17
|
+
limit: number;
|
|
18
|
+
/** Maximum characters returned for a single line. */
|
|
19
|
+
maxLineLength: number;
|
|
20
|
+
/** Maximum bytes returned for selected file lines. */
|
|
21
|
+
maxBytes: number;
|
|
22
|
+
/** Files at or above this size stream; smaller files read whole into memory. */
|
|
23
|
+
streamMinSize: number;
|
|
24
|
+
}
|
|
25
|
+
/** Validated `read` arguments after defaulting. */
|
|
26
|
+
interface ReadInput {
|
|
27
|
+
filePath: string;
|
|
28
|
+
offset: number;
|
|
29
|
+
limit: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validate value constraints the schema DSL can't express. `maxLimit` is the deployment's line cap.
|
|
33
|
+
* @param args - the schema-validated raw tool arguments; `offset`/`limit` must be positive integers when given.
|
|
34
|
+
* @param maxLimit - the configured line cap: both the default `limit` and the largest one accepted.
|
|
35
|
+
* @returns the validated input with `offset` defaulted to 1 and `limit` to `maxLimit`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseReadArgs(args: {
|
|
38
|
+
file_path: string;
|
|
39
|
+
offset?: number;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}, maxLimit: number): ReadInput;
|
|
42
|
+
/**
|
|
43
|
+
* Register the `read` tool and its system-prompt guidance.
|
|
44
|
+
* @param ctx - the plugin context; registrations are effects scoped to it, and execution uses its `fs` service.
|
|
45
|
+
* @param caps - the deployment's resolved read caps (plugin config after defaulting).
|
|
46
|
+
*/
|
|
47
|
+
export declare function applyReadTool(ctx: Context, caps: ReadToolCaps): void;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox-escalation surface shared by the `write` and `edit` tools: the
|
|
3
|
+
* per-call policy resolution, the advertised escalation fields, and the denial-marker
|
|
4
|
+
* mapping — all delegating the vocabulary and the fail-closed approval
|
|
5
|
+
* sequence to `@deepseek-ai/dsh-sandbox` (the same pieces `@deepseek-ai/dsh-tool-bash`
|
|
6
|
+
* uses), so bash and fs escalate identically. Built ONCE per plugin from
|
|
7
|
+
* `ctx.fs.sandboxMode` (the capability fact — is a confining backend mounted?)
|
|
8
|
+
* and shared by both mutating tools.
|
|
9
|
+
*
|
|
10
|
+
* @module @deepseek-ai/dsh-tool-fs/sandbox
|
|
11
|
+
*/
|
|
12
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
13
|
+
import type { ToolExecution } from '@deepseek-ai/dsh-tools';
|
|
14
|
+
import type { SandboxExecutionPolicy, SandboxMode } from '@deepseek-ai/dsh-sandbox';
|
|
15
|
+
/** The two escalation arguments a mutating tool may carry (advertised only under a confining backend). */
|
|
16
|
+
export interface FsEscalationArgs {
|
|
17
|
+
sandbox_permissions?: string;
|
|
18
|
+
justification?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The schema fields for the escalation arguments, spread into a tool's `parameters` when a confining backend is mounted. */
|
|
21
|
+
export interface EscalationSchemaFields {
|
|
22
|
+
sandbox_permissions: {
|
|
23
|
+
type: 'string';
|
|
24
|
+
enum: string[];
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
justification: {
|
|
28
|
+
type: 'string';
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The filesystem escalation surface: advertisement gating, per-call policy
|
|
34
|
+
* resolution, the one-approved wider retry, and denial-marker mapping. A pure
|
|
35
|
+
* product of `ctx` at plugin apply time.
|
|
36
|
+
*/
|
|
37
|
+
export declare class FsSandboxSurface {
|
|
38
|
+
private readonly ctx;
|
|
39
|
+
/** The escalation targets this composition advertises (`[]` when no confining backend is mounted). */
|
|
40
|
+
readonly escalationModes: readonly SandboxMode[];
|
|
41
|
+
/** Shared per-session policy resolver, required by a confining backend. */
|
|
42
|
+
private readonly policy;
|
|
43
|
+
constructor(ctx: Context);
|
|
44
|
+
/**
|
|
45
|
+
* The escalation schema fields for a mutating tool's `parameters`. Call it
|
|
46
|
+
* only under a confining backend (guard on {@link escalationModes}); the
|
|
47
|
+
* enum pins the closed target vocabulary, the strict-wider check happens per
|
|
48
|
+
* call at execution.
|
|
49
|
+
* @returns the two escalation parameter specs.
|
|
50
|
+
*/
|
|
51
|
+
schemaFields(): EscalationSchemaFields;
|
|
52
|
+
/**
|
|
53
|
+
* The policy to stamp onto this mutation: an approved escalation grant (a
|
|
54
|
+
* strictly wider retry resolved through `ctx.approval` before anything
|
|
55
|
+
* executes), else the session's standing mode. The calling session's cwd is
|
|
56
|
+
* always carried as the workspace root. Validates the escalation argument
|
|
57
|
+
* pairing first.
|
|
58
|
+
* @param toolName - the mutating tool's name, for the approval audit trail.
|
|
59
|
+
* @param args - the call's escalation arguments.
|
|
60
|
+
* @param exec - the tool-execution context (agent, callId, signal).
|
|
61
|
+
* @returns the policy to pass to the mutation, or undefined for an
|
|
62
|
+
* unsandboxed backend.
|
|
63
|
+
*/
|
|
64
|
+
resolvePolicy(toolName: string, args: FsEscalationArgs, exec: ToolExecution): Promise<SandboxExecutionPolicy | undefined>;
|
|
65
|
+
/**
|
|
66
|
+
* Map a thrown provider error for the model: a `FS_SANDBOX_DENIED` becomes a
|
|
67
|
+
* `FsError` whose text is the shared `[sandbox: …]` denial marker plus the
|
|
68
|
+
* same-turn escalation hint, so a policy denial reads identically to bash's
|
|
69
|
+
* WHILE keeping the structured `FS_SANDBOX_DENIED` code — `ToolRegistry`
|
|
70
|
+
* populates `result.error` only for `HarnessError` instances, so a plain
|
|
71
|
+
* `Error` would strip the code retry/observers key off. Any other error
|
|
72
|
+
* passes through unchanged. A `FS_SANDBOX_DENIED` only arises under a
|
|
73
|
+
* confining backend, which always advertises the escalation fields, so the
|
|
74
|
+
* hint always applies here.
|
|
75
|
+
* @param error - the error thrown by the mutation.
|
|
76
|
+
* @param policy - the policy stamped onto the call (names the mode in the marker).
|
|
77
|
+
* @returns the error to throw — the marker `FsError` for a sandbox denial, else the original.
|
|
78
|
+
*/
|
|
79
|
+
mapError(error: unknown, policy: SandboxExecutionPolicy | undefined): unknown;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the working directory a filesystem tool resolves relative paths against: the calling
|
|
3
|
+
* agent's per-session workspace (`exec.agent.session.header.cwd`), so each session's
|
|
4
|
+
* `read`/`write`/`edit` act on ITS workspace, not the server's launch dir — mirroring how
|
|
5
|
+
* `dsh-tool-bash` defaults a bash `workdir` to the session cwd.
|
|
6
|
+
* Non-agent calls return `undefined`, leaving the fallback in the provider rather than reading
|
|
7
|
+
* `process.cwd()` at the tool boundary.
|
|
8
|
+
* @module @deepseek-ai/dsh-tool-fs/session-cwd
|
|
9
|
+
*/
|
|
10
|
+
import type { ToolExecution } from '@deepseek-ai/dsh-tools';
|
|
11
|
+
/**
|
|
12
|
+
* The session workspace cwd for this call, or `undefined` when none applies.
|
|
13
|
+
* @param exec - the tool-execution context; only its optional `agent` is read.
|
|
14
|
+
* @param requestedPath - the path the provider will resolve; parent traversal
|
|
15
|
+
* makes a symlinked cwd's filesystem identity observable.
|
|
16
|
+
* @returns the calling agent's session cwd, or undefined for a non-agent caller (the backend then applies its own default).
|
|
17
|
+
*/
|
|
18
|
+
export declare function sessionCwd(exec: ToolExecution, requestedPath: string): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Resolution options shared by all model-facing filesystem tools.
|
|
21
|
+
* @param exec - the tool-execution context supplying session cwd and cancellation.
|
|
22
|
+
* @param requestedPath - the path the provider will resolve.
|
|
23
|
+
* @param policyWorkspaceRoot - resolved per-call root, when a mutation carries sandbox policy.
|
|
24
|
+
* @returns provider resolution options for the current tool call.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sessionResolveOptions(exec: ToolExecution, requestedPath: string, policyWorkspaceRoot?: string): {
|
|
27
|
+
cwd?: string;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=session-cwd.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing full-file write. It obtains an optional intent from the single policy slot, calls
|
|
3
|
+
* `ctx.fs.writeText` without a stat, then records the resulting version; no policy means an
|
|
4
|
+
* unconditional atomic create-or-overwrite.
|
|
5
|
+
* @module @deepseek-ai/dsh-tool-fs/src/write
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import type { FsWriteOutcome } from '@deepseek-ai/dsh-fs';
|
|
9
|
+
import type { FsSandboxSurface } from './sandbox.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Validate value constraints the schema DSL can't express: only a non-blank
|
|
12
|
+
* `file_path` — an empty `content` is legitimate (it writes an empty file).
|
|
13
|
+
* @param args - the schema-validated raw tool arguments.
|
|
14
|
+
* @returns the camelCased input; `content` passes through untouched.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseWriteArgs(args: {
|
|
17
|
+
file_path: string;
|
|
18
|
+
content: string;
|
|
19
|
+
}): {
|
|
20
|
+
filePath: string;
|
|
21
|
+
content: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Format a write outcome as one model-facing text block body.
|
|
25
|
+
* @param displayPath - the backend-resolved path rendered in the envelope's `<path>` element.
|
|
26
|
+
* @param outcome - the write outcome; its `operation` selects the Created/Updated wording.
|
|
27
|
+
* @returns the model-facing confirmation envelope (no file content is echoed back).
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatWriteOutput(displayPath: string, outcome: Pick<FsWriteOutcome, 'operation'>): string;
|
|
30
|
+
/**
|
|
31
|
+
* Register the `write` tool and its system-prompt guidance.
|
|
32
|
+
* @param ctx - the plugin context; registrations are effects scoped to it, and execution uses its `fs` service.
|
|
33
|
+
* @param sandbox - the shared sandbox-escalation surface (advertisement, mode stamping, denial mapping).
|
|
34
|
+
*/
|
|
35
|
+
export declare function applyWriteTool(ctx: Context, sandbox: FsSandboxSurface): void;
|
|
36
|
+
//# sourceMappingURL=write.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/dsh-tool-fs",
|
|
3
|
+
"description": "Model-facing filesystem tools (read, write, edit) over the DeepSeek Harness filesystem seam (ctx.fs)",
|
|
4
|
+
"version": "0.0.1-rc.1",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "restricted"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/fs/tool-fs"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./invariant": {
|
|
22
|
+
"types": "./lib/types/invariant.d.ts",
|
|
23
|
+
"default": "./lib/invariant.js"
|
|
24
|
+
},
|
|
25
|
+
"./src/*": "./src/*",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"lib/index.js",
|
|
30
|
+
"lib/invariant.js",
|
|
31
|
+
"lib/types/**/*.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"license": "BSD-3-Clause",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"diff": "^9.0.0",
|
|
36
|
+
"@deepseek-ai/schemastery": "^3.18.1-rc.1"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1",
|
|
40
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.1",
|
|
41
|
+
"@deepseek-ai/dsh-sandbox": "^0.0.1-rc.1",
|
|
42
|
+
"@deepseek-ai/dsh-fs": "^0.0.1-rc.1",
|
|
43
|
+
"@deepseek-ai/dsh-sandbox-policy": "^0.0.1-rc.1",
|
|
44
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
45
|
+
"@deepseek-ai/dsh-tools": "^0.0.1-rc.1",
|
|
46
|
+
"@deepseek-ai/dsh-user-approval": "^0.0.1-rc.1",
|
|
47
|
+
"@deepseek-ai/dsh-system-prompt": "^0.0.1-rc.1",
|
|
48
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@deepseek-ai/dsh-agent": "^0.0.1-rc.1",
|
|
52
|
+
"@deepseek-ai/dsh-agent-loop": "^0.0.1-rc.1",
|
|
53
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "^0.0.1-rc.1",
|
|
54
|
+
"@deepseek-ai/dsh-fs": "^0.0.1-rc.1",
|
|
55
|
+
"@deepseek-ai/dsh-fs-local": "^0.0.1-rc.1",
|
|
56
|
+
"@deepseek-ai/dsh-fs-policy": "^0.0.1-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1",
|
|
58
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-llm-deepseek": "^0.0.1-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-sandbox": "^0.0.1-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-sandbox-policy": "^0.0.1-rc.1",
|
|
62
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
63
|
+
"@deepseek-ai/dsh-system-prompt": "^0.0.1-rc.1",
|
|
64
|
+
"@deepseek-ai/dsh-tools": "^0.0.1-rc.1",
|
|
65
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1",
|
|
66
|
+
"@deepseek-ai/dsh-user-approval": "^0.0.1-rc.1"
|
|
67
|
+
}
|
|
68
|
+
}
|