@swoop111/dsh-tool-fs 0.0.0-stage → 0.2.0-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,58 @@
1
+ /**
2
+ * Window completion for reads: the neighbouring lines that give a delivered
3
+ * window its structural boundaries. The head is the single line that opened
4
+ * the construct the window starts inside; the tail is the run of following
5
+ * lines that closes the construct the window ends inside. Neither ever
6
+ * modifies, reorders, or drops a delivered line — a window either gains
7
+ * context or stays exactly as the caller asked for it.
8
+ *
9
+ * The head is one line because everything between that opening line and the
10
+ * window is the content the caller chose to skip; the tail is a run because
11
+ * the construct cannot be called closed until its closer arrives.
12
+ * @module @deepseek-ai/dsh-tool-fs/completion
13
+ */
14
+ import type { FileTextLine } from './read-render.ts';
15
+ import type { CompletionRule } from './structure.ts';
16
+ /** Fetches up to `count` lines of the file on one side of the window, in file order. */
17
+ export type LineSupplier = (count: number) => Promise<FileTextLine[] | undefined>;
18
+ /** Where a completion fetches the lines on each side of the window. */
19
+ export interface CompletionLineSuppliers {
20
+ /**
21
+ * The lines immediately before the window, in file order; the last entry is
22
+ * the window's predecessor line. `undefined` signals that no such line exists.
23
+ */
24
+ preceding: LineSupplier;
25
+ /**
26
+ * The lines immediately after the window, in file order; the first entry is
27
+ * the window's successor line. `undefined` signals end of file.
28
+ */
29
+ following: LineSupplier;
30
+ }
31
+ /** Configuration for window completion; the only field is a hard cap. */
32
+ export interface CompletionTuning {
33
+ /**
34
+ * Maximum lines appended to close the tail, and how far back the head search
35
+ * may reach for the line that opened the construct.
36
+ */
37
+ maxLines: number;
38
+ }
39
+ /** The neighbouring lines a window gained, and the rules that found them. */
40
+ export interface CompletionResult {
41
+ /** The line that opened the construct the window starts inside; empty when the window starts at a boundary. */
42
+ head: FileTextLine[];
43
+ /** The lines that close the construct the window ends inside; empty when the tail is balanced. */
44
+ tail: FileTextLine[];
45
+ /** The rule that produced `head`; absent when nothing was prepended. */
46
+ headRule?: CompletionRule;
47
+ /** The rule that produced `tail`; absent when nothing was appended. */
48
+ tailRule?: CompletionRule;
49
+ }
50
+ /**
51
+ * Complete a window's structural boundaries.
52
+ * @param lines - the delivered window lines, in file order.
53
+ * @param supply - the line sources on each side of the window.
54
+ * @param tuning - the hard caps for the added lines.
55
+ * @returns the head and tail lines with the rules that produced them; `undefined` when neither side completes.
56
+ */
57
+ export declare function completeWindow(lines: readonly FileTextLine[], supply: CompletionLineSuppliers, tuning: CompletionTuning): Promise<CompletionResult | undefined>;
58
+ //# sourceMappingURL=completion.d.ts.map
@@ -0,0 +1,41 @@
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, and for `write` whether the call created or updated
12
+ * the file, which tells an empty hunk list of a create from one of an
13
+ * unchanged overwrite. Attached opaquely (as `unknown`) on the tool result and
14
+ * persisted with the session log — it must be JSON-serializable (the session
15
+ * validates this at `append`), so `presentResult` reproduces the diff card on
16
+ * replay. The producing tool owns and narrows this opaque shape.
17
+ */
18
+ export type FsDiffMeta = {
19
+ diffs: FileDiff[];
20
+ operation?: 'create' | 'update';
21
+ };
22
+ /**
23
+ * Compute one {@link FileDiff} per hunk between `before` and `after`, each carrying the
24
+ * applied change plus {@link DIFF_CONTEXT} context lines. Pure insertions use `oldText: null`,
25
+ * patch-only no-newline markers are omitted, and scattered replacements remain separate hunks.
26
+ *
27
+ * @param path - the path stamped on every produced diff (the model-facing `file_path`; the
28
+ * bridge relativizes it).
29
+ * @param before - the file text before the change (the backend's LF-normalized diff basis).
30
+ * @param after - the file text after the change, on the same basis.
31
+ * @returns one diff per applied hunk, in file order; empty when the texts are identical.
32
+ */
33
+ export declare function computeHunkDiffs(path: string, before: string, after: string): FileDiff[];
34
+ /**
35
+ * Narrow opaque live or replayed result metadata to non-empty file diffs. Malformed metadata
36
+ * returns `undefined` so presentation can fall back instead of throwing during replay.
37
+ * @param meta - result metadata.
38
+ * @returns validated hunks, or `undefined` for absent or malformed data.
39
+ */
40
+ export declare function diffsFromMeta(meta: unknown): FileDiff[] | undefined;
41
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1,73 @@
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. When the literal match fails or is
5
+ * ambiguous, the `@deepseek-ai/dsh-fs-edit-repair` engine re-anchors the pair before the error
6
+ * reaches the model.
7
+ * @module @deepseek-ai/dsh-tool-fs/src/edit
8
+ */
9
+ import type { Context } from '@deepseek-ai/cordis';
10
+ import type { Session } from '@deepseek-ai/dsh-session';
11
+ import type { FsSandboxController } from './sandbox.ts';
12
+ /** Repair tuning for failed `edit` matches; rules live in `@deepseek-ai/dsh-fs-edit-repair`. */
13
+ export interface EditRepairConfig {
14
+ /** Disable the repair engine so failed matches always error (default enabled). */
15
+ enabled?: boolean;
16
+ /** Content length above which the line-window repair rules are skipped. */
17
+ maxFileChars?: number;
18
+ /** `old_string` line count above which the line-window repair rules are skipped. */
19
+ maxWindowLines?: number;
20
+ }
21
+ /**
22
+ * The edit repair tuning after defaulting, plus the session path-history
23
+ * source for missing-target re-anchoring.
24
+ */
25
+ export interface EditRepairTuning {
26
+ /** Master switch: failed-match repair and missing-path re-anchoring. */
27
+ enabled: boolean;
28
+ /** Content length above which the line-window repair rules are skipped. */
29
+ maxFileChars: number;
30
+ /** `old_string` line count above which the line-window repair rules are skipped. */
31
+ maxWindowLines: number;
32
+ /**
33
+ * Absolute path arguments of the session's prior successful tool calls, most
34
+ * recent first — the missing-path re-anchor's history source.
35
+ */
36
+ priorPaths(session: Session | undefined, limit?: number): string[];
37
+ }
38
+ /** Validated `edit` arguments after defaulting. */
39
+ interface EditInput {
40
+ filePath: string;
41
+ oldString: string;
42
+ newString: string;
43
+ replaceAll: boolean;
44
+ }
45
+ /**
46
+ * Validate value constraints the schema DSL can't express: a non-blank
47
+ * `file_path`, a non-empty `old_string`, and `old_string !== new_string`
48
+ * (an equal pair would be a guaranteed no-op edit).
49
+ * @param args - the schema-validated raw tool arguments.
50
+ * @returns the camelCased input with `replace_all` defaulted to false.
51
+ */
52
+ export declare function parseEditArgs(args: {
53
+ file_path: string;
54
+ old_string: string;
55
+ new_string: string;
56
+ replace_all?: boolean;
57
+ }): EditInput;
58
+ /**
59
+ * Format an edit success (single-match or replace-all) as a Claude-style model-facing message.
60
+ * @param displayPath - the backend-resolved path shown to the model.
61
+ * @param replaceAll - selects the all-occurrences wording over the single-replacement one.
62
+ * @returns the confirmation sentence the model sees as the tool result.
63
+ */
64
+ export declare function formatEditOutput(displayPath: string, replaceAll: boolean): string;
65
+ /**
66
+ * Register the `edit` tool and its scope-aware system-prompt guidance.
67
+ * @param ctx - the plugin context; registrations are effects scoped to it, and execution uses its `fs` service.
68
+ * @param sandbox - the shared sandbox-escalation API (advertisement, mode stamping, denial mapping).
69
+ * @param repair - the resolved tuning for the failed-match repair engine and missing-path re-anchoring.
70
+ */
71
+ export declare function applyEditTool(ctx: Context, sandbox: FsSandboxController, repair: EditRepairTuning): void;
72
+ export {};
73
+ //# 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 @deepseek-ai/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,36 @@
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 @deepseek-ai/dsh-tool-fs
6
+ */
7
+ import type { Context } from '@deepseek-ai/cordis';
8
+ import z from '@deepseek-ai/schemastery';
9
+ import type { ReadRepairConfig } from './read.ts';
10
+ import type { WriteRepairConfig } from './write.ts';
11
+ import type { EditRepairConfig } from './edit.ts';
12
+ /** Cordis plugin name used by loader diagnostics. */
13
+ export declare const name = "tool-fs";
14
+ /** Services required by the filesystem tool suite. */
15
+ export declare const inject: string[];
16
+ /** Plugin config (all optional — `Config` supplies the defaults). */
17
+ export interface Config {
18
+ /** Default and maximum number of lines returned by one `read` call. */
19
+ readLimit?: number;
20
+ /** Maximum characters returned for a single line before truncation. */
21
+ readMaxLineLength?: number;
22
+ /** Maximum bytes returned for the selected lines of one `read` call. */
23
+ readMaxBytes?: number;
24
+ /** Files at or above this size stream instead of loading whole into memory. */
25
+ readStreamMinSize?: number;
26
+ /** Repair tuning applied when `edit`'s `old_string` fails to match verbatim (enabled by default). */
27
+ editRepair?: EditRepairConfig;
28
+ /** Repair tuning for the `read` tool's addressing and path failures (enabled by default). */
29
+ readRepair?: ReadRepairConfig;
30
+ /** Tuning for the `write` tool's drifted-path hint on creates (enabled by default). */
31
+ writeRepair?: WriteRepairConfig;
32
+ }
33
+ export declare const Config: z<Config>;
34
+ /** Register the full `read`/`write`/`edit` filesystem tool suite, plus `read_image` while `attachments` is mounted. */
35
+ export declare function apply(ctx: Context, config: Config): void;
36
+ //# 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 @deepseek-ai/dsh-tool-fs/src/read-image
12
+ */
13
+ import type { Context } from '@deepseek-ai/cordis';
14
+ import type { ImageAttachmentRef, ImageMediaType } from '@deepseek-ai/dsh-attachment';
15
+ import type { ToolExecution } from '@deepseek-ai/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,129 @@
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
+ /** What read repair normalized, rendered after the footer; undefined when no repair fired. */
49
+ repairNote?: string;
50
+ }
51
+ /** The scan facts {@link parseOffsetOutOfRange} extracts from one offset-out-of-range failure. */
52
+ export interface OffsetOutOfRange {
53
+ /** The 1-based start line the caller requested. */
54
+ requestedOffset: number;
55
+ /** Exact total line count the scan observed. */
56
+ totalLines: number;
57
+ }
58
+ /**
59
+ * Recognize this package's own offset-out-of-range `FsError` and return its scan
60
+ * facts, so the read tool can tail-anchor the window instead of erroring. The
61
+ * message and this parser live in the same module on purpose: the format is a
62
+ * package-internal contract, pinned by tests on both sides.
63
+ * @param error - the caught value from {@link buildWindow}.
64
+ * @returns the requested offset and observed line count, or `undefined` for any other failure.
65
+ */
66
+ export declare function parseOffsetOutOfRange(error: unknown): OffsetOutOfRange | undefined;
67
+ /**
68
+ * Build one window from streamed or whole-file chunks, enforcing line and byte caps while still
69
+ * scanning to an exact total line count, and throwing `FS_NOT_FOUND` when the requested offset is
70
+ * past EOF.
71
+ * @param chunks - decoded text chunks in file order; chunk boundaries carry no meaning.
72
+ * @param request - the resolved window; the caller has already applied its defaults and caps.
73
+ * @param displayPath - the caller-facing path used in the offset-out-of-range error.
74
+ * @returns the numbered window lines, the total line count seen, and the byte-cap truncation flag.
75
+ */
76
+ export declare function buildWindow(chunks: AsyncIterable<string> | Iterable<string>, request: ReadWindow, displayPath: string): Promise<WindowResult>;
77
+ /**
78
+ * Format a read outcome as one OpenCode-style line-numbered text block body.
79
+ * @param displayPath - the backend-resolved path rendered in the envelope's `<path>` element.
80
+ * @param outcome - the windowed read to render.
81
+ * @returns the model-facing envelope: numbered lines, a continuation or end-of-file footer, and the repair disclosure when one fired.
82
+ */
83
+ export declare function formatReadOutput(displayPath: string, outcome: FileReadOutcome): string;
84
+ /**
85
+ * Derive the persisted `lang` hint from a read path's file extension. The shared
86
+ * table in `@deepseek-ai/dsh-util-code-language` owns the recognized suffixes and
87
+ * the path rules (both separators, a leading dot as the extension separator, and
88
+ * prototype-key safety); `readLangHintForPath` projects the read card's short ids
89
+ * over it, so a suffix whose value a recorded session already holds keeps it
90
+ * byte-identical while every other suffix uses its language's short name.
91
+ * @param path - the model-facing path the read reported.
92
+ * @returns the persisted language hint, or `undefined` when the extension maps to none.
93
+ */
94
+ export { readLangHintForPath as langFromPath } from '@deepseek-ai/dsh-util-code-language';
95
+ /**
96
+ * The `read` tool's private `tool/result` `meta` payload: the structured
97
+ * line-numbered window a capable UI renders as a code view. Attached opaquely (as
98
+ * `unknown`) on the tool result and persisted with the session log — it must be
99
+ * JSON-serializable (the session validates this at `append`), so `presentResult`
100
+ * reproduces the read card on replay when the raw structured output is no longer
101
+ * on the wire. The producing tool owns and narrows this opaque shape.
102
+ */
103
+ export interface FsReadMeta {
104
+ /** The read file's model-facing path. */
105
+ path: string;
106
+ /** The 1-based first line the window requested, kept even when `lines` is empty. */
107
+ offset: number;
108
+ /** The returned window's lines, each keeping its file line number. */
109
+ lines: FileTextLine[];
110
+ /** Exact total line count in the file. */
111
+ totalLines: number;
112
+ /** Syntax-highlighting language hint from the extension, or omitted for plain text. */
113
+ lang?: string;
114
+ }
115
+ /**
116
+ * Narrow opaque live or replayed result metadata to a structured read window.
117
+ * Malformed metadata returns `undefined` so presentation can fall back to the
118
+ * generic text card instead of throwing during replay. Beyond shape, the
119
+ * semantic contract of a read window is enforced against replayed JSON that is
120
+ * well-typed but out of range: `offset` must be a 1-based integer, `totalLines`
121
+ * must be a non-negative integer, each line number must be a 1-based integer no
122
+ * less than `offset`, the line numbers must strictly increase, and no line number
123
+ * may exceed `totalLines`. Any violation declines to the generic fallback rather
124
+ * than emitting a card that misnumbers or overcounts.
125
+ * @param meta - result metadata.
126
+ * @returns the validated read window, or `undefined` for absent, malformed, or semantically invalid data.
127
+ */
128
+ export declare function readMetaFromMeta(meta: unknown): FsReadMeta | undefined;
129
+ //# sourceMappingURL=read-render.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Shared path resolution and regular-file validation for model-facing read tools.
3
+ * @module @deepseek-ai/dsh-tool-fs/src/read-target
4
+ */
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ import type { FsInfo, FsTarget } from '@deepseek-ai/dsh-fs';
7
+ import type { ToolExecution } from '@deepseek-ai/dsh-tools';
8
+ import type { MissingPathRepair } from '@deepseek-ai/dsh-fs-edit-repair';
9
+ /**
10
+ * Resolve a model-supplied path, observe absence, and require a regular file.
11
+ * @param ctx - the plugin context providing filesystem resolution and observation events.
12
+ * @param exec - the current tool execution, including session cwd and cancellation.
13
+ * @param requestedPath - the raw path supplied to the tool.
14
+ * @returns the resolved target and its single stat result.
15
+ */
16
+ export declare function resolveRegularReadTarget(ctx: Context, exec: ToolExecution, requestedPath: string): Promise<{
17
+ target: FsTarget;
18
+ info: FsInfo;
19
+ }>;
20
+ /**
21
+ * Attempt the engine's missing-path composition for a failed tool target: a
22
+ * unique match among the session's prior successful path arguments, then a
23
+ * unique directory-tree completion, each proven present before adoption. A
24
+ * tool never re-anchors on ambiguity, so a wrong guess cannot replace a real
25
+ * answer — the caller keeps its verbatim error when this returns `undefined`.
26
+ * @param ctx - the plugin context providing filesystem resolution and listing.
27
+ * @param exec - the current tool execution, including session cwd and cancellation.
28
+ * @param requestedPath - the raw path the model supplied.
29
+ * @param knownPaths - the session's prior successful path arguments, most recent first.
30
+ * @returns the verified replacement path with its disclosure, or `undefined`.
31
+ */
32
+ export declare function repairTargetPath(ctx: Context, exec: ToolExecution, requestedPath: string, knownPaths: readonly string[]): Promise<MissingPathRepair | undefined>;
33
+ //# sourceMappingURL=read-target.d.ts.map
@@ -0,0 +1,150 @@
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
+ import type { ReadArgRepair } from '@deepseek-ai/dsh-arg-repair';
8
+ import type { Session } from '@deepseek-ai/dsh-session';
9
+ import type { ReadDuplicateVerdict } from '@deepseek-ai/dsh-fs-edit-repair';
10
+ /** Default and maximum number of lines returned by one `read` call (the `readLimit` config). */
11
+ export declare const READ_LIMIT = 2000;
12
+ /**
13
+ * Default streaming threshold (the `readStreamMinSize` config): files at or
14
+ * above this size stream; smaller files read whole into memory.
15
+ */
16
+ export declare const STREAM_MIN_SIZE: number;
17
+ /** Resolved read-tool caps — plugin config after defaulting (see `Config` in index.ts). */
18
+ export interface ReadToolCaps {
19
+ /** Default and maximum number of lines returned by one call. */
20
+ limit: number;
21
+ /** Maximum characters returned for a single line. */
22
+ maxLineLength: number;
23
+ /** Maximum bytes returned for selected file lines. */
24
+ maxBytes: number;
25
+ /** Files at or above this size stream; smaller files read whole into memory. */
26
+ streamMinSize: number;
27
+ }
28
+ /**
29
+ * Repair and duplicate-read tuning for the `read` tool; rules live in `@deepseek-ai/dsh-arg-repair`
30
+ * and `@deepseek-ai/dsh-fs-edit-repair`.
31
+ */
32
+ export interface ReadRepairConfig {
33
+ /** Disable the read repairs so invalid windows and missing paths always error (default enabled). */
34
+ enabled?: boolean;
35
+ /**
36
+ * Refuse a read fully covered by this session's recent window of the same
37
+ * file that no mutation, compaction, or step budget has invalidated — the
38
+ * model already holds that exact content. On by default.
39
+ */
40
+ duplicate?: {
41
+ /** Master switch for the duplicate-read refusal. */
42
+ enabled?: boolean;
43
+ /** Committed steps since the recorded window beyond which the model is assumed to have forgotten the content. */
44
+ maxSteps?: number;
45
+ };
46
+ /**
47
+ * Complete a window's structural boundaries from the neighbouring lines: the
48
+ * line that opened the construct the window starts inside, and the lines that
49
+ * close the construct it ends inside (markdown fence, bracket block, or
50
+ * indentation block). On by default.
51
+ */
52
+ completion?: {
53
+ /** Master switch for structural window completion. */
54
+ enabled?: boolean;
55
+ /** Maximum lines appended to close the tail, and how far back the head search may reach for the opening line. */
56
+ maxLines?: number;
57
+ };
58
+ }
59
+ /**
60
+ * Read repair tuning: the engine switch, the session path-history source, and
61
+ * the duplicate-read guard with its window projection.
62
+ * Disabled, every read failure keeps its verbatim error.
63
+ */
64
+ export interface ReadRepairTuning {
65
+ /** Master switch for the read repair rules. */
66
+ enabled: boolean;
67
+ /**
68
+ * Absolute path arguments of the session's prior successful tool calls, most
69
+ * recent first — `repairMissingPath`'s history source.
70
+ */
71
+ priorPaths(session: Session | undefined, limit?: number): string[];
72
+ /**
73
+ * The duplicate-read guard: `judge` consults the session's window history
74
+ * before the read runs; `record` stores the delivered window after it.
75
+ * Disabled, every read runs unconditionally.
76
+ */
77
+ duplicate: {
78
+ enabled: boolean;
79
+ /** Committed steps since the recorded window beyond which the model is assumed to have forgotten the content. */
80
+ maxSteps: number;
81
+ judge(session: Session | undefined, path: string, version: string, window: {
82
+ offset: number;
83
+ endLine: number;
84
+ }): ReadDuplicateVerdict | undefined;
85
+ record(session: Session | undefined, path: string, observation: {
86
+ offset: number;
87
+ endLine: number;
88
+ totalLines: number;
89
+ version: string;
90
+ }): void;
91
+ };
92
+ /**
93
+ * Structural window completion: prepends the line that opened the construct
94
+ * the window starts inside, and appends the following lines that close the
95
+ * construct it ends inside (markdown fence, bracket block, indentation
96
+ * block). Disabled, windows carry exactly the lines the caps selected.
97
+ * Completion states nothing: the added lines carry their own numbers, so the
98
+ * model reads where the window starts and stops without being told.
99
+ */
100
+ completion: {
101
+ enabled: boolean;
102
+ maxLines: number;
103
+ };
104
+ /**
105
+ * Claim the right to state one procedural disclosure in this session.
106
+ * Normalizing a read argument is stated once per rule: the delivered window
107
+ * and its footer already carry the effective range, so repeating the sentence
108
+ * costs tokens without changing what the model can do.
109
+ * @param session - the reading call's session; `undefined` states every claim.
110
+ * @param key - the rule's stable id, one per rule rather than per value.
111
+ * @returns true when this call is the session's first claim of `key`.
112
+ */
113
+ claimDisclosure(session: Session | undefined, key: string): boolean;
114
+ }
115
+ /** Validated `read` arguments after defaulting. */
116
+ interface ReadInput {
117
+ filePath: string;
118
+ offset: number;
119
+ limit: number;
120
+ /** Run the read even when the duplicate guard would intercept it. */
121
+ force: boolean;
122
+ /** What arg repair normalized before validation; absent when the raw args were already valid. */
123
+ repairs?: readonly ReadArgRepair[];
124
+ }
125
+ /**
126
+ * Validate value constraints the schema DSL can't express. `maxLimit` is the deployment's line cap.
127
+ * With repair enabled, the measured addressing failures are normalized first through
128
+ * {@link repairReadArgs}: a 0-based or negative start index and an over-cap or
129
+ * non-positive limit all carry unambiguous intent, so the value is substituted
130
+ * and the rule reported instead of erroring.
131
+ * @param args - the schema-validated raw tool arguments; `offset`/`limit` must be positive integers when given unrepairable shapes.
132
+ * @param maxLimit - the configured line cap: both the default `limit` and the largest one accepted.
133
+ * @param repairEnabled - the read repair engine's switch; disabled keeps the strict validation errors.
134
+ * @returns the validated input with `offset` defaulted to 1 and `limit` to `maxLimit`, plus the rules that fired.
135
+ */
136
+ export declare function parseReadArgs(args: {
137
+ file_path: string;
138
+ force?: boolean;
139
+ offset?: number;
140
+ limit?: number;
141
+ }, maxLimit: number, repairEnabled?: boolean): ReadInput;
142
+ /**
143
+ * Register the `read` tool and its scope-aware system-prompt guidance.
144
+ * @param ctx - the plugin context; registrations are effects scoped to it, and execution uses its `fs` service.
145
+ * @param caps - the deployment's resolved read caps (plugin config after defaulting).
146
+ * @param repair - the read repair tuning; disabled keeps every failure's verbatim error.
147
+ */
148
+ export declare function applyReadTool(ctx: Context, caps: ReadToolCaps, repair: ReadRepairTuning): void;
149
+ export {};
150
+ //# sourceMappingURL=read.d.ts.map