@swoop111/dsh-tool-fs 0.2.0-rc.2 → 0.2.0-rc.2.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.
@@ -1,129 +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). */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
8
  export declare const READ_MAX_LINE_LENGTH = 2000;
9
- /** Default maximum bytes returned for selected file lines (the `readMaxBytes` config). */
9
+
10
10
  export declare const READ_MAX_BYTES: number;
11
- /** Resolved read window. The consumer applies its defaults/caps before calling. */
11
+
12
12
  export interface ReadWindow {
13
- /** 1-based first line to return. */
13
+
14
14
  offset: number;
15
- /** Maximum number of lines to return. */
15
+
16
16
  limit: number;
17
- /** Maximum characters returned for a single line; overflow is truncated with a suffix. */
17
+
18
18
  maxLineLength: number;
19
- /** Maximum bytes of selected output; overflow stops the scan and marks `truncatedByBytes`. */
19
+
20
20
  maxBytes: number;
21
21
  }
22
- /** One line returned from a text file. */
22
+
23
23
  export interface FileTextLine {
24
- /** 1-based line number in the file. */
24
+
25
25
  number: number;
26
- /** Line text without its trailing newline. */
26
+
27
27
  text: string;
28
28
  }
29
- /** The windowed result {@link buildWindow} produces from a file's decoded text. */
29
+
30
30
  export interface WindowResult {
31
- /** Returned lines, already numbered. */
31
+
32
32
  lines: FileTextLine[];
33
- /** Exact total line count in the file. */
33
+
34
34
  totalLines: number;
35
- /** Whether selected output hit the byte cap. */
35
+
36
36
  truncatedByBytes: boolean;
37
37
  }
38
- /** Outcome of a bounded text read — what {@link formatReadOutput} renders. */
38
+
39
39
  export interface FileReadOutcome {
40
- /** 1-based first line requested. */
40
+
41
41
  offset: number;
42
- /** Returned lines, already numbered. */
42
+
43
43
  lines: FileTextLine[];
44
- /** Exact total line count in the file. */
44
+
45
45
  totalLines: number;
46
- /** Whether selected output hit the byte cap. */
46
+
47
47
  truncatedByBytes?: true;
48
- /** What read repair normalized, rendered after the footer; undefined when no repair fired. */
48
+
49
49
  repairNote?: string;
50
50
  }
