@x1a0f3n9/dsh-tool-fs 0.1.5-rc.2

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.
@@ -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 @x1a0f3n9/dsh-tool-fs/src/diff
5
+ */
6
+ import type { FileDiff } from '@x1a0f3n9/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 @x1a0f3n9/dsh-tool-fs/src/edit
6
+ */
7
+ import type { Context } from '@deepseek-ai/cordis';
8
+ import type { FsSandboxController } 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 scope-aware 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 API (advertisement, mode stamping, denial mapping).
40
+ */
41
+ export declare function applyEditTool(ctx: Context, sandbox: FsSandboxController): void;
42
+ export {};
43
+ //# sourceMappingURL=edit.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Model-facing diagnostics for guarded-mutation failures. Providers and
3
+ * policies retain operation-specific causes, while this package owns the
4
+ * stable message shown to the model.
5
+ * @module @x1a0f3n9/dsh-tool-fs/src/error
6
+ */
7
+ /**
8
+ * Render the stable model-facing diagnostic for a guarded-mutation failure.
9
+ * `FS_STALE_VERSION` keeps the provider's reason and appends its re-read
10
+ * remedy. `FS_NOT_OBSERVED` replaces operation-specific policy/provider text
11
+ * with one path-aware reason and read remedy. The original error remains the
12
+ * cause, and both diagnostics preserve its code for machine routing. Anything
13
+ * else passes through untouched.
14
+ * @param error - the caught value from a write/edit execution.
15
+ * @param displayPath - the resolved target path shown to the model.
16
+ * @returns a remediated `FsError` for the two guarded-mutation codes, else the original value.
17
+ */
18
+ export declare function remediateFsError(error: unknown, displayPath: string): unknown;
19
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Model-facing read, read_image, 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 @x1a0f3n9/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, plus `read_image` while `attachments` is mounted. */
26
+ export declare function apply(ctx: Context, config: Config): void;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The model-facing `read_image` tool commits a PNG/JPEG/WebP/GIF file. A path
3
+ * without a file extension is identified from its file signature, while the
4
+ * attachment service's full decode stays authoritative. The mounted `ctx.fs`
5
+ * backend owns path resolution and read access; names only declare media type.
6
+ *
7
+ * The route gate is deliberately stricter than the host upload preflight. An
8
+ * image-reading tool is useful only when the exact calling route can inspect
9
+ * its result, so unknown capability refuses instead of relying on an adapter
10
+ * failure after filesystem and attachment work.
11
+ * @module @x1a0f3n9/dsh-tool-fs/src/read-image
12
+ */
13
+ import type { Context } from '@deepseek-ai/cordis';
14
+ import type { ImageAttachmentRef, ImageMediaType } from '@x1a0f3n9/dsh-attachment';
15
+ import type { ToolExecution } from '@x1a0f3n9/dsh-tools';
16
+ /**
17
+ * Identify the media type declared by a supported image file signature.
18
+ * @param data - file bytes read through the current filesystem backend.
19
+ * @returns the detected supported media type, or undefined for other bytes.
20
+ */
21
+ export declare function sniffImageMediaType(data: Uint8Array): ImageMediaType | undefined;
22
+ /** The structured outcome declared by the `read_image` output schema. */
23
+ export interface ImageReadValue {
24
+ path: string;
25
+ image: {
26
+ attachmentId: string;
27
+ mediaType: ImageMediaType;
28
+ bytes: number;
29
+ width: number;
30
+ height: number;
31
+ name?: string;
32
+ /** Orientation-applied file dimensions before normalization; present only when storage reduced it. */
33
+ originalDimensions?: {
34
+ width: number;
35
+ height: number;
36
+ };
37
+ };
38
+ }
39
+ /**
40
+ * Map a model-supplied path to its declared image media type by extension.
41
+ * @param filePath - the raw `file_path` argument (not yet resolved).
42
+ * @returns the declared media type, or undefined when the path does not claim an image.
43
+ */
44
+ export declare function imageMediaTypeForPath(filePath: string): ImageMediaType | undefined;
45
+ /**
46
+ * Enforce the strict image-capability gate for the calling route. Resolves the
47
+ * session's latest routed provider/model (request header config, then agent
48
+ * options) and requires the exact resolved route to declare `image` input explicitly.
49
+ * @param ctx - the plugin context used to resolve the optional `llm` service.
50
+ * @param exec - the tool-execution context supplying the calling agent.
51
+ * @param requestedPath - the raw, not-yet-resolved path rendered in refusal messages.
52
+ */
53
+ export declare function assertImageCapableRoute(ctx: Context, exec: ToolExecution, requestedPath: string): Promise<void>;
54
+ /**
55
+ * Re-brand a structured image outcome into the durable attachment reference an
56
+ * `ImageBlock` carries.
57
+ * @param image - the image metadata from the output schema.
58
+ * @returns the branded attachment reference.
59
+ */
60
+ export declare function imageRefFromValue(image: ImageReadValue['image']): ImageAttachmentRef;
61
+ /**
62
+ * Format an image read as the model-facing envelope beside its image block.
63
+ * A downscaled read names the on-disk dimensions and the multiplier that maps
64
+ * coordinates measured on the attached image back onto the original file.
65
+ * @param displayPath - the backend-resolved path rendered in the envelope's `<path>` element.
66
+ * @param image - the image metadata to summarize.
67
+ * @returns the model-facing envelope; the image itself rides the adjacent image block.
68
+ */
69
+ export declare function formatImageReadOutput(displayPath: string, image: ImageReadValue['image']): string;
70
+ /**
71
+ * Register the `read_image` tool into the given context. The composing plugin
72
+ * owns the attachments gate: `src/index.ts` calls this inside
73
+ * `ctx.inject(['attachments'], …)` so the tool exists only while a durable
74
+ * store is mounted. Execution still re-checks `ctx.get('attachments')` for
75
+ * direct callers and gates on the calling route's declared image input.
76
+ * @param ctx - the registration scope; execution uses its `fs` service plus
77
+ * the optional `attachments`/`llm` services.
78
+ */
79
+ export declare function applyReadImageTool(ctx: Context): void;
80
+ //# sourceMappingURL=read-image.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 @x1a0f3n9/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,19 @@
1
+ /**
2
+ * Shared path resolution and regular-file validation for model-facing read tools.
3
+ * @module @x1a0f3n9/dsh-tool-fs/src/read-target
4
+ */
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ import type { FsInfo, FsTarget } from '@x1a0f3n9/dsh-fs';
7
+ import type { ToolExecution } from '@x1a0f3n9/dsh-tools';
8
+ /**
9
+ * Resolve a model-supplied path, observe absence, and require a regular file.
10
+ * @param ctx - the plugin context providing filesystem resolution and observation events.
11
+ * @param exec - the current tool execution, including session cwd and cancellation.
12
+ * @param requestedPath - the raw path supplied to the tool.
13
+ * @returns the resolved target and its single stat result.
14
+ */
15
+ export declare function resolveRegularReadTarget(ctx: Context, exec: ToolExecution, requestedPath: string): Promise<{
16
+ target: FsTarget;
17
+ info: FsInfo;
18
+ }>;
19
+ //# sourceMappingURL=read-target.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 @x1a0f3n9/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 scope-aware 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 API 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 `@x1a0f3n9/dsh-sandbox` (the same pieces `@x1a0f3n9/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 @x1a0f3n9/dsh-tool-fs/sandbox
11
+ */
12
+ import type { Context } from '@deepseek-ai/cordis';
13
+ import type { ToolExecution } from '@x1a0f3n9/dsh-tools';
14
+ import type { SandboxExecutionPolicy, SandboxMode } from '@x1a0f3n9/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 API: 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 FsSandboxController {
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 — `ToolRuntime`
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,29 @@
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 directory.
5
+ * Non-agent calls return `undefined`, leaving the fallback in the provider rather than reading
6
+ * `process.cwd()` at the tool boundary.
7
+ * @module @x1a0f3n9/dsh-tool-fs/session-cwd
8
+ */
9
+ import type { ToolExecution } from '@x1a0f3n9/dsh-tools';
10
+ /**
11
+ * The session workspace cwd for this call, or `undefined` when none applies.
12
+ * @param exec - the tool-execution context; only its optional `agent` is read.
13
+ * @param requestedPath - the path the provider will resolve; parent traversal
14
+ * makes a symlinked cwd's filesystem identity observable.
15
+ * @returns the calling agent's session cwd, or undefined for a non-agent caller (the backend then applies its own default).
16
+ */
17
+ export declare function sessionCwd(exec: ToolExecution, requestedPath: string): string | undefined;
18
+ /**
19
+ * Resolution options shared by all model-facing filesystem tools.
20
+ * @param exec - the tool-execution context supplying session cwd and cancellation.
21
+ * @param requestedPath - the path the provider will resolve.
22
+ * @param policyWorkspaceRoot - resolved per-call root, when a mutation carries sandbox policy.
23
+ * @returns provider resolution options for the current tool call.
24
+ */
25
+ export declare function sessionResolveOptions(exec: ToolExecution, requestedPath: string, policyWorkspaceRoot?: string): {
26
+ cwd?: string;
27
+ signal?: AbortSignal;
28
+ };
29
+ //# 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 @x1a0f3n9/dsh-tool-fs/src/write
6
+ */
7
+ import type { Context } from '@deepseek-ai/cordis';
8
+ import type { FsWriteOutcome } from '@x1a0f3n9/dsh-fs';
9
+ import type { FsSandboxController } 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 scope-aware 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 API (advertisement, mode stamping, denial mapping).
34
+ */
35
+ export declare function applyWriteTool(ctx: Context, sandbox: FsSandboxController): void;
36
+ //# sourceMappingURL=write.d.ts.map
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@x1a0f3n9/dsh-tool-fs",
3
+ "description": "Model-facing filesystem tools (read, write, edit) over the DeepSeek Harness filesystem seam (ctx.fs)",
4
+ "version": "0.1.5-rc.2",
5
+ "publishConfig": {
6
+ "access": "public"
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
+ "./src/*": "./src/*",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "lib/index.js",
26
+ "lib/types/**/*.d.ts"
27
+ ],
28
+ "license": "MIT",
29
+ "dependencies": {
30
+ "diff": "^9.0.0",
31
+ "@deepseek-ai/schemastery": "^3.18.2"
32
+ },
33
+ "peerDependencies": {
34
+ "@x1a0f3n9/dsh-attachment": "^0.1.5-rc.2",
35
+ "@x1a0f3n9/dsh-system-prompt": "^0.1.5-rc.2",
36
+ "@x1a0f3n9/dsh-llm": "^0.1.5-rc.2",
37
+ "@x1a0f3n9/dsh-sandbox-policy": "^0.1.5-rc.2",
38
+ "@x1a0f3n9/dsh-session": "^0.1.5-rc.2",
39
+ "@x1a0f3n9/dsh-sandbox": "^0.1.5-rc.2",
40
+ "@x1a0f3n9/dsh-user-approval": "^0.1.5-rc.2",
41
+ "@x1a0f3n9/dsh-tools": "^0.1.5-rc.2",
42
+ "@deepseek-ai/cordis": "^4.0.2",
43
+ "@x1a0f3n9/dsh-fs": "^0.1.5-rc.2"
44
+ },
45
+ "devDependencies": {
46
+ "@x1a0f3n9/dsh-agent-loop": "^0.1.5-rc.2",
47
+ "@x1a0f3n9/dsh-agent": "^0.1.5-rc.2",
48
+ "@x1a0f3n9/dsh-attachment": "^0.1.5-rc.2",
49
+ "@x1a0f3n9/dsh-agent-loop-testkit": "^0.1.5-rc.2",
50
+ "@x1a0f3n9/dsh-fs": "^0.1.5-rc.2",
51
+ "@x1a0f3n9/dsh-fs-local": "^0.1.5-rc.2",
52
+ "@x1a0f3n9/dsh-fs-observation-policy": "^0.1.5-rc.2",
53
+ "@x1a0f3n9/dsh-llm": "^0.1.5-rc.2",
54
+ "@x1a0f3n9/dsh-llm-deepseek": "^0.1.5-rc.2",
55
+ "@x1a0f3n9/dsh-sandbox": "^0.1.5-rc.2",
56
+ "@x1a0f3n9/dsh-sandbox-policy": "^0.1.5-rc.2",
57
+ "@x1a0f3n9/dsh-system-prompt": "^0.1.5-rc.2",
58
+ "@x1a0f3n9/dsh-session": "^0.1.5-rc.2",
59
+ "@x1a0f3n9/dsh-user-approval": "^0.1.5-rc.2",
60
+ "@deepseek-ai/cordis": "^4.0.2",
61
+ "@x1a0f3n9/dsh-session-projection": "^0.1.5-rc.2",
62
+ "@x1a0f3n9/dsh-scope": "^0.1.5-rc.2",
63
+ "@x1a0f3n9/dsh-tools": "^0.1.5-rc.2",
64
+ "@x1a0f3n9/dsh-code-runtime": "^0.1.5-rc.2"
65
+ }
66
+ }