51
- /** The scan facts {@link parseOffsetOutOfRange} extracts from one offset-out-of-range failure. */
51
+
52
52
  export interface OffsetOutOfRange {
53
- /** The 1-based start line the caller requested. */
53
+
54
54
  requestedOffset: number;
55
- /** Exact total line count the scan observed. */
55
+
56
56
  totalLines: number;
57
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
- */
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
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
- */
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
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
- */
77
+
78
+
79
+
80
+
81
+
82
+
83
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
- */
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
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
- */
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
103
  export interface FsReadMeta {
104
- /** The read file's model-facing path. */
104
+
105
105
  path: string;
106
- /** The 1-based first line the window requested, kept even when `lines` is empty. */
106
+
107
107
  offset: number;
108
- /** The returned window's lines, each keeping its file line number. */
108
+
109
109
  lines: FileTextLine[];
110
- /** Exact total line count in the file. */
110
+
111
111
  totalLines: number;
112
- /** Syntax-highlighting language hint from the extension, or omitted for plain text. */
112
+
113
113
  lang?: string;
114
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
- */
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
128
  export declare function readMetaFromMeta(meta: unknown): FsReadMeta | undefined;
129
- //# sourceMappingURL=read-render.d.ts.map
129
+
@@ -1,33 +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
- */
1
+
2
+
3
+
4
+
5
5
  import type { Context } from '@deepseek-ai/cordis';
6
6
  import type { FsInfo, FsTarget } from '@deepseek-ai/dsh-fs';
7
7
  import type { ToolExecution } from '@deepseek-ai/dsh-tools';
8
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
- */
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
16
  export declare function resolveRegularReadTarget(ctx: Context, exec: ToolExecution, requestedPath: string): Promise<{
17
17
  target: FsTarget;
18
18
  info: FsInfo;
19
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
- */
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
32
  export declare function repairTargetPath(ctx: Context, exec: ToolExecution, requestedPath: string, knownPaths: readonly string[]): Promise<MissingPathRepair | undefined>;
33
- //# sourceMappingURL=read-target.d.ts.map
33
+
@@ -1,82 +1,82 @@
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
- */
1
+
2
+
3
+
4
+
5
+
6
6
  import type { Context } from '@deepseek-ai/cordis';
7
7
  import type { ReadArgRepair } from '@deepseek-ai/dsh-arg-repair';
8
8
  import type { Session } from '@deepseek-ai/dsh-session';
9
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). */
10
+
11
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
- */
12
+
13
+
14
+
15
+
16
16
  export declare const STREAM_MIN_SIZE: number;
17
- /** Resolved read-tool caps — plugin config after defaulting (see `Config` in index.ts). */
17
+
18
18
  export interface ReadToolCaps {
19
- /** Default and maximum number of lines returned by one call. */
19
+
20
20
  limit: number;
21
- /** Maximum characters returned for a single line. */
21
+
22
22
  maxLineLength: number;
23
- /** Maximum bytes returned for selected file lines. */
23
+
24
24
  maxBytes: number;
25
- /** Files at or above this size stream; smaller files read whole into memory. */
25
+
26
26
  streamMinSize: number;
27
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
- */
28
+
29
+
30
+
31
+
32
32
  export interface ReadRepairConfig {
33
- /** Disable the read repairs so invalid windows and missing paths always error (default enabled). */
33
+
34
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
- */
35
+
36
+
37
+
38
+
39
+
40
40
  duplicate?: {
41
- /** Master switch for the duplicate-read refusal. */
41
+
42
42
  enabled?: boolean;
43
- /** Committed steps since the recorded window beyond which the model is assumed to have forgotten the content. */
43
+
44
44
  maxSteps?: number;
45
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
- */
46
+
47
+
48
+
49
+
50
+
51
+
52
52
  completion?: {
53
- /** Master switch for structural window completion. */
53
+
54
54
  enabled?: boolean;
55
- /** Maximum lines appended to close the tail, and how far back the head search may reach for the opening line. */
55
+
56
56
  maxLines?: number;
57
57
  };
58
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
- */
59
+
60
+
61
+
62
+
63
+
64
64
  export interface ReadRepairTuning {
65
- /** Master switch for the read repair rules. */
65
+
66
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
- */
67
+
68
+
69
+
70
+
71
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
- */
72
+
73
+
74
+
75
+
76
+
77
77
  duplicate: {
78
78
  enabled: boolean;
79
- /** Committed steps since the recorded window beyond which the model is assumed to have forgotten the content. */
79
+
80
80
  maxSteps: number;
81
81
  judge(session: Session | undefined, path: string, version: string, window: {
82
82
  offset: number;
@@ -89,62 +89,62 @@ export interface ReadRepairTuning {
89
89
  version: string;
90
90
  }): void;
91
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
- */
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
100
  completion: {
101
101
  enabled: boolean;
102
102
  maxLines: number;
103
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
- */
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
113
  claimDisclosure(session: Session | undefined, key: string): boolean;
114
114
  }
115
- /** Validated `read` arguments after defaulting. */
115
+
116
116
  interface ReadInput {
117
117
  filePath: string;
118
118
  offset: number;
119
119
  limit: number;
120
- /** Run the read even when the duplicate guard would intercept it. */
120
+
121
121
  force: boolean;
122
- /** What arg repair normalized before validation; absent when the raw args were already valid. */
122
+
123
123
  repairs?: readonly ReadArgRepair[];
124
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
- */
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
136
  export declare function parseReadArgs(args: {
137
137
  file_path: string;
138
138
  force?: boolean;
139
139
  offset?: number;
140
140
  limit?: number;
141
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
- */
142
+
143
+
144
+
145
+
146
+
147
+
148
148
  export declare function applyReadTool(ctx: Context, caps: ReadToolCaps, repair: ReadRepairTuning): void;
149
149
  export {};
150
- //# sourceMappingURL=read.d.ts.map
150
+
@@ -1,23 +1,23 @@
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 `@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
- */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
12
  import type { Context } from '@deepseek-ai/cordis';
13
13
  import type { ToolExecution } from '@deepseek-ai/dsh-tools';
14
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). */
15
+
16
16
  export interface FsEscalationArgs {
17
17
  sandbox_permissions?: string;
18
18
  justification?: string;
19
19
  }
20
- /** The schema fields for the escalation arguments, spread into a tool's `parameters` when a confining backend is mounted. */
20
+
21
21
  export interface EscalationSchemaFields {
22
22
  sandbox_permissions: {
23
23
  type: 'string';
@@ -29,54 +29,54 @@ export interface EscalationSchemaFields {
29
29
  description: string;
30
30
  };
31
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
- */
32
+
33
+
34
+
35
+
36
+
37
37
  export declare class FsSandboxController {
38
38
  private readonly ctx;
39
- /** The escalation targets this composition advertises (`[]` when no confining backend is mounted). */
39
+
40
40
  readonly escalationModes: readonly SandboxMode[];
41
- /** Shared per-session policy resolver, required by a confining backend. */
41
+
42
42
  private readonly policy;
43
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
- */
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
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. Repeating the standing mode
56
- * requires no approval. The calling session's cwd is
57
- * always carried as the workspace root. Validates the escalation argument
58
- * pairing first.
59
- * @param toolName - the mutating tool's name, for the approval audit trail.
60
- * @param args - the call's escalation arguments.
61
- * @param exec - the tool-execution context (agent, callId, signal).
62
- * @returns the policy to pass to the mutation, or undefined for an
63
- * unsandboxed backend.
64
- */
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
65
  resolvePolicy(toolName: string, args: FsEscalationArgs, exec: ToolExecution): Promise<SandboxExecutionPolicy | undefined>;
66
- /**
67
- * Map a thrown provider error for the model: a `FS_SANDBOX_DENIED` becomes a
68
- * `FsError` whose text is the shared `[sandbox: …]` denial marker plus the
69
- * same-turn escalation hint, so a policy denial reads identically to bash's
70
- * WHILE keeping the structured `FS_SANDBOX_DENIED` code — `ToolRuntime`
71
- * populates `result.error` only for `HarnessError` instances, so a plain
72
- * `Error` would strip the code retry/observers key off. Any other error
73
- * passes through unchanged. A `FS_SANDBOX_DENIED` only arises under a
74
- * confining backend, which always advertises the escalation fields, so the
75
- * hint always applies here.
76
- * @param error - the error thrown by the mutation.
77
- * @param policy - the policy stamped onto the call (names the mode in the marker).
78
- * @returns the error to throw — the marker `FsError` for a sandbox denial, else the original.
79
- */
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
80
  mapError(error: unknown, policy: SandboxExecutionPolicy | undefined): unknown;
81
81
  }
82
- //# sourceMappingURL=sandbox.d.ts.map
82
+